From 57b9a5c2e3019e69a74355fb2af012ae3e5f92dd Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 31 Jul 2019 19:33:40 +0100 Subject: [PATCH 01/98] Renamed RestrictionType to AccountRestrictionType --- e2e/infrastructure/AccountHttp.spec.ts | 8 ++--- e2e/infrastructure/TransactionHttp.spec.ts | 14 ++++----- src/core/utils/DtoMapping.ts | 14 ++++----- src/model/account/AccountRestriction.ts | 4 +-- ...ctionType.ts => AccountRestrictionType.ts} | 2 +- src/model/model.ts | 2 +- ...dressRestrictionModificationTransaction.ts | 6 ++-- ...osaicRestrictionModificationTransaction.ts | 6 ++-- ...ationRestrictionModificationTransaction.ts | 6 ++-- .../AccountRestrictionTransaction.ts | 14 ++++----- test/core/utils/TransactionMapping.spec.ts | 31 ++++++++++--------- .../SerializeTransactionToJSON.spec.ts | 14 ++++----- test/model/account/AccountRestriction.spec.ts | 4 +-- .../model/account/AccountRestrictions.spec.ts | 4 +-- .../account/AccountRestrictionsInfo.spec.ts | 4 +-- .../AccountRestrictionTransaction.spec.ts | 22 ++++++------- 16 files changed, 78 insertions(+), 77 deletions(-) rename src/model/account/{RestrictionType.ts => AccountRestrictionType.ts} (96%) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 89c0ba90ff..8f2d30b0b9 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -19,10 +19,10 @@ import {assert, expect} from 'chai'; import {AccountHttp} from '../../src/infrastructure/AccountHttp'; import { Listener, TransactionHttp } from '../../src/infrastructure/infrastructure'; import { Account } from '../../src/model/account/Account'; +import { AccountRestrictionType } from '../../src/model/account/AccountRestrictionType'; import {Address} from '../../src/model/account/Address'; -import { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../src/model/account/RestrictionType'; import {PublicAccount} from '../../src/model/account/PublicAccount'; +import { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType'; import {NetworkType} from '../../src/model/blockchain/NetworkType'; import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; import { AliasActionType } from '../../src/model/namespace/AliasActionType'; @@ -200,7 +200,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); @@ -426,7 +426,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 2f60993e0c..f7dba66f53 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -25,8 +25,8 @@ import { NamespaceHttp } from '../../src/infrastructure/infrastructure'; import {Listener} from '../../src/infrastructure/Listener'; import {TransactionHttp} from '../../src/infrastructure/TransactionHttp'; import {Account} from '../../src/model/account/Account'; +import { AccountRestrictionType } from '../../src/model/account/AccountRestrictionType'; import { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../src/model/account/RestrictionType'; import {NetworkType} from '../../src/model/blockchain/NetworkType'; import { Mosaic } from '../../src/model/mosaic/Mosaic'; import {MosaicId} from '../../src/model/mosaic/MosaicId'; @@ -404,7 +404,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -441,7 +441,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -479,7 +479,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockMosaic, + AccountRestrictionType.BlockMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -516,7 +516,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockMosaic, + AccountRestrictionType.BlockMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -554,7 +554,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockTransaction, + AccountRestrictionType.BlockTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -591,7 +591,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockTransaction, + AccountRestrictionType.BlockTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); diff --git a/src/core/utils/DtoMapping.ts b/src/core/utils/DtoMapping.ts index 9a0e2b77d1..2babb31068 100644 --- a/src/core/utils/DtoMapping.ts +++ b/src/core/utils/DtoMapping.ts @@ -17,8 +17,8 @@ import { AccountRestriction } from '../../model/account/AccountRestriction'; import { AccountRestrictions } from '../../model/account/AccountRestrictions'; import { AccountRestrictionsInfo } from '../../model/account/AccountRestrictionsInfo'; +import { AccountRestrictionType } from '../../model/account/AccountRestrictionType'; import { Address } from '../../model/account/Address'; -import { RestrictionType } from '../../model/account/RestrictionType'; import { MosaicId } from '../../model/mosaic/MosaicId'; export class DtoMapping { @@ -34,16 +34,16 @@ export class DtoMapping { new AccountRestrictions(Address.createFromEncoded(accountRestrictions.accountRestrictions.address), accountRestrictions.accountRestrictions.restrictions.map((prop) => { switch (prop.restrictionType) { - case RestrictionType.AllowAddress: - case RestrictionType.BlockAddress: + case AccountRestrictionType.AllowAddress: + case AccountRestrictionType.BlockAddress: return new AccountRestriction(prop.restrictionType, prop.values.map((value) => Address.createFromEncoded(value))); - case RestrictionType.AllowMosaic: - case RestrictionType.BlockMosaic: + case AccountRestrictionType.AllowMosaic: + case AccountRestrictionType.BlockMosaic: return new AccountRestriction(prop.restrictionType, prop.values.map((value) => new MosaicId(value))); - case RestrictionType.AllowTransaction: - case RestrictionType.BlockTransaction: + case AccountRestrictionType.AllowTransaction: + case AccountRestrictionType.BlockTransaction: return new AccountRestriction(prop.restrictionType, prop.values); default: throw new Error(`Invalid restriction type: ${prop.restrictionType}`); diff --git a/src/model/account/AccountRestriction.ts b/src/model/account/AccountRestriction.ts index 7eb6928f11..47bf9a345c 100644 --- a/src/model/account/AccountRestriction.ts +++ b/src/model/account/AccountRestriction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RestrictionType } from './RestrictionType'; +import { AccountRestrictionType } from './AccountRestrictionType'; /** * Account restriction structure describes restriction information. */ @@ -29,7 +29,7 @@ export class AccountRestriction { /** * Account restriction type */ - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, /** * Restriction values. */ diff --git a/src/model/account/RestrictionType.ts b/src/model/account/AccountRestrictionType.ts similarity index 96% rename from src/model/account/RestrictionType.ts rename to src/model/account/AccountRestrictionType.ts index aa7d236ed0..93b503b5af 100644 --- a/src/model/account/RestrictionType.ts +++ b/src/model/account/AccountRestrictionType.ts @@ -23,7 +23,7 @@ * 0x80 + type The restriction is interpreted as a blocking operation. */ -export enum RestrictionType { +export enum AccountRestrictionType { AllowAddress = 0x01, AllowMosaic = 0x02, AllowTransaction = 0x04, diff --git a/src/model/model.ts b/src/model/model.ts index 62bb27f331..4224630cc8 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -28,7 +28,7 @@ export * from './account/AccountRestrictions'; export * from './account/AccountRestrictionsInfo'; export * from './account/AccountRestriction'; export * from './account/RestrictionModificationType'; -export * from './account/RestrictionType'; +export * from './account/AccountRestrictionType'; export * from './account/AccountNames'; // Blockchain diff --git a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts b/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts index 3a9d99f813..822bc9d284 100644 --- a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts @@ -16,8 +16,8 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { PublicAccount } from '../account/PublicAccount'; -import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; @@ -39,7 +39,7 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio * @returns {AccountAddressRestrictionModificationTransaction} */ public static create(deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountAddressRestrictionModificationTransaction { @@ -66,7 +66,7 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, diff --git a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts b/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts index 3a32656795..9de6449f61 100644 --- a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts @@ -16,8 +16,8 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { PublicAccount } from '../account/PublicAccount'; -import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; @@ -39,7 +39,7 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction * @returns {AccountAddressRestrictionModificationTransaction} */ public static create(deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountMosaicRestrictionModificationTransaction { @@ -66,7 +66,7 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, diff --git a/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts b/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts index 38160cc79d..45788393e3 100644 --- a/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts @@ -16,8 +16,8 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { PublicAccount } from '../account/PublicAccount'; -import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; @@ -39,7 +39,7 @@ export class AccountOperationRestrictionModificationTransaction extends Transact * @returns {AccountOperationRestrictionModificationTransaction} */ public static create(deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountOperationRestrictionModificationTransaction { @@ -66,7 +66,7 @@ export class AccountOperationRestrictionModificationTransaction extends Transact version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, diff --git a/src/model/transaction/AccountRestrictionTransaction.ts b/src/model/transaction/AccountRestrictionTransaction.ts index 7e0f26c313..2bb4aceaf4 100644 --- a/src/model/transaction/AccountRestrictionTransaction.ts +++ b/src/model/transaction/AccountRestrictionTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RestrictionType } from '../account/RestrictionType'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountAddressRestrictionModificationTransaction } from './AccountAddressRestrictionModificationTransaction'; @@ -36,12 +36,12 @@ export class AccountRestrictionTransaction { */ public static createAddressRestrictionModificationTransaction( deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountAddressRestrictionModificationTransaction { - if (![RestrictionType.AllowAddress, RestrictionType.BlockAddress].includes(restrictionType)) { + if (![AccountRestrictionType.AllowAddress, AccountRestrictionType.BlockAddress].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountAddressRestrictionModificationTransaction.create( @@ -64,12 +64,12 @@ export class AccountRestrictionTransaction { */ public static createMosaicRestrictionModificationTransaction( deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountMosaicRestrictionModificationTransaction { - if (![RestrictionType.AllowMosaic, RestrictionType.BlockMosaic].includes(restrictionType)) { + if (![AccountRestrictionType.AllowMosaic, AccountRestrictionType.BlockMosaic].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountMosaicRestrictionModificationTransaction.create( @@ -92,12 +92,12 @@ export class AccountRestrictionTransaction { */ public static createOperationRestrictionModificationTransaction( deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountOperationRestrictionModificationTransaction { - if (![RestrictionType.AllowTransaction, RestrictionType.BlockTransaction].includes(restrictionType)) { + if (![AccountRestrictionType.AllowTransaction, AccountRestrictionType.BlockTransaction].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountOperationRestrictionModificationTransaction.create( diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index 98fb4f5c86..c30b9e5474 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -20,10 +20,10 @@ import { sha3_256 } from 'js-sha3'; import {Convert as convert} from '../../../src/core/format'; import { TransactionMapping } from '../../../src/core/utils/TransactionMapping'; import { Account } from '../../../src/model/account/Account'; +import { AccountRestrictionType } from '../../../src/model/account/AccountRestrictionType'; import { Address } from '../../../src/model/account/Address'; import { PublicAccount } from '../../../src/model/account/PublicAccount'; import { RestrictionModificationType } from '../../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../../src/model/account/RestrictionType'; import { NetworkType } from '../../../src/model/blockchain/NetworkType'; import { EncryptedMessage } from '../../../src/model/model'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; @@ -35,7 +35,7 @@ import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrency import { AliasActionType } from '../../../src/model/namespace/AliasActionType'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { NamespaceType } from '../../../src/model/namespace/NamespaceType'; -import { AccountAddressRestrictionModificationTransaction } from '../../../src/model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionModificationTransaction } from'../../../src/model/transaction/AccountAddressRestrictionModificationTransaction'; import { AccountLinkTransaction } from '../../../src/model/transaction/AccountLinkTransaction'; import { AccountMosaicRestrictionModificationTransaction } from '../../../src/model/transaction/AccountMosaicRestrictionModificationTransaction'; import { AccountRestrictionModification } from '../../../src/model/transaction/AccountRestrictionModification'; @@ -79,7 +79,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -89,7 +89,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); }); @@ -102,7 +102,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -111,7 +111,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowMosaic); expect(transaction.modifications[0].value[0]).to.be.equal(2262289484); expect(transaction.modifications[0].value[1]).to.be.equal(3405110546); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); @@ -125,15 +125,16 @@ describe('TransactionMapping - createFromPayload', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); - const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); + const transaction = TransactionMapping + .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction); expect(transaction.modifications[0].value).to.be.equal(operation); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -665,7 +666,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -674,7 +675,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(addressRestrictionTransaction.toJSON()) as AccountAddressRestrictionModificationTransaction; expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -686,7 +687,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -695,7 +696,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(mosaicRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC); - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowMosaic); expect(transaction.modifications.length).to.be.equal(1); }); @@ -707,7 +708,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -716,7 +717,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(operationRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction); expect(transaction.modifications.length).to.be.equal(1); }); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 5a13ee0d28..933663285b 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -18,10 +18,10 @@ import { expect } from 'chai'; import { sha3_256 } from 'js-sha3'; import {Convert as convert} from '../../src/core/format'; import { Account } from '../../src/model/account/Account'; +import { AccountRestrictionType } from '../../src/model/account/AccountRestrictionType'; import { Address } from '../../src/model/account/Address'; import { PublicAccount } from '../../src/model/account/PublicAccount'; import { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../src/model/account/RestrictionType'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; @@ -83,7 +83,7 @@ describe('SerializeTransactionToJSON', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -91,7 +91,7 @@ describe('SerializeTransactionToJSON', () => { const json = addressRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS); - expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -103,7 +103,7 @@ describe('SerializeTransactionToJSON', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -111,7 +111,7 @@ describe('SerializeTransactionToJSON', () => { const json = mosaicRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC); - expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowMosaic); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -123,7 +123,7 @@ describe('SerializeTransactionToJSON', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -131,7 +131,7 @@ describe('SerializeTransactionToJSON', () => { const json = operationRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); - expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction); expect(json.transaction.modifications.length).to.be.equal(1); }); diff --git a/test/model/account/AccountRestriction.spec.ts b/test/model/account/AccountRestriction.spec.ts index 5bc3e189b6..d41a0e73a6 100644 --- a/test/model/account/AccountRestriction.spec.ts +++ b/test/model/account/AccountRestriction.spec.ts @@ -17,13 +17,13 @@ import {deepEqual} from 'assert'; import {expect} from 'chai'; import { AccountRestriction } from '../../../src/model/account/AccountRestriction'; +import { AccountRestrictionType } from '../../../src/model/account/AccountRestrictionType'; import { Address } from '../../../src/model/account/Address'; -import { RestrictionType } from '../../../src/model/account/RestrictionType'; describe('AccountRestriction', () => { it('should createComplete an AccountRestriction object', () => { const accountRestrictionDTO = { - restrictionType: RestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowAddress, values: ['906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'], }; diff --git a/test/model/account/AccountRestrictions.spec.ts b/test/model/account/AccountRestrictions.spec.ts index 1ad76d7daa..8b30a7451b 100644 --- a/test/model/account/AccountRestrictions.spec.ts +++ b/test/model/account/AccountRestrictions.spec.ts @@ -17,7 +17,7 @@ import {deepEqual} from 'assert'; import {expect} from 'chai'; import {Address} from '../../../src/model/account/Address'; -import { AccountRestrictions, RestrictionModificationType, RestrictionType, AccountRestriction } from '../../../src/model/model'; +import { AccountRestriction, AccountRestrictions, AccountRestrictionType, RestrictionModificationType } from '../../../src/model/model'; describe('AccountRestrictions', () => { @@ -25,7 +25,7 @@ describe('AccountRestrictions', () => { const accountRestrictionsDTO = { address: Address.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'), restrictions: [{ - restrictionType: RestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/account/AccountRestrictionsInfo.spec.ts b/test/model/account/AccountRestrictionsInfo.spec.ts index 01ac4771f9..981817bcea 100644 --- a/test/model/account/AccountRestrictionsInfo.spec.ts +++ b/test/model/account/AccountRestrictionsInfo.spec.ts @@ -18,9 +18,9 @@ import {deepEqual} from 'assert'; import { AccountRestriction } from '../../../src/model/account/AccountRestriction'; import { AccountRestrictions } from '../../../src/model/account/AccountRestrictions'; import { AccountRestrictionsInfo } from '../../../src/model/account/AccountRestrictionsInfo'; +import { AccountRestrictionType } from '../../../src/model/account/AccountRestrictionType'; import {Address} from '../../../src/model/account/Address'; import { RestrictionModificationType } from '../../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../../src/model/account/RestrictionType'; describe('AccountRestrictionsInfo', () => { @@ -31,7 +31,7 @@ describe('AccountRestrictionsInfo', () => { accountRestrictions: { address: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', restrictions: [{ - restrictionType: RestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 04ef489a07..8f83e951f3 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -16,9 +16,9 @@ import {expect} from 'chai'; import {Account} from '../../../src/model/account/Account'; +import { AccountRestrictionType } from '../../../src/model/account/AccountRestrictionType'; import {Address} from '../../../src/model/account/Address'; import { RestrictionModificationType } from '../../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../../src/model/account/RestrictionType'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {MosaicId} from '../../../src/model/mosaic/MosaicId'; import { AccountRestrictionModification } from '../../../src/model/transaction/AccountRestrictionModification'; @@ -74,7 +74,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -90,7 +90,7 @@ describe('AccountRestrictionTransaction', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -105,7 +105,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -121,7 +121,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -138,7 +138,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -157,7 +157,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -182,7 +182,7 @@ describe('AccountRestrictionTransaction', () => { expect(() => { AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.Sentinel, + AccountRestrictionType.Sentinel, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -199,7 +199,7 @@ describe('AccountRestrictionTransaction', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -224,7 +224,7 @@ describe('AccountRestrictionTransaction', () => { expect(() => { AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.Sentinel, + AccountRestrictionType.Sentinel, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -241,7 +241,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); From 194a59a9a792d16c63ac69a037772f174c34c25d Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 2 Aug 2019 10:15:35 +0100 Subject: [PATCH 02/98] Refactored AccountRestrictionType --- e2e/infrastructure/AccountHttp.spec.ts | 4 +- e2e/infrastructure/TransactionHttp.spec.ts | 8 +- src/core/utils/DtoMapping.ts | 12 ++- src/model/account/AccountRestrictionType.ts | 89 ++++++++++++++++--- .../AccountRestrictionTransaction.ts | 12 ++- test/core/utils/TransactionMapping.spec.ts | 16 ++-- .../SerializeTransactionToJSON.spec.ts | 8 +- test/model/account/AccountRestriction.spec.ts | 2 +- .../model/account/AccountRestrictions.spec.ts | 2 +- .../account/AccountRestrictionsInfo.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 12 +-- 11 files changed, 120 insertions(+), 47 deletions(-) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 8f2d30b0b9..0f884a6e77 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -200,7 +200,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); @@ -426,7 +426,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index f7dba66f53..1a34d057e5 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -404,7 +404,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -441,7 +441,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -554,7 +554,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockTransaction, + AccountRestrictionType.BlockIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -591,7 +591,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockTransaction, + AccountRestrictionType.BlockIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); diff --git a/src/core/utils/DtoMapping.ts b/src/core/utils/DtoMapping.ts index 2babb31068..7670b1815e 100644 --- a/src/core/utils/DtoMapping.ts +++ b/src/core/utils/DtoMapping.ts @@ -34,16 +34,20 @@ export class DtoMapping { new AccountRestrictions(Address.createFromEncoded(accountRestrictions.accountRestrictions.address), accountRestrictions.accountRestrictions.restrictions.map((prop) => { switch (prop.restrictionType) { - case AccountRestrictionType.AllowAddress: - case AccountRestrictionType.BlockAddress: + case AccountRestrictionType.AllowIncomingAddress: + case AccountRestrictionType.BlockIncomingAddress: + case AccountRestrictionType.AllowOutgoingAddress: + case AccountRestrictionType.BlockOutgoingAddress: return new AccountRestriction(prop.restrictionType, prop.values.map((value) => Address.createFromEncoded(value))); case AccountRestrictionType.AllowMosaic: case AccountRestrictionType.BlockMosaic: return new AccountRestriction(prop.restrictionType, prop.values.map((value) => new MosaicId(value))); - case AccountRestrictionType.AllowTransaction: - case AccountRestrictionType.BlockTransaction: + case AccountRestrictionType.AllowIncomingTransactionType: + case AccountRestrictionType.AllowOutgoingTransactionType: + case AccountRestrictionType.BlockIncomingTransactionType: + case AccountRestrictionType.BlockOutgoingTransactionType: return new AccountRestriction(prop.restrictionType, prop.values); default: throw new Error(`Invalid restriction type: ${prop.restrictionType}`); diff --git a/src/model/account/AccountRestrictionType.ts b/src/model/account/AccountRestrictionType.ts index 93b503b5af..757c1fde75 100644 --- a/src/model/account/AccountRestrictionType.ts +++ b/src/model/account/AccountRestrictionType.ts @@ -1,7 +1,7 @@ /* * Copyright 2019 NEM * - * Licensed under the Apache License, Version 2.0 (the "License"); + * 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 * @@ -16,19 +16,82 @@ /** * Account restriction type - * 0x01 The restriction type is an address. - * 0x02 The restriction type is mosaic id. - * 0x03 The restriction type is a transaction type. - * 0x04 restriction type sentinel. - * 0x80 + type The restriction is interpreted as a blocking operation. + * 0x01 Account restriction type is an address. + * 0x02 Account restriction type is a mosaic id. + * 0x04 Account restriction type is a transaction type. + * 0x05 restriction type sentinel. + * 0x40 Account restriction is interpreted as outgoing restriction. + * 0x80 Account restriction is interpreted as blocking operation. */ -export enum AccountRestrictionType { - AllowAddress = 0x01, - AllowMosaic = 0x02, - AllowTransaction = 0x04, + // !!This enum will be deprecated once catbuffer code applied. +enum AccountRestrictionTypeEnum { + Address = 0x01, + Mosaic = 0x02, + TransactionType = 0x04, Sentinel = 0x05, - BlockAddress = (0x80 + 0x01), - BlockMosaic = (0x80 + 0x02), - BlockTransaction = (0x80 + 0x04), + Outgoing = 0x40, + Block = 0x80, +} + +export enum AccountRestrictionType { + /** + * Allow only incoming transactions from a given address. + */ + AllowIncomingAddress = AccountRestrictionTypeEnum.Address, + + /** + * Allow only incoming transactions containing a a given mosaic identifier. + */ + AllowMosaic = AccountRestrictionTypeEnum.Mosaic, + + /** + * Allow only outgoing transactions with a given transaction type. + */ + AllowIncomingTransactionType = AccountRestrictionTypeEnum.TransactionType, + + /** + * Allow only outgoing transactions to a given address. + */ + AllowOutgoingAddress = (AccountRestrictionTypeEnum.Address + AccountRestrictionTypeEnum.Outgoing), + + /** + * Allow only outgoing transactions with a given transaction type. + */ + AllowOutgoingTransactionType = (AccountRestrictionTypeEnum.TransactionType + + AccountRestrictionTypeEnum.Outgoing), + + /** + * Block incoming transactions from a given address. + */ + BlockIncomingAddress = (AccountRestrictionTypeEnum.Address + AccountRestrictionTypeEnum.Block), + + /** + * Block incoming transactions containing a given mosaic identifier. + */ + BlockMosaic = (AccountRestrictionTypeEnum.Mosaic + AccountRestrictionTypeEnum.Block), + + /** + * Block incoming transactions with a given transaction type. + */ + BlockIncomingTransactionType = (AccountRestrictionTypeEnum.TransactionType + + AccountRestrictionTypeEnum.Block), + + /** + * Block outgoing transactions from a given address. + */ + BlockOutgoingAddress = (AccountRestrictionTypeEnum.Address + + AccountRestrictionTypeEnum.Block + + AccountRestrictionTypeEnum.Outgoing), + /** + * Block outgoing transactions with a given transaction type. + */ + BlockOutgoingTransactionType = (AccountRestrictionTypeEnum.TransactionType + + AccountRestrictionTypeEnum.Block + + AccountRestrictionTypeEnum.Outgoing), + + /** + * Account restriction sentinel. + */ + Sentinel = AccountRestrictionTypeEnum.Sentinel, } diff --git a/src/model/transaction/AccountRestrictionTransaction.ts b/src/model/transaction/AccountRestrictionTransaction.ts index 2bb4aceaf4..1ebbbf7849 100644 --- a/src/model/transaction/AccountRestrictionTransaction.ts +++ b/src/model/transaction/AccountRestrictionTransaction.ts @@ -41,7 +41,10 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountAddressRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowAddress, AccountRestrictionType.BlockAddress].includes(restrictionType)) { + if (![AccountRestrictionType.AllowIncomingAddress, + AccountRestrictionType.AllowOutgoingAddress, + AccountRestrictionType.BlockOutgoingAddress, + AccountRestrictionType.BlockIncomingAddress].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountAddressRestrictionModificationTransaction.create( @@ -69,7 +72,7 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountMosaicRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowMosaic, AccountRestrictionType.BlockMosaic].includes(restrictionType)) { + if (![AccountRestrictionType.AllowMosaic,AccountRestrictionType.BlockMosaic].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountMosaicRestrictionModificationTransaction.create( @@ -97,7 +100,10 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountOperationRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowTransaction, AccountRestrictionType.BlockTransaction].includes(restrictionType)) { + if (![AccountRestrictionType.AllowIncomingTransactionType, + AccountRestrictionType.AllowOutgoingTransactionType, + AccountRestrictionType.BlockOutgoingTransactionType, + AccountRestrictionType.BlockOutgoingTransactionType].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountOperationRestrictionModificationTransaction.create( diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index c30b9e5474..b1e9300864 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -79,7 +79,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -89,7 +89,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); }); @@ -125,7 +125,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -134,7 +134,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType); expect(transaction.modifications[0].value).to.be.equal(operation); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -666,7 +666,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -675,7 +675,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(addressRestrictionTransaction.toJSON()) as AccountAddressRestrictionModificationTransaction; expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -708,7 +708,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -717,7 +717,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(operationRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); - expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType); expect(transaction.modifications.length).to.be.equal(1); }); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 933663285b..75f81eff2c 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -83,7 +83,7 @@ describe('SerializeTransactionToJSON', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -91,7 +91,7 @@ describe('SerializeTransactionToJSON', () => { const json = addressRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS); - expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -123,7 +123,7 @@ describe('SerializeTransactionToJSON', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -131,7 +131,7 @@ describe('SerializeTransactionToJSON', () => { const json = operationRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); - expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType); expect(json.transaction.modifications.length).to.be.equal(1); }); diff --git a/test/model/account/AccountRestriction.spec.ts b/test/model/account/AccountRestriction.spec.ts index d41a0e73a6..11defe8b1c 100644 --- a/test/model/account/AccountRestriction.spec.ts +++ b/test/model/account/AccountRestriction.spec.ts @@ -23,7 +23,7 @@ describe('AccountRestriction', () => { it('should createComplete an AccountRestriction object', () => { const accountRestrictionDTO = { - restrictionType: AccountRestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowIncomingAddress, values: ['906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'], }; diff --git a/test/model/account/AccountRestrictions.spec.ts b/test/model/account/AccountRestrictions.spec.ts index 8b30a7451b..0ed43b4f0b 100644 --- a/test/model/account/AccountRestrictions.spec.ts +++ b/test/model/account/AccountRestrictions.spec.ts @@ -25,7 +25,7 @@ describe('AccountRestrictions', () => { const accountRestrictionsDTO = { address: Address.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'), restrictions: [{ - restrictionType: AccountRestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowIncomingAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/account/AccountRestrictionsInfo.spec.ts b/test/model/account/AccountRestrictionsInfo.spec.ts index 981817bcea..f4291f2468 100644 --- a/test/model/account/AccountRestrictionsInfo.spec.ts +++ b/test/model/account/AccountRestrictionsInfo.spec.ts @@ -31,7 +31,7 @@ describe('AccountRestrictionsInfo', () => { accountRestrictions: { address: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', restrictions: [{ - restrictionType: AccountRestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowIncomingAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 8f83e951f3..59ccd31d5d 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -74,7 +74,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -105,7 +105,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -121,7 +121,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -138,7 +138,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -157,7 +157,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -241,7 +241,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); From 89e445b095cb86aa327d963d75cb2c2b7bbff3ef Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 5 Aug 2019 14:41:38 +0100 Subject: [PATCH 03/98] Updated tests --- e2e/infrastructure/TransactionHttp.spec.ts | 161 ++++++++++++++++- .../AccountRestrictionTransaction.spec.ts | 162 +++++++++++++++--- 2 files changed, 299 insertions(+), 24 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 1a34d057e5..2e14e46eb1 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -387,7 +387,83 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Address', () => { + describe('AccountRestrictionTransaction - Outgoing Address', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + + it('standalone', (done) => { + const addressRestrictionFilter = AccountRestrictionModification.createForAddress( + RestrictionModificationType.Add, + account3.address, + ); + const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingAddress, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + const signedTransaction = addressModification.signWith(account, generationHash); + + listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionModificationTransaction) => { + expect(transaction.modifications, 'Modifications').not.to.be.undefined; + expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; + expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; + expect(transaction.restrictionType, 'RestrictionType').not.to.be.undefined; + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + describe('AccountRestrictionTransaction - Outgoing Address', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('aggregate', (done) => { + const addressRestrictionFilter = AccountRestrictionModification.createForAddress( + RestrictionModificationType.Remove, + account3.address, + ); + const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingAddress, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [addressModification.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + listener.confirmed(account.address).subscribe((transaction: Transaction) => { + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + + describe('AccountRestrictionTransaction - Incoming Address', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -425,7 +501,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Address', () => { + describe('AccountRestrictionTransaction - Incoming Address', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -537,7 +613,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Operation', () => { + describe('AccountRestrictionTransaction - Incoming Operation', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -575,7 +651,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Operation', () => { + describe('AccountRestrictionTransaction - Incoming Operation', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -612,6 +688,83 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); + + describe('AccountRestrictionTransaction - Outgoing Operation', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + + it('standalone', (done) => { + const operationRestrictionFilter = AccountRestrictionModification.createForOperation( + RestrictionModificationType.Add, + TransactionType.LINK_ACCOUNT, + ); + const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingTransactionType, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + const signedTransaction = addressModification.signWith(account3, generationHash); + + listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionModificationTransaction) => { + expect(transaction.modifications, 'Modifications').not.to.be.undefined; + expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; + expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; + expect(transaction.restrictionType, 'RestrictionType').not.to.be.undefined; + done(); + }); + listener.status(account3.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + describe('AccountRestrictionTransaction - Outgoing Operation', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('aggregate', (done) => { + const operationRestrictionFilter = AccountRestrictionModification.createForOperation( + RestrictionModificationType.Remove, + TransactionType.LINK_ACCOUNT, + ); + const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingTransactionType, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [addressModification.toAggregate(account3.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = aggregateTransaction.signWith(account3, generationHash); + listener.confirmed(account3.address).subscribe((transaction: Transaction) => { + done(); + }); + listener.status(account3.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + describe('AccountLinkTransaction', () => { let listener: Listener; before (() => { diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 59ccd31d5d..eeb10081ff 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -148,7 +148,7 @@ describe('AccountRestrictionTransaction', () => { expect(addressRestrictionTransaction.maxFee.lower).to.be.equal(1); }); - it('should create address restriction transaction', () => { + it('should create allow incmoing address restriction transaction', () => { const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); const addressRestrictionFilter = AccountRestrictionModification.createForAddress( @@ -179,15 +179,24 @@ describe('AccountRestrictionTransaction', () => { address, ); - expect(() => { - AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( - Deadline.create(), - AccountRestrictionType.Sentinel, - [addressRestrictionFilter], - NetworkType.MIJIN_TEST, - ); - }).to.throw(Error, 'Restriction type is not allowed.'); - + const invalidType = [AccountRestrictionType.AllowIncomingTransactionType, + AccountRestrictionType.AllowMosaic, + AccountRestrictionType.AllowOutgoingTransactionType, + AccountRestrictionType.BlockIncomingTransactionType, + AccountRestrictionType.BlockMosaic, + AccountRestrictionType.BlockOutgoingTransactionType, + AccountRestrictionType.Sentinel, + ]; + invalidType.forEach((type) => { + expect(() => { + AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + type, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'Restriction type is not allowed.'); + }); }); it('should create mosaic restriction transaction', () => { @@ -213,7 +222,7 @@ describe('AccountRestrictionTransaction', () => { }); - it('should throw exception when create mosaic restriction transaction with wrong type', () => { + it('should throw exception when create account mosaic restriction transaction with wrong type', () => { const mosaicId = new MosaicId([2262289484, 3405110546]); const mosaicRestrictionFilter = AccountRestrictionModification.createForMosaic( @@ -221,15 +230,26 @@ describe('AccountRestrictionTransaction', () => { mosaicId, ); - expect(() => { - AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( - Deadline.create(), - AccountRestrictionType.Sentinel, - [mosaicRestrictionFilter], - NetworkType.MIJIN_TEST, - ); - }).to.throw(Error, 'Restriction type is not allowed.'); - + const invalidType = [AccountRestrictionType.AllowIncomingTransactionType, + AccountRestrictionType.AllowIncomingAddress, + AccountRestrictionType.AllowOutgoingTransactionType, + AccountRestrictionType.BlockIncomingTransactionType, + AccountRestrictionType.AllowOutgoingAddress, + AccountRestrictionType.BlockOutgoingTransactionType, + AccountRestrictionType.BlockIncomingAddress, + AccountRestrictionType.BlockOutgoingAddress, + AccountRestrictionType.Sentinel, + ]; + invalidType.forEach((type) => { + expect(() => { + AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( + Deadline.create(), + type, + [mosaicRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'Restriction type is not allowed.'); + }); }); it('should create operation restriction transaction', () => { @@ -254,4 +274,106 @@ describe('AccountRestrictionTransaction', () => { )).to.be.equal('0401004E42'); }); + + it('should throw exception when create account operation restriction transaction with wrong type', () => { + + const operation = TransactionType.ADDRESS_ALIAS; + const operationRestrictionFilter = AccountRestrictionModification.createForOperation( + RestrictionModificationType.Add, + operation, + ); + + const invalidType = [AccountRestrictionType.AllowIncomingAddress, + AccountRestrictionType.AllowMosaic, + AccountRestrictionType.BlockMosaic, + AccountRestrictionType.AllowOutgoingAddress, + AccountRestrictionType.BlockIncomingAddress, + AccountRestrictionType.BlockOutgoingAddress, + AccountRestrictionType.Sentinel, + ]; + invalidType.forEach((type) => { + expect(() => { + AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + type, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'Restriction type is not allowed.'); + }); + }); + + it('should create outgoing address restriction transaction', () => { + + const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const addressRestrictionFilter = AccountRestrictionModification.createForAddress( + RestrictionModificationType.Add, + address, + ); + let addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.AllowOutgoingAddress, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + + let signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('4101009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + + addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingAddress, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + + signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('C101009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + + }); + + it('should create outgoing operation restriction transaction', () => { + + const operation = TransactionType.ADDRESS_ALIAS; + const operationRestrictionFilter = AccountRestrictionModification.createForOperation( + RestrictionModificationType.Add, + operation, + ); + let operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.AllowOutgoingTransactionType, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + + let signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('4401004E42'); + + operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingTransactionType, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + + signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('C401004E42'); + + }); }); From be7f000abfa917cf5c608ae1097f1257bb430022 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 21:43:04 +0100 Subject: [PATCH 04/98] Added ts catbuffer codes (without aggregateTx) Appended new signwithCatbuffer method in Transaction (temp) Applied catbuffer builders on standalone transaction (builder) Updated unit tests --- e2e/infrastructure/TransactionHttp.spec.ts | 12 +- src/infrastructure/QueryParams.ts | 1 - .../AccountRestrictionsAddressTransaction.ts | 2 +- ...ccountRestrictionsEntityTypeTransaction.ts | 2 +- .../AccountRestrictionsMosaicTransaction.ts | 2 +- ...ntAddressRestrictionModificationBuilder.ts | 91 ++++++++ ...ddressRestrictionTransactionBodyBuilder.ts | 114 ++++++++++ ...untAddressRestrictionTransactionBuilder.ts | 116 +++++++++++ .../catbuffer/AccountLinkActionDto.ts | 29 +++ .../AccountLinkTransactionBodyBuilder.ts | 102 +++++++++ .../AccountLinkTransactionBuilder.ts | 113 ++++++++++ .../AccountMetadataTransactionBodyBuilder.ts | 147 +++++++++++++ .../AccountMetadataTransactionBuilder.ts | 139 +++++++++++++ ...untMosaicRestrictionModificationBuilder.ts | 91 ++++++++ ...MosaicRestrictionTransactionBodyBuilder.ts | 114 ++++++++++ ...ountMosaicRestrictionTransactionBuilder.ts | 116 +++++++++++ ...OperationRestrictionModificationBuilder.ts | 91 ++++++++ ...rationRestrictionTransactionBodyBuilder.ts | 114 ++++++++++ ...tOperationRestrictionTransactionBuilder.ts | 116 +++++++++++ ...AccountRestrictionModificationActionDto.ts | 29 +++ .../AccountRestrictionModificationBuilder.ts | 83 ++++++++ .../catbuffer/AccountRestrictionTypeDto.ts | 35 ++++ .../AddressAliasTransactionBodyBuilder.ts | 121 +++++++++++ .../AddressAliasTransactionBuilder.ts | 125 +++++++++++ src/infrastructure/catbuffer/AddressDto.ts | 79 +++++++ .../catbuffer/AliasActionDto.ts | 29 +++ src/infrastructure/catbuffer/AmountDto.ts | 80 ++++++++ .../catbuffer/BlockDurationDto.ts | 80 ++++++++ .../CosignatoryModificationActionDto.ts | 29 +++ .../CosignatoryModificationBuilder.ts | 102 +++++++++ ...untAddressRestrictionTransactionBuilder.ts | 110 ++++++++++ .../EmbeddedAccountLinkTransactionBuilder.ts | 107 ++++++++++ ...beddedAccountMetadataTransactionBuilder.ts | 133 ++++++++++++ ...ountMosaicRestrictionTransactionBuilder.ts | 110 ++++++++++ ...tOperationRestrictionTransactionBuilder.ts | 110 ++++++++++ .../EmbeddedAddressAliasTransactionBuilder.ts | 119 +++++++++++ .../EmbeddedHashLockTransactionBuilder.ts | 119 +++++++++++ ...aicAddressRestrictionTransactionBuilder.ts | 140 +++++++++++++ .../EmbeddedMosaicAliasTransactionBuilder.ts | 119 +++++++++++ ...eddedMosaicDefinitionTransactionBuilder.ts | 141 +++++++++++++ ...saicGlobalRestrictionTransactionBuilder.ts | 160 +++++++++++++++ ...mbeddedMosaicMetadataTransactionBuilder.ts | 144 +++++++++++++ ...dedMosaicSupplyChangeTransactionBuilder.ts | 120 +++++++++++ ...igAccountModificationTransactionBuilder.ts | 119 +++++++++++ ...ddedNamespaceMetadataTransactionBuilder.ts | 145 +++++++++++++ ...NamespaceRegistrationTransactionBuilder.ts | 143 +++++++++++++ .../EmbeddedSecretLockTransactionBuilder.ts | 142 +++++++++++++ .../EmbeddedSecretProofTransactionBuilder.ts | 129 ++++++++++++ .../catbuffer/EmbeddedTransactionBuilder.ts | 127 ++++++++++++ .../EmbeddedTransferTransactionBuilder.ts | 118 +++++++++++ src/infrastructure/catbuffer/EntityTypeDto.ts | 133 ++++++++++++ .../catbuffer/GeneratorUtils.ts | 141 +++++++++++++ src/infrastructure/catbuffer/Hash256Dto.ts | 79 +++++++ src/infrastructure/catbuffer/Hash512Dto.ts | 79 +++++++ .../HashLockTransactionBodyBuilder.ts | 121 +++++++++++ .../catbuffer/HashLockTransactionBuilder.ts | 125 +++++++++++ src/infrastructure/catbuffer/KeyDto.ts | 79 +++++++ .../catbuffer/LockHashAlgorithmDto.ts | 33 +++ ...ddressRestrictionTransactionBodyBuilder.ts | 158 ++++++++++++++ ...aicAddressRestrictionTransactionBuilder.ts | 146 +++++++++++++ .../MosaicAliasTransactionBodyBuilder.ts | 121 +++++++++++ .../MosaicAliasTransactionBuilder.ts | 125 +++++++++++ src/infrastructure/catbuffer/MosaicBuilder.ts | 102 +++++++++ .../MosaicDefinitionTransactionBodyBuilder.ts | 158 ++++++++++++++ .../MosaicDefinitionTransactionBuilder.ts | 147 +++++++++++++ .../catbuffer/MosaicFlagsDto.ts | 33 +++ ...GlobalRestrictionTransactionBodyBuilder.ts | 194 ++++++++++++++++++ ...saicGlobalRestrictionTransactionBuilder.ts | 166 +++++++++++++++ src/infrastructure/catbuffer/MosaicIdDto.ts | 80 ++++++++ .../MosaicMetadataTransactionBodyBuilder.ts | 168 +++++++++++++++ .../MosaicMetadataTransactionBuilder.ts | 150 ++++++++++++++ .../catbuffer/MosaicNonceDto.ts | 80 ++++++++ .../catbuffer/MosaicRestrictionTypeDto.ts | 39 ++++ .../catbuffer/MosaicSupplyChangeActionDto.ts | 29 +++ ...osaicSupplyChangeTransactionBodyBuilder.ts | 121 +++++++++++ .../MosaicSupplyChangeTransactionBuilder.ts | 125 +++++++++++ ...countModificationTransactionBodyBuilder.ts | 131 ++++++++++++ ...igAccountModificationTransactionBuilder.ts | 125 +++++++++++ .../catbuffer/NamespaceIdDto.ts | 80 ++++++++ ...NamespaceMetadataTransactionBodyBuilder.ts | 168 +++++++++++++++ .../NamespaceMetadataTransactionBuilder.ts | 151 ++++++++++++++ ...spaceRegistrationTransactionBodyBuilder.ts | 188 +++++++++++++++++ ...NamespaceRegistrationTransactionBuilder.ts | 149 ++++++++++++++ .../catbuffer/NamespaceRegistrationTypeDto.ts | 29 +++ .../SecretLockTransactionBodyBuilder.ts | 160 +++++++++++++++ .../catbuffer/SecretLockTransactionBuilder.ts | 148 +++++++++++++ .../SecretProofTransactionBodyBuilder.ts | 144 +++++++++++++ .../SecretProofTransactionBuilder.ts | 135 ++++++++++++ src/infrastructure/catbuffer/SignatureDto.ts | 79 +++++++ src/infrastructure/catbuffer/TimestampDto.ts | 80 ++++++++ .../catbuffer/TransactionBuilder.ts | 185 +++++++++++++++++ .../TransferTransactionBodyBuilder.ts | 135 ++++++++++++ .../catbuffer/TransferTransactionBuilder.ts | 124 +++++++++++ .../catbuffer/UnresolvedAddressDto.ts | 79 +++++++ .../catbuffer/UnresolvedMosaicBuilder.ts | 102 +++++++++ .../catbuffer/UnresolvedMosaicIdDto.ts | 80 ++++++++ .../transaction/CreateTransactionFromDTO.ts | 18 +- .../CreateTransactionFromPayload.ts | 24 +-- .../transaction/SerializeTransactionToJSON.ts | 24 +-- src/model/model.ts | 6 +- src/model/mosaic/MosaicFlag.ts | 25 +++ ...> AccountAddressRestrictionTransaction.ts} | 50 ++++- .../transaction/AccountLinkTransaction.ts | 27 +++ ...=> AccountMosaicRestrictionTransaction.ts} | 49 ++++- ...AccountOperationRestrictionTransaction.ts} | 46 ++++- .../AccountRestrictionTransaction.ts | 22 +- .../transaction/AddressAliasTransaction.ts | 30 +++ src/model/transaction/AggregateTransaction.ts | 10 +- src/model/transaction/LockFundsTransaction.ts | 7 + .../ModifyMultisigAccountTransaction.ts | 35 +++- .../MosaicAddressRestrictionTransaction.ts | 7 + .../transaction/MosaicAliasTransaction.ts | 29 +++ .../MosaicDefinitionTransaction.ts | 68 ++++++ .../MosaicGlobalRestrictionTransaction.ts | 7 + .../MosaicSupplyChangeTransaction.ts | 27 +++ .../RegisterNamespaceTransaction.ts | 7 + .../transaction/SecretLockTransaction.ts | 46 ++++- .../transaction/SecretProofTransaction.ts | 50 ++++- src/model/transaction/Transaction.ts | 62 +++++- src/model/transaction/TransactionType.ts | 42 ++-- src/model/transaction/TransactionVersion.ts | 4 +- src/model/transaction/TransferTransaction.ts | 61 +++++- test/core/utils/TransactionMapping.spec.ts | 20 +- .../SerializeTransactionToJSON.spec.ts | 6 +- .../AccountLinkTransaction.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 12 +- .../AddressAliasTransaction.spec.ts | 2 +- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- .../MosaicAliasTransaction.spec.ts | 4 +- .../MosaicDefinitionTransaction.spec.ts | 4 +- .../MultisigCosignatoryModification.spec.ts | 1 - .../transaction/SecretLockTransaction.spec.ts | 31 ++- .../SecretProofTransaction.spec.ts | 22 +- test/model/transaction/Transaction.spec.ts | 4 + .../transaction/TransferTransaction.spec.ts | 28 ++- 135 files changed, 11044 insertions(+), 140 deletions(-) create mode 100644 src/infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountLinkActionDto.ts create mode 100644 src/infrastructure/catbuffer/AccountLinkTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountLinkTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMetadataTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountRestrictionModificationActionDto.ts create mode 100644 src/infrastructure/catbuffer/AccountRestrictionModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountRestrictionTypeDto.ts create mode 100644 src/infrastructure/catbuffer/AddressAliasTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AddressAliasTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AddressDto.ts create mode 100644 src/infrastructure/catbuffer/AliasActionDto.ts create mode 100644 src/infrastructure/catbuffer/AmountDto.ts create mode 100644 src/infrastructure/catbuffer/BlockDurationDto.ts create mode 100644 src/infrastructure/catbuffer/CosignatoryModificationActionDto.ts create mode 100644 src/infrastructure/catbuffer/CosignatoryModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedTransferTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EntityTypeDto.ts create mode 100644 src/infrastructure/catbuffer/GeneratorUtils.ts create mode 100644 src/infrastructure/catbuffer/Hash256Dto.ts create mode 100644 src/infrastructure/catbuffer/Hash512Dto.ts create mode 100644 src/infrastructure/catbuffer/HashLockTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/HashLockTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/KeyDto.ts create mode 100644 src/infrastructure/catbuffer/LockHashAlgorithmDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicAliasTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicAliasTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicDefinitionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicDefinitionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicFlagsDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicIdDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicMetadataTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicNonceDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicRestrictionTypeDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicSupplyChangeActionDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MultisigAccountModificationTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceIdDto.ts create mode 100644 src/infrastructure/catbuffer/NamespaceMetadataTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceRegistrationTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceRegistrationTypeDto.ts create mode 100644 src/infrastructure/catbuffer/SecretLockTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/SecretLockTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/SecretProofTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/SecretProofTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/SignatureDto.ts create mode 100644 src/infrastructure/catbuffer/TimestampDto.ts create mode 100644 src/infrastructure/catbuffer/TransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/TransferTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/TransferTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/UnresolvedAddressDto.ts create mode 100644 src/infrastructure/catbuffer/UnresolvedMosaicBuilder.ts create mode 100644 src/infrastructure/catbuffer/UnresolvedMosaicIdDto.ts create mode 100644 src/model/mosaic/MosaicFlag.ts rename src/model/transaction/{AccountAddressRestrictionModificationTransaction.ts => AccountAddressRestrictionTransaction.ts} (64%) rename src/model/transaction/{AccountMosaicRestrictionModificationTransaction.ts => AccountMosaicRestrictionTransaction.ts} (65%) rename src/model/transaction/{AccountOperationRestrictionModificationTransaction.ts => AccountOperationRestrictionTransaction.ts} (67%) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 2f60993e0c..df7e919b07 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -37,10 +37,10 @@ import {MosaicSupplyType} from '../../src/model/mosaic/MosaicSupplyType'; import {NetworkCurrencyMosaic} from '../../src/model/mosaic/NetworkCurrencyMosaic'; import { AliasActionType } from '../../src/model/namespace/AliasActionType'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; -import { AccountAddressRestrictionModificationTransaction } from '../../src/model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from '../../src/model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../src/model/transaction/AccountLinkTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from '../../src/model/transaction/AccountMosaicRestrictionModificationTransaction'; -import { AccountOperationRestrictionModificationTransaction } from '../../src/model/transaction/AccountOperationRestrictionModificationTransaction'; +import { AccountMosaicRestrictionTransaction } from '../../src/model/transaction/AccountMosaicRestrictionTransaction'; +import { AccountOperationRestrictionTransaction } from '../../src/model/transaction/AccountOperationRestrictionTransaction'; import { AccountRestrictionModification } from '../../src/model/transaction/AccountRestrictionModification'; import { AccountRestrictionTransaction } from '../../src/model/transaction/AccountRestrictionTransaction'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; @@ -410,7 +410,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = addressModification.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionModificationTransaction) => { + listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionTransaction) => { expect(transaction.modifications, 'Modifications').not.to.be.undefined; expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; @@ -485,7 +485,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = addressModification.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AccountMosaicRestrictionModificationTransaction) => { + listener.confirmed(account.address).subscribe((transaction: AccountMosaicRestrictionTransaction) => { expect(transaction.modifications, 'Modifications').not.to.be.undefined; expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; @@ -560,7 +560,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = addressModification.signWith(account3, generationHash); - listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionModificationTransaction) => { + listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionTransaction) => { expect(transaction.modifications, 'Modifications').not.to.be.undefined; expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; diff --git a/src/infrastructure/QueryParams.ts b/src/infrastructure/QueryParams.ts index b1644cf2b3..ee41206d80 100644 --- a/src/infrastructure/QueryParams.ts +++ b/src/infrastructure/QueryParams.ts @@ -22,7 +22,6 @@ export enum Order { DESC = '-id', } - /** * The query params structure describes pagination params for requests. * diff --git a/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts b/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts index 452e4c30b7..bd355c6b94 100644 --- a/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts +++ b/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts @@ -45,7 +45,7 @@ export class Builder { modifications: any; constructor() { this.maxFee = [0, 0]; - this.type = TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS; + this.type = TransactionType.ACCOUNT_RESTRICTION_ADDRESS; } addFee(maxFee) { diff --git a/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts b/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts index edfed292ba..6973e8ccc4 100644 --- a/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts +++ b/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts @@ -45,7 +45,7 @@ export class Builder { modifications: any; constructor() { this.maxFee = [0, 0]; - this.type = TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION; + this.type = TransactionType.ACCOUNT_RESTRICTION_OPERATION; } addFee(maxFee) { diff --git a/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts b/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts index ec97bcc02e..da9338deb4 100644 --- a/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts +++ b/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts @@ -45,7 +45,7 @@ export class Builder { modifications: any; constructor() { this.maxFee = [0, 0]; - this.type = TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC; + this.type = TransactionType.ACCOUNT_RESTRICTION_MOSAIC; } addFee(maxFee) { diff --git a/src/infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder.ts b/src/infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder.ts new file mode 100644 index 0000000000..b8c508eb76 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder.ts @@ -0,0 +1,91 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountRestrictionModificationActionDto } from './AccountRestrictionModificationActionDto'; +import { AccountRestrictionModificationBuilder } from './AccountRestrictionModificationBuilder'; +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; + +/** Account address restriction modification. */ +export class AccountAddressRestrictionModificationBuilder extends AccountRestrictionModificationBuilder { + /** Address restriction value. */ + value: UnresolvedAddressDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + * @param value Address restriction value. + */ + public constructor(modificationAction: AccountRestrictionModificationActionDto, value: UnresolvedAddressDto) { + super(modificationAction); + this.value = value; + } + + /** + * Creates an instance of AccountAddressRestrictionModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountAddressRestrictionModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountAddressRestrictionModificationBuilder { + const byteArray = Array.from(payload); + const superObject = AccountRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const value = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, value.getSize()); + return new AccountAddressRestrictionModificationBuilder(superObject.modificationAction, value); + } + + /** + * Gets address restriction value. + * + * @return Address restriction value. + */ + public getValue(): UnresolvedAddressDto { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.value.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const valueBytes = this.value.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..fcc36e1509 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,114 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountAddressRestrictionModificationBuilder } from './AccountAddressRestrictionModificationBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for an account address restriction transaction. */ +export class AccountAddressRestrictionTransactionBodyBuilder { + /** Account restriction type. */ + restrictionType: AccountRestrictionTypeDto; + /** Account restriction modifications. */ + modifications: AccountAddressRestrictionModificationBuilder[]; + + /** + * Constructor. + * + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(restrictionType: AccountRestrictionTypeDto, modifications: AccountAddressRestrictionModificationBuilder[]) { + this.restrictionType = restrictionType; + this.modifications = modifications; + } + + /** + * Creates an instance of AccountAddressRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountAddressRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountAddressRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const restrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modificationsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modifications: AccountAddressRestrictionModificationBuilder[] = []; + for (let i = 0; i < modificationsCount; i++) { + const item = AccountAddressRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + modifications.push(item); + byteArray.splice(0, item.getSize()); + } + return new AccountAddressRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.restrictionType; + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountAddressRestrictionModificationBuilder[] { + return this.modifications; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // restrictionType + size += 1; // modificationsCount + this.modifications.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const restrictionTypeBytes = GeneratorUtils.uintToBuffer(this.restrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionTypeBytes); + const modificationsCountBytes = GeneratorUtils.uintToBuffer(this.modifications.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsCountBytes); + this.modifications.forEach((item) => { + const modificationsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..a20f98b7c6 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder.ts @@ -0,0 +1,116 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountAddressRestrictionModificationBuilder } from './AccountAddressRestrictionModificationBuilder'; +import { AccountAddressRestrictionTransactionBodyBuilder } from './AccountAddressRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account address restriction transaction. */ +export class AccountAddressRestrictionTransactionBuilder extends TransactionBuilder { + /** Account address restriction transaction body. */ + accountAddressRestrictionTransactionBody: AccountAddressRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountAddressRestrictionModificationBuilder[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.accountAddressRestrictionTransactionBody = new AccountAddressRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of AccountAddressRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountAddressRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountAddressRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountAddressRestrictionTransactionBody = AccountAddressRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountAddressRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountAddressRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountAddressRestrictionTransactionBody.restrictionType, accountAddressRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountAddressRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountAddressRestrictionModificationBuilder[] { + return this.accountAddressRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountAddressRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountAddressRestrictionTransactionBodyBytes = this.accountAddressRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountAddressRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountLinkActionDto.ts b/src/infrastructure/catbuffer/AccountLinkActionDto.ts new file mode 100644 index 0000000000..196ab88465 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountLinkActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of account link actions. */ +export enum AccountLinkActionDto { + /** Unlink account. */ + UNLINK = 0, + /** Link account. */ + LINK = 1, +} diff --git a/src/infrastructure/catbuffer/AccountLinkTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountLinkTransactionBodyBuilder.ts new file mode 100644 index 0000000000..bddb0b8579 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountLinkTransactionBodyBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountLinkActionDto } from './AccountLinkActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an account link transaction. */ +export class AccountLinkTransactionBodyBuilder { + /** Remote account public key. */ + remoteAccountPublicKey: KeyDto; + /** Account link action. */ + linkAction: AccountLinkActionDto; + + /** + * Constructor. + * + * @param remoteAccountPublicKey Remote account public key. + * @param linkAction Account link action. + */ + public constructor(remoteAccountPublicKey: KeyDto, linkAction: AccountLinkActionDto) { + this.remoteAccountPublicKey = remoteAccountPublicKey; + this.linkAction = linkAction; + } + + /** + * Creates an instance of AccountLinkTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountLinkTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountLinkTransactionBodyBuilder { + const byteArray = Array.from(payload); + const remoteAccountPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, remoteAccountPublicKey.getSize()); + const linkAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + return new AccountLinkTransactionBodyBuilder(remoteAccountPublicKey, linkAction); + } + + /** + * Gets remote account public key. + * + * @return Remote account public key. + */ + public getRemoteAccountPublicKey(): KeyDto { + return this.remoteAccountPublicKey; + } + + /** + * Gets account link action. + * + * @return Account link action. + */ + public getLinkAction(): AccountLinkActionDto { + return this.linkAction; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.remoteAccountPublicKey.getSize(); + size += 1; // linkAction + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const remoteAccountPublicKeyBytes = this.remoteAccountPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, remoteAccountPublicKeyBytes); + const linkActionBytes = GeneratorUtils.uintToBuffer(this.linkAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, linkActionBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountLinkTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountLinkTransactionBuilder.ts new file mode 100644 index 0000000000..13aecd9155 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountLinkTransactionBuilder.ts @@ -0,0 +1,113 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountLinkActionDto } from './AccountLinkActionDto'; +import { AccountLinkTransactionBodyBuilder } from './AccountLinkTransactionBodyBuilder'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account link transaction. */ +export class AccountLinkTransactionBuilder extends TransactionBuilder { + /** Account link transaction body. */ + accountLinkTransactionBody: AccountLinkTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param remoteAccountPublicKey Remote account public key. + * @param linkAction Account link action. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, remoteAccountPublicKey: KeyDto, linkAction: AccountLinkActionDto) { + super(signature, signer, version, type, fee, deadline); + this.accountLinkTransactionBody = new AccountLinkTransactionBodyBuilder(remoteAccountPublicKey, linkAction); + } + + /** + * Creates an instance of AccountLinkTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountLinkTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountLinkTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const accountLinkTransactionBody = AccountLinkTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountLinkTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountLinkTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountLinkTransactionBody.remoteAccountPublicKey, accountLinkTransactionBody.linkAction); + } + + /** + * Gets remote account public key. + * + * @return Remote account public key. + */ + public getRemoteAccountPublicKey(): KeyDto { + return this.accountLinkTransactionBody.getRemoteAccountPublicKey(); + } + + /** + * Gets account link action. + * + * @return Account link action. + */ + public getLinkAction(): AccountLinkActionDto { + return this.accountLinkTransactionBody.getLinkAction(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountLinkTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountLinkTransactionBodyBytes = this.accountLinkTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountLinkTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMetadataTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountMetadataTransactionBodyBuilder.ts new file mode 100644 index 0000000000..32353f22c9 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMetadataTransactionBodyBuilder.ts @@ -0,0 +1,147 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an account metadata transaction. */ +export class AccountMetadataTransactionBodyBuilder { + /** Metadata target public key. */ + targetPublicKey: KeyDto; + /** Metadata key scoped to source, target and type. */ + scopedMetadataKey: number[]; + /** Change in value size in bytes. */ + valueSizeDelta: number; + /** Difference between existing value and new value \note when there is no existing value, new value is same this value \note when there is an existing value, new value is calculated as xor(previous-value, value). */ + value: Uint8Array; + + /** + * Constructor. + * + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public constructor(targetPublicKey: KeyDto, scopedMetadataKey: number[], valueSizeDelta: number, value: Uint8Array) { + this.targetPublicKey = targetPublicKey; + this.scopedMetadataKey = scopedMetadataKey; + this.valueSizeDelta = valueSizeDelta; + this.value = value; + } + + /** + * Creates an instance of AccountMetadataTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMetadataTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMetadataTransactionBodyBuilder { + const byteArray = Array.from(payload); + const targetPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetPublicKey.getSize()); + const scopedMetadataKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const valueSizeDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const valueSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const value = GeneratorUtils.getBytes(Uint8Array.from(byteArray), valueSize); + byteArray.splice(0, valueSize); + return new AccountMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, valueSizeDelta, value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.targetPublicKey; + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.scopedMetadataKey; + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.valueSizeDelta; + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.targetPublicKey.getSize(); + size += 8; // scopedMetadataKey + size += 2; // valueSizeDelta + size += 2; // valueSize + size += this.value.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const targetPublicKeyBytes = this.targetPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetPublicKeyBytes); + const scopedMetadataKeyBytes = GeneratorUtils.uint64ToBuffer(this.getScopedMetadataKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, scopedMetadataKeyBytes); + const valueSizeDeltaBytes = GeneratorUtils.uintToBuffer(this.getValueSizeDelta(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeDeltaBytes); + const valueSizeBytes = GeneratorUtils.uintToBuffer(this.value.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.value); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..84daaea40a --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMetadataTransactionBuilder.ts @@ -0,0 +1,139 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMetadataTransactionBodyBuilder } from './AccountMetadataTransactionBodyBuilder'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account metadata transaction. */ +export class AccountMetadataTransactionBuilder extends TransactionBuilder { + /** Account metadata transaction body. */ + accountMetadataTransactionBody: AccountMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], valueSizeDelta: number, value: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.accountMetadataTransactionBody = new AccountMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, valueSizeDelta, value); + } + + /** + * Creates an instance of AccountMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const accountMetadataTransactionBody = AccountMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountMetadataTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountMetadataTransactionBody.targetPublicKey, accountMetadataTransactionBody.scopedMetadataKey, accountMetadataTransactionBody.valueSizeDelta, accountMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.accountMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.accountMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.accountMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.accountMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountMetadataTransactionBodyBytes = this.accountMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder.ts b/src/infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder.ts new file mode 100644 index 0000000000..29abdc38c8 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder.ts @@ -0,0 +1,91 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountRestrictionModificationActionDto } from './AccountRestrictionModificationActionDto'; +import { AccountRestrictionModificationBuilder } from './AccountRestrictionModificationBuilder'; +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Account mosaic restriction modification. */ +export class AccountMosaicRestrictionModificationBuilder extends AccountRestrictionModificationBuilder { + /** Mosaic identifier restriction value. */ + value: UnresolvedMosaicIdDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + * @param value Mosaic identifier restriction value. + */ + public constructor(modificationAction: AccountRestrictionModificationActionDto, value: UnresolvedMosaicIdDto) { + super(modificationAction); + this.value = value; + } + + /** + * Creates an instance of AccountMosaicRestrictionModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMosaicRestrictionModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMosaicRestrictionModificationBuilder { + const byteArray = Array.from(payload); + const superObject = AccountRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const value = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, value.getSize()); + return new AccountMosaicRestrictionModificationBuilder(superObject.modificationAction, value); + } + + /** + * Gets mosaic identifier restriction value. + * + * @return Mosaic identifier restriction value. + */ + public getValue(): UnresolvedMosaicIdDto { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.value.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const valueBytes = this.value.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..c094bdc1c2 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,114 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMosaicRestrictionModificationBuilder } from './AccountMosaicRestrictionModificationBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for an account mosaic restriction transaction. */ +export class AccountMosaicRestrictionTransactionBodyBuilder { + /** Account restriction type. */ + restrictionType: AccountRestrictionTypeDto; + /** Account restriction modifications. */ + modifications: AccountMosaicRestrictionModificationBuilder[]; + + /** + * Constructor. + * + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(restrictionType: AccountRestrictionTypeDto, modifications: AccountMosaicRestrictionModificationBuilder[]) { + this.restrictionType = restrictionType; + this.modifications = modifications; + } + + /** + * Creates an instance of AccountMosaicRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMosaicRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMosaicRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const restrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modificationsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modifications: AccountMosaicRestrictionModificationBuilder[] = []; + for (let i = 0; i < modificationsCount; i++) { + const item = AccountMosaicRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + modifications.push(item); + byteArray.splice(0, item.getSize()); + } + return new AccountMosaicRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.restrictionType; + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountMosaicRestrictionModificationBuilder[] { + return this.modifications; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // restrictionType + size += 1; // modificationsCount + this.modifications.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const restrictionTypeBytes = GeneratorUtils.uintToBuffer(this.restrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionTypeBytes); + const modificationsCountBytes = GeneratorUtils.uintToBuffer(this.modifications.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsCountBytes); + this.modifications.forEach((item) => { + const modificationsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..8b2f79a57e --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder.ts @@ -0,0 +1,116 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMosaicRestrictionModificationBuilder } from './AccountMosaicRestrictionModificationBuilder'; +import { AccountMosaicRestrictionTransactionBodyBuilder } from './AccountMosaicRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account mosaic restriction transaction. */ +export class AccountMosaicRestrictionTransactionBuilder extends TransactionBuilder { + /** Account mosaic restriction transaction body. */ + accountMosaicRestrictionTransactionBody: AccountMosaicRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountMosaicRestrictionModificationBuilder[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.accountMosaicRestrictionTransactionBody = new AccountMosaicRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of AccountMosaicRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMosaicRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMosaicRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountMosaicRestrictionTransactionBody = AccountMosaicRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountMosaicRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountMosaicRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountMosaicRestrictionTransactionBody.restrictionType, accountMosaicRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountMosaicRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountMosaicRestrictionModificationBuilder[] { + return this.accountMosaicRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountMosaicRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountMosaicRestrictionTransactionBodyBytes = this.accountMosaicRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountMosaicRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder.ts b/src/infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder.ts new file mode 100644 index 0000000000..669bfc4dce --- /dev/null +++ b/src/infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder.ts @@ -0,0 +1,91 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountRestrictionModificationActionDto } from './AccountRestrictionModificationActionDto'; +import { AccountRestrictionModificationBuilder } from './AccountRestrictionModificationBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Account operation restriction modification. */ +export class AccountOperationRestrictionModificationBuilder extends AccountRestrictionModificationBuilder { + /** Transaction type restriction value. */ + value: EntityTypeDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + * @param value Transaction type restriction value. + */ + public constructor(modificationAction: AccountRestrictionModificationActionDto, value: EntityTypeDto) { + super(modificationAction); + this.value = value; + } + + /** + * Creates an instance of AccountOperationRestrictionModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountOperationRestrictionModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountOperationRestrictionModificationBuilder { + const byteArray = Array.from(payload); + const superObject = AccountRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const value = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + return new AccountOperationRestrictionModificationBuilder(superObject.modificationAction, value); + } + + /** + * Gets transaction type restriction value. + * + * @return Transaction type restriction value. + */ + public getValue(): EntityTypeDto { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += 2; // value + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const valueBytes = GeneratorUtils.uintToBuffer(this.value, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..dd505b0b5f --- /dev/null +++ b/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,114 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountOperationRestrictionModificationBuilder } from './AccountOperationRestrictionModificationBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for an account operation restriction transaction. */ +export class AccountOperationRestrictionTransactionBodyBuilder { + /** Account restriction type. */ + restrictionType: AccountRestrictionTypeDto; + /** Account restriction modifications. */ + modifications: AccountOperationRestrictionModificationBuilder[]; + + /** + * Constructor. + * + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(restrictionType: AccountRestrictionTypeDto, modifications: AccountOperationRestrictionModificationBuilder[]) { + this.restrictionType = restrictionType; + this.modifications = modifications; + } + + /** + * Creates an instance of AccountOperationRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountOperationRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountOperationRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const restrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modificationsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modifications: AccountOperationRestrictionModificationBuilder[] = []; + for (let i = 0; i < modificationsCount; i++) { + const item = AccountOperationRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + modifications.push(item); + byteArray.splice(0, item.getSize()); + } + return new AccountOperationRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.restrictionType; + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountOperationRestrictionModificationBuilder[] { + return this.modifications; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // restrictionType + size += 1; // modificationsCount + this.modifications.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const restrictionTypeBytes = GeneratorUtils.uintToBuffer(this.restrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionTypeBytes); + const modificationsCountBytes = GeneratorUtils.uintToBuffer(this.modifications.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsCountBytes); + this.modifications.forEach((item) => { + const modificationsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..2f5795b732 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder.ts @@ -0,0 +1,116 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountOperationRestrictionModificationBuilder } from './AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBodyBuilder } from './AccountOperationRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account operation restriction transaction. */ +export class AccountOperationRestrictionTransactionBuilder extends TransactionBuilder { + /** Account operation restriction transaction body. */ + accountOperationRestrictionTransactionBody: AccountOperationRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountOperationRestrictionModificationBuilder[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.accountOperationRestrictionTransactionBody = new AccountOperationRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of AccountOperationRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountOperationRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountOperationRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountOperationRestrictionTransactionBody = AccountOperationRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountOperationRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountOperationRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountOperationRestrictionTransactionBody.restrictionType, accountOperationRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountOperationRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountOperationRestrictionModificationBuilder[] { + return this.accountOperationRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountOperationRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountOperationRestrictionTransactionBodyBytes = this.accountOperationRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountOperationRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountRestrictionModificationActionDto.ts b/src/infrastructure/catbuffer/AccountRestrictionModificationActionDto.ts new file mode 100644 index 0000000000..84da076601 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountRestrictionModificationActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of account restriction modification actions. */ +export enum AccountRestrictionModificationActionDto { + /** Remove account restriction value. */ + DEL = 0, + /** Add account restriction value. */ + ADD = 1, +} diff --git a/src/infrastructure/catbuffer/AccountRestrictionModificationBuilder.ts b/src/infrastructure/catbuffer/AccountRestrictionModificationBuilder.ts new file mode 100644 index 0000000000..286901d4c9 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountRestrictionModificationBuilder.ts @@ -0,0 +1,83 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountRestrictionModificationActionDto } from './AccountRestrictionModificationActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Account restriction basic modification. */ +export class AccountRestrictionModificationBuilder { + /** Modification action. */ + modificationAction: AccountRestrictionModificationActionDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + */ + public constructor(modificationAction: AccountRestrictionModificationActionDto) { + this.modificationAction = modificationAction; + } + + /** + * Creates an instance of AccountRestrictionModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountRestrictionModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountRestrictionModificationBuilder { + const byteArray = Array.from(payload); + const modificationAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + return new AccountRestrictionModificationBuilder(modificationAction); + } + + /** + * Gets modification action. + * + * @return Modification action. + */ + public getModificationAction(): AccountRestrictionModificationActionDto { + return this.modificationAction; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // modificationAction + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const modificationActionBytes = GeneratorUtils.uintToBuffer(this.modificationAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationActionBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountRestrictionTypeDto.ts b/src/infrastructure/catbuffer/AccountRestrictionTypeDto.ts new file mode 100644 index 0000000000..2d9cc2d061 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountRestrictionTypeDto.ts @@ -0,0 +1,35 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of account restriction types. */ +export enum AccountRestrictionTypeDto { + /** Restriction type is an address. */ + ADDRESS = 1, + /** Restriction type is a mosaic identifier. */ + MOSAIC_ID = 2, + /** Restriction type is a transaction type. */ + TRANSACTION_TYPE = 4, + /** Restriction is interpreted as outgoing. */ + OUTGOING = 64, + /** Restriction is interpreted as blocking operation. */ + BLOCK = 128, +} diff --git a/src/infrastructure/catbuffer/AddressAliasTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AddressAliasTransactionBodyBuilder.ts new file mode 100644 index 0000000000..0cdb182cc0 --- /dev/null +++ b/src/infrastructure/catbuffer/AddressAliasTransactionBodyBuilder.ts @@ -0,0 +1,121 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AddressDto } from './AddressDto'; +import { AliasActionDto } from './AliasActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for an address alias transaction. */ +export class AddressAliasTransactionBodyBuilder { + /** Alias action. */ + aliasAction: AliasActionDto; + /** Identifier of the namespace that will become an alias. */ + namespaceId: NamespaceIdDto; + /** Aliased address. */ + address: AddressDto; + + /** + * Constructor. + * + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param address Aliased address. + */ + public constructor(aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, address: AddressDto) { + this.aliasAction = aliasAction; + this.namespaceId = namespaceId; + this.address = address; + } + + /** + * Creates an instance of AddressAliasTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AddressAliasTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AddressAliasTransactionBodyBuilder { + const byteArray = Array.from(payload); + const aliasAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const namespaceId = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceId.getSize()); + const address = AddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, address.getSize()); + return new AddressAliasTransactionBodyBuilder(aliasAction, namespaceId, address); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.aliasAction; + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.namespaceId; + } + + /** + * Gets aliased address. + * + * @return Aliased address. + */ + public getAddress(): AddressDto { + return this.address; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // aliasAction + size += this.namespaceId.getSize(); + size += this.address.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const aliasActionBytes = GeneratorUtils.uintToBuffer(this.aliasAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, aliasActionBytes); + const namespaceIdBytes = this.namespaceId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceIdBytes); + const addressBytes = this.address.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, addressBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AddressAliasTransactionBuilder.ts b/src/infrastructure/catbuffer/AddressAliasTransactionBuilder.ts new file mode 100644 index 0000000000..a1b64702cc --- /dev/null +++ b/src/infrastructure/catbuffer/AddressAliasTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; +import { AddressDto } from './AddressDto'; +import { AliasActionDto } from './AliasActionDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded address alias transaction. */ +export class AddressAliasTransactionBuilder extends TransactionBuilder { + /** Address alias transaction body. */ + addressAliasTransactionBody: AddressAliasTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param address Aliased address. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, address: AddressDto) { + super(signature, signer, version, type, fee, deadline); + this.addressAliasTransactionBody = new AddressAliasTransactionBodyBuilder(aliasAction, namespaceId, address); + } + + /** + * Creates an instance of AddressAliasTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AddressAliasTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AddressAliasTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const addressAliasTransactionBody = AddressAliasTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, addressAliasTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AddressAliasTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, addressAliasTransactionBody.aliasAction, addressAliasTransactionBody.namespaceId, addressAliasTransactionBody.address); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.addressAliasTransactionBody.getAliasAction(); + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.addressAliasTransactionBody.getNamespaceId(); + } + + /** + * Gets aliased address. + * + * @return Aliased address. + */ + public getAddress(): AddressDto { + return this.addressAliasTransactionBody.getAddress(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.addressAliasTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const addressAliasTransactionBodyBytes = this.addressAliasTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, addressAliasTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AddressDto.ts b/src/infrastructure/catbuffer/AddressDto.ts new file mode 100644 index 0000000000..16214f53dc --- /dev/null +++ b/src/infrastructure/catbuffer/AddressDto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Address. */ +export class AddressDto { + /** Address. */ + address: Uint8Array; + + /** + * Constructor. + * + * @param address Address. + */ + constructor(address: Uint8Array) { + this.address = address; + } + + /** + * Creates an instance of AddressDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AddressDto. + */ + public static loadFromBinary(payload: Uint8Array): AddressDto { + const byteArray = Array.from(payload); + const address = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 25); + byteArray.splice(0, 25); + return new AddressDto(address); + } + + /** + * Gets Address. + * + * @return Address. + */ + public getAddress(): Uint8Array { + return this.address; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 25; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.address); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AliasActionDto.ts b/src/infrastructure/catbuffer/AliasActionDto.ts new file mode 100644 index 0000000000..58cd769ca8 --- /dev/null +++ b/src/infrastructure/catbuffer/AliasActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of alias actions. */ +export enum AliasActionDto { + /** Unlink alias. */ + UNLINK = 0, + /** Link alias. */ + LINK = 1, +} diff --git a/src/infrastructure/catbuffer/AmountDto.ts b/src/infrastructure/catbuffer/AmountDto.ts new file mode 100644 index 0000000000..b1e3c31731 --- /dev/null +++ b/src/infrastructure/catbuffer/AmountDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Amount. */ +export class AmountDto { + /** Amount. */ + amount: number[]; + + /** + * Constructor. + * + * @param amount Amount. + */ + constructor(amount: number[]) { + this.amount = amount; + } + + /** + * Creates an instance of AmountDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AmountDto. + */ + public static loadFromBinary(payload: Uint8Array): AmountDto { + const byteArray = Array.from(payload); + const amount = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new AmountDto(amount); + } + + /** + * Gets Amount. + * + * @return Amount. + */ + public getAmount(): number[] { + return this.amount; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const amountBytes = GeneratorUtils.uint64ToBuffer(this.getAmount()); + newArray = GeneratorUtils.concatTypedArrays(newArray, amountBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/BlockDurationDto.ts b/src/infrastructure/catbuffer/BlockDurationDto.ts new file mode 100644 index 0000000000..dfc232ebdc --- /dev/null +++ b/src/infrastructure/catbuffer/BlockDurationDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Block duration. */ +export class BlockDurationDto { + /** Block duration. */ + blockDuration: number[]; + + /** + * Constructor. + * + * @param blockDuration Block duration. + */ + constructor(blockDuration: number[]) { + this.blockDuration = blockDuration; + } + + /** + * Creates an instance of BlockDurationDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of BlockDurationDto. + */ + public static loadFromBinary(payload: Uint8Array): BlockDurationDto { + const byteArray = Array.from(payload); + const blockDuration = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new BlockDurationDto(blockDuration); + } + + /** + * Gets Block duration. + * + * @return Block duration. + */ + public getBlockDuration(): number[] { + return this.blockDuration; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const blockDurationBytes = GeneratorUtils.uint64ToBuffer(this.getBlockDuration()); + newArray = GeneratorUtils.concatTypedArrays(newArray, blockDurationBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/CosignatoryModificationActionDto.ts b/src/infrastructure/catbuffer/CosignatoryModificationActionDto.ts new file mode 100644 index 0000000000..c428422d9a --- /dev/null +++ b/src/infrastructure/catbuffer/CosignatoryModificationActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of cosignatory modification actions. */ +export enum CosignatoryModificationActionDto { + /** Remove cosignatory. */ + DEL = 0, + /** Add cosignatory. */ + ADD = 1, +} diff --git a/src/infrastructure/catbuffer/CosignatoryModificationBuilder.ts b/src/infrastructure/catbuffer/CosignatoryModificationBuilder.ts new file mode 100644 index 0000000000..8413b779db --- /dev/null +++ b/src/infrastructure/catbuffer/CosignatoryModificationBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { CosignatoryModificationActionDto } from './CosignatoryModificationActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for a cosignatory modification. */ +export class CosignatoryModificationBuilder { + /** Modification action. */ + modificationAction: CosignatoryModificationActionDto; + /** Cosignatory account public key. */ + cosignatoryPublicKey: KeyDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + * @param cosignatoryPublicKey Cosignatory account public key. + */ + public constructor(modificationAction: CosignatoryModificationActionDto, cosignatoryPublicKey: KeyDto) { + this.modificationAction = modificationAction; + this.cosignatoryPublicKey = cosignatoryPublicKey; + } + + /** + * Creates an instance of CosignatoryModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of CosignatoryModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): CosignatoryModificationBuilder { + const byteArray = Array.from(payload); + const modificationAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const cosignatoryPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, cosignatoryPublicKey.getSize()); + return new CosignatoryModificationBuilder(modificationAction, cosignatoryPublicKey); + } + + /** + * Gets modification action. + * + * @return Modification action. + */ + public getModificationAction(): CosignatoryModificationActionDto { + return this.modificationAction; + } + + /** + * Gets cosignatory account public key. + * + * @return Cosignatory account public key. + */ + public getCosignatoryPublicKey(): KeyDto { + return this.cosignatoryPublicKey; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // modificationAction + size += this.cosignatoryPublicKey.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const modificationActionBytes = GeneratorUtils.uintToBuffer(this.modificationAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationActionBytes); + const cosignatoryPublicKeyBytes = this.cosignatoryPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, cosignatoryPublicKeyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..af18bf390d --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder.ts @@ -0,0 +1,110 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountAddressRestrictionModificationBuilder } from './AccountAddressRestrictionModificationBuilder'; +import { AccountAddressRestrictionTransactionBodyBuilder } from './AccountAddressRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account address restriction transaction. */ +export class EmbeddedAccountAddressRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account address restriction transaction body. */ + accountAddressRestrictionTransactionBody: AccountAddressRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountAddressRestrictionModificationBuilder[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.accountAddressRestrictionTransactionBody = new AccountAddressRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of EmbeddedAccountAddressRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountAddressRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountAddressRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountAddressRestrictionTransactionBody = AccountAddressRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountAddressRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountAddressRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountAddressRestrictionTransactionBody.restrictionType, accountAddressRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountAddressRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountAddressRestrictionModificationBuilder[] { + return this.accountAddressRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountAddressRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountAddressRestrictionTransactionBodyBytes = this.accountAddressRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountAddressRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder.ts new file mode 100644 index 0000000000..c2219f36bb --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder.ts @@ -0,0 +1,107 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountLinkActionDto } from './AccountLinkActionDto'; +import { AccountLinkTransactionBodyBuilder } from './AccountLinkTransactionBodyBuilder'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account link transaction. */ +export class EmbeddedAccountLinkTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account link transaction body. */ + accountLinkTransactionBody: AccountLinkTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param remoteAccountPublicKey Remote account public key. + * @param linkAction Account link action. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, remoteAccountPublicKey: KeyDto, linkAction: AccountLinkActionDto) { + super(signer, version, type); + this.accountLinkTransactionBody = new AccountLinkTransactionBodyBuilder(remoteAccountPublicKey, linkAction); + } + + /** + * Creates an instance of EmbeddedAccountLinkTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountLinkTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountLinkTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const accountLinkTransactionBody = AccountLinkTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountLinkTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountLinkTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountLinkTransactionBody.remoteAccountPublicKey, accountLinkTransactionBody.linkAction); + } + + /** + * Gets remote account public key. + * + * @return Remote account public key. + */ + public getRemoteAccountPublicKey(): KeyDto { + return this.accountLinkTransactionBody.getRemoteAccountPublicKey(); + } + + /** + * Gets account link action. + * + * @return Account link action. + */ + public getLinkAction(): AccountLinkActionDto { + return this.accountLinkTransactionBody.getLinkAction(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountLinkTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountLinkTransactionBodyBytes = this.accountLinkTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountLinkTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..ec9f33ca7f --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder.ts @@ -0,0 +1,133 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMetadataTransactionBodyBuilder } from './AccountMetadataTransactionBodyBuilder'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account metadata transaction. */ +export class EmbeddedAccountMetadataTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account metadata transaction body. */ + accountMetadataTransactionBody: AccountMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], valueSizeDelta: number, value: Uint8Array) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.accountMetadataTransactionBody = new AccountMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, valueSizeDelta, value); + } + + /** + * Creates an instance of EmbeddedAccountMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const accountMetadataTransactionBody = AccountMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountMetadataTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountMetadataTransactionBody.targetPublicKey, accountMetadataTransactionBody.scopedMetadataKey, accountMetadataTransactionBody.valueSizeDelta, accountMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.accountMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.accountMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.accountMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.accountMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountMetadataTransactionBodyBytes = this.accountMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..d97d085545 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder.ts @@ -0,0 +1,110 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMosaicRestrictionModificationBuilder } from './AccountMosaicRestrictionModificationBuilder'; +import { AccountMosaicRestrictionTransactionBodyBuilder } from './AccountMosaicRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account mosaic restriction transaction. */ +export class EmbeddedAccountMosaicRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account mosaic restriction transaction body. */ + accountMosaicRestrictionTransactionBody: AccountMosaicRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountMosaicRestrictionModificationBuilder[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.accountMosaicRestrictionTransactionBody = new AccountMosaicRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of EmbeddedAccountMosaicRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountMosaicRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountMosaicRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountMosaicRestrictionTransactionBody = AccountMosaicRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountMosaicRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountMosaicRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountMosaicRestrictionTransactionBody.restrictionType, accountMosaicRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountMosaicRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountMosaicRestrictionModificationBuilder[] { + return this.accountMosaicRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountMosaicRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountMosaicRestrictionTransactionBodyBytes = this.accountMosaicRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountMosaicRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..c4de2fb15c --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder.ts @@ -0,0 +1,110 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountOperationRestrictionModificationBuilder } from './AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBodyBuilder } from './AccountOperationRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account operation restriction transaction. */ +export class EmbeddedAccountOperationRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account operation restriction transaction body. */ + accountOperationRestrictionTransactionBody: AccountOperationRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountOperationRestrictionModificationBuilder[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.accountOperationRestrictionTransactionBody = new AccountOperationRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of EmbeddedAccountOperationRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountOperationRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountOperationRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountOperationRestrictionTransactionBody = AccountOperationRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountOperationRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountOperationRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountOperationRestrictionTransactionBody.restrictionType, accountOperationRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountOperationRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountOperationRestrictionModificationBuilder[] { + return this.accountOperationRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountOperationRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountOperationRestrictionTransactionBodyBytes = this.accountOperationRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountOperationRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder.ts new file mode 100644 index 0000000000..7532500571 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder.ts @@ -0,0 +1,119 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; +import { AddressDto } from './AddressDto'; +import { AliasActionDto } from './AliasActionDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for an embedded address alias transaction. */ +export class EmbeddedAddressAliasTransactionBuilder extends EmbeddedTransactionBuilder { + /** Address alias transaction body. */ + addressAliasTransactionBody: AddressAliasTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param address Aliased address. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, address: AddressDto) { + super(signer, version, type); + this.addressAliasTransactionBody = new AddressAliasTransactionBodyBuilder(aliasAction, namespaceId, address); + } + + /** + * Creates an instance of EmbeddedAddressAliasTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAddressAliasTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAddressAliasTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const addressAliasTransactionBody = AddressAliasTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, addressAliasTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAddressAliasTransactionBuilder(superObject.signer, superObject.version, superObject.type, addressAliasTransactionBody.aliasAction, addressAliasTransactionBody.namespaceId, addressAliasTransactionBody.address); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.addressAliasTransactionBody.getAliasAction(); + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.addressAliasTransactionBody.getNamespaceId(); + } + + /** + * Gets aliased address. + * + * @return Aliased address. + */ + public getAddress(): AddressDto { + return this.addressAliasTransactionBody.getAddress(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.addressAliasTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const addressAliasTransactionBodyBytes = this.addressAliasTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, addressAliasTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder.ts new file mode 100644 index 0000000000..e91a7e98b4 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder.ts @@ -0,0 +1,119 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { HashLockTransactionBodyBuilder } from './HashLockTransactionBodyBuilder'; +import { KeyDto } from './KeyDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for an embedded hash lock transaction. */ +export class EmbeddedHashLockTransactionBuilder extends EmbeddedTransactionBuilder { + /** Hash lock transaction body. */ + hashLockTransactionBody: HashLockTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaic Lock mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hash Lock hash. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hash: Hash256Dto) { + super(signer, version, type); + this.hashLockTransactionBody = new HashLockTransactionBodyBuilder(mosaic, duration, hash); + } + + /** + * Creates an instance of EmbeddedHashLockTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedHashLockTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedHashLockTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const hashLockTransactionBody = HashLockTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, hashLockTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedHashLockTransactionBuilder(superObject.signer, superObject.version, superObject.type, hashLockTransactionBody.mosaic, hashLockTransactionBody.duration, hashLockTransactionBody.hash); + } + + /** + * Gets lock mosaic. + * + * @return Lock mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.hashLockTransactionBody.getMosaic(); + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.hashLockTransactionBody.getDuration(); + } + + /** + * Gets lock hash. + * + * @return Lock hash. + */ + public getHash(): Hash256Dto { + return this.hashLockTransactionBody.getHash(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.hashLockTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const hashLockTransactionBodyBytes = this.hashLockTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashLockTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..ead5de2075 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder.ts @@ -0,0 +1,140 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicAddressRestrictionTransactionBodyBuilder } from './MosaicAddressRestrictionTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an embedded mosaic address restriction transaction. */ +export class EmbeddedMosaicAddressRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic address restriction transaction body. */ + mosaicAddressRestrictionTransactionBody: MosaicAddressRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaicId Identifier of the mosaic to which the restriction applies. + * @param restrictionKey Restriction key. + * @param targetAddress Address being restricted. + * @param previousRestrictionValue Previous restriction value. + * @param newRestrictionValue New restriction value. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], targetAddress: UnresolvedAddressDto, previousRestrictionValue: number[], newRestrictionValue: number[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.mosaicAddressRestrictionTransactionBody = new MosaicAddressRestrictionTransactionBodyBuilder(mosaicId, restrictionKey, targetAddress, previousRestrictionValue, newRestrictionValue); + } + + /** + * Creates an instance of EmbeddedMosaicAddressRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicAddressRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicAddressRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicAddressRestrictionTransactionBody = MosaicAddressRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicAddressRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicAddressRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicAddressRestrictionTransactionBody.mosaicId, mosaicAddressRestrictionTransactionBody.restrictionKey, mosaicAddressRestrictionTransactionBody.targetAddress, mosaicAddressRestrictionTransactionBody.previousRestrictionValue, mosaicAddressRestrictionTransactionBody.newRestrictionValue); + } + + /** + * Gets identifier of the mosaic to which the restriction applies. + * + * @return Identifier of the mosaic to which the restriction applies. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicAddressRestrictionTransactionBody.getMosaicId(); + } + + /** + * Gets restriction key. + * + * @return Restriction key. + */ + public getRestrictionKey(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getRestrictionKey(); + } + + /** + * Gets address being restricted. + * + * @return Address being restricted. + */ + public getTargetAddress(): UnresolvedAddressDto { + return this.mosaicAddressRestrictionTransactionBody.getTargetAddress(); + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getPreviousRestrictionValue(); + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getNewRestrictionValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicAddressRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicAddressRestrictionTransactionBodyBytes = this.mosaicAddressRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicAddressRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder.ts new file mode 100644 index 0000000000..635b59964f --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder.ts @@ -0,0 +1,119 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AliasActionDto } from './AliasActionDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicAliasTransactionBodyBuilder } from './MosaicAliasTransactionBodyBuilder'; +import { MosaicIdDto } from './MosaicIdDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for an embedded mosaic alias transaction. */ +export class EmbeddedMosaicAliasTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic alias transaction body. */ + mosaicAliasTransactionBody: MosaicAliasTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param mosaicId Aliased mosaic identifier. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, mosaicId: MosaicIdDto) { + super(signer, version, type); + this.mosaicAliasTransactionBody = new MosaicAliasTransactionBodyBuilder(aliasAction, namespaceId, mosaicId); + } + + /** + * Creates an instance of EmbeddedMosaicAliasTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicAliasTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicAliasTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const mosaicAliasTransactionBody = MosaicAliasTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicAliasTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicAliasTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicAliasTransactionBody.aliasAction, mosaicAliasTransactionBody.namespaceId, mosaicAliasTransactionBody.mosaicId); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.mosaicAliasTransactionBody.getAliasAction(); + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.mosaicAliasTransactionBody.getNamespaceId(); + } + + /** + * Gets aliased mosaic identifier. + * + * @return Aliased mosaic identifier. + */ + public getMosaicId(): MosaicIdDto { + return this.mosaicAliasTransactionBody.getMosaicId(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicAliasTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicAliasTransactionBodyBytes = this.mosaicAliasTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicAliasTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder.ts new file mode 100644 index 0000000000..ad46a89813 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder.ts @@ -0,0 +1,141 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicDefinitionTransactionBodyBuilder } from './MosaicDefinitionTransactionBodyBuilder'; +import { MosaicIdDto } from './MosaicIdDto'; +import { MosaicNonceDto } from './MosaicNonceDto'; + +/** Binary layout for an embedded mosaic definition transaction. */ +export class EmbeddedMosaicDefinitionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic definition transaction body. */ + mosaicDefinitionTransactionBody: MosaicDefinitionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param nonce Mosaic nonce. + * @param id Mosaic identifier. + * @param flags Mosaic flags. + * @param divisibility Mosaic divisibility. + * @param duration Mosaic duration. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, nonce: MosaicNonceDto, id: MosaicIdDto, flags: number, divisibility: number, duration: BlockDurationDto) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.mosaicDefinitionTransactionBody = new MosaicDefinitionTransactionBodyBuilder(nonce, id, flags, divisibility, duration); + } + + /** + * Creates an instance of EmbeddedMosaicDefinitionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicDefinitionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicDefinitionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicDefinitionTransactionBody = MosaicDefinitionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicDefinitionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicDefinitionTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicDefinitionTransactionBody.nonce, mosaicDefinitionTransactionBody.id, mosaicDefinitionTransactionBody.flags, mosaicDefinitionTransactionBody.divisibility, mosaicDefinitionTransactionBody.duration); + } + + /** + * Gets mosaic nonce. + * + * @return Mosaic nonce. + */ + public getNonce(): MosaicNonceDto { + return this.mosaicDefinitionTransactionBody.getNonce(); + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getId(): MosaicIdDto { + return this.mosaicDefinitionTransactionBody.getId(); + } + + /** + * Gets mosaic flags. + * + * @return Mosaic flags. + */ + public getFlags(): number { + return this.mosaicDefinitionTransactionBody.getFlags(); + } + + /** + * Gets mosaic divisibility. + * + * @return Mosaic divisibility. + */ + public getDivisibility(): number { + return this.mosaicDefinitionTransactionBody.getDivisibility(); + } + + /** + * Gets mosaic duration. + * + * @return Mosaic duration. + */ + public getDuration(): BlockDurationDto { + return this.mosaicDefinitionTransactionBody.getDuration(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicDefinitionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicDefinitionTransactionBodyBytes = this.mosaicDefinitionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicDefinitionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..224df49b31 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder.ts @@ -0,0 +1,160 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicGlobalRestrictionTransactionBodyBuilder } from './MosaicGlobalRestrictionTransactionBodyBuilder'; +import { MosaicRestrictionTypeDto } from './MosaicRestrictionTypeDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an embedded mosaic global restriction transaction. */ +export class EmbeddedMosaicGlobalRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic global restriction transaction body. */ + mosaicGlobalRestrictionTransactionBody: MosaicGlobalRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaicId Identifier of the mosaic being restricted. + * @param referenceMosaicId Identifier of the mosaic providing the restriction key. + * @param restrictionKey Restriction key relative to the reference mosaic identifier. + * @param previousRestrictionValue Previous restriction value. + * @param previousRestrictionType Previous restriction type. + * @param newRestrictionValue New restriction value. + * @param newRestrictionType New restriction type. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaicId: UnresolvedMosaicIdDto, referenceMosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], previousRestrictionValue: number[], previousRestrictionType: MosaicRestrictionTypeDto, newRestrictionValue: number[], newRestrictionType: MosaicRestrictionTypeDto) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.mosaicGlobalRestrictionTransactionBody = new MosaicGlobalRestrictionTransactionBodyBuilder(mosaicId, referenceMosaicId, restrictionKey, previousRestrictionValue, previousRestrictionType, newRestrictionValue, newRestrictionType); + } + + /** + * Creates an instance of EmbeddedMosaicGlobalRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicGlobalRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicGlobalRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicGlobalRestrictionTransactionBody = MosaicGlobalRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicGlobalRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicGlobalRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicGlobalRestrictionTransactionBody.mosaicId, mosaicGlobalRestrictionTransactionBody.referenceMosaicId, mosaicGlobalRestrictionTransactionBody.restrictionKey, mosaicGlobalRestrictionTransactionBody.previousRestrictionValue, mosaicGlobalRestrictionTransactionBody.previousRestrictionType, mosaicGlobalRestrictionTransactionBody.newRestrictionValue, mosaicGlobalRestrictionTransactionBody.newRestrictionType); + } + + /** + * Gets identifier of the mosaic being restricted. + * + * @return Identifier of the mosaic being restricted. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicGlobalRestrictionTransactionBody.getMosaicId(); + } + + /** + * Gets identifier of the mosaic providing the restriction key. + * + * @return Identifier of the mosaic providing the restriction key. + */ + public getReferenceMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicGlobalRestrictionTransactionBody.getReferenceMosaicId(); + } + + /** + * Gets restriction key relative to the reference mosaic identifier. + * + * @return Restriction key relative to the reference mosaic identifier. + */ + public getRestrictionKey(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getRestrictionKey(); + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getPreviousRestrictionValue(); + } + + /** + * Gets previous restriction type. + * + * @return Previous restriction type. + */ + public getPreviousRestrictionType(): MosaicRestrictionTypeDto { + return this.mosaicGlobalRestrictionTransactionBody.getPreviousRestrictionType(); + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getNewRestrictionValue(); + } + + /** + * Gets new restriction type. + * + * @return New restriction type. + */ + public getNewRestrictionType(): MosaicRestrictionTypeDto { + return this.mosaicGlobalRestrictionTransactionBody.getNewRestrictionType(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicGlobalRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicGlobalRestrictionTransactionBodyBytes = this.mosaicGlobalRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicGlobalRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..378bec0bf3 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder.ts @@ -0,0 +1,144 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicMetadataTransactionBodyBuilder } from './MosaicMetadataTransactionBodyBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an embedded mosaic metadata transaction. */ +export class EmbeddedMosaicMetadataTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic metadata transaction body. */ + mosaicMetadataTransactionBody: MosaicMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetMosaicId Target mosaic identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], targetMosaicId: UnresolvedMosaicIdDto, valueSizeDelta: number, value: Uint8Array) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.mosaicMetadataTransactionBody = new MosaicMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetMosaicId, valueSizeDelta, value); + } + + /** + * Creates an instance of EmbeddedMosaicMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const mosaicMetadataTransactionBody = MosaicMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicMetadataTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicMetadataTransactionBody.targetPublicKey, mosaicMetadataTransactionBody.scopedMetadataKey, mosaicMetadataTransactionBody.targetMosaicId, mosaicMetadataTransactionBody.valueSizeDelta, mosaicMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.mosaicMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.mosaicMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets target mosaic identifier. + * + * @return Target mosaic identifier. + */ + public getTargetMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicMetadataTransactionBody.getTargetMosaicId(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.mosaicMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.mosaicMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicMetadataTransactionBodyBytes = this.mosaicMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder.ts new file mode 100644 index 0000000000..6f66b59522 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder.ts @@ -0,0 +1,120 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicSupplyChangeActionDto } from './MosaicSupplyChangeActionDto'; +import { MosaicSupplyChangeTransactionBodyBuilder } from './MosaicSupplyChangeTransactionBodyBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an embedded mosaic supply change transaction. */ +export class EmbeddedMosaicSupplyChangeTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic supply change transaction body. */ + mosaicSupplyChangeTransactionBody: MosaicSupplyChangeTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaicId Affected mosaic identifier. + * @param action Supply change action. + * @param delta Change amount. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaicId: UnresolvedMosaicIdDto, action: MosaicSupplyChangeActionDto, delta: AmountDto) { + super(signer, version, type); + this.mosaicSupplyChangeTransactionBody = new MosaicSupplyChangeTransactionBodyBuilder(mosaicId, action, delta); + } + + /** + * Creates an instance of EmbeddedMosaicSupplyChangeTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicSupplyChangeTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicSupplyChangeTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicSupplyChangeTransactionBody = MosaicSupplyChangeTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicSupplyChangeTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicSupplyChangeTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicSupplyChangeTransactionBody.mosaicId, mosaicSupplyChangeTransactionBody.action, mosaicSupplyChangeTransactionBody.delta); + } + + /** + * Gets affected mosaic identifier. + * + * @return Affected mosaic identifier. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicSupplyChangeTransactionBody.getMosaicId(); + } + + /** + * Gets supply change action. + * + * @return Supply change action. + */ + public getAction(): MosaicSupplyChangeActionDto { + return this.mosaicSupplyChangeTransactionBody.getAction(); + } + + /** + * Gets change amount. + * + * @return Change amount. + */ + public getDelta(): AmountDto { + return this.mosaicSupplyChangeTransactionBody.getDelta(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicSupplyChangeTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicSupplyChangeTransactionBodyBytes = this.mosaicSupplyChangeTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicSupplyChangeTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder.ts new file mode 100644 index 0000000000..b2de331994 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder.ts @@ -0,0 +1,119 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { CosignatoryModificationBuilder } from './CosignatoryModificationBuilder'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MultisigAccountModificationTransactionBodyBuilder } from './MultisigAccountModificationTransactionBodyBuilder'; + +/** Binary layout for an embedded multisig account modification transaction. */ +export class EmbeddedMultisigAccountModificationTransactionBuilder extends EmbeddedTransactionBuilder { + /** Multisig account modification transaction body. */ + multisigAccountModificationTransactionBody: MultisigAccountModificationTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param minRemovalDelta Relative change of the minimal number of cosignatories required when removing an account. + * @param minApprovalDelta Relative change of the minimal number of cosignatories required when approving a transaction. + * @param modifications Attached cosignatory modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, minRemovalDelta: number, minApprovalDelta: number, modifications: CosignatoryModificationBuilder[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.multisigAccountModificationTransactionBody = new MultisigAccountModificationTransactionBodyBuilder(minRemovalDelta, minApprovalDelta, modifications); + } + + /** + * Creates an instance of EmbeddedMultisigAccountModificationTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMultisigAccountModificationTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMultisigAccountModificationTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const multisigAccountModificationTransactionBody = MultisigAccountModificationTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, multisigAccountModificationTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMultisigAccountModificationTransactionBuilder(superObject.signer, superObject.version, superObject.type, multisigAccountModificationTransactionBody.minRemovalDelta, multisigAccountModificationTransactionBody.minApprovalDelta, multisigAccountModificationTransactionBody.modifications); + } + + /** + * Gets relative change of the minimal number of cosignatories required when removing an account. + * + * @return Relative change of the minimal number of cosignatories required when removing an account. + */ + public getMinRemovalDelta(): number { + return this.multisigAccountModificationTransactionBody.getMinRemovalDelta(); + } + + /** + * Gets relative change of the minimal number of cosignatories required when approving a transaction. + * + * @return Relative change of the minimal number of cosignatories required when approving a transaction. + */ + public getMinApprovalDelta(): number { + return this.multisigAccountModificationTransactionBody.getMinApprovalDelta(); + } + + /** + * Gets attached cosignatory modifications. + * + * @return Attached cosignatory modifications. + */ + public getModifications(): CosignatoryModificationBuilder[] { + return this.multisigAccountModificationTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.multisigAccountModificationTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const multisigAccountModificationTransactionBodyBytes = this.multisigAccountModificationTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, multisigAccountModificationTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..1d4bbe606c --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder.ts @@ -0,0 +1,145 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceMetadataTransactionBodyBuilder } from './NamespaceMetadataTransactionBodyBuilder'; + +/** Binary layout for an embedded namespace metadata transaction. */ +export class EmbeddedNamespaceMetadataTransactionBuilder extends EmbeddedTransactionBuilder { + /** Namespace metadata transaction body. */ + namespaceMetadataTransactionBody: NamespaceMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetNamespaceId Target namespace identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], targetNamespaceId: NamespaceIdDto, valueSizeDelta: number, value: Uint8Array) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.namespaceMetadataTransactionBody = new NamespaceMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetNamespaceId, valueSizeDelta, value); + } + + /** + * Creates an instance of EmbeddedNamespaceMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedNamespaceMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedNamespaceMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const namespaceMetadataTransactionBody = NamespaceMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedNamespaceMetadataTransactionBuilder(superObject.signer, superObject.version, superObject.type, namespaceMetadataTransactionBody.targetPublicKey, namespaceMetadataTransactionBody.scopedMetadataKey, namespaceMetadataTransactionBody.targetNamespaceId, namespaceMetadataTransactionBody.valueSizeDelta, namespaceMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.namespaceMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.namespaceMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets target namespace identifier. + * + * @return Target namespace identifier. + */ + public getTargetNamespaceId(): NamespaceIdDto { + return this.namespaceMetadataTransactionBody.getTargetNamespaceId(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.namespaceMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.namespaceMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.namespaceMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const namespaceMetadataTransactionBodyBytes = this.namespaceMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder.ts new file mode 100644 index 0000000000..29d51b3fb1 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder.ts @@ -0,0 +1,143 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceRegistrationTransactionBodyBuilder } from './NamespaceRegistrationTransactionBodyBuilder'; +import { NamespaceRegistrationTypeDto } from './NamespaceRegistrationTypeDto'; + +/** Binary layout for an embedded namespace registration transaction. */ +export class EmbeddedNamespaceRegistrationTransactionBuilder extends EmbeddedTransactionBuilder { + /** Namespace registration transaction body. */ + namespaceRegistrationTransactionBody: NamespaceRegistrationTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param duration Namespace duration. + * @param parentId Parent namespace identifier. + * @param id Namespace identifier. + * @param name Namespace name. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, id: NamespaceIdDto, name: Uint8Array, duration?: BlockDurationDto, parentId?: NamespaceIdDto) { + super(signer, version, type); + if ((duration && parentId) || (!duration && !parentId)) { + throw new Error('Invalid conditional parameters'); + } + // tslint:disable-next-line: max-line-length + this.namespaceRegistrationTransactionBody = new NamespaceRegistrationTransactionBodyBuilder(id, name, duration, parentId); + } + + /** + * Creates an instance of EmbeddedNamespaceRegistrationTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedNamespaceRegistrationTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedNamespaceRegistrationTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const namespaceRegistrationTransactionBody = NamespaceRegistrationTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceRegistrationTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedNamespaceRegistrationTransactionBuilder(superObject.signer, superObject.version, superObject.type, namespaceRegistrationTransactionBody.id, namespaceRegistrationTransactionBody.name, namespaceRegistrationTransactionBody.duration, namespaceRegistrationTransactionBody.parentId); + } + + /** + * Gets namespace registration type. + * + * @return Namespace registration type. + */ + public getRegistrationType(): NamespaceRegistrationTypeDto { + return this.namespaceRegistrationTransactionBody.getRegistrationType(); + } + + /** + * Gets namespace duration. + * + * @return Namespace duration. + */ + public getDuration(): BlockDurationDto | undefined { + return this.namespaceRegistrationTransactionBody.getDuration(); + } + + /** + * Gets parent namespace identifier. + * + * @return Parent namespace identifier. + */ + public getParentId(): NamespaceIdDto | undefined { + return this.namespaceRegistrationTransactionBody.getParentId(); + } + + /** + * Gets namespace identifier. + * + * @return Namespace identifier. + */ + public getId(): NamespaceIdDto { + return this.namespaceRegistrationTransactionBody.getId(); + } + + /** + * Gets namespace name. + * + * @return Namespace name. + */ + public getName(): Uint8Array { + return this.namespaceRegistrationTransactionBody.getName(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.namespaceRegistrationTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const namespaceRegistrationTransactionBodyBytes = this.namespaceRegistrationTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceRegistrationTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder.ts new file mode 100644 index 0000000000..e8f4c80213 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder.ts @@ -0,0 +1,142 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { KeyDto } from './KeyDto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { SecretLockTransactionBodyBuilder } from './SecretLockTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for an embedded secret lock transaction. */ +export class EmbeddedSecretLockTransactionBuilder extends EmbeddedTransactionBuilder { + /** Secret lock transaction body. */ + secretLockTransactionBody: SecretLockTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaic Locked mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Locked mosaic recipient. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.secretLockTransactionBody = new SecretLockTransactionBodyBuilder(mosaic, duration, hashAlgorithm, secret, recipient); + } + + /** + * Creates an instance of EmbeddedSecretLockTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedSecretLockTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedSecretLockTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const secretLockTransactionBody = SecretLockTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secretLockTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedSecretLockTransactionBuilder(superObject.signer, superObject.version, superObject.type, secretLockTransactionBody.mosaic, secretLockTransactionBody.duration, secretLockTransactionBody.hashAlgorithm, secretLockTransactionBody.secret, secretLockTransactionBody.recipient); + } + + /** + * Gets locked mosaic. + * + * @return Locked mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.secretLockTransactionBody.getMosaic(); + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.secretLockTransactionBody.getDuration(); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.secretLockTransactionBody.getHashAlgorithm(); + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secretLockTransactionBody.getSecret(); + } + + /** + * Gets locked mosaic recipient. + * + * @return Locked mosaic recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.secretLockTransactionBody.getRecipient(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.secretLockTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const secretLockTransactionBodyBytes = this.secretLockTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretLockTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder.ts new file mode 100644 index 0000000000..58d0df9188 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder.ts @@ -0,0 +1,129 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { KeyDto } from './KeyDto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { SecretProofTransactionBodyBuilder } from './SecretProofTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; + +/** Binary layout for an embedded secret proof transaction. */ +export class EmbeddedSecretProofTransactionBuilder extends EmbeddedTransactionBuilder { + /** Secret proof transaction body. */ + secretProofTransactionBody: SecretProofTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Recipient. + * @param proof Proof data. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto, proof: Uint8Array) { + super(signer, version, type); + this.secretProofTransactionBody = new SecretProofTransactionBodyBuilder(hashAlgorithm, secret, recipient, proof); + } + + /** + * Creates an instance of EmbeddedSecretProofTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedSecretProofTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedSecretProofTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const secretProofTransactionBody = SecretProofTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secretProofTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedSecretProofTransactionBuilder(superObject.signer, superObject.version, superObject.type, secretProofTransactionBody.hashAlgorithm, secretProofTransactionBody.secret, secretProofTransactionBody.recipient, secretProofTransactionBody.proof); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.secretProofTransactionBody.getHashAlgorithm(); + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secretProofTransactionBody.getSecret(); + } + + /** + * Gets recipient. + * + * @return Recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.secretProofTransactionBody.getRecipient(); + } + + /** + * Gets proof data. + * + * @return Proof data. + */ + public getProof(): Uint8Array { + return this.secretProofTransactionBody.getProof(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.secretProofTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const secretProofTransactionBodyBytes = this.secretProofTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretProofTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedTransactionBuilder.ts new file mode 100644 index 0000000000..836a8cda5d --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedTransactionBuilder.ts @@ -0,0 +1,127 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded transaction. */ +export class EmbeddedTransactionBuilder { + /** Entity size. */ + size = 0; + /** Entity signer's public key. */ + signer: KeyDto; + /** Entity version. */ + version: number; + /** Entity type. */ + type: EntityTypeDto; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + */ + public constructor(signer: KeyDto, version: number, type: EntityTypeDto) { + this.signer = signer; + this.version = version; + this.type = type; + } + + /** + * Creates an instance of EmbeddedTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedTransactionBuilder { + const byteArray = Array.from(payload); + const size = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signer.getSize()); + const version = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const type = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + return new EmbeddedTransactionBuilder(signer, version, type); + } + + /** + * Gets entity signer's public key. + * + * @return Entity signer's public key. + */ + public getSigner(): KeyDto { + return this.signer; + } + + /** + * Gets entity version. + * + * @return Entity version. + */ + public getVersion(): number { + return this.version; + } + + /** + * Gets entity type. + * + * @return Entity type. + */ + public getType(): EntityTypeDto { + return this.type; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 4; // size + size += this.signer.getSize(); + size += 2; // version + size += 2; // type + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const sizeBytes = GeneratorUtils.uintToBuffer(this.getSize(), 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, sizeBytes); + const signerBytes = this.signer.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); + const versionBytes = GeneratorUtils.uintToBuffer(this.getVersion(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, versionBytes); + const typeBytes = GeneratorUtils.uintToBuffer(this.type, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, typeBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedTransferTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedTransferTransactionBuilder.ts new file mode 100644 index 0000000000..f4402345ef --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedTransferTransactionBuilder.ts @@ -0,0 +1,118 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { TransferTransactionBodyBuilder } from './TransferTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for an embedded transfer transaction. */ +export class EmbeddedTransferTransactionBuilder extends EmbeddedTransactionBuilder { + /** Transfer transaction body. */ + transferTransactionBody: TransferTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param recipient Transaction recipient. + * @param message Transaction message. + * @param mosaics Attached mosaics. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, recipient: UnresolvedAddressDto, message: Uint8Array, mosaics: UnresolvedMosaicBuilder[]) { + super(signer, version, type); + this.transferTransactionBody = new TransferTransactionBodyBuilder(recipient, message, mosaics); + } + + /** + * Creates an instance of EmbeddedTransferTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedTransferTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedTransferTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const transferTransactionBody = TransferTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, transferTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedTransferTransactionBuilder(superObject.signer, superObject.version, superObject.type, transferTransactionBody.recipient, transferTransactionBody.message, transferTransactionBody.mosaics); + } + + /** + * Gets transaction recipient. + * + * @return Transaction recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.transferTransactionBody.getRecipient(); + } + + /** + * Gets transaction message. + * + * @return Transaction message. + */ + public getMessage(): Uint8Array { + return this.transferTransactionBody.getMessage(); + } + + /** + * Gets attached mosaics. + * + * @return Attached mosaics. + */ + public getMosaics(): UnresolvedMosaicBuilder[] { + return this.transferTransactionBody.getMosaics(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.transferTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const transferTransactionBodyBytes = this.transferTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, transferTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EntityTypeDto.ts b/src/infrastructure/catbuffer/EntityTypeDto.ts new file mode 100644 index 0000000000..52e1c55a94 --- /dev/null +++ b/src/infrastructure/catbuffer/EntityTypeDto.ts @@ -0,0 +1,133 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of entity types. */ +export enum EntityTypeDto { + /** Reserved entity type. */ + RESERVED = 0, + /** + * Transfer Transaction transaction type. + * @type {number} + */ + TRANSFER = 0x4154, + + /** + * Register namespace transaction type. + * @type {number} + */ + REGISTER_NAMESPACE = 0x414E, + + /** + * Address alias transaction type + * @type {number} + */ + ADDRESS_ALIAS = 0x424E, + + /** + * Mosaic alias transaction type + * @type {number} + */ + MOSAIC_ALIAS = 0x434E, + + /** + * Mosaic definition transaction type. + * @type {number} + */ + MOSAIC_DEFINITION = 0x414D, + + /** + * Mosaic supply change transaction. + * @type {number} + */ + MOSAIC_SUPPLY_CHANGE = 0x424D, + + /** + * Modify multisig account transaction type. + * @type {number} + */ + MODIFY_MULTISIG_ACCOUNT = 0x4155, + + /** + * Aggregate complete transaction type. + * @type {number} + */ + AGGREGATE_COMPLETE = 0x4141, + + /** + * Aggregate bonded transaction type + */ + AGGREGATE_BONDED = 0x4241, + + /** + * Lock transaction type + * @type {number} + */ + LOCK = 0x4148, + + /** + * Secret Lock Transaction type + * @type {number} + */ + SECRET_LOCK = 0x4152, + + /** + * Secret Proof transaction type + * @type {number} + */ + SECRET_PROOF = 0x4252, + + /** + * Account restriction address transaction type + * @type {number} + */ + ACCOUNT_RESTRICTION_ADDRESS = 0x4150, + + /** + * Account restriction mosaic transaction type + * @type {number} + */ + ACCOUNT_RESTRICTION_MOSAIC = 0x4250, + + /** + * Account restriction operation transaction type + * @type {number} + */ + ACCOUNT_RESTRICTION_OPERATION = 0x4350, + + /** + * Link account transaction type + * @type {number} + */ + LINK_ACCOUNT = 0x414C, + + /** + * Mosaic address restriction type + * @type {number} + */ + MOSAIC_ADDRESS_RESTRICTION = 0x4251, + + /** + * Mosaic global restriction type + * @type {number} + */ + MOSAIC_GLOBAL_RESTRICTION = 0x4151, +} diff --git a/src/infrastructure/catbuffer/GeneratorUtils.ts b/src/infrastructure/catbuffer/GeneratorUtils.ts new file mode 100644 index 0000000000..437c32d117 --- /dev/null +++ b/src/infrastructure/catbuffer/GeneratorUtils.ts @@ -0,0 +1,141 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +/** + * Generator utility class. + */ +export class GeneratorUtils { + + /** + * Converts a (64bit) uint8 array into a number array. + * @param {Uint8Array} input A uint8 array. + * @returns {number[]} The uint64 representation of the input. + */ + public static bufferToUint64 (input: Uint8Array): number[] { + if (8 !== input.length) { + throw Error(`byte array has unexpected size '${input.length}'`); + } + input = input.reverse(); + return [GeneratorUtils.readUint32At(input, 0), GeneratorUtils.readUint32At(input, 4)]; + } + + /** + * Read buffer into 32bits integer at given index. + * @param {Uint8Array} bytes A uint8 array. + * @param {number} index Index. + * @returns {number} 32bits integer. + */ + public static readUint32At(bytes: Uint8Array, index: number): number { + return (bytes[index] + (bytes[index + 1] << 8) + (bytes[index + 2] << 16) + (bytes[index + 3] << 24)) >>> 0; + } + + /** + * Write uint to buffer + * @param {number} uintValue A uint8 array. + * @param {number} bufferSize Buffer size. + * @returns {Uint8Array} + */ + public static uintToBuffer (uintValue: number, bufferSize: number): Uint8Array { + const buffer = new ArrayBuffer(bufferSize); + const dataView = new DataView(buffer); + if (1 === bufferSize) + dataView.setUint8(0, uintValue); + + else if (2 === bufferSize) + dataView.setUint16(0, uintValue, true); + + else if (4 === bufferSize) + dataView.setUint32(0, uintValue, true); + + else + throw new Error('Unexpected bufferSize'); + + return new Uint8Array(buffer); + } + + /** + * Write uint to buffer + * @param {Uint8Array} buffer A uint8 array. + * @returns {number} + */ + public static bufferToUint(buffer: Uint8Array): number { + const dataView = new DataView(buffer.buffer); + if (1 === buffer.byteLength) + return dataView.getUint8(0); + + else if (2 === buffer.byteLength) + return dataView.getUint16(0, true); + + else if (4 === buffer.byteLength) + return dataView.getUint32(0, true); + + throw new Error('Unexpected buffer size'); + }; + + /** + * Write Uint64 to buffer + * @param {number} uintValue Uint64 (number[]). + * @returns {Uint8Array} + */ + public static uint64ToBuffer(uintValue: number[]): Uint8Array { + const uint32Array = new Uint32Array(uintValue); + return new Uint8Array(uint32Array.buffer); + } + + /** + * Concatenate two arrays + * @param {Uint8Array} array1 A Uint8Array. + * @param {Uint8Array} array2 A Uint8Array. + * @returns {Uint8Array} + */ + public static concatTypedArrays(array1: Uint8Array, array2: Uint8Array): Uint8Array { + const newArray = new Uint8Array(array1.length + array2.length); + newArray.set(array1); + newArray.set(array2, array1.length); + return newArray; + } + + /** Converts an unsigned byte to a signed byte with the same binary representation. + * @param {number} input An unsigned byte. + * @returns {number} A signed byte with the same binary representation as the input. + * + */ + public static uint8ToInt8 = (input: number): number => { + if (0xFF < input) { + throw Error(`input '${input}' is out of range`); + } + return input << 24 >> 24; + } + + /** Get bytes by given sub array size. + * @param {Uint8Array} binary Binary bytes array. + * @param {number} size Subarray size. + * @returns {Uint8Array} + * + */ + public static getBytes(binary: Uint8Array, size: number): Uint8Array { + if (size > binary.length) + throw new RangeError(); + + const bytes = binary.slice(0, size); + return bytes; + } +} diff --git a/src/infrastructure/catbuffer/Hash256Dto.ts b/src/infrastructure/catbuffer/Hash256Dto.ts new file mode 100644 index 0000000000..0f09dfda19 --- /dev/null +++ b/src/infrastructure/catbuffer/Hash256Dto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Hash256. */ +export class Hash256Dto { + /** Hash256. */ + hash256: Uint8Array; + + /** + * Constructor. + * + * @param hash256 Hash256. + */ + constructor(hash256: Uint8Array) { + this.hash256 = hash256; + } + + /** + * Creates an instance of Hash256Dto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of Hash256Dto. + */ + public static loadFromBinary(payload: Uint8Array): Hash256Dto { + const byteArray = Array.from(payload); + const hash256 = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 32); + byteArray.splice(0, 32); + return new Hash256Dto(hash256); + } + + /** + * Gets Hash256. + * + * @return Hash256. + */ + public getHash256(): Uint8Array { + return this.hash256; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 32; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.hash256); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/Hash512Dto.ts b/src/infrastructure/catbuffer/Hash512Dto.ts new file mode 100644 index 0000000000..1455eb7623 --- /dev/null +++ b/src/infrastructure/catbuffer/Hash512Dto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Hash512. */ +export class Hash512Dto { + /** Hash512. */ + hash512: Uint8Array; + + /** + * Constructor. + * + * @param hash512 Hash512. + */ + constructor(hash512: Uint8Array) { + this.hash512 = hash512; + } + + /** + * Creates an instance of Hash512Dto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of Hash512Dto. + */ + public static loadFromBinary(payload: Uint8Array): Hash512Dto { + const byteArray = Array.from(payload); + const hash512 = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 64); + byteArray.splice(0, 64); + return new Hash512Dto(hash512); + } + + /** + * Gets Hash512. + * + * @return Hash512. + */ + public getHash512(): Uint8Array { + return this.hash512; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 64; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.hash512); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/HashLockTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/HashLockTransactionBodyBuilder.ts new file mode 100644 index 0000000000..26d8158335 --- /dev/null +++ b/src/infrastructure/catbuffer/HashLockTransactionBodyBuilder.ts @@ -0,0 +1,121 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a hash lock transaction. */ +export class HashLockTransactionBodyBuilder { + /** Lock mosaic. */ + mosaic: UnresolvedMosaicBuilder; + /** Number of blocks for which a lock should be valid. */ + duration: BlockDurationDto; + /** Lock hash. */ + hash: Hash256Dto; + + /** + * Constructor. + * + * @param mosaic Lock mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hash Lock hash. + */ + public constructor(mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hash: Hash256Dto) { + this.mosaic = mosaic; + this.duration = duration; + this.hash = hash; + } + + /** + * Creates an instance of HashLockTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of HashLockTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): HashLockTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaic = UnresolvedMosaicBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaic.getSize()); + const duration = BlockDurationDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, duration.getSize()); + const hash = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, hash.getSize()); + return new HashLockTransactionBodyBuilder(mosaic, duration, hash); + } + + /** + * Gets lock mosaic. + * + * @return Lock mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.mosaic; + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.duration; + } + + /** + * Gets lock hash. + * + * @return Lock hash. + */ + public getHash(): Hash256Dto { + return this.hash; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaic.getSize(); + size += this.duration.getSize(); + size += this.hash.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicBytes = this.mosaic.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicBytes); + const durationBytes = this.duration.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, durationBytes); + const hashBytes = this.hash.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/HashLockTransactionBuilder.ts b/src/infrastructure/catbuffer/HashLockTransactionBuilder.ts new file mode 100644 index 0000000000..b6c5b9643f --- /dev/null +++ b/src/infrastructure/catbuffer/HashLockTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { BlockDurationDto } from './BlockDurationDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { HashLockTransactionBodyBuilder } from './HashLockTransactionBodyBuilder'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a non-embedded hash lock transaction. */ +export class HashLockTransactionBuilder extends TransactionBuilder { + /** Hash lock transaction body. */ + hashLockTransactionBody: HashLockTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaic Lock mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hash Lock hash. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hash: Hash256Dto) { + super(signature, signer, version, type, fee, deadline); + this.hashLockTransactionBody = new HashLockTransactionBodyBuilder(mosaic, duration, hash); + } + + /** + * Creates an instance of HashLockTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of HashLockTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): HashLockTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const hashLockTransactionBody = HashLockTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, hashLockTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new HashLockTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, hashLockTransactionBody.mosaic, hashLockTransactionBody.duration, hashLockTransactionBody.hash); + } + + /** + * Gets lock mosaic. + * + * @return Lock mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.hashLockTransactionBody.getMosaic(); + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.hashLockTransactionBody.getDuration(); + } + + /** + * Gets lock hash. + * + * @return Lock hash. + */ + public getHash(): Hash256Dto { + return this.hashLockTransactionBody.getHash(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.hashLockTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const hashLockTransactionBodyBytes = this.hashLockTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashLockTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/KeyDto.ts b/src/infrastructure/catbuffer/KeyDto.ts new file mode 100644 index 0000000000..ea1fb55242 --- /dev/null +++ b/src/infrastructure/catbuffer/KeyDto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Key. */ +export class KeyDto { + /** Key. */ + key: Uint8Array; + + /** + * Constructor. + * + * @param key Key. + */ + constructor(key: Uint8Array) { + this.key = key; + } + + /** + * Creates an instance of KeyDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of KeyDto. + */ + public static loadFromBinary(payload: Uint8Array): KeyDto { + const byteArray = Array.from(payload); + const key = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 32); + byteArray.splice(0, 32); + return new KeyDto(key); + } + + /** + * Gets Key. + * + * @return Key. + */ + public getKey(): Uint8Array { + return this.key; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 32; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.key); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/LockHashAlgorithmDto.ts b/src/infrastructure/catbuffer/LockHashAlgorithmDto.ts new file mode 100644 index 0000000000..46ed416098 --- /dev/null +++ b/src/infrastructure/catbuffer/LockHashAlgorithmDto.ts @@ -0,0 +1,33 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of lock hash algorithms. */ +export enum LockHashAlgorithmDto { + /** Input is hashed using sha-3 256. */ + SHA3_256 = 0, + /** Input is hashed using keccak 256. */ + KECCAK_256 = 1, + /** Input is hashed twice: first with sha-256 and then with ripemd-160 (bitcoin's OP_HASH160). */ + HASH_160 = 2, + /** Input is hashed twice with sha-256 (bitcoin's OP_HASH256). */ + HASH_256 = 3, +} diff --git a/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..2572bae2f0 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,158 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a mosaic address restriction transaction. */ +export class MosaicAddressRestrictionTransactionBodyBuilder { + /** Identifier of the mosaic to which the restriction applies. */ + mosaicId: UnresolvedMosaicIdDto; + /** Restriction key. */ + restrictionKey: number[]; + /** Address being restricted. */ + targetAddress: UnresolvedAddressDto; + /** Previous restriction value. */ + previousRestrictionValue: number[]; + /** New restriction value. */ + newRestrictionValue: number[]; + + /** + * Constructor. + * + * @param mosaicId Identifier of the mosaic to which the restriction applies. + * @param restrictionKey Restriction key. + * @param targetAddress Address being restricted. + * @param previousRestrictionValue Previous restriction value. + * @param newRestrictionValue New restriction value. + */ + // tslint:disable-next-line: max-line-length + public constructor(mosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], targetAddress: UnresolvedAddressDto, previousRestrictionValue: number[], newRestrictionValue: number[]) { + this.mosaicId = mosaicId; + this.restrictionKey = restrictionKey; + this.targetAddress = targetAddress; + this.previousRestrictionValue = previousRestrictionValue; + this.newRestrictionValue = newRestrictionValue; + } + + /** + * Creates an instance of MosaicAddressRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicAddressRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicAddressRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const restrictionKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const targetAddress = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetAddress.getSize()); + const previousRestrictionValue = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const newRestrictionValue = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + // tslint:disable-next-line: max-line-length + return new MosaicAddressRestrictionTransactionBodyBuilder(mosaicId, restrictionKey, targetAddress, previousRestrictionValue, newRestrictionValue); + } + + /** + * Gets identifier of the mosaic to which the restriction applies. + * + * @return Identifier of the mosaic to which the restriction applies. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicId; + } + + /** + * Gets restriction key. + * + * @return Restriction key. + */ + public getRestrictionKey(): number[] { + return this.restrictionKey; + } + + /** + * Gets address being restricted. + * + * @return Address being restricted. + */ + public getTargetAddress(): UnresolvedAddressDto { + return this.targetAddress; + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.previousRestrictionValue; + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.newRestrictionValue; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += 8; // restrictionKey + size += this.targetAddress.getSize(); + size += 8; // previousRestrictionValue + size += 8; // newRestrictionValue + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const restrictionKeyBytes = GeneratorUtils.uint64ToBuffer(this.getRestrictionKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionKeyBytes); + const targetAddressBytes = this.targetAddress.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetAddressBytes); + const previousRestrictionValueBytes = GeneratorUtils.uint64ToBuffer(this.getPreviousRestrictionValue()); + newArray = GeneratorUtils.concatTypedArrays(newArray, previousRestrictionValueBytes); + const newRestrictionValueBytes = GeneratorUtils.uint64ToBuffer(this.getNewRestrictionValue()); + newArray = GeneratorUtils.concatTypedArrays(newArray, newRestrictionValueBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..ba0d6b5d7e --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder.ts @@ -0,0 +1,146 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicAddressRestrictionTransactionBodyBuilder } from './MosaicAddressRestrictionTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a non-embedded mosaic address restriction transaction. */ +export class MosaicAddressRestrictionTransactionBuilder extends TransactionBuilder { + /** Mosaic address restriction transaction body. */ + mosaicAddressRestrictionTransactionBody: MosaicAddressRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaicId Identifier of the mosaic to which the restriction applies. + * @param restrictionKey Restriction key. + * @param targetAddress Address being restricted. + * @param previousRestrictionValue Previous restriction value. + * @param newRestrictionValue New restriction value. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], targetAddress: UnresolvedAddressDto, previousRestrictionValue: number[], newRestrictionValue: number[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.mosaicAddressRestrictionTransactionBody = new MosaicAddressRestrictionTransactionBodyBuilder(mosaicId, restrictionKey, targetAddress, previousRestrictionValue, newRestrictionValue); + } + + /** + * Creates an instance of MosaicAddressRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicAddressRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicAddressRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicAddressRestrictionTransactionBody = MosaicAddressRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicAddressRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicAddressRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicAddressRestrictionTransactionBody.mosaicId, mosaicAddressRestrictionTransactionBody.restrictionKey, mosaicAddressRestrictionTransactionBody.targetAddress, mosaicAddressRestrictionTransactionBody.previousRestrictionValue, mosaicAddressRestrictionTransactionBody.newRestrictionValue); + } + + /** + * Gets identifier of the mosaic to which the restriction applies. + * + * @return Identifier of the mosaic to which the restriction applies. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicAddressRestrictionTransactionBody.getMosaicId(); + } + + /** + * Gets restriction key. + * + * @return Restriction key. + */ + public getRestrictionKey(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getRestrictionKey(); + } + + /** + * Gets address being restricted. + * + * @return Address being restricted. + */ + public getTargetAddress(): UnresolvedAddressDto { + return this.mosaicAddressRestrictionTransactionBody.getTargetAddress(); + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getPreviousRestrictionValue(); + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getNewRestrictionValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicAddressRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicAddressRestrictionTransactionBodyBytes = this.mosaicAddressRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicAddressRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicAliasTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicAliasTransactionBodyBuilder.ts new file mode 100644 index 0000000000..6c411a6ecb --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicAliasTransactionBodyBuilder.ts @@ -0,0 +1,121 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AliasActionDto } from './AliasActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicIdDto } from './MosaicIdDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for an mosaic alias transaction. */ +export class MosaicAliasTransactionBodyBuilder { + /** Alias action. */ + aliasAction: AliasActionDto; + /** Identifier of the namespace that will become an alias. */ + namespaceId: NamespaceIdDto; + /** Aliased mosaic identifier. */ + mosaicId: MosaicIdDto; + + /** + * Constructor. + * + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param mosaicId Aliased mosaic identifier. + */ + public constructor(aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, mosaicId: MosaicIdDto) { + this.aliasAction = aliasAction; + this.namespaceId = namespaceId; + this.mosaicId = mosaicId; + } + + /** + * Creates an instance of MosaicAliasTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicAliasTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicAliasTransactionBodyBuilder { + const byteArray = Array.from(payload); + const aliasAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const namespaceId = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceId.getSize()); + const mosaicId = MosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + return new MosaicAliasTransactionBodyBuilder(aliasAction, namespaceId, mosaicId); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.aliasAction; + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.namespaceId; + } + + /** + * Gets aliased mosaic identifier. + * + * @return Aliased mosaic identifier. + */ + public getMosaicId(): MosaicIdDto { + return this.mosaicId; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // aliasAction + size += this.namespaceId.getSize(); + size += this.mosaicId.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const aliasActionBytes = GeneratorUtils.uintToBuffer(this.aliasAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, aliasActionBytes); + const namespaceIdBytes = this.namespaceId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceIdBytes); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicAliasTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicAliasTransactionBuilder.ts new file mode 100644 index 0000000000..d126fef24c --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicAliasTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AliasActionDto } from './AliasActionDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicAliasTransactionBodyBuilder } from './MosaicAliasTransactionBodyBuilder'; +import { MosaicIdDto } from './MosaicIdDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded mosaic alias transaction. */ +export class MosaicAliasTransactionBuilder extends TransactionBuilder { + /** Mosaic alias transaction body. */ + mosaicAliasTransactionBody: MosaicAliasTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param mosaicId Aliased mosaic identifier. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, mosaicId: MosaicIdDto) { + super(signature, signer, version, type, fee, deadline); + this.mosaicAliasTransactionBody = new MosaicAliasTransactionBodyBuilder(aliasAction, namespaceId, mosaicId); + } + + /** + * Creates an instance of MosaicAliasTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicAliasTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicAliasTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const mosaicAliasTransactionBody = MosaicAliasTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicAliasTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicAliasTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicAliasTransactionBody.aliasAction, mosaicAliasTransactionBody.namespaceId, mosaicAliasTransactionBody.mosaicId); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.mosaicAliasTransactionBody.getAliasAction(); + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.mosaicAliasTransactionBody.getNamespaceId(); + } + + /** + * Gets aliased mosaic identifier. + * + * @return Aliased mosaic identifier. + */ + public getMosaicId(): MosaicIdDto { + return this.mosaicAliasTransactionBody.getMosaicId(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicAliasTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicAliasTransactionBodyBytes = this.mosaicAliasTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicAliasTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicBuilder.ts b/src/infrastructure/catbuffer/MosaicBuilder.ts new file mode 100644 index 0000000000..dc2ac60e87 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicIdDto } from './MosaicIdDto'; + +/** Binary layout for a mosaic. */ +export class MosaicBuilder { + /** Mosaic identifier. */ + mosaicId: MosaicIdDto; + /** Mosaic amount. */ + amount: AmountDto; + + /** + * Constructor. + * + * @param mosaicId Mosaic identifier. + * @param amount Mosaic amount. + */ + public constructor(mosaicId: MosaicIdDto, amount: AmountDto) { + this.mosaicId = mosaicId; + this.amount = amount; + } + + /** + * Creates an instance of MosaicBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicBuilder { + const byteArray = Array.from(payload); + const mosaicId = MosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const amount = AmountDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, amount.getSize()); + return new MosaicBuilder(mosaicId, amount); + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getMosaicId(): MosaicIdDto { + return this.mosaicId; + } + + /** + * Gets mosaic amount. + * + * @return Mosaic amount. + */ + public getAmount(): AmountDto { + return this.amount; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += this.amount.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const amountBytes = this.amount.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, amountBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicDefinitionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicDefinitionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..b82254e5f7 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicDefinitionTransactionBodyBuilder.ts @@ -0,0 +1,158 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicIdDto } from './MosaicIdDto'; +import { MosaicNonceDto } from './MosaicNonceDto'; + +/** Binary layout for a mosaic definition transaction. */ +export class MosaicDefinitionTransactionBodyBuilder { + /** Mosaic nonce. */ + nonce: MosaicNonceDto; + /** Mosaic identifier. */ + id: MosaicIdDto; + /** Mosaic flags. */ + flags: number; + /** Mosaic divisibility. */ + divisibility: number; + /** Mosaic duration. */ + duration: BlockDurationDto; + + /** + * Constructor. + * + * @param nonce Mosaic nonce. + * @param id Mosaic identifier. + * @param flags Mosaic flags. + * @param divisibility Mosaic divisibility. + * @param duration Mosaic duration. + */ + // tslint:disable-next-line: max-line-length + public constructor(nonce: MosaicNonceDto, id: MosaicIdDto, flags: number, divisibility: number, duration: BlockDurationDto) { + this.nonce = nonce; + this.id = id; + this.flags = flags; + this.divisibility = divisibility; + this.duration = duration; + } + + /** + * Creates an instance of MosaicDefinitionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicDefinitionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicDefinitionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const nonce = MosaicNonceDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, nonce.getSize()); + const id = MosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, id.getSize()); + const flags = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const divisibility = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const duration = BlockDurationDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, duration.getSize()); + return new MosaicDefinitionTransactionBodyBuilder(nonce, id, flags, divisibility, duration); + } + + /** + * Gets mosaic nonce. + * + * @return Mosaic nonce. + */ + public getNonce(): MosaicNonceDto { + return this.nonce; + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getId(): MosaicIdDto { + return this.id; + } + + /** + * Gets mosaic flags. + * + * @return Mosaic flags. + */ + public getFlags(): number { + return this.flags; + } + + /** + * Gets mosaic divisibility. + * + * @return Mosaic divisibility. + */ + public getDivisibility(): number { + return this.divisibility; + } + + /** + * Gets mosaic duration. + * + * @return Mosaic duration. + */ + public getDuration(): BlockDurationDto { + return this.duration; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.nonce.getSize(); + size += this.id.getSize(); + size += 1; // flags + size += 1; // divisibility + size += this.duration.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const nonceBytes = this.nonce.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, nonceBytes); + const idBytes = this.id.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, idBytes); + const flagsBytes = GeneratorUtils.uintToBuffer(this.getFlags(), 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, flagsBytes); + const divisibilityBytes = GeneratorUtils.uintToBuffer(this.getDivisibility(), 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, divisibilityBytes); + const durationBytes = this.duration.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, durationBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicDefinitionTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicDefinitionTransactionBuilder.ts new file mode 100644 index 0000000000..a32b33b5d9 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicDefinitionTransactionBuilder.ts @@ -0,0 +1,147 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { BlockDurationDto } from './BlockDurationDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicDefinitionTransactionBodyBuilder } from './MosaicDefinitionTransactionBodyBuilder'; +import { MosaicIdDto } from './MosaicIdDto'; +import { MosaicNonceDto } from './MosaicNonceDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded mosaic definition transaction. */ +export class MosaicDefinitionTransactionBuilder extends TransactionBuilder { + /** Mosaic definition transaction body. */ + mosaicDefinitionTransactionBody: MosaicDefinitionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param nonce Mosaic nonce. + * @param id Mosaic identifier. + * @param flags Mosaic flags. + * @param divisibility Mosaic divisibility. + * @param duration Mosaic duration. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, nonce: MosaicNonceDto, id: MosaicIdDto, flags: number, divisibility: number, duration: BlockDurationDto) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.mosaicDefinitionTransactionBody = new MosaicDefinitionTransactionBodyBuilder(nonce, id, flags, divisibility, duration); + } + + /** + * Creates an instance of MosaicDefinitionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicDefinitionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicDefinitionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicDefinitionTransactionBody = MosaicDefinitionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicDefinitionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicDefinitionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicDefinitionTransactionBody.nonce, mosaicDefinitionTransactionBody.id, mosaicDefinitionTransactionBody.flags, mosaicDefinitionTransactionBody.divisibility, mosaicDefinitionTransactionBody.duration); + } + + /** + * Gets mosaic nonce. + * + * @return Mosaic nonce. + */ + public getNonce(): MosaicNonceDto { + return this.mosaicDefinitionTransactionBody.getNonce(); + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getId(): MosaicIdDto { + return this.mosaicDefinitionTransactionBody.getId(); + } + + /** + * Gets mosaic flags. + * + * @return Mosaic flags. + */ + public getFlags(): number { + return this.mosaicDefinitionTransactionBody.getFlags(); + } + + /** + * Gets mosaic divisibility. + * + * @return Mosaic divisibility. + */ + public getDivisibility(): number { + return this.mosaicDefinitionTransactionBody.getDivisibility(); + } + + /** + * Gets mosaic duration. + * + * @return Mosaic duration. + */ + public getDuration(): BlockDurationDto { + return this.mosaicDefinitionTransactionBody.getDuration(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicDefinitionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicDefinitionTransactionBodyBytes = this.mosaicDefinitionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicDefinitionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicFlagsDto.ts b/src/infrastructure/catbuffer/MosaicFlagsDto.ts new file mode 100644 index 0000000000..11a740ab03 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicFlagsDto.ts @@ -0,0 +1,33 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of mosaic property flags. */ +export enum MosaicFlagsDto { + /** No flags present. */ + NONE = 0, + /** Mosaic supports supply changes even when mosaic owner owns partial supply. */ + SUPPLY_MUTABLE = 1, + /** Mosaic supports transfers between arbitrary accounts \note when not set, mosaic can only be transferred to and from mosaic owner. */ + TRANSFERABLE = 2, + /** Mosaic supports custom restrictions configured by mosaic owner. */ + RESTRICTABLE = 4, +} diff --git a/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..09f3fd4e5e --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,194 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicRestrictionTypeDto } from './MosaicRestrictionTypeDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a mosaic global restriction transaction. */ +export class MosaicGlobalRestrictionTransactionBodyBuilder { + /** Identifier of the mosaic being restricted. */ + mosaicId: UnresolvedMosaicIdDto; + /** Identifier of the mosaic providing the restriction key. */ + referenceMosaicId: UnresolvedMosaicIdDto; + /** Restriction key relative to the reference mosaic identifier. */ + restrictionKey: number[]; + /** Previous restriction value. */ + previousRestrictionValue: number[]; + /** Previous restriction type. */ + previousRestrictionType: MosaicRestrictionTypeDto; + /** New restriction value. */ + newRestrictionValue: number[]; + /** New restriction type. */ + newRestrictionType: MosaicRestrictionTypeDto; + + /** + * Constructor. + * + * @param mosaicId Identifier of the mosaic being restricted. + * @param referenceMosaicId Identifier of the mosaic providing the restriction key. + * @param restrictionKey Restriction key relative to the reference mosaic identifier. + * @param previousRestrictionValue Previous restriction value. + * @param previousRestrictionType Previous restriction type. + * @param newRestrictionValue New restriction value. + * @param newRestrictionType New restriction type. + */ + // tslint:disable-next-line: max-line-length + public constructor(mosaicId: UnresolvedMosaicIdDto, referenceMosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], previousRestrictionValue: number[], previousRestrictionType: MosaicRestrictionTypeDto, newRestrictionValue: number[], newRestrictionType: MosaicRestrictionTypeDto) { + this.mosaicId = mosaicId; + this.referenceMosaicId = referenceMosaicId; + this.restrictionKey = restrictionKey; + this.previousRestrictionValue = previousRestrictionValue; + this.previousRestrictionType = previousRestrictionType; + this.newRestrictionValue = newRestrictionValue; + this.newRestrictionType = newRestrictionType; + } + + /** + * Creates an instance of MosaicGlobalRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicGlobalRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicGlobalRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const referenceMosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, referenceMosaicId.getSize()); + const restrictionKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const previousRestrictionValue = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const previousRestrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const newRestrictionValue = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const newRestrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + // tslint:disable-next-line: max-line-length + return new MosaicGlobalRestrictionTransactionBodyBuilder(mosaicId, referenceMosaicId, restrictionKey, previousRestrictionValue, previousRestrictionType, newRestrictionValue, newRestrictionType); + } + + /** + * Gets identifier of the mosaic being restricted. + * + * @return Identifier of the mosaic being restricted. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicId; + } + + /** + * Gets identifier of the mosaic providing the restriction key. + * + * @return Identifier of the mosaic providing the restriction key. + */ + public getReferenceMosaicId(): UnresolvedMosaicIdDto { + return this.referenceMosaicId; + } + + /** + * Gets restriction key relative to the reference mosaic identifier. + * + * @return Restriction key relative to the reference mosaic identifier. + */ + public getRestrictionKey(): number[] { + return this.restrictionKey; + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.previousRestrictionValue; + } + + /** + * Gets previous restriction type. + * + * @return Previous restriction type. + */ + public getPreviousRestrictionType(): MosaicRestrictionTypeDto { + return this.previousRestrictionType; + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.newRestrictionValue; + } + + /** + * Gets new restriction type. + * + * @return New restriction type. + */ + public getNewRestrictionType(): MosaicRestrictionTypeDto { + return this.newRestrictionType; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += this.referenceMosaicId.getSize(); + size += 8; // restrictionKey + size += 8; // previousRestrictionValue + size += 1; // previousRestrictionType + size += 8; // newRestrictionValue + size += 1; // newRestrictionType + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const referenceMosaicIdBytes = this.referenceMosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, referenceMosaicIdBytes); + const restrictionKeyBytes = GeneratorUtils.uint64ToBuffer(this.getRestrictionKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionKeyBytes); + const previousRestrictionValueBytes = GeneratorUtils.uint64ToBuffer(this.getPreviousRestrictionValue()); + newArray = GeneratorUtils.concatTypedArrays(newArray, previousRestrictionValueBytes); + const previousRestrictionTypeBytes = GeneratorUtils.uintToBuffer(this.previousRestrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, previousRestrictionTypeBytes); + const newRestrictionValueBytes = GeneratorUtils.uint64ToBuffer(this.getNewRestrictionValue()); + newArray = GeneratorUtils.concatTypedArrays(newArray, newRestrictionValueBytes); + const newRestrictionTypeBytes = GeneratorUtils.uintToBuffer(this.newRestrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, newRestrictionTypeBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..e84414e6e2 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder.ts @@ -0,0 +1,166 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicGlobalRestrictionTransactionBodyBuilder } from './MosaicGlobalRestrictionTransactionBodyBuilder'; +import { MosaicRestrictionTypeDto } from './MosaicRestrictionTypeDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a non-embedded mosaic global restriction transaction. */ +export class MosaicGlobalRestrictionTransactionBuilder extends TransactionBuilder { + /** Mosaic global restriction transaction body. */ + mosaicGlobalRestrictionTransactionBody: MosaicGlobalRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaicId Identifier of the mosaic being restricted. + * @param referenceMosaicId Identifier of the mosaic providing the restriction key. + * @param restrictionKey Restriction key relative to the reference mosaic identifier. + * @param previousRestrictionValue Previous restriction value. + * @param previousRestrictionType Previous restriction type. + * @param newRestrictionValue New restriction value. + * @param newRestrictionType New restriction type. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaicId: UnresolvedMosaicIdDto, referenceMosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], previousRestrictionValue: number[], previousRestrictionType: MosaicRestrictionTypeDto, newRestrictionValue: number[], newRestrictionType: MosaicRestrictionTypeDto) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.mosaicGlobalRestrictionTransactionBody = new MosaicGlobalRestrictionTransactionBodyBuilder(mosaicId, referenceMosaicId, restrictionKey, previousRestrictionValue, previousRestrictionType, newRestrictionValue, newRestrictionType); + } + + /** + * Creates an instance of MosaicGlobalRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicGlobalRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicGlobalRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicGlobalRestrictionTransactionBody = MosaicGlobalRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicGlobalRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicGlobalRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicGlobalRestrictionTransactionBody.mosaicId, mosaicGlobalRestrictionTransactionBody.referenceMosaicId, mosaicGlobalRestrictionTransactionBody.restrictionKey, mosaicGlobalRestrictionTransactionBody.previousRestrictionValue, mosaicGlobalRestrictionTransactionBody.previousRestrictionType, mosaicGlobalRestrictionTransactionBody.newRestrictionValue, mosaicGlobalRestrictionTransactionBody.newRestrictionType); + } + + /** + * Gets identifier of the mosaic being restricted. + * + * @return Identifier of the mosaic being restricted. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicGlobalRestrictionTransactionBody.getMosaicId(); + } + + /** + * Gets identifier of the mosaic providing the restriction key. + * + * @return Identifier of the mosaic providing the restriction key. + */ + public getReferenceMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicGlobalRestrictionTransactionBody.getReferenceMosaicId(); + } + + /** + * Gets restriction key relative to the reference mosaic identifier. + * + * @return Restriction key relative to the reference mosaic identifier. + */ + public getRestrictionKey(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getRestrictionKey(); + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getPreviousRestrictionValue(); + } + + /** + * Gets previous restriction type. + * + * @return Previous restriction type. + */ + public getPreviousRestrictionType(): MosaicRestrictionTypeDto { + return this.mosaicGlobalRestrictionTransactionBody.getPreviousRestrictionType(); + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getNewRestrictionValue(); + } + + /** + * Gets new restriction type. + * + * @return New restriction type. + */ + public getNewRestrictionType(): MosaicRestrictionTypeDto { + return this.mosaicGlobalRestrictionTransactionBody.getNewRestrictionType(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicGlobalRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicGlobalRestrictionTransactionBodyBytes = this.mosaicGlobalRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicGlobalRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicIdDto.ts b/src/infrastructure/catbuffer/MosaicIdDto.ts new file mode 100644 index 0000000000..dd88e70b01 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicIdDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Mosaic id. */ +export class MosaicIdDto { + /** Mosaic id. */ + mosaicId: number[]; + + /** + * Constructor. + * + * @param mosaicId Mosaic id. + */ + constructor(mosaicId: number[]) { + this.mosaicId = mosaicId; + } + + /** + * Creates an instance of MosaicIdDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicIdDto. + */ + public static loadFromBinary(payload: Uint8Array): MosaicIdDto { + const byteArray = Array.from(payload); + const mosaicId = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new MosaicIdDto(mosaicId); + } + + /** + * Gets Mosaic id. + * + * @return Mosaic id. + */ + public getMosaicId(): number[] { + return this.mosaicId; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = GeneratorUtils.uint64ToBuffer(this.getMosaicId()); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicMetadataTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicMetadataTransactionBodyBuilder.ts new file mode 100644 index 0000000000..a4ee75bcbc --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicMetadataTransactionBodyBuilder.ts @@ -0,0 +1,168 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a mosaic metadata transaction. */ +export class MosaicMetadataTransactionBodyBuilder { + /** Metadata target public key. */ + targetPublicKey: KeyDto; + /** Metadata key scoped to source, target and type. */ + scopedMetadataKey: number[]; + /** Target mosaic identifier. */ + targetMosaicId: UnresolvedMosaicIdDto; + /** Change in value size in bytes. */ + valueSizeDelta: number; + /** Difference between existing value and new value \note when there is no existing value, new value is same this value \note when there is an existing value, new value is calculated as xor(previous-value, value). */ + value: Uint8Array; + + /** + * Constructor. + * + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetMosaicId Target mosaic identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(targetPublicKey: KeyDto, scopedMetadataKey: number[], targetMosaicId: UnresolvedMosaicIdDto, valueSizeDelta: number, value: Uint8Array) { + this.targetPublicKey = targetPublicKey; + this.scopedMetadataKey = scopedMetadataKey; + this.targetMosaicId = targetMosaicId; + this.valueSizeDelta = valueSizeDelta; + this.value = value; + } + + /** + * Creates an instance of MosaicMetadataTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicMetadataTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicMetadataTransactionBodyBuilder { + const byteArray = Array.from(payload); + const targetPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetPublicKey.getSize()); + const scopedMetadataKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const targetMosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetMosaicId.getSize()); + const valueSizeDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const valueSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const value = GeneratorUtils.getBytes(Uint8Array.from(byteArray), valueSize); + byteArray.splice(0, valueSize); + // tslint:disable-next-line: max-line-length + return new MosaicMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetMosaicId, valueSizeDelta, value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.targetPublicKey; + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.scopedMetadataKey; + } + + /** + * Gets target mosaic identifier. + * + * @return Target mosaic identifier. + */ + public getTargetMosaicId(): UnresolvedMosaicIdDto { + return this.targetMosaicId; + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.valueSizeDelta; + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.targetPublicKey.getSize(); + size += 8; // scopedMetadataKey + size += this.targetMosaicId.getSize(); + size += 2; // valueSizeDelta + size += 2; // valueSize + size += this.value.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const targetPublicKeyBytes = this.targetPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetPublicKeyBytes); + const scopedMetadataKeyBytes = GeneratorUtils.uint64ToBuffer(this.getScopedMetadataKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, scopedMetadataKeyBytes); + const targetMosaicIdBytes = this.targetMosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetMosaicIdBytes); + const valueSizeDeltaBytes = GeneratorUtils.uintToBuffer(this.getValueSizeDelta(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeDeltaBytes); + const valueSizeBytes = GeneratorUtils.uintToBuffer(this.value.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.value); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..1a5866a030 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicMetadataTransactionBuilder.ts @@ -0,0 +1,150 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicMetadataTransactionBodyBuilder } from './MosaicMetadataTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a non-embedded mosaic metadata transaction. */ +export class MosaicMetadataTransactionBuilder extends TransactionBuilder { + /** Mosaic metadata transaction body. */ + mosaicMetadataTransactionBody: MosaicMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetMosaicId Target mosaic identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], targetMosaicId: UnresolvedMosaicIdDto, valueSizeDelta: number, value: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.mosaicMetadataTransactionBody = new MosaicMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetMosaicId, valueSizeDelta, value); + } + + /** + * Creates an instance of MosaicMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const mosaicMetadataTransactionBody = MosaicMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicMetadataTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicMetadataTransactionBody.targetPublicKey, mosaicMetadataTransactionBody.scopedMetadataKey, mosaicMetadataTransactionBody.targetMosaicId, mosaicMetadataTransactionBody.valueSizeDelta, mosaicMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.mosaicMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.mosaicMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets target mosaic identifier. + * + * @return Target mosaic identifier. + */ + public getTargetMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicMetadataTransactionBody.getTargetMosaicId(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.mosaicMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.mosaicMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicMetadataTransactionBodyBytes = this.mosaicMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicNonceDto.ts b/src/infrastructure/catbuffer/MosaicNonceDto.ts new file mode 100644 index 0000000000..82db3703e0 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicNonceDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Mosaic nonce. */ +export class MosaicNonceDto { + /** Mosaic nonce. */ + mosaicNonce: number; + + /** + * Constructor. + * + * @param mosaicNonce Mosaic nonce. + */ + constructor(mosaicNonce: number) { + this.mosaicNonce = mosaicNonce; + } + + /** + * Creates an instance of MosaicNonceDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicNonceDto. + */ + public static loadFromBinary(payload: Uint8Array): MosaicNonceDto { + const byteArray = Array.from(payload); + const mosaicNonce = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + return new MosaicNonceDto(mosaicNonce); + } + + /** + * Gets Mosaic nonce. + * + * @return Mosaic nonce. + */ + public getMosaicNonce(): number { + return this.mosaicNonce; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 4; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicNonceBytes = GeneratorUtils.uintToBuffer(this.getMosaicNonce(), 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicNonceBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicRestrictionTypeDto.ts b/src/infrastructure/catbuffer/MosaicRestrictionTypeDto.ts new file mode 100644 index 0000000000..78b5f8d179 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicRestrictionTypeDto.ts @@ -0,0 +1,39 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of mosaic restriction types. */ +export enum MosaicRestrictionTypeDto { + /** Uninitialized value indicating no restriction. */ + NONE = 0, + /** Allow if equal. */ + EQ = 1, + /** Allow if not equal. */ + NE = 2, + /** Allow if less than. */ + LT = 3, + /** Allow if less than or equal. */ + LE = 4, + /** Allow if greater than. */ + GT = 5, + /** Allow if greater than or equal. */ + GE = 6, +} diff --git a/src/infrastructure/catbuffer/MosaicSupplyChangeActionDto.ts b/src/infrastructure/catbuffer/MosaicSupplyChangeActionDto.ts new file mode 100644 index 0000000000..eafa2d5b4e --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicSupplyChangeActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of mosaic supply change actions. */ +export enum MosaicSupplyChangeActionDto { + /** Decreases the supply. */ + DECREASE = 0, + /** Increases the supply. */ + INCREASE = 1, +} diff --git a/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBodyBuilder.ts new file mode 100644 index 0000000000..6e9a680728 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBodyBuilder.ts @@ -0,0 +1,121 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicSupplyChangeActionDto } from './MosaicSupplyChangeActionDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a mosaic supply change transaction. */ +export class MosaicSupplyChangeTransactionBodyBuilder { + /** Affected mosaic identifier. */ + mosaicId: UnresolvedMosaicIdDto; + /** Supply change action. */ + action: MosaicSupplyChangeActionDto; + /** Change amount. */ + delta: AmountDto; + + /** + * Constructor. + * + * @param mosaicId Affected mosaic identifier. + * @param action Supply change action. + * @param delta Change amount. + */ + public constructor(mosaicId: UnresolvedMosaicIdDto, action: MosaicSupplyChangeActionDto, delta: AmountDto) { + this.mosaicId = mosaicId; + this.action = action; + this.delta = delta; + } + + /** + * Creates an instance of MosaicSupplyChangeTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicSupplyChangeTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicSupplyChangeTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const action = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const delta = AmountDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, delta.getSize()); + return new MosaicSupplyChangeTransactionBodyBuilder(mosaicId, action, delta); + } + + /** + * Gets affected mosaic identifier. + * + * @return Affected mosaic identifier. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicId; + } + + /** + * Gets supply change action. + * + * @return Supply change action. + */ + public getAction(): MosaicSupplyChangeActionDto { + return this.action; + } + + /** + * Gets change amount. + * + * @return Change amount. + */ + public getDelta(): AmountDto { + return this.delta; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += 1; // action + size += this.delta.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const actionBytes = GeneratorUtils.uintToBuffer(this.action, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, actionBytes); + const deltaBytes = this.delta.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, deltaBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder.ts new file mode 100644 index 0000000000..ae1c675729 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicSupplyChangeActionDto } from './MosaicSupplyChangeActionDto'; +import { MosaicSupplyChangeTransactionBodyBuilder } from './MosaicSupplyChangeTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a non-embedded mosaic supply change transaction. */ +export class MosaicSupplyChangeTransactionBuilder extends TransactionBuilder { + /** Mosaic supply change transaction body. */ + mosaicSupplyChangeTransactionBody: MosaicSupplyChangeTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaicId Affected mosaic identifier. + * @param action Supply change action. + * @param delta Change amount. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaicId: UnresolvedMosaicIdDto, action: MosaicSupplyChangeActionDto, delta: AmountDto) { + super(signature, signer, version, type, fee, deadline); + this.mosaicSupplyChangeTransactionBody = new MosaicSupplyChangeTransactionBodyBuilder(mosaicId, action, delta); + } + + /** + * Creates an instance of MosaicSupplyChangeTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicSupplyChangeTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicSupplyChangeTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicSupplyChangeTransactionBody = MosaicSupplyChangeTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicSupplyChangeTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicSupplyChangeTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicSupplyChangeTransactionBody.mosaicId, mosaicSupplyChangeTransactionBody.action, mosaicSupplyChangeTransactionBody.delta); + } + + /** + * Gets affected mosaic identifier. + * + * @return Affected mosaic identifier. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicSupplyChangeTransactionBody.getMosaicId(); + } + + /** + * Gets supply change action. + * + * @return Supply change action. + */ + public getAction(): MosaicSupplyChangeActionDto { + return this.mosaicSupplyChangeTransactionBody.getAction(); + } + + /** + * Gets change amount. + * + * @return Change amount. + */ + public getDelta(): AmountDto { + return this.mosaicSupplyChangeTransactionBody.getDelta(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicSupplyChangeTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicSupplyChangeTransactionBodyBytes = this.mosaicSupplyChangeTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicSupplyChangeTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBodyBuilder.ts new file mode 100644 index 0000000000..9f646f89cb --- /dev/null +++ b/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBodyBuilder.ts @@ -0,0 +1,131 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { CosignatoryModificationBuilder } from './CosignatoryModificationBuilder'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for a multisig account modification transaction. */ +export class MultisigAccountModificationTransactionBodyBuilder { + /** Relative change of the minimal number of cosignatories required when removing an account. */ + minRemovalDelta: number; + /** Relative change of the minimal number of cosignatories required when approving a transaction. */ + minApprovalDelta: number; + /** Attached cosignatory modifications. */ + modifications: CosignatoryModificationBuilder[]; + + /** + * Constructor. + * + * @param minRemovalDelta Relative change of the minimal number of cosignatories required when removing an account. + * @param minApprovalDelta Relative change of the minimal number of cosignatories required when approving a transaction. + * @param modifications Attached cosignatory modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(minRemovalDelta: number, minApprovalDelta: number, modifications: CosignatoryModificationBuilder[]) { + this.minRemovalDelta = minRemovalDelta; + this.minApprovalDelta = minApprovalDelta; + this.modifications = modifications; + } + + /** + * Creates an instance of MultisigAccountModificationTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MultisigAccountModificationTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MultisigAccountModificationTransactionBodyBuilder { + const byteArray = Array.from(payload); + const minRemovalDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const minApprovalDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modificationsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modifications: CosignatoryModificationBuilder[] = []; + for (let i = 0; i < modificationsCount; i++) { + const item = CosignatoryModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + modifications.push(item); + byteArray.splice(0, item.getSize()); + } + return new MultisigAccountModificationTransactionBodyBuilder(minRemovalDelta, minApprovalDelta, modifications); + } + + /** + * Gets relative change of the minimal number of cosignatories required when removing an account. + * + * @return Relative change of the minimal number of cosignatories required when removing an account. + */ + public getMinRemovalDelta(): number { + return this.minRemovalDelta; + } + + /** + * Gets relative change of the minimal number of cosignatories required when approving a transaction. + * + * @return Relative change of the minimal number of cosignatories required when approving a transaction. + */ + public getMinApprovalDelta(): number { + return this.minApprovalDelta; + } + + /** + * Gets attached cosignatory modifications. + * + * @return Attached cosignatory modifications. + */ + public getModifications(): CosignatoryModificationBuilder[] { + return this.modifications; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // minRemovalDelta + size += 1; // minApprovalDelta + size += 1; // modificationsCount + this.modifications.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const minRemovalDeltaBytes = GeneratorUtils.uintToBuffer(this.getMinRemovalDelta(), 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, minRemovalDeltaBytes); + const minApprovalDeltaBytes = GeneratorUtils.uintToBuffer(this.getMinApprovalDelta(), 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, minApprovalDeltaBytes); + const modificationsCountBytes = GeneratorUtils.uintToBuffer(this.modifications.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsCountBytes); + this.modifications.forEach((item) => { + const modificationsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder.ts b/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder.ts new file mode 100644 index 0000000000..4405bdc6ca --- /dev/null +++ b/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { CosignatoryModificationBuilder } from './CosignatoryModificationBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MultisigAccountModificationTransactionBodyBuilder } from './MultisigAccountModificationTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded multisig account modification transaction. */ +export class MultisigAccountModificationTransactionBuilder extends TransactionBuilder { + /** Multisig account modification transaction body. */ + multisigAccountModificationTransactionBody: MultisigAccountModificationTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param minRemovalDelta Relative change of the minimal number of cosignatories required when removing an account. + * @param minApprovalDelta Relative change of the minimal number of cosignatories required when approving a transaction. + * @param modifications Attached cosignatory modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, minRemovalDelta: number, minApprovalDelta: number, modifications: CosignatoryModificationBuilder[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.multisigAccountModificationTransactionBody = new MultisigAccountModificationTransactionBodyBuilder(minRemovalDelta, minApprovalDelta, modifications); + } + + /** + * Creates an instance of MultisigAccountModificationTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MultisigAccountModificationTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MultisigAccountModificationTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const multisigAccountModificationTransactionBody = MultisigAccountModificationTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, multisigAccountModificationTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MultisigAccountModificationTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, multisigAccountModificationTransactionBody.minRemovalDelta, multisigAccountModificationTransactionBody.minApprovalDelta, multisigAccountModificationTransactionBody.modifications); + } + + /** + * Gets relative change of the minimal number of cosignatories required when removing an account. + * + * @return Relative change of the minimal number of cosignatories required when removing an account. + */ + public getMinRemovalDelta(): number { + return this.multisigAccountModificationTransactionBody.getMinRemovalDelta(); + } + + /** + * Gets relative change of the minimal number of cosignatories required when approving a transaction. + * + * @return Relative change of the minimal number of cosignatories required when approving a transaction. + */ + public getMinApprovalDelta(): number { + return this.multisigAccountModificationTransactionBody.getMinApprovalDelta(); + } + + /** + * Gets attached cosignatory modifications. + * + * @return Attached cosignatory modifications. + */ + public getModifications(): CosignatoryModificationBuilder[] { + return this.multisigAccountModificationTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.multisigAccountModificationTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const multisigAccountModificationTransactionBodyBytes = this.multisigAccountModificationTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, multisigAccountModificationTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceIdDto.ts b/src/infrastructure/catbuffer/NamespaceIdDto.ts new file mode 100644 index 0000000000..498f63dbe3 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceIdDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Namespace id. */ +export class NamespaceIdDto { + /** Namespace id. */ + namespaceId: number[]; + + /** + * Constructor. + * + * @param namespaceId Namespace id. + */ + constructor(namespaceId: number[]) { + this.namespaceId = namespaceId; + } + + /** + * Creates an instance of NamespaceIdDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceIdDto. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceIdDto { + const byteArray = Array.from(payload); + const namespaceId = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new NamespaceIdDto(namespaceId); + } + + /** + * Gets Namespace id. + * + * @return Namespace id. + */ + public getNamespaceId(): number[] { + return this.namespaceId; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const namespaceIdBytes = GeneratorUtils.uint64ToBuffer(this.getNamespaceId()); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceIdBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceMetadataTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/NamespaceMetadataTransactionBodyBuilder.ts new file mode 100644 index 0000000000..f460ab3c25 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceMetadataTransactionBodyBuilder.ts @@ -0,0 +1,168 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for a namespace metadata transaction. */ +export class NamespaceMetadataTransactionBodyBuilder { + /** Metadata target public key. */ + targetPublicKey: KeyDto; + /** Metadata key scoped to source, target and type. */ + scopedMetadataKey: number[]; + /** Target namespace identifier. */ + targetNamespaceId: NamespaceIdDto; + /** Change in value size in bytes. */ + valueSizeDelta: number; + /** Difference between existing value and new value \note when there is no existing value, new value is same this value \note when there is an existing value, new value is calculated as xor(previous-value, value). */ + value: Uint8Array; + + /** + * Constructor. + * + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetNamespaceId Target namespace identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(targetPublicKey: KeyDto, scopedMetadataKey: number[], targetNamespaceId: NamespaceIdDto, valueSizeDelta: number, value: Uint8Array) { + this.targetPublicKey = targetPublicKey; + this.scopedMetadataKey = scopedMetadataKey; + this.targetNamespaceId = targetNamespaceId; + this.valueSizeDelta = valueSizeDelta; + this.value = value; + } + + /** + * Creates an instance of NamespaceMetadataTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceMetadataTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceMetadataTransactionBodyBuilder { + const byteArray = Array.from(payload); + const targetPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetPublicKey.getSize()); + const scopedMetadataKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const targetNamespaceId = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetNamespaceId.getSize()); + const valueSizeDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const valueSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const value = GeneratorUtils.getBytes(Uint8Array.from(byteArray), valueSize); + byteArray.splice(0, valueSize); + // tslint:disable-next-line: max-line-length + return new NamespaceMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetNamespaceId, valueSizeDelta, value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.targetPublicKey; + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.scopedMetadataKey; + } + + /** + * Gets target namespace identifier. + * + * @return Target namespace identifier. + */ + public getTargetNamespaceId(): NamespaceIdDto { + return this.targetNamespaceId; + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.valueSizeDelta; + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.targetPublicKey.getSize(); + size += 8; // scopedMetadataKey + size += this.targetNamespaceId.getSize(); + size += 2; // valueSizeDelta + size += 2; // valueSize + size += this.value.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const targetPublicKeyBytes = this.targetPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetPublicKeyBytes); + const scopedMetadataKeyBytes = GeneratorUtils.uint64ToBuffer(this.getScopedMetadataKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, scopedMetadataKeyBytes); + const targetNamespaceIdBytes = this.targetNamespaceId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetNamespaceIdBytes); + const valueSizeDeltaBytes = GeneratorUtils.uintToBuffer(this.getValueSizeDelta(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeDeltaBytes); + const valueSizeBytes = GeneratorUtils.uintToBuffer(this.value.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.value); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/NamespaceMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..6b4b2e4885 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceMetadataTransactionBuilder.ts @@ -0,0 +1,151 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceMetadataTransactionBodyBuilder } from './NamespaceMetadataTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded namespace metadata transaction. */ +export class NamespaceMetadataTransactionBuilder extends TransactionBuilder { + /** Namespace metadata transaction body. */ + namespaceMetadataTransactionBody: NamespaceMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetNamespaceId Target namespace identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], targetNamespaceId: NamespaceIdDto, valueSizeDelta: number, value: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.namespaceMetadataTransactionBody = new NamespaceMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetNamespaceId, valueSizeDelta, value); + } + + /** + * Creates an instance of NamespaceMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const namespaceMetadataTransactionBody = NamespaceMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new NamespaceMetadataTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, namespaceMetadataTransactionBody.targetPublicKey, namespaceMetadataTransactionBody.scopedMetadataKey, namespaceMetadataTransactionBody.targetNamespaceId, namespaceMetadataTransactionBody.valueSizeDelta, namespaceMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.namespaceMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.namespaceMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets target namespace identifier. + * + * @return Target namespace identifier. + */ + public getTargetNamespaceId(): NamespaceIdDto { + return this.namespaceMetadataTransactionBody.getTargetNamespaceId(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.namespaceMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.namespaceMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.namespaceMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const namespaceMetadataTransactionBodyBytes = this.namespaceMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBodyBuilder.ts new file mode 100644 index 0000000000..465636812f --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBodyBuilder.ts @@ -0,0 +1,188 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceRegistrationTypeDto } from './NamespaceRegistrationTypeDto'; + +/** Binary layout for a namespace registration transaction. */ +export class NamespaceRegistrationTransactionBodyBuilder { + /** Namespace registration type. */ + registrationType: NamespaceRegistrationTypeDto; + /** Namespace duration. */ + duration?: BlockDurationDto; + /** Parent namespace identifier. */ + parentId?: NamespaceIdDto; + /** Namespace identifier. */ + id: NamespaceIdDto; + /** Namespace name. */ + name: Uint8Array; + + /** + * Constructor. + * + * @param duration Namespace duration. + * @param parentId Parent namespace identifier. + * @param id Namespace identifier. + * @param name Namespace name. + */ + public constructor(id: NamespaceIdDto, name: Uint8Array, duration?: BlockDurationDto, parentId?: NamespaceIdDto) { + if ((duration && parentId) || (!duration && !parentId)) { + throw new Error('Invalid conditional parameters'); + } + this.duration = duration; + this.parentId = parentId; + this.id = id; + this.name = name; + if (duration) { + this.registrationType = NamespaceRegistrationTypeDto.ROOT; + } + if (parentId) { + this.registrationType = NamespaceRegistrationTypeDto.CHILD; + } + } + + /** + * Creates an instance of NamespaceRegistrationTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceRegistrationTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceRegistrationTransactionBodyBuilder { + const byteArray = Array.from(payload); + const registrationType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + let duration; + if (registrationType === NamespaceRegistrationTypeDto.ROOT) { + duration = BlockDurationDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, duration.getSize()); + } + let parentId; + if (registrationType === NamespaceRegistrationTypeDto.CHILD) { + parentId = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, parentId.getSize()); + } + const id = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, id.getSize()); + const nameSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const name = GeneratorUtils.getBytes(Uint8Array.from(byteArray), nameSize); + byteArray.splice(0, nameSize); + return new NamespaceRegistrationTransactionBodyBuilder(id, name, duration, parentId); + } + + /** + * Gets namespace registration type. + * + * @return Namespace registration type. + */ + public getRegistrationType(): NamespaceRegistrationTypeDto { + return this.registrationType; + } + + /** + * Gets namespace duration. + * + * @return Namespace duration. + */ + public getDuration(): BlockDurationDto | undefined { + if (this.registrationType !== NamespaceRegistrationTypeDto.ROOT) { + throw new Error('registrationType is not set to ROOT.'); + } + return this.duration; + } + + /** + * Gets parent namespace identifier. + * + * @return Parent namespace identifier. + */ + public getParentId(): NamespaceIdDto | undefined { + if (this.registrationType !== NamespaceRegistrationTypeDto.CHILD) { + throw new Error('registrationType is not set to CHILD.'); + } + return this.parentId; + } + + /** + * Gets namespace identifier. + * + * @return Namespace identifier. + */ + public getId(): NamespaceIdDto { + return this.id; + } + + /** + * Gets namespace name. + * + * @return Namespace name. + */ + public getName(): Uint8Array { + return this.name; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // registrationType + if (this.registrationType === NamespaceRegistrationTypeDto.ROOT) { + size += this.duration!.getSize(); + } + if (this.registrationType === NamespaceRegistrationTypeDto.CHILD) { + size += this.parentId!.getSize(); + } + size += this.id.getSize(); + size += 1; // nameSize + size += this.name.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const registrationTypeBytes = GeneratorUtils.uintToBuffer(this.registrationType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, registrationTypeBytes); + if (this.registrationType === NamespaceRegistrationTypeDto.ROOT) { + const durationBytes = this.duration!.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, durationBytes); + } + if (this.registrationType === NamespaceRegistrationTypeDto.CHILD) { + const parentIdBytes = this.parentId!.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, parentIdBytes); + } + const idBytes = this.id.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, idBytes); + const nameSizeBytes = GeneratorUtils.uintToBuffer(this.name.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, nameSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.name); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder.ts b/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder.ts new file mode 100644 index 0000000000..a9e96db248 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder.ts @@ -0,0 +1,149 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { BlockDurationDto } from './BlockDurationDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceRegistrationTransactionBodyBuilder } from './NamespaceRegistrationTransactionBodyBuilder'; +import { NamespaceRegistrationTypeDto } from './NamespaceRegistrationTypeDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded namespace registration transaction. */ +export class NamespaceRegistrationTransactionBuilder extends TransactionBuilder { + /** Namespace registration transaction body. */ + namespaceRegistrationTransactionBody: NamespaceRegistrationTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param duration Namespace duration. + * @param parentId Parent namespace identifier. + * @param id Namespace identifier. + * @param name Namespace name. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, id: NamespaceIdDto, name: Uint8Array, duration?: BlockDurationDto, parentId?: NamespaceIdDto) { + super(signature, signer, version, type, fee, deadline); + if ((duration && parentId) || (!duration && !parentId)) { + throw new Error('Invalid conditional parameters'); + } + // tslint:disable-next-line: max-line-length + this.namespaceRegistrationTransactionBody = new NamespaceRegistrationTransactionBodyBuilder(id, name, duration, parentId); + } + + /** + * Creates an instance of NamespaceRegistrationTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceRegistrationTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceRegistrationTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const namespaceRegistrationTransactionBody = NamespaceRegistrationTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceRegistrationTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new NamespaceRegistrationTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, namespaceRegistrationTransactionBody.id, namespaceRegistrationTransactionBody.name, namespaceRegistrationTransactionBody.duration, namespaceRegistrationTransactionBody.parentId); + } + + /** + * Gets namespace registration type. + * + * @return Namespace registration type. + */ + public getRegistrationType(): NamespaceRegistrationTypeDto { + return this.namespaceRegistrationTransactionBody.getRegistrationType(); + } + + /** + * Gets namespace duration. + * + * @return Namespace duration. + */ + public getDuration(): BlockDurationDto | undefined { + return this.namespaceRegistrationTransactionBody.getDuration(); + } + + /** + * Gets parent namespace identifier. + * + * @return Parent namespace identifier. + */ + public getParentId(): NamespaceIdDto | undefined { + return this.namespaceRegistrationTransactionBody.getParentId(); + } + + /** + * Gets namespace identifier. + * + * @return Namespace identifier. + */ + public getId(): NamespaceIdDto { + return this.namespaceRegistrationTransactionBody.getId(); + } + + /** + * Gets namespace name. + * + * @return Namespace name. + */ + public getName(): Uint8Array { + return this.namespaceRegistrationTransactionBody.getName(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.namespaceRegistrationTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const namespaceRegistrationTransactionBodyBytes = this.namespaceRegistrationTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceRegistrationTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceRegistrationTypeDto.ts b/src/infrastructure/catbuffer/NamespaceRegistrationTypeDto.ts new file mode 100644 index 0000000000..349db68025 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceRegistrationTypeDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of namespace registration types. */ +export enum NamespaceRegistrationTypeDto { + /** Root namespace. */ + ROOT = 0, + /** Child namespace. */ + CHILD = 1, +} diff --git a/src/infrastructure/catbuffer/SecretLockTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/SecretLockTransactionBodyBuilder.ts new file mode 100644 index 0000000000..a38da76d77 --- /dev/null +++ b/src/infrastructure/catbuffer/SecretLockTransactionBodyBuilder.ts @@ -0,0 +1,160 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a secret lock transaction. */ +export class SecretLockTransactionBodyBuilder { + /** Locked mosaic. */ + mosaic: UnresolvedMosaicBuilder; + /** Number of blocks for which a lock should be valid. */ + duration: BlockDurationDto; + /** Hash algorithm. */ + hashAlgorithm: LockHashAlgorithmDto; + /** Secret. */ + secret: Hash256Dto; + /** Locked mosaic recipient. */ + recipient: UnresolvedAddressDto; + + /** + * Constructor. + * + * @param mosaic Locked mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Locked mosaic recipient. + */ + // tslint:disable-next-line: max-line-length + public constructor(mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto) { + this.mosaic = mosaic; + this.duration = duration; + this.hashAlgorithm = hashAlgorithm; + this.secret = secret; + this.recipient = recipient; + } + + /** + * Creates an instance of SecretLockTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SecretLockTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): SecretLockTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaic = UnresolvedMosaicBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaic.getSize()); + const duration = BlockDurationDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, duration.getSize()); + const hashAlgorithm = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const secret = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secret.getSize()); + const recipient = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, recipient.getSize()); + return new SecretLockTransactionBodyBuilder(mosaic, duration, hashAlgorithm, secret, recipient); + } + + /** + * Gets locked mosaic. + * + * @return Locked mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.mosaic; + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.duration; + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.hashAlgorithm; + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secret; + } + + /** + * Gets locked mosaic recipient. + * + * @return Locked mosaic recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.recipient; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaic.getSize(); + size += this.duration.getSize(); + size += 1; // hashAlgorithm + size += this.secret.getSize(); + size += this.recipient.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicBytes = this.mosaic.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicBytes); + const durationBytes = this.duration.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, durationBytes); + const hashAlgorithmBytes = GeneratorUtils.uintToBuffer(this.hashAlgorithm, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashAlgorithmBytes); + const secretBytes = this.secret.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretBytes); + const recipientBytes = this.recipient.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, recipientBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/SecretLockTransactionBuilder.ts b/src/infrastructure/catbuffer/SecretLockTransactionBuilder.ts new file mode 100644 index 0000000000..3f99ae1dd0 --- /dev/null +++ b/src/infrastructure/catbuffer/SecretLockTransactionBuilder.ts @@ -0,0 +1,148 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { BlockDurationDto } from './BlockDurationDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { KeyDto } from './KeyDto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { SecretLockTransactionBodyBuilder } from './SecretLockTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a non-embedded secret lock transaction. */ +export class SecretLockTransactionBuilder extends TransactionBuilder { + /** Secret lock transaction body. */ + secretLockTransactionBody: SecretLockTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaic Locked mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Locked mosaic recipient. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.secretLockTransactionBody = new SecretLockTransactionBodyBuilder(mosaic, duration, hashAlgorithm, secret, recipient); + } + + /** + * Creates an instance of SecretLockTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SecretLockTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): SecretLockTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const secretLockTransactionBody = SecretLockTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secretLockTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new SecretLockTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, secretLockTransactionBody.mosaic, secretLockTransactionBody.duration, secretLockTransactionBody.hashAlgorithm, secretLockTransactionBody.secret, secretLockTransactionBody.recipient); + } + + /** + * Gets locked mosaic. + * + * @return Locked mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.secretLockTransactionBody.getMosaic(); + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.secretLockTransactionBody.getDuration(); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.secretLockTransactionBody.getHashAlgorithm(); + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secretLockTransactionBody.getSecret(); + } + + /** + * Gets locked mosaic recipient. + * + * @return Locked mosaic recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.secretLockTransactionBody.getRecipient(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.secretLockTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const secretLockTransactionBodyBytes = this.secretLockTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretLockTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/SecretProofTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/SecretProofTransactionBodyBuilder.ts new file mode 100644 index 0000000000..ba7a2a1fa2 --- /dev/null +++ b/src/infrastructure/catbuffer/SecretProofTransactionBodyBuilder.ts @@ -0,0 +1,144 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; + +/** Binary layout for a secret proof transaction. */ +export class SecretProofTransactionBodyBuilder { + /** Hash algorithm. */ + hashAlgorithm: LockHashAlgorithmDto; + /** Secret. */ + secret: Hash256Dto; + /** Recipient. */ + recipient: UnresolvedAddressDto; + /** Proof data. */ + proof: Uint8Array; + + /** + * Constructor. + * + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Recipient. + * @param proof Proof data. + */ + // tslint:disable-next-line: max-line-length + public constructor(hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto, proof: Uint8Array) { + this.hashAlgorithm = hashAlgorithm; + this.secret = secret; + this.recipient = recipient; + this.proof = proof; + } + + /** + * Creates an instance of SecretProofTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SecretProofTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): SecretProofTransactionBodyBuilder { + const byteArray = Array.from(payload); + const hashAlgorithm = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const secret = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secret.getSize()); + const recipient = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, recipient.getSize()); + const proofSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const proof = GeneratorUtils.getBytes(Uint8Array.from(byteArray), proofSize); + byteArray.splice(0, proofSize); + return new SecretProofTransactionBodyBuilder(hashAlgorithm, secret, recipient, proof); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.hashAlgorithm; + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secret; + } + + /** + * Gets recipient. + * + * @return Recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.recipient; + } + + /** + * Gets proof data. + * + * @return Proof data. + */ + public getProof(): Uint8Array { + return this.proof; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // hashAlgorithm + size += this.secret.getSize(); + size += this.recipient.getSize(); + size += 2; // proofSize + size += this.proof.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const hashAlgorithmBytes = GeneratorUtils.uintToBuffer(this.hashAlgorithm, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashAlgorithmBytes); + const secretBytes = this.secret.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretBytes); + const recipientBytes = this.recipient.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, recipientBytes); + const proofSizeBytes = GeneratorUtils.uintToBuffer(this.proof.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, proofSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.proof); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/SecretProofTransactionBuilder.ts b/src/infrastructure/catbuffer/SecretProofTransactionBuilder.ts new file mode 100644 index 0000000000..445a74e418 --- /dev/null +++ b/src/infrastructure/catbuffer/SecretProofTransactionBuilder.ts @@ -0,0 +1,135 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { KeyDto } from './KeyDto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { SecretProofTransactionBodyBuilder } from './SecretProofTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; + +/** Binary layout for a non-embedded secret proof transaction. */ +export class SecretProofTransactionBuilder extends TransactionBuilder { + /** Secret proof transaction body. */ + secretProofTransactionBody: SecretProofTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Recipient. + * @param proof Proof data. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto, proof: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + this.secretProofTransactionBody = new SecretProofTransactionBodyBuilder(hashAlgorithm, secret, recipient, proof); + } + + /** + * Creates an instance of SecretProofTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SecretProofTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): SecretProofTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const secretProofTransactionBody = SecretProofTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secretProofTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new SecretProofTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, secretProofTransactionBody.hashAlgorithm, secretProofTransactionBody.secret, secretProofTransactionBody.recipient, secretProofTransactionBody.proof); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.secretProofTransactionBody.getHashAlgorithm(); + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secretProofTransactionBody.getSecret(); + } + + /** + * Gets recipient. + * + * @return Recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.secretProofTransactionBody.getRecipient(); + } + + /** + * Gets proof data. + * + * @return Proof data. + */ + public getProof(): Uint8Array { + return this.secretProofTransactionBody.getProof(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.secretProofTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const secretProofTransactionBodyBytes = this.secretProofTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretProofTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/SignatureDto.ts b/src/infrastructure/catbuffer/SignatureDto.ts new file mode 100644 index 0000000000..307efb2b50 --- /dev/null +++ b/src/infrastructure/catbuffer/SignatureDto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Signature. */ +export class SignatureDto { + /** Signature. */ + signature: Uint8Array; + + /** + * Constructor. + * + * @param signature Signature. + */ + constructor(signature: Uint8Array) { + this.signature = signature; + } + + /** + * Creates an instance of SignatureDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SignatureDto. + */ + public static loadFromBinary(payload: Uint8Array): SignatureDto { + const byteArray = Array.from(payload); + const signature = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 64); + byteArray.splice(0, 64); + return new SignatureDto(signature); + } + + /** + * Gets Signature. + * + * @return Signature. + */ + public getSignature(): Uint8Array { + return this.signature; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 64; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.signature); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/TimestampDto.ts b/src/infrastructure/catbuffer/TimestampDto.ts new file mode 100644 index 0000000000..af3de24b9e --- /dev/null +++ b/src/infrastructure/catbuffer/TimestampDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Timestamp. */ +export class TimestampDto { + /** Timestamp. */ + timestamp: number[]; + + /** + * Constructor. + * + * @param timestamp Timestamp. + */ + constructor(timestamp: number[]) { + this.timestamp = timestamp; + } + + /** + * Creates an instance of TimestampDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of TimestampDto. + */ + public static loadFromBinary(payload: Uint8Array): TimestampDto { + const byteArray = Array.from(payload); + const timestamp = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new TimestampDto(timestamp); + } + + /** + * Gets Timestamp. + * + * @return Timestamp. + */ + public getTimestamp(): number[] { + return this.timestamp; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const timestampBytes = GeneratorUtils.uint64ToBuffer(this.getTimestamp()); + newArray = GeneratorUtils.concatTypedArrays(newArray, timestampBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/TransactionBuilder.ts b/src/infrastructure/catbuffer/TransactionBuilder.ts new file mode 100644 index 0000000000..e50a3024be --- /dev/null +++ b/src/infrastructure/catbuffer/TransactionBuilder.ts @@ -0,0 +1,185 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; + +/** Binary layout for a transaction. */ +export class TransactionBuilder { + /** Entity size. */ + size = 0; + /** Entity signature. */ + signature: SignatureDto; + /** Entity signer's public key. */ + signer: KeyDto; + /** Entity version. */ + version: number; + /** Entity type. */ + type: EntityTypeDto; + /** Transaction fee. */ + fee: AmountDto; + /** Transaction deadline. */ + deadline: TimestampDto; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto) { + this.signature = signature; + this.signer = signer; + this.version = version; + this.type = type; + this.fee = fee; + this.deadline = deadline; + } + + /** + * Creates an instance of TransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of TransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): TransactionBuilder { + const byteArray = Array.from(payload); + const size = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + const signature = SignatureDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signature.getSize()); + const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signer.getSize()); + const version = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const type = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const fee = AmountDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, fee.getSize()); + const deadline = TimestampDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, deadline.getSize()); + return new TransactionBuilder(signature, signer, version, type, fee, deadline); + } + + /** + * Gets entity signature. + * + * @return Entity signature. + */ + public getSignature(): SignatureDto { + return this.signature; + } + + /** + * Gets entity signer's public key. + * + * @return Entity signer's public key. + */ + public getSigner(): KeyDto { + return this.signer; + } + + /** + * Gets entity version. + * + * @return Entity version. + */ + public getVersion(): number { + return this.version; + } + + /** + * Gets entity type. + * + * @return Entity type. + */ + public getType(): EntityTypeDto { + return this.type; + } + + /** + * Gets transaction fee.. + * + * @return Transaction fee. + */ + public getFee(): AmountDto { + return this.fee; + } + + /** + * Gets transaction deadline. + * + * @return Transaction deadline. + */ + public getDeadline(): TimestampDto { + return this.deadline; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 4; // size + size += this.signature.getSize(); + size += this.signer.getSize(); + size += 2; // version + size += 2; // type + size += this.fee.getSize(); + size += this.deadline.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const sizeBytes = GeneratorUtils.uintToBuffer(this.getSize(), 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, sizeBytes); + const signatureBytes = this.signature.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signatureBytes); + const signerBytes = this.signer.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); + const versionBytes = GeneratorUtils.uintToBuffer(this.getVersion(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, versionBytes); + const typeBytes = GeneratorUtils.uintToBuffer(this.type, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, typeBytes); + const feeBytes = this.fee.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, feeBytes); + const deadlineBytes = this.deadline.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, deadlineBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/TransferTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/TransferTransactionBodyBuilder.ts new file mode 100644 index 0000000000..e0ee7daed1 --- /dev/null +++ b/src/infrastructure/catbuffer/TransferTransactionBodyBuilder.ts @@ -0,0 +1,135 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a transfer transaction. */ +export class TransferTransactionBodyBuilder { + /** Transaction recipient. */ + recipient: UnresolvedAddressDto; + /** Transaction message. */ + message: Uint8Array; + /** Attached mosaics. */ + mosaics: UnresolvedMosaicBuilder[]; + + /** + * Constructor. + * + * @param recipient Transaction recipient. + * @param message Transaction message. + * @param mosaics Attached mosaics. + */ + public constructor(recipient: UnresolvedAddressDto, message: Uint8Array, mosaics: UnresolvedMosaicBuilder[]) { + this.recipient = recipient; + this.message = message; + this.mosaics = mosaics; + } + + /** + * Creates an instance of TransferTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of TransferTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): TransferTransactionBodyBuilder { + const byteArray = Array.from(payload); + const recipient = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, recipient.getSize()); + const messageSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const mosaicsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const message = GeneratorUtils.getBytes(Uint8Array.from(byteArray), messageSize); + byteArray.splice(0, messageSize); + const mosaics: UnresolvedMosaicBuilder[] = []; + for (let i = 0; i < mosaicsCount; i++) { + const item = UnresolvedMosaicBuilder.loadFromBinary(Uint8Array.from(byteArray)); + mosaics.push(item); + byteArray.splice(0, item.getSize()); + } + return new TransferTransactionBodyBuilder(recipient, message, mosaics); + } + + /** + * Gets transaction recipient. + * + * @return Transaction recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.recipient; + } + + /** + * Gets transaction message. + * + * @return Transaction message. + */ + public getMessage(): Uint8Array { + return this.message; + } + + /** + * Gets attached mosaics. + * + * @return Attached mosaics. + */ + public getMosaics(): UnresolvedMosaicBuilder[] { + return this.mosaics; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.recipient.getSize(); + size += 2; // messageSize + size += 1; // mosaicsCount + size += this.message.length; + this.mosaics.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const recipientBytes = this.recipient.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, recipientBytes); + const messageSizeBytes = GeneratorUtils.uintToBuffer(this.message.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, messageSizeBytes); + const mosaicsCountBytes = GeneratorUtils.uintToBuffer(this.mosaics.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicsCountBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.message); + this.mosaics.forEach((item) => { + const mosaicsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/TransferTransactionBuilder.ts b/src/infrastructure/catbuffer/TransferTransactionBuilder.ts new file mode 100644 index 0000000000..722d79409a --- /dev/null +++ b/src/infrastructure/catbuffer/TransferTransactionBuilder.ts @@ -0,0 +1,124 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { TransferTransactionBodyBuilder } from './TransferTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a non-embedded transfer transaction. */ +export class TransferTransactionBuilder extends TransactionBuilder { + /** Transfer transaction body. */ + transferTransactionBody: TransferTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param recipient Transaction recipient. + * @param message Transaction message. + * @param mosaics Attached mosaics. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, recipient: UnresolvedAddressDto, message: Uint8Array, mosaics: UnresolvedMosaicBuilder[]) { + super(signature, signer, version, type, fee, deadline); + this.transferTransactionBody = new TransferTransactionBodyBuilder(recipient, message, mosaics); + } + + /** + * Creates an instance of TransferTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of TransferTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): TransferTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const transferTransactionBody = TransferTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, transferTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new TransferTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, transferTransactionBody.recipient, transferTransactionBody.message, transferTransactionBody.mosaics); + } + + /** + * Gets transaction recipient. + * + * @return Transaction recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.transferTransactionBody.getRecipient(); + } + + /** + * Gets transaction message. + * + * @return Transaction message. + */ + public getMessage(): Uint8Array { + return this.transferTransactionBody.getMessage(); + } + + /** + * Gets attached mosaics. + * + * @return Attached mosaics. + */ + public getMosaics(): UnresolvedMosaicBuilder[] { + return this.transferTransactionBody.getMosaics(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.transferTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const transferTransactionBodyBytes = this.transferTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, transferTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/UnresolvedAddressDto.ts b/src/infrastructure/catbuffer/UnresolvedAddressDto.ts new file mode 100644 index 0000000000..2a0748d76d --- /dev/null +++ b/src/infrastructure/catbuffer/UnresolvedAddressDto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Unresolved address. */ +export class UnresolvedAddressDto { + /** Unresolved address. */ + unresolvedAddress: Uint8Array; + + /** + * Constructor. + * + * @param unresolvedAddress Unresolved address. + */ + constructor(unresolvedAddress: Uint8Array) { + this.unresolvedAddress = unresolvedAddress; + } + + /** + * Creates an instance of UnresolvedAddressDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of UnresolvedAddressDto. + */ + public static loadFromBinary(payload: Uint8Array): UnresolvedAddressDto { + const byteArray = Array.from(payload); + const unresolvedAddress = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 25); + byteArray.splice(0, 25); + return new UnresolvedAddressDto(unresolvedAddress); + } + + /** + * Gets Unresolved address. + * + * @return Unresolved address. + */ + public getUnresolvedAddress(): Uint8Array { + return this.unresolvedAddress; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 25; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.unresolvedAddress); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/UnresolvedMosaicBuilder.ts b/src/infrastructure/catbuffer/UnresolvedMosaicBuilder.ts new file mode 100644 index 0000000000..5091228ad9 --- /dev/null +++ b/src/infrastructure/catbuffer/UnresolvedMosaicBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an unresolved mosaic. */ +export class UnresolvedMosaicBuilder { + /** Mosaic identifier. */ + mosaicId: UnresolvedMosaicIdDto; + /** Mosaic amount. */ + amount: AmountDto; + + /** + * Constructor. + * + * @param mosaicId Mosaic identifier. + * @param amount Mosaic amount. + */ + public constructor(mosaicId: UnresolvedMosaicIdDto, amount: AmountDto) { + this.mosaicId = mosaicId; + this.amount = amount; + } + + /** + * Creates an instance of UnresolvedMosaicBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of UnresolvedMosaicBuilder. + */ + public static loadFromBinary(payload: Uint8Array): UnresolvedMosaicBuilder { + const byteArray = Array.from(payload); + const mosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const amount = AmountDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, amount.getSize()); + return new UnresolvedMosaicBuilder(mosaicId, amount); + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicId; + } + + /** + * Gets mosaic amount. + * + * @return Mosaic amount. + */ + public getAmount(): AmountDto { + return this.amount; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += this.amount.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const amountBytes = this.amount.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, amountBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/UnresolvedMosaicIdDto.ts b/src/infrastructure/catbuffer/UnresolvedMosaicIdDto.ts new file mode 100644 index 0000000000..8b49a58aea --- /dev/null +++ b/src/infrastructure/catbuffer/UnresolvedMosaicIdDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Unresolved mosaic id. */ +export class UnresolvedMosaicIdDto { + /** Unresolved mosaic id. */ + unresolvedMosaicId: number[]; + + /** + * Constructor. + * + * @param unresolvedMosaicId Unresolved mosaic id. + */ + constructor(unresolvedMosaicId: number[]) { + this.unresolvedMosaicId = unresolvedMosaicId; + } + + /** + * Creates an instance of UnresolvedMosaicIdDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of UnresolvedMosaicIdDto. + */ + public static loadFromBinary(payload: Uint8Array): UnresolvedMosaicIdDto { + const byteArray = Array.from(payload); + const unresolvedMosaicId = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new UnresolvedMosaicIdDto(unresolvedMosaicId); + } + + /** + * Gets Unresolved mosaic id. + * + * @return Unresolved mosaic id. + */ + public getUnresolvedMosaicId(): number[] { + return this.unresolvedMosaicId; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const unresolvedMosaicIdBytes = GeneratorUtils.uint64ToBuffer(this.getUnresolvedMosaicId()); + newArray = GeneratorUtils.concatTypedArrays(newArray, unresolvedMosaicIdBytes); + return newArray; + } +} diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index 65abcd1df5..066844f474 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -24,10 +24,10 @@ import {MosaicId} from '../../model/mosaic/MosaicId'; import {MosaicProperties} from '../../model/mosaic/MosaicProperties'; import { MosaicPropertyType } from '../../model/mosaic/MosaicPropertyType'; import {NamespaceId} from '../../model/namespace/NamespaceId'; -import {AccountAddressRestrictionModificationTransaction} from '../../model/transaction/AccountAddressRestrictionModificationTransaction'; +import {AccountAddressRestrictionTransaction} from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; -import {AccountMosaicRestrictionModificationTransaction} from '../../model/transaction/AccountMosaicRestrictionModificationTransaction'; -import {AccountOperationRestrictionModificationTransaction} from '../../model/transaction/AccountOperationRestrictionModificationTransaction'; +import {AccountMosaicRestrictionTransaction} from '../../model/transaction/AccountMosaicRestrictionTransaction'; +import {AccountOperationRestrictionTransaction} from '../../model/transaction/AccountOperationRestrictionTransaction'; import {AccountRestrictionModification} from '../../model/transaction/AccountRestrictionModification'; import {AddressAliasTransaction} from '../../model/transaction/AddressAliasTransaction'; import {AggregateTransaction} from '../../model/transaction/AggregateTransaction'; @@ -280,8 +280,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr extractNetworkType(transactionDTO.version)) : undefined, transactionInfo, ); - } else if (transactionDTO.type === TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS) { - return new AccountAddressRestrictionModificationTransaction( + } else if (transactionDTO.type === TransactionType.ACCOUNT_RESTRICTION_ADDRESS) { + return new AccountAddressRestrictionTransaction( extractNetworkType(transactionDTO.version), extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), @@ -296,8 +296,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr extractNetworkType(transactionDTO.version)) : undefined, transactionInfo, ); - } else if (transactionDTO.type === TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION) { - return new AccountOperationRestrictionModificationTransaction( + } else if (transactionDTO.type === TransactionType.ACCOUNT_RESTRICTION_OPERATION) { + return new AccountOperationRestrictionTransaction( extractNetworkType(transactionDTO.version), extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), @@ -312,8 +312,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr extractNetworkType(transactionDTO.version)) : undefined, transactionInfo, ); - } else if (transactionDTO.type === TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC) { - return new AccountMosaicRestrictionModificationTransaction( + } else if (transactionDTO.type === TransactionType.ACCOUNT_RESTRICTION_MOSAIC) { + return new AccountMosaicRestrictionTransaction( extractNetworkType(transactionDTO.version), extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index afe17f162a..b1198243fd 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -25,10 +25,10 @@ import { MosaicNonce } from '../../model/mosaic/MosaicNonce'; import { MosaicProperties } from '../../model/mosaic/MosaicProperties'; import { NamespaceId } from '../../model/namespace/NamespaceId'; import { NamespaceType } from '../../model/namespace/NamespaceType'; -import { AccountAddressRestrictionModificationTransaction } from '../../model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from '../../model/transaction/AccountMosaicRestrictionModificationTransaction'; -import { AccountOperationRestrictionModificationTransaction } from '../../model/transaction/AccountOperationRestrictionModificationTransaction'; +import { AccountMosaicRestrictionTransaction } from '../../model/transaction/AccountMosaicRestrictionTransaction'; +import { AccountOperationRestrictionTransaction } from '../../model/transaction/AccountOperationRestrictionTransaction'; import { AccountRestrictionModification } from '../../model/transaction/AccountRestrictionModification'; import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction'; import { AggregateTransaction } from '../../model/transaction/AggregateTransaction'; @@ -100,9 +100,9 @@ export const CreateTransactionFromPayload = (transactionBinary: string): Transac */ const CreateTransaction = (type: number, transactionData: string, networkType: NetworkType, deadline: number[]): Transaction => { switch (type) { - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS: - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION: - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC: + case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: + case TransactionType.ACCOUNT_RESTRICTION_OPERATION: + case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: const propertyTypeLength = 2; const modificationCountOffset = propertyTypeLength; @@ -114,8 +114,8 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N const modificationArray = modifications.match(/.{1,52}/g); switch (type) { - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS: - const t = AccountAddressRestrictionModificationTransaction.create( + case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: + const t = AccountAddressRestrictionTransaction.create( Deadline.createFromDTO(deadline), parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( @@ -125,8 +125,8 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N networkType, ); return t; - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC: - return AccountMosaicRestrictionModificationTransaction.create( + case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: + return AccountMosaicRestrictionTransaction.create( Deadline.createFromDTO(deadline), parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( @@ -135,8 +135,8 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N )) : [], networkType, ); - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION: - return AccountOperationRestrictionModificationTransaction.create( + case TransactionType.ACCOUNT_RESTRICTION_OPERATION: + return AccountOperationRestrictionTransaction.create( Deadline.createFromDTO(deadline), parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index a9c5c838e0..5c97375f5a 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -14,10 +14,10 @@ * limitations under the License. */ -import { AccountAddressRestrictionModificationTransaction } from '../../model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from '../../model/transaction/AccountMosaicRestrictionModificationTransaction'; -import { AccountOperationRestrictionModificationTransaction } from '../../model/transaction/AccountOperationRestrictionModificationTransaction'; +import { AccountMosaicRestrictionTransaction } from '../../model/transaction/AccountMosaicRestrictionTransaction'; +import { AccountOperationRestrictionTransaction } from '../../model/transaction/AccountOperationRestrictionTransaction'; import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction'; import { AggregateTransaction } from '../../model/transaction/AggregateTransaction'; import { LockFundsTransaction } from '../../model/transaction/LockFundsTransaction'; @@ -70,26 +70,26 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { duration: (transaction as LockFundsTransaction).duration.toDTO(), hash: (transaction as LockFundsTransaction).hash, }; - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS: + case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: return { - restrictionType: (transaction as AccountAddressRestrictionModificationTransaction).restrictionType, - modifications: (transaction as AccountAddressRestrictionModificationTransaction). + restrictionType: (transaction as AccountAddressRestrictionTransaction).restrictionType, + modifications: (transaction as AccountAddressRestrictionTransaction). modifications.map((modification) => { return modification.toDTO(); }), }; - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION: + case TransactionType.ACCOUNT_RESTRICTION_OPERATION: return { - restrictionType: (transaction as AccountOperationRestrictionModificationTransaction).restrictionType, - modifications: (transaction as AccountOperationRestrictionModificationTransaction). + restrictionType: (transaction as AccountOperationRestrictionTransaction).restrictionType, + modifications: (transaction as AccountOperationRestrictionTransaction). modifications.map((modification) => { return modification.toDTO(); }), }; - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC: + case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: return { - restrictionType: (transaction as AccountMosaicRestrictionModificationTransaction).restrictionType, - modifications: (transaction as AccountMosaicRestrictionModificationTransaction).modifications.map((modification) => { + restrictionType: (transaction as AccountMosaicRestrictionTransaction).restrictionType, + modifications: (transaction as AccountMosaicRestrictionTransaction).modifications.map((modification) => { return modification.toDTO(); }), }; diff --git a/src/model/model.ts b/src/model/model.ts index 62bb27f331..d8af90a9c4 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -92,9 +92,9 @@ export * from './receipt/Statement'; // Transaction export * from './transaction/AccountLinkTransaction'; export * from './transaction/AccountRestrictionTransaction'; -export * from './transaction/AccountAddressRestrictionModificationTransaction'; -export * from './transaction/AccountOperationRestrictionModificationTransaction'; -export * from './transaction/AccountMosaicRestrictionModificationTransaction'; +export * from './transaction/AccountAddressRestrictionTransaction'; +export * from './transaction/AccountMosaicRestrictionTransaction'; +export * from './transaction/AccountMosaicRestrictionTransaction'; export * from './transaction/AccountRestrictionModification'; export * from './transaction/AddressAliasTransaction'; export * from './transaction/AggregateTransaction'; diff --git a/src/model/mosaic/MosaicFlag.ts b/src/model/mosaic/MosaicFlag.ts new file mode 100644 index 0000000000..dcf6a8b500 --- /dev/null +++ b/src/model/mosaic/MosaicFlag.ts @@ -0,0 +1,25 @@ +/* + * Copyright 2018 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. + */ +export enum MosaicFlags { + /** No flags present. */ + NONE = 0, + /** Mosaic supports supply changes even when mosaic owner owns partial supply. */ + SUPPLY_MUTABLE = 1, + /** Mosaic supports transfers between arbitrary accounts \note when not set, mosaic can only be transferred to and from mosaic owner. */ + TRANSFERABLE = 2, + /** Mosaic supports custom restrictions configured by mosaic owner. */ + RESTRICTABLE = 4, +} diff --git a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts similarity index 64% rename from src/model/transaction/AccountAddressRestrictionModificationTransaction.ts rename to src/model/transaction/AccountAddressRestrictionTransaction.ts index 3a9d99f813..243b4ff560 100644 --- a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -14,8 +14,17 @@ * limitations under the License. */ +import { RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; +import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; @@ -27,7 +36,7 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -export class AccountAddressRestrictionModificationTransaction extends Transaction { +export class AccountAddressRestrictionTransaction extends Transaction { /** * Create a modify account address restriction transaction object @@ -36,15 +45,15 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio * @param modifications - The array of modifications. * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountAddressRestrictionModificationTransaction} + * @returns {AccountAddressRestrictionTransaction} */ public static create(deadline: Deadline, restrictionType: RestrictionType, modifications: Array>, networkType: NetworkType, - maxFee: UInt64 = new UInt64([0, 0])): AccountAddressRestrictionModificationTransaction { - return new AccountAddressRestrictionModificationTransaction(networkType, - TransactionVersion.MODIFY_ACCOUNT_RESTRICTION_ADDRESS, + maxFee: UInt64 = new UInt64([0, 0])): AccountAddressRestrictionTransaction { + return new AccountAddressRestrictionTransaction(networkType, + TransactionVersion.ACCOUNT_RESTRICTION_ADDRESS, deadline, maxFee, restrictionType, @@ -71,15 +80,15 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio signature?: string, signer?: PublicAccount, transactionInfo?: TransactionInfo) { - super(TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS, + super(TransactionType.ACCOUNT_RESTRICTION_ADDRESS, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } /** * @override Transaction.size() - * @description get the byte size of a AccountAddressRestrictionModificationTransaction + * @description get the byte size of a AccountAddressRestrictionTransaction * @returns {number} - * @memberof AccountAddressRestrictionModificationTransaction + * @memberof AccountAddressRestrictionTransaction */ public get size(): number { const byteSize = super.size; @@ -110,4 +119,29 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountAddressRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountAddressRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedAddressDto(RawAddress.stringToAddress(modification.value)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index 78915b03a3..41e00509b0 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -14,8 +14,15 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountLinkTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/AccountLinkTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; @@ -111,4 +118,24 @@ export class AccountLinkTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountLinkTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.LINK_ACCOUNT.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new KeyDto(Convert.hexToUint8(this.remoteAccountKey)), + this.linkAction.valueOf(), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts similarity index 65% rename from src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts rename to src/model/transaction/AccountMosaicRestrictionTransaction.ts index 3a32656795..cfac1c3ea1 100644 --- a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -16,6 +16,14 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; +import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; @@ -27,7 +35,7 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -export class AccountMosaicRestrictionModificationTransaction extends Transaction { +export class AccountMosaicRestrictionTransaction extends Transaction { /** * Create a modify account mosaic restriction transaction object @@ -36,15 +44,15 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction * @param modifications - The array of modifications. * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountAddressRestrictionModificationTransaction} + * @returns {AccountAddressRestrictionTransaction} */ public static create(deadline: Deadline, restrictionType: RestrictionType, modifications: Array>, networkType: NetworkType, - maxFee: UInt64 = new UInt64([0, 0])): AccountMosaicRestrictionModificationTransaction { - return new AccountMosaicRestrictionModificationTransaction(networkType, - TransactionVersion.MODIFY_ACCOUNT_RESTRICTION_MOSAIC, + maxFee: UInt64 = new UInt64([0, 0])): AccountMosaicRestrictionTransaction { + return new AccountMosaicRestrictionTransaction(networkType, + TransactionVersion.ACCOUNT_RESTRICTION_MOSAIC, deadline, maxFee, restrictionType, @@ -71,15 +79,15 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction signature?: string, signer?: PublicAccount, transactionInfo?: TransactionInfo) { - super(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC, + super(TransactionType.ACCOUNT_RESTRICTION_MOSAIC, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } /** * @override Transaction.size() - * @description get the byte size of a AccountMosaicRestrictionModificationTransaction + * @description get the byte size of a AccountMosaicRestrictionTransaction * @returns {number} - * @memberof AccountMosaicRestrictionModificationTransaction + * @memberof AccountMosaicRestrictionTransaction */ public get size(): number { const byteSize = super.size; @@ -110,4 +118,29 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountMosaicRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_MOSAIC.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountMosaicRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedMosaicIdDto(modification.value), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts similarity index 67% rename from src/model/transaction/AccountOperationRestrictionModificationTransaction.ts rename to src/model/transaction/AccountOperationRestrictionTransaction.ts index 38160cc79d..4ed72af488 100644 --- a/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -26,8 +26,15 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; -export class AccountOperationRestrictionModificationTransaction extends Transaction { +export class AccountOperationRestrictionTransaction extends Transaction { /** * Create a modify account operation restriction type transaction object @@ -36,14 +43,14 @@ export class AccountOperationRestrictionModificationTransaction extends Transact * @param modifications - The array of modifications. * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountOperationRestrictionModificationTransaction} + * @returns {AccountOperationRestrictionTransaction} */ public static create(deadline: Deadline, restrictionType: RestrictionType, modifications: Array>, networkType: NetworkType, - maxFee: UInt64 = new UInt64([0, 0])): AccountOperationRestrictionModificationTransaction { - return new AccountOperationRestrictionModificationTransaction(networkType, + maxFee: UInt64 = new UInt64([0, 0])): AccountOperationRestrictionTransaction { + return new AccountOperationRestrictionTransaction(networkType, TransactionVersion.MODIFY_ACCOUNT_RESTRICTION_ENTITY_TYPE, deadline, maxFee, @@ -71,15 +78,15 @@ export class AccountOperationRestrictionModificationTransaction extends Transact signature?: string, signer?: PublicAccount, transactionInfo?: TransactionInfo) { - super(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION, + super(TransactionType.ACCOUNT_RESTRICTION_OPERATION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } /** * @override Transaction.size() - * @description get the byte size of a AccountOperationRestrictionModificationTransaction + * @description get the byte size of a AccountOperationRestrictionTransaction * @returns {number} - * @memberof AccountOperationRestrictionModificationTransaction + * @memberof AccountOperationRestrictionTransaction */ public get size(): number { const byteSize = super.size; @@ -110,4 +117,29 @@ export class AccountOperationRestrictionModificationTransaction extends Transact .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountOperationRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_OPERATION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountOperationRestrictionModificationBuilder( + modification.modificationType.valueOf(), + modification.value.valueOf(), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountRestrictionTransaction.ts b/src/model/transaction/AccountRestrictionTransaction.ts index 7e0f26c313..e1a718141e 100644 --- a/src/model/transaction/AccountRestrictionTransaction.ts +++ b/src/model/transaction/AccountRestrictionTransaction.ts @@ -17,9 +17,9 @@ import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; -import { AccountAddressRestrictionModificationTransaction } from './AccountAddressRestrictionModificationTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from './AccountMosaicRestrictionModificationTransaction'; -import { AccountOperationRestrictionModificationTransaction } from './AccountOperationRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from './AccountAddressRestrictionTransaction'; +import { AccountMosaicRestrictionTransaction } from './AccountMosaicRestrictionTransaction'; +import { AccountOperationRestrictionTransaction } from './AccountOperationRestrictionTransaction'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; import { TransactionType } from './TransactionType'; @@ -32,7 +32,7 @@ export class AccountRestrictionTransaction { * @param modification - array of address modifications * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountAddressRestrictionModificationTransaction} + * @returns {AccountAddressRestrictionTransaction} */ public static createAddressRestrictionModificationTransaction( deadline: Deadline, @@ -40,11 +40,11 @@ export class AccountRestrictionTransaction { modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), - ): AccountAddressRestrictionModificationTransaction { + ): AccountAddressRestrictionTransaction { if (![RestrictionType.AllowAddress, RestrictionType.BlockAddress].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } - return AccountAddressRestrictionModificationTransaction.create( + return AccountAddressRestrictionTransaction.create( deadline, restrictionType, modifications, @@ -60,7 +60,7 @@ export class AccountRestrictionTransaction { * @param modification - array of mosaic modifications * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountMosaicRestrictionModificationTransaction} + * @returns {AccountMosaicRestrictionTransaction} */ public static createMosaicRestrictionModificationTransaction( deadline: Deadline, @@ -68,11 +68,11 @@ export class AccountRestrictionTransaction { modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), - ): AccountMosaicRestrictionModificationTransaction { + ): AccountMosaicRestrictionTransaction { if (![RestrictionType.AllowMosaic, RestrictionType.BlockMosaic].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } - return AccountMosaicRestrictionModificationTransaction.create( + return AccountMosaicRestrictionTransaction.create( deadline, restrictionType, modifications, @@ -96,11 +96,11 @@ export class AccountRestrictionTransaction { modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), - ): AccountOperationRestrictionModificationTransaction { + ): AccountOperationRestrictionTransaction { if (![RestrictionType.AllowTransaction, RestrictionType.BlockTransaction].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } - return AccountOperationRestrictionModificationTransaction.create( + return AccountOperationRestrictionTransaction.create( deadline, restrictionType, modifications, diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index a0ac7d269f..3744d2d651 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -16,6 +16,14 @@ import { Builder } from '../../infrastructure/builders/AddressAliasTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; +import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; +import { AddressDto } from '../../infrastructure/catbuffer/AddressDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -27,6 +35,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { RawAddress } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -126,4 +135,25 @@ export class AddressAliasTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AddressAliasTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ADDRESS_ALIAS.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new AddressDto(RawAddress.stringToAddress(this.address.plain())), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 495ba89fb8..016f66fd8e 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -203,4 +203,12 @@ export class AggregateTransaction extends Transaction { return byteSize + byteTransactionsSize + byteTransactions; } -} \ No newline at end of file + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } +} diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index 4036654043..9ad23c1a60 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -137,4 +137,11 @@ export class LockFundsTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index e8afe30251..dbc22505a7 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -14,8 +14,15 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MultisigModificationTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { CosignatoryModificationBuilder } from '../../infrastructure/catbuffer/CosignatoryModificationBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; @@ -112,7 +119,7 @@ export class ModifyMultisigAccountTransaction extends Transaction { // each modification contains : // - 1 byte for modificationType // - 32 bytes for cosignatoryPublicKey - const byteModifications = 33 * this.modifications.length + const byteModifications = 33 * this.modifications.length; return byteSize + byteRemovalDelta + byteApprovalDelta + byteNumModifications + byteModifications; } @@ -132,4 +139,30 @@ export class ModifyMultisigAccountTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MultisigAccountModificationTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MODIFY_MULTISIG_ACCOUNT.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.minRemovalDelta, + this.minApprovalDelta, + this.modifications.map((modification) => { + return new CosignatoryModificationBuilder( + modification.type.valueOf(), + new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index 8c03b28ab6..3bc49806c6 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -150,4 +150,11 @@ export class MosaicAddressRestrictionTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index 8cc1d1914a..0c52ad47eb 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -16,6 +16,14 @@ import { Builder } from '../../infrastructure/builders/MosaicAliasTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/MosaicAliasTransactionBuilder'; +import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; +import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { MosaicId } from '../mosaic/MosaicId'; @@ -122,4 +130,25 @@ export class MosaicAliasTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicAliasTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_ALIAS.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index b82844ab41..7a41faddf9 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -27,6 +27,19 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; +import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; +import { MosaicFlagsDto } from '../../infrastructure/catbuffer/MosaicFlagsDto'; +import { MosaicFlags } from '../mosaic/MosaicFlag'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { Convert } from '../../core/format'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; /** * Before a mosaic can be created or transferred, a corresponding definition of the mosaic has to be created and published to the network. @@ -115,6 +128,37 @@ export class MosaicDefinitionTransaction extends Transaction { return byteSize + byteNonce + byteMosaicId + byteNumProps + byteFlags + byteDivisibility + byteDurationSize + byteDuration; } + /** + * @description get the calculated mosaic flag value + * @returns {number} + * @memberof MosaicDefinitionTransaction + */ + public getMosaicFlagValue(): number { + let flag = MosaicFlags.NONE; + if (this.mosaicProperties.supplyMutable === true) { + flag += MosaicFlags.SUPPLY_MUTABLE; + } + + if (this.mosaicProperties.transferable === true) { + flag += MosaicFlags.TRANSFERABLE; + } + + if (this.mosaicProperties.restrictable === true) { + flag += MosaicFlags.RESTRICTABLE; + } + + return flag.valueOf(); + } + + /** + * @description Get mosaic nonce int value + * @returns {number} + * @memberof MosaicDefinitionTransaction + */ + public getMosaicNonceIntValue(): number { + return GeneratorUtils.readUint32At(this.nonce.toDTO(), 0); + } + /** * @internal * @returns {VerifiableTransaction} @@ -144,4 +188,28 @@ export class MosaicDefinitionTransaction extends Transaction { return mosaicDefinitionTransaction.build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicDefinitionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_DEFINITION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new MosaicNonceDto(this.getMosaicNonceIntValue()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + this.getMosaicFlagValue(), + this.mosaicProperties.divisibility, + new BlockDurationDto(this.mosaicProperties.duration ? + this.mosaicProperties.duration.toDTO() : []), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index 7530eba330..7cbb7a55d5 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -173,4 +173,11 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index 39b33d8318..b53fbd92d3 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -16,6 +16,12 @@ import { Builder } from '../../infrastructure/builders/MosaicSupplyChangeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { MosaicId } from '../mosaic/MosaicId'; @@ -125,4 +131,25 @@ export class MosaicSupplyChangeTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicSupplyChangeTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_SUPPLY_CHANGE.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + this.direction.valueOf(), + new AmountDto(this.delta.toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index da05639507..f1f29cd6a2 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -182,4 +182,11 @@ export class RegisterNamespaceTransaction extends Transaction { return registerNamespacetransaction.build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index 6862dc7a3b..9e02785071 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -13,9 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Convert as convert } from '../../core/format'; +import { Convert as convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/SecretLockTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SecretLockTransactionBuilder } from '../../infrastructure/catbuffer/SecretLockTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from '../../infrastructure/catbuffer/UnresolvedMosaicBuilder'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -134,6 +145,15 @@ export class SecretLockTransaction extends Transaction { return byteSize + byteMosaicId + byteAmount + byteDuration + byteAlgorithm + byteRecipient + byteSecret; } + /** + * @description Get secret bytes + * @returns {Uint8Array} + * @memberof SecretLockTransaction + */ + public getSecretByte(): Uint8Array { + return convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); + } + /** * @internal * @returns {VerifiableTransaction} @@ -153,4 +173,28 @@ export class SecretLockTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new SecretLockTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_LOCK.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), + new AmountDto(this.mosaic.amount.toDTO())), + new BlockDurationDto(this.duration.toDTO()), + this.hashType.valueOf(), + new Hash256Dto(this.getSecretByte()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipient.plain())), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index cf41678857..588638fcc6 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -14,9 +14,17 @@ * limitations under the License. */ -import { Convert as convert } from '../../core/format'; +import { Convert, Convert as convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/SecretProofTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SecretProofTransactionBuilder } from '../../infrastructure/catbuffer/SecretProofTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -113,6 +121,24 @@ export class SecretProofTransaction extends Transaction { return byteSize + byteAlgorithm + byteSecret + byteRecipient + byteProofSize + byteProof; } + /** + * @description Get secret bytes + * @returns {Uint8Array} + * @memberof SecretLockTransaction + */ + public getSecretByte(): Uint8Array { + return convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); + } + + /** + * @description Get proof bytes + * @returns {Uint8Array} + * @memberof SecretLockTransaction + */ + public getProofByte(): Uint8Array { + return convert.hexToUint8(this.proof); + } + /** * @internal * @returns {VerifiableTransaction} @@ -130,4 +156,26 @@ export class SecretProofTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new SecretProofTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_PROOF.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.hashType.valueOf(), + new Hash256Dto(this.getSecretByte()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipient.plain())), + this.getProofByte(), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index 63fb543965..0bc6786fb3 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -import { SignSchema } from '../../core/crypto'; +import { KeyPair, SHA3Hasher, SignSchema } from '../../core/crypto'; +import { Convert } from '../../core/format'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { SerializeTransactionToJSON } from '../../infrastructure/transaction/SerializeTransactionToJSON'; import { Account } from '../account/Account'; @@ -79,6 +80,16 @@ export abstract class Transaction { public readonly transactionInfo?: TransactionInfo | AggregateTransactionInfo) { } + /** + * @internal + */ + protected abstract buildTransaction(): VerifiableTransaction; + + /** + * @internal + */ + protected abstract generateBytes(): Uint8Array; + /** * @internal * Serialize and sign transaction creating a new SignedTransaction @@ -100,8 +111,55 @@ export abstract class Transaction { /** * @internal + * Serialize and sign transaction creating a new SignedTransaction + * @param account - The account to sign the transaction + * @param generationHash - Network generation hash hex + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {SignedTransaction} */ - protected abstract buildTransaction(): VerifiableTransaction; + public signWithCatbuffer(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { + const generationHashBytes = Array.from(Convert.hexToUint8(generationHash)); + const byteBuffer = Array.from(this.generateBytes()); + const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); + const keyPairEncoded = KeyPair.createKeyPairFromPrivateKeyString(account.privateKey, signSchema); + const signature = Array.from(KeyPair.sign(account, new Uint8Array(signingBytes), signSchema)); + const signedTransactionBuffer = byteBuffer + .splice(0, 4) + .concat(signature) + .concat(Array.from(keyPairEncoded.publicKey)) + .concat(byteBuffer + .splice(64 + 32, byteBuffer.length)); + const payload = Convert.uint8ToHex(signedTransactionBuffer); + return new SignedTransaction( + payload, + this.createTransactionHash(payload, generationHashBytes), + account.publicKey, + this.type, + this.networkType); + } + + /** + * Generate transaction hash hex + * @param {string} transactionPayload HexString Payload + * @param {Array} generationHashBuffer Network generation hash byte + * @returns {string} Returns Transaction Payload hash + */ + public createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { + const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); + const signingBytes = byteBuffer + .slice(4, 36) + .concat(byteBuffer + .slice(4 + 64, 4 + 64 + 32)) + .concat(generationHashBuffer) + .concat(byteBuffer + .splice(4 + 64 + 32, byteBuffer.length)); + + const hash = new Uint8Array(32); + + SHA3Hasher.func(hash, signingBytes, 32); + + return Convert.uint8ToHex(hash); + } /** * @internal diff --git a/src/model/transaction/TransactionType.ts b/src/model/transaction/TransactionType.ts index 7b2b000adf..9d571f0855 100644 --- a/src/model/transaction/TransactionType.ts +++ b/src/model/transaction/TransactionType.ts @@ -15,114 +15,116 @@ */ /** - * Static class containing transaction type constants. + * Enum containing transaction type constants. */ -export class TransactionType { +export enum TransactionType { + /** Reserved entity type. */ + RESERVED = 0, /** * Transfer Transaction transaction type. * @type {number} */ - public static readonly TRANSFER = 0x4154; + TRANSFER = 0x4154, /** * Register namespace transaction type. * @type {number} */ - public static readonly REGISTER_NAMESPACE = 0x414E; + REGISTER_NAMESPACE = 0x414E, /** * Address alias transaction type * @type {number} */ - public static readonly ADDRESS_ALIAS = 0x424E; + ADDRESS_ALIAS = 0x424E, /** * Mosaic alias transaction type * @type {number} */ - public static readonly MOSAIC_ALIAS = 0x434E; + MOSAIC_ALIAS = 0x434E, /** * Mosaic definition transaction type. * @type {number} */ - public static readonly MOSAIC_DEFINITION = 0x414D; + MOSAIC_DEFINITION = 0x414D, /** * Mosaic supply change transaction. * @type {number} */ - public static readonly MOSAIC_SUPPLY_CHANGE = 0x424D; + MOSAIC_SUPPLY_CHANGE = 0x424D, /** * Modify multisig account transaction type. * @type {number} */ - public static readonly MODIFY_MULTISIG_ACCOUNT = 0x4155; + MODIFY_MULTISIG_ACCOUNT = 0x4155, /** * Aggregate complete transaction type. * @type {number} */ - public static readonly AGGREGATE_COMPLETE = 0x4141; + AGGREGATE_COMPLETE = 0x4141, /** * Aggregate bonded transaction type */ - public static readonly AGGREGATE_BONDED = 0x4241; + AGGREGATE_BONDED = 0x4241, /** * Lock transaction type * @type {number} */ - public static readonly LOCK = 0x4148; + LOCK = 0x4148, /** * Secret Lock Transaction type * @type {number} */ - public static readonly SECRET_LOCK = 0x4152; + SECRET_LOCK = 0x4152, /** * Secret Proof transaction type * @type {number} */ - public static readonly SECRET_PROOF = 0x4252; + SECRET_PROOF = 0x4252, /** * Account restriction address transaction type * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_ADDRESS = 0x4150; + ACCOUNT_RESTRICTION_ADDRESS = 0x4150, /** * Account restriction mosaic transaction type * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_MOSAIC = 0x4250; + ACCOUNT_RESTRICTION_MOSAIC = 0x4250, /** * Account restriction operation transaction type * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_OPERATION = 0x4350; + ACCOUNT_RESTRICTION_OPERATION = 0x4350, /** * Link account transaction type * @type {number} */ - public static readonly LINK_ACCOUNT = 0x414C; + LINK_ACCOUNT = 0x414C, /** * Mosaic address restriction type * @type {number} */ - public static readonly MOSAIC_ADDRESS_RESTRICTION = 0x4251; + MOSAIC_ADDRESS_RESTRICTION = 0x4251, /** * Mosaic global restriction type * @type {number} */ - public static readonly MOSAIC_GLOBAL_RESTRICTION = 0x4151; + MOSAIC_GLOBAL_RESTRICTION = 0x4151, } diff --git a/src/model/transaction/TransactionVersion.ts b/src/model/transaction/TransactionVersion.ts index 953c35e096..71087ac326 100644 --- a/src/model/transaction/TransactionVersion.ts +++ b/src/model/transaction/TransactionVersion.ts @@ -116,13 +116,13 @@ export class TransactionVersion { * Account Restriction address transaction version * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_ADDRESS = 0x01; + public static readonly ACCOUNT_RESTRICTION_ADDRESS = 0x01; /** * Account Restriction mosaic transaction version * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_MOSAIC = 0x01; + public static readonly ACCOUNT_RESTRICTION_MOSAIC = 0x01; /** * Account Restriction operation transaction version diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 880374187d..31dea94577 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -14,9 +14,20 @@ * limitations under the License. */ -import { Convert as convert } from '../../core/format'; +import { Convert, Convert as convert } from '../../core/format'; +import { RawAddress } from '../../core/format/RawAddress'; import { Builder } from '../../infrastructure/builders/TransferTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { TransferTransactionBuilder } from '../../infrastructure/catbuffer/TransferTransactionBuilder'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from '../../infrastructure/catbuffer/UnresolvedMosaicBuilder'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -109,6 +120,30 @@ export class TransferTransaction extends Transaction { return (this.recipient as Address).plain(); } + /** + * Return sorted mosaic arrays + * @internal + * @returns {Mosaic[]} + */ + public sortMosaics(): Mosaic[] { + const sortedMosaics = this.mosaics.sort((a, b) => { + if (Number(a.id[1]) > b.id[1]) { return 1; } else if (a.id[1] < b.id[1]) { return -1; } + return 0; + }); + return sortedMosaics; + } + + /** + * Return message buffer + * @internal + * @returns {Uint8Array} + */ + public getMessageBuffer(): Uint8Array { + const payloadBuffer = Convert.hexToUint8(Convert.utf8ToHex(this.message.payload)); + const typeBuffer = GeneratorUtils.uintToBuffer(this.message.type, 1); + return GeneratorUtils.concatTypedArrays(typeBuffer, payloadBuffer); + } + /** * @override Transaction.size() * @description get the byte size of a TransferTransaction @@ -146,4 +181,28 @@ export class TransferTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new TransferTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.TRANSFER.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), + this.getMessageBuffer(), + this.sortMosaics().map((mosaic) => { + return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), + new AmountDto(mosaic.amount.toDTO())); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index 98fb4f5c86..01148693ad 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -35,9 +35,9 @@ import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrency import { AliasActionType } from '../../../src/model/namespace/AliasActionType'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { NamespaceType } from '../../../src/model/namespace/NamespaceType'; -import { AccountAddressRestrictionModificationTransaction } from '../../../src/model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from '../../../src/model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../../src/model/transaction/AccountLinkTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from '../../../src/model/transaction/AccountMosaicRestrictionModificationTransaction'; +import { AccountMosaicRestrictionTransaction } from '../../../src/model/transaction/AccountMosaicRestrictionTransaction'; import { AccountRestrictionModification } from '../../../src/model/transaction/AccountRestrictionModification'; import { AccountRestrictionTransaction } from '../../../src/model/transaction/AccountRestrictionTransaction'; import { AddressAliasTransaction } from '../../../src/model/transaction/AddressAliasTransaction'; @@ -87,7 +87,7 @@ describe('TransactionMapping - createFromPayload', () => { const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); const transaction = TransactionMapping - .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; + .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionTransaction; expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); @@ -110,7 +110,7 @@ describe('TransactionMapping - createFromPayload', () => { const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); const transaction = TransactionMapping - .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; + .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionTransaction; expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); expect(transaction.modifications[0].value[0]).to.be.equal(2262289484); expect(transaction.modifications[0].value[1]).to.be.equal(3405110546); @@ -132,7 +132,7 @@ describe('TransactionMapping - createFromPayload', () => { const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); - const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; + const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AccountAddressRestrictionTransaction; expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); expect(transaction.modifications[0].value).to.be.equal(operation); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); @@ -671,7 +671,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const transaction = - TransactionMapping.createFromDTO(addressRestrictionTransaction.toJSON()) as AccountAddressRestrictionModificationTransaction; + TransactionMapping.createFromDTO(addressRestrictionTransaction.toJSON()) as AccountAddressRestrictionTransaction; expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); @@ -692,9 +692,9 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const transaction = - TransactionMapping.createFromDTO(mosaicRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; + TransactionMapping.createFromDTO(mosaicRestrictionTransaction.toJSON()) as AccountMosaicRestrictionTransaction; - expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC); + expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_MOSAIC); expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); expect(transaction.modifications.length).to.be.equal(1); }); @@ -713,9 +713,9 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const transaction = - TransactionMapping.createFromDTO(operationRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; + TransactionMapping.createFromDTO(operationRestrictionTransaction.toJSON()) as AccountMosaicRestrictionTransaction; - expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); + expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_OPERATION); expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); expect(transaction.modifications.length).to.be.equal(1); }); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 5a13ee0d28..2bcf247f76 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -90,7 +90,7 @@ describe('SerializeTransactionToJSON', () => { const json = addressRestrictionTransaction.toJSON(); - expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS); + expect(json.transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_ADDRESS); expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -110,7 +110,7 @@ describe('SerializeTransactionToJSON', () => { const json = mosaicRestrictionTransaction.toJSON(); - expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC); + expect(json.transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_MOSAIC); expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -130,7 +130,7 @@ describe('SerializeTransactionToJSON', () => { const json = operationRestrictionTransaction.toJSON(); - expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); + expect(json.transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_OPERATION); expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); expect(json.transaction.modifications.length).to.be.equal(1); }); diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index 68c65c8eae..0d5b8c8b25 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountLinkTransaction', () => { expect(accountLinkTransaction.linkAction).to.be.equal(0); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); - const signedTransaction = accountLinkTransaction.signWith(account, generationHash); + const signedTransaction = accountLinkTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 04ef489a07..36dd3232a1 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountRestrictionTransaction', () => { }); describe('size', () => { - it('should return 148 for AccountAddressRestrictionModificationTransaction transaction byte size with 1 modification', () => { + it('should return 148 for AccountAddressRestrictionTransaction transaction byte size with 1 modification', () => { const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); const addressRestrictionFilter = AccountRestrictionModification.createForAddress( RestrictionModificationType.Add, @@ -82,7 +82,7 @@ describe('AccountRestrictionTransaction', () => { expect(addressRestrictionTransaction.size).to.be.equal(148); }); - it('should return 131 for AccountMosaicRestrictionModificationTransaction transaction byte size with 1 modification', () => { + it('should return 131 for AccountMosaicRestrictionTransaction transaction byte size with 1 modification', () => { const mosaicId = new MosaicId([2262289484, 3405110546]); const mosaicRestrictionFilter = AccountRestrictionModification.createForMosaic( RestrictionModificationType.Add, @@ -97,7 +97,7 @@ describe('AccountRestrictionTransaction', () => { expect(mosaicRestrictionTransaction.size).to.be.equal(131); }); - it('should return 125 for AccountOperationRestrictionModificationTransaction transaction byte size with 1 modification', () => { + it('should return 125 for AccountOperationRestrictionTransaction transaction byte size with 1 modification', () => { const operation = TransactionType.ADDRESS_ALIAS; const operationRestrictionFilter = AccountRestrictionModification.createForOperation( RestrictionModificationType.Add, @@ -162,7 +162,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = addressRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -204,7 +204,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -246,7 +246,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = operationRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index b05aa01f04..e2efb443b9 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('AddressAliasTransaction', () => { expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = addressAliasTransaction.signWith(account, generationHash); + const signedTransaction = addressAliasTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index 503f196c8d..eb46016c85 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -110,7 +110,7 @@ describe('ModifyMultisigAccountTransaction', () => { expect(modifyMultisigAccountTransaction.modifications[1].cosignatoryPublicAccount.publicKey) .to.be.equal('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); - const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); + const signedTransaction = modifyMultisigAccountTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index 82a26c9ed8..c08ff431f9 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -56,7 +56,7 @@ describe('MosaicAliasTransaction', () => { namespaceId, mosaicId, NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(mosaicAliasTransaction.maxFee.higher).to.be.equal(0); @@ -80,7 +80,7 @@ describe('MosaicAliasTransaction', () => { expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); expect(mosaicAliasTransaction.mosaicId.id.higher).to.be.equal(3405110546); - const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); + const signedTransaction = mosaicAliasTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index 5c15bafa89..688506516b 100644 --- a/test/model/transaction/MosaicDefinitionTransaction.spec.ts +++ b/test/model/transaction/MosaicDefinitionTransaction.spec.ts @@ -93,12 +93,12 @@ describe('MosaicDefinitionTransaction', () => { expect(mosaicDefinitionTransaction.mosaicProperties.transferable).to.be.equal(true); expect(mosaicDefinitionTransaction.mosaicProperties.restrictable).to.be.equal(true); - const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicDefinitionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('E6DE84B8010000000000000001070302E803000000000000'); + )).to.be.equal('E6DE84B801000000000000000703E803000000000000'); }); diff --git a/test/model/transaction/MultisigCosignatoryModification.spec.ts b/test/model/transaction/MultisigCosignatoryModification.spec.ts index 61356ec9d0..691a0692ce 100644 --- a/test/model/transaction/MultisigCosignatoryModification.spec.ts +++ b/test/model/transaction/MultisigCosignatoryModification.spec.ts @@ -42,7 +42,6 @@ describe('MultisigCosignatoryModification', () => { expect(multisigCosignatoryModification.type).to.be.equal(MultisigCosignatoryModificationType.Add); }); - it('should create Remove MultisigCosignatoryModification', () => { const multisigCosignatoryModification = new MultisigCosignatoryModification( MultisigCosignatoryModificationType.Remove, diff --git a/test/model/transaction/SecretLockTransaction.spec.ts b/test/model/transaction/SecretLockTransaction.spec.ts index 26bbd11ede..9f240dda47 100644 --- a/test/model/transaction/SecretLockTransaction.spec.ts +++ b/test/model/transaction/SecretLockTransaction.spec.ts @@ -18,6 +18,7 @@ import {expect} from 'chai'; import * as CryptoJS from 'crypto-js'; import {keccak_256, sha3_256} from 'js-sha3'; import {Convert as convert} from '../../../src/core/format'; +import { Account } from '../../../src/model/account/Account'; import {Address} from '../../../src/model/account/Address'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; @@ -25,9 +26,14 @@ import {Deadline} from '../../../src/model/transaction/Deadline'; import {HashType} from '../../../src/model/transaction/HashType'; import {SecretLockTransaction} from '../../../src/model/transaction/SecretLockTransaction'; import {UInt64} from '../../../src/model/UInt64'; +import { TestingAccount } from '../../conf/conf.spec'; describe('SecretLockTransaction', () => { - + let account: Account; + const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; + before(() => { + account = TestingAccount; + }); it('should default maxFee field be set to 0', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; const recipient = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); @@ -56,7 +62,7 @@ describe('SecretLockTransaction', () => { sha3_256.create().update(convert.hexToUint8(proof)).hex(), recipient, NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(secretLockTransaction.maxFee.higher).to.be.equal(0); @@ -83,6 +89,27 @@ describe('SecretLockTransaction', () => { expect(secretLockTransaction.recipient).to.be.equal(recipient); }); + it('should be created and sign SecretLock Transaction', () => { + const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; + const recipient = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + NetworkCurrencyMosaic.createAbsolute(10), + UInt64.fromUint(100), + HashType.Op_Sha3_256, + sha3_256.create().update(convert.hexToUint8(proof)).hex(), + recipient, + NetworkType.MIJIN_TEST, + ); + const signedTx = secretLockTransaction.signWithCatbuffer(account, generationHash); + expect(signedTx.payload.substring( + 240, + signedTx.payload.length, + )).to.be.equal( + '44B262C46CEABB850A000000000000006400000000000000009B3155B37159DA50AA52D5967C509B41' + + '0F5A36A3B1E31ECB5AC76675D79B4A5E90C2337113E6D8F15B56E0821149299F340C01706FC1CAD6CB'); + }); + it('should throw exception when the input is not related to HashTyp: Op_Sha3_256', () => { expect(() => { const recipient = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); diff --git a/test/model/transaction/SecretProofTransaction.spec.ts b/test/model/transaction/SecretProofTransaction.spec.ts index 6ee0b3aaab..8712f1ca9e 100644 --- a/test/model/transaction/SecretProofTransaction.spec.ts +++ b/test/model/transaction/SecretProofTransaction.spec.ts @@ -27,7 +27,7 @@ import { TestingAccount } from '../../conf/conf.spec'; describe('SecretProofTransaction', () => { let account: Account; - + const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; before(() => { account = TestingAccount; }); @@ -191,4 +191,24 @@ describe('SecretProofTransaction', () => { expect(secretProofTransaction.size).to.be.equal(212); }); }); + + it('should create and sign SecretProof Transaction', () => { + const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; + const secretProofTransaction = SecretProofTransaction.create( + Deadline.create(), + HashType.Op_Sha3_256, + sha3_256.create().update(convert.hexToUint8(proof)).hex(), + account.address, + proof, + NetworkType.MIJIN_TEST, + ); + + const signedTx = secretProofTransaction.signWithCatbuffer(account, generationHash); + expect(signedTx.payload.substring( + 240, + signedTx.payload.length, + )).to.be.equal( + '009B3155B37159DA50AA52D5967C509B410F5A36A3B1E31ECB5AC76675D79B4A5E90A75B6B63D31BDA938' + + '08727940F24699AECDDF17C568508BA2000B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'); + }); }); diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index c378c39c32..8e8b4cc9d4 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -238,4 +238,8 @@ class FakeTransaction extends Transaction { protected buildTransaction(): VerifiableTransaction { throw new Error('Method not implemented.'); } + + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/test/model/transaction/TransferTransaction.spec.ts b/test/model/transaction/TransferTransaction.spec.ts index 31e063be36..63d8bb880c 100644 --- a/test/model/transaction/TransferTransaction.spec.ts +++ b/test/model/transaction/TransferTransaction.spec.ts @@ -53,7 +53,7 @@ describe('TransferTransaction', () => { [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(transferTransaction.maxFee.higher).to.be.equal(0); @@ -193,4 +193,30 @@ describe('TransferTransaction', () => { expect(transaction.size).to.be.equal(158); }); }); + + it('should create TransferTransaction and sign using catbuffer', () => { + const transferTransaction = TransferTransaction.create( + Deadline.create(), + Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + [ + NetworkCurrencyMosaic.createRelative(100), + ], + PlainMessage.create('test-message'), + NetworkType.MIJIN_TEST, + ); + + expect(transferTransaction.message.payload).to.be.equal('test-message'); + expect(transferTransaction.mosaics.length).to.be.equal(1); + expect(transferTransaction.recipient).to.be.instanceof(Address); + expect((transferTransaction.recipient as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + + const signedTransaction = transferTransaction.signWithCatbuffer(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal( + '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000100746573742D6D657373616765' + + '44B262C46CEABB8500E1F50500000000'); + }); }); From 440233f2f9f63204a730cc478f367ccc9a900bc6 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 22:38:29 +0100 Subject: [PATCH 05/98] Manually added aggregate transaction builder --- .../catbuffer/AggregateTransactionBuilder.ts | 136 ++++++++++++++++++ .../catbuffer/CosignatureBuilder.ts | 102 +++++++++++++ .../catbuffer/DetachedCosignatureBuilder.ts | 97 +++++++++++++ 3 files changed, 335 insertions(+) create mode 100644 src/infrastructure/catbuffer/AggregateTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/CosignatureBuilder.ts create mode 100644 src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts diff --git a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts new file mode 100644 index 0000000000..64b11c499f --- /dev/null +++ b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts @@ -0,0 +1,136 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; +import { AddressDto } from './AddressDto'; +import { AliasActionDto } from './AliasActionDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** binary layout for an aggregate transaction. */ +export class AggregateTransactionBuilder extends TransactionBuilder { + /** embedded transactions. */ + transactions: Uint8Array; + /** cosignatures. */ + cosignatures: Uint8Array; + + /** + * Constructor. + * + * @param signature entity signature. + * @param signer entity signer's public key. + * @param version entity version. + * @param type entity type. + * @param fee transaction fee. + * @param deadline transaction deadline. + * @param transactions embedded transactions. + * @param cosignatures cosignatures. + */ + public constructor( + signature: SignatureDto, + signer: KeyDto, + version: number, + type: EntityTypeDto, + fee: AmountDto, + deadline: TimestampDto, + transactions: Uint8Array, + cosignatures: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + this.transactions = transactions; + this.cosignatures = cosignatures; + } + + /** + * loadFromBinary - Create an instance of AggregateTransactionBuilder from a stream. + * + * @param Uint8Array Byte to use to serialize the object. + * @return An instance of AggregateTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AggregateTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const payloadSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + const transactions = GeneratorUtils.getBytes(Uint8Array.from(byteArray), payloadSize); + byteArray.splice(0, transactions.length); + const cosignatures = Uint8Array.from(byteArray); + // tslint:disable-next-line: max-line-length + return new AggregateTransactionBuilder(superObject.signature, superObject.signer, superObject.version, + superObject.type, superObject.fee, superObject.deadline, + transactions, cosignatures); + } + + /** + * Get embedded transactions. + * + * @return embedded transactions. + */ + public getTransactions(): Uint8Array { + return this.transactions; + } + + /** + * Get cosignatures. + * + * @return cosignatures. + */ + public getCosignatures(): Uint8Array { + return this.cosignatures; + } + + /** + * Get the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += 4; // payloadSize + size += this.transactions.length; + size += this.cosignatures.length; + return size; + } + + /** + * Serialize the object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const payloadSizeBytes = GeneratorUtils.uintToBuffer(this.transactions.length, 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes); + const transactionBytes = this.transactions; + newArray = GeneratorUtils.concatTypedArrays(newArray, transactionBytes); + const cosignaturesBytes = this.transactions; + newArray = GeneratorUtils.concatTypedArrays(newArray, cosignaturesBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/CosignatureBuilder.ts b/src/infrastructure/catbuffer/CosignatureBuilder.ts new file mode 100644 index 0000000000..5e0ba7a43c --- /dev/null +++ b/src/infrastructure/catbuffer/CosignatureBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; + +/** a cosignature. */ +export class CosignatureBuilder { + /** cosigner public key. */ + signer: KeyDto; + /** cosigner signature. */ + signature: SignatureDto; + + /** + * Constructor. + * + * @param signer cosigner public key. + * @param signature cosigner signature. + */ + public constructor(signer: KeyDto, signature: SignatureDto) { + this.signer = signer; + this.signature = signature; + } + + /** + * loadFromBinary - Create an instance of CosignatureBuilder from a stream. + * + * @param payload Byte to use to serialize the object. + * @return An instance of CosignatureBuilder. + */ + public static loadFromBinary(payload: Uint8Array): CosignatureBuilder { + const byteArray = Array.from(payload); + const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signer.getSize()); + const signature = SignatureDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signature.getSize()); + return new CosignatureBuilder(signer, signature); + } + + /** + * Get cosigner public key. + * + * @return cosigner public key. + */ + public getSigner(): KeyDto { + return this.signer; + } + + /** + * Get cosigner signature. + * + * @return cosigner signature. + */ + public getSignature(): SignatureDto { + return this.signature; + } + + /** + * Get the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.signer.getSize(); + size += this.signature.getSize(); + return size; + } + + /** + * Serialize the object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const signerBytes = this.signer.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); + const signatureBytes = this.signature.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signatureBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts b/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts new file mode 100644 index 0000000000..58a3152ed0 --- /dev/null +++ b/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts @@ -0,0 +1,97 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { CosignatureBuilder } from './CosignatureBuilder'; +import { Hash256Dto } from './Hash256Dto'; + +/** a detached cosignature. */ +export class DetachedCosignatureBuilder extends CosignatureBuilder { + /** hash of the corresponding parent. */ + parentHash: Hash256Dto; + + /** + * Constructor. + * + * @param signer cosigner public key. + * @param signature cosigner signature. + * @param parentHash hash of the corresponding parent. + */ + public constructor(signer: KeyDto, signature: SignatureDto, parentHash: Hash256Dto) { + super(signer, signature); + this.parentHash = parentHash; + } + + /** + * loadFromBinary - Create an instance of DetachedCosignatureBuilder from a stream. + * + * @param payload Byte to use to serialize the object. + * @return An instance of DetachedCosignatureBuilder. + */ + public static loadFromBinary(payload: Uint8Array): DetachedCosignatureBuilder { + const byteArray = Array.from(payload); + const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signer.getSize()); + const signature = SignatureDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signature.getSize()); + const parentHash = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, parentHash.getSize()); + return new DetachedCosignatureBuilder(signer, signature, parentHash); + } + + /** + * Get hash of the corresponding parent. + * + * @return hash of the corresponding parent. + */ + public getParentHash(): Hash256Dto { + return this.parentHash; + } + + /** + * Get the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = super.getSize(); + size += this.parentHash.getSize(); + return size; + } + + /** + * Serialize the object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const signerBytes = this.signer.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); + const signatureBytes = this.signature.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signatureBytes); + const parentHashBytes = this.parentHash.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, parentHashBytes); + return newArray; + } +} From cb694bdea5182deff91b66582bb00fea781e5cd3 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 23:43:48 +0100 Subject: [PATCH 06/98] Added embedded transaction builders --- .../AccountAddressRestrictionTransaction.ts | 23 ++++++ .../transaction/AccountLinkTransaction.ts | 18 +++++ .../AccountMosaicRestrictionTransaction.ts | 23 ++++++ .../AccountOperationRestrictionTransaction.ts | 36 +++++++-- .../transaction/AddressAliasTransaction.ts | 21 +++++- src/model/transaction/AggregateTransaction.ts | 8 ++ src/model/transaction/LockFundsTransaction.ts | 47 +++++++++++- .../ModifyMultisigAccountTransaction.ts | 24 ++++++ .../MosaicAddressRestrictionTransaction.ts | 47 +++++++++++- .../transaction/MosaicAliasTransaction.ts | 19 +++++ .../MosaicDefinitionTransaction.ts | 45 ++++++++---- .../MosaicGlobalRestrictionTransaction.ts | 49 ++++++++++++- .../MosaicSupplyChangeTransaction.ts | 19 +++++ .../RegisterNamespaceTransaction.ts | 73 ++++++++++++++++++- .../transaction/SecretLockTransaction.ts | 22 ++++++ .../transaction/SecretProofTransaction.ts | 20 +++++ src/model/transaction/Transaction.ts | 5 ++ src/model/transaction/TransferTransaction.ts | 21 ++++++ .../transaction/LockFundsTransaction.spec.ts | 30 +++++++- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- ...osaicAddressRestrictionTransaction.spec.ts | 2 +- ...MosaicGlobalRestrictionTransaction.spec.ts | 2 +- .../RegisterNamespaceTransaction.spec.ts | 4 +- test/model/transaction/Transaction.spec.ts | 4 + 24 files changed, 531 insertions(+), 33 deletions(-) diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index 243b4ff560..de89c65970 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -20,6 +20,7 @@ import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTra import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -144,4 +145,26 @@ export class AccountAddressRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountAddressRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountAddressRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedAddressDto(RawAddress.stringToAddress(modification.value)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index 41e00509b0..0d8c60c32b 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -19,6 +19,7 @@ import { Builder } from '../../infrastructure/builders/AccountLinkTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/AccountLinkTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -138,4 +139,21 @@ export class AccountLinkTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountLinkTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.LINK_ACCOUNT.valueOf(), + new KeyDto(Convert.hexToUint8(this.remoteAccountKey)), + this.linkAction.valueOf(), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index cfac1c3ea1..f8275cf7eb 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -19,6 +19,7 @@ import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTra import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -143,4 +144,26 @@ export class AccountMosaicRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountMosaicRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_MOSAIC.valueOf(), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountMosaicRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedMosaicIdDto(modification.value), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index 4ed72af488..ac24764f6c 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -16,6 +16,13 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; @@ -26,13 +33,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; -import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; -import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; -import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; -import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; export class AccountOperationRestrictionTransaction extends Transaction { @@ -142,4 +142,26 @@ export class AccountOperationRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountOperationRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_OPERATION.valueOf(), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountOperationRestrictionModificationBuilder( + modification.modificationType.valueOf(), + modification.value.valueOf(), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 3744d2d651..3939d6c92b 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -14,11 +14,13 @@ * limitations under the License. */ +import { RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AddressAliasTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; import { AddressDto } from '../../infrastructure/catbuffer/AddressDto'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; @@ -35,7 +37,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { RawAddress } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -156,4 +157,22 @@ export class AddressAliasTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAddressAliasTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ADDRESS_ALIAS.valueOf(), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new AddressDto(RawAddress.stringToAddress(this.address.plain())), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 016f66fd8e..5f94e1fe33 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -211,4 +211,12 @@ export class AggregateTransaction extends Transaction { protected generateBytes(): Uint8Array { throw new Error('Not implemented'); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index 9ad23c1a60..52027d141d 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -14,8 +14,19 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/HashLockTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EmbeddedHashLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder'; +import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; +import { HashLockTransactionBuilder } from '../../infrastructure/catbuffer/HashLockTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicBuilder } from '../../infrastructure/catbuffer/UnresolvedMosaicBuilder'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { Mosaic } from '../mosaic/Mosaic'; @@ -142,6 +153,40 @@ export class LockFundsTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new HashLockTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.LOCK.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), + new AmountDto(this.mosaic.amount.toDTO())), + new BlockDurationDto(this.duration.toDTO()), + new Hash256Dto(Convert.hexToUint8(this.hash)), + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedHashLockTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.LOCK.valueOf(), + new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), + new AmountDto(this.mosaic.amount.toDTO())), + new BlockDurationDto(this.duration.toDTO()), + new Hash256Dto(Convert.hexToUint8(this.hash)), + ); + return transactionBuilder.serialize(); } } diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index dbc22505a7..f33e7af077 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -32,6 +32,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; /** * Modify multisig account transactions are part of the NEM's multisig account system. @@ -165,4 +166,27 @@ export class ModifyMultisigAccountTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMultisigAccountModificationTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MODIFY_MULTISIG_ACCOUNT.valueOf(), + this.minRemovalDelta, + this.minApprovalDelta, + this.modifications.map((modification) => { + return new CosignatoryModificationBuilder( + modification.type.valueOf(), + new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index 3bc49806c6..b1c62e0167 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -14,8 +14,17 @@ * limitations under the License. */ +import { RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicAddressRestrictionTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -155,6 +164,42 @@ export class MosaicAddressRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicAddressRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_ADDRESS_RESTRICTION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + this.restrictionKey.toDTO(), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.targetAddress.plain())), + this.previousRestrictionValue.toDTO(), + this.newRestrictionValue.toDTO(), + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicAddressRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_ADDRESS_RESTRICTION.valueOf(), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + this.restrictionKey.toDTO(), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.targetAddress.plain())), + this.previousRestrictionValue.toDTO(), + this.newRestrictionValue.toDTO(), + ); + return transactionBuilder.serialize(); } } diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index 0c52ad47eb..fef06fba35 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -17,6 +17,7 @@ import { Builder } from '../../infrastructure/builders/MosaicAliasTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { MosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/MosaicAliasTransactionBuilder'; @@ -151,4 +152,22 @@ export class MosaicAliasTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicAliasTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_ALIAS.valueOf(), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 7a41faddf9..8ac6e76eb0 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -16,8 +16,19 @@ import { Builder } from '../../infrastructure/builders/MosaicCreationTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EmbeddedMosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; +import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; +import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; +import { MosaicFlags } from '../mosaic/MosaicFlag'; import { MosaicId } from '../mosaic/MosaicId'; import { MosaicNonce } from '../mosaic/MosaicNonce'; import { MosaicProperties } from '../mosaic/MosaicProperties'; @@ -27,19 +38,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; -import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; -import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; -import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; -import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; -import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; -import { MosaicFlagsDto } from '../../infrastructure/catbuffer/MosaicFlagsDto'; -import { MosaicFlags } from '../mosaic/MosaicFlag'; -import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; -import { Convert } from '../../core/format'; -import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; /** * Before a mosaic can be created or transferred, a corresponding definition of the mosaic has to be created and published to the network. @@ -212,4 +210,25 @@ export class MosaicDefinitionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicDefinitionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_DEFINITION.valueOf(), + new MosaicNonceDto(this.getMosaicNonceIntValue()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + this.getMosaicFlagValue(), + this.mosaicProperties.divisibility, + new BlockDurationDto(this.mosaicProperties.duration ? + this.mosaicProperties.duration.toDTO() : []), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index 7cbb7a55d5..b2d421dca3 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -16,6 +16,13 @@ import { Builder } from '../../infrastructure/builders/MosaicGlobalRestrictionTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicGlobalRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicGlobalRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -178,6 +185,46 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicGlobalRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_GLOBAL_RESTRICTION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + new UnresolvedMosaicIdDto(this.referenceMosaicId.id.toDTO()), + this.restrictionKey.toDTO(), + this.previousRestrictionValue.toDTO(), + this.previousRestrictionType.valueOf(), + this.newRestrictionValue.toDTO(), + this.newRestrictionType.valueOf(), + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicGlobalRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_GLOBAL_RESTRICTION.valueOf(), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + new UnresolvedMosaicIdDto(this.referenceMosaicId.id.toDTO()), + this.restrictionKey.toDTO(), + this.previousRestrictionValue.toDTO(), + this.previousRestrictionType.valueOf(), + this.newRestrictionValue.toDTO(), + this.newRestrictionType.valueOf(), + ); + return transactionBuilder.serialize(); } } diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index b53fbd92d3..cc58bda02e 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -17,6 +17,7 @@ import { Builder } from '../../infrastructure/builders/MosaicSupplyChangeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { MosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -152,4 +153,22 @@ export class MosaicSupplyChangeTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicSupplyChangeTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_SUPPLY_CHANGE.valueOf(), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + this.direction.valueOf(), + new AmountDto(this.delta.toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index f1f29cd6a2..627397bc69 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -14,9 +14,17 @@ * limitations under the License. */ -import { Convert as convert } from '../../core/format'; +import { Convert, Convert as convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/NamespaceCreationTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EmbeddedNamespaceRegistrationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; +import { NamespaceRegistrationTransactionBuilder } from '../../infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import {NamespaceMosaicIdGenerator} from '../../infrastructure/transaction/NamespaceMosaicIdGenerator'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -187,6 +195,67 @@ export class RegisterNamespaceTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + let transactionBuilder: NamespaceRegistrationTransactionBuilder; + if (this.namespaceType === NamespaceType.RootNamespace) { + transactionBuilder = new NamespaceRegistrationTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.REGISTER_NAMESPACE.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), + new BlockDurationDto(this.duration!.toDTO()), + undefined, + ); + } else { + transactionBuilder = new NamespaceRegistrationTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.REGISTER_NAMESPACE.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), + undefined, + new NamespaceIdDto(this.parentId!.id.toDTO()), + ); + } + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + let transactionBuilder: EmbeddedNamespaceRegistrationTransactionBuilder; + if (this.namespaceType === NamespaceType.RootNamespace) { + transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_LOCK.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), + new BlockDurationDto(this.duration!.toDTO()), + undefined, + ); + } else { + transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_LOCK.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), + undefined, + new NamespaceIdDto(this.parentId!.id.toDTO()), + ); + } + return transactionBuilder.serialize(); } } diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index 9e02785071..9c0efaab1e 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -18,6 +18,7 @@ import { Builder } from '../../infrastructure/builders/SecretLockTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EmbeddedSecretLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -197,4 +198,25 @@ export class SecretLockTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedSecretLockTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_LOCK.valueOf(), + new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), + new AmountDto(this.mosaic.amount.toDTO())), + new BlockDurationDto(this.duration.toDTO()), + this.hashType.valueOf(), + new Hash256Dto(this.getSecretByte()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipient.plain())), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index 588638fcc6..acc1c53d7b 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -18,6 +18,7 @@ import { Convert, Convert as convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/SecretProofTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedSecretProofTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -178,4 +179,23 @@ export class SecretProofTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedSecretProofTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_PROOF.valueOf(), + this.hashType.valueOf(), + new Hash256Dto(this.getSecretByte()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipient.plain())), + this.getProofByte(), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index 0bc6786fb3..ceea1ab24c 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -90,6 +90,11 @@ export abstract class Transaction { */ protected abstract generateBytes(): Uint8Array; + /** + * @internal + */ + protected abstract generateEmbeddedBytes(): Uint8Array; + /** * @internal * Serialize and sign transaction creating a new SignedTransaction diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 31dea94577..08b6b29cc2 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -19,6 +19,7 @@ import { RawAddress } from '../../core/format/RawAddress'; import { Builder } from '../../infrastructure/builders/TransferTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedTransferTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedTransferTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -205,4 +206,24 @@ export class TransferTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const transactionBuilder = new EmbeddedTransferTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.TRANSFER.valueOf(), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), + this.getMessageBuffer(), + this.sortMosaics().map((mosaic) => { + return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), + new AmountDto(mosaic.amount.toDTO())); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/test/model/transaction/LockFundsTransaction.spec.ts b/test/model/transaction/LockFundsTransaction.spec.ts index ebd56dc4e0..df3583f1d7 100644 --- a/test/model/transaction/LockFundsTransaction.spec.ts +++ b/test/model/transaction/LockFundsTransaction.spec.ts @@ -15,6 +15,7 @@ */ import {deepEqual} from 'assert'; import {expect} from 'chai'; +import {Account} from '../../../src/model/account/Account'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; import {AggregateTransaction} from '../../../src/model/transaction/AggregateTransaction'; @@ -24,8 +25,11 @@ import {UInt64} from '../../../src/model/UInt64'; import {TestingAccount} from '../../conf/conf.spec'; describe('LockFundsTransaction', () => { - const account = TestingAccount; + let account: Account; const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; + before(() => { + account = TestingAccount; + }); it('should default maxFee field be set to 0', () => { const aggregateTransaction = AggregateTransaction.createBonded( Deadline.create(), @@ -58,7 +62,7 @@ describe('LockFundsTransaction', () => { UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(lockFundsTransaction.maxFee.higher).to.be.equal(0); @@ -100,6 +104,28 @@ describe('LockFundsTransaction', () => { }).to.throw(Error); }); + it('should create and sign LockFundsTransaction', () => { + const aggregateTransaction = AggregateTransaction.createBonded( + Deadline.create(), + [], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = account.sign(aggregateTransaction, generationHash); + const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), + NetworkCurrencyMosaic.createRelative(10), + UInt64.fromUint(10), + signedTransaction, + NetworkType.MIJIN_TEST, + ); + const signedTx = lockFundsTransaction.signWithCatbuffer(account, generationHash); + + expect(signedTx.payload.substring( + 136, + signedTransaction.payload.length - 32, + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE0190484100000000'); + }); + describe('size', () => { it('should return 176 for LockFundsTransaction transaction byte size', () => { const aggregateTransaction = AggregateTransaction.createBonded( diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index eb46016c85..1062a6afc4 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -70,7 +70,7 @@ describe('ModifyMultisigAccountTransaction', () => { NetworkType.MIJIN_TEST), )], NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(modifyMultisigAccountTransaction.maxFee.higher).to.be.equal(0); diff --git a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts index 947904ce56..02aad2fc65 100644 --- a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts @@ -47,7 +47,7 @@ describe('MosaicAddressRestrictionTransaction', () => { expect(mosaicAddressRestrictionTransaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(8).toHex()); expect(mosaicAddressRestrictionTransaction.targetAddress.plain()).to.be.equal(account.address.plain()); - const signedTransaction = mosaicAddressRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicAddressRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts index 39c409bd22..9e436d2fea 100644 --- a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts @@ -54,7 +54,7 @@ describe('MosaicGlobalRestrictionTransaction', () => { expect(mosaicGlobalRestrictionTransaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.EQ); expect(mosaicGlobalRestrictionTransaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); - const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicGlobalRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/RegisterNamespaceTransaction.spec.ts b/test/model/transaction/RegisterNamespaceTransaction.spec.ts index dcd12d95f7..db497c73b9 100644 --- a/test/model/transaction/RegisterNamespaceTransaction.spec.ts +++ b/test/model/transaction/RegisterNamespaceTransaction.spec.ts @@ -66,7 +66,7 @@ describe('RegisterNamespaceTransaction', () => { expect(registerNamespaceTransaction.duration!.lower).to.be.equal(1000); expect(registerNamespaceTransaction.duration!.higher).to.be.equal(0); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -83,7 +83,7 @@ describe('RegisterNamespaceTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index 8e8b4cc9d4..6f53048623 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -242,4 +242,8 @@ class FakeTransaction extends Transaction { protected generateBytes(): Uint8Array { throw new Error('Not implemented'); } + + protected generateEmbeddedBytes(): Uint8Array { + throw new Error('Not implemented'); + } } From 42eb3dccce7932983678e6a70491ad124992b95f Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 08:26:17 +0100 Subject: [PATCH 07/98] Applied catbuffer on aggregate transaction --- .../catbuffer/AggregateTransactionBuilder.ts | 6 +-- .../AccountAddressRestrictionTransaction.ts | 6 +-- .../transaction/AccountLinkTransaction.ts | 4 +- .../AccountMosaicRestrictionTransaction.ts | 6 +-- .../AccountOperationRestrictionTransaction.ts | 5 +- .../transaction/AddressAliasTransaction.ts | 6 +-- src/model/transaction/AggregateTransaction.ts | 47 +++++++++++++++++-- src/model/transaction/LockFundsTransaction.ts | 4 +- .../ModifyMultisigAccountTransaction.ts | 4 +- .../MosaicAddressRestrictionTransaction.ts | 6 +-- .../transaction/MosaicAliasTransaction.ts | 5 +- .../MosaicDefinitionTransaction.ts | 5 +- .../MosaicGlobalRestrictionTransaction.ts | 5 +- .../MosaicSupplyChangeTransaction.ts | 5 +- .../RegisterNamespaceTransaction.ts | 5 +- .../transaction/SecretLockTransaction.ts | 4 +- .../transaction/SecretProofTransaction.ts | 4 +- src/model/transaction/Transaction.ts | 9 ++++ src/model/transaction/TransferTransaction.ts | 3 +- .../transaction/AggregateTransaction.spec.ts | 2 +- 20 files changed, 81 insertions(+), 60 deletions(-) diff --git a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts index 64b11c499f..20462d8514 100644 --- a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts +++ b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts @@ -19,14 +19,10 @@ *** along with Catapult. If not, see . **/ -import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; -import { AddressDto } from './AddressDto'; -import { AliasActionDto } from './AliasActionDto'; import { AmountDto } from './AmountDto'; import { EntityTypeDto } from './EntityTypeDto'; import { GeneratorUtils } from './GeneratorUtils'; import { KeyDto } from './KeyDto'; -import { NamespaceIdDto } from './NamespaceIdDto'; import { SignatureDto } from './SignatureDto'; import { TimestampDto } from './TimestampDto'; import { TransactionBuilder } from './TransactionBuilder'; @@ -129,7 +125,7 @@ export class AggregateTransactionBuilder extends TransactionBuilder { newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes); const transactionBytes = this.transactions; newArray = GeneratorUtils.concatTypedArrays(newArray, transactionBytes); - const cosignaturesBytes = this.transactions; + const cosignaturesBytes = this.cosignatures; newArray = GeneratorUtils.concatTypedArrays(newArray, cosignaturesBytes); return newArray; } diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index de89c65970..fd4200205c 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RawAddress } from '../../core/format'; +import { Convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; @@ -151,10 +151,8 @@ export class AccountAddressRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountAddressRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), this.restrictionType.valueOf(), diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index 0d8c60c32b..bd0a0303db 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -145,10 +145,8 @@ export class AccountLinkTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountLinkTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.LINK_ACCOUNT.valueOf(), new KeyDto(Convert.hexToUint8(this.remoteAccountKey)), diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index f8275cf7eb..efe54c41d8 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -14,13 +14,13 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; @@ -150,10 +150,8 @@ export class AccountMosaicRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountMosaicRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ACCOUNT_RESTRICTION_MOSAIC.valueOf(), this.restrictionType.valueOf(), diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index ac24764f6c..b42d33e3ab 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; @@ -148,10 +149,8 @@ export class AccountOperationRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountOperationRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ACCOUNT_RESTRICTION_OPERATION.valueOf(), this.restrictionType.valueOf(), diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 3939d6c92b..e1149b090e 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RawAddress } from '../../core/format'; +import { Convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AddressAliasTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; @@ -163,10 +163,8 @@ export class AddressAliasTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAddressAliasTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ADDRESS_ALIAS.valueOf(), this.actionType.valueOf(), diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 5f94e1fe33..797eb757e5 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -15,8 +15,16 @@ */ import { SignSchema } from '../../core/crypto'; -import { Builder } from '../../infrastructure/builders/AggregateTransaction'; +import { Convert } from '../../core/format'; import { AggregateTransaction as AggregatedTransactionCore} from '../../infrastructure/builders/AggregateTransaction'; +import { Builder } from '../../infrastructure/builders/AggregateTransaction'; +import { AggregateTransactionBuilder } from '../../infrastructure/catbuffer/AggregateTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { CosignatureBuilder } from '../../infrastructure/catbuffer/CosignatureBuilder'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { Account } from '../account/Account'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -209,7 +217,40 @@ export class AggregateTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + let transactions = Uint8Array.from([]); + this.innerTransactions.forEach((transaction) => { + const transactionByte = transaction.toAggregateTransactionBytes(); + transactions = GeneratorUtils.concatTypedArrays(transactions, transactionByte); + }); + + const cosignatures = Uint8Array.from([]); + this.cosignatures.forEach((cosignature) => { + const signerBytes = Convert.hexToUint8(cosignature.signer.publicKey); + const signatureBytes = Convert.hexToUint8(cosignature.signature); + const cosignatureBytes = new CosignatureBuilder( + new KeyDto(signerBytes), + new SignatureDto(signatureBytes), + ).serialize(); + transactions = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); + }); + + console.log('cosignatures', Convert.uint8ToHex(cosignatures)); + console.log('transactions', Convert.uint8ToHex(transactions)); + + const transactionBuilder = new AggregateTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + this.type.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + transactions, + cosignatures, + ); + return transactionBuilder.serialize(); } /** @@ -217,6 +258,6 @@ export class AggregateTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - throw new Error('Not implemented'); + throw new Error('Method not implemented'); } } diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index 52027d141d..e34bb40489 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -176,10 +176,8 @@ export class LockFundsTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedHashLockTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.LOCK.valueOf(), new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index f33e7af077..fa1e35dfef 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -172,10 +172,8 @@ export class ModifyMultisigAccountTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMultisigAccountModificationTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MODIFY_MULTISIG_ACCOUNT.valueOf(), this.minRemovalDelta, diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index b1c62e0167..819d69c43c 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RawAddress } from '../../core/format'; +import { Convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicAddressRestrictionTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -188,10 +188,8 @@ export class MosaicAddressRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicAddressRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_ADDRESS_RESTRICTION.valueOf(), new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index fef06fba35..39b064bb16 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicAliasTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -158,10 +159,8 @@ export class MosaicAliasTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicAliasTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_ALIAS.valueOf(), this.actionType.valueOf(), diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 8ac6e76eb0..c0adbd1e8b 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicCreationTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -216,10 +217,8 @@ export class MosaicDefinitionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicDefinitionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_DEFINITION.valueOf(), new MosaicNonceDto(this.getMosaicNonceIntValue()), diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index b2d421dca3..7b4f757efc 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicGlobalRestrictionTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -211,10 +212,8 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicGlobalRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_GLOBAL_RESTRICTION.valueOf(), new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index cc58bda02e..be4f3a89a3 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -33,6 +33,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { Convert } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -159,10 +160,8 @@ export class MosaicSupplyChangeTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicSupplyChangeTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_SUPPLY_CHANGE.valueOf(), new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index 627397bc69..0cdcae2aa6 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -233,11 +233,10 @@ export class RegisterNamespaceTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); let transactionBuilder: EmbeddedNamespaceRegistrationTransactionBuilder; if (this.namespaceType === NamespaceType.RootNamespace) { transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.SECRET_LOCK.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), @@ -247,7 +246,7 @@ export class RegisterNamespaceTransaction extends Transaction { ); } else { transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.SECRET_LOCK.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index 9c0efaab1e..e65187384d 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -204,10 +204,8 @@ export class SecretLockTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedSecretLockTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.SECRET_LOCK.valueOf(), new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index acc1c53d7b..41df6b207b 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -185,10 +185,8 @@ export class SecretProofTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedSecretProofTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.SECRET_PROOF.valueOf(), this.hashType.valueOf(), diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index ceea1ab24c..ca2fbbce44 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -186,6 +186,15 @@ export abstract class Transaction { return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {signer}); } + /** + * Takes a transaction and formats bytes to be included in an aggregate transaction. + * + * @return transaction with signer serialized to be part of an aggregate transaction + */ + public toAggregateTransactionBytes() { + return this.generateEmbeddedBytes(); + } + /** * Transaction pending to be included in a block * @returns {boolean} diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 08b6b29cc2..6714fd7904 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -212,9 +212,8 @@ export class TransferTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); const transactionBuilder = new EmbeddedTransferTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.TRANSFER.valueOf(), new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index ab53059940..d6a4c714aa 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -106,7 +106,7 @@ describe('AggregateTransaction', () => { NetworkType.MIJIN_TEST, []); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); + const signedTransaction = aggregateTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); From bf80aa6430092a11e6d75b8db14868aeaab0638f Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 11:46:27 +0100 Subject: [PATCH 08/98] Removed old flatbuffer staffs --- e2e/conf/network.conf | 64 +- .../buffers/AccountLinkTransactionBuffer.ts | 425 ---------- ...untRestrictionsAddressTransactionBuffer.ts | 557 ------------- ...RestrictionsEntityTypeTransactionBuffer.ts | 520 ------------ ...ountRestrictionsMosaicTransactionBuffer.ts | 557 ------------- .../buffers/AddressAliasTransactionBuffer.ts | 479 ----------- .../buffers/AggregateTransactionBuffer.ts | 425 ---------- .../buffers/HashLockTransactionBuffer.ts | 571 ------------- ...saicAddressRestrictionTransactionBuffer.ts | 625 -------------- .../buffers/MosaicAliasTransactionBuffer.ts | 479 ----------- .../MosaicCreationTransactionBuffer.ts | 582 ------------- ...osaicGlobalRestrictionTransactionBuffer.ts | 657 --------------- .../MosaicSupplyChangeTransactionBuffer.ts | 479 ----------- .../MultisigModificationTransactionBuffer.ts | 571 ------------- .../NamespaceCreationTransactionBuffer.ts | 512 ------------ .../buffers/SecretLockTransactionBuffer.ts | 641 -------------- .../buffers/SecretProofTransactionBuffer.ts | 549 ------------ .../buffers/TransferTransactionBuffer.ts | 785 ------------------ .../builders/AccountLinkTransaction.ts | 110 --- .../AccountRestrictionsAddressTransaction.ts | 128 --- ...ccountRestrictionsEntityTypeTransaction.ts | 126 --- .../AccountRestrictionsMosaicTransaction.ts | 127 --- .../builders/AddressAliasTransaction.ts | 122 --- .../builders/AggregateTransaction.ts | 151 ---- .../builders/CosignatureTransaction.ts | 27 - src/infrastructure/builders/Deadline.ts | 22 - .../builders/HashLockTransaction.ts | 127 --- .../MosaicAddressRestrictionTransaction.ts | 146 ---- .../builders/MosaicAliasTransaction.ts | 122 --- .../builders/MosaicCreationTransaction.ts | 164 ---- .../MosaicGlobalRestrictionTransaction.ts | 159 ---- .../builders/MosaicSupplyChangeTransaction.ts | 120 --- .../MultisigModificationTransaction.ts | 134 --- .../builders/NamespaceCreationTransaction.ts | 142 ---- .../builders/SecretLockTransaction.ts | 142 ---- .../builders/SecretProofTransaction.ts | 127 --- .../builders/TransferTransaction.ts | 152 ---- .../builders/VerifiableTransaction.ts | 128 --- .../builders/VerificableTransactionBuilder.ts | 65 -- .../schemas/AccountLinkTransactionSchema.ts | 44 - ...onsAddressModificationTransactionSchema.ts | 48 -- ...EntityTypeModificationTransactionSchema.ts | 48 -- ...ionsMosaicModificationTransactionSchema.ts | 48 -- .../schemas/AddressAliasTransactionSchema.ts | 44 - .../schemas/AggregateTransactionSchema.ts | 44 - .../schemas/HashLockTransactionSchema.ts | 45 - ...saicAddressRestrictionTransactionSchema.ts | 46 - .../schemas/MosaicAliasTransactionSchema.ts | 44 - .../MosaicCreationTransactionSchema.ts | 63 -- ...osaicGlobalRestrictionTransactionSchema.ts | 49 -- .../MosaicSupplyChangeTransactionSchema.ts | 44 - .../MultisigModificationTransactionSchema.ts | 49 -- .../NamespaceCreationTransactionSchema.ts | 47 -- src/infrastructure/schemas/Schema.ts | 374 --------- .../schemas/SecretLockTransactionSchema.ts | 48 -- .../schemas/SecretProofTransactionSchema.ts | 47 -- .../schemas/TransferTransactionSchema.ts | 55 -- .../CreateTransactionFromPayload.ts | 14 +- src/model/namespace/AliasActionType.ts | 4 +- .../AccountAddressRestrictionTransaction.ts | 17 - .../transaction/AccountLinkTransaction.ts | 16 - .../AccountMosaicRestrictionTransaction.ts | 16 - .../AccountOperationRestrictionTransaction.ts | 16 - .../transaction/AddressAliasTransaction.ts | 17 - src/model/transaction/AggregateTransaction.ts | 67 +- .../transaction/CosignatureTransaction.ts | 39 +- src/model/transaction/LockFundsTransaction.ts | 19 - .../ModifyMultisigAccountTransaction.ts | 19 +- .../MosaicAddressRestrictionTransaction.ts | 19 - .../transaction/MosaicAliasTransaction.ts | 17 - .../MosaicDefinitionTransaction.ts | 35 +- .../MosaicGlobalRestrictionTransaction.ts | 21 - .../MosaicSupplyChangeTransaction.ts | 19 +- .../RegisterNamespaceTransaction.ts | 28 +- .../transaction/SecretLockTransaction.ts | 21 - .../transaction/SecretProofTransaction.ts | 19 - src/model/transaction/Transaction.ts | 88 +- src/model/transaction/TransferTransaction.ts | 35 +- .../AccountLinkTransaction.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 6 +- .../AddressAliasTransaction.spec.ts | 4 +- .../transaction/AggregateTransaction.spec.ts | 8 +- .../transaction/LockFundsTransaction.spec.ts | 2 +- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- ...osaicAddressRestrictionTransaction.spec.ts | 2 +- .../MosaicAliasTransaction.spec.ts | 4 +- .../MosaicDefinitionTransaction.spec.ts | 8 +- ...MosaicGlobalRestrictionTransaction.spec.ts | 2 +- .../RegisterNamespaceTransaction.spec.ts | 4 +- .../transaction/SecretLockTransaction.spec.ts | 2 +- .../SecretProofTransaction.spec.ts | 2 +- test/model/transaction/Transaction.spec.ts | 5 - .../transaction/TransferTransaction.spec.ts | 2 +- 93 files changed, 179 insertions(+), 13628 deletions(-) delete mode 100644 src/infrastructure/buffers/AccountLinkTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AccountRestrictionsAddressTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AccountRestrictionsEntityTypeTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AccountRestrictionsMosaicTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AddressAliasTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AggregateTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/HashLockTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicAddressRestrictionTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicAliasTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicCreationTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicGlobalRestrictionTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicSupplyChangeTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MultisigModificationTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/NamespaceCreationTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/SecretLockTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/SecretProofTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/TransferTransactionBuffer.ts delete mode 100644 src/infrastructure/builders/AccountLinkTransaction.ts delete mode 100644 src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts delete mode 100644 src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts delete mode 100644 src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts delete mode 100644 src/infrastructure/builders/AddressAliasTransaction.ts delete mode 100644 src/infrastructure/builders/AggregateTransaction.ts delete mode 100644 src/infrastructure/builders/CosignatureTransaction.ts delete mode 100644 src/infrastructure/builders/Deadline.ts delete mode 100644 src/infrastructure/builders/HashLockTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicAddressRestrictionTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicAliasTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicCreationTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicGlobalRestrictionTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicSupplyChangeTransaction.ts delete mode 100644 src/infrastructure/builders/MultisigModificationTransaction.ts delete mode 100644 src/infrastructure/builders/NamespaceCreationTransaction.ts delete mode 100644 src/infrastructure/builders/SecretLockTransaction.ts delete mode 100644 src/infrastructure/builders/SecretProofTransaction.ts delete mode 100644 src/infrastructure/builders/TransferTransaction.ts delete mode 100644 src/infrastructure/builders/VerifiableTransaction.ts delete mode 100644 src/infrastructure/builders/VerificableTransactionBuilder.ts delete mode 100644 src/infrastructure/schemas/AccountLinkTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AccountRestrictionsAddressModificationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AccountRestrictionsEntityTypeModificationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AccountRestrictionsMosaicModificationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AddressAliasTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AggregateTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/HashLockTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicAddressRestrictionTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicAliasTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicCreationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicGlobalRestrictionTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicSupplyChangeTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MultisigModificationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/NamespaceCreationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/Schema.ts delete mode 100644 src/infrastructure/schemas/SecretLockTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/SecretProofTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/TransferTransactionSchema.ts diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index 95fa85d3c7..79f895aecf 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -1,54 +1,54 @@ { - "apiUrl": "http://localhost:3000", + "apiUrl": "http://c2.nem.ninja:3000", "generationHash": "57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6", "testAccount": { - "privateKey": "D242FB34C2C4DD36E995B9C865F93940065E326661BA5A4A247331D211FE3A3D", - "address": "SBMYYFIM6VGG45KWGSZLSXFHP74WVT7MOF6UYBHT", - "publicKey": "2FC3872A792933617D70E02AFF8FBDE152821A0DF0CA5FB04CB56FC3D21C8863" + "privateKey": "E1C8521608F4896CA26A0C2DE739310EA4B06861D126CF4D6922064678A1969B", + "address": "SAKT3CKHCYIG5BBOPTSY2WXSVPBSLIA67AEOX4ND", + "publicKey": "9F784BF20318AE3CA6246C0EC2207FE095FFF7A84B6787E7E3C2CE4C3B92A2EA" }, "multisigAccount": { - "privateKey": "6EBE2AB0584C816771B494B36B40EC6CE1A0024C37DC6056D89D570A21A70262", - "address": "SCJAK5N6ICIE3JGHV5SVDSSNM5RUZZVDWQJ5G76N", - "publicKey": "224556169645EFAB772BFE1B5665490334428017E5D86FB3C9DFC4070B2F16A6" + "privateKey": "A9CEAA617D0B7D9DEBE9F96BD63CCF68A49950BB315CB9A4169FC6AAA1EC9E28", + "address": "SDWY3PYN4ZZO4S4EBEY2UPSSZUPGZH2G2LQMUSEU", + "publicKey": "8A613468924B8771779C7E4C889205A9BE6CAE0B9435B4BCC8E79A8DD8571608" }, "cosignatoryAccount": { - "privateKey": "44C0044B36AEF44C7743C407CEE4B6FD801BF6B0652AB7799B0991FFD3A81E71", - "address": "SCPL4YCGZYCML5WUSCIVN5MQF5YZAAF4GMZJIEL4", - "publicKey": "76C1622C7FB58986E500228E8FFB30C606CAAFC1CD78E770E82C73DAB7BD7C9F" + "privateKey": "8CBAA7491B7DC1070BECBC4F60AE55F4A272DA1DAD1D502DB016E142993817BA", + "address": "SB7Q5A3KEKFEWBPBTC6RFKU6Q2L4V7DM4ZNE4A7A", + "publicKey": "61B8EB2C02F3D3731A8EF6FE4CCD6BC84615BABA09CA3E891C0D2542096E6AD3" }, "cosignatory2Account": { - "privateKey": "F7B3A64652BAE6DB00D8B7C45F9D1C9BE0DB9E02002111A0B547AE1E220B7DDC", - "address": "SBISV4QCGJ7SSOLG64DBNPWU6J7SSY64R22D2L3Q", - "publicKey": "B5C2611E32E16482B0B9811ABF906A1DE84184DED1D343790482F517C02FB01C" + "privateKey": "60380027EBE63A5D60F6156F5637685172331705160783FF2F9D93C1E5A8622B", + "address": "SCM47E3JVPHOFWLSMNX3RKQQQIB3JUBR7MTX4M4P", + "publicKey": "3D9996683A0FA460D13288B846DF68A9B6C0C1F14EC2E43907DF8D84DC87B9C2" }, "cosignatory3Account": { - "privateKey": "A7D6ED74CDDECBF621DDC63558433DB604FA800D138810B3DF9B4EC880D0705F", - "address": "SD2UY5LHIAAZDVKRHBOYSS4MTLHVTJVUTQPEGV2U", - "publicKey": "3A33DA75E00F643C49C57E8BD3282149911B06FF107C37F7AEDFED5532166BDA" + "privateKey": "E39CE241F730CD190658AFDB5F3896628F92D7BC35D88435D148BED88C6CC844", + "address": "SDEVG5MU4MEGJ72NSBC7PKMK7JCJKN7QB3DOVARJ", + "publicKey": "422697046582D8B8063931B7327D0C06FA454B416F6A5C000922EC5BA546F4B2" }, "cosignatory4Account": { - "privateKey": "D2A12301F5595869EFD5374B3372F0ED7EC26BF73A71D310950CC018D3FA0B03", - "address": "SD7PYMM2BTT4SGSITZ2MBQBK4SXIQQQV4ZOP46VF", - "publicKey": "FDE589878756C2287056EC8D7B2829D9C1FA6D389EBDC808034813FE7810AAB0" + "privateKey": "0EA7E63C96FC580AD5EE85ED3C77A96B421F7C8BF75A83AB889313114C9082F2", + "address": "SCBNKMD23J7BO3Q42SEGP4LXGVJYSDPUESSEWGWZ", + "publicKey": "3A225A2C7C7D95279E74D420728D2DA2A176DE036B67909074AEF5F2DCFAF31C" }, "testAccount2": { - "privateKey": "E5DCCEBDB01A8B03A7DB7BA5888E2E33FD4617B5F6FED48C4C09C0780F422713", - "address": "SBSBLBT7CIOQG6XUI7TRDMHV4TKS5O7QM3MWQYHL", - "publicKey": "5F14CD455A1C0B08073C657EFA09365921736C1ADAF0F0685848678AE966EE09" + "privateKey": "A084418D937627BCDA19B277D8610C845124149FA18AABE96A17D56A2EA7FB8B", + "address": "SBF5HY3T7SXIBCSK4V4WNS4LS4QUMESMVNBCD2AQ", + "publicKey": "1C4B44400FDC933860B1949A5AEA756F19A36D73C4634699E49C3E7275EFA54F" }, "testAccount3": { - "privateKey": "CA95470BEFF4487D692D501E5C41F86FAE9CE6DD15B7B64E150E42A18BDE9CF8", - "address": "SBCFDASM35I6JSLUPQMSX2WGJG55WOCNB53NNVPH", - "publicKey": "E97077A656D9E7F5679880D4950BBF2B3638B7ACE17C82CCB7881DE9BAF396C6" + "privateKey": "8C9E72C5D8964A19174B478B65BD4B7F2AFD8F92C05AE45B15A9EDF222EC8CA8", + "address": "SDY65GIMMOF7GZGGART66QGS6ELWDTQT55JJOF42", + "publicKey": "B8320002C5CF64D855F073F2387FB18F13E7A04FA57FC3743694B04579104F98" }, "testAccountNoBalance": { - "privateKey": "A0591F79F588758280DFB4823A47FCEEC6A551344F794FFDE3760A9D7E1DE348", - "address": "SC5NTT5APX2FAUS4VQUII3UTMAD7GHRFTLDQOEDW", - "publicKey": "6D652E480E5B2997A19D0C7485724693D79A63FCD591A948B40240BD196BA7D6" + "privateKey": "CE4E6B1113EF8999ED79A027A4F3255C367BC2E40417E27E614FB7C12E42BDFA", + "address": "SDNMDW5TXIORKRXQ7F3QORRW4KUAK4ALQ7JWX2KJ", + "publicKey": "92658FE642AEAF1B766D0F4FE4E263C3A0E069735836383D31A70E2B7801358B" }, "harvestingAccount": { - "privateKey": "0B9802C011DA2D61BCD203F4DC76C012898EE38BA54A7E030B86630A8FD43CA6", - "address": "SAALWHKCWH72J53M3M4LB6UYFGLQMAOXJACWJX2U", - "publicKey": "092CAAFEBCB51C64A7CE423050964492407B264CA306D063DBA927A2304C4DD8" + "privateKey": "9999630E4AE5CA5675A703F3268084EB9A9B477A8C519D66465D5D21830E691A", + "address": "SC2PGQO5WV4QZRAQHJDNQ2Q5IFWA2D3VLFEFFZHC", + "publicKey": "74771A0B0B920D787F4F8242926C348007B23062910DE99C7E56AA79D4D7B90A" } -} \ No newline at end of file +} diff --git a/src/infrastructure/buffers/AccountLinkTransactionBuffer.ts b/src/infrastructure/buffers/AccountLinkTransactionBuffer.ts deleted file mode 100644 index 30dde827ce..0000000000 --- a/src/infrastructure/buffers/AccountLinkTransactionBuffer.ts +++ /dev/null @@ -1,425 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.AccountLinkTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AccountLinkTransactionBuffer} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AccountLinkTransactionBuffer=} obj - * @returns {Catapult.Buffers.AccountLinkTransactionBuffer} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.getRootAsAccountLinkTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AccountLinkTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signerLength = function() { - let offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signerArray = function() { - let offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.version = function() { - let offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.type = function() { - let offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.fee = function(index) { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.feeLength = function() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.feeArray = function() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.deadline = function(index) { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.deadlineLength = function() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.deadlineArray = function() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.remoteAccountKey = function(index) { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.remoteAccountKeyLength = function() { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.remoteAccountKeyArray = function() { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.linkAction = function() { - const offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startAccountLinkTransactionBuffer = function(builder) { - builder.startObject(12); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} remoteAccountKey - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addRemoteAccountKey = function(builder, remoteAccountKeyOffset) { - builder.addFieldOffset(7, remoteAccountKeyOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createRemoteAccountKeyVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startRemoteAccountKeyVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} linkAction - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addLinkAction = function(builder, linkAction) { - builder.addFieldInt8(8, linkAction, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.endAccountLinkTransactionBuffer = function(builder) { - const offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.finishAccountLinkTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AccountRestrictionsAddressTransactionBuffer.ts b/src/infrastructure/buffers/AccountRestrictionsAddressTransactionBuffer.ts deleted file mode 100644 index 7f71878ffc..0000000000 --- a/src/infrastructure/buffers/AccountRestrictionsAddressTransactionBuffer.ts +++ /dev/null @@ -1,557 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.RestrictionAddressModificationBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.RestrictionAddressModificationBuffer} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.RestrictionAddressModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionAddressModificationBuffer} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.getRootAsRestrictionAddressModificationBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.RestrictionAddressModificationBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.modificationType = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.value = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.valueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.valueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.startRestrictionAddressModificationBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.addModificationType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} valueOffset - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.addValue = function(builder, valueOffset) { - builder.addFieldOffset(1, valueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.createValueVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.startValueVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.endRestrictionAddressModificationBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer=} obj - * @returns {Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.getRootAsAccountRestrictionsAddressTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.restrictionType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.modificationCount = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.RestrictionAddressModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionAddressModificationBuffer} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.modifications = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? (obj || new Catapult.Buffers.RestrictionAddressModificationBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.modificationsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startAccountRestrictionsAddressTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} restrictionType - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addRestrictionType = function(builder, restrictionType) { - builder.addFieldInt8(7, restrictionType, 0); -}; - - -/** - * @param {flatbuffers.Builder} builder - * @param {number} modificationCount - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addModificationCount = function(builder, modificationCount) { - builder.addFieldInt8(8, modificationCount, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} modificationsOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addModifications = function(builder, modificationsOffset) { - builder.addFieldOffset(9, modificationsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createModificationsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startModificationsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.endAccountRestrictionsAddressTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.finishAccountRestrictionsAddressTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AccountRestrictionsEntityTypeTransactionBuffer.ts b/src/infrastructure/buffers/AccountRestrictionsEntityTypeTransactionBuffer.ts deleted file mode 100644 index b842f8d776..0000000000 --- a/src/infrastructure/buffers/AccountRestrictionsEntityTypeTransactionBuffer.ts +++ /dev/null @@ -1,520 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.RestrictionEntityTypeModificationBuffer} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.RestrictionEntityTypeModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionEntityTypeModificationBuffer} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.getRootAsRestrictionEntityTypeModificationBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.RestrictionEntityTypeModificationBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.prototype.modificationType = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.prototype.value = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.startRestrictionEntityTypeModificationBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.addModificationType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} valueOffset - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.addValue = function(builder, valueOffset) { - builder.addFieldInt16(1, valueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.endRestrictionEntityTypeModificationBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer=} obj - * @returns {Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.getRootAsAccountRestrictionsEntityTypeTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.restrictionType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.modificationCount = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.RestrictionEntityTypeModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionEntityTypeModificationBuffer} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.modifications = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? (obj || new Catapult.Buffers.RestrictionEntityTypeModificationBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.modificationsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startAccountRestrictionsEntityTypeTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} restrictionType - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addRestrictionType = function(builder, restrictionType) { - builder.addFieldInt8(7, restrictionType, 0); -}; - - -/** - * @param {flatbuffers.Builder} builder - * @param {number} modificationCount - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addModificationCount = function(builder, modificationCount) { - builder.addFieldInt8(8, modificationCount, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} modificationsOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addModifications = function(builder, modificationsOffset) { - builder.addFieldOffset(9, modificationsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createModificationsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startModificationsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.endAccountRestrictionsEntityTypeTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.finishAccountRestrictionsEntityTypeTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AccountRestrictionsMosaicTransactionBuffer.ts b/src/infrastructure/buffers/AccountRestrictionsMosaicTransactionBuffer.ts deleted file mode 100644 index 2fde91933f..0000000000 --- a/src/infrastructure/buffers/AccountRestrictionsMosaicTransactionBuffer.ts +++ /dev/null @@ -1,557 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.RestrictionMosaicModificationBuffer} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.RestrictionMosaicModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionMosaicModificationBuffer} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.getRootAsRestrictionMosaicModificationBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.RestrictionMosaicModificationBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.modificationType = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.value = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.valueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.valueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.startRestrictionMosaicModificationBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.addModificationType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} valueOffset - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.addValue = function(builder, valueOffset) { - builder.addFieldOffset(1, valueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.createValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.startValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.endRestrictionMosaicModificationBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer=} obj - * @returns {Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.getRootAsAccountRestrictionsMosaicTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.restrictionType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.modificationCount = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.RestrictionMosaicModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionMosaicModificationBuffer} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.modifications = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? (obj || new Catapult.Buffers.RestrictionMosaicModificationBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.modificationsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startAccountRestrictionsMosaicTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} restrictionType - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addRestrictionType = function(builder, restrictionType) { - builder.addFieldInt8(7, restrictionType, 0); -}; - - -/** - * @param {flatbuffers.Builder} builder - * @param {number} modificationCount - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addModificationCount = function(builder, modificationCount) { - builder.addFieldInt8(8, modificationCount, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} modificationsOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addModifications = function(builder, modificationsOffset) { - builder.addFieldOffset(9, modificationsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createModificationsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startModificationsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.endAccountRestrictionsMosaicTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.finishAccountRestrictionsMosaicTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AddressAliasTransactionBuffer.ts b/src/infrastructure/buffers/AddressAliasTransactionBuffer.ts deleted file mode 100644 index 48dd845503..0000000000 --- a/src/infrastructure/buffers/AddressAliasTransactionBuffer.ts +++ /dev/null @@ -1,479 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.AddressAliasTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AddressAliasTransactionBuffer} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AddressAliasTransactionBuffer=} obj - * @returns {Catapult.Buffers.AddressAliasTransactionBuffer} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.getRootAsAddressAliasTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AddressAliasTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.actionType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.namespaceId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.namespaceIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.namespaceIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.address = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.addressLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.addressArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startAddressAliasTransactionBuffer = function(builder) { - builder.startObject(10); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} actionType - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addActionType = function(builder, actionType) { - builder.addFieldInt8(7, actionType, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deltaOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addNamespaceId = function(builder, namespaceIdOffset) { - builder.addFieldOffset(8, namespaceIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createNamespaceIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startNamespaceIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addAddress = function(builder, addressOffset) { - builder.addFieldOffset(9, addressOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createAddressVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startAddressVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.endAddressAliasTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.finishAddressAliasTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AggregateTransactionBuffer.ts b/src/infrastructure/buffers/AggregateTransactionBuffer.ts deleted file mode 100644 index e2f9f68e83..0000000000 --- a/src/infrastructure/buffers/AggregateTransactionBuffer.ts +++ /dev/null @@ -1,425 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.AggregateTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AggregateTransactionBuffer} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AggregateTransactionBuffer=} obj - * @returns {Catapult.Buffers.AggregateTransactionBuffer} - */ -Catapult.Buffers.AggregateTransactionBuffer.getRootAsAggregateTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AggregateTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.transactionsSize = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.transactions = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.transactionsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.transactionsArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AggregateTransactionBuffer.startAggregateTransactionBuffer = function(builder) { - builder.startObject(9); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AggregateTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AggregateTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AggregateTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} transactionsSize - */ -Catapult.Buffers.AggregateTransactionBuffer.addTransactionsSize = function(builder, transactionsSize) { - builder.addFieldInt32(7, transactionsSize, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} transactionsOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addTransactions = function(builder, transactionsOffset) { - builder.addFieldOffset(8, transactionsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createTransactionsVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startTransactionsVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.endAggregateTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AggregateTransactionBuffer.finishAggregateTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/HashLockTransactionBuffer.ts b/src/infrastructure/buffers/HashLockTransactionBuffer.ts deleted file mode 100644 index ed4f0d4d8d..0000000000 --- a/src/infrastructure/buffers/HashLockTransactionBuffer.ts +++ /dev/null @@ -1,571 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.HashLockTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.HashLockTransactionBuffer} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.HashLockTransactionBuffer=} obj - * @returns {Catapult.Buffers.HashLockTransactionBuffer} - */ -Catapult.Buffers.HashLockTransactionBuffer.getRootAsHashLockTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.HashLockTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicAmount = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicAmountLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicAmountArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.duration = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.durationLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.durationArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.hash = function(index) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.hashLength = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.hashArray = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.HashLockTransactionBuffer.startHashLockTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.HashLockTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.HashLockTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.HashLockTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicAmountOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addMosaicAmount = function(builder, mosaicAmountOffset) { - builder.addFieldOffset(8, mosaicAmountOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createMosaicAmountVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startMosaicAmountVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} durationOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addDuration = function(builder, durationOffset) { - builder.addFieldOffset(9, durationOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createDurationVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startDurationVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} hashOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addHash = function(builder, hashOffset) { - builder.addFieldOffset(10, hashOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createHashVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startHashVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.endHashLockTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.HashLockTransactionBuffer.finishHashLockTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicAddressRestrictionTransactionBuffer.ts b/src/infrastructure/buffers/MosaicAddressRestrictionTransactionBuffer.ts deleted file mode 100644 index a306031841..0000000000 --- a/src/infrastructure/buffers/MosaicAddressRestrictionTransactionBuffer.ts +++ /dev/null @@ -1,625 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.getRootAsMosaicAddressRestrictionTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.restrictionKey = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.restrictionKeyLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.restrictionKeyArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.targetAddress = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.targetAddressLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.targetAddressArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.previousRestrictionValue = function(index) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.previousRestrictionValueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.previousRestrictionValueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.newRestrictionValue = function(index) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.newRestrictionValueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.newRestrictionValueValueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startMosaicAddressRestrictionTransactionBuffer = function(builder) { - builder.startObject(14); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} restrictionKeyOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addRestrictionKey = function(builder, restrictionKeyOffset) { - builder.addFieldOffset(8, restrictionKeyOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createRestrictionKeyVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startRestrictionKeyVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} targetAddressOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addTargetAddress = function(builder, targetAddressOffset) { - builder.addFieldOffset(9, targetAddressOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createTargetAddressVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startTargetAddressVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} previousRestrictionValueOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addPreviousRestrictionValue = function(builder, previousRestrictionValueOffset) { - builder.addFieldOffset(10, previousRestrictionValueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createPreviousRestrictionValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startPreviousRestrictionValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} newRestrictionValueOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addNewRestrictionValue = function(builder, newRestrictionValueOffset) { - builder.addFieldOffset(11, newRestrictionValueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createNewRestrictionValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startNewRestrictionValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.endMosaicAddressRestrictionTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.finishMosaicAddressRestrictionTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicAliasTransactionBuffer.ts b/src/infrastructure/buffers/MosaicAliasTransactionBuffer.ts deleted file mode 100644 index ee4d523f8d..0000000000 --- a/src/infrastructure/buffers/MosaicAliasTransactionBuffer.ts +++ /dev/null @@ -1,479 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicAliasTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicAliasTransactionBuffer} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicAliasTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicAliasTransactionBuffer} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.getRootAsMosaicAliasTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicAliasTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.actionType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.namespaceId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.namespaceIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.namespaceIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startMosaicAliasTransactionBuffer = function(builder) { - builder.startObject(10); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} actionType - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addActionType = function(builder, actionType) { - builder.addFieldInt8(7, actionType, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deltaOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addNamespaceId = function(builder, namespaceIdOffset) { - builder.addFieldOffset(8, namespaceIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createNamespaceIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startNamespaceIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(9, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.endMosaicAliasTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.finishMosaicAliasTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicCreationTransactionBuffer.ts b/src/infrastructure/buffers/MosaicCreationTransactionBuffer.ts deleted file mode 100644 index eef8821885..0000000000 --- a/src/infrastructure/buffers/MosaicCreationTransactionBuffer.ts +++ /dev/null @@ -1,582 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicCreationTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicCreationTransactionBuffer} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicCreationTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicCreationTransactionBuffer} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.getRootAsMosaicCreationTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicCreationTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.nonce = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.nonceLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.nonceArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.numOptionalProperties = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.flags = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.divisibility = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.indicateDuration = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.duration = function(index) { - var offset = this.bb.__offset(this.bb_pos, 30); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.durationLength = function() { - var offset = this.bb.__offset(this.bb_pos, 30); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.durationArray = function() { - var offset = this.bb.__offset(this.bb_pos, 30); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startMosaicCreationTransactionBuffer = function(builder) { - builder.startObject(14); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} nonce - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addNonce = function(builder, nonceOffset) { - - builder.addFieldOffset(7, nonceOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createNonceVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startNonceVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(8, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numOptionalProperties - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addNumOptionalProperties = function(builder, numOptionalProperties) { - builder.addFieldInt8(9, numOptionalProperties, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} flags - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addFlags = function(builder, flags) { - builder.addFieldInt8(10, flags, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} divisibility - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addDivisibility = function(builder, divisibility) { - builder.addFieldInt8(11, divisibility, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} indicateDuration - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addIndicateDuration = function(builder, indicateDuration) { - builder.addFieldInt8(12, indicateDuration, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} durationOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addDuration = function(builder, durationOffset) { - builder.addFieldOffset(13, durationOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createDurationVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startDurationVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.endMosaicCreationTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.finishMosaicCreationTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicGlobalRestrictionTransactionBuffer.ts b/src/infrastructure/buffers/MosaicGlobalRestrictionTransactionBuffer.ts deleted file mode 100644 index 794dfd3add..0000000000 --- a/src/infrastructure/buffers/MosaicGlobalRestrictionTransactionBuffer.ts +++ /dev/null @@ -1,657 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.getRootAsMosaicGlobalRestrictionTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.referenceMosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.referenceMosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.referenceMosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.restrictionKey = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.restrictionKeyLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.restrictionKeyArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.previousRestrictionValue = function(index) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.previousRestrictionValueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.previousRestrictionValueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.previousRestrictionType = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.newRestrictionValue = function(index) { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.newRestrictionValueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.newRestrictionValueValueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.newRestrictionValue = function() { - var offset = this.bb.__offset(this.bb_pos, 30); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startMosaicGlobalRestrictionTransactionBuffer = function(builder) { - builder.startObject(14); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} referenceMosaicIdOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addReferenceMosaicId = function(builder, referenceMosaicIdOffset) { - builder.addFieldOffset(8, referenceMosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createReferenceMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startReferenceMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} restrictionKeyOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addRestrictionKey = function(builder, restrictionKeyOffset) { - builder.addFieldOffset(9, restrictionKeyOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createRestrictionKeyVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startRestrictionKeyVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} previousRestrictionValueOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addPreviousRestrictionValue = function(builder, previousRestrictionValueOffset) { - builder.addFieldOffset(10, previousRestrictionValueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createPreviousRestrictionValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startPreviousRestrictionValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} previousRestrictionType - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addPreviousRestrictionType = function(builder, previousRestrictionType) { - builder.addFieldInt16(11, previousRestrictionType, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} newRestrictionValueOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addNewRestrictionValue = function(builder, newRestrictionValueOffset) { - builder.addFieldOffset(12, newRestrictionValueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createNewRestrictionValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startNewRestrictionValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} newRestrictionType - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addNewRestrictionType = function(builder, newRestrictionType) { - builder.addFieldInt16(13, newRestrictionType, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.endMosaicGlobalRestrictionTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.finishMosaicGlobalRestrictionTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicSupplyChangeTransactionBuffer.ts b/src/infrastructure/buffers/MosaicSupplyChangeTransactionBuffer.ts deleted file mode 100644 index 0297f46688..0000000000 --- a/src/infrastructure/buffers/MosaicSupplyChangeTransactionBuffer.ts +++ /dev/null @@ -1,479 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicSupplyChangeTransactionBuffer} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicSupplyChangeTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicSupplyChangeTransactionBuffer} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.getRootAsMosaicSupplyChangeTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicSupplyChangeTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.direction = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.delta = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deltaLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deltaArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startMosaicSupplyChangeTransactionBuffer = function(builder) { - builder.startObject(10); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} direction - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addDirection = function(builder, direction) { - builder.addFieldInt8(8, direction, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deltaOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addDelta = function(builder, deltaOffset) { - builder.addFieldOffset(9, deltaOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createDeltaVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startDeltaVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.endMosaicSupplyChangeTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.finishMosaicSupplyChangeTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MultisigModificationTransactionBuffer.ts b/src/infrastructure/buffers/MultisigModificationTransactionBuffer.ts deleted file mode 100644 index 14376de447..0000000000 --- a/src/infrastructure/buffers/MultisigModificationTransactionBuffer.ts +++ /dev/null @@ -1,571 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.CosignatoryModificationBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.CosignatoryModificationBuffer} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.CosignatoryModificationBuffer=} obj - * @returns {Catapult.Buffers.CosignatoryModificationBuffer} - */ -Catapult.Buffers.CosignatoryModificationBuffer.getRootAsCosignatoryModificationBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.CosignatoryModificationBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.cosignatoryPublicKey = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.cosignatoryPublicKeyLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.cosignatoryPublicKeyArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.CosignatoryModificationBuffer.startCosignatoryModificationBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.CosignatoryModificationBuffer.addType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} cosignatoryPublicKeyOffset - */ -Catapult.Buffers.CosignatoryModificationBuffer.addCosignatoryPublicKey = function(builder, cosignatoryPublicKeyOffset) { - builder.addFieldOffset(1, cosignatoryPublicKeyOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.CosignatoryModificationBuffer.createCosignatoryPublicKeyVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.CosignatoryModificationBuffer.startCosignatoryPublicKeyVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.CosignatoryModificationBuffer.endCosignatoryModificationBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.MultisigModificationTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MultisigModificationTransactionBuffer} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MultisigModificationTransactionBuffer=} obj - * @returns {Catapult.Buffers.MultisigModificationTransactionBuffer} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.getRootAsMultisigModificationTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MultisigModificationTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.minRemovalDelta = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.minApprovalDelta = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.numModifications = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.CosignatoryModificationBuffer=} obj - * @returns {Catapult.Buffers.CosignatoryModificationBuffer} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.modifications = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? (obj || new Catapult.Buffers.CosignatoryModificationBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.modificationsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startMultisigModificationTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} minRemovalDelta - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addMinRemovalDelta = function(builder, minRemovalDelta) { - builder.addFieldInt8(7, minRemovalDelta, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} minApprovalDelta - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addMinApprovalDelta = function(builder, minApprovalDelta) { - builder.addFieldInt8(8, minApprovalDelta, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numModifications - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addNumModifications = function(builder, numModifications) { - builder.addFieldInt8(9, numModifications, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} modificationsOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addModifications = function(builder, modificationsOffset) { - builder.addFieldOffset(10, modificationsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createModificationsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startModificationsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.endMultisigModificationTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.finishMultisigModificationTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/NamespaceCreationTransactionBuffer.ts b/src/infrastructure/buffers/NamespaceCreationTransactionBuffer.ts deleted file mode 100644 index 47e9657a44..0000000000 --- a/src/infrastructure/buffers/NamespaceCreationTransactionBuffer.ts +++ /dev/null @@ -1,512 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.NamespaceCreationTransactionBuffer} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.NamespaceCreationTransactionBuffer=} obj - * @returns {Catapult.Buffers.NamespaceCreationTransactionBuffer} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.getRootAsNamespaceCreationTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.NamespaceCreationTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.durationParentId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.durationParentIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.durationParentIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceNameSize = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Encoding=} optionalEncoding - * @returns {string|Uint8Array|null} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceName = function(optionalEncoding) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startNamespaceCreationTransactionBuffer = function(builder) { - builder.startObject(12); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} namespaceType - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addNamespaceType = function(builder, namespaceType) { - builder.addFieldInt8(7, namespaceType, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} durationParentIdOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addDurationParentId = function(builder, durationParentIdOffset) { - builder.addFieldOffset(8, durationParentIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createDurationParentIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startDurationParentIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} namespaceIdOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addNamespaceId = function(builder, namespaceIdOffset) { - builder.addFieldOffset(9, namespaceIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createNamespaceIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startNamespaceIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} namespaceNameSize - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addNamespaceNameSize = function(builder, namespaceNameSize) { - builder.addFieldInt8(10, namespaceNameSize, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} namespaceNameOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addNamespaceName = function(builder, namespaceNameOffset) { - builder.addFieldOffset(11, namespaceNameOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.endNamespaceCreationTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.finishNamespaceCreationTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/SecretLockTransactionBuffer.ts b/src/infrastructure/buffers/SecretLockTransactionBuffer.ts deleted file mode 100644 index 4036cdd4c2..0000000000 --- a/src/infrastructure/buffers/SecretLockTransactionBuffer.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.SecretLockTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.SecretLockTransactionBuffer} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.SecretLockTransactionBuffer=} obj - * @returns {Catapult.Buffers.SecretLockTransactionBuffer} - */ -Catapult.Buffers.SecretLockTransactionBuffer.getRootAsSecretLockTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.SecretLockTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicAmount = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicAmountLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicAmountArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.duration = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.durationLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.durationArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.hashAlgorithm = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.secret = function(index) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.secretLength = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.secretArray = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.recipient = function(index) { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.recipientLength = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.recipientArray = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.SecretLockTransactionBuffer.startSecretLockTransactionBuffer = function(builder) { - builder.startObject(13); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.SecretLockTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.SecretLockTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.SecretLockTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicAmountOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addMosaicAmount = function(builder, mosaicAmountOffset) { - builder.addFieldOffset(8, mosaicAmountOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createMosaicAmountVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startMosaicAmountVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} durationOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addDuration = function(builder, durationOffset) { - builder.addFieldOffset(9, durationOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createDurationVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startDurationVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} hashAlgorithm - */ -Catapult.Buffers.SecretLockTransactionBuffer.addHashAlgorithm = function(builder, hashAlgorithm) { - builder.addFieldInt8(10, hashAlgorithm, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} secretOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addSecret = function(builder, secretOffset) { - builder.addFieldOffset(11, secretOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createSecretVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startSecretVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} recipientOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addRecipient = function(builder, recipientOffset) { - builder.addFieldOffset(12, recipientOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createRecipientVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startRecipientVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.endSecretLockTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.SecretLockTransactionBuffer.finishSecretLockTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/SecretProofTransactionBuffer.ts b/src/infrastructure/buffers/SecretProofTransactionBuffer.ts deleted file mode 100644 index 570f57a886..0000000000 --- a/src/infrastructure/buffers/SecretProofTransactionBuffer.ts +++ /dev/null @@ -1,549 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.SecretProofTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.SecretProofTransactionBuffer} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.SecretProofTransactionBuffer=} obj - * @returns {Catapult.Buffers.SecretProofTransactionBuffer} - */ -Catapult.Buffers.SecretProofTransactionBuffer.getRootAsSecretProofTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.SecretProofTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.hashAlgorithm = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.secret = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.secretLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.secretArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.recipient = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.recipientLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.recipientArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.proofSize = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.proof = function(index) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.proofLength = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.proofArray = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.SecretProofTransactionBuffer.startSecretProofTransactionBuffer = function(builder) { - builder.startObject(12); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.SecretProofTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.SecretProofTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.SecretProofTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} hashAlgorithm - */ -Catapult.Buffers.SecretProofTransactionBuffer.addHashAlgorithm = function(builder, hashAlgorithm) { - builder.addFieldInt8(7, hashAlgorithm, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} secretOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addSecret = function(builder, secretOffset) { - builder.addFieldOffset(8, secretOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createSecretVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startSecretVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} recipientOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addRecipient = function(builder, recipientOffset) { - builder.addFieldOffset(9, recipientOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createRecipientVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startRecipientVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} proofSize - */ -Catapult.Buffers.SecretProofTransactionBuffer.addProofSize = function(builder, proofSize) { - builder.addFieldInt16(10, proofSize, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} proofOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addProof = function(builder, proofOffset) { - builder.addFieldOffset(11, proofOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createProofVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startProofVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.endSecretProofTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.SecretProofTransactionBuffer.finishSecretProofTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/TransferTransactionBuffer.ts b/src/infrastructure/buffers/TransferTransactionBuffer.ts deleted file mode 100644 index 05be19edfb..0000000000 --- a/src/infrastructure/buffers/TransferTransactionBuffer.ts +++ /dev/null @@ -1,785 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MessageBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MessageBuffer} - */ -Catapult.Buffers.MessageBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MessageBuffer=} obj - * @returns {Catapult.Buffers.MessageBuffer} - */ -Catapult.Buffers.MessageBuffer.getRootAsMessageBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MessageBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MessageBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MessageBuffer.prototype.payload = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MessageBuffer.prototype.payloadLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MessageBuffer.prototype.payloadArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MessageBuffer.startMessageBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MessageBuffer.addType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} payloadOffset - */ -Catapult.Buffers.MessageBuffer.addPayload = function(builder, payloadOffset) { - builder.addFieldOffset(1, payloadOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MessageBuffer.createPayloadVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MessageBuffer.startPayloadVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MessageBuffer.endMessageBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicBuffer} - */ -Catapult.Buffers.MosaicBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicBuffer=} obj - * @returns {Catapult.Buffers.MosaicBuffer} - */ -Catapult.Buffers.MosaicBuffer.getRootAsMosaicBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicBuffer.prototype.id = function(index) { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicBuffer.prototype.idLength = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicBuffer.prototype.idArray = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicBuffer.prototype.amount = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicBuffer.prototype.amountLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicBuffer.prototype.amountArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicBuffer.startMosaicBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} idOffset - */ -Catapult.Buffers.MosaicBuffer.addId = function(builder, idOffset) { - builder.addFieldOffset(0, idOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicBuffer.createIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicBuffer.startIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} amountOffset - */ -Catapult.Buffers.MosaicBuffer.addAmount = function(builder, amountOffset) { - builder.addFieldOffset(1, amountOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicBuffer.createAmountVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicBuffer.startAmountVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicBuffer.endMosaicBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.TransferTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.TransferTransactionBuffer} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.TransferTransactionBuffer=} obj - * @returns {Catapult.Buffers.TransferTransactionBuffer} - */ -Catapult.Buffers.TransferTransactionBuffer.getRootAsTransferTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.TransferTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.recipient = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.recipientLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.recipientArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.messageSize = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.numMosaics = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {Catapult.Buffers.MessageBuffer=} obj - * @returns {Catapult.Buffers.MessageBuffer|null} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.message = function(obj) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? (obj || new Catapult.Buffers.MessageBuffer).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.MosaicBuffer=} obj - * @returns {Catapult.Buffers.MosaicBuffer} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.mosaics = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? (obj || new Catapult.Buffers.MosaicBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.mosaicsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.TransferTransactionBuffer.startTransferTransactionBuffer = function(builder) { - builder.startObject(12); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.TransferTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.TransferTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.TransferTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} recipientOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addRecipient = function(builder, recipientOffset) { - builder.addFieldOffset(7, recipientOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createRecipientVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startRecipientVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} messageSize - */ -Catapult.Buffers.TransferTransactionBuffer.addMessageSize = function(builder, messageSize) { - builder.addFieldInt16(8, messageSize, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numMosaics - */ -Catapult.Buffers.TransferTransactionBuffer.addNumMosaics = function(builder, numMosaics) { - builder.addFieldInt8(9, numMosaics, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} messageOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addMessage = function(builder, messageOffset) { - builder.addFieldOffset(10, messageOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicsOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addMosaics = function(builder, mosaicsOffset) { - builder.addFieldOffset(11, mosaicsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createMosaicsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startMosaicsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.endTransferTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.TransferTransactionBuffer.finishTransferTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/builders/AccountLinkTransaction.ts b/src/infrastructure/builders/AccountLinkTransaction.ts deleted file mode 100644 index 15cdb7738c..0000000000 --- a/src/infrastructure/builders/AccountLinkTransaction.ts +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AccountLinkTransaction - */ -import { Convert as convert } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import AccountLinkTransactionBufferPackage from '../buffers/AccountLinkTransactionBuffer'; -import AccountLinkTransactionSchema from '../schemas/AccountLinkTransactionSchema'; -import {VerifiableTransaction} from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - AccountLinkTransactionBuffer, -} = AccountLinkTransactionBufferPackage.Buffers; - -export class AccountLinkTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AccountLinkTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - remoteAccountKey: any; - linkAction: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.LINK_ACCOUNT; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRemoteAccountKey(remoteAccountKey) { - this.remoteAccountKey = convert.hexToUint8(remoteAccountKey); - return this; - } - - addLinkAction(linkAction) { - this.linkAction = linkAction; - return this; - } - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = AccountLinkTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = AccountLinkTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = AccountLinkTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = AccountLinkTransactionBuffer.createFeeVector(builder, this.maxFee); - const remoteAccountKeyVector = AccountLinkTransactionBuffer.createRemoteAccountKeyVector(builder, this.remoteAccountKey); - - AccountLinkTransactionBuffer.startAccountLinkTransactionBuffer(builder); - AccountLinkTransactionBuffer.addSize(builder, 153); - AccountLinkTransactionBuffer.addSignature(builder, signatureVector); - AccountLinkTransactionBuffer.addSigner(builder, signerVector); - AccountLinkTransactionBuffer.addVersion(builder, this.version); - AccountLinkTransactionBuffer.addType(builder, this.type); - AccountLinkTransactionBuffer.addFee(builder, feeVector); - AccountLinkTransactionBuffer.addDeadline(builder, deadlineVector); - AccountLinkTransactionBuffer.addRemoteAccountKey(builder, remoteAccountKeyVector); - AccountLinkTransactionBuffer.addLinkAction(builder, this.linkAction); - - // Calculate size - - const codedTransfer = AccountLinkTransactionBuffer.endAccountLinkTransactionBuffer(builder); - builder.finish(codedTransfer); - - const bytes = builder.asUint8Array(); - return new AccountLinkTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts b/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts deleted file mode 100644 index bd355c6b94..0000000000 --- a/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AccountRestrictionsAddressTransaction - */ -import { RawAddress as address } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import AccountRestrictionsAddressTransactionBufferPackage from '../buffers/AccountRestrictionsAddressTransactionBuffer'; -import AccountRestrictionsAddressModificationTransactionSchema from '../schemas/AccountRestrictionsAddressModificationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; -const { - AccountRestrictionsAddressTransactionBuffer, - RestrictionAddressModificationBuffer, -} = AccountRestrictionsAddressTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -export default class AccountRestrictionsAddressTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AccountRestrictionsAddressModificationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - restrictionType: any; - modifications: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.ACCOUNT_RESTRICTION_ADDRESS; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionType(restrictionType) { - this.restrictionType = restrictionType; - return this; - } - - addModifications(modifications) { - this.modifications = modifications; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create modifications - const modificationsArray: any = []; - this.modifications.forEach((modification) => { - const addressModificationVector = RestrictionAddressModificationBuffer - .createValueVector(builder, address.stringToAddress(modification.value)); - RestrictionAddressModificationBuffer.startRestrictionAddressModificationBuffer(builder); - RestrictionAddressModificationBuffer.addModificationType(builder, modification.type); - RestrictionAddressModificationBuffer.addValue(builder, addressModificationVector); - modificationsArray.push(RestrictionAddressModificationBuffer.endRestrictionAddressModificationBuffer(builder)); - }); - - // Create vectors - const signatureVector = AccountRestrictionsAddressTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = AccountRestrictionsAddressTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = AccountRestrictionsAddressTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = AccountRestrictionsAddressTransactionBuffer - .createFeeVector(builder, this.maxFee); - const modificationVector = AccountRestrictionsAddressTransactionBuffer - .createModificationsVector(builder, modificationsArray); - - AccountRestrictionsAddressTransactionBuffer.startAccountRestrictionsAddressTransactionBuffer(builder); - AccountRestrictionsAddressTransactionBuffer.addSize(builder, 122 + (26 * this.modifications.length)); - AccountRestrictionsAddressTransactionBuffer.addSignature(builder, signatureVector); - AccountRestrictionsAddressTransactionBuffer.addSigner(builder, signerVector); - AccountRestrictionsAddressTransactionBuffer.addVersion(builder, this.version); - AccountRestrictionsAddressTransactionBuffer.addType(builder, this.type); - AccountRestrictionsAddressTransactionBuffer.addFee(builder, feeVector); - AccountRestrictionsAddressTransactionBuffer.addDeadline(builder, deadlineVector); - AccountRestrictionsAddressTransactionBuffer.addRestrictionType(builder, this.restrictionType); - AccountRestrictionsAddressTransactionBuffer.addModificationCount(builder, this.modifications.length); - AccountRestrictionsAddressTransactionBuffer.addModifications(builder, modificationVector); - - // Calculate size - const codedAccountRestrictionsAddress = - AccountRestrictionsAddressTransactionBuffer.endAccountRestrictionsAddressTransactionBuffer(builder); - builder.finish(codedAccountRestrictionsAddress); - - const bytes = builder.asUint8Array(); - - return new AccountRestrictionsAddressTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts b/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts deleted file mode 100644 index 6973e8ccc4..0000000000 --- a/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AccountRestrictionsEntityTypeTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import AccountRestrictionsEntityTypeTransactionBufferPackage from '../buffers/AccountRestrictionsEntityTypeTransactionBuffer'; -import AccountRestrictionsEntityTypeModificationTransactionSchema from '../schemas/AccountRestrictionsEntityTypeModificationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - AccountRestrictionsEntityTypeTransactionBuffer, - RestrictionEntityTypeModificationBuffer, -} = AccountRestrictionsEntityTypeTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -export default class AccountRestrictionsEntityTypeTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AccountRestrictionsEntityTypeModificationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - restrictionType: any; - modifications: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.ACCOUNT_RESTRICTION_OPERATION; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionType(restrictionType) { - this.restrictionType = restrictionType; - return this; - } - - addModifications(modifications) { - this.modifications = modifications; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create modifications - const modificationsArray: any = []; - this.modifications.forEach((modification) => { - RestrictionEntityTypeModificationBuffer.startRestrictionEntityTypeModificationBuffer(builder); - RestrictionEntityTypeModificationBuffer.addModificationType(builder, modification.type); - RestrictionEntityTypeModificationBuffer.addValue(builder, modification.value); - modificationsArray.push(RestrictionEntityTypeModificationBuffer.endRestrictionEntityTypeModificationBuffer(builder)); - }); - - // Create vectors - const signatureVector = AccountRestrictionsEntityTypeTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = AccountRestrictionsEntityTypeTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = AccountRestrictionsEntityTypeTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = AccountRestrictionsEntityTypeTransactionBuffer - .createFeeVector(builder, this.maxFee); - const modificationVector = AccountRestrictionsEntityTypeTransactionBuffer - .createModificationsVector(builder, modificationsArray); - - AccountRestrictionsEntityTypeTransactionBuffer.startAccountRestrictionsEntityTypeTransactionBuffer(builder); - AccountRestrictionsEntityTypeTransactionBuffer.addSize(builder, 122 + (3 * this.modifications.length)); - AccountRestrictionsEntityTypeTransactionBuffer.addSignature(builder, signatureVector); - AccountRestrictionsEntityTypeTransactionBuffer.addSigner(builder, signerVector); - AccountRestrictionsEntityTypeTransactionBuffer.addVersion(builder, this.version); - AccountRestrictionsEntityTypeTransactionBuffer.addType(builder, this.type); - AccountRestrictionsEntityTypeTransactionBuffer.addFee(builder, feeVector); - AccountRestrictionsEntityTypeTransactionBuffer.addDeadline(builder, deadlineVector); - AccountRestrictionsEntityTypeTransactionBuffer.addRestrictionType(builder, this.restrictionType); - AccountRestrictionsEntityTypeTransactionBuffer.addModificationCount(builder, this.modifications.length); - AccountRestrictionsEntityTypeTransactionBuffer.addModifications(builder, modificationVector); - - // Calculate size - const codedAccountRestrictionsAddress = AccountRestrictionsEntityTypeTransactionBuffer - .endAccountRestrictionsEntityTypeTransactionBuffer(builder); - builder.finish(codedAccountRestrictionsAddress); - - const bytes = builder.asUint8Array(); - - return new AccountRestrictionsEntityTypeTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts b/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts deleted file mode 100644 index da9338deb4..0000000000 --- a/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AccountRestrictionsMosaicTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import AccountRestrictionsMosaicTransactionBufferPackage from '../buffers/AccountRestrictionsMosaicTransactionBuffer'; -import AccountRestrictionsMosaicModificationTransactionSchema from '../schemas/AccountRestrictionsMosaicModificationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - AccountRestrictionsMosaicTransactionBuffer, - RestrictionMosaicModificationBuffer, -} = AccountRestrictionsMosaicTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -export default class AccountRestrictionsMosaicTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AccountRestrictionsMosaicModificationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - restrictionType: any; - modifications: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.ACCOUNT_RESTRICTION_MOSAIC; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionType(restrictionType) { - this.restrictionType = restrictionType; - return this; - } - - addModifications(modifications) { - this.modifications = modifications; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create modifications - const modificationsArray: any = []; - this.modifications.forEach((modification) => { - const addressModificationVector = RestrictionMosaicModificationBuffer - .createValueVector(builder, modification.value); - RestrictionMosaicModificationBuffer.startRestrictionMosaicModificationBuffer(builder); - RestrictionMosaicModificationBuffer.addModificationType(builder, modification.type); - RestrictionMosaicModificationBuffer.addValue(builder, addressModificationVector); - modificationsArray.push(RestrictionMosaicModificationBuffer.endRestrictionMosaicModificationBuffer(builder)); - }); - - // Create vectors - const signatureVector = AccountRestrictionsMosaicTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = AccountRestrictionsMosaicTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = AccountRestrictionsMosaicTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = AccountRestrictionsMosaicTransactionBuffer - .createFeeVector(builder, this.maxFee); - const modificationVector = AccountRestrictionsMosaicTransactionBuffer - .createModificationsVector(builder, modificationsArray); - - AccountRestrictionsMosaicTransactionBuffer.startAccountRestrictionsMosaicTransactionBuffer(builder); - AccountRestrictionsMosaicTransactionBuffer.addSize(builder, 122 + (9 * this.modifications.length)); - AccountRestrictionsMosaicTransactionBuffer.addSignature(builder, signatureVector); - AccountRestrictionsMosaicTransactionBuffer.addSigner(builder, signerVector); - AccountRestrictionsMosaicTransactionBuffer.addVersion(builder, this.version); - AccountRestrictionsMosaicTransactionBuffer.addType(builder, this.type); - AccountRestrictionsMosaicTransactionBuffer.addFee(builder, feeVector); - AccountRestrictionsMosaicTransactionBuffer.addDeadline(builder, deadlineVector); - AccountRestrictionsMosaicTransactionBuffer.addRestrictionType(builder, this.restrictionType); - AccountRestrictionsMosaicTransactionBuffer.addModificationCount(builder, this.modifications.length); - AccountRestrictionsMosaicTransactionBuffer.addModifications(builder, modificationVector); - - // Calculate size - const codedAccountRestrictionsMosaic = AccountRestrictionsMosaicTransactionBuffer.endAccountRestrictionsMosaicTransactionBuffer(builder); - builder.finish(codedAccountRestrictionsMosaic); - - const bytes = builder.asUint8Array(); - - return new AccountRestrictionsMosaicTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/AddressAliasTransaction.ts b/src/infrastructure/builders/AddressAliasTransaction.ts deleted file mode 100644 index fa5aefba1c..0000000000 --- a/src/infrastructure/builders/AddressAliasTransaction.ts +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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 { RawAddress as addressLibrary } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import AddressAliasTransactionBufferPackage from '../buffers/AddressAliasTransactionBuffer'; -import AddressAliasTransactionSchema from '../schemas/AddressAliasTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - AddressAliasTransactionBuffer, -} = AddressAliasTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -/** - * @module transactions/AddressAliasTransaction - */ -export class AddressAliasTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AddressAliasTransactionSchema); - } -} -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - address: any; - namespaceId: any; - actionType: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.ADDRESS_ALIAS; - } - - addFee(maxFee) { - this.maxFee = maxFee; - 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 = addressLibrary.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.maxFee); - 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); - } -} diff --git a/src/infrastructure/builders/AggregateTransaction.ts b/src/infrastructure/builders/AggregateTransaction.ts deleted file mode 100644 index 8aae5a5e28..0000000000 --- a/src/infrastructure/builders/AggregateTransaction.ts +++ /dev/null @@ -1,151 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AggregateTransaction - */ -import { SignSchema } from '../../core/crypto'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import AggregateTransactionBufferPackage from '../buffers/AggregateTransactionBuffer'; -import AggregateTransactionSchema from '../schemas/AggregateTransactionSchema'; -import { CosignatureTransaction} from './CosignatureTransaction'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - AggregateTransactionBuffer, -} = AggregateTransactionBufferPackage.Buffers; - -export class AggregateTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AggregateTransactionSchema); - } - - signTransactionWithCosigners(initializer, cosigners, generationHash, signSchema: SignSchema = SignSchema.SHA3) { - const signedTransaction = this.signTransaction(initializer, generationHash, signSchema); - cosigners.forEach((cosigner) => { - const signatureTransaction = new CosignatureTransaction(signedTransaction.hash); - const signatureCosignTransaction = signatureTransaction.signCosignatoriesTransaction(cosigner, signSchema); - signedTransaction.payload = signedTransaction.payload + - signatureCosignTransaction.signer + signatureCosignTransaction.signature; - }); - - // Calculate new size - const size = `00000000${(signedTransaction.payload.length / 2).toString(16)}`; - const formatedSize = size.substr(size.length - 8, size.length); - const littleEndianSize = formatedSize.substr(6, 2) + formatedSize.substr(4, 2) + - formatedSize.substr(2, 2) + formatedSize.substr(0, 2); - - signedTransaction.payload = littleEndianSize + - signedTransaction.payload.substr(8, signedTransaction.payload.length - 8); - - return signedTransaction; - } - - signTransactionGivenSignatures(initializer, cosignedSignedTransactions, generationHash, signSchema = SignSchema.SHA3) { - const signedTransaction = this.signTransaction(initializer, generationHash, signSchema); - cosignedSignedTransactions.forEach((cosignedTransaction) => { - signedTransaction.payload = signedTransaction.payload + cosignedTransaction.signer + cosignedTransaction.signature; - }); - - // Calculate new size - const size = `00000000${(signedTransaction.payload.length / 2).toString(16)}`; - const formatedSize = size.substr(size.length - 8, size.length); - const littleEndianSize = formatedSize.substr(6, 2) + formatedSize.substr(4, 2) + - formatedSize.substr(2, 2) + formatedSize.substr(0, 2); - - signedTransaction.payload = littleEndianSize + - signedTransaction.payload.substr(8, signedTransaction.payload.length - 8); - - return signedTransaction; - } -} -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - transactions: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.AGGREGATE_COMPLETE; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addTransactions(transactions) { - let tmp = []; - for (let i = 0; i < transactions.length; ++i) { - tmp = tmp.concat(transactions[i]); - } - - this.transactions = tmp; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = AggregateTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)) - .map(Number.prototype.valueOf, 0)); - const signerVector = AggregateTransactionBuffer - .createSignerVector(builder, Array(...Array(32)) - .map(Number.prototype.valueOf, 0)); - const deadlineVector = AggregateTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = AggregateTransactionBuffer.createFeeVector(builder, this.maxFee); - const modificationsVector = AggregateTransactionBuffer.createTransactionsVector(builder, this.transactions); - - AggregateTransactionBuffer.startAggregateTransactionBuffer(builder); - AggregateTransactionBuffer.addSize(builder, 120 + 4 + this.transactions.length); - AggregateTransactionBuffer.addSignature(builder, signatureVector); - AggregateTransactionBuffer.addSigner(builder, signerVector); - AggregateTransactionBuffer.addVersion(builder, this.version); - AggregateTransactionBuffer.addType(builder, this.type); - AggregateTransactionBuffer.addFee(builder, feeVector); - AggregateTransactionBuffer.addDeadline(builder, deadlineVector); - AggregateTransactionBuffer.addTransactionsSize(builder, 0 !== this.transactions.length ? this.transactions.length : 4294967296); - AggregateTransactionBuffer.addTransactions(builder, modificationsVector); - - // Calculate size - const codedAggregate = AggregateTransactionBuffer.endAggregateTransactionBuffer(builder); - builder.finish(codedAggregate); - - const bytes = builder.asUint8Array(); - return new AggregateTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/CosignatureTransaction.ts b/src/infrastructure/builders/CosignatureTransaction.ts deleted file mode 100644 index 717041f910..0000000000 --- a/src/infrastructure/builders/CosignatureTransaction.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 { Convert as convert } from '../../core/format/Convert'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -/** - * @module transactions/AggregateSignatureTransaction - * @version 1.0.0 - */ -export class CosignatureTransaction extends VerifiableTransaction { - constructor(hash) { - super(convert.hexToUint8(hash), undefined); - } -} diff --git a/src/infrastructure/builders/Deadline.ts b/src/infrastructure/builders/Deadline.ts deleted file mode 100644 index 3b37923c5a..0000000000 --- a/src/infrastructure/builders/Deadline.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 { RawUInt64 as uint64 } from '../../core/format'; - -export default function deadline(deadlineParam) { - const NetworkTime = (new Date()).getTime() - 1459468800000; - const deadlineValue = deadlineParam || 60 * 60 * 1000; - return uint64.fromUint(deadlineValue + NetworkTime); -} \ No newline at end of file diff --git a/src/infrastructure/builders/HashLockTransaction.ts b/src/infrastructure/builders/HashLockTransaction.ts deleted file mode 100644 index 538454d3ea..0000000000 --- a/src/infrastructure/builders/HashLockTransaction.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/HashLockTransaction - */ -import { Convert as convert } from '../../core/format'; -import * as HashLockTransactionBufferPackage from '../buffers/HashLockTransactionBuffer'; -import HashLockTransactionSchema from '../schemas/HashLockTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; -import { TransactionType } from '../../model/transaction/TransactionType'; - -import {flatbuffers} from 'flatbuffers'; - -const { - HashLockTransactionBuffer, -} = HashLockTransactionBufferPackage.default.Buffers; - -export default class HashLockTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, HashLockTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - mosaicAmount: any; - duration: any; - hash: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.LOCK; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - addMosaicAmount(mosaicAmount) { - this.mosaicAmount = mosaicAmount; - return this; - } - - addDuration(duration) { - this.duration = duration; - return this; - } - - addHash(hash) { - this.hash = hash; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = HashLockTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = HashLockTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = HashLockTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = HashLockTransactionBuffer.createFeeVector(builder, this.maxFee); - const mosaicIdVector = HashLockTransactionBuffer.createMosaicIdVector(builder, this.mosaicId); - const mosaicAmountVector = HashLockTransactionBuffer.createMosaicAmountVector(builder, this.mosaicAmount); - const durationVector = HashLockTransactionBuffer.createDurationVector(builder, this.duration); - const byteHash = convert.hexToUint8(this.hash); - const hashVector = HashLockTransactionBuffer.createHashVector(builder, byteHash); - - HashLockTransactionBuffer.startHashLockTransactionBuffer(builder); - HashLockTransactionBuffer.addSize(builder, 176); - HashLockTransactionBuffer.addSignature(builder, signatureVector); - HashLockTransactionBuffer.addSigner(builder, signerVector); - HashLockTransactionBuffer.addVersion(builder, this.version); - HashLockTransactionBuffer.addType(builder, this.type); - HashLockTransactionBuffer.addFee(builder, feeVector); - HashLockTransactionBuffer.addDeadline(builder, deadlineVector); - HashLockTransactionBuffer.addMosaicId(builder, mosaicIdVector); - HashLockTransactionBuffer.addMosaicAmount(builder, mosaicAmountVector); - HashLockTransactionBuffer.addDuration(builder, durationVector); - HashLockTransactionBuffer.addHash(builder, hashVector); - - const codedHashLock = HashLockTransactionBuffer.endHashLockTransactionBuffer(builder); - builder.finish(codedHashLock); - - const bytes = builder.asUint8Array(); - return new HashLockTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/MosaicAddressRestrictionTransaction.ts b/src/infrastructure/builders/MosaicAddressRestrictionTransaction.ts deleted file mode 100644 index 0b214c496b..0000000000 --- a/src/infrastructure/builders/MosaicAddressRestrictionTransaction.ts +++ /dev/null @@ -1,146 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/MosaicAddressRestrictionTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicAddressRestrictionTransactionBufferPackage from '../buffers/MosaicAddressRestrictionTransactionBuffer'; -import MosaicAddressRestrictionTransactionSchema from '../schemas/MosaicAddressRestrictionTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; -import { RawAddress } from '../../core/format'; - -const { - MosaicAddressRestrictionTransactionBuffer, -} = MosaicAddressRestrictionTransactionBufferPackage.Buffers; - -export default class MosaicAddressRestrictionTransaction extends VerifiableTransaction { - constructor(bytes, schema) { - super(bytes, schema); - } -} -// tslint:disable-next-line: max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - restrictionKey: any; - targetAddress: any; - previousRestrictionValue: any; - newRestrictionValue: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_ADDRESS_RESTRICTION; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionKey(restrictionKey) { - this.restrictionKey = restrictionKey; - return this; - } - - addTargetAddress(targetAddress) { - this.targetAddress = RawAddress.stringToAddress(targetAddress); - return this; - } - - addPreviousRestrictionValue(previousRestrictionValue) { - this.previousRestrictionValue = previousRestrictionValue; - return this; - } - - addNewRestrictionValue(newRestrictionValue) { - this.newRestrictionValue = newRestrictionValue; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicAddressRestrictionTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicAddressRestrictionTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicAddressRestrictionTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicAddressRestrictionTransactionBuffer - .createFeeVector(builder, this.maxFee); - const mosaicIdVector = MosaicAddressRestrictionTransactionBuffer - .createMosaicIdVector(builder, this.mosaicId); - const restrictionKeyVector = MosaicAddressRestrictionTransactionBuffer - .createRestrictionKeyVector(builder, this.restrictionKey); - const targetAddressVector = MosaicAddressRestrictionTransactionBuffer - .createTargetAddressVector(builder, this.targetAddress); - const previousRestrictionValueVector = MosaicAddressRestrictionTransactionBuffer - .createPreviousRestrictionValueVector(builder, this.previousRestrictionValue); - const newRestrictionValueVector = MosaicAddressRestrictionTransactionBuffer - .createNewRestrictionValueVector(builder, this.newRestrictionValue); - - MosaicAddressRestrictionTransactionBuffer.startMosaicAddressRestrictionTransactionBuffer(builder); - MosaicAddressRestrictionTransactionBuffer.addSize(builder, 169); - MosaicAddressRestrictionTransactionBuffer.addSignature(builder, signatureVector); - MosaicAddressRestrictionTransactionBuffer.addSigner(builder, signerVector); - MosaicAddressRestrictionTransactionBuffer.addVersion(builder, this.version); - MosaicAddressRestrictionTransactionBuffer.addType(builder, this.type); - MosaicAddressRestrictionTransactionBuffer.addFee(builder, feeVector); - MosaicAddressRestrictionTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicAddressRestrictionTransactionBuffer.addMosaicId(builder, mosaicIdVector); - MosaicAddressRestrictionTransactionBuffer.addRestrictionKey(builder, restrictionKeyVector); - MosaicAddressRestrictionTransactionBuffer.addTargetAddress(builder, targetAddressVector); - MosaicAddressRestrictionTransactionBuffer.addPreviousRestrictionValue(builder, previousRestrictionValueVector); - MosaicAddressRestrictionTransactionBuffer.addNewRestrictionValue(builder, newRestrictionValueVector); - - // Calculate size - - const codedMosaicAddressRestriction = - MosaicAddressRestrictionTransactionBuffer.endMosaicAddressRestrictionTransactionBuffer(builder); - builder.finish(codedMosaicAddressRestriction); - - const bytes = builder.asUint8Array(); - - const schema = MosaicAddressRestrictionTransactionSchema; - return new MosaicAddressRestrictionTransaction(bytes, schema); - } -} diff --git a/src/infrastructure/builders/MosaicAliasTransaction.ts b/src/infrastructure/builders/MosaicAliasTransaction.ts deleted file mode 100644 index 8d96078f09..0000000000 --- a/src/infrastructure/builders/MosaicAliasTransaction.ts +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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 { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicAliasTransactionBufferPackage from '../buffers/MosaicAliasTransactionBuffer'; -import MosaicAliasTransactionSchema from '../schemas/MosaicAliasTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - MosaicAliasTransactionBuffer, -} = MosaicAliasTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -/** - * @module transactions/MosaicAliasTransaction - */ -export default class MosaicAliasTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, MosaicAliasTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - actionType: any; - namespaceId: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_ALIAS; - } - - addFee(maxFee) { - this.maxFee = maxFee; - 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; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicAliasTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicAliasTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicAliasTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicAliasTransactionBuffer - .createFeeVector(builder, this.maxFee); - const namespaceIdVector = MosaicAliasTransactionBuffer - .createNamespaceIdVector(builder, this.namespaceId); - const mosaicIdVector = MosaicAliasTransactionBuffer - .createMosaicIdVector(builder, this.mosaicId); - - MosaicAliasTransactionBuffer.startMosaicAliasTransactionBuffer(builder); - MosaicAliasTransactionBuffer.addSize(builder, 137); - MosaicAliasTransactionBuffer.addSignature(builder, signatureVector); - MosaicAliasTransactionBuffer.addSigner(builder, signerVector); - MosaicAliasTransactionBuffer.addVersion(builder, this.version); - MosaicAliasTransactionBuffer.addType(builder, this.type); - MosaicAliasTransactionBuffer.addFee(builder, feeVector); - MosaicAliasTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicAliasTransactionBuffer.addActionType(builder, this.actionType); - MosaicAliasTransactionBuffer.addNamespaceId(builder, namespaceIdVector); - MosaicAliasTransactionBuffer.addMosaicId(builder, mosaicIdVector); - - // Calculate size - const codedMosaicChangeSupply = MosaicAliasTransactionBuffer.endMosaicAliasTransactionBuffer(builder); - builder.finish(codedMosaicChangeSupply); - - const bytes = builder.asUint8Array(); - - return new MosaicAliasTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/MosaicCreationTransaction.ts b/src/infrastructure/builders/MosaicCreationTransaction.ts deleted file mode 100644 index d74ba21660..0000000000 --- a/src/infrastructure/builders/MosaicCreationTransaction.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/MosaicCreationTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicCreationTransactionBufferPackage from '../buffers/MosaicCreationTransactionBuffer'; -import { - schema as MosaicCreationTransactionSchema, - schemaNoDuration as MosaicCreationTransactionSchemaNoDuration, -} from '../schemas/MosaicCreationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - MosaicCreationTransactionBuffer, -} = MosaicCreationTransactionBufferPackage.Buffers; - -export default class MosaicCreationTransaction extends VerifiableTransaction { - constructor(bytes, schema) { - super(bytes, schema); - } -} -// tslint:disable-next-line: max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - flags: any; - nonce: any; - divisibility: any; - duration: any; - constructor() { - this.flags = 0; - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_DEFINITION; - this.nonce = 0; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addNonce(nonce) { - this.nonce = nonce; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addDuration(duration) { - this.duration = duration; - return this; - } - - addDivisibility(divisibility) { - this.divisibility = divisibility; - return this; - } - - addSupplyMutable() { - this.flags += 1; - return this; - } - - addTransferability() { - this.flags += 2; - return this; - } - - addRestrictable() { - this.flags += 4; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicCreationTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicCreationTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicCreationTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicCreationTransactionBuffer - .createFeeVector(builder, this.maxFee); - const nonceVector = MosaicCreationTransactionBuffer - .createNonceVector(builder, this.nonce); - const mosaicIdVector = MosaicCreationTransactionBuffer - .createMosaicIdVector(builder, this.mosaicId); - - const durationVector = MosaicCreationTransactionBuffer - .createDurationVector(builder, this.duration); - - const durationProvided = 0 < this.duration.length; - - MosaicCreationTransactionBuffer.startMosaicCreationTransactionBuffer(builder); - MosaicCreationTransactionBuffer.addSize(builder, durationProvided ? 144 : 135); - MosaicCreationTransactionBuffer.addSignature(builder, signatureVector); - MosaicCreationTransactionBuffer.addSigner(builder, signerVector); - MosaicCreationTransactionBuffer.addVersion(builder, this.version); - MosaicCreationTransactionBuffer.addType(builder, this.type); - MosaicCreationTransactionBuffer.addFee(builder, feeVector); - MosaicCreationTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicCreationTransactionBuffer.addNonce(builder, nonceVector); - MosaicCreationTransactionBuffer.addMosaicId(builder, mosaicIdVector); - MosaicCreationTransactionBuffer.addNumOptionalProperties(builder, durationProvided ? 1 : 0); - MosaicCreationTransactionBuffer.addFlags(builder, this.flags); - - MosaicCreationTransactionBuffer.addDivisibility(builder, this.divisibility); - - if (durationProvided) { - MosaicCreationTransactionBuffer.addIndicateDuration(builder, 2); - MosaicCreationTransactionBuffer.addDuration(builder, durationVector); - } - - // Calculate size - - const codedMosaicCreation = MosaicCreationTransactionBuffer.endMosaicCreationTransactionBuffer(builder); - builder.finish(codedMosaicCreation); - - const bytes = builder.asUint8Array(); - - const schema = durationProvided ? MosaicCreationTransactionSchema : MosaicCreationTransactionSchemaNoDuration; - return new MosaicCreationTransaction(bytes, schema); - } -} diff --git a/src/infrastructure/builders/MosaicGlobalRestrictionTransaction.ts b/src/infrastructure/builders/MosaicGlobalRestrictionTransaction.ts deleted file mode 100644 index 608cc0f2c0..0000000000 --- a/src/infrastructure/builders/MosaicGlobalRestrictionTransaction.ts +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/MosaicGlobalRestrictionTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicGlobalRestrictionTransactionBufferPackage from '../buffers/MosaicGlobalRestrictionTransactionBuffer'; -import MosaicGlobalRestrictionTransactionSchema from '../schemas/MosaicGlobalRestrictionTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - MosaicGlobalRestrictionTransactionBuffer, -} = MosaicGlobalRestrictionTransactionBufferPackage.Buffers; - -export default class MosaicGlobalRestrictionTransaction extends VerifiableTransaction { - constructor(bytes, schema) { - super(bytes, schema); - } -} -// tslint:disable-next-line: max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - referenceMosaicId: any; - restrictionKey: any; - previousRestrictionValue: any; - previousRestrictionType: any; - newRestrictionValue: any; - newRestrictionType: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_GLOBAL_RESTRICTION; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionKey(restrictionKey) { - this.restrictionKey = restrictionKey; - return this; - } - - addPreviousRestrictionValue(previousRestrictionValue) { - this.previousRestrictionValue = previousRestrictionValue; - return this; - } - - addPreviousRestrictionType(previousRestrictionType) { - this.previousRestrictionType = previousRestrictionType; - return this; - } - - addNewRestrictionValue(newRestrictionValue) { - this.newRestrictionValue = newRestrictionValue; - return this; - } - - addNewRestrictionType(newRestrictionType) { - this.newRestrictionType = newRestrictionType; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - addReferenceMosaicId(referenceMosaicId) { - this.referenceMosaicId = referenceMosaicId; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicGlobalRestrictionTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicGlobalRestrictionTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicGlobalRestrictionTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicGlobalRestrictionTransactionBuffer - .createFeeVector(builder, this.maxFee); - const mosaicIdVector = MosaicGlobalRestrictionTransactionBuffer - .createMosaicIdVector(builder, this.mosaicId); - const referenceMosaicIdVector = MosaicGlobalRestrictionTransactionBuffer - .createReferenceMosaicIdVector(builder, this.referenceMosaicId); - const restrictionKeyVector = MosaicGlobalRestrictionTransactionBuffer - .createRestrictionKeyVector(builder, this.restrictionKey); - const previousRestrictionValueVector = MosaicGlobalRestrictionTransactionBuffer - .createPreviousRestrictionValueVector(builder, this.previousRestrictionValue); - const newRestrictionValueVector = MosaicGlobalRestrictionTransactionBuffer - .createNewRestrictionValueVector(builder, this.newRestrictionValue); - - MosaicGlobalRestrictionTransactionBuffer.startMosaicGlobalRestrictionTransactionBuffer(builder); - MosaicGlobalRestrictionTransactionBuffer.addSize(builder, 162); - MosaicGlobalRestrictionTransactionBuffer.addSignature(builder, signatureVector); - MosaicGlobalRestrictionTransactionBuffer.addSigner(builder, signerVector); - MosaicGlobalRestrictionTransactionBuffer.addVersion(builder, this.version); - MosaicGlobalRestrictionTransactionBuffer.addType(builder, this.type); - MosaicGlobalRestrictionTransactionBuffer.addFee(builder, feeVector); - MosaicGlobalRestrictionTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicGlobalRestrictionTransactionBuffer.addMosaicId(builder, mosaicIdVector); - MosaicGlobalRestrictionTransactionBuffer.addReferenceMosaicId(builder, referenceMosaicIdVector); - MosaicGlobalRestrictionTransactionBuffer.addRestrictionKey(builder, restrictionKeyVector); - MosaicGlobalRestrictionTransactionBuffer.addPreviousRestrictionValue(builder, previousRestrictionValueVector); - MosaicGlobalRestrictionTransactionBuffer.addPreviousRestrictionType(builder, this.previousRestrictionType); - MosaicGlobalRestrictionTransactionBuffer.addNewRestrictionValue(builder, newRestrictionValueVector); - MosaicGlobalRestrictionTransactionBuffer.addNewRestrictionType(builder, this.newRestrictionType); - - // Calculate size - - const codedMosaicGlobalRestriction = - MosaicGlobalRestrictionTransactionBuffer.endMosaicGlobalRestrictionTransactionBuffer(builder); - builder.finish(codedMosaicGlobalRestriction); - - const bytes = builder.asUint8Array(); - - const schema = MosaicGlobalRestrictionTransactionSchema; - return new MosaicGlobalRestrictionTransaction(bytes, schema); - } -} diff --git a/src/infrastructure/builders/MosaicSupplyChangeTransaction.ts b/src/infrastructure/builders/MosaicSupplyChangeTransaction.ts deleted file mode 100644 index cfff8db53c..0000000000 --- a/src/infrastructure/builders/MosaicSupplyChangeTransaction.ts +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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 { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicSupplyChangeTransactionBufferPackage from '../buffers/MosaicSupplyChangeTransactionBuffer'; -import MosaicSupplyChangeTransactionSchema from '../schemas/MosaicSupplyChangeTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - MosaicSupplyChangeTransactionBuffer, -} = MosaicSupplyChangeTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -/** - * @module transactions/MosaicSupplyChangeTransaction - */ -export default class MosaicSupplyChangeTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, MosaicSupplyChangeTransactionSchema); - } -} -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - direction: any; - delta: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_SUPPLY_CHANGE; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - addDirection(direction) { - this.direction = direction; - return this; - } - - addDelta(delta) { - this.delta = delta; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicSupplyChangeTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicSupplyChangeTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicSupplyChangeTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicSupplyChangeTransactionBuffer - .createFeeVector(builder, this.maxFee); - const mosaicIdVector = MosaicSupplyChangeTransactionBuffer - .createFeeVector(builder, this.mosaicId); - const deltaVector = MosaicSupplyChangeTransactionBuffer - .createFeeVector(builder, this.delta); - - MosaicSupplyChangeTransactionBuffer.startMosaicSupplyChangeTransactionBuffer(builder); - MosaicSupplyChangeTransactionBuffer.addSize(builder, 137); - MosaicSupplyChangeTransactionBuffer.addSignature(builder, signatureVector); - MosaicSupplyChangeTransactionBuffer.addSigner(builder, signerVector); - MosaicSupplyChangeTransactionBuffer.addVersion(builder, this.version); - MosaicSupplyChangeTransactionBuffer.addType(builder, this.type); - MosaicSupplyChangeTransactionBuffer.addFee(builder, feeVector); - MosaicSupplyChangeTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicSupplyChangeTransactionBuffer.addMosaicId(builder, mosaicIdVector); - MosaicSupplyChangeTransactionBuffer.addDirection(builder, this.direction); - MosaicSupplyChangeTransactionBuffer.addDelta(builder, deltaVector); - - // Calculate size - const codedMosaicChangeSupply = MosaicSupplyChangeTransactionBuffer.endMosaicSupplyChangeTransactionBuffer(builder); - builder.finish(codedMosaicChangeSupply); - - const bytes = builder.asUint8Array(); - return new MosaicSupplyChangeTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/MultisigModificationTransaction.ts b/src/infrastructure/builders/MultisigModificationTransaction.ts deleted file mode 100644 index a11dbfdeb5..0000000000 --- a/src/infrastructure/builders/MultisigModificationTransaction.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* - * 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 { Convert as convert } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import MultisigModificationTransactionBufferPackage from '../buffers/MultisigModificationTransactionBuffer'; -import MultisigModificationTransactionSchema from '../schemas/MultisigModificationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - MultisigModificationTransactionBuffer, - CosignatoryModificationBuffer, -} = MultisigModificationTransactionBufferPackage.Buffers; - -/** - * @module transactions/MultisigModificationTransaction - */ -export default class MultisigModificationTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, MultisigModificationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - minRemovalDelta: any; - minApprovalDelta: any; - modifications: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MODIFY_MULTISIG_ACCOUNT; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addMinRemovalDelta(minRemovalDelta) { - this.minRemovalDelta = minRemovalDelta; - return this; - } - - addMinApprovalDelta(minApprovalDelta) { - this.minApprovalDelta = minApprovalDelta; - return this; - } - - addModifications(modifications) { - this.modifications = modifications; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create modifications - const modificationsArray: any = []; - this.modifications.forEach((modification) => { - const cosignatoryPublicKeyVector = CosignatoryModificationBuffer - .createCosignatoryPublicKeyVector(builder, convert.hexToUint8(modification.cosignatoryPublicKey)); - CosignatoryModificationBuffer.startCosignatoryModificationBuffer(builder); - CosignatoryModificationBuffer.addType(builder, modification.type); - CosignatoryModificationBuffer.addCosignatoryPublicKey(builder, cosignatoryPublicKeyVector); - modificationsArray.push(CosignatoryModificationBuffer.endCosignatoryModificationBuffer(builder)); - }); - - // Create vectors - const signatureVector = MultisigModificationTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MultisigModificationTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MultisigModificationTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MultisigModificationTransactionBuffer - .createFeeVector(builder, this.maxFee); - const modificationsVector = MultisigModificationTransactionBuffer - .createModificationsVector(builder, modificationsArray); - - MultisigModificationTransactionBuffer.startMultisigModificationTransactionBuffer(builder); - MultisigModificationTransactionBuffer.addSize(builder, 123 + (33 * this.modifications.length)); - MultisigModificationTransactionBuffer.addSignature(builder, signatureVector); - MultisigModificationTransactionBuffer.addSigner(builder, signerVector); - MultisigModificationTransactionBuffer.addVersion(builder, this.version); - MultisigModificationTransactionBuffer.addType(builder, this.type); - MultisigModificationTransactionBuffer.addFee(builder, feeVector); - MultisigModificationTransactionBuffer.addDeadline(builder, deadlineVector); - MultisigModificationTransactionBuffer.addMinRemovalDelta(builder, this.minRemovalDelta); - MultisigModificationTransactionBuffer.addMinApprovalDelta(builder, this.minApprovalDelta); - MultisigModificationTransactionBuffer.addNumModifications(builder, this.modifications.length); - MultisigModificationTransactionBuffer.addModifications(builder, modificationsVector); - - // Calculate size - const codedMultisigAggregate = MultisigModificationTransactionBuffer - .endMultisigModificationTransactionBuffer(builder); - builder.finish(codedMultisigAggregate); - - const bytes = builder.asUint8Array(); - return new MultisigModificationTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/NamespaceCreationTransaction.ts b/src/infrastructure/builders/NamespaceCreationTransaction.ts deleted file mode 100644 index 0cf2ba5d67..0000000000 --- a/src/infrastructure/builders/NamespaceCreationTransaction.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/NamespaceCreationTransaction - */ -import { Convert as convert } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import * as NamespaceCreationTransactionBufferPackage from '../buffers/NamespaceCreationTransactionBuffer'; -import NamespaceCreationTransactionSchema from '../schemas/NamespaceCreationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - NamespaceCreationTransactionBuffer, -} = NamespaceCreationTransactionBufferPackage.default.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -export default class NamespaceCreationTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, NamespaceCreationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - namespaceType: any; - duration: any; - parentId: any; - namespaceId: any; - namespaceName: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.REGISTER_NAMESPACE; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addNamespaceType(namespaceType) { - this.namespaceType = namespaceType; - return this; - } - - addDuration(duration) { - this.duration = duration; - return this; - } - - addParentId(parentId) { - this.parentId = parentId; - return this; - } - - addNamespaceId(namespaceId) { - this.namespaceId = namespaceId; - return this; - } - - addNamespaceName(namespaceName) { - this.namespaceName = namespaceName; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - const namespaceNameLength = convert.utf8ToHex(this.namespaceName).length / 2; - - // create vectors - const signatureVector = NamespaceCreationTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = NamespaceCreationTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = NamespaceCreationTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = NamespaceCreationTransactionBuffer - .createFeeVector(builder, this.maxFee); - const parentIdVector = 1 === this.namespaceType ? this.parentId : this.duration; - const durationParentIdVector = NamespaceCreationTransactionBuffer - .createDurationParentIdVector(builder, parentIdVector); - const namespaceIdVector = NamespaceCreationTransactionBuffer - .createNamespaceIdVector(builder, this.namespaceId); - - const name = builder.createString(this.namespaceName); - - NamespaceCreationTransactionBuffer.startNamespaceCreationTransactionBuffer(builder); - NamespaceCreationTransactionBuffer.addSize(builder, 138 + namespaceNameLength); - NamespaceCreationTransactionBuffer.addSignature(builder, signatureVector); - NamespaceCreationTransactionBuffer.addSigner(builder, signerVector); - NamespaceCreationTransactionBuffer.addVersion(builder, this.version); - NamespaceCreationTransactionBuffer.addType(builder, this.type); - NamespaceCreationTransactionBuffer.addFee(builder, feeVector); - NamespaceCreationTransactionBuffer.addDeadline(builder, deadlineVector); - NamespaceCreationTransactionBuffer.addNamespaceType(builder, this.namespaceType); - NamespaceCreationTransactionBuffer.addDurationParentId(builder, durationParentIdVector); - NamespaceCreationTransactionBuffer.addNamespaceId(builder, namespaceIdVector); - NamespaceCreationTransactionBuffer.addNamespaceNameSize(builder, namespaceNameLength); - NamespaceCreationTransactionBuffer.addNamespaceName(builder, name); - - // Calculate size - const codedNamespace = NamespaceCreationTransactionBuffer.endNamespaceCreationTransactionBuffer(builder); - builder.finish(codedNamespace); - - const bytes = builder.asUint8Array(); - return new NamespaceCreationTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/SecretLockTransaction.ts b/src/infrastructure/builders/SecretLockTransaction.ts deleted file mode 100644 index 5e66e40c9b..0000000000 --- a/src/infrastructure/builders/SecretLockTransaction.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/SecretLockTransaction - */ -import { Convert as convert, RawAddress as address } from '../../core/format'; -import * as SecretLockTransactionBufferPackage from '../../infrastructure/buffers/SecretLockTransactionBuffer'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; -import SecretLockTransactionSchema from '../../infrastructure/schemas/SecretLockTransactionSchema'; -import { TransactionType } from '../../model/transaction/TransactionType'; - -import {flatbuffers} from 'flatbuffers'; - -const { - SecretLockTransactionBuffer, -} = SecretLockTransactionBufferPackage.default.Buffers; - -export default class SecretLockTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, SecretLockTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - mosaicAmount: any; - duration: any; - hashAlgorithm: any; - secret: any; - recipient: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.SECRET_LOCK; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - addMosaicAmount(mosaicAmount) { - this.mosaicAmount = mosaicAmount; - return this; - } - - addDuration(duration) { - this.duration = duration; - return this; - } - - addHashAlgorithm(hashAlgorithm) { - this.hashAlgorithm = hashAlgorithm; - return this; - } - - addSecret(secret) { - this.secret = secret; - return this; - } - - addRecipient(recipient) { - this.recipient = address.stringToAddress(recipient); - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = SecretLockTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = SecretLockTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = SecretLockTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = SecretLockTransactionBuffer.createFeeVector(builder, this.maxFee); - const mosaicIdVector = SecretLockTransactionBuffer.createMosaicIdVector(builder, this.mosaicId); - const mosaicAmountVector = SecretLockTransactionBuffer.createMosaicAmountVector(builder, this.mosaicAmount); - const durationVector = SecretLockTransactionBuffer.createDurationVector(builder, this.duration); - const byteSecret = convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); - const secretVector = SecretLockTransactionBuffer.createSecretVector(builder, byteSecret); - const recipientVector = SecretLockTransactionBuffer.createRecipientVector(builder, this.recipient); - - SecretLockTransactionBuffer.startSecretLockTransactionBuffer(builder); - SecretLockTransactionBuffer.addSize(builder, 202); - SecretLockTransactionBuffer.addSignature(builder, signatureVector); - SecretLockTransactionBuffer.addSigner(builder, signerVector); - SecretLockTransactionBuffer.addVersion(builder, this.version); - SecretLockTransactionBuffer.addType(builder, this.type); - SecretLockTransactionBuffer.addFee(builder, feeVector); - SecretLockTransactionBuffer.addDeadline(builder, deadlineVector); - SecretLockTransactionBuffer.addMosaicId(builder, mosaicIdVector); - SecretLockTransactionBuffer.addMosaicAmount(builder, mosaicAmountVector); - SecretLockTransactionBuffer.addDuration(builder, durationVector); - SecretLockTransactionBuffer.addHashAlgorithm(builder, this.hashAlgorithm); - SecretLockTransactionBuffer.addSecret(builder, secretVector); - SecretLockTransactionBuffer.addRecipient(builder, recipientVector); - - const codedSecretLock = SecretLockTransactionBuffer.endSecretLockTransactionBuffer(builder); - builder.finish(codedSecretLock); - - const bytes = builder.asUint8Array(); - return new SecretLockTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/SecretProofTransaction.ts b/src/infrastructure/builders/SecretProofTransaction.ts deleted file mode 100644 index 619e037173..0000000000 --- a/src/infrastructure/builders/SecretProofTransaction.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/SecretProofTransaction - */ -import { Convert as convert, RawAddress as address } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import * as SecretProofTransactionBufferPackage from '../buffers/SecretProofTransactionBuffer'; -import SecretProofTransactionSchema from '../schemas/SecretProofTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - SecretProofTransactionBuffer, -} = SecretProofTransactionBufferPackage.default.Buffers; - -export default class SecretProofTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, SecretProofTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - hashAlgorithm: any; - secret: any; - recipient: any; - proof: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.SECRET_PROOF; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addHashAlgorithm(hashAlgorithm) { - this.hashAlgorithm = hashAlgorithm; - return this; - } - - addSecret(secret) { - this.secret = secret; - return this; - } - addRecipient(recipient) { - this.recipient = address.stringToAddress(recipient); - return this; - } - - addProof(proof) { - this.proof = proof; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = SecretProofTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = SecretProofTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = SecretProofTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = SecretProofTransactionBuffer.createFeeVector(builder, this.maxFee); - const byteSecret = convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); - const secretVector = SecretProofTransactionBuffer.createSecretVector(builder, byteSecret); - const recipientVector = SecretProofTransactionBuffer.createRecipientVector(builder, this.recipient); - const byteProof = convert.hexToUint8(this.proof); - const proofVector = SecretProofTransactionBuffer.createProofVector(builder, byteProof); - - SecretProofTransactionBuffer.startSecretProofTransactionBuffer(builder); - SecretProofTransactionBuffer.addSize(builder, 180 + byteProof.length); - SecretProofTransactionBuffer.addSignature(builder, signatureVector); - SecretProofTransactionBuffer.addSigner(builder, signerVector); - SecretProofTransactionBuffer.addVersion(builder, this.version); - SecretProofTransactionBuffer.addType(builder, this.type); - SecretProofTransactionBuffer.addFee(builder, feeVector); - SecretProofTransactionBuffer.addDeadline(builder, deadlineVector); - SecretProofTransactionBuffer.addHashAlgorithm(builder, this.hashAlgorithm); - SecretProofTransactionBuffer.addSecret(builder, secretVector); - SecretProofTransactionBuffer.addRecipient(builder, recipientVector); - SecretProofTransactionBuffer.addProofSize(builder, byteProof.length); - SecretProofTransactionBuffer.addProof(builder, proofVector); - - const codedSecretProof = SecretProofTransactionBuffer.endSecretProofTransactionBuffer(builder); - builder.finish(codedSecretProof); - - const bytes = builder.asUint8Array(); - return new SecretProofTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/TransferTransaction.ts b/src/infrastructure/builders/TransferTransaction.ts deleted file mode 100644 index 0153d44a91..0000000000 --- a/src/infrastructure/builders/TransferTransaction.ts +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/TransferTransaction - */ -import { Convert as convert, RawAddress as address} from '../../core/format'; -import * as TransferTransactionBufferPackage from '../../infrastructure/buffers/TransferTransactionBuffer'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; -import TransferTransactionSchema from '../../infrastructure/schemas/TransferTransactionSchema'; -import { TransactionType } from '../../model/transaction/TransactionType'; - -import {flatbuffers} from 'flatbuffers'; - -const { - TransferTransactionBuffer, - MessageBuffer, - MosaicBuffer, -} = TransferTransactionBufferPackage.default.Buffers; - -export default class TransferTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, TransferTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - recipient: any; - message: any; - mosaics: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.TRANSFER; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRecipient(recipient) { - if (/^[0-9a-fA-F]{16}$/.test(recipient)) { - // received hexadecimal notation of namespaceId (alias) - this.recipient = address.aliasToRecipient(convert.hexToUint8(recipient)); - } else { - // received recipient address - this.recipient = address.stringToAddress(recipient); - } - return this; - } - - addMessage(message) { - this.message = message; - return this; - } - - addMosaics(mosaics) { - this.mosaics = mosaics.sort((a, b) => { - if (Number(a.id[1]) > b.id[1]) { return 1; } else if (a.id[1] < b.id[1]) { return -1; } - return 0; - }); - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - // Constants - - // Create message - const bytePayload = convert.hexToUint8(convert.utf8ToHex(this.message.payload)); - const payload = MessageBuffer.createPayloadVector(builder, bytePayload); - MessageBuffer.startMessageBuffer(builder); - MessageBuffer.addType(builder, this.message.type); - MessageBuffer.addPayload(builder, payload); - const message = MessageBuffer.endMessageBuffer(builder); - - // Create mosaics - const mosaics: any = []; - this.mosaics.forEach(mosaic => { - const id = MosaicBuffer.createIdVector(builder, mosaic.id); - const amount = MosaicBuffer.createAmountVector(builder, mosaic.amount); - MosaicBuffer.startMosaicBuffer(builder); - MosaicBuffer.addId(builder, id); - MosaicBuffer.addAmount(builder, amount); - mosaics.push(MosaicBuffer.endMosaicBuffer(builder)); - }); - - // Create vectors - const signatureVector = TransferTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = TransferTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = TransferTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = TransferTransactionBuffer.createFeeVector(builder, this.maxFee); - const recipientVector = TransferTransactionBuffer.createRecipientVector(builder, this.recipient); - const mosaicsVector = TransferTransactionBuffer.createMosaicsVector(builder, mosaics); - - TransferTransactionBuffer.startTransferTransactionBuffer(builder); - TransferTransactionBuffer.addSize(builder, 149 + (16 * this.mosaics.length) + bytePayload.length); - TransferTransactionBuffer.addSignature(builder, signatureVector); - TransferTransactionBuffer.addSigner(builder, signerVector); - TransferTransactionBuffer.addVersion(builder, this.version); - TransferTransactionBuffer.addType(builder, this.type); - TransferTransactionBuffer.addFee(builder, feeVector); - TransferTransactionBuffer.addDeadline(builder, deadlineVector); - TransferTransactionBuffer.addRecipient(builder, recipientVector); - TransferTransactionBuffer.addNumMosaics(builder, this.mosaics.length); - TransferTransactionBuffer.addMessageSize(builder, bytePayload.length + 1); - TransferTransactionBuffer.addMessage(builder, message); - TransferTransactionBuffer.addMosaics(builder, mosaicsVector); - - // Calculate size - - const codedTransfer = TransferTransactionBuffer.endTransferTransactionBuffer(builder); - builder.finish(codedTransfer); - - const bytes = builder.asUint8Array(); - return new TransferTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/VerifiableTransaction.ts b/src/infrastructure/builders/VerifiableTransaction.ts deleted file mode 100644 index d83b079d59..0000000000 --- a/src/infrastructure/builders/VerifiableTransaction.ts +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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 { KeyPair, SignSchema } from '../../core/crypto'; -import { SHA3Hasher as sha3Hasher } from '../../core/crypto/SHA3Hasher'; -import { Convert as convert } from '../../core/format'; - -/** - * VerifiableTransaction - * @module transactions/VerifiableTransaction - * @version 1.0.0 - */ -export class VerifiableTransaction { - bytes: any; - schema: any; - /** - * @constructor - * @param {Uint8Array} bytes Uint8Array after flatbuffers.build.asUint8Array() - * @param {module:schema/Schema} schema Schema definition corresponding to flatbuffer Schema - */ - constructor(bytes, schema) { - this.bytes = bytes; - this.schema = schema; - } - - /** - * @param {string} transactionPayload HexString Payload - * @param {string} generationHash Network generation hash byte - * @returns {*|string} Returns Transaction Payload hash - */ - static createTransactionHash(transactionPayload, generationHash) { - const byteBuffer = Array.from(convert.hexToUint8(transactionPayload)); - const signingBytes = byteBuffer - .slice(4, 36) - .concat(byteBuffer - .slice(4 + 64, 4 + 64 + 32)) - .concat(generationHash) - .concat(byteBuffer - .splice(4 + 64 + 32, byteBuffer.length)); - - const hash = new Uint8Array(32); - - sha3Hasher.func(hash, signingBytes, 32); - - return convert.uint8ToHex(hash); - } - - /** - * @param {KeyPair } keyPair KeyPair instance - * @param {string} generationHash Network generation hash hex - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {module:model/TransactionPayload} - Signed Transaction Payload - */ - signTransaction(keyPair, generationHash, signSchema: SignSchema = SignSchema.SHA3) { - const generationHashBytes = Array.from(convert.hexToUint8(generationHash)); - const byteBuffer = this.serialize(); - const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); - const keyPairEncoded = KeyPair.createKeyPairFromPrivateKeyString(keyPair.privateKey, signSchema); - const signature = Array.from(KeyPair.sign(keyPair, new Uint8Array(signingBytes), signSchema)); - const signedTransactionBuffer = byteBuffer - .splice(0, 4) - .concat(signature) - .concat(Array.from(keyPairEncoded.publicKey)) - .concat(byteBuffer - .splice(64 + 32, byteBuffer.length)); - const payload = convert.uint8ToHex(signedTransactionBuffer); - return { - payload, - hash: VerifiableTransaction.createTransactionHash(payload, generationHashBytes), - }; - } - - serialize() { - return this.schema.serialize(Array.from(this.bytes)); - } - - /** - * @returns {string} - Serialized Transaction Payload - */ - serializeUnsignedTransaction() { - return convert.uint8ToHex(this.serialize()); - } - - /** - * @param {KeyPair} keyPair KeyPair instance - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {module:model/TransactionPayload} Returns TransactionPayload instance - */ - signCosignatoriesTransaction(keyPair, signSchema: SignSchema = SignSchema.SHA3) { - const signature = KeyPair.sign(keyPair, new Uint8Array(this.bytes), signSchema); - return { - parentHash: convert.uint8ToHex(this.bytes), - signature: convert.uint8ToHex(signature), - signer: keyPair.publicKey, - }; - } - - /** - * Converts the transaction into AggregateTransaction compatible - * @param {string} [_signer] Signer public key - * @returns {Array.<*>} AggregateTransaction bytes - */ - toAggregateTransaction(_signer) { - const signer = convert.hexToUint8(_signer); - let resultBytes = this.schema.serialize(Array.from(this.bytes)); - resultBytes.splice(0, 4 + 64 + 32); - resultBytes = Array.from(signer).concat(resultBytes); - resultBytes.splice(32 + 2 + 2, 16); - return Array.from((new Uint8Array([ - (resultBytes.length + 4 & 0x000000ff), - (resultBytes.length + 4 & 0x0000ff00) >> 8, - (resultBytes.length + 4 & 0x00ff0000) >> 16, - (resultBytes.length + 4 & 0xff000000) >> 24, - ]))).concat(resultBytes); - } -} diff --git a/src/infrastructure/builders/VerificableTransactionBuilder.ts b/src/infrastructure/builders/VerificableTransactionBuilder.ts deleted file mode 100644 index a63c9cb9ab..0000000000 --- a/src/infrastructure/builders/VerificableTransactionBuilder.ts +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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'; - -const { - flatbuffers -} = require('flatbuffers'); - -/** - * @module transactions/VerifiableTransactionBuilder - */ - -/** - * @callback LambdaBuilder - * @param {flatbuffers.Builder} builder - * @return {void} - */ - -export default class VerifiableTransactionBuilder { - bytes: any; - schema: any - /** - * @param {LambdaBuilder} lambda Callback - * @returns {VerifiableTransactionBuilder} Returns self instance - */ - addTransaction(lambda) { - const builder = new flatbuffers.Builder(1); - - lambda(builder); - - this.bytes = builder.asUint8Array(); - return this; - } - - /** - * @param {module:schema/Schema} schema Schema corresponding with flatbuffers Schema used on addTransaction - * @returns {VerifiableTransactionBuilder} Returns self instance - */ - addSchema(schema) { - this.schema = schema; - return this; - } - - /** - * @returns {VerifiableTransaction} Returns VerifiableTransaction instance - */ - build() { - return new VerifiableTransaction(this.bytes, this.schema); - } -} diff --git a/src/infrastructure/schemas/AccountLinkTransactionSchema.ts b/src/infrastructure/schemas/AccountLinkTransactionSchema.ts deleted file mode 100644 index 5a0e3be1ba..0000000000 --- a/src/infrastructure/schemas/AccountLinkTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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/AccountLinkTransaction - */ - -/** - * Account Link schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('remoteAccountKey'), - ubyte('linkAction') -]); -export default schema; diff --git a/src/infrastructure/schemas/AccountRestrictionsAddressModificationTransactionSchema.ts b/src/infrastructure/schemas/AccountRestrictionsAddressModificationTransactionSchema.ts deleted file mode 100644 index f08fd0cda3..0000000000 --- a/src/infrastructure/schemas/AccountRestrictionsAddressModificationTransactionSchema.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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, - ushort, - tableArray, - uint -} from './Schema'; - -/** - * @module schema/AccountRestrictionsAddressModificationTransactionSchema - */ - -/** - * Account restriction address 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('restrictionType'), - ubyte('modificationCount'), - tableArray('modifications', [ - ubyte('modificationType'), - array('value', TypeSize.BYTE) - ]) -]); diff --git a/src/infrastructure/schemas/AccountRestrictionsEntityTypeModificationTransactionSchema.ts b/src/infrastructure/schemas/AccountRestrictionsEntityTypeModificationTransactionSchema.ts deleted file mode 100644 index 6d9090a5c0..0000000000 --- a/src/infrastructure/schemas/AccountRestrictionsEntityTypeModificationTransactionSchema.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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, - ushort, - tableArray, - uint -} from './Schema'; - -/** - * @module schema/AccountRestrictionsEntityTypeModificationTransactionSchema - */ - -/** - * Account restrictions address 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('restrictionType'), - ubyte('modificationCount'), - tableArray('modifications', [ - ubyte('modificationType'), - ushort('value') - ]) -]); diff --git a/src/infrastructure/schemas/AccountRestrictionsMosaicModificationTransactionSchema.ts b/src/infrastructure/schemas/AccountRestrictionsMosaicModificationTransactionSchema.ts deleted file mode 100644 index 557c38898e..0000000000 --- a/src/infrastructure/schemas/AccountRestrictionsMosaicModificationTransactionSchema.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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, - ushort, - tableArray, - uint -} from './Schema'; - -/** - * @module schema/AccountRestrictionsMosaicModificationTransactionSchema - */ - -/** - * Account restrictions address 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('restrictionType'), - ubyte('modificationCount'), - tableArray('modifications', [ - ubyte('modificationType'), - array('value', TypeSize.INT) - ]) -]); diff --git a/src/infrastructure/schemas/AddressAliasTransactionSchema.ts b/src/infrastructure/schemas/AddressAliasTransactionSchema.ts deleted file mode 100644 index 4a9ceb4d25..0000000000 --- a/src/infrastructure/schemas/AddressAliasTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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) -]); diff --git a/src/infrastructure/schemas/AggregateTransactionSchema.ts b/src/infrastructure/schemas/AggregateTransactionSchema.ts deleted file mode 100644 index f27bc0e142..0000000000 --- a/src/infrastructure/schemas/AggregateTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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, - uint, - ushort -} from './Schema'; - -/** - * @module schema/AggregateTransactionSchema - */ - -/** - * Aggregate transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - uint('transactionsSize'), - array('transactions') -]); - -export default schema; diff --git a/src/infrastructure/schemas/HashLockTransactionSchema.ts b/src/infrastructure/schemas/HashLockTransactionSchema.ts deleted file mode 100644 index 2efbf4ffaa..0000000000 --- a/src/infrastructure/schemas/HashLockTransactionSchema.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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, - uint, - ushort -} from './Schema'; - -/** - * @module schema/HashLockTransactionSchema - */ - -/** - * Hash lock transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('mosaicId', TypeSize.INT), - array('mosaicAmount', TypeSize.INT), - array('duration', TypeSize.INT), - array('hash') -]); -export default schema; diff --git a/src/infrastructure/schemas/MosaicAddressRestrictionTransactionSchema.ts b/src/infrastructure/schemas/MosaicAddressRestrictionTransactionSchema.ts deleted file mode 100644 index 18123110e1..0000000000 --- a/src/infrastructure/schemas/MosaicAddressRestrictionTransactionSchema.ts +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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/MosaicAddressRestrictionTransactionSchema - */ - -/** - * Account Link 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), - array('mosaicId', TypeSize.INT), - array('restrictionKey', TypeSize.INT), - array('targetAddress', TypeSize.BYTE), - array('previousRestrictionValue', TypeSize.INT), - array('newRestrictionValue', TypeSize.INT), -]); diff --git a/src/infrastructure/schemas/MosaicAliasTransactionSchema.ts b/src/infrastructure/schemas/MosaicAliasTransactionSchema.ts deleted file mode 100644 index b8a69b4c3e..0000000000 --- a/src/infrastructure/schemas/MosaicAliasTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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) -]); diff --git a/src/infrastructure/schemas/MosaicCreationTransactionSchema.ts b/src/infrastructure/schemas/MosaicCreationTransactionSchema.ts deleted file mode 100644 index e9d947652a..0000000000 --- a/src/infrastructure/schemas/MosaicCreationTransactionSchema.ts +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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/MosaicCreationTransactionSchema - */ - -/** - * Mosaic definition creation transaction schema - * @const {module:schema/Schema} - */ -export const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('nonce', TypeSize.BYTE), - array('mosaicId', TypeSize.INT), - ubyte('numOptionalProperties'), - ubyte('flags'), - ubyte('divisibility'), - ubyte('indicateDuration'), - array('duration', TypeSize.INT) -]); - -export const schemaNoDuration = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('nonce', TypeSize.BYTE), - array('mosaicId', TypeSize.INT), - ubyte('numOptionalProperties'), - ubyte('flags'), - ubyte('divisibility') -]); diff --git a/src/infrastructure/schemas/MosaicGlobalRestrictionTransactionSchema.ts b/src/infrastructure/schemas/MosaicGlobalRestrictionTransactionSchema.ts deleted file mode 100644 index d5be82b1ec..0000000000 --- a/src/infrastructure/schemas/MosaicGlobalRestrictionTransactionSchema.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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/MosaicGlobalRestrictionTransactionSchema - */ - -/** - * Account Link 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), - array('mosaicId', TypeSize.INT), - array('referenceMosaicId', TypeSize.INT), - array('restrictionKey', TypeSize.INT), - array('previousRestrictionValue', TypeSize.INT), - ubyte('previousRestrictionType'), - array('newRestrictionValue', TypeSize.INT), - ubyte('newRestrictionType'), - -]); diff --git a/src/infrastructure/schemas/MosaicSupplyChangeTransactionSchema.ts b/src/infrastructure/schemas/MosaicSupplyChangeTransactionSchema.ts deleted file mode 100644 index 19df7503b8..0000000000 --- a/src/infrastructure/schemas/MosaicSupplyChangeTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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/MosaicSupplyChangeTransactionSchema - */ - -/** - * Mosaic supply change 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), - array('mosaicId', TypeSize.INT), - ubyte('direction'), - array('delta', TypeSize.INT) -]); diff --git a/src/infrastructure/schemas/MultisigModificationTransactionSchema.ts b/src/infrastructure/schemas/MultisigModificationTransactionSchema.ts deleted file mode 100644 index 91beb8efc6..0000000000 --- a/src/infrastructure/schemas/MultisigModificationTransactionSchema.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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, - tableArray, - TypeSize, - ubyte, - uint, - ushort -} from './Schema'; - -/** - * @module schema/MultigAggregateModificationTransactionSchema - */ - -/** - * Multisig aggregate modification 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('minRemovalDelta'), - ubyte('minApprovalDelta'), - ubyte('numModifications'), - tableArray('modifications', [ - ubyte('type'), - array('cosignatoryPublicKey') - ]) -]); diff --git a/src/infrastructure/schemas/NamespaceCreationTransactionSchema.ts b/src/infrastructure/schemas/NamespaceCreationTransactionSchema.ts deleted file mode 100644 index 7694dddc5e..0000000000 --- a/src/infrastructure/schemas/NamespaceCreationTransactionSchema.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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, - string, - TypeSize, - ubyte, - uint, - ushort -} from './Schema'; - -/** - * @module schema/NamespaceCreationTransactionSchema - */ - -/** - * Provision namespace 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('namespaceType'), - array('durationParentId', TypeSize.INT), - array('namespaceId', TypeSize.INT), - ubyte('namespaceNameSize'), - string('name') -]); diff --git a/src/infrastructure/schemas/Schema.ts b/src/infrastructure/schemas/Schema.ts deleted file mode 100644 index 212378e39e..0000000000 --- a/src/infrastructure/schemas/Schema.ts +++ /dev/null @@ -1,374 +0,0 @@ -/* - * 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. - */ - -/* eslint-disable no-use-before-define */ - -/** - * In bytes - * @type {{BYTE: number, SHORT: number, INT: number}} - */ -export const TypeSize = { - BYTE: 1, - SHORT: 2, - INT: 4, -}; - -/** - * @param {string} name Attribute name - * @returns {ScalarAttribute} return ScalarAttribute Instance - */ -export const ubyte = (name) => { - return new ScalarAttribute(name, TypeSize.BYTE); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const byte = (name) => { - return new ScalarAttribute(name, TypeSize.BYTE); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const ushort = (name) => { - return new ScalarAttribute(name, TypeSize.SHORT); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const short = (name) => { - return new ScalarAttribute(name, TypeSize.SHORT); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const uint = (name) => { - return new ScalarAttribute(name, TypeSize.INT); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const int = (name) => { - return new ScalarAttribute(name, TypeSize.INT); -}; - -/** - * - * @param {string} name Attribute Name - * @param {number} typeSize Attribute Byte Size - * @returns {ArrayAttribute} ArrayAttribute Instance - */ -export const array = (name, typeSize = TypeSize.BYTE) => { - return new ArrayAttribute(name, typeSize); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ArrayAttribute} ArrayAttribute Instance - */ -export const string = (name) => { - return array(name); -}; - -/** - * - * @param {string} name Attribute Name - * @param {module:schema/Schema} schema Table Specific Schema definition - * @returns {TableAttribute} TableAttribute Instance - */ -export const table = (name, schema) => { - return new TableAttribute(name, schema); -}; - -/** - * - * @param {string} name Attribute Name - * @param {module:schema/Schema} schema Schema Definition - * @returns {TableArrayAttribute} TableAttribute Instance - */ -export const tableArray = (name, schema) => { - return new TableArrayAttribute(name, schema); -}; - -/* eslint-disable */ -const readInt32 = (offset, bytes) => { - return bytes[offset] | bytes[offset + 1] << 8 | bytes[offset + 2] << 16 | bytes[offset + 3] << 24; -}; - -const readInt16 = (offset, bytes) => { - return bytes[offset] | bytes[offset + 1] << 8; -}; - -const __offset = (val0, fieldPos, bytes) => { - const vtable = val0 - readInt32(val0, bytes); - return fieldPos < readInt16(vtable, bytes) ? readInt16(vtable + fieldPos, bytes) : 0; -}; - -const __vector_length = (offset, bytes) => { - return readInt32(offset + readInt32(offset, bytes), bytes); -}; - -const __indirect = (offset, bytes) => { - return offset + readInt32(offset, bytes); -}; - -const __vector = (offset, bytes) => { - return offset + readInt32(offset, bytes) + 4; -}; - -const findVector = (val0, fieldPos, bytes, size) => { - const offset = __offset(val0, fieldPos, bytes); - const offsetLong = offset + val0; - const vecStart = __vector(offsetLong, bytes); - const vecLength = __vector_length(offsetLong, bytes) * (size ? size : 1); - return offset ? bytes.slice(vecStart, vecStart + vecLength) : 0; -}; - -const findParam = (val0, fieldPos, bytes, numBytes) => { - const offset = __offset(val0, fieldPos, bytes); - return offset ? bytes.slice(offset + val0, offset + val0 + numBytes) : 0; -}; - -const findObjectStartPosition = (val0, fieldPos, bytes) => { - const offset = __offset(val0, fieldPos, bytes); - return __indirect(offset + val0, bytes); -}; - -const findArrayLength = (val0, fieldPos, bytes) => { - const offset = __offset(val0, fieldPos, bytes); - return offset ? __vector_length(val0 + offset, bytes) : 0; -}; - -const findObjectArrayElementStartPosition = (val0, fieldPos, bytes, index) => { - const offset = __offset(val0, fieldPos, bytes); - const vector = __vector(val0 + offset, bytes); - return __indirect(vector + index * 4, bytes); -}; - -/** - * Schema - * @module schema/Schema - */ -export class Schema { - schemaDefinition; - /** - * @constructor - * @param {Array.} schemaDefinition Schema Definition - */ - constructor(schemaDefinition) { - this.schemaDefinition = schemaDefinition; - } - - /** - * - * @param {Uint8Array} bytes flatbuffers bytes - * @returns {Uint8Array} catapult buffer - */ - serialize(bytes) { - let i = 0; - let resultBytes = []; - while (i < this.schemaDefinition.length) { - resultBytes = resultBytes.concat(this.schemaDefinition[i].serialize(bytes, 4 + (i * 2))); - i++; - } - return resultBytes; - } - - /** - * @param {Uint8Array} bytes flatbuffer bytes - * @returns {Array} Array with field name + payload - */ - debugSerialize(bytes) { - let i = 0; - let result: any = []; - while (i < this.schemaDefinition.length) { - result = result.concat({ - name: this.schemaDefinition[i].name, - bytes: this.schemaDefinition[i].debugSerialize(bytes, 4 + i * 2), - }); - i++; - } - return result; - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Attribute { - name: any; - /** - * @constructor - * @param {string} name schema attribute name - */ - constructor(name) { - this.name = name; - } - - /** - * - * @param {Uint8Array} buffer flatbuffer bytes - * @param {number} position attribute possition in flatbuffer bytes - * @param {number} val0 position in case that it is an inner object - */ - serialize(buffer, position, val0 = undefined) { - throw new Error('Unimplemented method'); - } - - /** - * @suppress warnings - * @param {Uint8Array} buffer buffer flatbuffer bytes - * @param {number} position attribute possition in flatbuffer bytes - * @param {number} val0 position in case that it is an inner object - */ - debugSerialize(buffer, position, val0 = undefined) { - throw new Error('Unimplemented method'); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class ScalarAttribute extends Attribute { - typeSize: any; - name: any; - /** - * @constructor - * @param {string} name schema attribute name - * @param {number} typeSize - */ - constructor(name, typeSize) { - super(name); - this.typeSize = typeSize; - } - - serialize(buffer, position, val0 = undefined) { - return findParam(val0 ? val0 : buffer[0], position, buffer, this.typeSize); - } - - debugSerialize(buffer, position, val0 = undefined) { - return { - name: this.name, - bytes: this.serialize(buffer, position, val0), - }; - } -} - -// tslint:disable-next-line:max-classes-per-file -export class ArrayAttribute extends Attribute { - typeSize: any; - name: any; - /** - * @constructor - * @param name - {string} - * @param typeSize - {TypeSize} - */ - constructor(name, typeSize) { - super(name); - this.typeSize = typeSize; - } - - serialize(buffer, position, val0 = undefined) { - return findVector(val0 ? val0 : buffer[0], position, buffer, this.typeSize); - } - - debugSerialize(buffer, position, val0 = undefined) { - return { - name: this.name, - bytes: this.serialize(buffer, position, val0), - }; - } -} - -// tslint:disable-next-line:max-classes-per-file -export class TableAttribute extends Attribute { - schema: any; - name: any; - /** - * - * @param {string} name - * @param {module:schema/Schema} schema - */ - constructor(name, schema) { - super(name); - this.schema = schema; - } - - serialize(bytes, position, val0 = undefined) { - let result = []; - const messageStartPosition = findObjectStartPosition(val0 ? val0 : bytes[0], position, bytes); - let i = 0; - while (i < this.schema.length) { - result = result.concat(this.schema[i].serialize(bytes, 4 + i * 2, messageStartPosition)); - i++; - } - return result; - } - - debugSerialize(buffer, position, val0 = undefined) { - return { - name: this.name, - bytes: this.serialize(buffer, position, val0), - }; - } -} - -// tslint:disable-next-line:max-classes-per-file -export class TableArrayAttribute extends Attribute { - schema: any; - name: any; - /** - * @constructor - * @param {string} name - * @param {module:schema/Schema} schema - */ - constructor(name, schema) { - super(name); - this.schema = schema; - } - - serialize(bytes, position, val0 = undefined) { - let result = []; - const arrayLength = findArrayLength(val0 ? val0 : bytes[0], position, bytes); - let i = 0; - while (i < arrayLength) { - const startArrayPosition = findObjectArrayElementStartPosition(val0 ? val0 : bytes[0], position, bytes, i); - for (let j = 0; j < this.schema.length; ++j) { - result = result.concat(this.schema[j].serialize(bytes, 4 + j * 2, startArrayPosition)); - } - i++; - } - return result; - } - - debugSerialize(buffer, position, val0 = undefined) { - return { - name: this.name, - bytes: this.serialize(buffer, position, val0), - }; - } -} diff --git a/src/infrastructure/schemas/SecretLockTransactionSchema.ts b/src/infrastructure/schemas/SecretLockTransactionSchema.ts deleted file mode 100644 index 046f02c178..0000000000 --- a/src/infrastructure/schemas/SecretLockTransactionSchema.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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/SecretLockTransactionSchema - */ - -/** - * Secret lock transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('mosaicId', TypeSize.INT), - array('mosaicAmount', TypeSize.INT), - array('duration', TypeSize.INT), - ubyte('hashAlgorithm'), - array('secret'), - array('recipient') -]); -export default schema; diff --git a/src/infrastructure/schemas/SecretProofTransactionSchema.ts b/src/infrastructure/schemas/SecretProofTransactionSchema.ts deleted file mode 100644 index db03f6eaf4..0000000000 --- a/src/infrastructure/schemas/SecretProofTransactionSchema.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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/SecretProofTransactionSchema - */ - -/** - * Secret proof transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - ubyte('hashAlgorithm'), - array('secret'), - array('recipient'), - ushort('proofSize'), - array('proof') -]); -export default schema; diff --git a/src/infrastructure/schemas/TransferTransactionSchema.ts b/src/infrastructure/schemas/TransferTransactionSchema.ts deleted file mode 100644 index eb8efdfd4e..0000000000 --- a/src/infrastructure/schemas/TransferTransactionSchema.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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, - table, - tableArray, - TypeSize, - ubyte, - uint, - ushort -} from './Schema'; - -/** - * @module schema/TransferTransactionSchema - */ - -/** - * Transfer transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('recipient'), - ushort('messageSize'), - ubyte('numMosaics'), - table('message', [ - ubyte('type'), - array('payload') - ]), - tableArray('mosaics', [ - array('id', TypeSize.INT), - array('amount', TypeSize.INT) - ]) -]); -export default schema; diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index b1198243fd..6491749d4c 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -190,27 +190,21 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N case TransactionType.MOSAIC_DEFINITION: const mosaicDefMosaicNonceLength = 8; const mosaicDefMosaicIdLength = 16; - const mosaicDefPropsNumLength = 2; const mosaicDefPropsFlagsLength = 2; const mosaicDefDivisibilityLength = 2; - const mosaicDefDurationIndLength = 2; const mosaicDefDurationLength = 16; const mosaicIdOffset = mosaicDefMosaicNonceLength; - const propsOffset = mosaicIdOffset + mosaicDefMosaicIdLength; - const flagsOffset = propsOffset + mosaicDefPropsNumLength; + const flagsOffset = mosaicIdOffset + mosaicDefMosaicIdLength; const divisibilityOffset = flagsOffset + mosaicDefPropsFlagsLength; - const durationIndOffset = divisibilityOffset + mosaicDefDivisibilityLength; - const durationOffset = durationIndOffset + mosaicDefDurationIndLength; + const durationOffset = divisibilityOffset + mosaicDefDivisibilityLength; // read bytes const mosaicNonce = transactionData.substring(0, mosaicDefMosaicNonceLength); - const mosaicId = transactionData.substring(mosaicIdOffset, propsOffset); - const props = transactionData.substring(propsOffset, flagsOffset); + const mosaicId = transactionData.substring(mosaicIdOffset, flagsOffset); const flags = parseInt(convert.uint8ToHex(convert.hexToUint8( transactionData.substring(flagsOffset, divisibilityOffset)).reverse()), 16); - const divisibility = transactionData.substring(divisibilityOffset, durationIndOffset); - const durationInd = transactionData.substring(durationIndOffset, durationOffset); + const divisibility = transactionData.substring(divisibilityOffset, durationOffset); const duration = transactionData.substring(durationOffset); const regexArray = mosaicNonce.match(/.{1,2}/g); diff --git a/src/model/namespace/AliasActionType.ts b/src/model/namespace/AliasActionType.ts index e44895f689..27669a1d91 100644 --- a/src/model/namespace/AliasActionType.ts +++ b/src/model/namespace/AliasActionType.ts @@ -20,6 +20,6 @@ * 1: Unlink an alias. */ export enum AliasActionType { - Link = 0, - Unlink = 1, + Link = 1, + Unlink = 0, } diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index fd4200205c..150cd213b6 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -15,13 +15,10 @@ */ import { Convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; @@ -106,20 +103,6 @@ export class AccountAddressRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRestrictionType(this.restrictionType) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index bd0a0303db..58584444b2 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountLinkTransaction'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/AccountLinkTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder'; @@ -105,20 +103,6 @@ export class AccountLinkTransaction extends Transaction { return byteSize + bytePublicKey + byteLinkAction; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRemoteAccountKey(this.remoteAccountKey) - .addLinkAction(this.linkAction) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index efe54c41d8..be182d398b 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -105,20 +103,6 @@ export class AccountMosaicRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRestrictionType(this.restrictionType) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index b42d33e3ab..3ee53a4b4d 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -104,20 +102,6 @@ export class AccountOperationRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRestrictionType(this.restrictionType) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index e1149b090e..ccb9010d0d 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AddressAliasTransaction'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; import { AddressDto } from '../../infrastructure/catbuffer/AddressDto'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -121,21 +119,6 @@ export class AddressAliasTransaction extends Transaction { return byteSize + byteActionType + byteNamespaceId + byteAddress; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addActionType(this.actionType) - .addNamespaceId(this.namespaceId.id.toDTO()) - .addAddress(this.address.plain()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 797eb757e5..608559f663 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -14,10 +14,8 @@ * limitations under the License. */ -import { SignSchema } from '../../core/crypto'; +import { KeyPair, SignSchema } from '../../core/crypto'; import { Convert } from '../../core/format'; -import { AggregateTransaction as AggregatedTransactionCore} from '../../infrastructure/builders/AggregateTransaction'; -import { Builder } from '../../infrastructure/builders/AggregateTransaction'; import { AggregateTransactionBuilder } from '../../infrastructure/catbuffer/AggregateTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { CosignatureBuilder } from '../../infrastructure/catbuffer/CosignatureBuilder'; @@ -31,6 +29,7 @@ import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AggregateTransactionCosignature } from './AggregateTransactionCosignature'; import { CosignatureSignedTransaction } from './CosignatureSignedTransaction'; +import { CosignatureTransaction } from './CosignatureTransaction'; import { Deadline } from './Deadline'; import { InnerTransaction } from './InnerTransaction'; import { SignedTransaction } from './SignedTransaction'; @@ -123,21 +122,6 @@ export class AggregateTransaction extends Transaction { ); } - /** - * @internal - * @returns {AggregateTransaction} - */ - public buildTransaction(): AggregatedTransactionCore { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addType(this.type) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addTransactions(this.innerTransactions.map((transaction) => { - return transaction.aggregateTransaction(); - })).build(); - } - /** * @internal * Sign transaction with cosignatories creating a new SignedTransaction @@ -150,11 +134,23 @@ export class AggregateTransaction extends Transaction { public signTransactionWithCosignatories(initiatorAccount: Account, cosignatories: Account[], generationHash: string, - signSchema: SignSchema = SignSchema.SHA3) { - const aggregateTransaction = this.buildTransaction(); - const signedTransactionRaw = aggregateTransaction - .signTransactionWithCosigners(initiatorAccount, cosignatories, generationHash, signSchema); - return new SignedTransaction(signedTransactionRaw.payload, signedTransactionRaw.hash, initiatorAccount.publicKey, + signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { + const signedTransaction = this.signWith(initiatorAccount, generationHash, signSchema); + const transactionHashBytes = Convert.hexToUint8(signedTransaction.hash); + let signedPayload = signedTransaction.payload; + cosignatories.forEach((cosigner) => { + const signature = KeyPair.sign(cosigner, transactionHashBytes, signSchema); + signedPayload += cosigner.publicKey + Convert.uint8ToHex(signature); + }); + + // Calculate new size + const size = `00000000${(signedPayload.length / 2).toString(16)}`; + const formatedSize = size.substr(size.length - 8, size.length); + const littleEndianSize = formatedSize.substr(6, 2) + formatedSize.substr(4, 2) + + formatedSize.substr(2, 2) + formatedSize.substr(0, 2); + + signedPayload = littleEndianSize + signedPayload.substr(8, signedPayload.length - 8); + return new SignedTransaction(signedPayload, signedTransaction.hash, initiatorAccount.publicKey, this.type, this.networkType); } @@ -171,13 +167,21 @@ export class AggregateTransaction extends Transaction { public signTransactionGivenSignatures(initiatorAccount: Account, cosignatureSignedTransactions: CosignatureSignedTransaction[], generationHash: string, - signSchema: SignSchema= SignSchema.SHA3) { - const aggregateTransaction = this.buildTransaction(); - const signedTransactionRaw = aggregateTransaction.signTransactionGivenSignatures(initiatorAccount, - cosignatureSignedTransactions, - generationHash, - signSchema); - return new SignedTransaction(signedTransactionRaw.payload, signedTransactionRaw.hash, initiatorAccount.publicKey, + signSchema: SignSchema= SignSchema.SHA3): SignedTransaction { + const signedTransaction = this.signWith(initiatorAccount, generationHash, signSchema); + let signedPayload = signedTransaction.payload; + cosignatureSignedTransactions.forEach((cosignedTransaction) => { + signedPayload += cosignedTransaction.signer + cosignedTransaction.signature; + }); + + // Calculate new size + const size = `00000000${(signedPayload.length / 2).toString(16)}`; + const formatedSize = size.substr(size.length - 8, size.length); + const littleEndianSize = formatedSize.substr(6, 2) + formatedSize.substr(4, 2) + + formatedSize.substr(2, 2) + formatedSize.substr(0, 2); + + signedPayload = littleEndianSize + signedPayload.substr(8, signedPayload.length - 8); + return new SignedTransaction(signedPayload, signedTransaction.hash, initiatorAccount.publicKey, this.type, this.networkType); } @@ -237,9 +241,6 @@ export class AggregateTransaction extends Transaction { transactions = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); }); - console.log('cosignatures', Convert.uint8ToHex(cosignatures)); - console.log('transactions', Convert.uint8ToHex(transactions)); - const transactionBuilder = new AggregateTransactionBuilder( new SignatureDto(signatureBuffer), new KeyDto(signerBuffer), diff --git a/src/model/transaction/CosignatureTransaction.ts b/src/model/transaction/CosignatureTransaction.ts index d1b6ddc5b5..62e4a248ed 100644 --- a/src/model/transaction/CosignatureTransaction.ts +++ b/src/model/transaction/CosignatureTransaction.ts @@ -14,13 +14,12 @@ * limitations under the License. */ -import { SignSchema } from '../../core/crypto'; +import { KeyPair, SignSchema } from '../../core/crypto'; import { Convert } from '../../core/format/Convert'; -import {CosignatureTransaction as CosignaturetransactionLibrary} from '../../infrastructure/builders/CosignatureTransaction'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import {Account} from '../account/Account'; import {AggregateTransaction} from './AggregateTransaction'; import {CosignatureSignedTransaction} from './CosignatureSignedTransaction'; +import { Transaction } from './Transaction'; /** * Cosignature transaction is used to sign an aggregate transactions with missing cosignatures. @@ -41,9 +40,9 @@ export class CosignatureTransaction { * @param transactionToCosign - Transaction to cosign. * @returns {CosignatureTransaction} */ - public static create(transactionToCosign: AggregateTransaction) { + public static create(transactionToCosign: AggregateTransaction): CosignatureTransaction { if (transactionToCosign.isUnannounced()) { - throw new Error('transaction to cosign should be announced first'); + throw new Error('Transaction to cosign should be announced first'); } return new CosignatureTransaction(transactionToCosign); } @@ -64,12 +63,14 @@ export class CosignatureTransaction { /** * For aggregated complete transaction, cosignatories are gathered off chain announced. */ - const transactionHash = VerifiableTransaction.createTransactionHash(payload, Array.from(Convert.hexToUint8(generationHash))); - const aggregateSignatureTransaction = new CosignaturetransactionLibrary(transactionHash); - const signedTransactionRaw = aggregateSignatureTransaction.signCosignatoriesTransaction(account, signSchema); - return new CosignatureSignedTransaction(signedTransactionRaw.parentHash, - signedTransactionRaw.signature, - signedTransactionRaw.signer); + const transactionHash = Transaction.createTransactionHash(payload, Array.from(Convert.hexToUint8(generationHash))); + const hashBytes = Convert.hexToUint8(transactionHash); + const signature = KeyPair.sign(account, new Uint8Array(hashBytes), signSchema); + return new CosignatureSignedTransaction( + Convert.uint8ToHex(hashBytes), + Convert.uint8ToHex(signature), + account.publicKey, + ); } /** @@ -80,10 +81,16 @@ export class CosignatureTransaction { * @returns {CosignatureSignedTransaction} */ public signWith(account: Account, signSchema: SignSchema = SignSchema.SHA3): CosignatureSignedTransaction { - const aggregateSignatureTransaction = new CosignaturetransactionLibrary(this.transactionToCosign.transactionInfo!.hash); - const signedTransactionRaw = aggregateSignatureTransaction.signCosignatoriesTransaction(account, signSchema); - return new CosignatureSignedTransaction(signedTransactionRaw.parentHash, - signedTransactionRaw.signature, - signedTransactionRaw.signer); + if (!this.transactionToCosign.transactionInfo!.hash) { + throw new Error('Transaction to cosign should be announced first'); + } + const hash = this.transactionToCosign.transactionInfo!.hash; + const hashBytes = Convert.hexToUint8(hash ? hash : ''); + const signature = KeyPair.sign(account, new Uint8Array(hashBytes), signSchema); + return new CosignatureSignedTransaction( + hash ? hash : '', + Convert.uint8ToHex(signature), + account.publicKey, + ); } } diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index e34bb40489..b36810cf05 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/HashLockTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedHashLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder'; @@ -131,23 +129,6 @@ export class LockFundsTransaction extends Transaction { return byteSize + byteMosaicId + byteAmount + byteDuration + byteHash; } - /** - * @internal - * @return {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addType(this.type) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaic.id.id.toDTO()) - .addMosaicAmount(this.mosaic.amount.toDTO()) - .addDuration(this.duration.toDTO()) - .addHash(this.hash) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index fa1e35dfef..6fb31645ba 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -15,10 +15,9 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MultisigModificationTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { CosignatoryModificationBuilder } from '../../infrastructure/catbuffer/CosignatoryModificationBuilder'; +import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { MultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -32,7 +31,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; /** * Modify multisig account transactions are part of the NEM's multisig account system. @@ -125,21 +123,6 @@ export class ModifyMultisigAccountTransaction extends Transaction { return byteSize + byteRemovalDelta + byteApprovalDelta + byteNumModifications + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMinApprovalDelta(this.minApprovalDelta) - .addMinRemovalDelta(this.minRemovalDelta) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index 819d69c43c..f366fc0aed 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MosaicAddressRestrictionTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -142,23 +140,6 @@ export class MosaicAddressRestrictionTransaction extends Transaction { byteTargetAddress + bytePreviousRestrictionValue + byteNewRestrictionValue; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaicId.id.toDTO()) - .addRestrictionKey(this.restrictionKey.toDTO()) - .addTargetAddress(this.targetAddress.plain()) - .addPreviousRestrictionValue(this.previousRestrictionValue.toDTO()) - .addNewRestrictionValue(this.newRestrictionValue.toDTO()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index 39b064bb16..220317b9d9 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MosaicAliasTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; @@ -117,21 +115,6 @@ export class MosaicAliasTransaction extends Transaction { return byteSize + byteType + byteNamespaceId + byteMosaicId; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addActionType(this.actionType) - .addNamespaceId(this.namespaceId.id.toDTO()) - .addMosaicId(this.mosaicId.id.toDTO()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index c0adbd1e8b..9ebbf03fe6 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MosaicCreationTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedMosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder'; @@ -158,35 +156,6 @@ export class MosaicDefinitionTransaction extends Transaction { return GeneratorUtils.readUint32At(this.nonce.toDTO(), 0); } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - let mosaicDefinitionTransaction = new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addDivisibility(this.mosaicProperties.divisibility) - .addDuration(this.mosaicProperties.duration ? this.mosaicProperties.duration.toDTO() : []) - .addNonce(this.nonce.toDTO()) - .addMosaicId(this.mosaicId.id.toDTO()); - - if (this.mosaicProperties.supplyMutable === true) { - mosaicDefinitionTransaction = mosaicDefinitionTransaction.addSupplyMutable(); - } - - if (this.mosaicProperties.transferable === true) { - mosaicDefinitionTransaction = mosaicDefinitionTransaction.addTransferability(); - } - - if (this.mosaicProperties.restrictable === true) { - mosaicDefinitionTransaction = mosaicDefinitionTransaction.addRestrictable(); - } - - return mosaicDefinitionTransaction.build(); - } - /** * @internal * @returns {Uint8Array} @@ -207,7 +176,7 @@ export class MosaicDefinitionTransaction extends Transaction { this.getMosaicFlagValue(), this.mosaicProperties.divisibility, new BlockDurationDto(this.mosaicProperties.duration ? - this.mosaicProperties.duration.toDTO() : []), + this.mosaicProperties.duration.toDTO() : UInt64.fromUint(0).toDTO()), ); return transactionBuilder.serialize(); } @@ -226,7 +195,7 @@ export class MosaicDefinitionTransaction extends Transaction { this.getMosaicFlagValue(), this.mosaicProperties.divisibility, new BlockDurationDto(this.mosaicProperties.duration ? - this.mosaicProperties.duration.toDTO() : []), + this.mosaicProperties.duration.toDTO() : UInt64.fromUint(0).toDTO()), ); return transactionBuilder.serialize(); } diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index 7b4f757efc..9081fa5dbc 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MosaicGlobalRestrictionTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicGlobalRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -162,25 +160,6 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { bytePreviousRestrictionType; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaicId.id.toDTO()) - .addReferenceMosaicId(this.referenceMosaicId.id.toDTO()) - .addRestrictionKey(this.restrictionKey.toDTO()) - .addPreviousRestrictionValue(this.previousRestrictionValue.toDTO()) - .addPreviousRestrictionType(this.previousRestrictionType) - .addNewRestrictionValue(this.newRestrictionValue.toDTO()) - .addNewRestrictionType(this.newRestrictionType) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index be4f3a89a3..03f0137241 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { Builder } from '../../infrastructure/builders/MosaicSupplyChangeTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -33,7 +32,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { Convert } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -118,21 +116,6 @@ export class MosaicSupplyChangeTransaction extends Transaction { return byteSize + byteMosaicId + byteDirection + byteDelta; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaicId.id.toDTO()) - .addDirection(this.direction) - .addDelta(this.delta.toDTO()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index 0cdcae2aa6..3089126e25 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert, Convert as convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/NamespaceCreationTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedNamespaceRegistrationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder'; @@ -168,28 +166,6 @@ export class RegisterNamespaceTransaction extends Transaction { return byteSize + byteType + byteDurationParentId + byteNamespaceId + byteNameSize + byteName; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - let registerNamespacetransaction = new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addNamespaceType(this.namespaceType) - .addNamespaceId(this.namespaceId.id.toDTO()) - .addNamespaceName(this.namespaceName); - - if (this.namespaceType === NamespaceType.RootNamespace) { - registerNamespacetransaction = registerNamespacetransaction.addDuration(this.duration!.toDTO()); - } else { - registerNamespacetransaction = registerNamespacetransaction.addParentId(this.parentId!.id.toDTO()); - } - - return registerNamespacetransaction.build(); - } - /** * @internal * @returns {Uint8Array} @@ -238,7 +214,7 @@ export class RegisterNamespaceTransaction extends Transaction { transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), - TransactionType.SECRET_LOCK.valueOf(), + TransactionType.REGISTER_NAMESPACE.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), new BlockDurationDto(this.duration!.toDTO()), @@ -248,7 +224,7 @@ export class RegisterNamespaceTransaction extends Transaction { transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), - TransactionType.SECRET_LOCK.valueOf(), + TransactionType.REGISTER_NAMESPACE.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), undefined, diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index e65187384d..5efbe3c3fe 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -14,8 +14,6 @@ * limitations under the License. */ import { Convert as convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/SecretLockTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedSecretLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder'; @@ -155,25 +153,6 @@ export class SecretLockTransaction extends Transaction { return convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addType(this.type) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaic.id.id.toDTO()) - .addMosaicAmount(this.mosaic.amount.toDTO()) - .addDuration(this.duration.toDTO()) - .addHashAlgorithm(this.hashType) - .addSecret(this.secret) - .addRecipient(this.recipient.plain()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index 41df6b207b..cbca7576b2 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert, Convert as convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/SecretProofTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedSecretProofTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; @@ -140,23 +138,6 @@ export class SecretProofTransaction extends Transaction { return convert.hexToUint8(this.proof); } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addType(this.type) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addHashAlgorithm(this.hashType) - .addSecret(this.secret) - .addRecipient(this.recipient.plain()) - .addProof(this.proof) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index ca2fbbce44..29d3ae1b3d 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -16,7 +16,6 @@ import { KeyPair, SHA3Hasher, SignSchema } from '../../core/crypto'; import { Convert } from '../../core/format'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { SerializeTransactionToJSON } from '../../infrastructure/transaction/SerializeTransactionToJSON'; import { Account } from '../account/Account'; import { PublicAccount } from '../account/PublicAccount'; @@ -81,9 +80,27 @@ export abstract class Transaction { } /** - * @internal + * Generate transaction hash hex + * @param {string} transactionPayload HexString Payload + * @param {Array} generationHashBuffer Network generation hash byte + * @returns {string} Returns Transaction Payload hash */ - protected abstract buildTransaction(): VerifiableTransaction; + public static createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { + const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); + const signingBytes = byteBuffer + .slice(4, 36) + .concat(byteBuffer + .slice(4 + 64, 4 + 64 + 32)) + .concat(generationHashBuffer) + .concat(byteBuffer + .splice(4 + 64 + 32, byteBuffer.length)); + + const hash = new Uint8Array(32); + + SHA3Hasher.func(hash, signingBytes, 32); + + return Convert.uint8ToHex(hash); + } /** * @internal @@ -104,25 +121,6 @@ export abstract class Transaction { * @returns {SignedTransaction} */ public signWith(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { - const transaction = this.buildTransaction(); - const signedTransactionRaw = transaction.signTransaction(account, generationHash, signSchema); - return new SignedTransaction( - signedTransactionRaw.payload, - signedTransactionRaw.hash, - account.publicKey, - this.type, - this.networkType); - } - - /** - * @internal - * Serialize and sign transaction creating a new SignedTransaction - * @param account - The account to sign the transaction - * @param generationHash - Network generation hash hex - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {SignedTransaction} - */ - public signWithCatbuffer(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { const generationHashBytes = Array.from(Convert.hexToUint8(generationHash)); const byteBuffer = Array.from(this.generateBytes()); const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); @@ -137,41 +135,28 @@ export abstract class Transaction { const payload = Convert.uint8ToHex(signedTransactionBuffer); return new SignedTransaction( payload, - this.createTransactionHash(payload, generationHashBytes), + Transaction.createTransactionHash(payload, generationHashBytes), account.publicKey, this.type, this.networkType); } /** - * Generate transaction hash hex - * @param {string} transactionPayload HexString Payload - * @param {Array} generationHashBuffer Network generation hash byte - * @returns {string} Returns Transaction Payload hash - */ - public createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { - const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); - const signingBytes = byteBuffer - .slice(4, 36) - .concat(byteBuffer - .slice(4 + 64, 4 + 64 + 32)) - .concat(generationHashBuffer) - .concat(byteBuffer - .splice(4 + 64 + 32, byteBuffer.length)); - - const hash = new Uint8Array(32); - - SHA3Hasher.func(hash, signingBytes, 32); - - return Convert.uint8ToHex(hash); - } - - /** - * @internal - * @returns {Array} + * Converts the transaction into AggregateTransaction compatible + * @returns {Array.<*>} AggregateTransaction bytes */ public aggregateTransaction(): number[] { - return this.buildTransaction().toAggregateTransaction(this.signer!.publicKey); + const signer = Convert.hexToUint8(this.signer!.publicKey); + let resultBytes = Array.from(this.generateBytes()); + resultBytes.splice(0, 4 + 64 + 32); + resultBytes = Array.from(signer).concat(resultBytes); + resultBytes.splice(32 + 2 + 2, 16); + return Array.from((new Uint8Array([ + (resultBytes.length + 4 & 0x000000ff), + (resultBytes.length + 4 & 0x0000ff00) >> 8, + (resultBytes.length + 4 & 0x00ff0000) >> 16, + (resultBytes.length + 4 & 0xff000000) >> 24, + ]))).concat(resultBytes); } /** @@ -278,9 +263,8 @@ export abstract class Transaction { * @returns {string} * @memberof Transaction */ - public serialize() { - const transaction = this.buildTransaction(); - return transaction.serializeUnsignedTransaction(); + public serialize(): string { + return Convert.uint8ToHex(this.generateBytes()); } /** diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 6714fd7904..c78253b040 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -16,8 +16,6 @@ import { Convert, Convert as convert } from '../../core/format'; import { RawAddress } from '../../core/format/RawAddress'; -import { Builder } from '../../infrastructure/builders/TransferTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedTransferTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedTransferTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; @@ -145,6 +143,22 @@ export class TransferTransaction extends Transaction { return GeneratorUtils.concatTypedArrays(typeBuffer, payloadBuffer); } + /** + * Return unresolved address bytes of the recipient + * @internal + * @returns {string} + */ + public getRecipientBytes(): Uint8Array { + const recipient = this.recipientToString(); + if (/^[0-9a-fA-F]{16}$/.test(recipient)) { + // received hexadecimal notation of namespaceId (alias) + return RawAddress.aliasToRecipient(convert.hexToUint8(recipient)); + } else { + // received recipient address + return RawAddress.stringToAddress(recipient); + } + } + /** * @override Transaction.size() * @description get the byte size of a TransferTransaction @@ -167,21 +181,6 @@ export class TransferTransaction extends Transaction { return byteSize + byteRecipient + byteNumMosaics + bytePayload + byteMosaics; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRecipient(this.recipientToString()) - .addMosaics(this.mosaics.map((mosaic) => mosaic.toDTO())) - .addMessage(this.message) - .build(); - } - /** * @internal * @returns {Uint8Array} @@ -197,7 +196,7 @@ export class TransferTransaction extends Transaction { TransactionType.TRANSFER.valueOf(), new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), - new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), + new UnresolvedAddressDto(this.getRecipientBytes()), this.getMessageBuffer(), this.sortMosaics().map((mosaic) => { return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index 0d5b8c8b25..68c65c8eae 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountLinkTransaction', () => { expect(accountLinkTransaction.linkAction).to.be.equal(0); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); - const signedTransaction = accountLinkTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = accountLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 36dd3232a1..6291870102 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -162,7 +162,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = addressRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -204,7 +204,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = mosaicRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -246,7 +246,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = operationRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index e2efb443b9..e6b56c8d68 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -80,12 +80,12 @@ describe('AddressAliasTransaction', () => { expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = addressAliasTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = addressAliasTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('002AD8FC018D9A49E19050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + )).to.be.equal('012AD8FC018D9A49E19050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); }); diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index d6a4c714aa..9334b7a15a 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -106,7 +106,7 @@ describe('AggregateTransaction', () => { NetworkType.MIJIN_TEST, []); - const signedTransaction = aggregateTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); @@ -166,12 +166,12 @@ describe('AggregateTransaction', () => { const signedTransaction = aggregateTransaction.signWith(account, generationHash); - expect(signedTransaction.payload.substring(0, 8)).to.be.equal('BC000000'); - expect(signedTransaction.payload.substring(240, 256)).to.be.equal('4000000040000000'); + expect(signedTransaction.payload.substring(0, 8)).to.be.equal('BA000000'); + expect(signedTransaction.payload.substring(240, 256)).to.be.equal('3E0000003E000000'); expect(signedTransaction.payload.substring( 320, signedTransaction.payload.length, - )).to.be.equal('01904D41E6DE84B8010000000000000001070302E803000000000000'); + )).to.be.equal('01904D41E6DE84B801000000000000000703E803000000000000'); }); it('should createComplete an AggregateTransaction object with MosaicSupplyChangeTransaction', () => { diff --git a/test/model/transaction/LockFundsTransaction.spec.ts b/test/model/transaction/LockFundsTransaction.spec.ts index df3583f1d7..779e6166d7 100644 --- a/test/model/transaction/LockFundsTransaction.spec.ts +++ b/test/model/transaction/LockFundsTransaction.spec.ts @@ -118,7 +118,7 @@ describe('LockFundsTransaction', () => { signedTransaction, NetworkType.MIJIN_TEST, ); - const signedTx = lockFundsTransaction.signWithCatbuffer(account, generationHash); + const signedTx = lockFundsTransaction.signWith(account, generationHash); expect(signedTx.payload.substring( 136, diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index 1062a6afc4..1d0734794d 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -110,7 +110,7 @@ describe('ModifyMultisigAccountTransaction', () => { expect(modifyMultisigAccountTransaction.modifications[1].cosignatoryPublicAccount.publicKey) .to.be.equal('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); - const signedTransaction = modifyMultisigAccountTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts index 02aad2fc65..947904ce56 100644 --- a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts @@ -47,7 +47,7 @@ describe('MosaicAddressRestrictionTransaction', () => { expect(mosaicAddressRestrictionTransaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(8).toHex()); expect(mosaicAddressRestrictionTransaction.targetAddress.plain()).to.be.equal(account.address.plain()); - const signedTransaction = mosaicAddressRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicAddressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index c08ff431f9..3ef279ee6f 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -80,12 +80,12 @@ describe('MosaicAliasTransaction', () => { expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); expect(mosaicAliasTransaction.mosaicId.id.higher).to.be.equal(3405110546); - const signedTransaction = mosaicAliasTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('002AD8FC018D9A49E14CCCD78612DDF5CA'); + )).to.be.equal('012AD8FC018D9A49E14CCCD78612DDF5CA'); }); diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index 688506516b..f444278cbe 100644 --- a/test/model/transaction/MosaicDefinitionTransaction.spec.ts +++ b/test/model/transaction/MosaicDefinitionTransaction.spec.ts @@ -64,7 +64,7 @@ describe('MosaicDefinitionTransaction', () => { duration: UInt64.fromUint(1000), }), NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(mosaicDefinitionTransaction.maxFee.higher).to.be.equal(0); @@ -93,7 +93,7 @@ describe('MosaicDefinitionTransaction', () => { expect(mosaicDefinitionTransaction.mosaicProperties.transferable).to.be.equal(true); expect(mosaicDefinitionTransaction.mosaicProperties.restrictable).to.be.equal(true); - const signedTransaction = mosaicDefinitionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -129,7 +129,7 @@ describe('MosaicDefinitionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('E6DE84B8010000000000000001000302E803000000000000'); + )).to.be.equal('E6DE84B801000000000000000003E803000000000000'); }); @@ -175,7 +175,7 @@ describe('MosaicDefinitionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('E6DE84B80100000000000000000003'); + )).to.be.equal('E6DE84B8010000000000000000030000000000000000'); }); }); diff --git a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts index 9e436d2fea..39c409bd22 100644 --- a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts @@ -54,7 +54,7 @@ describe('MosaicGlobalRestrictionTransaction', () => { expect(mosaicGlobalRestrictionTransaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.EQ); expect(mosaicGlobalRestrictionTransaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); - const signedTransaction = mosaicGlobalRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/RegisterNamespaceTransaction.spec.ts b/test/model/transaction/RegisterNamespaceTransaction.spec.ts index db497c73b9..dcd12d95f7 100644 --- a/test/model/transaction/RegisterNamespaceTransaction.spec.ts +++ b/test/model/transaction/RegisterNamespaceTransaction.spec.ts @@ -66,7 +66,7 @@ describe('RegisterNamespaceTransaction', () => { expect(registerNamespaceTransaction.duration!.lower).to.be.equal(1000); expect(registerNamespaceTransaction.duration!.higher).to.be.equal(0); - const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -83,7 +83,7 @@ describe('RegisterNamespaceTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/SecretLockTransaction.spec.ts b/test/model/transaction/SecretLockTransaction.spec.ts index 9f240dda47..9b5a00780d 100644 --- a/test/model/transaction/SecretLockTransaction.spec.ts +++ b/test/model/transaction/SecretLockTransaction.spec.ts @@ -101,7 +101,7 @@ describe('SecretLockTransaction', () => { recipient, NetworkType.MIJIN_TEST, ); - const signedTx = secretLockTransaction.signWithCatbuffer(account, generationHash); + const signedTx = secretLockTransaction.signWith(account, generationHash); expect(signedTx.payload.substring( 240, signedTx.payload.length, diff --git a/test/model/transaction/SecretProofTransaction.spec.ts b/test/model/transaction/SecretProofTransaction.spec.ts index 8712f1ca9e..951b1ab8f0 100644 --- a/test/model/transaction/SecretProofTransaction.spec.ts +++ b/test/model/transaction/SecretProofTransaction.spec.ts @@ -203,7 +203,7 @@ describe('SecretProofTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTx = secretProofTransaction.signWithCatbuffer(account, generationHash); + const signedTx = secretProofTransaction.signWith(account, generationHash); expect(signedTx.payload.substring( 240, signedTx.payload.length, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index 6f53048623..d0baad099a 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -15,7 +15,6 @@ */ import { expect } from 'chai'; -import { VerifiableTransaction } from '../../../src/infrastructure/builders/VerifiableTransaction'; import { Account } from '../../../src/model/account/Account'; import { Address } from '../../../src/model/account/Address'; import { NetworkType } from '../../../src/model/blockchain/NetworkType'; @@ -235,10 +234,6 @@ class FakeTransaction extends Transaction { throw new Error('Method not implemented.'); } - protected buildTransaction(): VerifiableTransaction { - throw new Error('Method not implemented.'); - } - protected generateBytes(): Uint8Array { throw new Error('Not implemented'); } diff --git a/test/model/transaction/TransferTransaction.spec.ts b/test/model/transaction/TransferTransaction.spec.ts index 63d8bb880c..969bf81a1b 100644 --- a/test/model/transaction/TransferTransaction.spec.ts +++ b/test/model/transaction/TransferTransaction.spec.ts @@ -210,7 +210,7 @@ describe('TransferTransaction', () => { expect(transferTransaction.recipient).to.be.instanceof(Address); expect((transferTransaction.recipient as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = transferTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = transferTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, From 4a98ddba5605d5013b83e2b9a785e449781a5a5f Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 12:15:35 +0100 Subject: [PATCH 09/98] updated action types value --- src/model/account/RestrictionModificationType.ts | 4 ++-- src/model/mosaic/MosaicSupplyType.ts | 4 ++-- src/model/namespace/AliasActionType.ts | 4 ++-- src/model/transaction/LinkAction.ts | 4 ++-- src/model/transaction/MultisigCosignatoryModificationType.ts | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/model/account/RestrictionModificationType.ts b/src/model/account/RestrictionModificationType.ts index b4aabd8151..a9aa625500 100644 --- a/src/model/account/RestrictionModificationType.ts +++ b/src/model/account/RestrictionModificationType.ts @@ -18,6 +18,6 @@ * Account restriction modification type */ export enum RestrictionModificationType { - Add = 0x00, - Remove = 0x01, + Add = 0x01, + Remove = 0x00, } diff --git a/src/model/mosaic/MosaicSupplyType.ts b/src/model/mosaic/MosaicSupplyType.ts index c5cf2655fa..0f28e995b0 100644 --- a/src/model/mosaic/MosaicSupplyType.ts +++ b/src/model/mosaic/MosaicSupplyType.ts @@ -20,6 +20,6 @@ * 1: Decrease in supply. */ export enum MosaicSupplyType { - Decrease = 0, - Increase = 1, + Decrease = 0x00, + Increase = 0x01, } diff --git a/src/model/namespace/AliasActionType.ts b/src/model/namespace/AliasActionType.ts index 27669a1d91..b107b0d65d 100644 --- a/src/model/namespace/AliasActionType.ts +++ b/src/model/namespace/AliasActionType.ts @@ -20,6 +20,6 @@ * 1: Unlink an alias. */ export enum AliasActionType { - Link = 1, - Unlink = 0, + Link = 0x01, + Unlink = 0x00, } diff --git a/src/model/transaction/LinkAction.ts b/src/model/transaction/LinkAction.ts index 678e1bb87d..212a0a9c80 100644 --- a/src/model/transaction/LinkAction.ts +++ b/src/model/transaction/LinkAction.ts @@ -15,6 +15,6 @@ */ export enum LinkAction { - Link = 0, - Unlink = 1, + Link = 0x01, + Unlink = 0x00, } diff --git a/src/model/transaction/MultisigCosignatoryModificationType.ts b/src/model/transaction/MultisigCosignatoryModificationType.ts index 7aa92781f7..2edfa42d01 100644 --- a/src/model/transaction/MultisigCosignatoryModificationType.ts +++ b/src/model/transaction/MultisigCosignatoryModificationType.ts @@ -20,6 +20,6 @@ * 1: Remove cosignatory. */ export enum MultisigCosignatoryModificationType { - Add = 0, - Remove = 1, + Add = 0x01, + Remove = 0x00, } From fbc3a8a2724f4ea901bcdcc98aad4a8ce13d6a22 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 12:16:52 +0100 Subject: [PATCH 10/98] restored network config for e2e --- e2e/conf/network.conf | 66 +++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index 79f895aecf..150443d82d 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -1,54 +1,54 @@ { - "apiUrl": "http://c2.nem.ninja:3000", - "generationHash": "57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6", + "apiUrl": "http://localhost:3000", + "generationHash": "5E34C898234E17E8553359D4DEAA123742C323F4C42758C511E6CC805934853E", "testAccount": { - "privateKey": "E1C8521608F4896CA26A0C2DE739310EA4B06861D126CF4D6922064678A1969B", - "address": "SAKT3CKHCYIG5BBOPTSY2WXSVPBSLIA67AEOX4ND", - "publicKey": "9F784BF20318AE3CA6246C0EC2207FE095FFF7A84B6787E7E3C2CE4C3B92A2EA" + "privateKey": "C422CC3C9257A1568036E1726E64EB5923C8363A13D4344F9E66CD89C8789BC7", + "address": "SAMA2UEQNAQ45DWYDNJVLPWKQJDAHFZIVLWACIGN", + "publicKey": "8A78C9E9B0E59D0F74C0D47AB29FBD523C706293A3FA9CD9FE0EEB2C10EA924A" }, "multisigAccount": { - "privateKey": "A9CEAA617D0B7D9DEBE9F96BD63CCF68A49950BB315CB9A4169FC6AAA1EC9E28", - "address": "SDWY3PYN4ZZO4S4EBEY2UPSSZUPGZH2G2LQMUSEU", - "publicKey": "8A613468924B8771779C7E4C889205A9BE6CAE0B9435B4BCC8E79A8DD8571608" + "privateKey": "F6815438AE34F95F2CF364B4679D16F3602CA2107073C0709738BAB457B09A45", + "publicKey": "FAF3F9FD3E32EB43273E5351BAE705D0179D37CBDCC4DD78A0C73232DD3EF32C", + "address": "SDC4BXKIIDBQA2CY6RPRFO3WLC5OZHLKLJJ3NFEH" }, "cosignatoryAccount": { - "privateKey": "8CBAA7491B7DC1070BECBC4F60AE55F4A272DA1DAD1D502DB016E142993817BA", - "address": "SB7Q5A3KEKFEWBPBTC6RFKU6Q2L4V7DM4ZNE4A7A", - "publicKey": "61B8EB2C02F3D3731A8EF6FE4CCD6BC84615BABA09CA3E891C0D2542096E6AD3" + "privateKey": "F48EA053D7D2B47DC518FDD69B338D34C819D9AC51E8754378F2D86FC29783C7", + "publicKey": "D9FB51DDFA64CC56D7AEBB32976DA8A3A72C8C7D02838AA1041046FA0883EBC6", + "address": "SCHNSELDJ7JN5MPHBOKHNBR2QRST4GOGEMS4XZNE" }, "cosignatory2Account": { - "privateKey": "60380027EBE63A5D60F6156F5637685172331705160783FF2F9D93C1E5A8622B", - "address": "SCM47E3JVPHOFWLSMNX3RKQQQIB3JUBR7MTX4M4P", - "publicKey": "3D9996683A0FA460D13288B846DF68A9B6C0C1F14EC2E43907DF8D84DC87B9C2" + "privateKey": "E697E9E0D849ACD3BD9379E80C4E953B23375112C28D983AF94160AD269BE327", + "publicKey": "2B4598150E66B26D991FA56FAF691C539FD1A92EBEA99E2AF91808B9C7C4316F", + "address": "SAWZITCY4TCOFBSSINFO4DQZTRBSB5W5OBSQE237" }, "cosignatory3Account": { - "privateKey": "E39CE241F730CD190658AFDB5F3896628F92D7BC35D88435D148BED88C6CC844", - "address": "SDEVG5MU4MEGJ72NSBC7PKMK7JCJKN7QB3DOVARJ", - "publicKey": "422697046582D8B8063931B7327D0C06FA454B416F6A5C000922EC5BA546F4B2" + "privateKey": "3F42F4308B3EA912A9FE482D6DD04CCFD8D37E4397BF9655AA2EF36894491CAB", + "publicKey": "26A339827614E7AEE9DB427323AA3A49A48456AA5656D9A2E1B50FF93DE90756", + "address": "SCGYYXGL3TLZBOA5TUCCQYIM6NSYSLVCBVHGYKKW" }, "cosignatory4Account": { - "privateKey": "0EA7E63C96FC580AD5EE85ED3C77A96B421F7C8BF75A83AB889313114C9082F2", - "address": "SCBNKMD23J7BO3Q42SEGP4LXGVJYSDPUESSEWGWZ", - "publicKey": "3A225A2C7C7D95279E74D420728D2DA2A176DE036B67909074AEF5F2DCFAF31C" + "privateKey": "53D6A6659A200DAF4930AD4C8A3B5B28ECAAA1F643E990C0A41C0B8EC9B3D05A", + "publicKey": "F721863CC533C3DF4429A957F822B986C81E62A91726A3E3BD0B861FA42F757D", + "address": "SD3JPQ2KXMQKLVOHJV7GTOYV73CL72ZSEOW7RIWE" }, "testAccount2": { - "privateKey": "A084418D937627BCDA19B277D8610C845124149FA18AABE96A17D56A2EA7FB8B", - "address": "SBF5HY3T7SXIBCSK4V4WNS4LS4QUMESMVNBCD2AQ", - "publicKey": "1C4B44400FDC933860B1949A5AEA756F19A36D73C4634699E49C3E7275EFA54F" + "privateKey": "F0AB1010EFEE19EE5373719881DF5123C13E643C519655F7E97347BFF77175BF", + "publicKey": "9DBF67474D6E1F8B131B4EB1F5BA0595AFFAE1123607BC1048F342193D7E669F", + "address": "SDBC4JE7GTJAKN2XJCQWWRJMYA35AFOYQBATXOUA" }, "testAccount3": { - "privateKey": "8C9E72C5D8964A19174B478B65BD4B7F2AFD8F92C05AE45B15A9EDF222EC8CA8", - "address": "SDY65GIMMOF7GZGGART66QGS6ELWDTQT55JJOF42", - "publicKey": "B8320002C5CF64D855F073F2387FB18F13E7A04FA57FC3743694B04579104F98" + "privateKey": "61C3C8F24E3708CFE17A64B66EBD29D747326DBF7962EBEE9340439725C04F11", + "publicKey": "399C1D18FDE3293DCF7BF522626266663C83453BDF7D38C9E96AFC795C07E0A2", + "address": "SC7PPZRJMEMQ7S32PURJTTNHOATDYQ4NPRFOAOUO" }, "testAccountNoBalance": { - "privateKey": "CE4E6B1113EF8999ED79A027A4F3255C367BC2E40417E27E614FB7C12E42BDFA", - "address": "SDNMDW5TXIORKRXQ7F3QORRW4KUAK4ALQ7JWX2KJ", - "publicKey": "92658FE642AEAF1B766D0F4FE4E263C3A0E069735836383D31A70E2B7801358B" + "privateKey": "6530E5ED4B6D32CB9AF2EE09D2889DC781C569B83C137854EDC7773B057074A1", + "publicKey": "559019D82C4CACAAE616A024544251D58BB4464CD36407224475A577F9649E78", + "address": "SCQP4B6BDNH5MZHTLL2ZNXIPYSLD5BU4NDXBZXNK" }, "harvestingAccount": { - "privateKey": "9999630E4AE5CA5675A703F3268084EB9A9B477A8C519D66465D5D21830E691A", - "address": "SC2PGQO5WV4QZRAQHJDNQ2Q5IFWA2D3VLFEFFZHC", - "publicKey": "74771A0B0B920D787F4F8242926C348007B23062910DE99C7E56AA79D4D7B90A" + "privateKey": "AF39DCC819388A2CE9DC0922730D7579588571A63F349A0FB1BC44807C926E53", + "publicKey": "FAEDB16763F22870B75BF934EA5F2792BDF109EC0C504718DDCBD92DF13C2628", + "address": "SCNPFCWFV2FYQVMU5HMJJTMADRZ3LRXVA76F56N2" } -} +} \ No newline at end of file From cf17571ab3ca74e5d30d08fc6497ea0253e24106 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 12:22:36 +0100 Subject: [PATCH 11/98] Fixed unit tests after swapping action type value --- test/core/utils/TransactionMapping.spec.ts | 2 +- test/model/transaction/AccountLinkTransaction.spec.ts | 10 +++++----- .../transaction/AccountRestrictionTransaction.spec.ts | 6 +++--- test/model/transaction/AggregateTransaction.spec.ts | 4 ++-- .../ModifyMultisigAccountTransaction.spec.ts | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index 01148693ad..21188eb17f 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -498,7 +498,7 @@ describe('TransactionMapping - createFromPayload', () => { const signedTransaction = accountLinkTransaction.signWith(account, generationHash); const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AccountLinkTransaction; - expect(transaction.linkAction).to.be.equal(0); + expect(transaction.linkAction).to.be.equal(1); expect(transaction.remoteAccountKey).to.be.equal(account.publicKey); }); diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index 68c65c8eae..ec2fe1630d 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -48,7 +48,7 @@ describe('AccountLinkTransaction', () => { account.publicKey, LinkAction.Link, NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(accountLinkTransaction.maxFee.higher).to.be.equal(0); @@ -63,7 +63,7 @@ describe('AccountLinkTransaction', () => { NetworkType.MIJIN_TEST, ); - expect(accountLinkTransaction.linkAction).to.be.equal(0); + expect(accountLinkTransaction.linkAction).to.be.equal(1); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); const signedTransaction = accountLinkTransaction.signWith(account, generationHash); @@ -71,7 +71,7 @@ describe('AccountLinkTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE00'); + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE01'); }); it('should create an AccountLinkTransaction object with unlink action', () => { @@ -82,7 +82,7 @@ describe('AccountLinkTransaction', () => { NetworkType.MIJIN_TEST, ); - expect(accountLinkTransaction.linkAction).to.be.equal(1); + expect(accountLinkTransaction.linkAction).to.be.equal(0); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); const signedTransaction = accountLinkTransaction.signWith(account, generationHash); @@ -90,7 +90,7 @@ describe('AccountLinkTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE01'); + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE00'); }); describe('size', () => { diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 6291870102..550ee81fc1 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -167,7 +167,7 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('0101009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + )).to.be.equal('0101019050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); }); @@ -209,7 +209,7 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('0201004CCCD78612DDF5CA'); + )).to.be.equal('0201014CCCD78612DDF5CA'); }); @@ -251,7 +251,7 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('0401004E42'); + )).to.be.equal('0401014E42'); }); }); diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 9334b7a15a..072302eba9 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -232,8 +232,8 @@ describe('AggregateTransaction', () => { expect(signedTransaction.payload.substring( 320, signedTransaction.payload.length, - )).to.be.equal('0190554101020200B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC240' + - '0B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); + )).to.be.equal('0190554101020201B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC2401B1B5581FC81A69' + + '70DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); }); it('should createComplete an AggregateTransaction object with different cosignatories', () => { diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index 1d0734794d..375de0a62a 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -115,8 +115,8 @@ describe('ModifyMultisigAccountTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('01020200B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC' + - '6EC2400B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); + )).to.be.equal('01020201B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC2401B1' + + 'B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); }); From 0d307882f8bf1922c9cff5aa0d8c83e6126f3428 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 21:43:04 +0100 Subject: [PATCH 12/98] Added ts catbuffer codes (without aggregateTx) Appended new signwithCatbuffer method in Transaction (temp) Applied catbuffer builders on standalone transaction (builder) Updated unit tests --- e2e/infrastructure/TransactionHttp.spec.ts | 12 +- src/infrastructure/QueryParams.ts | 1 - .../AccountRestrictionsAddressTransaction.ts | 2 +- ...ccountRestrictionsEntityTypeTransaction.ts | 2 +- .../AccountRestrictionsMosaicTransaction.ts | 2 +- ...ntAddressRestrictionModificationBuilder.ts | 91 ++++++++ ...ddressRestrictionTransactionBodyBuilder.ts | 114 ++++++++++ ...untAddressRestrictionTransactionBuilder.ts | 116 +++++++++++ .../catbuffer/AccountLinkActionDto.ts | 29 +++ .../AccountLinkTransactionBodyBuilder.ts | 102 +++++++++ .../AccountLinkTransactionBuilder.ts | 113 ++++++++++ .../AccountMetadataTransactionBodyBuilder.ts | 147 +++++++++++++ .../AccountMetadataTransactionBuilder.ts | 139 +++++++++++++ ...untMosaicRestrictionModificationBuilder.ts | 91 ++++++++ ...MosaicRestrictionTransactionBodyBuilder.ts | 114 ++++++++++ ...ountMosaicRestrictionTransactionBuilder.ts | 116 +++++++++++ ...OperationRestrictionModificationBuilder.ts | 91 ++++++++ ...rationRestrictionTransactionBodyBuilder.ts | 114 ++++++++++ ...tOperationRestrictionTransactionBuilder.ts | 116 +++++++++++ ...AccountRestrictionModificationActionDto.ts | 29 +++ .../AccountRestrictionModificationBuilder.ts | 83 ++++++++ .../catbuffer/AccountRestrictionTypeDto.ts | 35 ++++ .../AddressAliasTransactionBodyBuilder.ts | 121 +++++++++++ .../AddressAliasTransactionBuilder.ts | 125 +++++++++++ src/infrastructure/catbuffer/AddressDto.ts | 79 +++++++ .../catbuffer/AliasActionDto.ts | 29 +++ src/infrastructure/catbuffer/AmountDto.ts | 80 ++++++++ .../catbuffer/BlockDurationDto.ts | 80 ++++++++ .../CosignatoryModificationActionDto.ts | 29 +++ .../CosignatoryModificationBuilder.ts | 102 +++++++++ ...untAddressRestrictionTransactionBuilder.ts | 110 ++++++++++ .../EmbeddedAccountLinkTransactionBuilder.ts | 107 ++++++++++ ...beddedAccountMetadataTransactionBuilder.ts | 133 ++++++++++++ ...ountMosaicRestrictionTransactionBuilder.ts | 110 ++++++++++ ...tOperationRestrictionTransactionBuilder.ts | 110 ++++++++++ .../EmbeddedAddressAliasTransactionBuilder.ts | 119 +++++++++++ .../EmbeddedHashLockTransactionBuilder.ts | 119 +++++++++++ ...aicAddressRestrictionTransactionBuilder.ts | 140 +++++++++++++ .../EmbeddedMosaicAliasTransactionBuilder.ts | 119 +++++++++++ ...eddedMosaicDefinitionTransactionBuilder.ts | 141 +++++++++++++ ...saicGlobalRestrictionTransactionBuilder.ts | 160 +++++++++++++++ ...mbeddedMosaicMetadataTransactionBuilder.ts | 144 +++++++++++++ ...dedMosaicSupplyChangeTransactionBuilder.ts | 120 +++++++++++ ...igAccountModificationTransactionBuilder.ts | 119 +++++++++++ ...ddedNamespaceMetadataTransactionBuilder.ts | 145 +++++++++++++ ...NamespaceRegistrationTransactionBuilder.ts | 143 +++++++++++++ .../EmbeddedSecretLockTransactionBuilder.ts | 142 +++++++++++++ .../EmbeddedSecretProofTransactionBuilder.ts | 129 ++++++++++++ .../catbuffer/EmbeddedTransactionBuilder.ts | 127 ++++++++++++ .../EmbeddedTransferTransactionBuilder.ts | 118 +++++++++++ src/infrastructure/catbuffer/EntityTypeDto.ts | 133 ++++++++++++ .../catbuffer/GeneratorUtils.ts | 141 +++++++++++++ src/infrastructure/catbuffer/Hash256Dto.ts | 79 +++++++ src/infrastructure/catbuffer/Hash512Dto.ts | 79 +++++++ .../HashLockTransactionBodyBuilder.ts | 121 +++++++++++ .../catbuffer/HashLockTransactionBuilder.ts | 125 +++++++++++ src/infrastructure/catbuffer/KeyDto.ts | 79 +++++++ .../catbuffer/LockHashAlgorithmDto.ts | 33 +++ ...ddressRestrictionTransactionBodyBuilder.ts | 158 ++++++++++++++ ...aicAddressRestrictionTransactionBuilder.ts | 146 +++++++++++++ .../MosaicAliasTransactionBodyBuilder.ts | 121 +++++++++++ .../MosaicAliasTransactionBuilder.ts | 125 +++++++++++ src/infrastructure/catbuffer/MosaicBuilder.ts | 102 +++++++++ .../MosaicDefinitionTransactionBodyBuilder.ts | 158 ++++++++++++++ .../MosaicDefinitionTransactionBuilder.ts | 147 +++++++++++++ .../catbuffer/MosaicFlagsDto.ts | 33 +++ ...GlobalRestrictionTransactionBodyBuilder.ts | 194 ++++++++++++++++++ ...saicGlobalRestrictionTransactionBuilder.ts | 166 +++++++++++++++ src/infrastructure/catbuffer/MosaicIdDto.ts | 80 ++++++++ .../MosaicMetadataTransactionBodyBuilder.ts | 168 +++++++++++++++ .../MosaicMetadataTransactionBuilder.ts | 150 ++++++++++++++ .../catbuffer/MosaicNonceDto.ts | 80 ++++++++ .../catbuffer/MosaicRestrictionTypeDto.ts | 39 ++++ .../catbuffer/MosaicSupplyChangeActionDto.ts | 29 +++ ...osaicSupplyChangeTransactionBodyBuilder.ts | 121 +++++++++++ .../MosaicSupplyChangeTransactionBuilder.ts | 125 +++++++++++ ...countModificationTransactionBodyBuilder.ts | 131 ++++++++++++ ...igAccountModificationTransactionBuilder.ts | 125 +++++++++++ .../catbuffer/NamespaceIdDto.ts | 80 ++++++++ ...NamespaceMetadataTransactionBodyBuilder.ts | 168 +++++++++++++++ .../NamespaceMetadataTransactionBuilder.ts | 151 ++++++++++++++ ...spaceRegistrationTransactionBodyBuilder.ts | 188 +++++++++++++++++ ...NamespaceRegistrationTransactionBuilder.ts | 149 ++++++++++++++ .../catbuffer/NamespaceRegistrationTypeDto.ts | 29 +++ .../SecretLockTransactionBodyBuilder.ts | 160 +++++++++++++++ .../catbuffer/SecretLockTransactionBuilder.ts | 148 +++++++++++++ .../SecretProofTransactionBodyBuilder.ts | 144 +++++++++++++ .../SecretProofTransactionBuilder.ts | 135 ++++++++++++ src/infrastructure/catbuffer/SignatureDto.ts | 79 +++++++ src/infrastructure/catbuffer/TimestampDto.ts | 80 ++++++++ .../catbuffer/TransactionBuilder.ts | 185 +++++++++++++++++ .../TransferTransactionBodyBuilder.ts | 135 ++++++++++++ .../catbuffer/TransferTransactionBuilder.ts | 124 +++++++++++ .../catbuffer/UnresolvedAddressDto.ts | 79 +++++++ .../catbuffer/UnresolvedMosaicBuilder.ts | 102 +++++++++ .../catbuffer/UnresolvedMosaicIdDto.ts | 80 ++++++++ .../transaction/CreateTransactionFromDTO.ts | 18 +- .../CreateTransactionFromPayload.ts | 24 +-- .../transaction/SerializeTransactionToJSON.ts | 24 +-- src/model/model.ts | 6 +- src/model/mosaic/MosaicFlag.ts | 25 +++ ...> AccountAddressRestrictionTransaction.ts} | 50 ++++- .../transaction/AccountLinkTransaction.ts | 27 +++ ...=> AccountMosaicRestrictionTransaction.ts} | 49 ++++- ...AccountOperationRestrictionTransaction.ts} | 46 ++++- .../AccountRestrictionTransaction.ts | 22 +- .../transaction/AddressAliasTransaction.ts | 30 +++ src/model/transaction/AggregateTransaction.ts | 10 +- src/model/transaction/LockFundsTransaction.ts | 7 + .../ModifyMultisigAccountTransaction.ts | 35 +++- .../MosaicAddressRestrictionTransaction.ts | 7 + .../transaction/MosaicAliasTransaction.ts | 29 +++ .../MosaicDefinitionTransaction.ts | 68 ++++++ .../MosaicGlobalRestrictionTransaction.ts | 7 + .../MosaicSupplyChangeTransaction.ts | 27 +++ .../RegisterNamespaceTransaction.ts | 7 + .../transaction/SecretLockTransaction.ts | 46 ++++- .../transaction/SecretProofTransaction.ts | 50 ++++- src/model/transaction/Transaction.ts | 62 +++++- src/model/transaction/TransactionType.ts | 42 ++-- src/model/transaction/TransactionVersion.ts | 4 +- src/model/transaction/TransferTransaction.ts | 61 +++++- test/core/utils/TransactionMapping.spec.ts | 18 +- .../SerializeTransactionToJSON.spec.ts | 6 +- .../AccountLinkTransaction.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 12 +- .../AddressAliasTransaction.spec.ts | 2 +- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- .../MosaicAliasTransaction.spec.ts | 4 +- .../MosaicDefinitionTransaction.spec.ts | 4 +- .../transaction/SecretLockTransaction.spec.ts | 31 ++- .../SecretProofTransaction.spec.ts | 22 +- test/model/transaction/Transaction.spec.ts | 4 + .../transaction/TransferTransaction.spec.ts | 28 ++- 134 files changed, 11043 insertions(+), 138 deletions(-) create mode 100644 src/infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountLinkActionDto.ts create mode 100644 src/infrastructure/catbuffer/AccountLinkTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountLinkTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMetadataTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountRestrictionModificationActionDto.ts create mode 100644 src/infrastructure/catbuffer/AccountRestrictionModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountRestrictionTypeDto.ts create mode 100644 src/infrastructure/catbuffer/AddressAliasTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AddressAliasTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AddressDto.ts create mode 100644 src/infrastructure/catbuffer/AliasActionDto.ts create mode 100644 src/infrastructure/catbuffer/AmountDto.ts create mode 100644 src/infrastructure/catbuffer/BlockDurationDto.ts create mode 100644 src/infrastructure/catbuffer/CosignatoryModificationActionDto.ts create mode 100644 src/infrastructure/catbuffer/CosignatoryModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedTransferTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EntityTypeDto.ts create mode 100644 src/infrastructure/catbuffer/GeneratorUtils.ts create mode 100644 src/infrastructure/catbuffer/Hash256Dto.ts create mode 100644 src/infrastructure/catbuffer/Hash512Dto.ts create mode 100644 src/infrastructure/catbuffer/HashLockTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/HashLockTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/KeyDto.ts create mode 100644 src/infrastructure/catbuffer/LockHashAlgorithmDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicAliasTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicAliasTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicDefinitionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicDefinitionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicFlagsDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicIdDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicMetadataTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicNonceDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicRestrictionTypeDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicSupplyChangeActionDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MultisigAccountModificationTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceIdDto.ts create mode 100644 src/infrastructure/catbuffer/NamespaceMetadataTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceRegistrationTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceRegistrationTypeDto.ts create mode 100644 src/infrastructure/catbuffer/SecretLockTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/SecretLockTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/SecretProofTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/SecretProofTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/SignatureDto.ts create mode 100644 src/infrastructure/catbuffer/TimestampDto.ts create mode 100644 src/infrastructure/catbuffer/TransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/TransferTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/TransferTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/UnresolvedAddressDto.ts create mode 100644 src/infrastructure/catbuffer/UnresolvedMosaicBuilder.ts create mode 100644 src/infrastructure/catbuffer/UnresolvedMosaicIdDto.ts create mode 100644 src/model/mosaic/MosaicFlag.ts rename src/model/transaction/{AccountAddressRestrictionModificationTransaction.ts => AccountAddressRestrictionTransaction.ts} (64%) rename src/model/transaction/{AccountMosaicRestrictionModificationTransaction.ts => AccountMosaicRestrictionTransaction.ts} (65%) rename src/model/transaction/{AccountOperationRestrictionModificationTransaction.ts => AccountOperationRestrictionTransaction.ts} (67%) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 2ad8b0be8d..d15c87fd4b 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -37,10 +37,10 @@ import {MosaicSupplyType} from '../../src/model/mosaic/MosaicSupplyType'; import {NetworkCurrencyMosaic} from '../../src/model/mosaic/NetworkCurrencyMosaic'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; -import { AccountAddressRestrictionModificationTransaction } from '../../src/model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from '../../src/model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../src/model/transaction/AccountLinkTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from '../../src/model/transaction/AccountMosaicRestrictionModificationTransaction'; -import { AccountOperationRestrictionModificationTransaction } from '../../src/model/transaction/AccountOperationRestrictionModificationTransaction'; +import { AccountMosaicRestrictionTransaction } from '../../src/model/transaction/AccountMosaicRestrictionTransaction'; +import { AccountOperationRestrictionTransaction } from '../../src/model/transaction/AccountOperationRestrictionTransaction'; import { AccountRestrictionModification } from '../../src/model/transaction/AccountRestrictionModification'; import { AccountRestrictionTransaction } from '../../src/model/transaction/AccountRestrictionTransaction'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; @@ -410,7 +410,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = addressModification.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionModificationTransaction) => { + listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionTransaction) => { expect(transaction.modifications, 'Modifications').not.to.be.undefined; expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; @@ -485,7 +485,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = addressModification.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AccountMosaicRestrictionModificationTransaction) => { + listener.confirmed(account.address).subscribe((transaction: AccountMosaicRestrictionTransaction) => { expect(transaction.modifications, 'Modifications').not.to.be.undefined; expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; @@ -560,7 +560,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = addressModification.signWith(account3, generationHash); - listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionModificationTransaction) => { + listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionTransaction) => { expect(transaction.modifications, 'Modifications').not.to.be.undefined; expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; diff --git a/src/infrastructure/QueryParams.ts b/src/infrastructure/QueryParams.ts index b1644cf2b3..ee41206d80 100644 --- a/src/infrastructure/QueryParams.ts +++ b/src/infrastructure/QueryParams.ts @@ -22,7 +22,6 @@ export enum Order { DESC = '-id', } - /** * The query params structure describes pagination params for requests. * diff --git a/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts b/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts index 452e4c30b7..bd355c6b94 100644 --- a/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts +++ b/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts @@ -45,7 +45,7 @@ export class Builder { modifications: any; constructor() { this.maxFee = [0, 0]; - this.type = TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS; + this.type = TransactionType.ACCOUNT_RESTRICTION_ADDRESS; } addFee(maxFee) { diff --git a/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts b/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts index edfed292ba..6973e8ccc4 100644 --- a/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts +++ b/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts @@ -45,7 +45,7 @@ export class Builder { modifications: any; constructor() { this.maxFee = [0, 0]; - this.type = TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION; + this.type = TransactionType.ACCOUNT_RESTRICTION_OPERATION; } addFee(maxFee) { diff --git a/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts b/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts index ec97bcc02e..da9338deb4 100644 --- a/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts +++ b/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts @@ -45,7 +45,7 @@ export class Builder { modifications: any; constructor() { this.maxFee = [0, 0]; - this.type = TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC; + this.type = TransactionType.ACCOUNT_RESTRICTION_MOSAIC; } addFee(maxFee) { diff --git a/src/infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder.ts b/src/infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder.ts new file mode 100644 index 0000000000..b8c508eb76 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder.ts @@ -0,0 +1,91 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountRestrictionModificationActionDto } from './AccountRestrictionModificationActionDto'; +import { AccountRestrictionModificationBuilder } from './AccountRestrictionModificationBuilder'; +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; + +/** Account address restriction modification. */ +export class AccountAddressRestrictionModificationBuilder extends AccountRestrictionModificationBuilder { + /** Address restriction value. */ + value: UnresolvedAddressDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + * @param value Address restriction value. + */ + public constructor(modificationAction: AccountRestrictionModificationActionDto, value: UnresolvedAddressDto) { + super(modificationAction); + this.value = value; + } + + /** + * Creates an instance of AccountAddressRestrictionModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountAddressRestrictionModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountAddressRestrictionModificationBuilder { + const byteArray = Array.from(payload); + const superObject = AccountRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const value = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, value.getSize()); + return new AccountAddressRestrictionModificationBuilder(superObject.modificationAction, value); + } + + /** + * Gets address restriction value. + * + * @return Address restriction value. + */ + public getValue(): UnresolvedAddressDto { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.value.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const valueBytes = this.value.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..fcc36e1509 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,114 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountAddressRestrictionModificationBuilder } from './AccountAddressRestrictionModificationBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for an account address restriction transaction. */ +export class AccountAddressRestrictionTransactionBodyBuilder { + /** Account restriction type. */ + restrictionType: AccountRestrictionTypeDto; + /** Account restriction modifications. */ + modifications: AccountAddressRestrictionModificationBuilder[]; + + /** + * Constructor. + * + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(restrictionType: AccountRestrictionTypeDto, modifications: AccountAddressRestrictionModificationBuilder[]) { + this.restrictionType = restrictionType; + this.modifications = modifications; + } + + /** + * Creates an instance of AccountAddressRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountAddressRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountAddressRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const restrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modificationsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modifications: AccountAddressRestrictionModificationBuilder[] = []; + for (let i = 0; i < modificationsCount; i++) { + const item = AccountAddressRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + modifications.push(item); + byteArray.splice(0, item.getSize()); + } + return new AccountAddressRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.restrictionType; + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountAddressRestrictionModificationBuilder[] { + return this.modifications; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // restrictionType + size += 1; // modificationsCount + this.modifications.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const restrictionTypeBytes = GeneratorUtils.uintToBuffer(this.restrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionTypeBytes); + const modificationsCountBytes = GeneratorUtils.uintToBuffer(this.modifications.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsCountBytes); + this.modifications.forEach((item) => { + const modificationsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..a20f98b7c6 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder.ts @@ -0,0 +1,116 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountAddressRestrictionModificationBuilder } from './AccountAddressRestrictionModificationBuilder'; +import { AccountAddressRestrictionTransactionBodyBuilder } from './AccountAddressRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account address restriction transaction. */ +export class AccountAddressRestrictionTransactionBuilder extends TransactionBuilder { + /** Account address restriction transaction body. */ + accountAddressRestrictionTransactionBody: AccountAddressRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountAddressRestrictionModificationBuilder[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.accountAddressRestrictionTransactionBody = new AccountAddressRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of AccountAddressRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountAddressRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountAddressRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountAddressRestrictionTransactionBody = AccountAddressRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountAddressRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountAddressRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountAddressRestrictionTransactionBody.restrictionType, accountAddressRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountAddressRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountAddressRestrictionModificationBuilder[] { + return this.accountAddressRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountAddressRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountAddressRestrictionTransactionBodyBytes = this.accountAddressRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountAddressRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountLinkActionDto.ts b/src/infrastructure/catbuffer/AccountLinkActionDto.ts new file mode 100644 index 0000000000..196ab88465 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountLinkActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of account link actions. */ +export enum AccountLinkActionDto { + /** Unlink account. */ + UNLINK = 0, + /** Link account. */ + LINK = 1, +} diff --git a/src/infrastructure/catbuffer/AccountLinkTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountLinkTransactionBodyBuilder.ts new file mode 100644 index 0000000000..bddb0b8579 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountLinkTransactionBodyBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountLinkActionDto } from './AccountLinkActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an account link transaction. */ +export class AccountLinkTransactionBodyBuilder { + /** Remote account public key. */ + remoteAccountPublicKey: KeyDto; + /** Account link action. */ + linkAction: AccountLinkActionDto; + + /** + * Constructor. + * + * @param remoteAccountPublicKey Remote account public key. + * @param linkAction Account link action. + */ + public constructor(remoteAccountPublicKey: KeyDto, linkAction: AccountLinkActionDto) { + this.remoteAccountPublicKey = remoteAccountPublicKey; + this.linkAction = linkAction; + } + + /** + * Creates an instance of AccountLinkTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountLinkTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountLinkTransactionBodyBuilder { + const byteArray = Array.from(payload); + const remoteAccountPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, remoteAccountPublicKey.getSize()); + const linkAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + return new AccountLinkTransactionBodyBuilder(remoteAccountPublicKey, linkAction); + } + + /** + * Gets remote account public key. + * + * @return Remote account public key. + */ + public getRemoteAccountPublicKey(): KeyDto { + return this.remoteAccountPublicKey; + } + + /** + * Gets account link action. + * + * @return Account link action. + */ + public getLinkAction(): AccountLinkActionDto { + return this.linkAction; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.remoteAccountPublicKey.getSize(); + size += 1; // linkAction + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const remoteAccountPublicKeyBytes = this.remoteAccountPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, remoteAccountPublicKeyBytes); + const linkActionBytes = GeneratorUtils.uintToBuffer(this.linkAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, linkActionBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountLinkTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountLinkTransactionBuilder.ts new file mode 100644 index 0000000000..13aecd9155 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountLinkTransactionBuilder.ts @@ -0,0 +1,113 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountLinkActionDto } from './AccountLinkActionDto'; +import { AccountLinkTransactionBodyBuilder } from './AccountLinkTransactionBodyBuilder'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account link transaction. */ +export class AccountLinkTransactionBuilder extends TransactionBuilder { + /** Account link transaction body. */ + accountLinkTransactionBody: AccountLinkTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param remoteAccountPublicKey Remote account public key. + * @param linkAction Account link action. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, remoteAccountPublicKey: KeyDto, linkAction: AccountLinkActionDto) { + super(signature, signer, version, type, fee, deadline); + this.accountLinkTransactionBody = new AccountLinkTransactionBodyBuilder(remoteAccountPublicKey, linkAction); + } + + /** + * Creates an instance of AccountLinkTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountLinkTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountLinkTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const accountLinkTransactionBody = AccountLinkTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountLinkTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountLinkTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountLinkTransactionBody.remoteAccountPublicKey, accountLinkTransactionBody.linkAction); + } + + /** + * Gets remote account public key. + * + * @return Remote account public key. + */ + public getRemoteAccountPublicKey(): KeyDto { + return this.accountLinkTransactionBody.getRemoteAccountPublicKey(); + } + + /** + * Gets account link action. + * + * @return Account link action. + */ + public getLinkAction(): AccountLinkActionDto { + return this.accountLinkTransactionBody.getLinkAction(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountLinkTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountLinkTransactionBodyBytes = this.accountLinkTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountLinkTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMetadataTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountMetadataTransactionBodyBuilder.ts new file mode 100644 index 0000000000..32353f22c9 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMetadataTransactionBodyBuilder.ts @@ -0,0 +1,147 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an account metadata transaction. */ +export class AccountMetadataTransactionBodyBuilder { + /** Metadata target public key. */ + targetPublicKey: KeyDto; + /** Metadata key scoped to source, target and type. */ + scopedMetadataKey: number[]; + /** Change in value size in bytes. */ + valueSizeDelta: number; + /** Difference between existing value and new value \note when there is no existing value, new value is same this value \note when there is an existing value, new value is calculated as xor(previous-value, value). */ + value: Uint8Array; + + /** + * Constructor. + * + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public constructor(targetPublicKey: KeyDto, scopedMetadataKey: number[], valueSizeDelta: number, value: Uint8Array) { + this.targetPublicKey = targetPublicKey; + this.scopedMetadataKey = scopedMetadataKey; + this.valueSizeDelta = valueSizeDelta; + this.value = value; + } + + /** + * Creates an instance of AccountMetadataTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMetadataTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMetadataTransactionBodyBuilder { + const byteArray = Array.from(payload); + const targetPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetPublicKey.getSize()); + const scopedMetadataKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const valueSizeDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const valueSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const value = GeneratorUtils.getBytes(Uint8Array.from(byteArray), valueSize); + byteArray.splice(0, valueSize); + return new AccountMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, valueSizeDelta, value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.targetPublicKey; + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.scopedMetadataKey; + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.valueSizeDelta; + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.targetPublicKey.getSize(); + size += 8; // scopedMetadataKey + size += 2; // valueSizeDelta + size += 2; // valueSize + size += this.value.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const targetPublicKeyBytes = this.targetPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetPublicKeyBytes); + const scopedMetadataKeyBytes = GeneratorUtils.uint64ToBuffer(this.getScopedMetadataKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, scopedMetadataKeyBytes); + const valueSizeDeltaBytes = GeneratorUtils.uintToBuffer(this.getValueSizeDelta(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeDeltaBytes); + const valueSizeBytes = GeneratorUtils.uintToBuffer(this.value.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.value); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..84daaea40a --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMetadataTransactionBuilder.ts @@ -0,0 +1,139 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMetadataTransactionBodyBuilder } from './AccountMetadataTransactionBodyBuilder'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account metadata transaction. */ +export class AccountMetadataTransactionBuilder extends TransactionBuilder { + /** Account metadata transaction body. */ + accountMetadataTransactionBody: AccountMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], valueSizeDelta: number, value: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.accountMetadataTransactionBody = new AccountMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, valueSizeDelta, value); + } + + /** + * Creates an instance of AccountMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const accountMetadataTransactionBody = AccountMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountMetadataTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountMetadataTransactionBody.targetPublicKey, accountMetadataTransactionBody.scopedMetadataKey, accountMetadataTransactionBody.valueSizeDelta, accountMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.accountMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.accountMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.accountMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.accountMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountMetadataTransactionBodyBytes = this.accountMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder.ts b/src/infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder.ts new file mode 100644 index 0000000000..29abdc38c8 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder.ts @@ -0,0 +1,91 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountRestrictionModificationActionDto } from './AccountRestrictionModificationActionDto'; +import { AccountRestrictionModificationBuilder } from './AccountRestrictionModificationBuilder'; +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Account mosaic restriction modification. */ +export class AccountMosaicRestrictionModificationBuilder extends AccountRestrictionModificationBuilder { + /** Mosaic identifier restriction value. */ + value: UnresolvedMosaicIdDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + * @param value Mosaic identifier restriction value. + */ + public constructor(modificationAction: AccountRestrictionModificationActionDto, value: UnresolvedMosaicIdDto) { + super(modificationAction); + this.value = value; + } + + /** + * Creates an instance of AccountMosaicRestrictionModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMosaicRestrictionModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMosaicRestrictionModificationBuilder { + const byteArray = Array.from(payload); + const superObject = AccountRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const value = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, value.getSize()); + return new AccountMosaicRestrictionModificationBuilder(superObject.modificationAction, value); + } + + /** + * Gets mosaic identifier restriction value. + * + * @return Mosaic identifier restriction value. + */ + public getValue(): UnresolvedMosaicIdDto { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.value.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const valueBytes = this.value.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..c094bdc1c2 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,114 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMosaicRestrictionModificationBuilder } from './AccountMosaicRestrictionModificationBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for an account mosaic restriction transaction. */ +export class AccountMosaicRestrictionTransactionBodyBuilder { + /** Account restriction type. */ + restrictionType: AccountRestrictionTypeDto; + /** Account restriction modifications. */ + modifications: AccountMosaicRestrictionModificationBuilder[]; + + /** + * Constructor. + * + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(restrictionType: AccountRestrictionTypeDto, modifications: AccountMosaicRestrictionModificationBuilder[]) { + this.restrictionType = restrictionType; + this.modifications = modifications; + } + + /** + * Creates an instance of AccountMosaicRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMosaicRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMosaicRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const restrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modificationsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modifications: AccountMosaicRestrictionModificationBuilder[] = []; + for (let i = 0; i < modificationsCount; i++) { + const item = AccountMosaicRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + modifications.push(item); + byteArray.splice(0, item.getSize()); + } + return new AccountMosaicRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.restrictionType; + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountMosaicRestrictionModificationBuilder[] { + return this.modifications; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // restrictionType + size += 1; // modificationsCount + this.modifications.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const restrictionTypeBytes = GeneratorUtils.uintToBuffer(this.restrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionTypeBytes); + const modificationsCountBytes = GeneratorUtils.uintToBuffer(this.modifications.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsCountBytes); + this.modifications.forEach((item) => { + const modificationsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..8b2f79a57e --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder.ts @@ -0,0 +1,116 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMosaicRestrictionModificationBuilder } from './AccountMosaicRestrictionModificationBuilder'; +import { AccountMosaicRestrictionTransactionBodyBuilder } from './AccountMosaicRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account mosaic restriction transaction. */ +export class AccountMosaicRestrictionTransactionBuilder extends TransactionBuilder { + /** Account mosaic restriction transaction body. */ + accountMosaicRestrictionTransactionBody: AccountMosaicRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountMosaicRestrictionModificationBuilder[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.accountMosaicRestrictionTransactionBody = new AccountMosaicRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of AccountMosaicRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMosaicRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMosaicRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountMosaicRestrictionTransactionBody = AccountMosaicRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountMosaicRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountMosaicRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountMosaicRestrictionTransactionBody.restrictionType, accountMosaicRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountMosaicRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountMosaicRestrictionModificationBuilder[] { + return this.accountMosaicRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountMosaicRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountMosaicRestrictionTransactionBodyBytes = this.accountMosaicRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountMosaicRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder.ts b/src/infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder.ts new file mode 100644 index 0000000000..669bfc4dce --- /dev/null +++ b/src/infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder.ts @@ -0,0 +1,91 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountRestrictionModificationActionDto } from './AccountRestrictionModificationActionDto'; +import { AccountRestrictionModificationBuilder } from './AccountRestrictionModificationBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Account operation restriction modification. */ +export class AccountOperationRestrictionModificationBuilder extends AccountRestrictionModificationBuilder { + /** Transaction type restriction value. */ + value: EntityTypeDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + * @param value Transaction type restriction value. + */ + public constructor(modificationAction: AccountRestrictionModificationActionDto, value: EntityTypeDto) { + super(modificationAction); + this.value = value; + } + + /** + * Creates an instance of AccountOperationRestrictionModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountOperationRestrictionModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountOperationRestrictionModificationBuilder { + const byteArray = Array.from(payload); + const superObject = AccountRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const value = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + return new AccountOperationRestrictionModificationBuilder(superObject.modificationAction, value); + } + + /** + * Gets transaction type restriction value. + * + * @return Transaction type restriction value. + */ + public getValue(): EntityTypeDto { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += 2; // value + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const valueBytes = GeneratorUtils.uintToBuffer(this.value, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..dd505b0b5f --- /dev/null +++ b/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,114 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountOperationRestrictionModificationBuilder } from './AccountOperationRestrictionModificationBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for an account operation restriction transaction. */ +export class AccountOperationRestrictionTransactionBodyBuilder { + /** Account restriction type. */ + restrictionType: AccountRestrictionTypeDto; + /** Account restriction modifications. */ + modifications: AccountOperationRestrictionModificationBuilder[]; + + /** + * Constructor. + * + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(restrictionType: AccountRestrictionTypeDto, modifications: AccountOperationRestrictionModificationBuilder[]) { + this.restrictionType = restrictionType; + this.modifications = modifications; + } + + /** + * Creates an instance of AccountOperationRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountOperationRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountOperationRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const restrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modificationsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modifications: AccountOperationRestrictionModificationBuilder[] = []; + for (let i = 0; i < modificationsCount; i++) { + const item = AccountOperationRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + modifications.push(item); + byteArray.splice(0, item.getSize()); + } + return new AccountOperationRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.restrictionType; + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountOperationRestrictionModificationBuilder[] { + return this.modifications; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // restrictionType + size += 1; // modificationsCount + this.modifications.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const restrictionTypeBytes = GeneratorUtils.uintToBuffer(this.restrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionTypeBytes); + const modificationsCountBytes = GeneratorUtils.uintToBuffer(this.modifications.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsCountBytes); + this.modifications.forEach((item) => { + const modificationsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..2f5795b732 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder.ts @@ -0,0 +1,116 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountOperationRestrictionModificationBuilder } from './AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBodyBuilder } from './AccountOperationRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account operation restriction transaction. */ +export class AccountOperationRestrictionTransactionBuilder extends TransactionBuilder { + /** Account operation restriction transaction body. */ + accountOperationRestrictionTransactionBody: AccountOperationRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountOperationRestrictionModificationBuilder[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.accountOperationRestrictionTransactionBody = new AccountOperationRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of AccountOperationRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountOperationRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountOperationRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountOperationRestrictionTransactionBody = AccountOperationRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountOperationRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountOperationRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountOperationRestrictionTransactionBody.restrictionType, accountOperationRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountOperationRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountOperationRestrictionModificationBuilder[] { + return this.accountOperationRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountOperationRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountOperationRestrictionTransactionBodyBytes = this.accountOperationRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountOperationRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountRestrictionModificationActionDto.ts b/src/infrastructure/catbuffer/AccountRestrictionModificationActionDto.ts new file mode 100644 index 0000000000..84da076601 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountRestrictionModificationActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of account restriction modification actions. */ +export enum AccountRestrictionModificationActionDto { + /** Remove account restriction value. */ + DEL = 0, + /** Add account restriction value. */ + ADD = 1, +} diff --git a/src/infrastructure/catbuffer/AccountRestrictionModificationBuilder.ts b/src/infrastructure/catbuffer/AccountRestrictionModificationBuilder.ts new file mode 100644 index 0000000000..286901d4c9 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountRestrictionModificationBuilder.ts @@ -0,0 +1,83 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountRestrictionModificationActionDto } from './AccountRestrictionModificationActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Account restriction basic modification. */ +export class AccountRestrictionModificationBuilder { + /** Modification action. */ + modificationAction: AccountRestrictionModificationActionDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + */ + public constructor(modificationAction: AccountRestrictionModificationActionDto) { + this.modificationAction = modificationAction; + } + + /** + * Creates an instance of AccountRestrictionModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountRestrictionModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountRestrictionModificationBuilder { + const byteArray = Array.from(payload); + const modificationAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + return new AccountRestrictionModificationBuilder(modificationAction); + } + + /** + * Gets modification action. + * + * @return Modification action. + */ + public getModificationAction(): AccountRestrictionModificationActionDto { + return this.modificationAction; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // modificationAction + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const modificationActionBytes = GeneratorUtils.uintToBuffer(this.modificationAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationActionBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountRestrictionTypeDto.ts b/src/infrastructure/catbuffer/AccountRestrictionTypeDto.ts new file mode 100644 index 0000000000..2d9cc2d061 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountRestrictionTypeDto.ts @@ -0,0 +1,35 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of account restriction types. */ +export enum AccountRestrictionTypeDto { + /** Restriction type is an address. */ + ADDRESS = 1, + /** Restriction type is a mosaic identifier. */ + MOSAIC_ID = 2, + /** Restriction type is a transaction type. */ + TRANSACTION_TYPE = 4, + /** Restriction is interpreted as outgoing. */ + OUTGOING = 64, + /** Restriction is interpreted as blocking operation. */ + BLOCK = 128, +} diff --git a/src/infrastructure/catbuffer/AddressAliasTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AddressAliasTransactionBodyBuilder.ts new file mode 100644 index 0000000000..0cdb182cc0 --- /dev/null +++ b/src/infrastructure/catbuffer/AddressAliasTransactionBodyBuilder.ts @@ -0,0 +1,121 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AddressDto } from './AddressDto'; +import { AliasActionDto } from './AliasActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for an address alias transaction. */ +export class AddressAliasTransactionBodyBuilder { + /** Alias action. */ + aliasAction: AliasActionDto; + /** Identifier of the namespace that will become an alias. */ + namespaceId: NamespaceIdDto; + /** Aliased address. */ + address: AddressDto; + + /** + * Constructor. + * + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param address Aliased address. + */ + public constructor(aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, address: AddressDto) { + this.aliasAction = aliasAction; + this.namespaceId = namespaceId; + this.address = address; + } + + /** + * Creates an instance of AddressAliasTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AddressAliasTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AddressAliasTransactionBodyBuilder { + const byteArray = Array.from(payload); + const aliasAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const namespaceId = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceId.getSize()); + const address = AddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, address.getSize()); + return new AddressAliasTransactionBodyBuilder(aliasAction, namespaceId, address); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.aliasAction; + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.namespaceId; + } + + /** + * Gets aliased address. + * + * @return Aliased address. + */ + public getAddress(): AddressDto { + return this.address; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // aliasAction + size += this.namespaceId.getSize(); + size += this.address.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const aliasActionBytes = GeneratorUtils.uintToBuffer(this.aliasAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, aliasActionBytes); + const namespaceIdBytes = this.namespaceId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceIdBytes); + const addressBytes = this.address.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, addressBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AddressAliasTransactionBuilder.ts b/src/infrastructure/catbuffer/AddressAliasTransactionBuilder.ts new file mode 100644 index 0000000000..a1b64702cc --- /dev/null +++ b/src/infrastructure/catbuffer/AddressAliasTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; +import { AddressDto } from './AddressDto'; +import { AliasActionDto } from './AliasActionDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded address alias transaction. */ +export class AddressAliasTransactionBuilder extends TransactionBuilder { + /** Address alias transaction body. */ + addressAliasTransactionBody: AddressAliasTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param address Aliased address. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, address: AddressDto) { + super(signature, signer, version, type, fee, deadline); + this.addressAliasTransactionBody = new AddressAliasTransactionBodyBuilder(aliasAction, namespaceId, address); + } + + /** + * Creates an instance of AddressAliasTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AddressAliasTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AddressAliasTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const addressAliasTransactionBody = AddressAliasTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, addressAliasTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AddressAliasTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, addressAliasTransactionBody.aliasAction, addressAliasTransactionBody.namespaceId, addressAliasTransactionBody.address); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.addressAliasTransactionBody.getAliasAction(); + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.addressAliasTransactionBody.getNamespaceId(); + } + + /** + * Gets aliased address. + * + * @return Aliased address. + */ + public getAddress(): AddressDto { + return this.addressAliasTransactionBody.getAddress(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.addressAliasTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const addressAliasTransactionBodyBytes = this.addressAliasTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, addressAliasTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AddressDto.ts b/src/infrastructure/catbuffer/AddressDto.ts new file mode 100644 index 0000000000..16214f53dc --- /dev/null +++ b/src/infrastructure/catbuffer/AddressDto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Address. */ +export class AddressDto { + /** Address. */ + address: Uint8Array; + + /** + * Constructor. + * + * @param address Address. + */ + constructor(address: Uint8Array) { + this.address = address; + } + + /** + * Creates an instance of AddressDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AddressDto. + */ + public static loadFromBinary(payload: Uint8Array): AddressDto { + const byteArray = Array.from(payload); + const address = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 25); + byteArray.splice(0, 25); + return new AddressDto(address); + } + + /** + * Gets Address. + * + * @return Address. + */ + public getAddress(): Uint8Array { + return this.address; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 25; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.address); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AliasActionDto.ts b/src/infrastructure/catbuffer/AliasActionDto.ts new file mode 100644 index 0000000000..58cd769ca8 --- /dev/null +++ b/src/infrastructure/catbuffer/AliasActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of alias actions. */ +export enum AliasActionDto { + /** Unlink alias. */ + UNLINK = 0, + /** Link alias. */ + LINK = 1, +} diff --git a/src/infrastructure/catbuffer/AmountDto.ts b/src/infrastructure/catbuffer/AmountDto.ts new file mode 100644 index 0000000000..b1e3c31731 --- /dev/null +++ b/src/infrastructure/catbuffer/AmountDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Amount. */ +export class AmountDto { + /** Amount. */ + amount: number[]; + + /** + * Constructor. + * + * @param amount Amount. + */ + constructor(amount: number[]) { + this.amount = amount; + } + + /** + * Creates an instance of AmountDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AmountDto. + */ + public static loadFromBinary(payload: Uint8Array): AmountDto { + const byteArray = Array.from(payload); + const amount = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new AmountDto(amount); + } + + /** + * Gets Amount. + * + * @return Amount. + */ + public getAmount(): number[] { + return this.amount; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const amountBytes = GeneratorUtils.uint64ToBuffer(this.getAmount()); + newArray = GeneratorUtils.concatTypedArrays(newArray, amountBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/BlockDurationDto.ts b/src/infrastructure/catbuffer/BlockDurationDto.ts new file mode 100644 index 0000000000..dfc232ebdc --- /dev/null +++ b/src/infrastructure/catbuffer/BlockDurationDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Block duration. */ +export class BlockDurationDto { + /** Block duration. */ + blockDuration: number[]; + + /** + * Constructor. + * + * @param blockDuration Block duration. + */ + constructor(blockDuration: number[]) { + this.blockDuration = blockDuration; + } + + /** + * Creates an instance of BlockDurationDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of BlockDurationDto. + */ + public static loadFromBinary(payload: Uint8Array): BlockDurationDto { + const byteArray = Array.from(payload); + const blockDuration = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new BlockDurationDto(blockDuration); + } + + /** + * Gets Block duration. + * + * @return Block duration. + */ + public getBlockDuration(): number[] { + return this.blockDuration; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const blockDurationBytes = GeneratorUtils.uint64ToBuffer(this.getBlockDuration()); + newArray = GeneratorUtils.concatTypedArrays(newArray, blockDurationBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/CosignatoryModificationActionDto.ts b/src/infrastructure/catbuffer/CosignatoryModificationActionDto.ts new file mode 100644 index 0000000000..c428422d9a --- /dev/null +++ b/src/infrastructure/catbuffer/CosignatoryModificationActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of cosignatory modification actions. */ +export enum CosignatoryModificationActionDto { + /** Remove cosignatory. */ + DEL = 0, + /** Add cosignatory. */ + ADD = 1, +} diff --git a/src/infrastructure/catbuffer/CosignatoryModificationBuilder.ts b/src/infrastructure/catbuffer/CosignatoryModificationBuilder.ts new file mode 100644 index 0000000000..8413b779db --- /dev/null +++ b/src/infrastructure/catbuffer/CosignatoryModificationBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { CosignatoryModificationActionDto } from './CosignatoryModificationActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for a cosignatory modification. */ +export class CosignatoryModificationBuilder { + /** Modification action. */ + modificationAction: CosignatoryModificationActionDto; + /** Cosignatory account public key. */ + cosignatoryPublicKey: KeyDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + * @param cosignatoryPublicKey Cosignatory account public key. + */ + public constructor(modificationAction: CosignatoryModificationActionDto, cosignatoryPublicKey: KeyDto) { + this.modificationAction = modificationAction; + this.cosignatoryPublicKey = cosignatoryPublicKey; + } + + /** + * Creates an instance of CosignatoryModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of CosignatoryModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): CosignatoryModificationBuilder { + const byteArray = Array.from(payload); + const modificationAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const cosignatoryPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, cosignatoryPublicKey.getSize()); + return new CosignatoryModificationBuilder(modificationAction, cosignatoryPublicKey); + } + + /** + * Gets modification action. + * + * @return Modification action. + */ + public getModificationAction(): CosignatoryModificationActionDto { + return this.modificationAction; + } + + /** + * Gets cosignatory account public key. + * + * @return Cosignatory account public key. + */ + public getCosignatoryPublicKey(): KeyDto { + return this.cosignatoryPublicKey; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // modificationAction + size += this.cosignatoryPublicKey.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const modificationActionBytes = GeneratorUtils.uintToBuffer(this.modificationAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationActionBytes); + const cosignatoryPublicKeyBytes = this.cosignatoryPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, cosignatoryPublicKeyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..af18bf390d --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder.ts @@ -0,0 +1,110 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountAddressRestrictionModificationBuilder } from './AccountAddressRestrictionModificationBuilder'; +import { AccountAddressRestrictionTransactionBodyBuilder } from './AccountAddressRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account address restriction transaction. */ +export class EmbeddedAccountAddressRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account address restriction transaction body. */ + accountAddressRestrictionTransactionBody: AccountAddressRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountAddressRestrictionModificationBuilder[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.accountAddressRestrictionTransactionBody = new AccountAddressRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of EmbeddedAccountAddressRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountAddressRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountAddressRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountAddressRestrictionTransactionBody = AccountAddressRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountAddressRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountAddressRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountAddressRestrictionTransactionBody.restrictionType, accountAddressRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountAddressRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountAddressRestrictionModificationBuilder[] { + return this.accountAddressRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountAddressRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountAddressRestrictionTransactionBodyBytes = this.accountAddressRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountAddressRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder.ts new file mode 100644 index 0000000000..c2219f36bb --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder.ts @@ -0,0 +1,107 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountLinkActionDto } from './AccountLinkActionDto'; +import { AccountLinkTransactionBodyBuilder } from './AccountLinkTransactionBodyBuilder'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account link transaction. */ +export class EmbeddedAccountLinkTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account link transaction body. */ + accountLinkTransactionBody: AccountLinkTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param remoteAccountPublicKey Remote account public key. + * @param linkAction Account link action. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, remoteAccountPublicKey: KeyDto, linkAction: AccountLinkActionDto) { + super(signer, version, type); + this.accountLinkTransactionBody = new AccountLinkTransactionBodyBuilder(remoteAccountPublicKey, linkAction); + } + + /** + * Creates an instance of EmbeddedAccountLinkTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountLinkTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountLinkTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const accountLinkTransactionBody = AccountLinkTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountLinkTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountLinkTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountLinkTransactionBody.remoteAccountPublicKey, accountLinkTransactionBody.linkAction); + } + + /** + * Gets remote account public key. + * + * @return Remote account public key. + */ + public getRemoteAccountPublicKey(): KeyDto { + return this.accountLinkTransactionBody.getRemoteAccountPublicKey(); + } + + /** + * Gets account link action. + * + * @return Account link action. + */ + public getLinkAction(): AccountLinkActionDto { + return this.accountLinkTransactionBody.getLinkAction(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountLinkTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountLinkTransactionBodyBytes = this.accountLinkTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountLinkTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..ec9f33ca7f --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder.ts @@ -0,0 +1,133 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMetadataTransactionBodyBuilder } from './AccountMetadataTransactionBodyBuilder'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account metadata transaction. */ +export class EmbeddedAccountMetadataTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account metadata transaction body. */ + accountMetadataTransactionBody: AccountMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], valueSizeDelta: number, value: Uint8Array) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.accountMetadataTransactionBody = new AccountMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, valueSizeDelta, value); + } + + /** + * Creates an instance of EmbeddedAccountMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const accountMetadataTransactionBody = AccountMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountMetadataTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountMetadataTransactionBody.targetPublicKey, accountMetadataTransactionBody.scopedMetadataKey, accountMetadataTransactionBody.valueSizeDelta, accountMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.accountMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.accountMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.accountMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.accountMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountMetadataTransactionBodyBytes = this.accountMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..d97d085545 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder.ts @@ -0,0 +1,110 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMosaicRestrictionModificationBuilder } from './AccountMosaicRestrictionModificationBuilder'; +import { AccountMosaicRestrictionTransactionBodyBuilder } from './AccountMosaicRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account mosaic restriction transaction. */ +export class EmbeddedAccountMosaicRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account mosaic restriction transaction body. */ + accountMosaicRestrictionTransactionBody: AccountMosaicRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountMosaicRestrictionModificationBuilder[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.accountMosaicRestrictionTransactionBody = new AccountMosaicRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of EmbeddedAccountMosaicRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountMosaicRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountMosaicRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountMosaicRestrictionTransactionBody = AccountMosaicRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountMosaicRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountMosaicRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountMosaicRestrictionTransactionBody.restrictionType, accountMosaicRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountMosaicRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountMosaicRestrictionModificationBuilder[] { + return this.accountMosaicRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountMosaicRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountMosaicRestrictionTransactionBodyBytes = this.accountMosaicRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountMosaicRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..c4de2fb15c --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder.ts @@ -0,0 +1,110 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountOperationRestrictionModificationBuilder } from './AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBodyBuilder } from './AccountOperationRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account operation restriction transaction. */ +export class EmbeddedAccountOperationRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account operation restriction transaction body. */ + accountOperationRestrictionTransactionBody: AccountOperationRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountOperationRestrictionModificationBuilder[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.accountOperationRestrictionTransactionBody = new AccountOperationRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of EmbeddedAccountOperationRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountOperationRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountOperationRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountOperationRestrictionTransactionBody = AccountOperationRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountOperationRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountOperationRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountOperationRestrictionTransactionBody.restrictionType, accountOperationRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountOperationRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountOperationRestrictionModificationBuilder[] { + return this.accountOperationRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountOperationRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountOperationRestrictionTransactionBodyBytes = this.accountOperationRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountOperationRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder.ts new file mode 100644 index 0000000000..7532500571 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder.ts @@ -0,0 +1,119 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; +import { AddressDto } from './AddressDto'; +import { AliasActionDto } from './AliasActionDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for an embedded address alias transaction. */ +export class EmbeddedAddressAliasTransactionBuilder extends EmbeddedTransactionBuilder { + /** Address alias transaction body. */ + addressAliasTransactionBody: AddressAliasTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param address Aliased address. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, address: AddressDto) { + super(signer, version, type); + this.addressAliasTransactionBody = new AddressAliasTransactionBodyBuilder(aliasAction, namespaceId, address); + } + + /** + * Creates an instance of EmbeddedAddressAliasTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAddressAliasTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAddressAliasTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const addressAliasTransactionBody = AddressAliasTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, addressAliasTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAddressAliasTransactionBuilder(superObject.signer, superObject.version, superObject.type, addressAliasTransactionBody.aliasAction, addressAliasTransactionBody.namespaceId, addressAliasTransactionBody.address); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.addressAliasTransactionBody.getAliasAction(); + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.addressAliasTransactionBody.getNamespaceId(); + } + + /** + * Gets aliased address. + * + * @return Aliased address. + */ + public getAddress(): AddressDto { + return this.addressAliasTransactionBody.getAddress(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.addressAliasTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const addressAliasTransactionBodyBytes = this.addressAliasTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, addressAliasTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder.ts new file mode 100644 index 0000000000..e91a7e98b4 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder.ts @@ -0,0 +1,119 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { HashLockTransactionBodyBuilder } from './HashLockTransactionBodyBuilder'; +import { KeyDto } from './KeyDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for an embedded hash lock transaction. */ +export class EmbeddedHashLockTransactionBuilder extends EmbeddedTransactionBuilder { + /** Hash lock transaction body. */ + hashLockTransactionBody: HashLockTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaic Lock mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hash Lock hash. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hash: Hash256Dto) { + super(signer, version, type); + this.hashLockTransactionBody = new HashLockTransactionBodyBuilder(mosaic, duration, hash); + } + + /** + * Creates an instance of EmbeddedHashLockTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedHashLockTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedHashLockTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const hashLockTransactionBody = HashLockTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, hashLockTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedHashLockTransactionBuilder(superObject.signer, superObject.version, superObject.type, hashLockTransactionBody.mosaic, hashLockTransactionBody.duration, hashLockTransactionBody.hash); + } + + /** + * Gets lock mosaic. + * + * @return Lock mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.hashLockTransactionBody.getMosaic(); + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.hashLockTransactionBody.getDuration(); + } + + /** + * Gets lock hash. + * + * @return Lock hash. + */ + public getHash(): Hash256Dto { + return this.hashLockTransactionBody.getHash(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.hashLockTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const hashLockTransactionBodyBytes = this.hashLockTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashLockTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..ead5de2075 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder.ts @@ -0,0 +1,140 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicAddressRestrictionTransactionBodyBuilder } from './MosaicAddressRestrictionTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an embedded mosaic address restriction transaction. */ +export class EmbeddedMosaicAddressRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic address restriction transaction body. */ + mosaicAddressRestrictionTransactionBody: MosaicAddressRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaicId Identifier of the mosaic to which the restriction applies. + * @param restrictionKey Restriction key. + * @param targetAddress Address being restricted. + * @param previousRestrictionValue Previous restriction value. + * @param newRestrictionValue New restriction value. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], targetAddress: UnresolvedAddressDto, previousRestrictionValue: number[], newRestrictionValue: number[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.mosaicAddressRestrictionTransactionBody = new MosaicAddressRestrictionTransactionBodyBuilder(mosaicId, restrictionKey, targetAddress, previousRestrictionValue, newRestrictionValue); + } + + /** + * Creates an instance of EmbeddedMosaicAddressRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicAddressRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicAddressRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicAddressRestrictionTransactionBody = MosaicAddressRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicAddressRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicAddressRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicAddressRestrictionTransactionBody.mosaicId, mosaicAddressRestrictionTransactionBody.restrictionKey, mosaicAddressRestrictionTransactionBody.targetAddress, mosaicAddressRestrictionTransactionBody.previousRestrictionValue, mosaicAddressRestrictionTransactionBody.newRestrictionValue); + } + + /** + * Gets identifier of the mosaic to which the restriction applies. + * + * @return Identifier of the mosaic to which the restriction applies. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicAddressRestrictionTransactionBody.getMosaicId(); + } + + /** + * Gets restriction key. + * + * @return Restriction key. + */ + public getRestrictionKey(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getRestrictionKey(); + } + + /** + * Gets address being restricted. + * + * @return Address being restricted. + */ + public getTargetAddress(): UnresolvedAddressDto { + return this.mosaicAddressRestrictionTransactionBody.getTargetAddress(); + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getPreviousRestrictionValue(); + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getNewRestrictionValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicAddressRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicAddressRestrictionTransactionBodyBytes = this.mosaicAddressRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicAddressRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder.ts new file mode 100644 index 0000000000..635b59964f --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder.ts @@ -0,0 +1,119 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AliasActionDto } from './AliasActionDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicAliasTransactionBodyBuilder } from './MosaicAliasTransactionBodyBuilder'; +import { MosaicIdDto } from './MosaicIdDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for an embedded mosaic alias transaction. */ +export class EmbeddedMosaicAliasTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic alias transaction body. */ + mosaicAliasTransactionBody: MosaicAliasTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param mosaicId Aliased mosaic identifier. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, mosaicId: MosaicIdDto) { + super(signer, version, type); + this.mosaicAliasTransactionBody = new MosaicAliasTransactionBodyBuilder(aliasAction, namespaceId, mosaicId); + } + + /** + * Creates an instance of EmbeddedMosaicAliasTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicAliasTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicAliasTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const mosaicAliasTransactionBody = MosaicAliasTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicAliasTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicAliasTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicAliasTransactionBody.aliasAction, mosaicAliasTransactionBody.namespaceId, mosaicAliasTransactionBody.mosaicId); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.mosaicAliasTransactionBody.getAliasAction(); + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.mosaicAliasTransactionBody.getNamespaceId(); + } + + /** + * Gets aliased mosaic identifier. + * + * @return Aliased mosaic identifier. + */ + public getMosaicId(): MosaicIdDto { + return this.mosaicAliasTransactionBody.getMosaicId(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicAliasTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicAliasTransactionBodyBytes = this.mosaicAliasTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicAliasTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder.ts new file mode 100644 index 0000000000..ad46a89813 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder.ts @@ -0,0 +1,141 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicDefinitionTransactionBodyBuilder } from './MosaicDefinitionTransactionBodyBuilder'; +import { MosaicIdDto } from './MosaicIdDto'; +import { MosaicNonceDto } from './MosaicNonceDto'; + +/** Binary layout for an embedded mosaic definition transaction. */ +export class EmbeddedMosaicDefinitionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic definition transaction body. */ + mosaicDefinitionTransactionBody: MosaicDefinitionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param nonce Mosaic nonce. + * @param id Mosaic identifier. + * @param flags Mosaic flags. + * @param divisibility Mosaic divisibility. + * @param duration Mosaic duration. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, nonce: MosaicNonceDto, id: MosaicIdDto, flags: number, divisibility: number, duration: BlockDurationDto) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.mosaicDefinitionTransactionBody = new MosaicDefinitionTransactionBodyBuilder(nonce, id, flags, divisibility, duration); + } + + /** + * Creates an instance of EmbeddedMosaicDefinitionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicDefinitionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicDefinitionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicDefinitionTransactionBody = MosaicDefinitionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicDefinitionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicDefinitionTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicDefinitionTransactionBody.nonce, mosaicDefinitionTransactionBody.id, mosaicDefinitionTransactionBody.flags, mosaicDefinitionTransactionBody.divisibility, mosaicDefinitionTransactionBody.duration); + } + + /** + * Gets mosaic nonce. + * + * @return Mosaic nonce. + */ + public getNonce(): MosaicNonceDto { + return this.mosaicDefinitionTransactionBody.getNonce(); + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getId(): MosaicIdDto { + return this.mosaicDefinitionTransactionBody.getId(); + } + + /** + * Gets mosaic flags. + * + * @return Mosaic flags. + */ + public getFlags(): number { + return this.mosaicDefinitionTransactionBody.getFlags(); + } + + /** + * Gets mosaic divisibility. + * + * @return Mosaic divisibility. + */ + public getDivisibility(): number { + return this.mosaicDefinitionTransactionBody.getDivisibility(); + } + + /** + * Gets mosaic duration. + * + * @return Mosaic duration. + */ + public getDuration(): BlockDurationDto { + return this.mosaicDefinitionTransactionBody.getDuration(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicDefinitionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicDefinitionTransactionBodyBytes = this.mosaicDefinitionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicDefinitionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..224df49b31 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder.ts @@ -0,0 +1,160 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicGlobalRestrictionTransactionBodyBuilder } from './MosaicGlobalRestrictionTransactionBodyBuilder'; +import { MosaicRestrictionTypeDto } from './MosaicRestrictionTypeDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an embedded mosaic global restriction transaction. */ +export class EmbeddedMosaicGlobalRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic global restriction transaction body. */ + mosaicGlobalRestrictionTransactionBody: MosaicGlobalRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaicId Identifier of the mosaic being restricted. + * @param referenceMosaicId Identifier of the mosaic providing the restriction key. + * @param restrictionKey Restriction key relative to the reference mosaic identifier. + * @param previousRestrictionValue Previous restriction value. + * @param previousRestrictionType Previous restriction type. + * @param newRestrictionValue New restriction value. + * @param newRestrictionType New restriction type. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaicId: UnresolvedMosaicIdDto, referenceMosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], previousRestrictionValue: number[], previousRestrictionType: MosaicRestrictionTypeDto, newRestrictionValue: number[], newRestrictionType: MosaicRestrictionTypeDto) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.mosaicGlobalRestrictionTransactionBody = new MosaicGlobalRestrictionTransactionBodyBuilder(mosaicId, referenceMosaicId, restrictionKey, previousRestrictionValue, previousRestrictionType, newRestrictionValue, newRestrictionType); + } + + /** + * Creates an instance of EmbeddedMosaicGlobalRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicGlobalRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicGlobalRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicGlobalRestrictionTransactionBody = MosaicGlobalRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicGlobalRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicGlobalRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicGlobalRestrictionTransactionBody.mosaicId, mosaicGlobalRestrictionTransactionBody.referenceMosaicId, mosaicGlobalRestrictionTransactionBody.restrictionKey, mosaicGlobalRestrictionTransactionBody.previousRestrictionValue, mosaicGlobalRestrictionTransactionBody.previousRestrictionType, mosaicGlobalRestrictionTransactionBody.newRestrictionValue, mosaicGlobalRestrictionTransactionBody.newRestrictionType); + } + + /** + * Gets identifier of the mosaic being restricted. + * + * @return Identifier of the mosaic being restricted. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicGlobalRestrictionTransactionBody.getMosaicId(); + } + + /** + * Gets identifier of the mosaic providing the restriction key. + * + * @return Identifier of the mosaic providing the restriction key. + */ + public getReferenceMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicGlobalRestrictionTransactionBody.getReferenceMosaicId(); + } + + /** + * Gets restriction key relative to the reference mosaic identifier. + * + * @return Restriction key relative to the reference mosaic identifier. + */ + public getRestrictionKey(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getRestrictionKey(); + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getPreviousRestrictionValue(); + } + + /** + * Gets previous restriction type. + * + * @return Previous restriction type. + */ + public getPreviousRestrictionType(): MosaicRestrictionTypeDto { + return this.mosaicGlobalRestrictionTransactionBody.getPreviousRestrictionType(); + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getNewRestrictionValue(); + } + + /** + * Gets new restriction type. + * + * @return New restriction type. + */ + public getNewRestrictionType(): MosaicRestrictionTypeDto { + return this.mosaicGlobalRestrictionTransactionBody.getNewRestrictionType(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicGlobalRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicGlobalRestrictionTransactionBodyBytes = this.mosaicGlobalRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicGlobalRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..378bec0bf3 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder.ts @@ -0,0 +1,144 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicMetadataTransactionBodyBuilder } from './MosaicMetadataTransactionBodyBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an embedded mosaic metadata transaction. */ +export class EmbeddedMosaicMetadataTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic metadata transaction body. */ + mosaicMetadataTransactionBody: MosaicMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetMosaicId Target mosaic identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], targetMosaicId: UnresolvedMosaicIdDto, valueSizeDelta: number, value: Uint8Array) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.mosaicMetadataTransactionBody = new MosaicMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetMosaicId, valueSizeDelta, value); + } + + /** + * Creates an instance of EmbeddedMosaicMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const mosaicMetadataTransactionBody = MosaicMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicMetadataTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicMetadataTransactionBody.targetPublicKey, mosaicMetadataTransactionBody.scopedMetadataKey, mosaicMetadataTransactionBody.targetMosaicId, mosaicMetadataTransactionBody.valueSizeDelta, mosaicMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.mosaicMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.mosaicMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets target mosaic identifier. + * + * @return Target mosaic identifier. + */ + public getTargetMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicMetadataTransactionBody.getTargetMosaicId(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.mosaicMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.mosaicMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicMetadataTransactionBodyBytes = this.mosaicMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder.ts new file mode 100644 index 0000000000..6f66b59522 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder.ts @@ -0,0 +1,120 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicSupplyChangeActionDto } from './MosaicSupplyChangeActionDto'; +import { MosaicSupplyChangeTransactionBodyBuilder } from './MosaicSupplyChangeTransactionBodyBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an embedded mosaic supply change transaction. */ +export class EmbeddedMosaicSupplyChangeTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic supply change transaction body. */ + mosaicSupplyChangeTransactionBody: MosaicSupplyChangeTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaicId Affected mosaic identifier. + * @param action Supply change action. + * @param delta Change amount. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaicId: UnresolvedMosaicIdDto, action: MosaicSupplyChangeActionDto, delta: AmountDto) { + super(signer, version, type); + this.mosaicSupplyChangeTransactionBody = new MosaicSupplyChangeTransactionBodyBuilder(mosaicId, action, delta); + } + + /** + * Creates an instance of EmbeddedMosaicSupplyChangeTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicSupplyChangeTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicSupplyChangeTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicSupplyChangeTransactionBody = MosaicSupplyChangeTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicSupplyChangeTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicSupplyChangeTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicSupplyChangeTransactionBody.mosaicId, mosaicSupplyChangeTransactionBody.action, mosaicSupplyChangeTransactionBody.delta); + } + + /** + * Gets affected mosaic identifier. + * + * @return Affected mosaic identifier. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicSupplyChangeTransactionBody.getMosaicId(); + } + + /** + * Gets supply change action. + * + * @return Supply change action. + */ + public getAction(): MosaicSupplyChangeActionDto { + return this.mosaicSupplyChangeTransactionBody.getAction(); + } + + /** + * Gets change amount. + * + * @return Change amount. + */ + public getDelta(): AmountDto { + return this.mosaicSupplyChangeTransactionBody.getDelta(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicSupplyChangeTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicSupplyChangeTransactionBodyBytes = this.mosaicSupplyChangeTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicSupplyChangeTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder.ts new file mode 100644 index 0000000000..b2de331994 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder.ts @@ -0,0 +1,119 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { CosignatoryModificationBuilder } from './CosignatoryModificationBuilder'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MultisigAccountModificationTransactionBodyBuilder } from './MultisigAccountModificationTransactionBodyBuilder'; + +/** Binary layout for an embedded multisig account modification transaction. */ +export class EmbeddedMultisigAccountModificationTransactionBuilder extends EmbeddedTransactionBuilder { + /** Multisig account modification transaction body. */ + multisigAccountModificationTransactionBody: MultisigAccountModificationTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param minRemovalDelta Relative change of the minimal number of cosignatories required when removing an account. + * @param minApprovalDelta Relative change of the minimal number of cosignatories required when approving a transaction. + * @param modifications Attached cosignatory modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, minRemovalDelta: number, minApprovalDelta: number, modifications: CosignatoryModificationBuilder[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.multisigAccountModificationTransactionBody = new MultisigAccountModificationTransactionBodyBuilder(minRemovalDelta, minApprovalDelta, modifications); + } + + /** + * Creates an instance of EmbeddedMultisigAccountModificationTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMultisigAccountModificationTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMultisigAccountModificationTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const multisigAccountModificationTransactionBody = MultisigAccountModificationTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, multisigAccountModificationTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMultisigAccountModificationTransactionBuilder(superObject.signer, superObject.version, superObject.type, multisigAccountModificationTransactionBody.minRemovalDelta, multisigAccountModificationTransactionBody.minApprovalDelta, multisigAccountModificationTransactionBody.modifications); + } + + /** + * Gets relative change of the minimal number of cosignatories required when removing an account. + * + * @return Relative change of the minimal number of cosignatories required when removing an account. + */ + public getMinRemovalDelta(): number { + return this.multisigAccountModificationTransactionBody.getMinRemovalDelta(); + } + + /** + * Gets relative change of the minimal number of cosignatories required when approving a transaction. + * + * @return Relative change of the minimal number of cosignatories required when approving a transaction. + */ + public getMinApprovalDelta(): number { + return this.multisigAccountModificationTransactionBody.getMinApprovalDelta(); + } + + /** + * Gets attached cosignatory modifications. + * + * @return Attached cosignatory modifications. + */ + public getModifications(): CosignatoryModificationBuilder[] { + return this.multisigAccountModificationTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.multisigAccountModificationTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const multisigAccountModificationTransactionBodyBytes = this.multisigAccountModificationTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, multisigAccountModificationTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..1d4bbe606c --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder.ts @@ -0,0 +1,145 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceMetadataTransactionBodyBuilder } from './NamespaceMetadataTransactionBodyBuilder'; + +/** Binary layout for an embedded namespace metadata transaction. */ +export class EmbeddedNamespaceMetadataTransactionBuilder extends EmbeddedTransactionBuilder { + /** Namespace metadata transaction body. */ + namespaceMetadataTransactionBody: NamespaceMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetNamespaceId Target namespace identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], targetNamespaceId: NamespaceIdDto, valueSizeDelta: number, value: Uint8Array) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.namespaceMetadataTransactionBody = new NamespaceMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetNamespaceId, valueSizeDelta, value); + } + + /** + * Creates an instance of EmbeddedNamespaceMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedNamespaceMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedNamespaceMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const namespaceMetadataTransactionBody = NamespaceMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedNamespaceMetadataTransactionBuilder(superObject.signer, superObject.version, superObject.type, namespaceMetadataTransactionBody.targetPublicKey, namespaceMetadataTransactionBody.scopedMetadataKey, namespaceMetadataTransactionBody.targetNamespaceId, namespaceMetadataTransactionBody.valueSizeDelta, namespaceMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.namespaceMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.namespaceMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets target namespace identifier. + * + * @return Target namespace identifier. + */ + public getTargetNamespaceId(): NamespaceIdDto { + return this.namespaceMetadataTransactionBody.getTargetNamespaceId(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.namespaceMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.namespaceMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.namespaceMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const namespaceMetadataTransactionBodyBytes = this.namespaceMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder.ts new file mode 100644 index 0000000000..29d51b3fb1 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder.ts @@ -0,0 +1,143 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceRegistrationTransactionBodyBuilder } from './NamespaceRegistrationTransactionBodyBuilder'; +import { NamespaceRegistrationTypeDto } from './NamespaceRegistrationTypeDto'; + +/** Binary layout for an embedded namespace registration transaction. */ +export class EmbeddedNamespaceRegistrationTransactionBuilder extends EmbeddedTransactionBuilder { + /** Namespace registration transaction body. */ + namespaceRegistrationTransactionBody: NamespaceRegistrationTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param duration Namespace duration. + * @param parentId Parent namespace identifier. + * @param id Namespace identifier. + * @param name Namespace name. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, id: NamespaceIdDto, name: Uint8Array, duration?: BlockDurationDto, parentId?: NamespaceIdDto) { + super(signer, version, type); + if ((duration && parentId) || (!duration && !parentId)) { + throw new Error('Invalid conditional parameters'); + } + // tslint:disable-next-line: max-line-length + this.namespaceRegistrationTransactionBody = new NamespaceRegistrationTransactionBodyBuilder(id, name, duration, parentId); + } + + /** + * Creates an instance of EmbeddedNamespaceRegistrationTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedNamespaceRegistrationTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedNamespaceRegistrationTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const namespaceRegistrationTransactionBody = NamespaceRegistrationTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceRegistrationTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedNamespaceRegistrationTransactionBuilder(superObject.signer, superObject.version, superObject.type, namespaceRegistrationTransactionBody.id, namespaceRegistrationTransactionBody.name, namespaceRegistrationTransactionBody.duration, namespaceRegistrationTransactionBody.parentId); + } + + /** + * Gets namespace registration type. + * + * @return Namespace registration type. + */ + public getRegistrationType(): NamespaceRegistrationTypeDto { + return this.namespaceRegistrationTransactionBody.getRegistrationType(); + } + + /** + * Gets namespace duration. + * + * @return Namespace duration. + */ + public getDuration(): BlockDurationDto | undefined { + return this.namespaceRegistrationTransactionBody.getDuration(); + } + + /** + * Gets parent namespace identifier. + * + * @return Parent namespace identifier. + */ + public getParentId(): NamespaceIdDto | undefined { + return this.namespaceRegistrationTransactionBody.getParentId(); + } + + /** + * Gets namespace identifier. + * + * @return Namespace identifier. + */ + public getId(): NamespaceIdDto { + return this.namespaceRegistrationTransactionBody.getId(); + } + + /** + * Gets namespace name. + * + * @return Namespace name. + */ + public getName(): Uint8Array { + return this.namespaceRegistrationTransactionBody.getName(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.namespaceRegistrationTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const namespaceRegistrationTransactionBodyBytes = this.namespaceRegistrationTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceRegistrationTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder.ts new file mode 100644 index 0000000000..e8f4c80213 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder.ts @@ -0,0 +1,142 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { KeyDto } from './KeyDto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { SecretLockTransactionBodyBuilder } from './SecretLockTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for an embedded secret lock transaction. */ +export class EmbeddedSecretLockTransactionBuilder extends EmbeddedTransactionBuilder { + /** Secret lock transaction body. */ + secretLockTransactionBody: SecretLockTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaic Locked mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Locked mosaic recipient. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.secretLockTransactionBody = new SecretLockTransactionBodyBuilder(mosaic, duration, hashAlgorithm, secret, recipient); + } + + /** + * Creates an instance of EmbeddedSecretLockTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedSecretLockTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedSecretLockTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const secretLockTransactionBody = SecretLockTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secretLockTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedSecretLockTransactionBuilder(superObject.signer, superObject.version, superObject.type, secretLockTransactionBody.mosaic, secretLockTransactionBody.duration, secretLockTransactionBody.hashAlgorithm, secretLockTransactionBody.secret, secretLockTransactionBody.recipient); + } + + /** + * Gets locked mosaic. + * + * @return Locked mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.secretLockTransactionBody.getMosaic(); + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.secretLockTransactionBody.getDuration(); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.secretLockTransactionBody.getHashAlgorithm(); + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secretLockTransactionBody.getSecret(); + } + + /** + * Gets locked mosaic recipient. + * + * @return Locked mosaic recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.secretLockTransactionBody.getRecipient(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.secretLockTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const secretLockTransactionBodyBytes = this.secretLockTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretLockTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder.ts new file mode 100644 index 0000000000..58d0df9188 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder.ts @@ -0,0 +1,129 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { KeyDto } from './KeyDto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { SecretProofTransactionBodyBuilder } from './SecretProofTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; + +/** Binary layout for an embedded secret proof transaction. */ +export class EmbeddedSecretProofTransactionBuilder extends EmbeddedTransactionBuilder { + /** Secret proof transaction body. */ + secretProofTransactionBody: SecretProofTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Recipient. + * @param proof Proof data. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto, proof: Uint8Array) { + super(signer, version, type); + this.secretProofTransactionBody = new SecretProofTransactionBodyBuilder(hashAlgorithm, secret, recipient, proof); + } + + /** + * Creates an instance of EmbeddedSecretProofTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedSecretProofTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedSecretProofTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const secretProofTransactionBody = SecretProofTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secretProofTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedSecretProofTransactionBuilder(superObject.signer, superObject.version, superObject.type, secretProofTransactionBody.hashAlgorithm, secretProofTransactionBody.secret, secretProofTransactionBody.recipient, secretProofTransactionBody.proof); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.secretProofTransactionBody.getHashAlgorithm(); + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secretProofTransactionBody.getSecret(); + } + + /** + * Gets recipient. + * + * @return Recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.secretProofTransactionBody.getRecipient(); + } + + /** + * Gets proof data. + * + * @return Proof data. + */ + public getProof(): Uint8Array { + return this.secretProofTransactionBody.getProof(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.secretProofTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const secretProofTransactionBodyBytes = this.secretProofTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretProofTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedTransactionBuilder.ts new file mode 100644 index 0000000000..836a8cda5d --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedTransactionBuilder.ts @@ -0,0 +1,127 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded transaction. */ +export class EmbeddedTransactionBuilder { + /** Entity size. */ + size = 0; + /** Entity signer's public key. */ + signer: KeyDto; + /** Entity version. */ + version: number; + /** Entity type. */ + type: EntityTypeDto; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + */ + public constructor(signer: KeyDto, version: number, type: EntityTypeDto) { + this.signer = signer; + this.version = version; + this.type = type; + } + + /** + * Creates an instance of EmbeddedTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedTransactionBuilder { + const byteArray = Array.from(payload); + const size = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signer.getSize()); + const version = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const type = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + return new EmbeddedTransactionBuilder(signer, version, type); + } + + /** + * Gets entity signer's public key. + * + * @return Entity signer's public key. + */ + public getSigner(): KeyDto { + return this.signer; + } + + /** + * Gets entity version. + * + * @return Entity version. + */ + public getVersion(): number { + return this.version; + } + + /** + * Gets entity type. + * + * @return Entity type. + */ + public getType(): EntityTypeDto { + return this.type; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 4; // size + size += this.signer.getSize(); + size += 2; // version + size += 2; // type + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const sizeBytes = GeneratorUtils.uintToBuffer(this.getSize(), 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, sizeBytes); + const signerBytes = this.signer.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); + const versionBytes = GeneratorUtils.uintToBuffer(this.getVersion(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, versionBytes); + const typeBytes = GeneratorUtils.uintToBuffer(this.type, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, typeBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedTransferTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedTransferTransactionBuilder.ts new file mode 100644 index 0000000000..f4402345ef --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedTransferTransactionBuilder.ts @@ -0,0 +1,118 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { TransferTransactionBodyBuilder } from './TransferTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for an embedded transfer transaction. */ +export class EmbeddedTransferTransactionBuilder extends EmbeddedTransactionBuilder { + /** Transfer transaction body. */ + transferTransactionBody: TransferTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param recipient Transaction recipient. + * @param message Transaction message. + * @param mosaics Attached mosaics. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, recipient: UnresolvedAddressDto, message: Uint8Array, mosaics: UnresolvedMosaicBuilder[]) { + super(signer, version, type); + this.transferTransactionBody = new TransferTransactionBodyBuilder(recipient, message, mosaics); + } + + /** + * Creates an instance of EmbeddedTransferTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedTransferTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedTransferTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const transferTransactionBody = TransferTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, transferTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedTransferTransactionBuilder(superObject.signer, superObject.version, superObject.type, transferTransactionBody.recipient, transferTransactionBody.message, transferTransactionBody.mosaics); + } + + /** + * Gets transaction recipient. + * + * @return Transaction recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.transferTransactionBody.getRecipient(); + } + + /** + * Gets transaction message. + * + * @return Transaction message. + */ + public getMessage(): Uint8Array { + return this.transferTransactionBody.getMessage(); + } + + /** + * Gets attached mosaics. + * + * @return Attached mosaics. + */ + public getMosaics(): UnresolvedMosaicBuilder[] { + return this.transferTransactionBody.getMosaics(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.transferTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const transferTransactionBodyBytes = this.transferTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, transferTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EntityTypeDto.ts b/src/infrastructure/catbuffer/EntityTypeDto.ts new file mode 100644 index 0000000000..52e1c55a94 --- /dev/null +++ b/src/infrastructure/catbuffer/EntityTypeDto.ts @@ -0,0 +1,133 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of entity types. */ +export enum EntityTypeDto { + /** Reserved entity type. */ + RESERVED = 0, + /** + * Transfer Transaction transaction type. + * @type {number} + */ + TRANSFER = 0x4154, + + /** + * Register namespace transaction type. + * @type {number} + */ + REGISTER_NAMESPACE = 0x414E, + + /** + * Address alias transaction type + * @type {number} + */ + ADDRESS_ALIAS = 0x424E, + + /** + * Mosaic alias transaction type + * @type {number} + */ + MOSAIC_ALIAS = 0x434E, + + /** + * Mosaic definition transaction type. + * @type {number} + */ + MOSAIC_DEFINITION = 0x414D, + + /** + * Mosaic supply change transaction. + * @type {number} + */ + MOSAIC_SUPPLY_CHANGE = 0x424D, + + /** + * Modify multisig account transaction type. + * @type {number} + */ + MODIFY_MULTISIG_ACCOUNT = 0x4155, + + /** + * Aggregate complete transaction type. + * @type {number} + */ + AGGREGATE_COMPLETE = 0x4141, + + /** + * Aggregate bonded transaction type + */ + AGGREGATE_BONDED = 0x4241, + + /** + * Lock transaction type + * @type {number} + */ + LOCK = 0x4148, + + /** + * Secret Lock Transaction type + * @type {number} + */ + SECRET_LOCK = 0x4152, + + /** + * Secret Proof transaction type + * @type {number} + */ + SECRET_PROOF = 0x4252, + + /** + * Account restriction address transaction type + * @type {number} + */ + ACCOUNT_RESTRICTION_ADDRESS = 0x4150, + + /** + * Account restriction mosaic transaction type + * @type {number} + */ + ACCOUNT_RESTRICTION_MOSAIC = 0x4250, + + /** + * Account restriction operation transaction type + * @type {number} + */ + ACCOUNT_RESTRICTION_OPERATION = 0x4350, + + /** + * Link account transaction type + * @type {number} + */ + LINK_ACCOUNT = 0x414C, + + /** + * Mosaic address restriction type + * @type {number} + */ + MOSAIC_ADDRESS_RESTRICTION = 0x4251, + + /** + * Mosaic global restriction type + * @type {number} + */ + MOSAIC_GLOBAL_RESTRICTION = 0x4151, +} diff --git a/src/infrastructure/catbuffer/GeneratorUtils.ts b/src/infrastructure/catbuffer/GeneratorUtils.ts new file mode 100644 index 0000000000..437c32d117 --- /dev/null +++ b/src/infrastructure/catbuffer/GeneratorUtils.ts @@ -0,0 +1,141 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +/** + * Generator utility class. + */ +export class GeneratorUtils { + + /** + * Converts a (64bit) uint8 array into a number array. + * @param {Uint8Array} input A uint8 array. + * @returns {number[]} The uint64 representation of the input. + */ + public static bufferToUint64 (input: Uint8Array): number[] { + if (8 !== input.length) { + throw Error(`byte array has unexpected size '${input.length}'`); + } + input = input.reverse(); + return [GeneratorUtils.readUint32At(input, 0), GeneratorUtils.readUint32At(input, 4)]; + } + + /** + * Read buffer into 32bits integer at given index. + * @param {Uint8Array} bytes A uint8 array. + * @param {number} index Index. + * @returns {number} 32bits integer. + */ + public static readUint32At(bytes: Uint8Array, index: number): number { + return (bytes[index] + (bytes[index + 1] << 8) + (bytes[index + 2] << 16) + (bytes[index + 3] << 24)) >>> 0; + } + + /** + * Write uint to buffer + * @param {number} uintValue A uint8 array. + * @param {number} bufferSize Buffer size. + * @returns {Uint8Array} + */ + public static uintToBuffer (uintValue: number, bufferSize: number): Uint8Array { + const buffer = new ArrayBuffer(bufferSize); + const dataView = new DataView(buffer); + if (1 === bufferSize) + dataView.setUint8(0, uintValue); + + else if (2 === bufferSize) + dataView.setUint16(0, uintValue, true); + + else if (4 === bufferSize) + dataView.setUint32(0, uintValue, true); + + else + throw new Error('Unexpected bufferSize'); + + return new Uint8Array(buffer); + } + + /** + * Write uint to buffer + * @param {Uint8Array} buffer A uint8 array. + * @returns {number} + */ + public static bufferToUint(buffer: Uint8Array): number { + const dataView = new DataView(buffer.buffer); + if (1 === buffer.byteLength) + return dataView.getUint8(0); + + else if (2 === buffer.byteLength) + return dataView.getUint16(0, true); + + else if (4 === buffer.byteLength) + return dataView.getUint32(0, true); + + throw new Error('Unexpected buffer size'); + }; + + /** + * Write Uint64 to buffer + * @param {number} uintValue Uint64 (number[]). + * @returns {Uint8Array} + */ + public static uint64ToBuffer(uintValue: number[]): Uint8Array { + const uint32Array = new Uint32Array(uintValue); + return new Uint8Array(uint32Array.buffer); + } + + /** + * Concatenate two arrays + * @param {Uint8Array} array1 A Uint8Array. + * @param {Uint8Array} array2 A Uint8Array. + * @returns {Uint8Array} + */ + public static concatTypedArrays(array1: Uint8Array, array2: Uint8Array): Uint8Array { + const newArray = new Uint8Array(array1.length + array2.length); + newArray.set(array1); + newArray.set(array2, array1.length); + return newArray; + } + + /** Converts an unsigned byte to a signed byte with the same binary representation. + * @param {number} input An unsigned byte. + * @returns {number} A signed byte with the same binary representation as the input. + * + */ + public static uint8ToInt8 = (input: number): number => { + if (0xFF < input) { + throw Error(`input '${input}' is out of range`); + } + return input << 24 >> 24; + } + + /** Get bytes by given sub array size. + * @param {Uint8Array} binary Binary bytes array. + * @param {number} size Subarray size. + * @returns {Uint8Array} + * + */ + public static getBytes(binary: Uint8Array, size: number): Uint8Array { + if (size > binary.length) + throw new RangeError(); + + const bytes = binary.slice(0, size); + return bytes; + } +} diff --git a/src/infrastructure/catbuffer/Hash256Dto.ts b/src/infrastructure/catbuffer/Hash256Dto.ts new file mode 100644 index 0000000000..0f09dfda19 --- /dev/null +++ b/src/infrastructure/catbuffer/Hash256Dto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Hash256. */ +export class Hash256Dto { + /** Hash256. */ + hash256: Uint8Array; + + /** + * Constructor. + * + * @param hash256 Hash256. + */ + constructor(hash256: Uint8Array) { + this.hash256 = hash256; + } + + /** + * Creates an instance of Hash256Dto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of Hash256Dto. + */ + public static loadFromBinary(payload: Uint8Array): Hash256Dto { + const byteArray = Array.from(payload); + const hash256 = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 32); + byteArray.splice(0, 32); + return new Hash256Dto(hash256); + } + + /** + * Gets Hash256. + * + * @return Hash256. + */ + public getHash256(): Uint8Array { + return this.hash256; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 32; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.hash256); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/Hash512Dto.ts b/src/infrastructure/catbuffer/Hash512Dto.ts new file mode 100644 index 0000000000..1455eb7623 --- /dev/null +++ b/src/infrastructure/catbuffer/Hash512Dto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Hash512. */ +export class Hash512Dto { + /** Hash512. */ + hash512: Uint8Array; + + /** + * Constructor. + * + * @param hash512 Hash512. + */ + constructor(hash512: Uint8Array) { + this.hash512 = hash512; + } + + /** + * Creates an instance of Hash512Dto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of Hash512Dto. + */ + public static loadFromBinary(payload: Uint8Array): Hash512Dto { + const byteArray = Array.from(payload); + const hash512 = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 64); + byteArray.splice(0, 64); + return new Hash512Dto(hash512); + } + + /** + * Gets Hash512. + * + * @return Hash512. + */ + public getHash512(): Uint8Array { + return this.hash512; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 64; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.hash512); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/HashLockTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/HashLockTransactionBodyBuilder.ts new file mode 100644 index 0000000000..26d8158335 --- /dev/null +++ b/src/infrastructure/catbuffer/HashLockTransactionBodyBuilder.ts @@ -0,0 +1,121 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a hash lock transaction. */ +export class HashLockTransactionBodyBuilder { + /** Lock mosaic. */ + mosaic: UnresolvedMosaicBuilder; + /** Number of blocks for which a lock should be valid. */ + duration: BlockDurationDto; + /** Lock hash. */ + hash: Hash256Dto; + + /** + * Constructor. + * + * @param mosaic Lock mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hash Lock hash. + */ + public constructor(mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hash: Hash256Dto) { + this.mosaic = mosaic; + this.duration = duration; + this.hash = hash; + } + + /** + * Creates an instance of HashLockTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of HashLockTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): HashLockTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaic = UnresolvedMosaicBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaic.getSize()); + const duration = BlockDurationDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, duration.getSize()); + const hash = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, hash.getSize()); + return new HashLockTransactionBodyBuilder(mosaic, duration, hash); + } + + /** + * Gets lock mosaic. + * + * @return Lock mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.mosaic; + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.duration; + } + + /** + * Gets lock hash. + * + * @return Lock hash. + */ + public getHash(): Hash256Dto { + return this.hash; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaic.getSize(); + size += this.duration.getSize(); + size += this.hash.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicBytes = this.mosaic.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicBytes); + const durationBytes = this.duration.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, durationBytes); + const hashBytes = this.hash.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/HashLockTransactionBuilder.ts b/src/infrastructure/catbuffer/HashLockTransactionBuilder.ts new file mode 100644 index 0000000000..b6c5b9643f --- /dev/null +++ b/src/infrastructure/catbuffer/HashLockTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { BlockDurationDto } from './BlockDurationDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { HashLockTransactionBodyBuilder } from './HashLockTransactionBodyBuilder'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a non-embedded hash lock transaction. */ +export class HashLockTransactionBuilder extends TransactionBuilder { + /** Hash lock transaction body. */ + hashLockTransactionBody: HashLockTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaic Lock mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hash Lock hash. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hash: Hash256Dto) { + super(signature, signer, version, type, fee, deadline); + this.hashLockTransactionBody = new HashLockTransactionBodyBuilder(mosaic, duration, hash); + } + + /** + * Creates an instance of HashLockTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of HashLockTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): HashLockTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const hashLockTransactionBody = HashLockTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, hashLockTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new HashLockTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, hashLockTransactionBody.mosaic, hashLockTransactionBody.duration, hashLockTransactionBody.hash); + } + + /** + * Gets lock mosaic. + * + * @return Lock mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.hashLockTransactionBody.getMosaic(); + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.hashLockTransactionBody.getDuration(); + } + + /** + * Gets lock hash. + * + * @return Lock hash. + */ + public getHash(): Hash256Dto { + return this.hashLockTransactionBody.getHash(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.hashLockTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const hashLockTransactionBodyBytes = this.hashLockTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashLockTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/KeyDto.ts b/src/infrastructure/catbuffer/KeyDto.ts new file mode 100644 index 0000000000..ea1fb55242 --- /dev/null +++ b/src/infrastructure/catbuffer/KeyDto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Key. */ +export class KeyDto { + /** Key. */ + key: Uint8Array; + + /** + * Constructor. + * + * @param key Key. + */ + constructor(key: Uint8Array) { + this.key = key; + } + + /** + * Creates an instance of KeyDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of KeyDto. + */ + public static loadFromBinary(payload: Uint8Array): KeyDto { + const byteArray = Array.from(payload); + const key = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 32); + byteArray.splice(0, 32); + return new KeyDto(key); + } + + /** + * Gets Key. + * + * @return Key. + */ + public getKey(): Uint8Array { + return this.key; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 32; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.key); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/LockHashAlgorithmDto.ts b/src/infrastructure/catbuffer/LockHashAlgorithmDto.ts new file mode 100644 index 0000000000..46ed416098 --- /dev/null +++ b/src/infrastructure/catbuffer/LockHashAlgorithmDto.ts @@ -0,0 +1,33 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of lock hash algorithms. */ +export enum LockHashAlgorithmDto { + /** Input is hashed using sha-3 256. */ + SHA3_256 = 0, + /** Input is hashed using keccak 256. */ + KECCAK_256 = 1, + /** Input is hashed twice: first with sha-256 and then with ripemd-160 (bitcoin's OP_HASH160). */ + HASH_160 = 2, + /** Input is hashed twice with sha-256 (bitcoin's OP_HASH256). */ + HASH_256 = 3, +} diff --git a/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..2572bae2f0 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,158 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a mosaic address restriction transaction. */ +export class MosaicAddressRestrictionTransactionBodyBuilder { + /** Identifier of the mosaic to which the restriction applies. */ + mosaicId: UnresolvedMosaicIdDto; + /** Restriction key. */ + restrictionKey: number[]; + /** Address being restricted. */ + targetAddress: UnresolvedAddressDto; + /** Previous restriction value. */ + previousRestrictionValue: number[]; + /** New restriction value. */ + newRestrictionValue: number[]; + + /** + * Constructor. + * + * @param mosaicId Identifier of the mosaic to which the restriction applies. + * @param restrictionKey Restriction key. + * @param targetAddress Address being restricted. + * @param previousRestrictionValue Previous restriction value. + * @param newRestrictionValue New restriction value. + */ + // tslint:disable-next-line: max-line-length + public constructor(mosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], targetAddress: UnresolvedAddressDto, previousRestrictionValue: number[], newRestrictionValue: number[]) { + this.mosaicId = mosaicId; + this.restrictionKey = restrictionKey; + this.targetAddress = targetAddress; + this.previousRestrictionValue = previousRestrictionValue; + this.newRestrictionValue = newRestrictionValue; + } + + /** + * Creates an instance of MosaicAddressRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicAddressRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicAddressRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const restrictionKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const targetAddress = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetAddress.getSize()); + const previousRestrictionValue = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const newRestrictionValue = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + // tslint:disable-next-line: max-line-length + return new MosaicAddressRestrictionTransactionBodyBuilder(mosaicId, restrictionKey, targetAddress, previousRestrictionValue, newRestrictionValue); + } + + /** + * Gets identifier of the mosaic to which the restriction applies. + * + * @return Identifier of the mosaic to which the restriction applies. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicId; + } + + /** + * Gets restriction key. + * + * @return Restriction key. + */ + public getRestrictionKey(): number[] { + return this.restrictionKey; + } + + /** + * Gets address being restricted. + * + * @return Address being restricted. + */ + public getTargetAddress(): UnresolvedAddressDto { + return this.targetAddress; + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.previousRestrictionValue; + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.newRestrictionValue; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += 8; // restrictionKey + size += this.targetAddress.getSize(); + size += 8; // previousRestrictionValue + size += 8; // newRestrictionValue + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const restrictionKeyBytes = GeneratorUtils.uint64ToBuffer(this.getRestrictionKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionKeyBytes); + const targetAddressBytes = this.targetAddress.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetAddressBytes); + const previousRestrictionValueBytes = GeneratorUtils.uint64ToBuffer(this.getPreviousRestrictionValue()); + newArray = GeneratorUtils.concatTypedArrays(newArray, previousRestrictionValueBytes); + const newRestrictionValueBytes = GeneratorUtils.uint64ToBuffer(this.getNewRestrictionValue()); + newArray = GeneratorUtils.concatTypedArrays(newArray, newRestrictionValueBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..ba0d6b5d7e --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder.ts @@ -0,0 +1,146 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicAddressRestrictionTransactionBodyBuilder } from './MosaicAddressRestrictionTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a non-embedded mosaic address restriction transaction. */ +export class MosaicAddressRestrictionTransactionBuilder extends TransactionBuilder { + /** Mosaic address restriction transaction body. */ + mosaicAddressRestrictionTransactionBody: MosaicAddressRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaicId Identifier of the mosaic to which the restriction applies. + * @param restrictionKey Restriction key. + * @param targetAddress Address being restricted. + * @param previousRestrictionValue Previous restriction value. + * @param newRestrictionValue New restriction value. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], targetAddress: UnresolvedAddressDto, previousRestrictionValue: number[], newRestrictionValue: number[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.mosaicAddressRestrictionTransactionBody = new MosaicAddressRestrictionTransactionBodyBuilder(mosaicId, restrictionKey, targetAddress, previousRestrictionValue, newRestrictionValue); + } + + /** + * Creates an instance of MosaicAddressRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicAddressRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicAddressRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicAddressRestrictionTransactionBody = MosaicAddressRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicAddressRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicAddressRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicAddressRestrictionTransactionBody.mosaicId, mosaicAddressRestrictionTransactionBody.restrictionKey, mosaicAddressRestrictionTransactionBody.targetAddress, mosaicAddressRestrictionTransactionBody.previousRestrictionValue, mosaicAddressRestrictionTransactionBody.newRestrictionValue); + } + + /** + * Gets identifier of the mosaic to which the restriction applies. + * + * @return Identifier of the mosaic to which the restriction applies. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicAddressRestrictionTransactionBody.getMosaicId(); + } + + /** + * Gets restriction key. + * + * @return Restriction key. + */ + public getRestrictionKey(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getRestrictionKey(); + } + + /** + * Gets address being restricted. + * + * @return Address being restricted. + */ + public getTargetAddress(): UnresolvedAddressDto { + return this.mosaicAddressRestrictionTransactionBody.getTargetAddress(); + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getPreviousRestrictionValue(); + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getNewRestrictionValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicAddressRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicAddressRestrictionTransactionBodyBytes = this.mosaicAddressRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicAddressRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicAliasTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicAliasTransactionBodyBuilder.ts new file mode 100644 index 0000000000..6c411a6ecb --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicAliasTransactionBodyBuilder.ts @@ -0,0 +1,121 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AliasActionDto } from './AliasActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicIdDto } from './MosaicIdDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for an mosaic alias transaction. */ +export class MosaicAliasTransactionBodyBuilder { + /** Alias action. */ + aliasAction: AliasActionDto; + /** Identifier of the namespace that will become an alias. */ + namespaceId: NamespaceIdDto; + /** Aliased mosaic identifier. */ + mosaicId: MosaicIdDto; + + /** + * Constructor. + * + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param mosaicId Aliased mosaic identifier. + */ + public constructor(aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, mosaicId: MosaicIdDto) { + this.aliasAction = aliasAction; + this.namespaceId = namespaceId; + this.mosaicId = mosaicId; + } + + /** + * Creates an instance of MosaicAliasTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicAliasTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicAliasTransactionBodyBuilder { + const byteArray = Array.from(payload); + const aliasAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const namespaceId = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceId.getSize()); + const mosaicId = MosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + return new MosaicAliasTransactionBodyBuilder(aliasAction, namespaceId, mosaicId); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.aliasAction; + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.namespaceId; + } + + /** + * Gets aliased mosaic identifier. + * + * @return Aliased mosaic identifier. + */ + public getMosaicId(): MosaicIdDto { + return this.mosaicId; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // aliasAction + size += this.namespaceId.getSize(); + size += this.mosaicId.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const aliasActionBytes = GeneratorUtils.uintToBuffer(this.aliasAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, aliasActionBytes); + const namespaceIdBytes = this.namespaceId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceIdBytes); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicAliasTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicAliasTransactionBuilder.ts new file mode 100644 index 0000000000..d126fef24c --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicAliasTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AliasActionDto } from './AliasActionDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicAliasTransactionBodyBuilder } from './MosaicAliasTransactionBodyBuilder'; +import { MosaicIdDto } from './MosaicIdDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded mosaic alias transaction. */ +export class MosaicAliasTransactionBuilder extends TransactionBuilder { + /** Mosaic alias transaction body. */ + mosaicAliasTransactionBody: MosaicAliasTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param mosaicId Aliased mosaic identifier. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, mosaicId: MosaicIdDto) { + super(signature, signer, version, type, fee, deadline); + this.mosaicAliasTransactionBody = new MosaicAliasTransactionBodyBuilder(aliasAction, namespaceId, mosaicId); + } + + /** + * Creates an instance of MosaicAliasTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicAliasTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicAliasTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const mosaicAliasTransactionBody = MosaicAliasTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicAliasTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicAliasTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicAliasTransactionBody.aliasAction, mosaicAliasTransactionBody.namespaceId, mosaicAliasTransactionBody.mosaicId); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.mosaicAliasTransactionBody.getAliasAction(); + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.mosaicAliasTransactionBody.getNamespaceId(); + } + + /** + * Gets aliased mosaic identifier. + * + * @return Aliased mosaic identifier. + */ + public getMosaicId(): MosaicIdDto { + return this.mosaicAliasTransactionBody.getMosaicId(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicAliasTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicAliasTransactionBodyBytes = this.mosaicAliasTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicAliasTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicBuilder.ts b/src/infrastructure/catbuffer/MosaicBuilder.ts new file mode 100644 index 0000000000..dc2ac60e87 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicIdDto } from './MosaicIdDto'; + +/** Binary layout for a mosaic. */ +export class MosaicBuilder { + /** Mosaic identifier. */ + mosaicId: MosaicIdDto; + /** Mosaic amount. */ + amount: AmountDto; + + /** + * Constructor. + * + * @param mosaicId Mosaic identifier. + * @param amount Mosaic amount. + */ + public constructor(mosaicId: MosaicIdDto, amount: AmountDto) { + this.mosaicId = mosaicId; + this.amount = amount; + } + + /** + * Creates an instance of MosaicBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicBuilder { + const byteArray = Array.from(payload); + const mosaicId = MosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const amount = AmountDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, amount.getSize()); + return new MosaicBuilder(mosaicId, amount); + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getMosaicId(): MosaicIdDto { + return this.mosaicId; + } + + /** + * Gets mosaic amount. + * + * @return Mosaic amount. + */ + public getAmount(): AmountDto { + return this.amount; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += this.amount.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const amountBytes = this.amount.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, amountBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicDefinitionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicDefinitionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..b82254e5f7 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicDefinitionTransactionBodyBuilder.ts @@ -0,0 +1,158 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicIdDto } from './MosaicIdDto'; +import { MosaicNonceDto } from './MosaicNonceDto'; + +/** Binary layout for a mosaic definition transaction. */ +export class MosaicDefinitionTransactionBodyBuilder { + /** Mosaic nonce. */ + nonce: MosaicNonceDto; + /** Mosaic identifier. */ + id: MosaicIdDto; + /** Mosaic flags. */ + flags: number; + /** Mosaic divisibility. */ + divisibility: number; + /** Mosaic duration. */ + duration: BlockDurationDto; + + /** + * Constructor. + * + * @param nonce Mosaic nonce. + * @param id Mosaic identifier. + * @param flags Mosaic flags. + * @param divisibility Mosaic divisibility. + * @param duration Mosaic duration. + */ + // tslint:disable-next-line: max-line-length + public constructor(nonce: MosaicNonceDto, id: MosaicIdDto, flags: number, divisibility: number, duration: BlockDurationDto) { + this.nonce = nonce; + this.id = id; + this.flags = flags; + this.divisibility = divisibility; + this.duration = duration; + } + + /** + * Creates an instance of MosaicDefinitionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicDefinitionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicDefinitionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const nonce = MosaicNonceDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, nonce.getSize()); + const id = MosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, id.getSize()); + const flags = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const divisibility = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const duration = BlockDurationDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, duration.getSize()); + return new MosaicDefinitionTransactionBodyBuilder(nonce, id, flags, divisibility, duration); + } + + /** + * Gets mosaic nonce. + * + * @return Mosaic nonce. + */ + public getNonce(): MosaicNonceDto { + return this.nonce; + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getId(): MosaicIdDto { + return this.id; + } + + /** + * Gets mosaic flags. + * + * @return Mosaic flags. + */ + public getFlags(): number { + return this.flags; + } + + /** + * Gets mosaic divisibility. + * + * @return Mosaic divisibility. + */ + public getDivisibility(): number { + return this.divisibility; + } + + /** + * Gets mosaic duration. + * + * @return Mosaic duration. + */ + public getDuration(): BlockDurationDto { + return this.duration; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.nonce.getSize(); + size += this.id.getSize(); + size += 1; // flags + size += 1; // divisibility + size += this.duration.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const nonceBytes = this.nonce.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, nonceBytes); + const idBytes = this.id.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, idBytes); + const flagsBytes = GeneratorUtils.uintToBuffer(this.getFlags(), 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, flagsBytes); + const divisibilityBytes = GeneratorUtils.uintToBuffer(this.getDivisibility(), 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, divisibilityBytes); + const durationBytes = this.duration.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, durationBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicDefinitionTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicDefinitionTransactionBuilder.ts new file mode 100644 index 0000000000..a32b33b5d9 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicDefinitionTransactionBuilder.ts @@ -0,0 +1,147 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { BlockDurationDto } from './BlockDurationDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicDefinitionTransactionBodyBuilder } from './MosaicDefinitionTransactionBodyBuilder'; +import { MosaicIdDto } from './MosaicIdDto'; +import { MosaicNonceDto } from './MosaicNonceDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded mosaic definition transaction. */ +export class MosaicDefinitionTransactionBuilder extends TransactionBuilder { + /** Mosaic definition transaction body. */ + mosaicDefinitionTransactionBody: MosaicDefinitionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param nonce Mosaic nonce. + * @param id Mosaic identifier. + * @param flags Mosaic flags. + * @param divisibility Mosaic divisibility. + * @param duration Mosaic duration. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, nonce: MosaicNonceDto, id: MosaicIdDto, flags: number, divisibility: number, duration: BlockDurationDto) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.mosaicDefinitionTransactionBody = new MosaicDefinitionTransactionBodyBuilder(nonce, id, flags, divisibility, duration); + } + + /** + * Creates an instance of MosaicDefinitionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicDefinitionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicDefinitionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicDefinitionTransactionBody = MosaicDefinitionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicDefinitionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicDefinitionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicDefinitionTransactionBody.nonce, mosaicDefinitionTransactionBody.id, mosaicDefinitionTransactionBody.flags, mosaicDefinitionTransactionBody.divisibility, mosaicDefinitionTransactionBody.duration); + } + + /** + * Gets mosaic nonce. + * + * @return Mosaic nonce. + */ + public getNonce(): MosaicNonceDto { + return this.mosaicDefinitionTransactionBody.getNonce(); + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getId(): MosaicIdDto { + return this.mosaicDefinitionTransactionBody.getId(); + } + + /** + * Gets mosaic flags. + * + * @return Mosaic flags. + */ + public getFlags(): number { + return this.mosaicDefinitionTransactionBody.getFlags(); + } + + /** + * Gets mosaic divisibility. + * + * @return Mosaic divisibility. + */ + public getDivisibility(): number { + return this.mosaicDefinitionTransactionBody.getDivisibility(); + } + + /** + * Gets mosaic duration. + * + * @return Mosaic duration. + */ + public getDuration(): BlockDurationDto { + return this.mosaicDefinitionTransactionBody.getDuration(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicDefinitionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicDefinitionTransactionBodyBytes = this.mosaicDefinitionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicDefinitionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicFlagsDto.ts b/src/infrastructure/catbuffer/MosaicFlagsDto.ts new file mode 100644 index 0000000000..11a740ab03 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicFlagsDto.ts @@ -0,0 +1,33 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of mosaic property flags. */ +export enum MosaicFlagsDto { + /** No flags present. */ + NONE = 0, + /** Mosaic supports supply changes even when mosaic owner owns partial supply. */ + SUPPLY_MUTABLE = 1, + /** Mosaic supports transfers between arbitrary accounts \note when not set, mosaic can only be transferred to and from mosaic owner. */ + TRANSFERABLE = 2, + /** Mosaic supports custom restrictions configured by mosaic owner. */ + RESTRICTABLE = 4, +} diff --git a/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..09f3fd4e5e --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,194 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicRestrictionTypeDto } from './MosaicRestrictionTypeDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a mosaic global restriction transaction. */ +export class MosaicGlobalRestrictionTransactionBodyBuilder { + /** Identifier of the mosaic being restricted. */ + mosaicId: UnresolvedMosaicIdDto; + /** Identifier of the mosaic providing the restriction key. */ + referenceMosaicId: UnresolvedMosaicIdDto; + /** Restriction key relative to the reference mosaic identifier. */ + restrictionKey: number[]; + /** Previous restriction value. */ + previousRestrictionValue: number[]; + /** Previous restriction type. */ + previousRestrictionType: MosaicRestrictionTypeDto; + /** New restriction value. */ + newRestrictionValue: number[]; + /** New restriction type. */ + newRestrictionType: MosaicRestrictionTypeDto; + + /** + * Constructor. + * + * @param mosaicId Identifier of the mosaic being restricted. + * @param referenceMosaicId Identifier of the mosaic providing the restriction key. + * @param restrictionKey Restriction key relative to the reference mosaic identifier. + * @param previousRestrictionValue Previous restriction value. + * @param previousRestrictionType Previous restriction type. + * @param newRestrictionValue New restriction value. + * @param newRestrictionType New restriction type. + */ + // tslint:disable-next-line: max-line-length + public constructor(mosaicId: UnresolvedMosaicIdDto, referenceMosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], previousRestrictionValue: number[], previousRestrictionType: MosaicRestrictionTypeDto, newRestrictionValue: number[], newRestrictionType: MosaicRestrictionTypeDto) { + this.mosaicId = mosaicId; + this.referenceMosaicId = referenceMosaicId; + this.restrictionKey = restrictionKey; + this.previousRestrictionValue = previousRestrictionValue; + this.previousRestrictionType = previousRestrictionType; + this.newRestrictionValue = newRestrictionValue; + this.newRestrictionType = newRestrictionType; + } + + /** + * Creates an instance of MosaicGlobalRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicGlobalRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicGlobalRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const referenceMosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, referenceMosaicId.getSize()); + const restrictionKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const previousRestrictionValue = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const previousRestrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const newRestrictionValue = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const newRestrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + // tslint:disable-next-line: max-line-length + return new MosaicGlobalRestrictionTransactionBodyBuilder(mosaicId, referenceMosaicId, restrictionKey, previousRestrictionValue, previousRestrictionType, newRestrictionValue, newRestrictionType); + } + + /** + * Gets identifier of the mosaic being restricted. + * + * @return Identifier of the mosaic being restricted. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicId; + } + + /** + * Gets identifier of the mosaic providing the restriction key. + * + * @return Identifier of the mosaic providing the restriction key. + */ + public getReferenceMosaicId(): UnresolvedMosaicIdDto { + return this.referenceMosaicId; + } + + /** + * Gets restriction key relative to the reference mosaic identifier. + * + * @return Restriction key relative to the reference mosaic identifier. + */ + public getRestrictionKey(): number[] { + return this.restrictionKey; + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.previousRestrictionValue; + } + + /** + * Gets previous restriction type. + * + * @return Previous restriction type. + */ + public getPreviousRestrictionType(): MosaicRestrictionTypeDto { + return this.previousRestrictionType; + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.newRestrictionValue; + } + + /** + * Gets new restriction type. + * + * @return New restriction type. + */ + public getNewRestrictionType(): MosaicRestrictionTypeDto { + return this.newRestrictionType; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += this.referenceMosaicId.getSize(); + size += 8; // restrictionKey + size += 8; // previousRestrictionValue + size += 1; // previousRestrictionType + size += 8; // newRestrictionValue + size += 1; // newRestrictionType + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const referenceMosaicIdBytes = this.referenceMosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, referenceMosaicIdBytes); + const restrictionKeyBytes = GeneratorUtils.uint64ToBuffer(this.getRestrictionKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionKeyBytes); + const previousRestrictionValueBytes = GeneratorUtils.uint64ToBuffer(this.getPreviousRestrictionValue()); + newArray = GeneratorUtils.concatTypedArrays(newArray, previousRestrictionValueBytes); + const previousRestrictionTypeBytes = GeneratorUtils.uintToBuffer(this.previousRestrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, previousRestrictionTypeBytes); + const newRestrictionValueBytes = GeneratorUtils.uint64ToBuffer(this.getNewRestrictionValue()); + newArray = GeneratorUtils.concatTypedArrays(newArray, newRestrictionValueBytes); + const newRestrictionTypeBytes = GeneratorUtils.uintToBuffer(this.newRestrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, newRestrictionTypeBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..e84414e6e2 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder.ts @@ -0,0 +1,166 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicGlobalRestrictionTransactionBodyBuilder } from './MosaicGlobalRestrictionTransactionBodyBuilder'; +import { MosaicRestrictionTypeDto } from './MosaicRestrictionTypeDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a non-embedded mosaic global restriction transaction. */ +export class MosaicGlobalRestrictionTransactionBuilder extends TransactionBuilder { + /** Mosaic global restriction transaction body. */ + mosaicGlobalRestrictionTransactionBody: MosaicGlobalRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaicId Identifier of the mosaic being restricted. + * @param referenceMosaicId Identifier of the mosaic providing the restriction key. + * @param restrictionKey Restriction key relative to the reference mosaic identifier. + * @param previousRestrictionValue Previous restriction value. + * @param previousRestrictionType Previous restriction type. + * @param newRestrictionValue New restriction value. + * @param newRestrictionType New restriction type. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaicId: UnresolvedMosaicIdDto, referenceMosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], previousRestrictionValue: number[], previousRestrictionType: MosaicRestrictionTypeDto, newRestrictionValue: number[], newRestrictionType: MosaicRestrictionTypeDto) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.mosaicGlobalRestrictionTransactionBody = new MosaicGlobalRestrictionTransactionBodyBuilder(mosaicId, referenceMosaicId, restrictionKey, previousRestrictionValue, previousRestrictionType, newRestrictionValue, newRestrictionType); + } + + /** + * Creates an instance of MosaicGlobalRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicGlobalRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicGlobalRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicGlobalRestrictionTransactionBody = MosaicGlobalRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicGlobalRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicGlobalRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicGlobalRestrictionTransactionBody.mosaicId, mosaicGlobalRestrictionTransactionBody.referenceMosaicId, mosaicGlobalRestrictionTransactionBody.restrictionKey, mosaicGlobalRestrictionTransactionBody.previousRestrictionValue, mosaicGlobalRestrictionTransactionBody.previousRestrictionType, mosaicGlobalRestrictionTransactionBody.newRestrictionValue, mosaicGlobalRestrictionTransactionBody.newRestrictionType); + } + + /** + * Gets identifier of the mosaic being restricted. + * + * @return Identifier of the mosaic being restricted. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicGlobalRestrictionTransactionBody.getMosaicId(); + } + + /** + * Gets identifier of the mosaic providing the restriction key. + * + * @return Identifier of the mosaic providing the restriction key. + */ + public getReferenceMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicGlobalRestrictionTransactionBody.getReferenceMosaicId(); + } + + /** + * Gets restriction key relative to the reference mosaic identifier. + * + * @return Restriction key relative to the reference mosaic identifier. + */ + public getRestrictionKey(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getRestrictionKey(); + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getPreviousRestrictionValue(); + } + + /** + * Gets previous restriction type. + * + * @return Previous restriction type. + */ + public getPreviousRestrictionType(): MosaicRestrictionTypeDto { + return this.mosaicGlobalRestrictionTransactionBody.getPreviousRestrictionType(); + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getNewRestrictionValue(); + } + + /** + * Gets new restriction type. + * + * @return New restriction type. + */ + public getNewRestrictionType(): MosaicRestrictionTypeDto { + return this.mosaicGlobalRestrictionTransactionBody.getNewRestrictionType(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicGlobalRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicGlobalRestrictionTransactionBodyBytes = this.mosaicGlobalRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicGlobalRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicIdDto.ts b/src/infrastructure/catbuffer/MosaicIdDto.ts new file mode 100644 index 0000000000..dd88e70b01 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicIdDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Mosaic id. */ +export class MosaicIdDto { + /** Mosaic id. */ + mosaicId: number[]; + + /** + * Constructor. + * + * @param mosaicId Mosaic id. + */ + constructor(mosaicId: number[]) { + this.mosaicId = mosaicId; + } + + /** + * Creates an instance of MosaicIdDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicIdDto. + */ + public static loadFromBinary(payload: Uint8Array): MosaicIdDto { + const byteArray = Array.from(payload); + const mosaicId = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new MosaicIdDto(mosaicId); + } + + /** + * Gets Mosaic id. + * + * @return Mosaic id. + */ + public getMosaicId(): number[] { + return this.mosaicId; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = GeneratorUtils.uint64ToBuffer(this.getMosaicId()); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicMetadataTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicMetadataTransactionBodyBuilder.ts new file mode 100644 index 0000000000..a4ee75bcbc --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicMetadataTransactionBodyBuilder.ts @@ -0,0 +1,168 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a mosaic metadata transaction. */ +export class MosaicMetadataTransactionBodyBuilder { + /** Metadata target public key. */ + targetPublicKey: KeyDto; + /** Metadata key scoped to source, target and type. */ + scopedMetadataKey: number[]; + /** Target mosaic identifier. */ + targetMosaicId: UnresolvedMosaicIdDto; + /** Change in value size in bytes. */ + valueSizeDelta: number; + /** Difference between existing value and new value \note when there is no existing value, new value is same this value \note when there is an existing value, new value is calculated as xor(previous-value, value). */ + value: Uint8Array; + + /** + * Constructor. + * + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetMosaicId Target mosaic identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(targetPublicKey: KeyDto, scopedMetadataKey: number[], targetMosaicId: UnresolvedMosaicIdDto, valueSizeDelta: number, value: Uint8Array) { + this.targetPublicKey = targetPublicKey; + this.scopedMetadataKey = scopedMetadataKey; + this.targetMosaicId = targetMosaicId; + this.valueSizeDelta = valueSizeDelta; + this.value = value; + } + + /** + * Creates an instance of MosaicMetadataTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicMetadataTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicMetadataTransactionBodyBuilder { + const byteArray = Array.from(payload); + const targetPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetPublicKey.getSize()); + const scopedMetadataKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const targetMosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetMosaicId.getSize()); + const valueSizeDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const valueSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const value = GeneratorUtils.getBytes(Uint8Array.from(byteArray), valueSize); + byteArray.splice(0, valueSize); + // tslint:disable-next-line: max-line-length + return new MosaicMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetMosaicId, valueSizeDelta, value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.targetPublicKey; + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.scopedMetadataKey; + } + + /** + * Gets target mosaic identifier. + * + * @return Target mosaic identifier. + */ + public getTargetMosaicId(): UnresolvedMosaicIdDto { + return this.targetMosaicId; + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.valueSizeDelta; + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.targetPublicKey.getSize(); + size += 8; // scopedMetadataKey + size += this.targetMosaicId.getSize(); + size += 2; // valueSizeDelta + size += 2; // valueSize + size += this.value.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const targetPublicKeyBytes = this.targetPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetPublicKeyBytes); + const scopedMetadataKeyBytes = GeneratorUtils.uint64ToBuffer(this.getScopedMetadataKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, scopedMetadataKeyBytes); + const targetMosaicIdBytes = this.targetMosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetMosaicIdBytes); + const valueSizeDeltaBytes = GeneratorUtils.uintToBuffer(this.getValueSizeDelta(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeDeltaBytes); + const valueSizeBytes = GeneratorUtils.uintToBuffer(this.value.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.value); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..1a5866a030 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicMetadataTransactionBuilder.ts @@ -0,0 +1,150 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicMetadataTransactionBodyBuilder } from './MosaicMetadataTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a non-embedded mosaic metadata transaction. */ +export class MosaicMetadataTransactionBuilder extends TransactionBuilder { + /** Mosaic metadata transaction body. */ + mosaicMetadataTransactionBody: MosaicMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetMosaicId Target mosaic identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], targetMosaicId: UnresolvedMosaicIdDto, valueSizeDelta: number, value: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.mosaicMetadataTransactionBody = new MosaicMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetMosaicId, valueSizeDelta, value); + } + + /** + * Creates an instance of MosaicMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const mosaicMetadataTransactionBody = MosaicMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicMetadataTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicMetadataTransactionBody.targetPublicKey, mosaicMetadataTransactionBody.scopedMetadataKey, mosaicMetadataTransactionBody.targetMosaicId, mosaicMetadataTransactionBody.valueSizeDelta, mosaicMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.mosaicMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.mosaicMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets target mosaic identifier. + * + * @return Target mosaic identifier. + */ + public getTargetMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicMetadataTransactionBody.getTargetMosaicId(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.mosaicMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.mosaicMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicMetadataTransactionBodyBytes = this.mosaicMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicNonceDto.ts b/src/infrastructure/catbuffer/MosaicNonceDto.ts new file mode 100644 index 0000000000..82db3703e0 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicNonceDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Mosaic nonce. */ +export class MosaicNonceDto { + /** Mosaic nonce. */ + mosaicNonce: number; + + /** + * Constructor. + * + * @param mosaicNonce Mosaic nonce. + */ + constructor(mosaicNonce: number) { + this.mosaicNonce = mosaicNonce; + } + + /** + * Creates an instance of MosaicNonceDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicNonceDto. + */ + public static loadFromBinary(payload: Uint8Array): MosaicNonceDto { + const byteArray = Array.from(payload); + const mosaicNonce = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + return new MosaicNonceDto(mosaicNonce); + } + + /** + * Gets Mosaic nonce. + * + * @return Mosaic nonce. + */ + public getMosaicNonce(): number { + return this.mosaicNonce; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 4; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicNonceBytes = GeneratorUtils.uintToBuffer(this.getMosaicNonce(), 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicNonceBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicRestrictionTypeDto.ts b/src/infrastructure/catbuffer/MosaicRestrictionTypeDto.ts new file mode 100644 index 0000000000..78b5f8d179 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicRestrictionTypeDto.ts @@ -0,0 +1,39 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of mosaic restriction types. */ +export enum MosaicRestrictionTypeDto { + /** Uninitialized value indicating no restriction. */ + NONE = 0, + /** Allow if equal. */ + EQ = 1, + /** Allow if not equal. */ + NE = 2, + /** Allow if less than. */ + LT = 3, + /** Allow if less than or equal. */ + LE = 4, + /** Allow if greater than. */ + GT = 5, + /** Allow if greater than or equal. */ + GE = 6, +} diff --git a/src/infrastructure/catbuffer/MosaicSupplyChangeActionDto.ts b/src/infrastructure/catbuffer/MosaicSupplyChangeActionDto.ts new file mode 100644 index 0000000000..eafa2d5b4e --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicSupplyChangeActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of mosaic supply change actions. */ +export enum MosaicSupplyChangeActionDto { + /** Decreases the supply. */ + DECREASE = 0, + /** Increases the supply. */ + INCREASE = 1, +} diff --git a/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBodyBuilder.ts new file mode 100644 index 0000000000..6e9a680728 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBodyBuilder.ts @@ -0,0 +1,121 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicSupplyChangeActionDto } from './MosaicSupplyChangeActionDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a mosaic supply change transaction. */ +export class MosaicSupplyChangeTransactionBodyBuilder { + /** Affected mosaic identifier. */ + mosaicId: UnresolvedMosaicIdDto; + /** Supply change action. */ + action: MosaicSupplyChangeActionDto; + /** Change amount. */ + delta: AmountDto; + + /** + * Constructor. + * + * @param mosaicId Affected mosaic identifier. + * @param action Supply change action. + * @param delta Change amount. + */ + public constructor(mosaicId: UnresolvedMosaicIdDto, action: MosaicSupplyChangeActionDto, delta: AmountDto) { + this.mosaicId = mosaicId; + this.action = action; + this.delta = delta; + } + + /** + * Creates an instance of MosaicSupplyChangeTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicSupplyChangeTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicSupplyChangeTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const action = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const delta = AmountDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, delta.getSize()); + return new MosaicSupplyChangeTransactionBodyBuilder(mosaicId, action, delta); + } + + /** + * Gets affected mosaic identifier. + * + * @return Affected mosaic identifier. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicId; + } + + /** + * Gets supply change action. + * + * @return Supply change action. + */ + public getAction(): MosaicSupplyChangeActionDto { + return this.action; + } + + /** + * Gets change amount. + * + * @return Change amount. + */ + public getDelta(): AmountDto { + return this.delta; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += 1; // action + size += this.delta.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const actionBytes = GeneratorUtils.uintToBuffer(this.action, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, actionBytes); + const deltaBytes = this.delta.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, deltaBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder.ts new file mode 100644 index 0000000000..ae1c675729 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicSupplyChangeActionDto } from './MosaicSupplyChangeActionDto'; +import { MosaicSupplyChangeTransactionBodyBuilder } from './MosaicSupplyChangeTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a non-embedded mosaic supply change transaction. */ +export class MosaicSupplyChangeTransactionBuilder extends TransactionBuilder { + /** Mosaic supply change transaction body. */ + mosaicSupplyChangeTransactionBody: MosaicSupplyChangeTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaicId Affected mosaic identifier. + * @param action Supply change action. + * @param delta Change amount. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaicId: UnresolvedMosaicIdDto, action: MosaicSupplyChangeActionDto, delta: AmountDto) { + super(signature, signer, version, type, fee, deadline); + this.mosaicSupplyChangeTransactionBody = new MosaicSupplyChangeTransactionBodyBuilder(mosaicId, action, delta); + } + + /** + * Creates an instance of MosaicSupplyChangeTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicSupplyChangeTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicSupplyChangeTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicSupplyChangeTransactionBody = MosaicSupplyChangeTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicSupplyChangeTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicSupplyChangeTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicSupplyChangeTransactionBody.mosaicId, mosaicSupplyChangeTransactionBody.action, mosaicSupplyChangeTransactionBody.delta); + } + + /** + * Gets affected mosaic identifier. + * + * @return Affected mosaic identifier. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicSupplyChangeTransactionBody.getMosaicId(); + } + + /** + * Gets supply change action. + * + * @return Supply change action. + */ + public getAction(): MosaicSupplyChangeActionDto { + return this.mosaicSupplyChangeTransactionBody.getAction(); + } + + /** + * Gets change amount. + * + * @return Change amount. + */ + public getDelta(): AmountDto { + return this.mosaicSupplyChangeTransactionBody.getDelta(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicSupplyChangeTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicSupplyChangeTransactionBodyBytes = this.mosaicSupplyChangeTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicSupplyChangeTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBodyBuilder.ts new file mode 100644 index 0000000000..9f646f89cb --- /dev/null +++ b/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBodyBuilder.ts @@ -0,0 +1,131 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { CosignatoryModificationBuilder } from './CosignatoryModificationBuilder'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for a multisig account modification transaction. */ +export class MultisigAccountModificationTransactionBodyBuilder { + /** Relative change of the minimal number of cosignatories required when removing an account. */ + minRemovalDelta: number; + /** Relative change of the minimal number of cosignatories required when approving a transaction. */ + minApprovalDelta: number; + /** Attached cosignatory modifications. */ + modifications: CosignatoryModificationBuilder[]; + + /** + * Constructor. + * + * @param minRemovalDelta Relative change of the minimal number of cosignatories required when removing an account. + * @param minApprovalDelta Relative change of the minimal number of cosignatories required when approving a transaction. + * @param modifications Attached cosignatory modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(minRemovalDelta: number, minApprovalDelta: number, modifications: CosignatoryModificationBuilder[]) { + this.minRemovalDelta = minRemovalDelta; + this.minApprovalDelta = minApprovalDelta; + this.modifications = modifications; + } + + /** + * Creates an instance of MultisigAccountModificationTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MultisigAccountModificationTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MultisigAccountModificationTransactionBodyBuilder { + const byteArray = Array.from(payload); + const minRemovalDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const minApprovalDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modificationsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modifications: CosignatoryModificationBuilder[] = []; + for (let i = 0; i < modificationsCount; i++) { + const item = CosignatoryModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + modifications.push(item); + byteArray.splice(0, item.getSize()); + } + return new MultisigAccountModificationTransactionBodyBuilder(minRemovalDelta, minApprovalDelta, modifications); + } + + /** + * Gets relative change of the minimal number of cosignatories required when removing an account. + * + * @return Relative change of the minimal number of cosignatories required when removing an account. + */ + public getMinRemovalDelta(): number { + return this.minRemovalDelta; + } + + /** + * Gets relative change of the minimal number of cosignatories required when approving a transaction. + * + * @return Relative change of the minimal number of cosignatories required when approving a transaction. + */ + public getMinApprovalDelta(): number { + return this.minApprovalDelta; + } + + /** + * Gets attached cosignatory modifications. + * + * @return Attached cosignatory modifications. + */ + public getModifications(): CosignatoryModificationBuilder[] { + return this.modifications; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // minRemovalDelta + size += 1; // minApprovalDelta + size += 1; // modificationsCount + this.modifications.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const minRemovalDeltaBytes = GeneratorUtils.uintToBuffer(this.getMinRemovalDelta(), 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, minRemovalDeltaBytes); + const minApprovalDeltaBytes = GeneratorUtils.uintToBuffer(this.getMinApprovalDelta(), 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, minApprovalDeltaBytes); + const modificationsCountBytes = GeneratorUtils.uintToBuffer(this.modifications.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsCountBytes); + this.modifications.forEach((item) => { + const modificationsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder.ts b/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder.ts new file mode 100644 index 0000000000..4405bdc6ca --- /dev/null +++ b/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { CosignatoryModificationBuilder } from './CosignatoryModificationBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MultisigAccountModificationTransactionBodyBuilder } from './MultisigAccountModificationTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded multisig account modification transaction. */ +export class MultisigAccountModificationTransactionBuilder extends TransactionBuilder { + /** Multisig account modification transaction body. */ + multisigAccountModificationTransactionBody: MultisigAccountModificationTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param minRemovalDelta Relative change of the minimal number of cosignatories required when removing an account. + * @param minApprovalDelta Relative change of the minimal number of cosignatories required when approving a transaction. + * @param modifications Attached cosignatory modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, minRemovalDelta: number, minApprovalDelta: number, modifications: CosignatoryModificationBuilder[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.multisigAccountModificationTransactionBody = new MultisigAccountModificationTransactionBodyBuilder(minRemovalDelta, minApprovalDelta, modifications); + } + + /** + * Creates an instance of MultisigAccountModificationTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MultisigAccountModificationTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MultisigAccountModificationTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const multisigAccountModificationTransactionBody = MultisigAccountModificationTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, multisigAccountModificationTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MultisigAccountModificationTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, multisigAccountModificationTransactionBody.minRemovalDelta, multisigAccountModificationTransactionBody.minApprovalDelta, multisigAccountModificationTransactionBody.modifications); + } + + /** + * Gets relative change of the minimal number of cosignatories required when removing an account. + * + * @return Relative change of the minimal number of cosignatories required when removing an account. + */ + public getMinRemovalDelta(): number { + return this.multisigAccountModificationTransactionBody.getMinRemovalDelta(); + } + + /** + * Gets relative change of the minimal number of cosignatories required when approving a transaction. + * + * @return Relative change of the minimal number of cosignatories required when approving a transaction. + */ + public getMinApprovalDelta(): number { + return this.multisigAccountModificationTransactionBody.getMinApprovalDelta(); + } + + /** + * Gets attached cosignatory modifications. + * + * @return Attached cosignatory modifications. + */ + public getModifications(): CosignatoryModificationBuilder[] { + return this.multisigAccountModificationTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.multisigAccountModificationTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const multisigAccountModificationTransactionBodyBytes = this.multisigAccountModificationTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, multisigAccountModificationTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceIdDto.ts b/src/infrastructure/catbuffer/NamespaceIdDto.ts new file mode 100644 index 0000000000..498f63dbe3 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceIdDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Namespace id. */ +export class NamespaceIdDto { + /** Namespace id. */ + namespaceId: number[]; + + /** + * Constructor. + * + * @param namespaceId Namespace id. + */ + constructor(namespaceId: number[]) { + this.namespaceId = namespaceId; + } + + /** + * Creates an instance of NamespaceIdDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceIdDto. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceIdDto { + const byteArray = Array.from(payload); + const namespaceId = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new NamespaceIdDto(namespaceId); + } + + /** + * Gets Namespace id. + * + * @return Namespace id. + */ + public getNamespaceId(): number[] { + return this.namespaceId; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const namespaceIdBytes = GeneratorUtils.uint64ToBuffer(this.getNamespaceId()); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceIdBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceMetadataTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/NamespaceMetadataTransactionBodyBuilder.ts new file mode 100644 index 0000000000..f460ab3c25 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceMetadataTransactionBodyBuilder.ts @@ -0,0 +1,168 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for a namespace metadata transaction. */ +export class NamespaceMetadataTransactionBodyBuilder { + /** Metadata target public key. */ + targetPublicKey: KeyDto; + /** Metadata key scoped to source, target and type. */ + scopedMetadataKey: number[]; + /** Target namespace identifier. */ + targetNamespaceId: NamespaceIdDto; + /** Change in value size in bytes. */ + valueSizeDelta: number; + /** Difference between existing value and new value \note when there is no existing value, new value is same this value \note when there is an existing value, new value is calculated as xor(previous-value, value). */ + value: Uint8Array; + + /** + * Constructor. + * + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetNamespaceId Target namespace identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(targetPublicKey: KeyDto, scopedMetadataKey: number[], targetNamespaceId: NamespaceIdDto, valueSizeDelta: number, value: Uint8Array) { + this.targetPublicKey = targetPublicKey; + this.scopedMetadataKey = scopedMetadataKey; + this.targetNamespaceId = targetNamespaceId; + this.valueSizeDelta = valueSizeDelta; + this.value = value; + } + + /** + * Creates an instance of NamespaceMetadataTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceMetadataTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceMetadataTransactionBodyBuilder { + const byteArray = Array.from(payload); + const targetPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetPublicKey.getSize()); + const scopedMetadataKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const targetNamespaceId = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetNamespaceId.getSize()); + const valueSizeDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const valueSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const value = GeneratorUtils.getBytes(Uint8Array.from(byteArray), valueSize); + byteArray.splice(0, valueSize); + // tslint:disable-next-line: max-line-length + return new NamespaceMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetNamespaceId, valueSizeDelta, value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.targetPublicKey; + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.scopedMetadataKey; + } + + /** + * Gets target namespace identifier. + * + * @return Target namespace identifier. + */ + public getTargetNamespaceId(): NamespaceIdDto { + return this.targetNamespaceId; + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.valueSizeDelta; + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.targetPublicKey.getSize(); + size += 8; // scopedMetadataKey + size += this.targetNamespaceId.getSize(); + size += 2; // valueSizeDelta + size += 2; // valueSize + size += this.value.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const targetPublicKeyBytes = this.targetPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetPublicKeyBytes); + const scopedMetadataKeyBytes = GeneratorUtils.uint64ToBuffer(this.getScopedMetadataKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, scopedMetadataKeyBytes); + const targetNamespaceIdBytes = this.targetNamespaceId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetNamespaceIdBytes); + const valueSizeDeltaBytes = GeneratorUtils.uintToBuffer(this.getValueSizeDelta(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeDeltaBytes); + const valueSizeBytes = GeneratorUtils.uintToBuffer(this.value.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.value); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/NamespaceMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..6b4b2e4885 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceMetadataTransactionBuilder.ts @@ -0,0 +1,151 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceMetadataTransactionBodyBuilder } from './NamespaceMetadataTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded namespace metadata transaction. */ +export class NamespaceMetadataTransactionBuilder extends TransactionBuilder { + /** Namespace metadata transaction body. */ + namespaceMetadataTransactionBody: NamespaceMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetNamespaceId Target namespace identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], targetNamespaceId: NamespaceIdDto, valueSizeDelta: number, value: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.namespaceMetadataTransactionBody = new NamespaceMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetNamespaceId, valueSizeDelta, value); + } + + /** + * Creates an instance of NamespaceMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const namespaceMetadataTransactionBody = NamespaceMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new NamespaceMetadataTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, namespaceMetadataTransactionBody.targetPublicKey, namespaceMetadataTransactionBody.scopedMetadataKey, namespaceMetadataTransactionBody.targetNamespaceId, namespaceMetadataTransactionBody.valueSizeDelta, namespaceMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.namespaceMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.namespaceMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets target namespace identifier. + * + * @return Target namespace identifier. + */ + public getTargetNamespaceId(): NamespaceIdDto { + return this.namespaceMetadataTransactionBody.getTargetNamespaceId(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.namespaceMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.namespaceMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.namespaceMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const namespaceMetadataTransactionBodyBytes = this.namespaceMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBodyBuilder.ts new file mode 100644 index 0000000000..465636812f --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBodyBuilder.ts @@ -0,0 +1,188 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceRegistrationTypeDto } from './NamespaceRegistrationTypeDto'; + +/** Binary layout for a namespace registration transaction. */ +export class NamespaceRegistrationTransactionBodyBuilder { + /** Namespace registration type. */ + registrationType: NamespaceRegistrationTypeDto; + /** Namespace duration. */ + duration?: BlockDurationDto; + /** Parent namespace identifier. */ + parentId?: NamespaceIdDto; + /** Namespace identifier. */ + id: NamespaceIdDto; + /** Namespace name. */ + name: Uint8Array; + + /** + * Constructor. + * + * @param duration Namespace duration. + * @param parentId Parent namespace identifier. + * @param id Namespace identifier. + * @param name Namespace name. + */ + public constructor(id: NamespaceIdDto, name: Uint8Array, duration?: BlockDurationDto, parentId?: NamespaceIdDto) { + if ((duration && parentId) || (!duration && !parentId)) { + throw new Error('Invalid conditional parameters'); + } + this.duration = duration; + this.parentId = parentId; + this.id = id; + this.name = name; + if (duration) { + this.registrationType = NamespaceRegistrationTypeDto.ROOT; + } + if (parentId) { + this.registrationType = NamespaceRegistrationTypeDto.CHILD; + } + } + + /** + * Creates an instance of NamespaceRegistrationTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceRegistrationTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceRegistrationTransactionBodyBuilder { + const byteArray = Array.from(payload); + const registrationType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + let duration; + if (registrationType === NamespaceRegistrationTypeDto.ROOT) { + duration = BlockDurationDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, duration.getSize()); + } + let parentId; + if (registrationType === NamespaceRegistrationTypeDto.CHILD) { + parentId = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, parentId.getSize()); + } + const id = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, id.getSize()); + const nameSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const name = GeneratorUtils.getBytes(Uint8Array.from(byteArray), nameSize); + byteArray.splice(0, nameSize); + return new NamespaceRegistrationTransactionBodyBuilder(id, name, duration, parentId); + } + + /** + * Gets namespace registration type. + * + * @return Namespace registration type. + */ + public getRegistrationType(): NamespaceRegistrationTypeDto { + return this.registrationType; + } + + /** + * Gets namespace duration. + * + * @return Namespace duration. + */ + public getDuration(): BlockDurationDto | undefined { + if (this.registrationType !== NamespaceRegistrationTypeDto.ROOT) { + throw new Error('registrationType is not set to ROOT.'); + } + return this.duration; + } + + /** + * Gets parent namespace identifier. + * + * @return Parent namespace identifier. + */ + public getParentId(): NamespaceIdDto | undefined { + if (this.registrationType !== NamespaceRegistrationTypeDto.CHILD) { + throw new Error('registrationType is not set to CHILD.'); + } + return this.parentId; + } + + /** + * Gets namespace identifier. + * + * @return Namespace identifier. + */ + public getId(): NamespaceIdDto { + return this.id; + } + + /** + * Gets namespace name. + * + * @return Namespace name. + */ + public getName(): Uint8Array { + return this.name; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // registrationType + if (this.registrationType === NamespaceRegistrationTypeDto.ROOT) { + size += this.duration!.getSize(); + } + if (this.registrationType === NamespaceRegistrationTypeDto.CHILD) { + size += this.parentId!.getSize(); + } + size += this.id.getSize(); + size += 1; // nameSize + size += this.name.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const registrationTypeBytes = GeneratorUtils.uintToBuffer(this.registrationType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, registrationTypeBytes); + if (this.registrationType === NamespaceRegistrationTypeDto.ROOT) { + const durationBytes = this.duration!.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, durationBytes); + } + if (this.registrationType === NamespaceRegistrationTypeDto.CHILD) { + const parentIdBytes = this.parentId!.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, parentIdBytes); + } + const idBytes = this.id.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, idBytes); + const nameSizeBytes = GeneratorUtils.uintToBuffer(this.name.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, nameSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.name); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder.ts b/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder.ts new file mode 100644 index 0000000000..a9e96db248 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder.ts @@ -0,0 +1,149 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { BlockDurationDto } from './BlockDurationDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceRegistrationTransactionBodyBuilder } from './NamespaceRegistrationTransactionBodyBuilder'; +import { NamespaceRegistrationTypeDto } from './NamespaceRegistrationTypeDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded namespace registration transaction. */ +export class NamespaceRegistrationTransactionBuilder extends TransactionBuilder { + /** Namespace registration transaction body. */ + namespaceRegistrationTransactionBody: NamespaceRegistrationTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param duration Namespace duration. + * @param parentId Parent namespace identifier. + * @param id Namespace identifier. + * @param name Namespace name. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, id: NamespaceIdDto, name: Uint8Array, duration?: BlockDurationDto, parentId?: NamespaceIdDto) { + super(signature, signer, version, type, fee, deadline); + if ((duration && parentId) || (!duration && !parentId)) { + throw new Error('Invalid conditional parameters'); + } + // tslint:disable-next-line: max-line-length + this.namespaceRegistrationTransactionBody = new NamespaceRegistrationTransactionBodyBuilder(id, name, duration, parentId); + } + + /** + * Creates an instance of NamespaceRegistrationTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceRegistrationTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceRegistrationTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const namespaceRegistrationTransactionBody = NamespaceRegistrationTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceRegistrationTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new NamespaceRegistrationTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, namespaceRegistrationTransactionBody.id, namespaceRegistrationTransactionBody.name, namespaceRegistrationTransactionBody.duration, namespaceRegistrationTransactionBody.parentId); + } + + /** + * Gets namespace registration type. + * + * @return Namespace registration type. + */ + public getRegistrationType(): NamespaceRegistrationTypeDto { + return this.namespaceRegistrationTransactionBody.getRegistrationType(); + } + + /** + * Gets namespace duration. + * + * @return Namespace duration. + */ + public getDuration(): BlockDurationDto | undefined { + return this.namespaceRegistrationTransactionBody.getDuration(); + } + + /** + * Gets parent namespace identifier. + * + * @return Parent namespace identifier. + */ + public getParentId(): NamespaceIdDto | undefined { + return this.namespaceRegistrationTransactionBody.getParentId(); + } + + /** + * Gets namespace identifier. + * + * @return Namespace identifier. + */ + public getId(): NamespaceIdDto { + return this.namespaceRegistrationTransactionBody.getId(); + } + + /** + * Gets namespace name. + * + * @return Namespace name. + */ + public getName(): Uint8Array { + return this.namespaceRegistrationTransactionBody.getName(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.namespaceRegistrationTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const namespaceRegistrationTransactionBodyBytes = this.namespaceRegistrationTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceRegistrationTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceRegistrationTypeDto.ts b/src/infrastructure/catbuffer/NamespaceRegistrationTypeDto.ts new file mode 100644 index 0000000000..349db68025 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceRegistrationTypeDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of namespace registration types. */ +export enum NamespaceRegistrationTypeDto { + /** Root namespace. */ + ROOT = 0, + /** Child namespace. */ + CHILD = 1, +} diff --git a/src/infrastructure/catbuffer/SecretLockTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/SecretLockTransactionBodyBuilder.ts new file mode 100644 index 0000000000..a38da76d77 --- /dev/null +++ b/src/infrastructure/catbuffer/SecretLockTransactionBodyBuilder.ts @@ -0,0 +1,160 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a secret lock transaction. */ +export class SecretLockTransactionBodyBuilder { + /** Locked mosaic. */ + mosaic: UnresolvedMosaicBuilder; + /** Number of blocks for which a lock should be valid. */ + duration: BlockDurationDto; + /** Hash algorithm. */ + hashAlgorithm: LockHashAlgorithmDto; + /** Secret. */ + secret: Hash256Dto; + /** Locked mosaic recipient. */ + recipient: UnresolvedAddressDto; + + /** + * Constructor. + * + * @param mosaic Locked mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Locked mosaic recipient. + */ + // tslint:disable-next-line: max-line-length + public constructor(mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto) { + this.mosaic = mosaic; + this.duration = duration; + this.hashAlgorithm = hashAlgorithm; + this.secret = secret; + this.recipient = recipient; + } + + /** + * Creates an instance of SecretLockTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SecretLockTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): SecretLockTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaic = UnresolvedMosaicBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaic.getSize()); + const duration = BlockDurationDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, duration.getSize()); + const hashAlgorithm = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const secret = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secret.getSize()); + const recipient = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, recipient.getSize()); + return new SecretLockTransactionBodyBuilder(mosaic, duration, hashAlgorithm, secret, recipient); + } + + /** + * Gets locked mosaic. + * + * @return Locked mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.mosaic; + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.duration; + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.hashAlgorithm; + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secret; + } + + /** + * Gets locked mosaic recipient. + * + * @return Locked mosaic recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.recipient; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaic.getSize(); + size += this.duration.getSize(); + size += 1; // hashAlgorithm + size += this.secret.getSize(); + size += this.recipient.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicBytes = this.mosaic.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicBytes); + const durationBytes = this.duration.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, durationBytes); + const hashAlgorithmBytes = GeneratorUtils.uintToBuffer(this.hashAlgorithm, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashAlgorithmBytes); + const secretBytes = this.secret.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretBytes); + const recipientBytes = this.recipient.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, recipientBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/SecretLockTransactionBuilder.ts b/src/infrastructure/catbuffer/SecretLockTransactionBuilder.ts new file mode 100644 index 0000000000..3f99ae1dd0 --- /dev/null +++ b/src/infrastructure/catbuffer/SecretLockTransactionBuilder.ts @@ -0,0 +1,148 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { BlockDurationDto } from './BlockDurationDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { KeyDto } from './KeyDto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { SecretLockTransactionBodyBuilder } from './SecretLockTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a non-embedded secret lock transaction. */ +export class SecretLockTransactionBuilder extends TransactionBuilder { + /** Secret lock transaction body. */ + secretLockTransactionBody: SecretLockTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaic Locked mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Locked mosaic recipient. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.secretLockTransactionBody = new SecretLockTransactionBodyBuilder(mosaic, duration, hashAlgorithm, secret, recipient); + } + + /** + * Creates an instance of SecretLockTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SecretLockTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): SecretLockTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const secretLockTransactionBody = SecretLockTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secretLockTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new SecretLockTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, secretLockTransactionBody.mosaic, secretLockTransactionBody.duration, secretLockTransactionBody.hashAlgorithm, secretLockTransactionBody.secret, secretLockTransactionBody.recipient); + } + + /** + * Gets locked mosaic. + * + * @return Locked mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.secretLockTransactionBody.getMosaic(); + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.secretLockTransactionBody.getDuration(); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.secretLockTransactionBody.getHashAlgorithm(); + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secretLockTransactionBody.getSecret(); + } + + /** + * Gets locked mosaic recipient. + * + * @return Locked mosaic recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.secretLockTransactionBody.getRecipient(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.secretLockTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const secretLockTransactionBodyBytes = this.secretLockTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretLockTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/SecretProofTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/SecretProofTransactionBodyBuilder.ts new file mode 100644 index 0000000000..ba7a2a1fa2 --- /dev/null +++ b/src/infrastructure/catbuffer/SecretProofTransactionBodyBuilder.ts @@ -0,0 +1,144 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; + +/** Binary layout for a secret proof transaction. */ +export class SecretProofTransactionBodyBuilder { + /** Hash algorithm. */ + hashAlgorithm: LockHashAlgorithmDto; + /** Secret. */ + secret: Hash256Dto; + /** Recipient. */ + recipient: UnresolvedAddressDto; + /** Proof data. */ + proof: Uint8Array; + + /** + * Constructor. + * + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Recipient. + * @param proof Proof data. + */ + // tslint:disable-next-line: max-line-length + public constructor(hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto, proof: Uint8Array) { + this.hashAlgorithm = hashAlgorithm; + this.secret = secret; + this.recipient = recipient; + this.proof = proof; + } + + /** + * Creates an instance of SecretProofTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SecretProofTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): SecretProofTransactionBodyBuilder { + const byteArray = Array.from(payload); + const hashAlgorithm = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const secret = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secret.getSize()); + const recipient = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, recipient.getSize()); + const proofSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const proof = GeneratorUtils.getBytes(Uint8Array.from(byteArray), proofSize); + byteArray.splice(0, proofSize); + return new SecretProofTransactionBodyBuilder(hashAlgorithm, secret, recipient, proof); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.hashAlgorithm; + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secret; + } + + /** + * Gets recipient. + * + * @return Recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.recipient; + } + + /** + * Gets proof data. + * + * @return Proof data. + */ + public getProof(): Uint8Array { + return this.proof; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // hashAlgorithm + size += this.secret.getSize(); + size += this.recipient.getSize(); + size += 2; // proofSize + size += this.proof.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const hashAlgorithmBytes = GeneratorUtils.uintToBuffer(this.hashAlgorithm, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashAlgorithmBytes); + const secretBytes = this.secret.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretBytes); + const recipientBytes = this.recipient.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, recipientBytes); + const proofSizeBytes = GeneratorUtils.uintToBuffer(this.proof.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, proofSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.proof); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/SecretProofTransactionBuilder.ts b/src/infrastructure/catbuffer/SecretProofTransactionBuilder.ts new file mode 100644 index 0000000000..445a74e418 --- /dev/null +++ b/src/infrastructure/catbuffer/SecretProofTransactionBuilder.ts @@ -0,0 +1,135 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { KeyDto } from './KeyDto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { SecretProofTransactionBodyBuilder } from './SecretProofTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; + +/** Binary layout for a non-embedded secret proof transaction. */ +export class SecretProofTransactionBuilder extends TransactionBuilder { + /** Secret proof transaction body. */ + secretProofTransactionBody: SecretProofTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Recipient. + * @param proof Proof data. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto, proof: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + this.secretProofTransactionBody = new SecretProofTransactionBodyBuilder(hashAlgorithm, secret, recipient, proof); + } + + /** + * Creates an instance of SecretProofTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SecretProofTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): SecretProofTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const secretProofTransactionBody = SecretProofTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secretProofTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new SecretProofTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, secretProofTransactionBody.hashAlgorithm, secretProofTransactionBody.secret, secretProofTransactionBody.recipient, secretProofTransactionBody.proof); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.secretProofTransactionBody.getHashAlgorithm(); + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secretProofTransactionBody.getSecret(); + } + + /** + * Gets recipient. + * + * @return Recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.secretProofTransactionBody.getRecipient(); + } + + /** + * Gets proof data. + * + * @return Proof data. + */ + public getProof(): Uint8Array { + return this.secretProofTransactionBody.getProof(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.secretProofTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const secretProofTransactionBodyBytes = this.secretProofTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretProofTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/SignatureDto.ts b/src/infrastructure/catbuffer/SignatureDto.ts new file mode 100644 index 0000000000..307efb2b50 --- /dev/null +++ b/src/infrastructure/catbuffer/SignatureDto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Signature. */ +export class SignatureDto { + /** Signature. */ + signature: Uint8Array; + + /** + * Constructor. + * + * @param signature Signature. + */ + constructor(signature: Uint8Array) { + this.signature = signature; + } + + /** + * Creates an instance of SignatureDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SignatureDto. + */ + public static loadFromBinary(payload: Uint8Array): SignatureDto { + const byteArray = Array.from(payload); + const signature = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 64); + byteArray.splice(0, 64); + return new SignatureDto(signature); + } + + /** + * Gets Signature. + * + * @return Signature. + */ + public getSignature(): Uint8Array { + return this.signature; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 64; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.signature); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/TimestampDto.ts b/src/infrastructure/catbuffer/TimestampDto.ts new file mode 100644 index 0000000000..af3de24b9e --- /dev/null +++ b/src/infrastructure/catbuffer/TimestampDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Timestamp. */ +export class TimestampDto { + /** Timestamp. */ + timestamp: number[]; + + /** + * Constructor. + * + * @param timestamp Timestamp. + */ + constructor(timestamp: number[]) { + this.timestamp = timestamp; + } + + /** + * Creates an instance of TimestampDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of TimestampDto. + */ + public static loadFromBinary(payload: Uint8Array): TimestampDto { + const byteArray = Array.from(payload); + const timestamp = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new TimestampDto(timestamp); + } + + /** + * Gets Timestamp. + * + * @return Timestamp. + */ + public getTimestamp(): number[] { + return this.timestamp; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const timestampBytes = GeneratorUtils.uint64ToBuffer(this.getTimestamp()); + newArray = GeneratorUtils.concatTypedArrays(newArray, timestampBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/TransactionBuilder.ts b/src/infrastructure/catbuffer/TransactionBuilder.ts new file mode 100644 index 0000000000..e50a3024be --- /dev/null +++ b/src/infrastructure/catbuffer/TransactionBuilder.ts @@ -0,0 +1,185 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; + +/** Binary layout for a transaction. */ +export class TransactionBuilder { + /** Entity size. */ + size = 0; + /** Entity signature. */ + signature: SignatureDto; + /** Entity signer's public key. */ + signer: KeyDto; + /** Entity version. */ + version: number; + /** Entity type. */ + type: EntityTypeDto; + /** Transaction fee. */ + fee: AmountDto; + /** Transaction deadline. */ + deadline: TimestampDto; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto) { + this.signature = signature; + this.signer = signer; + this.version = version; + this.type = type; + this.fee = fee; + this.deadline = deadline; + } + + /** + * Creates an instance of TransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of TransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): TransactionBuilder { + const byteArray = Array.from(payload); + const size = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + const signature = SignatureDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signature.getSize()); + const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signer.getSize()); + const version = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const type = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const fee = AmountDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, fee.getSize()); + const deadline = TimestampDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, deadline.getSize()); + return new TransactionBuilder(signature, signer, version, type, fee, deadline); + } + + /** + * Gets entity signature. + * + * @return Entity signature. + */ + public getSignature(): SignatureDto { + return this.signature; + } + + /** + * Gets entity signer's public key. + * + * @return Entity signer's public key. + */ + public getSigner(): KeyDto { + return this.signer; + } + + /** + * Gets entity version. + * + * @return Entity version. + */ + public getVersion(): number { + return this.version; + } + + /** + * Gets entity type. + * + * @return Entity type. + */ + public getType(): EntityTypeDto { + return this.type; + } + + /** + * Gets transaction fee.. + * + * @return Transaction fee. + */ + public getFee(): AmountDto { + return this.fee; + } + + /** + * Gets transaction deadline. + * + * @return Transaction deadline. + */ + public getDeadline(): TimestampDto { + return this.deadline; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 4; // size + size += this.signature.getSize(); + size += this.signer.getSize(); + size += 2; // version + size += 2; // type + size += this.fee.getSize(); + size += this.deadline.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const sizeBytes = GeneratorUtils.uintToBuffer(this.getSize(), 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, sizeBytes); + const signatureBytes = this.signature.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signatureBytes); + const signerBytes = this.signer.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); + const versionBytes = GeneratorUtils.uintToBuffer(this.getVersion(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, versionBytes); + const typeBytes = GeneratorUtils.uintToBuffer(this.type, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, typeBytes); + const feeBytes = this.fee.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, feeBytes); + const deadlineBytes = this.deadline.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, deadlineBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/TransferTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/TransferTransactionBodyBuilder.ts new file mode 100644 index 0000000000..e0ee7daed1 --- /dev/null +++ b/src/infrastructure/catbuffer/TransferTransactionBodyBuilder.ts @@ -0,0 +1,135 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a transfer transaction. */ +export class TransferTransactionBodyBuilder { + /** Transaction recipient. */ + recipient: UnresolvedAddressDto; + /** Transaction message. */ + message: Uint8Array; + /** Attached mosaics. */ + mosaics: UnresolvedMosaicBuilder[]; + + /** + * Constructor. + * + * @param recipient Transaction recipient. + * @param message Transaction message. + * @param mosaics Attached mosaics. + */ + public constructor(recipient: UnresolvedAddressDto, message: Uint8Array, mosaics: UnresolvedMosaicBuilder[]) { + this.recipient = recipient; + this.message = message; + this.mosaics = mosaics; + } + + /** + * Creates an instance of TransferTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of TransferTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): TransferTransactionBodyBuilder { + const byteArray = Array.from(payload); + const recipient = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, recipient.getSize()); + const messageSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const mosaicsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const message = GeneratorUtils.getBytes(Uint8Array.from(byteArray), messageSize); + byteArray.splice(0, messageSize); + const mosaics: UnresolvedMosaicBuilder[] = []; + for (let i = 0; i < mosaicsCount; i++) { + const item = UnresolvedMosaicBuilder.loadFromBinary(Uint8Array.from(byteArray)); + mosaics.push(item); + byteArray.splice(0, item.getSize()); + } + return new TransferTransactionBodyBuilder(recipient, message, mosaics); + } + + /** + * Gets transaction recipient. + * + * @return Transaction recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.recipient; + } + + /** + * Gets transaction message. + * + * @return Transaction message. + */ + public getMessage(): Uint8Array { + return this.message; + } + + /** + * Gets attached mosaics. + * + * @return Attached mosaics. + */ + public getMosaics(): UnresolvedMosaicBuilder[] { + return this.mosaics; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.recipient.getSize(); + size += 2; // messageSize + size += 1; // mosaicsCount + size += this.message.length; + this.mosaics.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const recipientBytes = this.recipient.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, recipientBytes); + const messageSizeBytes = GeneratorUtils.uintToBuffer(this.message.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, messageSizeBytes); + const mosaicsCountBytes = GeneratorUtils.uintToBuffer(this.mosaics.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicsCountBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.message); + this.mosaics.forEach((item) => { + const mosaicsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/TransferTransactionBuilder.ts b/src/infrastructure/catbuffer/TransferTransactionBuilder.ts new file mode 100644 index 0000000000..722d79409a --- /dev/null +++ b/src/infrastructure/catbuffer/TransferTransactionBuilder.ts @@ -0,0 +1,124 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { TransferTransactionBodyBuilder } from './TransferTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a non-embedded transfer transaction. */ +export class TransferTransactionBuilder extends TransactionBuilder { + /** Transfer transaction body. */ + transferTransactionBody: TransferTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param recipient Transaction recipient. + * @param message Transaction message. + * @param mosaics Attached mosaics. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, recipient: UnresolvedAddressDto, message: Uint8Array, mosaics: UnresolvedMosaicBuilder[]) { + super(signature, signer, version, type, fee, deadline); + this.transferTransactionBody = new TransferTransactionBodyBuilder(recipient, message, mosaics); + } + + /** + * Creates an instance of TransferTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of TransferTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): TransferTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const transferTransactionBody = TransferTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, transferTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new TransferTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, transferTransactionBody.recipient, transferTransactionBody.message, transferTransactionBody.mosaics); + } + + /** + * Gets transaction recipient. + * + * @return Transaction recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.transferTransactionBody.getRecipient(); + } + + /** + * Gets transaction message. + * + * @return Transaction message. + */ + public getMessage(): Uint8Array { + return this.transferTransactionBody.getMessage(); + } + + /** + * Gets attached mosaics. + * + * @return Attached mosaics. + */ + public getMosaics(): UnresolvedMosaicBuilder[] { + return this.transferTransactionBody.getMosaics(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.transferTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const transferTransactionBodyBytes = this.transferTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, transferTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/UnresolvedAddressDto.ts b/src/infrastructure/catbuffer/UnresolvedAddressDto.ts new file mode 100644 index 0000000000..2a0748d76d --- /dev/null +++ b/src/infrastructure/catbuffer/UnresolvedAddressDto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Unresolved address. */ +export class UnresolvedAddressDto { + /** Unresolved address. */ + unresolvedAddress: Uint8Array; + + /** + * Constructor. + * + * @param unresolvedAddress Unresolved address. + */ + constructor(unresolvedAddress: Uint8Array) { + this.unresolvedAddress = unresolvedAddress; + } + + /** + * Creates an instance of UnresolvedAddressDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of UnresolvedAddressDto. + */ + public static loadFromBinary(payload: Uint8Array): UnresolvedAddressDto { + const byteArray = Array.from(payload); + const unresolvedAddress = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 25); + byteArray.splice(0, 25); + return new UnresolvedAddressDto(unresolvedAddress); + } + + /** + * Gets Unresolved address. + * + * @return Unresolved address. + */ + public getUnresolvedAddress(): Uint8Array { + return this.unresolvedAddress; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 25; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.unresolvedAddress); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/UnresolvedMosaicBuilder.ts b/src/infrastructure/catbuffer/UnresolvedMosaicBuilder.ts new file mode 100644 index 0000000000..5091228ad9 --- /dev/null +++ b/src/infrastructure/catbuffer/UnresolvedMosaicBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an unresolved mosaic. */ +export class UnresolvedMosaicBuilder { + /** Mosaic identifier. */ + mosaicId: UnresolvedMosaicIdDto; + /** Mosaic amount. */ + amount: AmountDto; + + /** + * Constructor. + * + * @param mosaicId Mosaic identifier. + * @param amount Mosaic amount. + */ + public constructor(mosaicId: UnresolvedMosaicIdDto, amount: AmountDto) { + this.mosaicId = mosaicId; + this.amount = amount; + } + + /** + * Creates an instance of UnresolvedMosaicBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of UnresolvedMosaicBuilder. + */ + public static loadFromBinary(payload: Uint8Array): UnresolvedMosaicBuilder { + const byteArray = Array.from(payload); + const mosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const amount = AmountDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, amount.getSize()); + return new UnresolvedMosaicBuilder(mosaicId, amount); + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicId; + } + + /** + * Gets mosaic amount. + * + * @return Mosaic amount. + */ + public getAmount(): AmountDto { + return this.amount; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += this.amount.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const amountBytes = this.amount.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, amountBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/UnresolvedMosaicIdDto.ts b/src/infrastructure/catbuffer/UnresolvedMosaicIdDto.ts new file mode 100644 index 0000000000..8b49a58aea --- /dev/null +++ b/src/infrastructure/catbuffer/UnresolvedMosaicIdDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Unresolved mosaic id. */ +export class UnresolvedMosaicIdDto { + /** Unresolved mosaic id. */ + unresolvedMosaicId: number[]; + + /** + * Constructor. + * + * @param unresolvedMosaicId Unresolved mosaic id. + */ + constructor(unresolvedMosaicId: number[]) { + this.unresolvedMosaicId = unresolvedMosaicId; + } + + /** + * Creates an instance of UnresolvedMosaicIdDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of UnresolvedMosaicIdDto. + */ + public static loadFromBinary(payload: Uint8Array): UnresolvedMosaicIdDto { + const byteArray = Array.from(payload); + const unresolvedMosaicId = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new UnresolvedMosaicIdDto(unresolvedMosaicId); + } + + /** + * Gets Unresolved mosaic id. + * + * @return Unresolved mosaic id. + */ + public getUnresolvedMosaicId(): number[] { + return this.unresolvedMosaicId; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const unresolvedMosaicIdBytes = GeneratorUtils.uint64ToBuffer(this.getUnresolvedMosaicId()); + newArray = GeneratorUtils.concatTypedArrays(newArray, unresolvedMosaicIdBytes); + return newArray; + } +} diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index 2205ed1d37..e6a1e3d7ae 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -24,10 +24,10 @@ import {MosaicId} from '../../model/mosaic/MosaicId'; import {MosaicProperties} from '../../model/mosaic/MosaicProperties'; import { MosaicPropertyType } from '../../model/mosaic/MosaicPropertyType'; import {NamespaceId} from '../../model/namespace/NamespaceId'; -import {AccountAddressRestrictionModificationTransaction} from '../../model/transaction/AccountAddressRestrictionModificationTransaction'; +import {AccountAddressRestrictionTransaction} from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; -import {AccountMosaicRestrictionModificationTransaction} from '../../model/transaction/AccountMosaicRestrictionModificationTransaction'; -import {AccountOperationRestrictionModificationTransaction} from '../../model/transaction/AccountOperationRestrictionModificationTransaction'; +import {AccountMosaicRestrictionTransaction} from '../../model/transaction/AccountMosaicRestrictionTransaction'; +import {AccountOperationRestrictionTransaction} from '../../model/transaction/AccountOperationRestrictionTransaction'; import {AccountRestrictionModification} from '../../model/transaction/AccountRestrictionModification'; import {AddressAliasTransaction} from '../../model/transaction/AddressAliasTransaction'; import {AggregateTransaction} from '../../model/transaction/AggregateTransaction'; @@ -280,8 +280,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr extractNetworkType(transactionDTO.version)) : undefined, transactionInfo, ); - } else if (transactionDTO.type === TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS) { - return new AccountAddressRestrictionModificationTransaction( + } else if (transactionDTO.type === TransactionType.ACCOUNT_RESTRICTION_ADDRESS) { + return new AccountAddressRestrictionTransaction( extractNetworkType(transactionDTO.version), extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), @@ -296,8 +296,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr extractNetworkType(transactionDTO.version)) : undefined, transactionInfo, ); - } else if (transactionDTO.type === TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION) { - return new AccountOperationRestrictionModificationTransaction( + } else if (transactionDTO.type === TransactionType.ACCOUNT_RESTRICTION_OPERATION) { + return new AccountOperationRestrictionTransaction( extractNetworkType(transactionDTO.version), extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), @@ -312,8 +312,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr extractNetworkType(transactionDTO.version)) : undefined, transactionInfo, ); - } else if (transactionDTO.type === TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC) { - return new AccountMosaicRestrictionModificationTransaction( + } else if (transactionDTO.type === TransactionType.ACCOUNT_RESTRICTION_MOSAIC) { + return new AccountMosaicRestrictionTransaction( extractNetworkType(transactionDTO.version), extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index afe17f162a..b1198243fd 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -25,10 +25,10 @@ import { MosaicNonce } from '../../model/mosaic/MosaicNonce'; import { MosaicProperties } from '../../model/mosaic/MosaicProperties'; import { NamespaceId } from '../../model/namespace/NamespaceId'; import { NamespaceType } from '../../model/namespace/NamespaceType'; -import { AccountAddressRestrictionModificationTransaction } from '../../model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from '../../model/transaction/AccountMosaicRestrictionModificationTransaction'; -import { AccountOperationRestrictionModificationTransaction } from '../../model/transaction/AccountOperationRestrictionModificationTransaction'; +import { AccountMosaicRestrictionTransaction } from '../../model/transaction/AccountMosaicRestrictionTransaction'; +import { AccountOperationRestrictionTransaction } from '../../model/transaction/AccountOperationRestrictionTransaction'; import { AccountRestrictionModification } from '../../model/transaction/AccountRestrictionModification'; import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction'; import { AggregateTransaction } from '../../model/transaction/AggregateTransaction'; @@ -100,9 +100,9 @@ export const CreateTransactionFromPayload = (transactionBinary: string): Transac */ const CreateTransaction = (type: number, transactionData: string, networkType: NetworkType, deadline: number[]): Transaction => { switch (type) { - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS: - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION: - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC: + case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: + case TransactionType.ACCOUNT_RESTRICTION_OPERATION: + case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: const propertyTypeLength = 2; const modificationCountOffset = propertyTypeLength; @@ -114,8 +114,8 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N const modificationArray = modifications.match(/.{1,52}/g); switch (type) { - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS: - const t = AccountAddressRestrictionModificationTransaction.create( + case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: + const t = AccountAddressRestrictionTransaction.create( Deadline.createFromDTO(deadline), parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( @@ -125,8 +125,8 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N networkType, ); return t; - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC: - return AccountMosaicRestrictionModificationTransaction.create( + case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: + return AccountMosaicRestrictionTransaction.create( Deadline.createFromDTO(deadline), parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( @@ -135,8 +135,8 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N )) : [], networkType, ); - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION: - return AccountOperationRestrictionModificationTransaction.create( + case TransactionType.ACCOUNT_RESTRICTION_OPERATION: + return AccountOperationRestrictionTransaction.create( Deadline.createFromDTO(deadline), parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index 4802bbd278..4ba47f1e4c 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -14,10 +14,10 @@ * limitations under the License. */ -import { AccountAddressRestrictionModificationTransaction } from '../../model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from '../../model/transaction/AccountMosaicRestrictionModificationTransaction'; -import { AccountOperationRestrictionModificationTransaction } from '../../model/transaction/AccountOperationRestrictionModificationTransaction'; +import { AccountMosaicRestrictionTransaction } from '../../model/transaction/AccountMosaicRestrictionTransaction'; +import { AccountOperationRestrictionTransaction } from '../../model/transaction/AccountOperationRestrictionTransaction'; import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction'; import { AggregateTransaction } from '../../model/transaction/AggregateTransaction'; import { LockFundsTransaction } from '../../model/transaction/LockFundsTransaction'; @@ -70,26 +70,26 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { duration: (transaction as LockFundsTransaction).duration.toDTO(), hash: (transaction as LockFundsTransaction).hash, }; - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS: + case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: return { - restrictionType: (transaction as AccountAddressRestrictionModificationTransaction).restrictionType, - modifications: (transaction as AccountAddressRestrictionModificationTransaction). + restrictionType: (transaction as AccountAddressRestrictionTransaction).restrictionType, + modifications: (transaction as AccountAddressRestrictionTransaction). modifications.map((modification) => { return modification.toDTO(); }), }; - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION: + case TransactionType.ACCOUNT_RESTRICTION_OPERATION: return { - restrictionType: (transaction as AccountOperationRestrictionModificationTransaction).restrictionType, - modifications: (transaction as AccountOperationRestrictionModificationTransaction). + restrictionType: (transaction as AccountOperationRestrictionTransaction).restrictionType, + modifications: (transaction as AccountOperationRestrictionTransaction). modifications.map((modification) => { return modification.toDTO(); }), }; - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC: + case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: return { - restrictionType: (transaction as AccountMosaicRestrictionModificationTransaction).restrictionType, - modifications: (transaction as AccountMosaicRestrictionModificationTransaction).modifications.map((modification) => { + restrictionType: (transaction as AccountMosaicRestrictionTransaction).restrictionType, + modifications: (transaction as AccountMosaicRestrictionTransaction).modifications.map((modification) => { return modification.toDTO(); }), }; diff --git a/src/model/model.ts b/src/model/model.ts index ec948eca39..06d3767f14 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -92,9 +92,9 @@ export * from './receipt/Statement'; // Transaction export * from './transaction/AccountLinkTransaction'; export * from './transaction/AccountRestrictionTransaction'; -export * from './transaction/AccountAddressRestrictionModificationTransaction'; -export * from './transaction/AccountOperationRestrictionModificationTransaction'; -export * from './transaction/AccountMosaicRestrictionModificationTransaction'; +export * from './transaction/AccountAddressRestrictionTransaction'; +export * from './transaction/AccountMosaicRestrictionTransaction'; +export * from './transaction/AccountMosaicRestrictionTransaction'; export * from './transaction/AccountRestrictionModification'; export * from './transaction/AddressAliasTransaction'; export * from './transaction/AggregateTransaction'; diff --git a/src/model/mosaic/MosaicFlag.ts b/src/model/mosaic/MosaicFlag.ts new file mode 100644 index 0000000000..dcf6a8b500 --- /dev/null +++ b/src/model/mosaic/MosaicFlag.ts @@ -0,0 +1,25 @@ +/* + * Copyright 2018 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. + */ +export enum MosaicFlags { + /** No flags present. */ + NONE = 0, + /** Mosaic supports supply changes even when mosaic owner owns partial supply. */ + SUPPLY_MUTABLE = 1, + /** Mosaic supports transfers between arbitrary accounts \note when not set, mosaic can only be transferred to and from mosaic owner. */ + TRANSFERABLE = 2, + /** Mosaic supports custom restrictions configured by mosaic owner. */ + RESTRICTABLE = 4, +} diff --git a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts similarity index 64% rename from src/model/transaction/AccountAddressRestrictionModificationTransaction.ts rename to src/model/transaction/AccountAddressRestrictionTransaction.ts index 3a9d99f813..243b4ff560 100644 --- a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -14,8 +14,17 @@ * limitations under the License. */ +import { RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; +import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; @@ -27,7 +36,7 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -export class AccountAddressRestrictionModificationTransaction extends Transaction { +export class AccountAddressRestrictionTransaction extends Transaction { /** * Create a modify account address restriction transaction object @@ -36,15 +45,15 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio * @param modifications - The array of modifications. * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountAddressRestrictionModificationTransaction} + * @returns {AccountAddressRestrictionTransaction} */ public static create(deadline: Deadline, restrictionType: RestrictionType, modifications: Array>, networkType: NetworkType, - maxFee: UInt64 = new UInt64([0, 0])): AccountAddressRestrictionModificationTransaction { - return new AccountAddressRestrictionModificationTransaction(networkType, - TransactionVersion.MODIFY_ACCOUNT_RESTRICTION_ADDRESS, + maxFee: UInt64 = new UInt64([0, 0])): AccountAddressRestrictionTransaction { + return new AccountAddressRestrictionTransaction(networkType, + TransactionVersion.ACCOUNT_RESTRICTION_ADDRESS, deadline, maxFee, restrictionType, @@ -71,15 +80,15 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio signature?: string, signer?: PublicAccount, transactionInfo?: TransactionInfo) { - super(TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS, + super(TransactionType.ACCOUNT_RESTRICTION_ADDRESS, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } /** * @override Transaction.size() - * @description get the byte size of a AccountAddressRestrictionModificationTransaction + * @description get the byte size of a AccountAddressRestrictionTransaction * @returns {number} - * @memberof AccountAddressRestrictionModificationTransaction + * @memberof AccountAddressRestrictionTransaction */ public get size(): number { const byteSize = super.size; @@ -110,4 +119,29 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountAddressRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountAddressRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedAddressDto(RawAddress.stringToAddress(modification.value)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index 78915b03a3..41e00509b0 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -14,8 +14,15 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountLinkTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/AccountLinkTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; @@ -111,4 +118,24 @@ export class AccountLinkTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountLinkTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.LINK_ACCOUNT.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new KeyDto(Convert.hexToUint8(this.remoteAccountKey)), + this.linkAction.valueOf(), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts similarity index 65% rename from src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts rename to src/model/transaction/AccountMosaicRestrictionTransaction.ts index 3a32656795..cfac1c3ea1 100644 --- a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -16,6 +16,14 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; +import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; @@ -27,7 +35,7 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -export class AccountMosaicRestrictionModificationTransaction extends Transaction { +export class AccountMosaicRestrictionTransaction extends Transaction { /** * Create a modify account mosaic restriction transaction object @@ -36,15 +44,15 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction * @param modifications - The array of modifications. * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountAddressRestrictionModificationTransaction} + * @returns {AccountAddressRestrictionTransaction} */ public static create(deadline: Deadline, restrictionType: RestrictionType, modifications: Array>, networkType: NetworkType, - maxFee: UInt64 = new UInt64([0, 0])): AccountMosaicRestrictionModificationTransaction { - return new AccountMosaicRestrictionModificationTransaction(networkType, - TransactionVersion.MODIFY_ACCOUNT_RESTRICTION_MOSAIC, + maxFee: UInt64 = new UInt64([0, 0])): AccountMosaicRestrictionTransaction { + return new AccountMosaicRestrictionTransaction(networkType, + TransactionVersion.ACCOUNT_RESTRICTION_MOSAIC, deadline, maxFee, restrictionType, @@ -71,15 +79,15 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction signature?: string, signer?: PublicAccount, transactionInfo?: TransactionInfo) { - super(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC, + super(TransactionType.ACCOUNT_RESTRICTION_MOSAIC, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } /** * @override Transaction.size() - * @description get the byte size of a AccountMosaicRestrictionModificationTransaction + * @description get the byte size of a AccountMosaicRestrictionTransaction * @returns {number} - * @memberof AccountMosaicRestrictionModificationTransaction + * @memberof AccountMosaicRestrictionTransaction */ public get size(): number { const byteSize = super.size; @@ -110,4 +118,29 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountMosaicRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_MOSAIC.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountMosaicRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedMosaicIdDto(modification.value), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts similarity index 67% rename from src/model/transaction/AccountOperationRestrictionModificationTransaction.ts rename to src/model/transaction/AccountOperationRestrictionTransaction.ts index 38160cc79d..4ed72af488 100644 --- a/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -26,8 +26,15 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; -export class AccountOperationRestrictionModificationTransaction extends Transaction { +export class AccountOperationRestrictionTransaction extends Transaction { /** * Create a modify account operation restriction type transaction object @@ -36,14 +43,14 @@ export class AccountOperationRestrictionModificationTransaction extends Transact * @param modifications - The array of modifications. * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountOperationRestrictionModificationTransaction} + * @returns {AccountOperationRestrictionTransaction} */ public static create(deadline: Deadline, restrictionType: RestrictionType, modifications: Array>, networkType: NetworkType, - maxFee: UInt64 = new UInt64([0, 0])): AccountOperationRestrictionModificationTransaction { - return new AccountOperationRestrictionModificationTransaction(networkType, + maxFee: UInt64 = new UInt64([0, 0])): AccountOperationRestrictionTransaction { + return new AccountOperationRestrictionTransaction(networkType, TransactionVersion.MODIFY_ACCOUNT_RESTRICTION_ENTITY_TYPE, deadline, maxFee, @@ -71,15 +78,15 @@ export class AccountOperationRestrictionModificationTransaction extends Transact signature?: string, signer?: PublicAccount, transactionInfo?: TransactionInfo) { - super(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION, + super(TransactionType.ACCOUNT_RESTRICTION_OPERATION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } /** * @override Transaction.size() - * @description get the byte size of a AccountOperationRestrictionModificationTransaction + * @description get the byte size of a AccountOperationRestrictionTransaction * @returns {number} - * @memberof AccountOperationRestrictionModificationTransaction + * @memberof AccountOperationRestrictionTransaction */ public get size(): number { const byteSize = super.size; @@ -110,4 +117,29 @@ export class AccountOperationRestrictionModificationTransaction extends Transact .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountOperationRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_OPERATION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountOperationRestrictionModificationBuilder( + modification.modificationType.valueOf(), + modification.value.valueOf(), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountRestrictionTransaction.ts b/src/model/transaction/AccountRestrictionTransaction.ts index 7e0f26c313..e1a718141e 100644 --- a/src/model/transaction/AccountRestrictionTransaction.ts +++ b/src/model/transaction/AccountRestrictionTransaction.ts @@ -17,9 +17,9 @@ import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; -import { AccountAddressRestrictionModificationTransaction } from './AccountAddressRestrictionModificationTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from './AccountMosaicRestrictionModificationTransaction'; -import { AccountOperationRestrictionModificationTransaction } from './AccountOperationRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from './AccountAddressRestrictionTransaction'; +import { AccountMosaicRestrictionTransaction } from './AccountMosaicRestrictionTransaction'; +import { AccountOperationRestrictionTransaction } from './AccountOperationRestrictionTransaction'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; import { TransactionType } from './TransactionType'; @@ -32,7 +32,7 @@ export class AccountRestrictionTransaction { * @param modification - array of address modifications * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountAddressRestrictionModificationTransaction} + * @returns {AccountAddressRestrictionTransaction} */ public static createAddressRestrictionModificationTransaction( deadline: Deadline, @@ -40,11 +40,11 @@ export class AccountRestrictionTransaction { modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), - ): AccountAddressRestrictionModificationTransaction { + ): AccountAddressRestrictionTransaction { if (![RestrictionType.AllowAddress, RestrictionType.BlockAddress].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } - return AccountAddressRestrictionModificationTransaction.create( + return AccountAddressRestrictionTransaction.create( deadline, restrictionType, modifications, @@ -60,7 +60,7 @@ export class AccountRestrictionTransaction { * @param modification - array of mosaic modifications * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountMosaicRestrictionModificationTransaction} + * @returns {AccountMosaicRestrictionTransaction} */ public static createMosaicRestrictionModificationTransaction( deadline: Deadline, @@ -68,11 +68,11 @@ export class AccountRestrictionTransaction { modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), - ): AccountMosaicRestrictionModificationTransaction { + ): AccountMosaicRestrictionTransaction { if (![RestrictionType.AllowMosaic, RestrictionType.BlockMosaic].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } - return AccountMosaicRestrictionModificationTransaction.create( + return AccountMosaicRestrictionTransaction.create( deadline, restrictionType, modifications, @@ -96,11 +96,11 @@ export class AccountRestrictionTransaction { modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), - ): AccountOperationRestrictionModificationTransaction { + ): AccountOperationRestrictionTransaction { if (![RestrictionType.AllowTransaction, RestrictionType.BlockTransaction].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } - return AccountOperationRestrictionModificationTransaction.create( + return AccountOperationRestrictionTransaction.create( deadline, restrictionType, modifications, diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index c52a9efbed..b1b449dc69 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -16,6 +16,14 @@ import { Builder } from '../../infrastructure/builders/AddressAliasTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; +import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; +import { AddressDto } from '../../infrastructure/catbuffer/AddressDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -27,6 +35,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { RawAddress } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -126,4 +135,25 @@ export class AddressAliasTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AddressAliasTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ADDRESS_ALIAS.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new AddressDto(RawAddress.stringToAddress(this.address.plain())), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 495ba89fb8..016f66fd8e 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -203,4 +203,12 @@ export class AggregateTransaction extends Transaction { return byteSize + byteTransactionsSize + byteTransactions; } -} \ No newline at end of file + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } +} diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index 4036654043..9ad23c1a60 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -137,4 +137,11 @@ export class LockFundsTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index e8afe30251..dbc22505a7 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -14,8 +14,15 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MultisigModificationTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { CosignatoryModificationBuilder } from '../../infrastructure/catbuffer/CosignatoryModificationBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; @@ -112,7 +119,7 @@ export class ModifyMultisigAccountTransaction extends Transaction { // each modification contains : // - 1 byte for modificationType // - 32 bytes for cosignatoryPublicKey - const byteModifications = 33 * this.modifications.length + const byteModifications = 33 * this.modifications.length; return byteSize + byteRemovalDelta + byteApprovalDelta + byteNumModifications + byteModifications; } @@ -132,4 +139,30 @@ export class ModifyMultisigAccountTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MultisigAccountModificationTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MODIFY_MULTISIG_ACCOUNT.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.minRemovalDelta, + this.minApprovalDelta, + this.modifications.map((modification) => { + return new CosignatoryModificationBuilder( + modification.type.valueOf(), + new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index 8c03b28ab6..3bc49806c6 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -150,4 +150,11 @@ export class MosaicAddressRestrictionTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index 8220ccea1e..2ae1588994 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -16,6 +16,14 @@ import { Builder } from '../../infrastructure/builders/MosaicAliasTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/MosaicAliasTransactionBuilder'; +import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; +import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { MosaicId } from '../mosaic/MosaicId'; @@ -122,4 +130,25 @@ export class MosaicAliasTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicAliasTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_ALIAS.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index b82844ab41..7a41faddf9 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -27,6 +27,19 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; +import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; +import { MosaicFlagsDto } from '../../infrastructure/catbuffer/MosaicFlagsDto'; +import { MosaicFlags } from '../mosaic/MosaicFlag'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { Convert } from '../../core/format'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; /** * Before a mosaic can be created or transferred, a corresponding definition of the mosaic has to be created and published to the network. @@ -115,6 +128,37 @@ export class MosaicDefinitionTransaction extends Transaction { return byteSize + byteNonce + byteMosaicId + byteNumProps + byteFlags + byteDivisibility + byteDurationSize + byteDuration; } + /** + * @description get the calculated mosaic flag value + * @returns {number} + * @memberof MosaicDefinitionTransaction + */ + public getMosaicFlagValue(): number { + let flag = MosaicFlags.NONE; + if (this.mosaicProperties.supplyMutable === true) { + flag += MosaicFlags.SUPPLY_MUTABLE; + } + + if (this.mosaicProperties.transferable === true) { + flag += MosaicFlags.TRANSFERABLE; + } + + if (this.mosaicProperties.restrictable === true) { + flag += MosaicFlags.RESTRICTABLE; + } + + return flag.valueOf(); + } + + /** + * @description Get mosaic nonce int value + * @returns {number} + * @memberof MosaicDefinitionTransaction + */ + public getMosaicNonceIntValue(): number { + return GeneratorUtils.readUint32At(this.nonce.toDTO(), 0); + } + /** * @internal * @returns {VerifiableTransaction} @@ -144,4 +188,28 @@ export class MosaicDefinitionTransaction extends Transaction { return mosaicDefinitionTransaction.build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicDefinitionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_DEFINITION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new MosaicNonceDto(this.getMosaicNonceIntValue()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + this.getMosaicFlagValue(), + this.mosaicProperties.divisibility, + new BlockDurationDto(this.mosaicProperties.duration ? + this.mosaicProperties.duration.toDTO() : []), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index 7530eba330..7cbb7a55d5 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -173,4 +173,11 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index 39b33d8318..b53fbd92d3 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -16,6 +16,12 @@ import { Builder } from '../../infrastructure/builders/MosaicSupplyChangeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { MosaicId } from '../mosaic/MosaicId'; @@ -125,4 +131,25 @@ export class MosaicSupplyChangeTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicSupplyChangeTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_SUPPLY_CHANGE.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + this.direction.valueOf(), + new AmountDto(this.delta.toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index da05639507..f1f29cd6a2 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -182,4 +182,11 @@ export class RegisterNamespaceTransaction extends Transaction { return registerNamespacetransaction.build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index 6862dc7a3b..9e02785071 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -13,9 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Convert as convert } from '../../core/format'; +import { Convert as convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/SecretLockTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SecretLockTransactionBuilder } from '../../infrastructure/catbuffer/SecretLockTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from '../../infrastructure/catbuffer/UnresolvedMosaicBuilder'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -134,6 +145,15 @@ export class SecretLockTransaction extends Transaction { return byteSize + byteMosaicId + byteAmount + byteDuration + byteAlgorithm + byteRecipient + byteSecret; } + /** + * @description Get secret bytes + * @returns {Uint8Array} + * @memberof SecretLockTransaction + */ + public getSecretByte(): Uint8Array { + return convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); + } + /** * @internal * @returns {VerifiableTransaction} @@ -153,4 +173,28 @@ export class SecretLockTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new SecretLockTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_LOCK.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), + new AmountDto(this.mosaic.amount.toDTO())), + new BlockDurationDto(this.duration.toDTO()), + this.hashType.valueOf(), + new Hash256Dto(this.getSecretByte()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipient.plain())), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index cf41678857..588638fcc6 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -14,9 +14,17 @@ * limitations under the License. */ -import { Convert as convert } from '../../core/format'; +import { Convert, Convert as convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/SecretProofTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SecretProofTransactionBuilder } from '../../infrastructure/catbuffer/SecretProofTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -113,6 +121,24 @@ export class SecretProofTransaction extends Transaction { return byteSize + byteAlgorithm + byteSecret + byteRecipient + byteProofSize + byteProof; } + /** + * @description Get secret bytes + * @returns {Uint8Array} + * @memberof SecretLockTransaction + */ + public getSecretByte(): Uint8Array { + return convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); + } + + /** + * @description Get proof bytes + * @returns {Uint8Array} + * @memberof SecretLockTransaction + */ + public getProofByte(): Uint8Array { + return convert.hexToUint8(this.proof); + } + /** * @internal * @returns {VerifiableTransaction} @@ -130,4 +156,26 @@ export class SecretProofTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new SecretProofTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_PROOF.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.hashType.valueOf(), + new Hash256Dto(this.getSecretByte()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipient.plain())), + this.getProofByte(), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index 63fb543965..0bc6786fb3 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -import { SignSchema } from '../../core/crypto'; +import { KeyPair, SHA3Hasher, SignSchema } from '../../core/crypto'; +import { Convert } from '../../core/format'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { SerializeTransactionToJSON } from '../../infrastructure/transaction/SerializeTransactionToJSON'; import { Account } from '../account/Account'; @@ -79,6 +80,16 @@ export abstract class Transaction { public readonly transactionInfo?: TransactionInfo | AggregateTransactionInfo) { } + /** + * @internal + */ + protected abstract buildTransaction(): VerifiableTransaction; + + /** + * @internal + */ + protected abstract generateBytes(): Uint8Array; + /** * @internal * Serialize and sign transaction creating a new SignedTransaction @@ -100,8 +111,55 @@ export abstract class Transaction { /** * @internal + * Serialize and sign transaction creating a new SignedTransaction + * @param account - The account to sign the transaction + * @param generationHash - Network generation hash hex + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {SignedTransaction} */ - protected abstract buildTransaction(): VerifiableTransaction; + public signWithCatbuffer(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { + const generationHashBytes = Array.from(Convert.hexToUint8(generationHash)); + const byteBuffer = Array.from(this.generateBytes()); + const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); + const keyPairEncoded = KeyPair.createKeyPairFromPrivateKeyString(account.privateKey, signSchema); + const signature = Array.from(KeyPair.sign(account, new Uint8Array(signingBytes), signSchema)); + const signedTransactionBuffer = byteBuffer + .splice(0, 4) + .concat(signature) + .concat(Array.from(keyPairEncoded.publicKey)) + .concat(byteBuffer + .splice(64 + 32, byteBuffer.length)); + const payload = Convert.uint8ToHex(signedTransactionBuffer); + return new SignedTransaction( + payload, + this.createTransactionHash(payload, generationHashBytes), + account.publicKey, + this.type, + this.networkType); + } + + /** + * Generate transaction hash hex + * @param {string} transactionPayload HexString Payload + * @param {Array} generationHashBuffer Network generation hash byte + * @returns {string} Returns Transaction Payload hash + */ + public createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { + const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); + const signingBytes = byteBuffer + .slice(4, 36) + .concat(byteBuffer + .slice(4 + 64, 4 + 64 + 32)) + .concat(generationHashBuffer) + .concat(byteBuffer + .splice(4 + 64 + 32, byteBuffer.length)); + + const hash = new Uint8Array(32); + + SHA3Hasher.func(hash, signingBytes, 32); + + return Convert.uint8ToHex(hash); + } /** * @internal diff --git a/src/model/transaction/TransactionType.ts b/src/model/transaction/TransactionType.ts index 7b2b000adf..9d571f0855 100644 --- a/src/model/transaction/TransactionType.ts +++ b/src/model/transaction/TransactionType.ts @@ -15,114 +15,116 @@ */ /** - * Static class containing transaction type constants. + * Enum containing transaction type constants. */ -export class TransactionType { +export enum TransactionType { + /** Reserved entity type. */ + RESERVED = 0, /** * Transfer Transaction transaction type. * @type {number} */ - public static readonly TRANSFER = 0x4154; + TRANSFER = 0x4154, /** * Register namespace transaction type. * @type {number} */ - public static readonly REGISTER_NAMESPACE = 0x414E; + REGISTER_NAMESPACE = 0x414E, /** * Address alias transaction type * @type {number} */ - public static readonly ADDRESS_ALIAS = 0x424E; + ADDRESS_ALIAS = 0x424E, /** * Mosaic alias transaction type * @type {number} */ - public static readonly MOSAIC_ALIAS = 0x434E; + MOSAIC_ALIAS = 0x434E, /** * Mosaic definition transaction type. * @type {number} */ - public static readonly MOSAIC_DEFINITION = 0x414D; + MOSAIC_DEFINITION = 0x414D, /** * Mosaic supply change transaction. * @type {number} */ - public static readonly MOSAIC_SUPPLY_CHANGE = 0x424D; + MOSAIC_SUPPLY_CHANGE = 0x424D, /** * Modify multisig account transaction type. * @type {number} */ - public static readonly MODIFY_MULTISIG_ACCOUNT = 0x4155; + MODIFY_MULTISIG_ACCOUNT = 0x4155, /** * Aggregate complete transaction type. * @type {number} */ - public static readonly AGGREGATE_COMPLETE = 0x4141; + AGGREGATE_COMPLETE = 0x4141, /** * Aggregate bonded transaction type */ - public static readonly AGGREGATE_BONDED = 0x4241; + AGGREGATE_BONDED = 0x4241, /** * Lock transaction type * @type {number} */ - public static readonly LOCK = 0x4148; + LOCK = 0x4148, /** * Secret Lock Transaction type * @type {number} */ - public static readonly SECRET_LOCK = 0x4152; + SECRET_LOCK = 0x4152, /** * Secret Proof transaction type * @type {number} */ - public static readonly SECRET_PROOF = 0x4252; + SECRET_PROOF = 0x4252, /** * Account restriction address transaction type * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_ADDRESS = 0x4150; + ACCOUNT_RESTRICTION_ADDRESS = 0x4150, /** * Account restriction mosaic transaction type * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_MOSAIC = 0x4250; + ACCOUNT_RESTRICTION_MOSAIC = 0x4250, /** * Account restriction operation transaction type * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_OPERATION = 0x4350; + ACCOUNT_RESTRICTION_OPERATION = 0x4350, /** * Link account transaction type * @type {number} */ - public static readonly LINK_ACCOUNT = 0x414C; + LINK_ACCOUNT = 0x414C, /** * Mosaic address restriction type * @type {number} */ - public static readonly MOSAIC_ADDRESS_RESTRICTION = 0x4251; + MOSAIC_ADDRESS_RESTRICTION = 0x4251, /** * Mosaic global restriction type * @type {number} */ - public static readonly MOSAIC_GLOBAL_RESTRICTION = 0x4151; + MOSAIC_GLOBAL_RESTRICTION = 0x4151, } diff --git a/src/model/transaction/TransactionVersion.ts b/src/model/transaction/TransactionVersion.ts index 953c35e096..71087ac326 100644 --- a/src/model/transaction/TransactionVersion.ts +++ b/src/model/transaction/TransactionVersion.ts @@ -116,13 +116,13 @@ export class TransactionVersion { * Account Restriction address transaction version * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_ADDRESS = 0x01; + public static readonly ACCOUNT_RESTRICTION_ADDRESS = 0x01; /** * Account Restriction mosaic transaction version * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_MOSAIC = 0x01; + public static readonly ACCOUNT_RESTRICTION_MOSAIC = 0x01; /** * Account Restriction operation transaction version diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 880374187d..31dea94577 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -14,9 +14,20 @@ * limitations under the License. */ -import { Convert as convert } from '../../core/format'; +import { Convert, Convert as convert } from '../../core/format'; +import { RawAddress } from '../../core/format/RawAddress'; import { Builder } from '../../infrastructure/builders/TransferTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { TransferTransactionBuilder } from '../../infrastructure/catbuffer/TransferTransactionBuilder'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from '../../infrastructure/catbuffer/UnresolvedMosaicBuilder'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -109,6 +120,30 @@ export class TransferTransaction extends Transaction { return (this.recipient as Address).plain(); } + /** + * Return sorted mosaic arrays + * @internal + * @returns {Mosaic[]} + */ + public sortMosaics(): Mosaic[] { + const sortedMosaics = this.mosaics.sort((a, b) => { + if (Number(a.id[1]) > b.id[1]) { return 1; } else if (a.id[1] < b.id[1]) { return -1; } + return 0; + }); + return sortedMosaics; + } + + /** + * Return message buffer + * @internal + * @returns {Uint8Array} + */ + public getMessageBuffer(): Uint8Array { + const payloadBuffer = Convert.hexToUint8(Convert.utf8ToHex(this.message.payload)); + const typeBuffer = GeneratorUtils.uintToBuffer(this.message.type, 1); + return GeneratorUtils.concatTypedArrays(typeBuffer, payloadBuffer); + } + /** * @override Transaction.size() * @description get the byte size of a TransferTransaction @@ -146,4 +181,28 @@ export class TransferTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new TransferTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.TRANSFER.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), + this.getMessageBuffer(), + this.sortMosaics().map((mosaic) => { + return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), + new AmountDto(mosaic.amount.toDTO())); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index b3653114f1..ee1576a54e 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -35,9 +35,9 @@ import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrency import { AliasAction } from '../../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { NamespaceType } from '../../../src/model/namespace/NamespaceType'; -import { AccountAddressRestrictionModificationTransaction } from '../../../src/model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from '../../../src/model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../../src/model/transaction/AccountLinkTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from '../../../src/model/transaction/AccountMosaicRestrictionModificationTransaction'; +import { AccountMosaicRestrictionTransaction } from '../../../src/model/transaction/AccountMosaicRestrictionTransaction'; import { AccountRestrictionModification } from '../../../src/model/transaction/AccountRestrictionModification'; import { AccountRestrictionTransaction } from '../../../src/model/transaction/AccountRestrictionTransaction'; import { AddressAliasTransaction } from '../../../src/model/transaction/AddressAliasTransaction'; @@ -87,7 +87,7 @@ describe('TransactionMapping - createFromPayload', () => { const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); const transaction = TransactionMapping - .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; + .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionTransaction; expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); @@ -110,7 +110,7 @@ describe('TransactionMapping - createFromPayload', () => { const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); const transaction = TransactionMapping - .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; + .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionTransaction; expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); expect(transaction.modifications[0].value[0]).to.be.equal(2262289484); expect(transaction.modifications[0].value[1]).to.be.equal(3405110546); @@ -672,7 +672,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const transaction = - TransactionMapping.createFromDTO(addressRestrictionTransaction.toJSON()) as AccountAddressRestrictionModificationTransaction; + TransactionMapping.createFromDTO(addressRestrictionTransaction.toJSON()) as AccountAddressRestrictionTransaction; expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); @@ -693,9 +693,9 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const transaction = - TransactionMapping.createFromDTO(mosaicRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; + TransactionMapping.createFromDTO(mosaicRestrictionTransaction.toJSON()) as AccountMosaicRestrictionTransaction; - expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC); + expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_MOSAIC); expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); expect(transaction.modifications.length).to.be.equal(1); }); @@ -714,9 +714,9 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const transaction = - TransactionMapping.createFromDTO(operationRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; + TransactionMapping.createFromDTO(operationRestrictionTransaction.toJSON()) as AccountMosaicRestrictionTransaction; - expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); + expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_OPERATION); expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); expect(transaction.modifications.length).to.be.equal(1); }); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 2f3ce56962..90aaa81936 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -90,7 +90,7 @@ describe('SerializeTransactionToJSON', () => { const json = addressRestrictionTransaction.toJSON(); - expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS); + expect(json.transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_ADDRESS); expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -110,7 +110,7 @@ describe('SerializeTransactionToJSON', () => { const json = mosaicRestrictionTransaction.toJSON(); - expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC); + expect(json.transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_MOSAIC); expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -130,7 +130,7 @@ describe('SerializeTransactionToJSON', () => { const json = operationRestrictionTransaction.toJSON(); - expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); + expect(json.transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_OPERATION); expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); expect(json.transaction.modifications.length).to.be.equal(1); }); diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index 68c65c8eae..0d5b8c8b25 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountLinkTransaction', () => { expect(accountLinkTransaction.linkAction).to.be.equal(0); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); - const signedTransaction = accountLinkTransaction.signWith(account, generationHash); + const signedTransaction = accountLinkTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 04ef489a07..36dd3232a1 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountRestrictionTransaction', () => { }); describe('size', () => { - it('should return 148 for AccountAddressRestrictionModificationTransaction transaction byte size with 1 modification', () => { + it('should return 148 for AccountAddressRestrictionTransaction transaction byte size with 1 modification', () => { const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); const addressRestrictionFilter = AccountRestrictionModification.createForAddress( RestrictionModificationType.Add, @@ -82,7 +82,7 @@ describe('AccountRestrictionTransaction', () => { expect(addressRestrictionTransaction.size).to.be.equal(148); }); - it('should return 131 for AccountMosaicRestrictionModificationTransaction transaction byte size with 1 modification', () => { + it('should return 131 for AccountMosaicRestrictionTransaction transaction byte size with 1 modification', () => { const mosaicId = new MosaicId([2262289484, 3405110546]); const mosaicRestrictionFilter = AccountRestrictionModification.createForMosaic( RestrictionModificationType.Add, @@ -97,7 +97,7 @@ describe('AccountRestrictionTransaction', () => { expect(mosaicRestrictionTransaction.size).to.be.equal(131); }); - it('should return 125 for AccountOperationRestrictionModificationTransaction transaction byte size with 1 modification', () => { + it('should return 125 for AccountOperationRestrictionTransaction transaction byte size with 1 modification', () => { const operation = TransactionType.ADDRESS_ALIAS; const operationRestrictionFilter = AccountRestrictionModification.createForOperation( RestrictionModificationType.Add, @@ -162,7 +162,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = addressRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -204,7 +204,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -246,7 +246,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = operationRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index 3111de06cb..2721b583d9 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('AddressAliasTransaction', () => { expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = addressAliasTransaction.signWith(account, generationHash); + const signedTransaction = addressAliasTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index f6065c02b3..c1c549a0b6 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -110,7 +110,7 @@ describe('ModifyMultisigAccountTransaction', () => { expect(modifyMultisigAccountTransaction.modifications[1].cosignatoryPublicAccount.publicKey) .to.be.equal('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); - const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); + const signedTransaction = modifyMultisigAccountTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index 0cf1077609..a9314a0c54 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -56,7 +56,7 @@ describe('MosaicAliasTransaction', () => { namespaceId, mosaicId, NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(mosaicAliasTransaction.maxFee.higher).to.be.equal(0); @@ -80,7 +80,7 @@ describe('MosaicAliasTransaction', () => { expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); expect(mosaicAliasTransaction.mosaicId.id.higher).to.be.equal(3405110546); - const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); + const signedTransaction = mosaicAliasTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index 5c15bafa89..688506516b 100644 --- a/test/model/transaction/MosaicDefinitionTransaction.spec.ts +++ b/test/model/transaction/MosaicDefinitionTransaction.spec.ts @@ -93,12 +93,12 @@ describe('MosaicDefinitionTransaction', () => { expect(mosaicDefinitionTransaction.mosaicProperties.transferable).to.be.equal(true); expect(mosaicDefinitionTransaction.mosaicProperties.restrictable).to.be.equal(true); - const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicDefinitionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('E6DE84B8010000000000000001070302E803000000000000'); + )).to.be.equal('E6DE84B801000000000000000703E803000000000000'); }); diff --git a/test/model/transaction/SecretLockTransaction.spec.ts b/test/model/transaction/SecretLockTransaction.spec.ts index 26bbd11ede..9f240dda47 100644 --- a/test/model/transaction/SecretLockTransaction.spec.ts +++ b/test/model/transaction/SecretLockTransaction.spec.ts @@ -18,6 +18,7 @@ import {expect} from 'chai'; import * as CryptoJS from 'crypto-js'; import {keccak_256, sha3_256} from 'js-sha3'; import {Convert as convert} from '../../../src/core/format'; +import { Account } from '../../../src/model/account/Account'; import {Address} from '../../../src/model/account/Address'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; @@ -25,9 +26,14 @@ import {Deadline} from '../../../src/model/transaction/Deadline'; import {HashType} from '../../../src/model/transaction/HashType'; import {SecretLockTransaction} from '../../../src/model/transaction/SecretLockTransaction'; import {UInt64} from '../../../src/model/UInt64'; +import { TestingAccount } from '../../conf/conf.spec'; describe('SecretLockTransaction', () => { - + let account: Account; + const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; + before(() => { + account = TestingAccount; + }); it('should default maxFee field be set to 0', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; const recipient = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); @@ -56,7 +62,7 @@ describe('SecretLockTransaction', () => { sha3_256.create().update(convert.hexToUint8(proof)).hex(), recipient, NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(secretLockTransaction.maxFee.higher).to.be.equal(0); @@ -83,6 +89,27 @@ describe('SecretLockTransaction', () => { expect(secretLockTransaction.recipient).to.be.equal(recipient); }); + it('should be created and sign SecretLock Transaction', () => { + const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; + const recipient = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + NetworkCurrencyMosaic.createAbsolute(10), + UInt64.fromUint(100), + HashType.Op_Sha3_256, + sha3_256.create().update(convert.hexToUint8(proof)).hex(), + recipient, + NetworkType.MIJIN_TEST, + ); + const signedTx = secretLockTransaction.signWithCatbuffer(account, generationHash); + expect(signedTx.payload.substring( + 240, + signedTx.payload.length, + )).to.be.equal( + '44B262C46CEABB850A000000000000006400000000000000009B3155B37159DA50AA52D5967C509B41' + + '0F5A36A3B1E31ECB5AC76675D79B4A5E90C2337113E6D8F15B56E0821149299F340C01706FC1CAD6CB'); + }); + it('should throw exception when the input is not related to HashTyp: Op_Sha3_256', () => { expect(() => { const recipient = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); diff --git a/test/model/transaction/SecretProofTransaction.spec.ts b/test/model/transaction/SecretProofTransaction.spec.ts index 6ee0b3aaab..8712f1ca9e 100644 --- a/test/model/transaction/SecretProofTransaction.spec.ts +++ b/test/model/transaction/SecretProofTransaction.spec.ts @@ -27,7 +27,7 @@ import { TestingAccount } from '../../conf/conf.spec'; describe('SecretProofTransaction', () => { let account: Account; - + const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; before(() => { account = TestingAccount; }); @@ -191,4 +191,24 @@ describe('SecretProofTransaction', () => { expect(secretProofTransaction.size).to.be.equal(212); }); }); + + it('should create and sign SecretProof Transaction', () => { + const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; + const secretProofTransaction = SecretProofTransaction.create( + Deadline.create(), + HashType.Op_Sha3_256, + sha3_256.create().update(convert.hexToUint8(proof)).hex(), + account.address, + proof, + NetworkType.MIJIN_TEST, + ); + + const signedTx = secretProofTransaction.signWithCatbuffer(account, generationHash); + expect(signedTx.payload.substring( + 240, + signedTx.payload.length, + )).to.be.equal( + '009B3155B37159DA50AA52D5967C509B410F5A36A3B1E31ECB5AC76675D79B4A5E90A75B6B63D31BDA938' + + '08727940F24699AECDDF17C568508BA2000B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'); + }); }); diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index c378c39c32..8e8b4cc9d4 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -238,4 +238,8 @@ class FakeTransaction extends Transaction { protected buildTransaction(): VerifiableTransaction { throw new Error('Method not implemented.'); } + + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/test/model/transaction/TransferTransaction.spec.ts b/test/model/transaction/TransferTransaction.spec.ts index 31e063be36..63d8bb880c 100644 --- a/test/model/transaction/TransferTransaction.spec.ts +++ b/test/model/transaction/TransferTransaction.spec.ts @@ -53,7 +53,7 @@ describe('TransferTransaction', () => { [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(transferTransaction.maxFee.higher).to.be.equal(0); @@ -193,4 +193,30 @@ describe('TransferTransaction', () => { expect(transaction.size).to.be.equal(158); }); }); + + it('should create TransferTransaction and sign using catbuffer', () => { + const transferTransaction = TransferTransaction.create( + Deadline.create(), + Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + [ + NetworkCurrencyMosaic.createRelative(100), + ], + PlainMessage.create('test-message'), + NetworkType.MIJIN_TEST, + ); + + expect(transferTransaction.message.payload).to.be.equal('test-message'); + expect(transferTransaction.mosaics.length).to.be.equal(1); + expect(transferTransaction.recipient).to.be.instanceof(Address); + expect((transferTransaction.recipient as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + + const signedTransaction = transferTransaction.signWithCatbuffer(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal( + '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000100746573742D6D657373616765' + + '44B262C46CEABB8500E1F50500000000'); + }); }); From 5b9b4ad6d0290f05276cb0a31b8be52a2a72b8d5 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 22:38:29 +0100 Subject: [PATCH 13/98] Manually added aggregate transaction builder --- .../catbuffer/AggregateTransactionBuilder.ts | 136 ++++++++++++++++++ .../catbuffer/CosignatureBuilder.ts | 102 +++++++++++++ .../catbuffer/DetachedCosignatureBuilder.ts | 97 +++++++++++++ 3 files changed, 335 insertions(+) create mode 100644 src/infrastructure/catbuffer/AggregateTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/CosignatureBuilder.ts create mode 100644 src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts diff --git a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts new file mode 100644 index 0000000000..64b11c499f --- /dev/null +++ b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts @@ -0,0 +1,136 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; +import { AddressDto } from './AddressDto'; +import { AliasActionDto } from './AliasActionDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** binary layout for an aggregate transaction. */ +export class AggregateTransactionBuilder extends TransactionBuilder { + /** embedded transactions. */ + transactions: Uint8Array; + /** cosignatures. */ + cosignatures: Uint8Array; + + /** + * Constructor. + * + * @param signature entity signature. + * @param signer entity signer's public key. + * @param version entity version. + * @param type entity type. + * @param fee transaction fee. + * @param deadline transaction deadline. + * @param transactions embedded transactions. + * @param cosignatures cosignatures. + */ + public constructor( + signature: SignatureDto, + signer: KeyDto, + version: number, + type: EntityTypeDto, + fee: AmountDto, + deadline: TimestampDto, + transactions: Uint8Array, + cosignatures: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + this.transactions = transactions; + this.cosignatures = cosignatures; + } + + /** + * loadFromBinary - Create an instance of AggregateTransactionBuilder from a stream. + * + * @param Uint8Array Byte to use to serialize the object. + * @return An instance of AggregateTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AggregateTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const payloadSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + const transactions = GeneratorUtils.getBytes(Uint8Array.from(byteArray), payloadSize); + byteArray.splice(0, transactions.length); + const cosignatures = Uint8Array.from(byteArray); + // tslint:disable-next-line: max-line-length + return new AggregateTransactionBuilder(superObject.signature, superObject.signer, superObject.version, + superObject.type, superObject.fee, superObject.deadline, + transactions, cosignatures); + } + + /** + * Get embedded transactions. + * + * @return embedded transactions. + */ + public getTransactions(): Uint8Array { + return this.transactions; + } + + /** + * Get cosignatures. + * + * @return cosignatures. + */ + public getCosignatures(): Uint8Array { + return this.cosignatures; + } + + /** + * Get the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += 4; // payloadSize + size += this.transactions.length; + size += this.cosignatures.length; + return size; + } + + /** + * Serialize the object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const payloadSizeBytes = GeneratorUtils.uintToBuffer(this.transactions.length, 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes); + const transactionBytes = this.transactions; + newArray = GeneratorUtils.concatTypedArrays(newArray, transactionBytes); + const cosignaturesBytes = this.transactions; + newArray = GeneratorUtils.concatTypedArrays(newArray, cosignaturesBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/CosignatureBuilder.ts b/src/infrastructure/catbuffer/CosignatureBuilder.ts new file mode 100644 index 0000000000..5e0ba7a43c --- /dev/null +++ b/src/infrastructure/catbuffer/CosignatureBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; + +/** a cosignature. */ +export class CosignatureBuilder { + /** cosigner public key. */ + signer: KeyDto; + /** cosigner signature. */ + signature: SignatureDto; + + /** + * Constructor. + * + * @param signer cosigner public key. + * @param signature cosigner signature. + */ + public constructor(signer: KeyDto, signature: SignatureDto) { + this.signer = signer; + this.signature = signature; + } + + /** + * loadFromBinary - Create an instance of CosignatureBuilder from a stream. + * + * @param payload Byte to use to serialize the object. + * @return An instance of CosignatureBuilder. + */ + public static loadFromBinary(payload: Uint8Array): CosignatureBuilder { + const byteArray = Array.from(payload); + const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signer.getSize()); + const signature = SignatureDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signature.getSize()); + return new CosignatureBuilder(signer, signature); + } + + /** + * Get cosigner public key. + * + * @return cosigner public key. + */ + public getSigner(): KeyDto { + return this.signer; + } + + /** + * Get cosigner signature. + * + * @return cosigner signature. + */ + public getSignature(): SignatureDto { + return this.signature; + } + + /** + * Get the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.signer.getSize(); + size += this.signature.getSize(); + return size; + } + + /** + * Serialize the object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const signerBytes = this.signer.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); + const signatureBytes = this.signature.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signatureBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts b/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts new file mode 100644 index 0000000000..58a3152ed0 --- /dev/null +++ b/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts @@ -0,0 +1,97 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { CosignatureBuilder } from './CosignatureBuilder'; +import { Hash256Dto } from './Hash256Dto'; + +/** a detached cosignature. */ +export class DetachedCosignatureBuilder extends CosignatureBuilder { + /** hash of the corresponding parent. */ + parentHash: Hash256Dto; + + /** + * Constructor. + * + * @param signer cosigner public key. + * @param signature cosigner signature. + * @param parentHash hash of the corresponding parent. + */ + public constructor(signer: KeyDto, signature: SignatureDto, parentHash: Hash256Dto) { + super(signer, signature); + this.parentHash = parentHash; + } + + /** + * loadFromBinary - Create an instance of DetachedCosignatureBuilder from a stream. + * + * @param payload Byte to use to serialize the object. + * @return An instance of DetachedCosignatureBuilder. + */ + public static loadFromBinary(payload: Uint8Array): DetachedCosignatureBuilder { + const byteArray = Array.from(payload); + const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signer.getSize()); + const signature = SignatureDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signature.getSize()); + const parentHash = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, parentHash.getSize()); + return new DetachedCosignatureBuilder(signer, signature, parentHash); + } + + /** + * Get hash of the corresponding parent. + * + * @return hash of the corresponding parent. + */ + public getParentHash(): Hash256Dto { + return this.parentHash; + } + + /** + * Get the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = super.getSize(); + size += this.parentHash.getSize(); + return size; + } + + /** + * Serialize the object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const signerBytes = this.signer.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); + const signatureBytes = this.signature.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signatureBytes); + const parentHashBytes = this.parentHash.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, parentHashBytes); + return newArray; + } +} From 416ffda977b344b2cfba52c29195da5779634668 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 23:43:48 +0100 Subject: [PATCH 14/98] Added embedded transaction builders --- .../AccountAddressRestrictionTransaction.ts | 23 ++++++ .../transaction/AccountLinkTransaction.ts | 18 +++++ .../AccountMosaicRestrictionTransaction.ts | 23 ++++++ .../AccountOperationRestrictionTransaction.ts | 36 +++++++-- .../transaction/AddressAliasTransaction.ts | 21 +++++- src/model/transaction/AggregateTransaction.ts | 8 ++ src/model/transaction/LockFundsTransaction.ts | 47 +++++++++++- .../ModifyMultisigAccountTransaction.ts | 24 ++++++ .../MosaicAddressRestrictionTransaction.ts | 47 +++++++++++- .../transaction/MosaicAliasTransaction.ts | 19 +++++ .../MosaicDefinitionTransaction.ts | 45 ++++++++---- .../MosaicGlobalRestrictionTransaction.ts | 49 ++++++++++++- .../MosaicSupplyChangeTransaction.ts | 19 +++++ .../RegisterNamespaceTransaction.ts | 73 ++++++++++++++++++- .../transaction/SecretLockTransaction.ts | 22 ++++++ .../transaction/SecretProofTransaction.ts | 20 +++++ src/model/transaction/Transaction.ts | 5 ++ src/model/transaction/TransferTransaction.ts | 21 ++++++ .../transaction/LockFundsTransaction.spec.ts | 30 +++++++- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- ...osaicAddressRestrictionTransaction.spec.ts | 2 +- ...MosaicGlobalRestrictionTransaction.spec.ts | 2 +- .../RegisterNamespaceTransaction.spec.ts | 4 +- test/model/transaction/Transaction.spec.ts | 4 + 24 files changed, 531 insertions(+), 33 deletions(-) diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index 243b4ff560..de89c65970 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -20,6 +20,7 @@ import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTra import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -144,4 +145,26 @@ export class AccountAddressRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountAddressRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountAddressRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedAddressDto(RawAddress.stringToAddress(modification.value)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index 41e00509b0..0d8c60c32b 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -19,6 +19,7 @@ import { Builder } from '../../infrastructure/builders/AccountLinkTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/AccountLinkTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -138,4 +139,21 @@ export class AccountLinkTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountLinkTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.LINK_ACCOUNT.valueOf(), + new KeyDto(Convert.hexToUint8(this.remoteAccountKey)), + this.linkAction.valueOf(), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index cfac1c3ea1..f8275cf7eb 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -19,6 +19,7 @@ import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTra import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -143,4 +144,26 @@ export class AccountMosaicRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountMosaicRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_MOSAIC.valueOf(), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountMosaicRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedMosaicIdDto(modification.value), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index 4ed72af488..ac24764f6c 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -16,6 +16,13 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; @@ -26,13 +33,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; -import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; -import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; -import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; -import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; export class AccountOperationRestrictionTransaction extends Transaction { @@ -142,4 +142,26 @@ export class AccountOperationRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountOperationRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_OPERATION.valueOf(), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountOperationRestrictionModificationBuilder( + modification.modificationType.valueOf(), + modification.value.valueOf(), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index b1b449dc69..8be88d2be4 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -14,11 +14,13 @@ * limitations under the License. */ +import { RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AddressAliasTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; import { AddressDto } from '../../infrastructure/catbuffer/AddressDto'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; @@ -35,7 +37,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { RawAddress } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -156,4 +157,22 @@ export class AddressAliasTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAddressAliasTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ADDRESS_ALIAS.valueOf(), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new AddressDto(RawAddress.stringToAddress(this.address.plain())), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 016f66fd8e..5f94e1fe33 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -211,4 +211,12 @@ export class AggregateTransaction extends Transaction { protected generateBytes(): Uint8Array { throw new Error('Not implemented'); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index 9ad23c1a60..52027d141d 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -14,8 +14,19 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/HashLockTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EmbeddedHashLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder'; +import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; +import { HashLockTransactionBuilder } from '../../infrastructure/catbuffer/HashLockTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicBuilder } from '../../infrastructure/catbuffer/UnresolvedMosaicBuilder'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { Mosaic } from '../mosaic/Mosaic'; @@ -142,6 +153,40 @@ export class LockFundsTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new HashLockTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.LOCK.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), + new AmountDto(this.mosaic.amount.toDTO())), + new BlockDurationDto(this.duration.toDTO()), + new Hash256Dto(Convert.hexToUint8(this.hash)), + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedHashLockTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.LOCK.valueOf(), + new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), + new AmountDto(this.mosaic.amount.toDTO())), + new BlockDurationDto(this.duration.toDTO()), + new Hash256Dto(Convert.hexToUint8(this.hash)), + ); + return transactionBuilder.serialize(); } } diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index dbc22505a7..f33e7af077 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -32,6 +32,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; /** * Modify multisig account transactions are part of the NEM's multisig account system. @@ -165,4 +166,27 @@ export class ModifyMultisigAccountTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMultisigAccountModificationTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MODIFY_MULTISIG_ACCOUNT.valueOf(), + this.minRemovalDelta, + this.minApprovalDelta, + this.modifications.map((modification) => { + return new CosignatoryModificationBuilder( + modification.type.valueOf(), + new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index 3bc49806c6..b1c62e0167 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -14,8 +14,17 @@ * limitations under the License. */ +import { RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicAddressRestrictionTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -155,6 +164,42 @@ export class MosaicAddressRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicAddressRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_ADDRESS_RESTRICTION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + this.restrictionKey.toDTO(), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.targetAddress.plain())), + this.previousRestrictionValue.toDTO(), + this.newRestrictionValue.toDTO(), + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicAddressRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_ADDRESS_RESTRICTION.valueOf(), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + this.restrictionKey.toDTO(), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.targetAddress.plain())), + this.previousRestrictionValue.toDTO(), + this.newRestrictionValue.toDTO(), + ); + return transactionBuilder.serialize(); } } diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index 2ae1588994..6e2e600ff8 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -17,6 +17,7 @@ import { Builder } from '../../infrastructure/builders/MosaicAliasTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { MosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/MosaicAliasTransactionBuilder'; @@ -151,4 +152,22 @@ export class MosaicAliasTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicAliasTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_ALIAS.valueOf(), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 7a41faddf9..8ac6e76eb0 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -16,8 +16,19 @@ import { Builder } from '../../infrastructure/builders/MosaicCreationTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EmbeddedMosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; +import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; +import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; +import { MosaicFlags } from '../mosaic/MosaicFlag'; import { MosaicId } from '../mosaic/MosaicId'; import { MosaicNonce } from '../mosaic/MosaicNonce'; import { MosaicProperties } from '../mosaic/MosaicProperties'; @@ -27,19 +38,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; -import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; -import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; -import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; -import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; -import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; -import { MosaicFlagsDto } from '../../infrastructure/catbuffer/MosaicFlagsDto'; -import { MosaicFlags } from '../mosaic/MosaicFlag'; -import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; -import { Convert } from '../../core/format'; -import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; /** * Before a mosaic can be created or transferred, a corresponding definition of the mosaic has to be created and published to the network. @@ -212,4 +210,25 @@ export class MosaicDefinitionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicDefinitionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_DEFINITION.valueOf(), + new MosaicNonceDto(this.getMosaicNonceIntValue()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + this.getMosaicFlagValue(), + this.mosaicProperties.divisibility, + new BlockDurationDto(this.mosaicProperties.duration ? + this.mosaicProperties.duration.toDTO() : []), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index 7cbb7a55d5..b2d421dca3 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -16,6 +16,13 @@ import { Builder } from '../../infrastructure/builders/MosaicGlobalRestrictionTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicGlobalRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicGlobalRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -178,6 +185,46 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicGlobalRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_GLOBAL_RESTRICTION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + new UnresolvedMosaicIdDto(this.referenceMosaicId.id.toDTO()), + this.restrictionKey.toDTO(), + this.previousRestrictionValue.toDTO(), + this.previousRestrictionType.valueOf(), + this.newRestrictionValue.toDTO(), + this.newRestrictionType.valueOf(), + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicGlobalRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_GLOBAL_RESTRICTION.valueOf(), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + new UnresolvedMosaicIdDto(this.referenceMosaicId.id.toDTO()), + this.restrictionKey.toDTO(), + this.previousRestrictionValue.toDTO(), + this.previousRestrictionType.valueOf(), + this.newRestrictionValue.toDTO(), + this.newRestrictionType.valueOf(), + ); + return transactionBuilder.serialize(); } } diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index b53fbd92d3..cc58bda02e 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -17,6 +17,7 @@ import { Builder } from '../../infrastructure/builders/MosaicSupplyChangeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { MosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -152,4 +153,22 @@ export class MosaicSupplyChangeTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicSupplyChangeTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_SUPPLY_CHANGE.valueOf(), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + this.direction.valueOf(), + new AmountDto(this.delta.toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index f1f29cd6a2..627397bc69 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -14,9 +14,17 @@ * limitations under the License. */ -import { Convert as convert } from '../../core/format'; +import { Convert, Convert as convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/NamespaceCreationTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EmbeddedNamespaceRegistrationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; +import { NamespaceRegistrationTransactionBuilder } from '../../infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import {NamespaceMosaicIdGenerator} from '../../infrastructure/transaction/NamespaceMosaicIdGenerator'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -187,6 +195,67 @@ export class RegisterNamespaceTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + let transactionBuilder: NamespaceRegistrationTransactionBuilder; + if (this.namespaceType === NamespaceType.RootNamespace) { + transactionBuilder = new NamespaceRegistrationTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.REGISTER_NAMESPACE.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), + new BlockDurationDto(this.duration!.toDTO()), + undefined, + ); + } else { + transactionBuilder = new NamespaceRegistrationTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.REGISTER_NAMESPACE.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), + undefined, + new NamespaceIdDto(this.parentId!.id.toDTO()), + ); + } + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + let transactionBuilder: EmbeddedNamespaceRegistrationTransactionBuilder; + if (this.namespaceType === NamespaceType.RootNamespace) { + transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_LOCK.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), + new BlockDurationDto(this.duration!.toDTO()), + undefined, + ); + } else { + transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_LOCK.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), + undefined, + new NamespaceIdDto(this.parentId!.id.toDTO()), + ); + } + return transactionBuilder.serialize(); } } diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index 9e02785071..9c0efaab1e 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -18,6 +18,7 @@ import { Builder } from '../../infrastructure/builders/SecretLockTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EmbeddedSecretLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -197,4 +198,25 @@ export class SecretLockTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedSecretLockTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_LOCK.valueOf(), + new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), + new AmountDto(this.mosaic.amount.toDTO())), + new BlockDurationDto(this.duration.toDTO()), + this.hashType.valueOf(), + new Hash256Dto(this.getSecretByte()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipient.plain())), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index 588638fcc6..acc1c53d7b 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -18,6 +18,7 @@ import { Convert, Convert as convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/SecretProofTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedSecretProofTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -178,4 +179,23 @@ export class SecretProofTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedSecretProofTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_PROOF.valueOf(), + this.hashType.valueOf(), + new Hash256Dto(this.getSecretByte()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipient.plain())), + this.getProofByte(), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index 0bc6786fb3..ceea1ab24c 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -90,6 +90,11 @@ export abstract class Transaction { */ protected abstract generateBytes(): Uint8Array; + /** + * @internal + */ + protected abstract generateEmbeddedBytes(): Uint8Array; + /** * @internal * Serialize and sign transaction creating a new SignedTransaction diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 31dea94577..08b6b29cc2 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -19,6 +19,7 @@ import { RawAddress } from '../../core/format/RawAddress'; import { Builder } from '../../infrastructure/builders/TransferTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedTransferTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedTransferTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -205,4 +206,24 @@ export class TransferTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const transactionBuilder = new EmbeddedTransferTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.TRANSFER.valueOf(), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), + this.getMessageBuffer(), + this.sortMosaics().map((mosaic) => { + return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), + new AmountDto(mosaic.amount.toDTO())); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/test/model/transaction/LockFundsTransaction.spec.ts b/test/model/transaction/LockFundsTransaction.spec.ts index ebd56dc4e0..df3583f1d7 100644 --- a/test/model/transaction/LockFundsTransaction.spec.ts +++ b/test/model/transaction/LockFundsTransaction.spec.ts @@ -15,6 +15,7 @@ */ import {deepEqual} from 'assert'; import {expect} from 'chai'; +import {Account} from '../../../src/model/account/Account'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; import {AggregateTransaction} from '../../../src/model/transaction/AggregateTransaction'; @@ -24,8 +25,11 @@ import {UInt64} from '../../../src/model/UInt64'; import {TestingAccount} from '../../conf/conf.spec'; describe('LockFundsTransaction', () => { - const account = TestingAccount; + let account: Account; const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; + before(() => { + account = TestingAccount; + }); it('should default maxFee field be set to 0', () => { const aggregateTransaction = AggregateTransaction.createBonded( Deadline.create(), @@ -58,7 +62,7 @@ describe('LockFundsTransaction', () => { UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(lockFundsTransaction.maxFee.higher).to.be.equal(0); @@ -100,6 +104,28 @@ describe('LockFundsTransaction', () => { }).to.throw(Error); }); + it('should create and sign LockFundsTransaction', () => { + const aggregateTransaction = AggregateTransaction.createBonded( + Deadline.create(), + [], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = account.sign(aggregateTransaction, generationHash); + const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), + NetworkCurrencyMosaic.createRelative(10), + UInt64.fromUint(10), + signedTransaction, + NetworkType.MIJIN_TEST, + ); + const signedTx = lockFundsTransaction.signWithCatbuffer(account, generationHash); + + expect(signedTx.payload.substring( + 136, + signedTransaction.payload.length - 32, + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE0190484100000000'); + }); + describe('size', () => { it('should return 176 for LockFundsTransaction transaction byte size', () => { const aggregateTransaction = AggregateTransaction.createBonded( diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index c1c549a0b6..f6232022da 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -70,7 +70,7 @@ describe('ModifyMultisigAccountTransaction', () => { NetworkType.MIJIN_TEST), )], NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(modifyMultisigAccountTransaction.maxFee.higher).to.be.equal(0); diff --git a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts index 947904ce56..02aad2fc65 100644 --- a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts @@ -47,7 +47,7 @@ describe('MosaicAddressRestrictionTransaction', () => { expect(mosaicAddressRestrictionTransaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(8).toHex()); expect(mosaicAddressRestrictionTransaction.targetAddress.plain()).to.be.equal(account.address.plain()); - const signedTransaction = mosaicAddressRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicAddressRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts index 39c409bd22..9e436d2fea 100644 --- a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts @@ -54,7 +54,7 @@ describe('MosaicGlobalRestrictionTransaction', () => { expect(mosaicGlobalRestrictionTransaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.EQ); expect(mosaicGlobalRestrictionTransaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); - const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicGlobalRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/RegisterNamespaceTransaction.spec.ts b/test/model/transaction/RegisterNamespaceTransaction.spec.ts index dcd12d95f7..db497c73b9 100644 --- a/test/model/transaction/RegisterNamespaceTransaction.spec.ts +++ b/test/model/transaction/RegisterNamespaceTransaction.spec.ts @@ -66,7 +66,7 @@ describe('RegisterNamespaceTransaction', () => { expect(registerNamespaceTransaction.duration!.lower).to.be.equal(1000); expect(registerNamespaceTransaction.duration!.higher).to.be.equal(0); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -83,7 +83,7 @@ describe('RegisterNamespaceTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index 8e8b4cc9d4..6f53048623 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -242,4 +242,8 @@ class FakeTransaction extends Transaction { protected generateBytes(): Uint8Array { throw new Error('Not implemented'); } + + protected generateEmbeddedBytes(): Uint8Array { + throw new Error('Not implemented'); + } } From 01234ca994bad184e5a419fc8874756a572c3dce Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 08:26:17 +0100 Subject: [PATCH 15/98] Applied catbuffer on aggregate transaction --- .../catbuffer/AggregateTransactionBuilder.ts | 6 +-- .../AccountAddressRestrictionTransaction.ts | 6 +-- .../transaction/AccountLinkTransaction.ts | 4 +- .../AccountMosaicRestrictionTransaction.ts | 6 +-- .../AccountOperationRestrictionTransaction.ts | 5 +- .../transaction/AddressAliasTransaction.ts | 6 +-- src/model/transaction/AggregateTransaction.ts | 47 +++++++++++++++++-- src/model/transaction/LockFundsTransaction.ts | 4 +- .../ModifyMultisigAccountTransaction.ts | 4 +- .../MosaicAddressRestrictionTransaction.ts | 6 +-- .../transaction/MosaicAliasTransaction.ts | 5 +- .../MosaicDefinitionTransaction.ts | 5 +- .../MosaicGlobalRestrictionTransaction.ts | 5 +- .../MosaicSupplyChangeTransaction.ts | 5 +- .../RegisterNamespaceTransaction.ts | 5 +- .../transaction/SecretLockTransaction.ts | 4 +- .../transaction/SecretProofTransaction.ts | 4 +- src/model/transaction/Transaction.ts | 9 ++++ src/model/transaction/TransferTransaction.ts | 3 +- .../transaction/AggregateTransaction.spec.ts | 2 +- 20 files changed, 81 insertions(+), 60 deletions(-) diff --git a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts index 64b11c499f..20462d8514 100644 --- a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts +++ b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts @@ -19,14 +19,10 @@ *** along with Catapult. If not, see . **/ -import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; -import { AddressDto } from './AddressDto'; -import { AliasActionDto } from './AliasActionDto'; import { AmountDto } from './AmountDto'; import { EntityTypeDto } from './EntityTypeDto'; import { GeneratorUtils } from './GeneratorUtils'; import { KeyDto } from './KeyDto'; -import { NamespaceIdDto } from './NamespaceIdDto'; import { SignatureDto } from './SignatureDto'; import { TimestampDto } from './TimestampDto'; import { TransactionBuilder } from './TransactionBuilder'; @@ -129,7 +125,7 @@ export class AggregateTransactionBuilder extends TransactionBuilder { newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes); const transactionBytes = this.transactions; newArray = GeneratorUtils.concatTypedArrays(newArray, transactionBytes); - const cosignaturesBytes = this.transactions; + const cosignaturesBytes = this.cosignatures; newArray = GeneratorUtils.concatTypedArrays(newArray, cosignaturesBytes); return newArray; } diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index de89c65970..fd4200205c 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RawAddress } from '../../core/format'; +import { Convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; @@ -151,10 +151,8 @@ export class AccountAddressRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountAddressRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), this.restrictionType.valueOf(), diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index 0d8c60c32b..bd0a0303db 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -145,10 +145,8 @@ export class AccountLinkTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountLinkTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.LINK_ACCOUNT.valueOf(), new KeyDto(Convert.hexToUint8(this.remoteAccountKey)), diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index f8275cf7eb..efe54c41d8 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -14,13 +14,13 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; @@ -150,10 +150,8 @@ export class AccountMosaicRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountMosaicRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ACCOUNT_RESTRICTION_MOSAIC.valueOf(), this.restrictionType.valueOf(), diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index ac24764f6c..b42d33e3ab 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; @@ -148,10 +149,8 @@ export class AccountOperationRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountOperationRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ACCOUNT_RESTRICTION_OPERATION.valueOf(), this.restrictionType.valueOf(), diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 8be88d2be4..98a416a6d3 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RawAddress } from '../../core/format'; +import { Convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AddressAliasTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; @@ -163,10 +163,8 @@ export class AddressAliasTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAddressAliasTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ADDRESS_ALIAS.valueOf(), this.actionType.valueOf(), diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 5f94e1fe33..797eb757e5 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -15,8 +15,16 @@ */ import { SignSchema } from '../../core/crypto'; -import { Builder } from '../../infrastructure/builders/AggregateTransaction'; +import { Convert } from '../../core/format'; import { AggregateTransaction as AggregatedTransactionCore} from '../../infrastructure/builders/AggregateTransaction'; +import { Builder } from '../../infrastructure/builders/AggregateTransaction'; +import { AggregateTransactionBuilder } from '../../infrastructure/catbuffer/AggregateTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { CosignatureBuilder } from '../../infrastructure/catbuffer/CosignatureBuilder'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { Account } from '../account/Account'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -209,7 +217,40 @@ export class AggregateTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + let transactions = Uint8Array.from([]); + this.innerTransactions.forEach((transaction) => { + const transactionByte = transaction.toAggregateTransactionBytes(); + transactions = GeneratorUtils.concatTypedArrays(transactions, transactionByte); + }); + + const cosignatures = Uint8Array.from([]); + this.cosignatures.forEach((cosignature) => { + const signerBytes = Convert.hexToUint8(cosignature.signer.publicKey); + const signatureBytes = Convert.hexToUint8(cosignature.signature); + const cosignatureBytes = new CosignatureBuilder( + new KeyDto(signerBytes), + new SignatureDto(signatureBytes), + ).serialize(); + transactions = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); + }); + + console.log('cosignatures', Convert.uint8ToHex(cosignatures)); + console.log('transactions', Convert.uint8ToHex(transactions)); + + const transactionBuilder = new AggregateTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + this.type.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + transactions, + cosignatures, + ); + return transactionBuilder.serialize(); } /** @@ -217,6 +258,6 @@ export class AggregateTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - throw new Error('Not implemented'); + throw new Error('Method not implemented'); } } diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index 52027d141d..e34bb40489 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -176,10 +176,8 @@ export class LockFundsTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedHashLockTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.LOCK.valueOf(), new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index f33e7af077..fa1e35dfef 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -172,10 +172,8 @@ export class ModifyMultisigAccountTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMultisigAccountModificationTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MODIFY_MULTISIG_ACCOUNT.valueOf(), this.minRemovalDelta, diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index b1c62e0167..819d69c43c 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RawAddress } from '../../core/format'; +import { Convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicAddressRestrictionTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -188,10 +188,8 @@ export class MosaicAddressRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicAddressRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_ADDRESS_RESTRICTION.valueOf(), new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index 6e2e600ff8..f822b73505 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicAliasTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -158,10 +159,8 @@ export class MosaicAliasTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicAliasTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_ALIAS.valueOf(), this.actionType.valueOf(), diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 8ac6e76eb0..c0adbd1e8b 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicCreationTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -216,10 +217,8 @@ export class MosaicDefinitionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicDefinitionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_DEFINITION.valueOf(), new MosaicNonceDto(this.getMosaicNonceIntValue()), diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index b2d421dca3..7b4f757efc 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicGlobalRestrictionTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -211,10 +212,8 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicGlobalRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_GLOBAL_RESTRICTION.valueOf(), new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index cc58bda02e..be4f3a89a3 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -33,6 +33,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { Convert } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -159,10 +160,8 @@ export class MosaicSupplyChangeTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicSupplyChangeTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_SUPPLY_CHANGE.valueOf(), new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index 627397bc69..0cdcae2aa6 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -233,11 +233,10 @@ export class RegisterNamespaceTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); let transactionBuilder: EmbeddedNamespaceRegistrationTransactionBuilder; if (this.namespaceType === NamespaceType.RootNamespace) { transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.SECRET_LOCK.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), @@ -247,7 +246,7 @@ export class RegisterNamespaceTransaction extends Transaction { ); } else { transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.SECRET_LOCK.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index 9c0efaab1e..e65187384d 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -204,10 +204,8 @@ export class SecretLockTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedSecretLockTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.SECRET_LOCK.valueOf(), new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index acc1c53d7b..41df6b207b 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -185,10 +185,8 @@ export class SecretProofTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedSecretProofTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.SECRET_PROOF.valueOf(), this.hashType.valueOf(), diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index ceea1ab24c..ca2fbbce44 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -186,6 +186,15 @@ export abstract class Transaction { return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {signer}); } + /** + * Takes a transaction and formats bytes to be included in an aggregate transaction. + * + * @return transaction with signer serialized to be part of an aggregate transaction + */ + public toAggregateTransactionBytes() { + return this.generateEmbeddedBytes(); + } + /** * Transaction pending to be included in a block * @returns {boolean} diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 08b6b29cc2..6714fd7904 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -212,9 +212,8 @@ export class TransferTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); const transactionBuilder = new EmbeddedTransferTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.TRANSFER.valueOf(), new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index ab53059940..d6a4c714aa 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -106,7 +106,7 @@ describe('AggregateTransaction', () => { NetworkType.MIJIN_TEST, []); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); + const signedTransaction = aggregateTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); From 6abee2aa280c69a53a3b2e0a4e17cba7c8fca8ea Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 11:46:27 +0100 Subject: [PATCH 16/98] Removed old flatbuffer staffs --- e2e/conf/network.conf | 64 +- .../buffers/AccountLinkTransactionBuffer.ts | 425 ---------- ...untRestrictionsAddressTransactionBuffer.ts | 557 ------------- ...RestrictionsEntityTypeTransactionBuffer.ts | 520 ------------ ...ountRestrictionsMosaicTransactionBuffer.ts | 557 ------------- .../buffers/AddressAliasTransactionBuffer.ts | 479 ----------- .../buffers/AggregateTransactionBuffer.ts | 425 ---------- .../buffers/HashLockTransactionBuffer.ts | 571 ------------- ...saicAddressRestrictionTransactionBuffer.ts | 625 -------------- .../buffers/MosaicAliasTransactionBuffer.ts | 479 ----------- .../MosaicCreationTransactionBuffer.ts | 582 ------------- ...osaicGlobalRestrictionTransactionBuffer.ts | 657 --------------- .../MosaicSupplyChangeTransactionBuffer.ts | 479 ----------- .../MultisigModificationTransactionBuffer.ts | 571 ------------- .../NamespaceCreationTransactionBuffer.ts | 512 ------------ .../buffers/SecretLockTransactionBuffer.ts | 641 -------------- .../buffers/SecretProofTransactionBuffer.ts | 549 ------------ .../buffers/TransferTransactionBuffer.ts | 785 ------------------ .../builders/AccountLinkTransaction.ts | 110 --- .../AccountRestrictionsAddressTransaction.ts | 128 --- ...ccountRestrictionsEntityTypeTransaction.ts | 126 --- .../AccountRestrictionsMosaicTransaction.ts | 127 --- .../builders/AddressAliasTransaction.ts | 122 --- .../builders/AggregateTransaction.ts | 151 ---- .../builders/CosignatureTransaction.ts | 27 - src/infrastructure/builders/Deadline.ts | 22 - .../builders/HashLockTransaction.ts | 127 --- .../MosaicAddressRestrictionTransaction.ts | 146 ---- .../builders/MosaicAliasTransaction.ts | 122 --- .../builders/MosaicCreationTransaction.ts | 164 ---- .../MosaicGlobalRestrictionTransaction.ts | 159 ---- .../builders/MosaicSupplyChangeTransaction.ts | 120 --- .../MultisigModificationTransaction.ts | 134 --- .../builders/NamespaceCreationTransaction.ts | 142 ---- .../builders/SecretLockTransaction.ts | 142 ---- .../builders/SecretProofTransaction.ts | 127 --- .../builders/TransferTransaction.ts | 152 ---- .../builders/VerifiableTransaction.ts | 128 --- .../builders/VerificableTransactionBuilder.ts | 65 -- .../schemas/AccountLinkTransactionSchema.ts | 44 - ...onsAddressModificationTransactionSchema.ts | 48 -- ...EntityTypeModificationTransactionSchema.ts | 48 -- ...ionsMosaicModificationTransactionSchema.ts | 48 -- .../schemas/AddressAliasTransactionSchema.ts | 44 - .../schemas/AggregateTransactionSchema.ts | 44 - .../schemas/HashLockTransactionSchema.ts | 45 - ...saicAddressRestrictionTransactionSchema.ts | 46 - .../schemas/MosaicAliasTransactionSchema.ts | 44 - .../MosaicCreationTransactionSchema.ts | 63 -- ...osaicGlobalRestrictionTransactionSchema.ts | 49 -- .../MosaicSupplyChangeTransactionSchema.ts | 44 - .../MultisigModificationTransactionSchema.ts | 49 -- .../NamespaceCreationTransactionSchema.ts | 47 -- src/infrastructure/schemas/Schema.ts | 374 --------- .../schemas/SecretLockTransactionSchema.ts | 48 -- .../schemas/SecretProofTransactionSchema.ts | 47 -- .../schemas/TransferTransactionSchema.ts | 55 -- .../CreateTransactionFromPayload.ts | 14 +- .../AccountAddressRestrictionTransaction.ts | 17 - .../transaction/AccountLinkTransaction.ts | 16 - .../AccountMosaicRestrictionTransaction.ts | 16 - .../AccountOperationRestrictionTransaction.ts | 16 - .../transaction/AddressAliasTransaction.ts | 17 - src/model/transaction/AggregateTransaction.ts | 67 +- .../transaction/CosignatureTransaction.ts | 39 +- src/model/transaction/LockFundsTransaction.ts | 19 - .../ModifyMultisigAccountTransaction.ts | 19 +- .../MosaicAddressRestrictionTransaction.ts | 19 - .../transaction/MosaicAliasTransaction.ts | 17 - .../MosaicDefinitionTransaction.ts | 35 +- .../MosaicGlobalRestrictionTransaction.ts | 21 - .../MosaicSupplyChangeTransaction.ts | 19 +- .../RegisterNamespaceTransaction.ts | 28 +- .../transaction/SecretLockTransaction.ts | 21 - .../transaction/SecretProofTransaction.ts | 19 - src/model/transaction/Transaction.ts | 88 +- src/model/transaction/TransferTransaction.ts | 35 +- .../AccountLinkTransaction.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 6 +- .../AddressAliasTransaction.spec.ts | 4 +- .../transaction/AggregateTransaction.spec.ts | 8 +- .../transaction/LockFundsTransaction.spec.ts | 2 +- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- ...osaicAddressRestrictionTransaction.spec.ts | 2 +- .../MosaicAliasTransaction.spec.ts | 4 +- .../MosaicDefinitionTransaction.spec.ts | 8 +- ...MosaicGlobalRestrictionTransaction.spec.ts | 2 +- .../RegisterNamespaceTransaction.spec.ts | 4 +- .../transaction/SecretLockTransaction.spec.ts | 2 +- .../SecretProofTransaction.spec.ts | 2 +- test/model/transaction/Transaction.spec.ts | 5 - .../transaction/TransferTransaction.spec.ts | 2 +- 92 files changed, 177 insertions(+), 13626 deletions(-) delete mode 100644 src/infrastructure/buffers/AccountLinkTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AccountRestrictionsAddressTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AccountRestrictionsEntityTypeTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AccountRestrictionsMosaicTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AddressAliasTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AggregateTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/HashLockTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicAddressRestrictionTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicAliasTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicCreationTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicGlobalRestrictionTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicSupplyChangeTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MultisigModificationTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/NamespaceCreationTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/SecretLockTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/SecretProofTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/TransferTransactionBuffer.ts delete mode 100644 src/infrastructure/builders/AccountLinkTransaction.ts delete mode 100644 src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts delete mode 100644 src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts delete mode 100644 src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts delete mode 100644 src/infrastructure/builders/AddressAliasTransaction.ts delete mode 100644 src/infrastructure/builders/AggregateTransaction.ts delete mode 100644 src/infrastructure/builders/CosignatureTransaction.ts delete mode 100644 src/infrastructure/builders/Deadline.ts delete mode 100644 src/infrastructure/builders/HashLockTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicAddressRestrictionTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicAliasTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicCreationTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicGlobalRestrictionTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicSupplyChangeTransaction.ts delete mode 100644 src/infrastructure/builders/MultisigModificationTransaction.ts delete mode 100644 src/infrastructure/builders/NamespaceCreationTransaction.ts delete mode 100644 src/infrastructure/builders/SecretLockTransaction.ts delete mode 100644 src/infrastructure/builders/SecretProofTransaction.ts delete mode 100644 src/infrastructure/builders/TransferTransaction.ts delete mode 100644 src/infrastructure/builders/VerifiableTransaction.ts delete mode 100644 src/infrastructure/builders/VerificableTransactionBuilder.ts delete mode 100644 src/infrastructure/schemas/AccountLinkTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AccountRestrictionsAddressModificationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AccountRestrictionsEntityTypeModificationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AccountRestrictionsMosaicModificationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AddressAliasTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AggregateTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/HashLockTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicAddressRestrictionTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicAliasTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicCreationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicGlobalRestrictionTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicSupplyChangeTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MultisigModificationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/NamespaceCreationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/Schema.ts delete mode 100644 src/infrastructure/schemas/SecretLockTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/SecretProofTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/TransferTransactionSchema.ts diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index 95fa85d3c7..79f895aecf 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -1,54 +1,54 @@ { - "apiUrl": "http://localhost:3000", + "apiUrl": "http://c2.nem.ninja:3000", "generationHash": "57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6", "testAccount": { - "privateKey": "D242FB34C2C4DD36E995B9C865F93940065E326661BA5A4A247331D211FE3A3D", - "address": "SBMYYFIM6VGG45KWGSZLSXFHP74WVT7MOF6UYBHT", - "publicKey": "2FC3872A792933617D70E02AFF8FBDE152821A0DF0CA5FB04CB56FC3D21C8863" + "privateKey": "E1C8521608F4896CA26A0C2DE739310EA4B06861D126CF4D6922064678A1969B", + "address": "SAKT3CKHCYIG5BBOPTSY2WXSVPBSLIA67AEOX4ND", + "publicKey": "9F784BF20318AE3CA6246C0EC2207FE095FFF7A84B6787E7E3C2CE4C3B92A2EA" }, "multisigAccount": { - "privateKey": "6EBE2AB0584C816771B494B36B40EC6CE1A0024C37DC6056D89D570A21A70262", - "address": "SCJAK5N6ICIE3JGHV5SVDSSNM5RUZZVDWQJ5G76N", - "publicKey": "224556169645EFAB772BFE1B5665490334428017E5D86FB3C9DFC4070B2F16A6" + "privateKey": "A9CEAA617D0B7D9DEBE9F96BD63CCF68A49950BB315CB9A4169FC6AAA1EC9E28", + "address": "SDWY3PYN4ZZO4S4EBEY2UPSSZUPGZH2G2LQMUSEU", + "publicKey": "8A613468924B8771779C7E4C889205A9BE6CAE0B9435B4BCC8E79A8DD8571608" }, "cosignatoryAccount": { - "privateKey": "44C0044B36AEF44C7743C407CEE4B6FD801BF6B0652AB7799B0991FFD3A81E71", - "address": "SCPL4YCGZYCML5WUSCIVN5MQF5YZAAF4GMZJIEL4", - "publicKey": "76C1622C7FB58986E500228E8FFB30C606CAAFC1CD78E770E82C73DAB7BD7C9F" + "privateKey": "8CBAA7491B7DC1070BECBC4F60AE55F4A272DA1DAD1D502DB016E142993817BA", + "address": "SB7Q5A3KEKFEWBPBTC6RFKU6Q2L4V7DM4ZNE4A7A", + "publicKey": "61B8EB2C02F3D3731A8EF6FE4CCD6BC84615BABA09CA3E891C0D2542096E6AD3" }, "cosignatory2Account": { - "privateKey": "F7B3A64652BAE6DB00D8B7C45F9D1C9BE0DB9E02002111A0B547AE1E220B7DDC", - "address": "SBISV4QCGJ7SSOLG64DBNPWU6J7SSY64R22D2L3Q", - "publicKey": "B5C2611E32E16482B0B9811ABF906A1DE84184DED1D343790482F517C02FB01C" + "privateKey": "60380027EBE63A5D60F6156F5637685172331705160783FF2F9D93C1E5A8622B", + "address": "SCM47E3JVPHOFWLSMNX3RKQQQIB3JUBR7MTX4M4P", + "publicKey": "3D9996683A0FA460D13288B846DF68A9B6C0C1F14EC2E43907DF8D84DC87B9C2" }, "cosignatory3Account": { - "privateKey": "A7D6ED74CDDECBF621DDC63558433DB604FA800D138810B3DF9B4EC880D0705F", - "address": "SD2UY5LHIAAZDVKRHBOYSS4MTLHVTJVUTQPEGV2U", - "publicKey": "3A33DA75E00F643C49C57E8BD3282149911B06FF107C37F7AEDFED5532166BDA" + "privateKey": "E39CE241F730CD190658AFDB5F3896628F92D7BC35D88435D148BED88C6CC844", + "address": "SDEVG5MU4MEGJ72NSBC7PKMK7JCJKN7QB3DOVARJ", + "publicKey": "422697046582D8B8063931B7327D0C06FA454B416F6A5C000922EC5BA546F4B2" }, "cosignatory4Account": { - "privateKey": "D2A12301F5595869EFD5374B3372F0ED7EC26BF73A71D310950CC018D3FA0B03", - "address": "SD7PYMM2BTT4SGSITZ2MBQBK4SXIQQQV4ZOP46VF", - "publicKey": "FDE589878756C2287056EC8D7B2829D9C1FA6D389EBDC808034813FE7810AAB0" + "privateKey": "0EA7E63C96FC580AD5EE85ED3C77A96B421F7C8BF75A83AB889313114C9082F2", + "address": "SCBNKMD23J7BO3Q42SEGP4LXGVJYSDPUESSEWGWZ", + "publicKey": "3A225A2C7C7D95279E74D420728D2DA2A176DE036B67909074AEF5F2DCFAF31C" }, "testAccount2": { - "privateKey": "E5DCCEBDB01A8B03A7DB7BA5888E2E33FD4617B5F6FED48C4C09C0780F422713", - "address": "SBSBLBT7CIOQG6XUI7TRDMHV4TKS5O7QM3MWQYHL", - "publicKey": "5F14CD455A1C0B08073C657EFA09365921736C1ADAF0F0685848678AE966EE09" + "privateKey": "A084418D937627BCDA19B277D8610C845124149FA18AABE96A17D56A2EA7FB8B", + "address": "SBF5HY3T7SXIBCSK4V4WNS4LS4QUMESMVNBCD2AQ", + "publicKey": "1C4B44400FDC933860B1949A5AEA756F19A36D73C4634699E49C3E7275EFA54F" }, "testAccount3": { - "privateKey": "CA95470BEFF4487D692D501E5C41F86FAE9CE6DD15B7B64E150E42A18BDE9CF8", - "address": "SBCFDASM35I6JSLUPQMSX2WGJG55WOCNB53NNVPH", - "publicKey": "E97077A656D9E7F5679880D4950BBF2B3638B7ACE17C82CCB7881DE9BAF396C6" + "privateKey": "8C9E72C5D8964A19174B478B65BD4B7F2AFD8F92C05AE45B15A9EDF222EC8CA8", + "address": "SDY65GIMMOF7GZGGART66QGS6ELWDTQT55JJOF42", + "publicKey": "B8320002C5CF64D855F073F2387FB18F13E7A04FA57FC3743694B04579104F98" }, "testAccountNoBalance": { - "privateKey": "A0591F79F588758280DFB4823A47FCEEC6A551344F794FFDE3760A9D7E1DE348", - "address": "SC5NTT5APX2FAUS4VQUII3UTMAD7GHRFTLDQOEDW", - "publicKey": "6D652E480E5B2997A19D0C7485724693D79A63FCD591A948B40240BD196BA7D6" + "privateKey": "CE4E6B1113EF8999ED79A027A4F3255C367BC2E40417E27E614FB7C12E42BDFA", + "address": "SDNMDW5TXIORKRXQ7F3QORRW4KUAK4ALQ7JWX2KJ", + "publicKey": "92658FE642AEAF1B766D0F4FE4E263C3A0E069735836383D31A70E2B7801358B" }, "harvestingAccount": { - "privateKey": "0B9802C011DA2D61BCD203F4DC76C012898EE38BA54A7E030B86630A8FD43CA6", - "address": "SAALWHKCWH72J53M3M4LB6UYFGLQMAOXJACWJX2U", - "publicKey": "092CAAFEBCB51C64A7CE423050964492407B264CA306D063DBA927A2304C4DD8" + "privateKey": "9999630E4AE5CA5675A703F3268084EB9A9B477A8C519D66465D5D21830E691A", + "address": "SC2PGQO5WV4QZRAQHJDNQ2Q5IFWA2D3VLFEFFZHC", + "publicKey": "74771A0B0B920D787F4F8242926C348007B23062910DE99C7E56AA79D4D7B90A" } -} \ No newline at end of file +} diff --git a/src/infrastructure/buffers/AccountLinkTransactionBuffer.ts b/src/infrastructure/buffers/AccountLinkTransactionBuffer.ts deleted file mode 100644 index 30dde827ce..0000000000 --- a/src/infrastructure/buffers/AccountLinkTransactionBuffer.ts +++ /dev/null @@ -1,425 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.AccountLinkTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AccountLinkTransactionBuffer} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AccountLinkTransactionBuffer=} obj - * @returns {Catapult.Buffers.AccountLinkTransactionBuffer} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.getRootAsAccountLinkTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AccountLinkTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signerLength = function() { - let offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signerArray = function() { - let offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.version = function() { - let offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.type = function() { - let offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.fee = function(index) { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.feeLength = function() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.feeArray = function() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.deadline = function(index) { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.deadlineLength = function() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.deadlineArray = function() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.remoteAccountKey = function(index) { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.remoteAccountKeyLength = function() { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.remoteAccountKeyArray = function() { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.linkAction = function() { - const offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startAccountLinkTransactionBuffer = function(builder) { - builder.startObject(12); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} remoteAccountKey - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addRemoteAccountKey = function(builder, remoteAccountKeyOffset) { - builder.addFieldOffset(7, remoteAccountKeyOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createRemoteAccountKeyVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startRemoteAccountKeyVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} linkAction - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addLinkAction = function(builder, linkAction) { - builder.addFieldInt8(8, linkAction, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.endAccountLinkTransactionBuffer = function(builder) { - const offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.finishAccountLinkTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AccountRestrictionsAddressTransactionBuffer.ts b/src/infrastructure/buffers/AccountRestrictionsAddressTransactionBuffer.ts deleted file mode 100644 index 7f71878ffc..0000000000 --- a/src/infrastructure/buffers/AccountRestrictionsAddressTransactionBuffer.ts +++ /dev/null @@ -1,557 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.RestrictionAddressModificationBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.RestrictionAddressModificationBuffer} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.RestrictionAddressModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionAddressModificationBuffer} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.getRootAsRestrictionAddressModificationBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.RestrictionAddressModificationBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.modificationType = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.value = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.valueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.valueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.startRestrictionAddressModificationBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.addModificationType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} valueOffset - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.addValue = function(builder, valueOffset) { - builder.addFieldOffset(1, valueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.createValueVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.startValueVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.endRestrictionAddressModificationBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer=} obj - * @returns {Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.getRootAsAccountRestrictionsAddressTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.restrictionType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.modificationCount = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.RestrictionAddressModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionAddressModificationBuffer} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.modifications = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? (obj || new Catapult.Buffers.RestrictionAddressModificationBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.modificationsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startAccountRestrictionsAddressTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} restrictionType - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addRestrictionType = function(builder, restrictionType) { - builder.addFieldInt8(7, restrictionType, 0); -}; - - -/** - * @param {flatbuffers.Builder} builder - * @param {number} modificationCount - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addModificationCount = function(builder, modificationCount) { - builder.addFieldInt8(8, modificationCount, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} modificationsOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addModifications = function(builder, modificationsOffset) { - builder.addFieldOffset(9, modificationsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createModificationsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startModificationsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.endAccountRestrictionsAddressTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.finishAccountRestrictionsAddressTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AccountRestrictionsEntityTypeTransactionBuffer.ts b/src/infrastructure/buffers/AccountRestrictionsEntityTypeTransactionBuffer.ts deleted file mode 100644 index b842f8d776..0000000000 --- a/src/infrastructure/buffers/AccountRestrictionsEntityTypeTransactionBuffer.ts +++ /dev/null @@ -1,520 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.RestrictionEntityTypeModificationBuffer} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.RestrictionEntityTypeModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionEntityTypeModificationBuffer} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.getRootAsRestrictionEntityTypeModificationBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.RestrictionEntityTypeModificationBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.prototype.modificationType = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.prototype.value = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.startRestrictionEntityTypeModificationBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.addModificationType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} valueOffset - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.addValue = function(builder, valueOffset) { - builder.addFieldInt16(1, valueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.endRestrictionEntityTypeModificationBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer=} obj - * @returns {Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.getRootAsAccountRestrictionsEntityTypeTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.restrictionType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.modificationCount = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.RestrictionEntityTypeModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionEntityTypeModificationBuffer} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.modifications = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? (obj || new Catapult.Buffers.RestrictionEntityTypeModificationBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.modificationsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startAccountRestrictionsEntityTypeTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} restrictionType - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addRestrictionType = function(builder, restrictionType) { - builder.addFieldInt8(7, restrictionType, 0); -}; - - -/** - * @param {flatbuffers.Builder} builder - * @param {number} modificationCount - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addModificationCount = function(builder, modificationCount) { - builder.addFieldInt8(8, modificationCount, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} modificationsOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addModifications = function(builder, modificationsOffset) { - builder.addFieldOffset(9, modificationsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createModificationsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startModificationsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.endAccountRestrictionsEntityTypeTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.finishAccountRestrictionsEntityTypeTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AccountRestrictionsMosaicTransactionBuffer.ts b/src/infrastructure/buffers/AccountRestrictionsMosaicTransactionBuffer.ts deleted file mode 100644 index 2fde91933f..0000000000 --- a/src/infrastructure/buffers/AccountRestrictionsMosaicTransactionBuffer.ts +++ /dev/null @@ -1,557 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.RestrictionMosaicModificationBuffer} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.RestrictionMosaicModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionMosaicModificationBuffer} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.getRootAsRestrictionMosaicModificationBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.RestrictionMosaicModificationBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.modificationType = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.value = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.valueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.valueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.startRestrictionMosaicModificationBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.addModificationType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} valueOffset - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.addValue = function(builder, valueOffset) { - builder.addFieldOffset(1, valueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.createValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.startValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.endRestrictionMosaicModificationBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer=} obj - * @returns {Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.getRootAsAccountRestrictionsMosaicTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.restrictionType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.modificationCount = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.RestrictionMosaicModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionMosaicModificationBuffer} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.modifications = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? (obj || new Catapult.Buffers.RestrictionMosaicModificationBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.modificationsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startAccountRestrictionsMosaicTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} restrictionType - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addRestrictionType = function(builder, restrictionType) { - builder.addFieldInt8(7, restrictionType, 0); -}; - - -/** - * @param {flatbuffers.Builder} builder - * @param {number} modificationCount - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addModificationCount = function(builder, modificationCount) { - builder.addFieldInt8(8, modificationCount, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} modificationsOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addModifications = function(builder, modificationsOffset) { - builder.addFieldOffset(9, modificationsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createModificationsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startModificationsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.endAccountRestrictionsMosaicTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.finishAccountRestrictionsMosaicTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AddressAliasTransactionBuffer.ts b/src/infrastructure/buffers/AddressAliasTransactionBuffer.ts deleted file mode 100644 index 00aa5f0a78..0000000000 --- a/src/infrastructure/buffers/AddressAliasTransactionBuffer.ts +++ /dev/null @@ -1,479 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.AddressAliasTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AddressAliasTransactionBuffer} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AddressAliasTransactionBuffer=} obj - * @returns {Catapult.Buffers.AddressAliasTransactionBuffer} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.getRootAsAddressAliasTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AddressAliasTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.aliasAction = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.namespaceId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.namespaceIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.namespaceIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.address = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.addressLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.addressArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startAddressAliasTransactionBuffer = function(builder) { - builder.startObject(10); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} aliasAction - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addAliasAction = function(builder, aliasAction) { - builder.addFieldInt8(7, aliasAction, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deltaOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addNamespaceId = function(builder, namespaceIdOffset) { - builder.addFieldOffset(8, namespaceIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createNamespaceIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startNamespaceIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addAddress = function(builder, addressOffset) { - builder.addFieldOffset(9, addressOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createAddressVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startAddressVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.endAddressAliasTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.finishAddressAliasTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AggregateTransactionBuffer.ts b/src/infrastructure/buffers/AggregateTransactionBuffer.ts deleted file mode 100644 index e2f9f68e83..0000000000 --- a/src/infrastructure/buffers/AggregateTransactionBuffer.ts +++ /dev/null @@ -1,425 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.AggregateTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AggregateTransactionBuffer} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AggregateTransactionBuffer=} obj - * @returns {Catapult.Buffers.AggregateTransactionBuffer} - */ -Catapult.Buffers.AggregateTransactionBuffer.getRootAsAggregateTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AggregateTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.transactionsSize = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.transactions = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.transactionsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.transactionsArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AggregateTransactionBuffer.startAggregateTransactionBuffer = function(builder) { - builder.startObject(9); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AggregateTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AggregateTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AggregateTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} transactionsSize - */ -Catapult.Buffers.AggregateTransactionBuffer.addTransactionsSize = function(builder, transactionsSize) { - builder.addFieldInt32(7, transactionsSize, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} transactionsOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addTransactions = function(builder, transactionsOffset) { - builder.addFieldOffset(8, transactionsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createTransactionsVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startTransactionsVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.endAggregateTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AggregateTransactionBuffer.finishAggregateTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/HashLockTransactionBuffer.ts b/src/infrastructure/buffers/HashLockTransactionBuffer.ts deleted file mode 100644 index ed4f0d4d8d..0000000000 --- a/src/infrastructure/buffers/HashLockTransactionBuffer.ts +++ /dev/null @@ -1,571 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.HashLockTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.HashLockTransactionBuffer} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.HashLockTransactionBuffer=} obj - * @returns {Catapult.Buffers.HashLockTransactionBuffer} - */ -Catapult.Buffers.HashLockTransactionBuffer.getRootAsHashLockTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.HashLockTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicAmount = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicAmountLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicAmountArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.duration = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.durationLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.durationArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.hash = function(index) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.hashLength = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.hashArray = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.HashLockTransactionBuffer.startHashLockTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.HashLockTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.HashLockTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.HashLockTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicAmountOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addMosaicAmount = function(builder, mosaicAmountOffset) { - builder.addFieldOffset(8, mosaicAmountOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createMosaicAmountVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startMosaicAmountVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} durationOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addDuration = function(builder, durationOffset) { - builder.addFieldOffset(9, durationOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createDurationVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startDurationVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} hashOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addHash = function(builder, hashOffset) { - builder.addFieldOffset(10, hashOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createHashVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startHashVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.endHashLockTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.HashLockTransactionBuffer.finishHashLockTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicAddressRestrictionTransactionBuffer.ts b/src/infrastructure/buffers/MosaicAddressRestrictionTransactionBuffer.ts deleted file mode 100644 index a306031841..0000000000 --- a/src/infrastructure/buffers/MosaicAddressRestrictionTransactionBuffer.ts +++ /dev/null @@ -1,625 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.getRootAsMosaicAddressRestrictionTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.restrictionKey = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.restrictionKeyLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.restrictionKeyArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.targetAddress = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.targetAddressLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.targetAddressArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.previousRestrictionValue = function(index) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.previousRestrictionValueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.previousRestrictionValueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.newRestrictionValue = function(index) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.newRestrictionValueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.newRestrictionValueValueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startMosaicAddressRestrictionTransactionBuffer = function(builder) { - builder.startObject(14); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} restrictionKeyOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addRestrictionKey = function(builder, restrictionKeyOffset) { - builder.addFieldOffset(8, restrictionKeyOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createRestrictionKeyVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startRestrictionKeyVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} targetAddressOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addTargetAddress = function(builder, targetAddressOffset) { - builder.addFieldOffset(9, targetAddressOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createTargetAddressVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startTargetAddressVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} previousRestrictionValueOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addPreviousRestrictionValue = function(builder, previousRestrictionValueOffset) { - builder.addFieldOffset(10, previousRestrictionValueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createPreviousRestrictionValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startPreviousRestrictionValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} newRestrictionValueOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addNewRestrictionValue = function(builder, newRestrictionValueOffset) { - builder.addFieldOffset(11, newRestrictionValueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createNewRestrictionValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startNewRestrictionValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.endMosaicAddressRestrictionTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.finishMosaicAddressRestrictionTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicAliasTransactionBuffer.ts b/src/infrastructure/buffers/MosaicAliasTransactionBuffer.ts deleted file mode 100644 index 3632f14354..0000000000 --- a/src/infrastructure/buffers/MosaicAliasTransactionBuffer.ts +++ /dev/null @@ -1,479 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicAliasTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicAliasTransactionBuffer} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicAliasTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicAliasTransactionBuffer} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.getRootAsMosaicAliasTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicAliasTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.aliasAction = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.namespaceId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.namespaceIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.namespaceIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startMosaicAliasTransactionBuffer = function(builder) { - builder.startObject(10); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} aliasAction - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addAliasAction = function(builder, aliasAction) { - builder.addFieldInt8(7, aliasAction, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deltaOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addNamespaceId = function(builder, namespaceIdOffset) { - builder.addFieldOffset(8, namespaceIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createNamespaceIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startNamespaceIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(9, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.endMosaicAliasTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.finishMosaicAliasTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicCreationTransactionBuffer.ts b/src/infrastructure/buffers/MosaicCreationTransactionBuffer.ts deleted file mode 100644 index eef8821885..0000000000 --- a/src/infrastructure/buffers/MosaicCreationTransactionBuffer.ts +++ /dev/null @@ -1,582 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicCreationTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicCreationTransactionBuffer} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicCreationTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicCreationTransactionBuffer} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.getRootAsMosaicCreationTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicCreationTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.nonce = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.nonceLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.nonceArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.numOptionalProperties = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.flags = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.divisibility = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.indicateDuration = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.duration = function(index) { - var offset = this.bb.__offset(this.bb_pos, 30); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.durationLength = function() { - var offset = this.bb.__offset(this.bb_pos, 30); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.durationArray = function() { - var offset = this.bb.__offset(this.bb_pos, 30); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startMosaicCreationTransactionBuffer = function(builder) { - builder.startObject(14); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} nonce - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addNonce = function(builder, nonceOffset) { - - builder.addFieldOffset(7, nonceOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createNonceVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startNonceVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(8, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numOptionalProperties - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addNumOptionalProperties = function(builder, numOptionalProperties) { - builder.addFieldInt8(9, numOptionalProperties, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} flags - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addFlags = function(builder, flags) { - builder.addFieldInt8(10, flags, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} divisibility - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addDivisibility = function(builder, divisibility) { - builder.addFieldInt8(11, divisibility, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} indicateDuration - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addIndicateDuration = function(builder, indicateDuration) { - builder.addFieldInt8(12, indicateDuration, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} durationOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addDuration = function(builder, durationOffset) { - builder.addFieldOffset(13, durationOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createDurationVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startDurationVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.endMosaicCreationTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.finishMosaicCreationTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicGlobalRestrictionTransactionBuffer.ts b/src/infrastructure/buffers/MosaicGlobalRestrictionTransactionBuffer.ts deleted file mode 100644 index 794dfd3add..0000000000 --- a/src/infrastructure/buffers/MosaicGlobalRestrictionTransactionBuffer.ts +++ /dev/null @@ -1,657 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.getRootAsMosaicGlobalRestrictionTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.referenceMosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.referenceMosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.referenceMosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.restrictionKey = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.restrictionKeyLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.restrictionKeyArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.previousRestrictionValue = function(index) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.previousRestrictionValueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.previousRestrictionValueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.previousRestrictionType = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.newRestrictionValue = function(index) { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.newRestrictionValueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.newRestrictionValueValueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.newRestrictionValue = function() { - var offset = this.bb.__offset(this.bb_pos, 30); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startMosaicGlobalRestrictionTransactionBuffer = function(builder) { - builder.startObject(14); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} referenceMosaicIdOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addReferenceMosaicId = function(builder, referenceMosaicIdOffset) { - builder.addFieldOffset(8, referenceMosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createReferenceMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startReferenceMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} restrictionKeyOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addRestrictionKey = function(builder, restrictionKeyOffset) { - builder.addFieldOffset(9, restrictionKeyOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createRestrictionKeyVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startRestrictionKeyVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} previousRestrictionValueOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addPreviousRestrictionValue = function(builder, previousRestrictionValueOffset) { - builder.addFieldOffset(10, previousRestrictionValueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createPreviousRestrictionValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startPreviousRestrictionValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} previousRestrictionType - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addPreviousRestrictionType = function(builder, previousRestrictionType) { - builder.addFieldInt16(11, previousRestrictionType, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} newRestrictionValueOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addNewRestrictionValue = function(builder, newRestrictionValueOffset) { - builder.addFieldOffset(12, newRestrictionValueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createNewRestrictionValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startNewRestrictionValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} newRestrictionType - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addNewRestrictionType = function(builder, newRestrictionType) { - builder.addFieldInt16(13, newRestrictionType, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.endMosaicGlobalRestrictionTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.finishMosaicGlobalRestrictionTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicSupplyChangeTransactionBuffer.ts b/src/infrastructure/buffers/MosaicSupplyChangeTransactionBuffer.ts deleted file mode 100644 index 0297f46688..0000000000 --- a/src/infrastructure/buffers/MosaicSupplyChangeTransactionBuffer.ts +++ /dev/null @@ -1,479 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicSupplyChangeTransactionBuffer} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicSupplyChangeTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicSupplyChangeTransactionBuffer} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.getRootAsMosaicSupplyChangeTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicSupplyChangeTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.direction = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.delta = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deltaLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deltaArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startMosaicSupplyChangeTransactionBuffer = function(builder) { - builder.startObject(10); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} direction - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addDirection = function(builder, direction) { - builder.addFieldInt8(8, direction, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deltaOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addDelta = function(builder, deltaOffset) { - builder.addFieldOffset(9, deltaOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createDeltaVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startDeltaVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.endMosaicSupplyChangeTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.finishMosaicSupplyChangeTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MultisigModificationTransactionBuffer.ts b/src/infrastructure/buffers/MultisigModificationTransactionBuffer.ts deleted file mode 100644 index 14376de447..0000000000 --- a/src/infrastructure/buffers/MultisigModificationTransactionBuffer.ts +++ /dev/null @@ -1,571 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.CosignatoryModificationBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.CosignatoryModificationBuffer} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.CosignatoryModificationBuffer=} obj - * @returns {Catapult.Buffers.CosignatoryModificationBuffer} - */ -Catapult.Buffers.CosignatoryModificationBuffer.getRootAsCosignatoryModificationBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.CosignatoryModificationBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.cosignatoryPublicKey = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.cosignatoryPublicKeyLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.cosignatoryPublicKeyArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.CosignatoryModificationBuffer.startCosignatoryModificationBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.CosignatoryModificationBuffer.addType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} cosignatoryPublicKeyOffset - */ -Catapult.Buffers.CosignatoryModificationBuffer.addCosignatoryPublicKey = function(builder, cosignatoryPublicKeyOffset) { - builder.addFieldOffset(1, cosignatoryPublicKeyOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.CosignatoryModificationBuffer.createCosignatoryPublicKeyVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.CosignatoryModificationBuffer.startCosignatoryPublicKeyVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.CosignatoryModificationBuffer.endCosignatoryModificationBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.MultisigModificationTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MultisigModificationTransactionBuffer} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MultisigModificationTransactionBuffer=} obj - * @returns {Catapult.Buffers.MultisigModificationTransactionBuffer} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.getRootAsMultisigModificationTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MultisigModificationTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.minRemovalDelta = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.minApprovalDelta = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.numModifications = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.CosignatoryModificationBuffer=} obj - * @returns {Catapult.Buffers.CosignatoryModificationBuffer} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.modifications = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? (obj || new Catapult.Buffers.CosignatoryModificationBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.modificationsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startMultisigModificationTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} minRemovalDelta - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addMinRemovalDelta = function(builder, minRemovalDelta) { - builder.addFieldInt8(7, minRemovalDelta, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} minApprovalDelta - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addMinApprovalDelta = function(builder, minApprovalDelta) { - builder.addFieldInt8(8, minApprovalDelta, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numModifications - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addNumModifications = function(builder, numModifications) { - builder.addFieldInt8(9, numModifications, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} modificationsOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addModifications = function(builder, modificationsOffset) { - builder.addFieldOffset(10, modificationsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createModificationsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startModificationsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.endMultisigModificationTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.finishMultisigModificationTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/NamespaceCreationTransactionBuffer.ts b/src/infrastructure/buffers/NamespaceCreationTransactionBuffer.ts deleted file mode 100644 index 47e9657a44..0000000000 --- a/src/infrastructure/buffers/NamespaceCreationTransactionBuffer.ts +++ /dev/null @@ -1,512 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.NamespaceCreationTransactionBuffer} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.NamespaceCreationTransactionBuffer=} obj - * @returns {Catapult.Buffers.NamespaceCreationTransactionBuffer} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.getRootAsNamespaceCreationTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.NamespaceCreationTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.durationParentId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.durationParentIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.durationParentIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceNameSize = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Encoding=} optionalEncoding - * @returns {string|Uint8Array|null} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceName = function(optionalEncoding) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startNamespaceCreationTransactionBuffer = function(builder) { - builder.startObject(12); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} namespaceType - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addNamespaceType = function(builder, namespaceType) { - builder.addFieldInt8(7, namespaceType, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} durationParentIdOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addDurationParentId = function(builder, durationParentIdOffset) { - builder.addFieldOffset(8, durationParentIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createDurationParentIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startDurationParentIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} namespaceIdOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addNamespaceId = function(builder, namespaceIdOffset) { - builder.addFieldOffset(9, namespaceIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createNamespaceIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startNamespaceIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} namespaceNameSize - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addNamespaceNameSize = function(builder, namespaceNameSize) { - builder.addFieldInt8(10, namespaceNameSize, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} namespaceNameOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addNamespaceName = function(builder, namespaceNameOffset) { - builder.addFieldOffset(11, namespaceNameOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.endNamespaceCreationTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.finishNamespaceCreationTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/SecretLockTransactionBuffer.ts b/src/infrastructure/buffers/SecretLockTransactionBuffer.ts deleted file mode 100644 index 4036cdd4c2..0000000000 --- a/src/infrastructure/buffers/SecretLockTransactionBuffer.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.SecretLockTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.SecretLockTransactionBuffer} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.SecretLockTransactionBuffer=} obj - * @returns {Catapult.Buffers.SecretLockTransactionBuffer} - */ -Catapult.Buffers.SecretLockTransactionBuffer.getRootAsSecretLockTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.SecretLockTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicAmount = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicAmountLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicAmountArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.duration = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.durationLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.durationArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.hashAlgorithm = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.secret = function(index) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.secretLength = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.secretArray = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.recipient = function(index) { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.recipientLength = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.recipientArray = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.SecretLockTransactionBuffer.startSecretLockTransactionBuffer = function(builder) { - builder.startObject(13); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.SecretLockTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.SecretLockTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.SecretLockTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicAmountOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addMosaicAmount = function(builder, mosaicAmountOffset) { - builder.addFieldOffset(8, mosaicAmountOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createMosaicAmountVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startMosaicAmountVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} durationOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addDuration = function(builder, durationOffset) { - builder.addFieldOffset(9, durationOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createDurationVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startDurationVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} hashAlgorithm - */ -Catapult.Buffers.SecretLockTransactionBuffer.addHashAlgorithm = function(builder, hashAlgorithm) { - builder.addFieldInt8(10, hashAlgorithm, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} secretOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addSecret = function(builder, secretOffset) { - builder.addFieldOffset(11, secretOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createSecretVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startSecretVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} recipientOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addRecipient = function(builder, recipientOffset) { - builder.addFieldOffset(12, recipientOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createRecipientVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startRecipientVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.endSecretLockTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.SecretLockTransactionBuffer.finishSecretLockTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/SecretProofTransactionBuffer.ts b/src/infrastructure/buffers/SecretProofTransactionBuffer.ts deleted file mode 100644 index 570f57a886..0000000000 --- a/src/infrastructure/buffers/SecretProofTransactionBuffer.ts +++ /dev/null @@ -1,549 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.SecretProofTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.SecretProofTransactionBuffer} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.SecretProofTransactionBuffer=} obj - * @returns {Catapult.Buffers.SecretProofTransactionBuffer} - */ -Catapult.Buffers.SecretProofTransactionBuffer.getRootAsSecretProofTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.SecretProofTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.hashAlgorithm = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.secret = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.secretLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.secretArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.recipient = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.recipientLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.recipientArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.proofSize = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.proof = function(index) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.proofLength = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.proofArray = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.SecretProofTransactionBuffer.startSecretProofTransactionBuffer = function(builder) { - builder.startObject(12); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.SecretProofTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.SecretProofTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.SecretProofTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} hashAlgorithm - */ -Catapult.Buffers.SecretProofTransactionBuffer.addHashAlgorithm = function(builder, hashAlgorithm) { - builder.addFieldInt8(7, hashAlgorithm, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} secretOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addSecret = function(builder, secretOffset) { - builder.addFieldOffset(8, secretOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createSecretVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startSecretVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} recipientOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addRecipient = function(builder, recipientOffset) { - builder.addFieldOffset(9, recipientOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createRecipientVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startRecipientVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} proofSize - */ -Catapult.Buffers.SecretProofTransactionBuffer.addProofSize = function(builder, proofSize) { - builder.addFieldInt16(10, proofSize, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} proofOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addProof = function(builder, proofOffset) { - builder.addFieldOffset(11, proofOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createProofVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startProofVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.endSecretProofTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.SecretProofTransactionBuffer.finishSecretProofTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/TransferTransactionBuffer.ts b/src/infrastructure/buffers/TransferTransactionBuffer.ts deleted file mode 100644 index 05be19edfb..0000000000 --- a/src/infrastructure/buffers/TransferTransactionBuffer.ts +++ /dev/null @@ -1,785 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MessageBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MessageBuffer} - */ -Catapult.Buffers.MessageBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MessageBuffer=} obj - * @returns {Catapult.Buffers.MessageBuffer} - */ -Catapult.Buffers.MessageBuffer.getRootAsMessageBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MessageBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MessageBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MessageBuffer.prototype.payload = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MessageBuffer.prototype.payloadLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MessageBuffer.prototype.payloadArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MessageBuffer.startMessageBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MessageBuffer.addType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} payloadOffset - */ -Catapult.Buffers.MessageBuffer.addPayload = function(builder, payloadOffset) { - builder.addFieldOffset(1, payloadOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MessageBuffer.createPayloadVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MessageBuffer.startPayloadVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MessageBuffer.endMessageBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicBuffer} - */ -Catapult.Buffers.MosaicBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicBuffer=} obj - * @returns {Catapult.Buffers.MosaicBuffer} - */ -Catapult.Buffers.MosaicBuffer.getRootAsMosaicBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicBuffer.prototype.id = function(index) { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicBuffer.prototype.idLength = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicBuffer.prototype.idArray = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicBuffer.prototype.amount = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicBuffer.prototype.amountLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicBuffer.prototype.amountArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicBuffer.startMosaicBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} idOffset - */ -Catapult.Buffers.MosaicBuffer.addId = function(builder, idOffset) { - builder.addFieldOffset(0, idOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicBuffer.createIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicBuffer.startIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} amountOffset - */ -Catapult.Buffers.MosaicBuffer.addAmount = function(builder, amountOffset) { - builder.addFieldOffset(1, amountOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicBuffer.createAmountVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicBuffer.startAmountVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicBuffer.endMosaicBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.TransferTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.TransferTransactionBuffer} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.TransferTransactionBuffer=} obj - * @returns {Catapult.Buffers.TransferTransactionBuffer} - */ -Catapult.Buffers.TransferTransactionBuffer.getRootAsTransferTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.TransferTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.recipient = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.recipientLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.recipientArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.messageSize = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.numMosaics = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {Catapult.Buffers.MessageBuffer=} obj - * @returns {Catapult.Buffers.MessageBuffer|null} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.message = function(obj) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? (obj || new Catapult.Buffers.MessageBuffer).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.MosaicBuffer=} obj - * @returns {Catapult.Buffers.MosaicBuffer} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.mosaics = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? (obj || new Catapult.Buffers.MosaicBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.mosaicsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.TransferTransactionBuffer.startTransferTransactionBuffer = function(builder) { - builder.startObject(12); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.TransferTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.TransferTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.TransferTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} recipientOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addRecipient = function(builder, recipientOffset) { - builder.addFieldOffset(7, recipientOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createRecipientVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startRecipientVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} messageSize - */ -Catapult.Buffers.TransferTransactionBuffer.addMessageSize = function(builder, messageSize) { - builder.addFieldInt16(8, messageSize, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numMosaics - */ -Catapult.Buffers.TransferTransactionBuffer.addNumMosaics = function(builder, numMosaics) { - builder.addFieldInt8(9, numMosaics, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} messageOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addMessage = function(builder, messageOffset) { - builder.addFieldOffset(10, messageOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicsOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addMosaics = function(builder, mosaicsOffset) { - builder.addFieldOffset(11, mosaicsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createMosaicsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startMosaicsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.endTransferTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.TransferTransactionBuffer.finishTransferTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/builders/AccountLinkTransaction.ts b/src/infrastructure/builders/AccountLinkTransaction.ts deleted file mode 100644 index 15cdb7738c..0000000000 --- a/src/infrastructure/builders/AccountLinkTransaction.ts +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AccountLinkTransaction - */ -import { Convert as convert } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import AccountLinkTransactionBufferPackage from '../buffers/AccountLinkTransactionBuffer'; -import AccountLinkTransactionSchema from '../schemas/AccountLinkTransactionSchema'; -import {VerifiableTransaction} from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - AccountLinkTransactionBuffer, -} = AccountLinkTransactionBufferPackage.Buffers; - -export class AccountLinkTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AccountLinkTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - remoteAccountKey: any; - linkAction: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.LINK_ACCOUNT; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRemoteAccountKey(remoteAccountKey) { - this.remoteAccountKey = convert.hexToUint8(remoteAccountKey); - return this; - } - - addLinkAction(linkAction) { - this.linkAction = linkAction; - return this; - } - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = AccountLinkTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = AccountLinkTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = AccountLinkTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = AccountLinkTransactionBuffer.createFeeVector(builder, this.maxFee); - const remoteAccountKeyVector = AccountLinkTransactionBuffer.createRemoteAccountKeyVector(builder, this.remoteAccountKey); - - AccountLinkTransactionBuffer.startAccountLinkTransactionBuffer(builder); - AccountLinkTransactionBuffer.addSize(builder, 153); - AccountLinkTransactionBuffer.addSignature(builder, signatureVector); - AccountLinkTransactionBuffer.addSigner(builder, signerVector); - AccountLinkTransactionBuffer.addVersion(builder, this.version); - AccountLinkTransactionBuffer.addType(builder, this.type); - AccountLinkTransactionBuffer.addFee(builder, feeVector); - AccountLinkTransactionBuffer.addDeadline(builder, deadlineVector); - AccountLinkTransactionBuffer.addRemoteAccountKey(builder, remoteAccountKeyVector); - AccountLinkTransactionBuffer.addLinkAction(builder, this.linkAction); - - // Calculate size - - const codedTransfer = AccountLinkTransactionBuffer.endAccountLinkTransactionBuffer(builder); - builder.finish(codedTransfer); - - const bytes = builder.asUint8Array(); - return new AccountLinkTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts b/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts deleted file mode 100644 index bd355c6b94..0000000000 --- a/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AccountRestrictionsAddressTransaction - */ -import { RawAddress as address } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import AccountRestrictionsAddressTransactionBufferPackage from '../buffers/AccountRestrictionsAddressTransactionBuffer'; -import AccountRestrictionsAddressModificationTransactionSchema from '../schemas/AccountRestrictionsAddressModificationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; -const { - AccountRestrictionsAddressTransactionBuffer, - RestrictionAddressModificationBuffer, -} = AccountRestrictionsAddressTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -export default class AccountRestrictionsAddressTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AccountRestrictionsAddressModificationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - restrictionType: any; - modifications: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.ACCOUNT_RESTRICTION_ADDRESS; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionType(restrictionType) { - this.restrictionType = restrictionType; - return this; - } - - addModifications(modifications) { - this.modifications = modifications; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create modifications - const modificationsArray: any = []; - this.modifications.forEach((modification) => { - const addressModificationVector = RestrictionAddressModificationBuffer - .createValueVector(builder, address.stringToAddress(modification.value)); - RestrictionAddressModificationBuffer.startRestrictionAddressModificationBuffer(builder); - RestrictionAddressModificationBuffer.addModificationType(builder, modification.type); - RestrictionAddressModificationBuffer.addValue(builder, addressModificationVector); - modificationsArray.push(RestrictionAddressModificationBuffer.endRestrictionAddressModificationBuffer(builder)); - }); - - // Create vectors - const signatureVector = AccountRestrictionsAddressTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = AccountRestrictionsAddressTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = AccountRestrictionsAddressTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = AccountRestrictionsAddressTransactionBuffer - .createFeeVector(builder, this.maxFee); - const modificationVector = AccountRestrictionsAddressTransactionBuffer - .createModificationsVector(builder, modificationsArray); - - AccountRestrictionsAddressTransactionBuffer.startAccountRestrictionsAddressTransactionBuffer(builder); - AccountRestrictionsAddressTransactionBuffer.addSize(builder, 122 + (26 * this.modifications.length)); - AccountRestrictionsAddressTransactionBuffer.addSignature(builder, signatureVector); - AccountRestrictionsAddressTransactionBuffer.addSigner(builder, signerVector); - AccountRestrictionsAddressTransactionBuffer.addVersion(builder, this.version); - AccountRestrictionsAddressTransactionBuffer.addType(builder, this.type); - AccountRestrictionsAddressTransactionBuffer.addFee(builder, feeVector); - AccountRestrictionsAddressTransactionBuffer.addDeadline(builder, deadlineVector); - AccountRestrictionsAddressTransactionBuffer.addRestrictionType(builder, this.restrictionType); - AccountRestrictionsAddressTransactionBuffer.addModificationCount(builder, this.modifications.length); - AccountRestrictionsAddressTransactionBuffer.addModifications(builder, modificationVector); - - // Calculate size - const codedAccountRestrictionsAddress = - AccountRestrictionsAddressTransactionBuffer.endAccountRestrictionsAddressTransactionBuffer(builder); - builder.finish(codedAccountRestrictionsAddress); - - const bytes = builder.asUint8Array(); - - return new AccountRestrictionsAddressTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts b/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts deleted file mode 100644 index 6973e8ccc4..0000000000 --- a/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AccountRestrictionsEntityTypeTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import AccountRestrictionsEntityTypeTransactionBufferPackage from '../buffers/AccountRestrictionsEntityTypeTransactionBuffer'; -import AccountRestrictionsEntityTypeModificationTransactionSchema from '../schemas/AccountRestrictionsEntityTypeModificationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - AccountRestrictionsEntityTypeTransactionBuffer, - RestrictionEntityTypeModificationBuffer, -} = AccountRestrictionsEntityTypeTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -export default class AccountRestrictionsEntityTypeTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AccountRestrictionsEntityTypeModificationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - restrictionType: any; - modifications: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.ACCOUNT_RESTRICTION_OPERATION; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionType(restrictionType) { - this.restrictionType = restrictionType; - return this; - } - - addModifications(modifications) { - this.modifications = modifications; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create modifications - const modificationsArray: any = []; - this.modifications.forEach((modification) => { - RestrictionEntityTypeModificationBuffer.startRestrictionEntityTypeModificationBuffer(builder); - RestrictionEntityTypeModificationBuffer.addModificationType(builder, modification.type); - RestrictionEntityTypeModificationBuffer.addValue(builder, modification.value); - modificationsArray.push(RestrictionEntityTypeModificationBuffer.endRestrictionEntityTypeModificationBuffer(builder)); - }); - - // Create vectors - const signatureVector = AccountRestrictionsEntityTypeTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = AccountRestrictionsEntityTypeTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = AccountRestrictionsEntityTypeTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = AccountRestrictionsEntityTypeTransactionBuffer - .createFeeVector(builder, this.maxFee); - const modificationVector = AccountRestrictionsEntityTypeTransactionBuffer - .createModificationsVector(builder, modificationsArray); - - AccountRestrictionsEntityTypeTransactionBuffer.startAccountRestrictionsEntityTypeTransactionBuffer(builder); - AccountRestrictionsEntityTypeTransactionBuffer.addSize(builder, 122 + (3 * this.modifications.length)); - AccountRestrictionsEntityTypeTransactionBuffer.addSignature(builder, signatureVector); - AccountRestrictionsEntityTypeTransactionBuffer.addSigner(builder, signerVector); - AccountRestrictionsEntityTypeTransactionBuffer.addVersion(builder, this.version); - AccountRestrictionsEntityTypeTransactionBuffer.addType(builder, this.type); - AccountRestrictionsEntityTypeTransactionBuffer.addFee(builder, feeVector); - AccountRestrictionsEntityTypeTransactionBuffer.addDeadline(builder, deadlineVector); - AccountRestrictionsEntityTypeTransactionBuffer.addRestrictionType(builder, this.restrictionType); - AccountRestrictionsEntityTypeTransactionBuffer.addModificationCount(builder, this.modifications.length); - AccountRestrictionsEntityTypeTransactionBuffer.addModifications(builder, modificationVector); - - // Calculate size - const codedAccountRestrictionsAddress = AccountRestrictionsEntityTypeTransactionBuffer - .endAccountRestrictionsEntityTypeTransactionBuffer(builder); - builder.finish(codedAccountRestrictionsAddress); - - const bytes = builder.asUint8Array(); - - return new AccountRestrictionsEntityTypeTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts b/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts deleted file mode 100644 index da9338deb4..0000000000 --- a/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AccountRestrictionsMosaicTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import AccountRestrictionsMosaicTransactionBufferPackage from '../buffers/AccountRestrictionsMosaicTransactionBuffer'; -import AccountRestrictionsMosaicModificationTransactionSchema from '../schemas/AccountRestrictionsMosaicModificationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - AccountRestrictionsMosaicTransactionBuffer, - RestrictionMosaicModificationBuffer, -} = AccountRestrictionsMosaicTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -export default class AccountRestrictionsMosaicTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AccountRestrictionsMosaicModificationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - restrictionType: any; - modifications: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.ACCOUNT_RESTRICTION_MOSAIC; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionType(restrictionType) { - this.restrictionType = restrictionType; - return this; - } - - addModifications(modifications) { - this.modifications = modifications; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create modifications - const modificationsArray: any = []; - this.modifications.forEach((modification) => { - const addressModificationVector = RestrictionMosaicModificationBuffer - .createValueVector(builder, modification.value); - RestrictionMosaicModificationBuffer.startRestrictionMosaicModificationBuffer(builder); - RestrictionMosaicModificationBuffer.addModificationType(builder, modification.type); - RestrictionMosaicModificationBuffer.addValue(builder, addressModificationVector); - modificationsArray.push(RestrictionMosaicModificationBuffer.endRestrictionMosaicModificationBuffer(builder)); - }); - - // Create vectors - const signatureVector = AccountRestrictionsMosaicTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = AccountRestrictionsMosaicTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = AccountRestrictionsMosaicTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = AccountRestrictionsMosaicTransactionBuffer - .createFeeVector(builder, this.maxFee); - const modificationVector = AccountRestrictionsMosaicTransactionBuffer - .createModificationsVector(builder, modificationsArray); - - AccountRestrictionsMosaicTransactionBuffer.startAccountRestrictionsMosaicTransactionBuffer(builder); - AccountRestrictionsMosaicTransactionBuffer.addSize(builder, 122 + (9 * this.modifications.length)); - AccountRestrictionsMosaicTransactionBuffer.addSignature(builder, signatureVector); - AccountRestrictionsMosaicTransactionBuffer.addSigner(builder, signerVector); - AccountRestrictionsMosaicTransactionBuffer.addVersion(builder, this.version); - AccountRestrictionsMosaicTransactionBuffer.addType(builder, this.type); - AccountRestrictionsMosaicTransactionBuffer.addFee(builder, feeVector); - AccountRestrictionsMosaicTransactionBuffer.addDeadline(builder, deadlineVector); - AccountRestrictionsMosaicTransactionBuffer.addRestrictionType(builder, this.restrictionType); - AccountRestrictionsMosaicTransactionBuffer.addModificationCount(builder, this.modifications.length); - AccountRestrictionsMosaicTransactionBuffer.addModifications(builder, modificationVector); - - // Calculate size - const codedAccountRestrictionsMosaic = AccountRestrictionsMosaicTransactionBuffer.endAccountRestrictionsMosaicTransactionBuffer(builder); - builder.finish(codedAccountRestrictionsMosaic); - - const bytes = builder.asUint8Array(); - - return new AccountRestrictionsMosaicTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/AddressAliasTransaction.ts b/src/infrastructure/builders/AddressAliasTransaction.ts deleted file mode 100644 index bbbda06fb9..0000000000 --- a/src/infrastructure/builders/AddressAliasTransaction.ts +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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 { RawAddress as addressLibrary } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import AddressAliasTransactionBufferPackage from '../buffers/AddressAliasTransactionBuffer'; -import AddressAliasTransactionSchema from '../schemas/AddressAliasTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - AddressAliasTransactionBuffer, -} = AddressAliasTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -/** - * @module transactions/AddressAliasTransaction - */ -export class AddressAliasTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AddressAliasTransactionSchema); - } -} -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - address: any; - namespaceId: any; - aliasAction: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.ADDRESS_ALIAS; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addAliasAction(aliasAction) { - this.aliasAction = aliasAction; - return this; - } - - addNamespaceId(namespaceId) { - this.namespaceId = namespaceId; - return this; - } - - addAddress(address) { - this.address = addressLibrary.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.maxFee); - 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.addAliasAction(builder, this.aliasAction); - 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); - } -} diff --git a/src/infrastructure/builders/AggregateTransaction.ts b/src/infrastructure/builders/AggregateTransaction.ts deleted file mode 100644 index 8aae5a5e28..0000000000 --- a/src/infrastructure/builders/AggregateTransaction.ts +++ /dev/null @@ -1,151 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AggregateTransaction - */ -import { SignSchema } from '../../core/crypto'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import AggregateTransactionBufferPackage from '../buffers/AggregateTransactionBuffer'; -import AggregateTransactionSchema from '../schemas/AggregateTransactionSchema'; -import { CosignatureTransaction} from './CosignatureTransaction'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - AggregateTransactionBuffer, -} = AggregateTransactionBufferPackage.Buffers; - -export class AggregateTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AggregateTransactionSchema); - } - - signTransactionWithCosigners(initializer, cosigners, generationHash, signSchema: SignSchema = SignSchema.SHA3) { - const signedTransaction = this.signTransaction(initializer, generationHash, signSchema); - cosigners.forEach((cosigner) => { - const signatureTransaction = new CosignatureTransaction(signedTransaction.hash); - const signatureCosignTransaction = signatureTransaction.signCosignatoriesTransaction(cosigner, signSchema); - signedTransaction.payload = signedTransaction.payload + - signatureCosignTransaction.signer + signatureCosignTransaction.signature; - }); - - // Calculate new size - const size = `00000000${(signedTransaction.payload.length / 2).toString(16)}`; - const formatedSize = size.substr(size.length - 8, size.length); - const littleEndianSize = formatedSize.substr(6, 2) + formatedSize.substr(4, 2) + - formatedSize.substr(2, 2) + formatedSize.substr(0, 2); - - signedTransaction.payload = littleEndianSize + - signedTransaction.payload.substr(8, signedTransaction.payload.length - 8); - - return signedTransaction; - } - - signTransactionGivenSignatures(initializer, cosignedSignedTransactions, generationHash, signSchema = SignSchema.SHA3) { - const signedTransaction = this.signTransaction(initializer, generationHash, signSchema); - cosignedSignedTransactions.forEach((cosignedTransaction) => { - signedTransaction.payload = signedTransaction.payload + cosignedTransaction.signer + cosignedTransaction.signature; - }); - - // Calculate new size - const size = `00000000${(signedTransaction.payload.length / 2).toString(16)}`; - const formatedSize = size.substr(size.length - 8, size.length); - const littleEndianSize = formatedSize.substr(6, 2) + formatedSize.substr(4, 2) + - formatedSize.substr(2, 2) + formatedSize.substr(0, 2); - - signedTransaction.payload = littleEndianSize + - signedTransaction.payload.substr(8, signedTransaction.payload.length - 8); - - return signedTransaction; - } -} -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - transactions: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.AGGREGATE_COMPLETE; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addTransactions(transactions) { - let tmp = []; - for (let i = 0; i < transactions.length; ++i) { - tmp = tmp.concat(transactions[i]); - } - - this.transactions = tmp; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = AggregateTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)) - .map(Number.prototype.valueOf, 0)); - const signerVector = AggregateTransactionBuffer - .createSignerVector(builder, Array(...Array(32)) - .map(Number.prototype.valueOf, 0)); - const deadlineVector = AggregateTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = AggregateTransactionBuffer.createFeeVector(builder, this.maxFee); - const modificationsVector = AggregateTransactionBuffer.createTransactionsVector(builder, this.transactions); - - AggregateTransactionBuffer.startAggregateTransactionBuffer(builder); - AggregateTransactionBuffer.addSize(builder, 120 + 4 + this.transactions.length); - AggregateTransactionBuffer.addSignature(builder, signatureVector); - AggregateTransactionBuffer.addSigner(builder, signerVector); - AggregateTransactionBuffer.addVersion(builder, this.version); - AggregateTransactionBuffer.addType(builder, this.type); - AggregateTransactionBuffer.addFee(builder, feeVector); - AggregateTransactionBuffer.addDeadline(builder, deadlineVector); - AggregateTransactionBuffer.addTransactionsSize(builder, 0 !== this.transactions.length ? this.transactions.length : 4294967296); - AggregateTransactionBuffer.addTransactions(builder, modificationsVector); - - // Calculate size - const codedAggregate = AggregateTransactionBuffer.endAggregateTransactionBuffer(builder); - builder.finish(codedAggregate); - - const bytes = builder.asUint8Array(); - return new AggregateTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/CosignatureTransaction.ts b/src/infrastructure/builders/CosignatureTransaction.ts deleted file mode 100644 index 717041f910..0000000000 --- a/src/infrastructure/builders/CosignatureTransaction.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 { Convert as convert } from '../../core/format/Convert'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -/** - * @module transactions/AggregateSignatureTransaction - * @version 1.0.0 - */ -export class CosignatureTransaction extends VerifiableTransaction { - constructor(hash) { - super(convert.hexToUint8(hash), undefined); - } -} diff --git a/src/infrastructure/builders/Deadline.ts b/src/infrastructure/builders/Deadline.ts deleted file mode 100644 index 3b37923c5a..0000000000 --- a/src/infrastructure/builders/Deadline.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 { RawUInt64 as uint64 } from '../../core/format'; - -export default function deadline(deadlineParam) { - const NetworkTime = (new Date()).getTime() - 1459468800000; - const deadlineValue = deadlineParam || 60 * 60 * 1000; - return uint64.fromUint(deadlineValue + NetworkTime); -} \ No newline at end of file diff --git a/src/infrastructure/builders/HashLockTransaction.ts b/src/infrastructure/builders/HashLockTransaction.ts deleted file mode 100644 index 538454d3ea..0000000000 --- a/src/infrastructure/builders/HashLockTransaction.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/HashLockTransaction - */ -import { Convert as convert } from '../../core/format'; -import * as HashLockTransactionBufferPackage from '../buffers/HashLockTransactionBuffer'; -import HashLockTransactionSchema from '../schemas/HashLockTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; -import { TransactionType } from '../../model/transaction/TransactionType'; - -import {flatbuffers} from 'flatbuffers'; - -const { - HashLockTransactionBuffer, -} = HashLockTransactionBufferPackage.default.Buffers; - -export default class HashLockTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, HashLockTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - mosaicAmount: any; - duration: any; - hash: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.LOCK; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - addMosaicAmount(mosaicAmount) { - this.mosaicAmount = mosaicAmount; - return this; - } - - addDuration(duration) { - this.duration = duration; - return this; - } - - addHash(hash) { - this.hash = hash; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = HashLockTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = HashLockTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = HashLockTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = HashLockTransactionBuffer.createFeeVector(builder, this.maxFee); - const mosaicIdVector = HashLockTransactionBuffer.createMosaicIdVector(builder, this.mosaicId); - const mosaicAmountVector = HashLockTransactionBuffer.createMosaicAmountVector(builder, this.mosaicAmount); - const durationVector = HashLockTransactionBuffer.createDurationVector(builder, this.duration); - const byteHash = convert.hexToUint8(this.hash); - const hashVector = HashLockTransactionBuffer.createHashVector(builder, byteHash); - - HashLockTransactionBuffer.startHashLockTransactionBuffer(builder); - HashLockTransactionBuffer.addSize(builder, 176); - HashLockTransactionBuffer.addSignature(builder, signatureVector); - HashLockTransactionBuffer.addSigner(builder, signerVector); - HashLockTransactionBuffer.addVersion(builder, this.version); - HashLockTransactionBuffer.addType(builder, this.type); - HashLockTransactionBuffer.addFee(builder, feeVector); - HashLockTransactionBuffer.addDeadline(builder, deadlineVector); - HashLockTransactionBuffer.addMosaicId(builder, mosaicIdVector); - HashLockTransactionBuffer.addMosaicAmount(builder, mosaicAmountVector); - HashLockTransactionBuffer.addDuration(builder, durationVector); - HashLockTransactionBuffer.addHash(builder, hashVector); - - const codedHashLock = HashLockTransactionBuffer.endHashLockTransactionBuffer(builder); - builder.finish(codedHashLock); - - const bytes = builder.asUint8Array(); - return new HashLockTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/MosaicAddressRestrictionTransaction.ts b/src/infrastructure/builders/MosaicAddressRestrictionTransaction.ts deleted file mode 100644 index 0b214c496b..0000000000 --- a/src/infrastructure/builders/MosaicAddressRestrictionTransaction.ts +++ /dev/null @@ -1,146 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/MosaicAddressRestrictionTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicAddressRestrictionTransactionBufferPackage from '../buffers/MosaicAddressRestrictionTransactionBuffer'; -import MosaicAddressRestrictionTransactionSchema from '../schemas/MosaicAddressRestrictionTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; -import { RawAddress } from '../../core/format'; - -const { - MosaicAddressRestrictionTransactionBuffer, -} = MosaicAddressRestrictionTransactionBufferPackage.Buffers; - -export default class MosaicAddressRestrictionTransaction extends VerifiableTransaction { - constructor(bytes, schema) { - super(bytes, schema); - } -} -// tslint:disable-next-line: max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - restrictionKey: any; - targetAddress: any; - previousRestrictionValue: any; - newRestrictionValue: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_ADDRESS_RESTRICTION; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionKey(restrictionKey) { - this.restrictionKey = restrictionKey; - return this; - } - - addTargetAddress(targetAddress) { - this.targetAddress = RawAddress.stringToAddress(targetAddress); - return this; - } - - addPreviousRestrictionValue(previousRestrictionValue) { - this.previousRestrictionValue = previousRestrictionValue; - return this; - } - - addNewRestrictionValue(newRestrictionValue) { - this.newRestrictionValue = newRestrictionValue; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicAddressRestrictionTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicAddressRestrictionTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicAddressRestrictionTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicAddressRestrictionTransactionBuffer - .createFeeVector(builder, this.maxFee); - const mosaicIdVector = MosaicAddressRestrictionTransactionBuffer - .createMosaicIdVector(builder, this.mosaicId); - const restrictionKeyVector = MosaicAddressRestrictionTransactionBuffer - .createRestrictionKeyVector(builder, this.restrictionKey); - const targetAddressVector = MosaicAddressRestrictionTransactionBuffer - .createTargetAddressVector(builder, this.targetAddress); - const previousRestrictionValueVector = MosaicAddressRestrictionTransactionBuffer - .createPreviousRestrictionValueVector(builder, this.previousRestrictionValue); - const newRestrictionValueVector = MosaicAddressRestrictionTransactionBuffer - .createNewRestrictionValueVector(builder, this.newRestrictionValue); - - MosaicAddressRestrictionTransactionBuffer.startMosaicAddressRestrictionTransactionBuffer(builder); - MosaicAddressRestrictionTransactionBuffer.addSize(builder, 169); - MosaicAddressRestrictionTransactionBuffer.addSignature(builder, signatureVector); - MosaicAddressRestrictionTransactionBuffer.addSigner(builder, signerVector); - MosaicAddressRestrictionTransactionBuffer.addVersion(builder, this.version); - MosaicAddressRestrictionTransactionBuffer.addType(builder, this.type); - MosaicAddressRestrictionTransactionBuffer.addFee(builder, feeVector); - MosaicAddressRestrictionTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicAddressRestrictionTransactionBuffer.addMosaicId(builder, mosaicIdVector); - MosaicAddressRestrictionTransactionBuffer.addRestrictionKey(builder, restrictionKeyVector); - MosaicAddressRestrictionTransactionBuffer.addTargetAddress(builder, targetAddressVector); - MosaicAddressRestrictionTransactionBuffer.addPreviousRestrictionValue(builder, previousRestrictionValueVector); - MosaicAddressRestrictionTransactionBuffer.addNewRestrictionValue(builder, newRestrictionValueVector); - - // Calculate size - - const codedMosaicAddressRestriction = - MosaicAddressRestrictionTransactionBuffer.endMosaicAddressRestrictionTransactionBuffer(builder); - builder.finish(codedMosaicAddressRestriction); - - const bytes = builder.asUint8Array(); - - const schema = MosaicAddressRestrictionTransactionSchema; - return new MosaicAddressRestrictionTransaction(bytes, schema); - } -} diff --git a/src/infrastructure/builders/MosaicAliasTransaction.ts b/src/infrastructure/builders/MosaicAliasTransaction.ts deleted file mode 100644 index 7d3abcb45d..0000000000 --- a/src/infrastructure/builders/MosaicAliasTransaction.ts +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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 { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicAliasTransactionBufferPackage from '../buffers/MosaicAliasTransactionBuffer'; -import MosaicAliasTransactionSchema from '../schemas/MosaicAliasTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - MosaicAliasTransactionBuffer, -} = MosaicAliasTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -/** - * @module transactions/MosaicAliasTransaction - */ -export default class MosaicAliasTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, MosaicAliasTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - aliasAction: any; - namespaceId: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_ALIAS; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addAliasAction(aliasAction) { - this.aliasAction = aliasAction; - return this; - } - - addNamespaceId(namespaceId) { - this.namespaceId = namespaceId; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicAliasTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicAliasTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicAliasTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicAliasTransactionBuffer - .createFeeVector(builder, this.maxFee); - const namespaceIdVector = MosaicAliasTransactionBuffer - .createNamespaceIdVector(builder, this.namespaceId); - const mosaicIdVector = MosaicAliasTransactionBuffer - .createMosaicIdVector(builder, this.mosaicId); - - MosaicAliasTransactionBuffer.startMosaicAliasTransactionBuffer(builder); - MosaicAliasTransactionBuffer.addSize(builder, 137); - MosaicAliasTransactionBuffer.addSignature(builder, signatureVector); - MosaicAliasTransactionBuffer.addSigner(builder, signerVector); - MosaicAliasTransactionBuffer.addVersion(builder, this.version); - MosaicAliasTransactionBuffer.addType(builder, this.type); - MosaicAliasTransactionBuffer.addFee(builder, feeVector); - MosaicAliasTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicAliasTransactionBuffer.addAliasAction(builder, this.aliasAction); - MosaicAliasTransactionBuffer.addNamespaceId(builder, namespaceIdVector); - MosaicAliasTransactionBuffer.addMosaicId(builder, mosaicIdVector); - - // Calculate size - const codedMosaicChangeSupply = MosaicAliasTransactionBuffer.endMosaicAliasTransactionBuffer(builder); - builder.finish(codedMosaicChangeSupply); - - const bytes = builder.asUint8Array(); - - return new MosaicAliasTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/MosaicCreationTransaction.ts b/src/infrastructure/builders/MosaicCreationTransaction.ts deleted file mode 100644 index d74ba21660..0000000000 --- a/src/infrastructure/builders/MosaicCreationTransaction.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/MosaicCreationTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicCreationTransactionBufferPackage from '../buffers/MosaicCreationTransactionBuffer'; -import { - schema as MosaicCreationTransactionSchema, - schemaNoDuration as MosaicCreationTransactionSchemaNoDuration, -} from '../schemas/MosaicCreationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - MosaicCreationTransactionBuffer, -} = MosaicCreationTransactionBufferPackage.Buffers; - -export default class MosaicCreationTransaction extends VerifiableTransaction { - constructor(bytes, schema) { - super(bytes, schema); - } -} -// tslint:disable-next-line: max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - flags: any; - nonce: any; - divisibility: any; - duration: any; - constructor() { - this.flags = 0; - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_DEFINITION; - this.nonce = 0; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addNonce(nonce) { - this.nonce = nonce; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addDuration(duration) { - this.duration = duration; - return this; - } - - addDivisibility(divisibility) { - this.divisibility = divisibility; - return this; - } - - addSupplyMutable() { - this.flags += 1; - return this; - } - - addTransferability() { - this.flags += 2; - return this; - } - - addRestrictable() { - this.flags += 4; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicCreationTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicCreationTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicCreationTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicCreationTransactionBuffer - .createFeeVector(builder, this.maxFee); - const nonceVector = MosaicCreationTransactionBuffer - .createNonceVector(builder, this.nonce); - const mosaicIdVector = MosaicCreationTransactionBuffer - .createMosaicIdVector(builder, this.mosaicId); - - const durationVector = MosaicCreationTransactionBuffer - .createDurationVector(builder, this.duration); - - const durationProvided = 0 < this.duration.length; - - MosaicCreationTransactionBuffer.startMosaicCreationTransactionBuffer(builder); - MosaicCreationTransactionBuffer.addSize(builder, durationProvided ? 144 : 135); - MosaicCreationTransactionBuffer.addSignature(builder, signatureVector); - MosaicCreationTransactionBuffer.addSigner(builder, signerVector); - MosaicCreationTransactionBuffer.addVersion(builder, this.version); - MosaicCreationTransactionBuffer.addType(builder, this.type); - MosaicCreationTransactionBuffer.addFee(builder, feeVector); - MosaicCreationTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicCreationTransactionBuffer.addNonce(builder, nonceVector); - MosaicCreationTransactionBuffer.addMosaicId(builder, mosaicIdVector); - MosaicCreationTransactionBuffer.addNumOptionalProperties(builder, durationProvided ? 1 : 0); - MosaicCreationTransactionBuffer.addFlags(builder, this.flags); - - MosaicCreationTransactionBuffer.addDivisibility(builder, this.divisibility); - - if (durationProvided) { - MosaicCreationTransactionBuffer.addIndicateDuration(builder, 2); - MosaicCreationTransactionBuffer.addDuration(builder, durationVector); - } - - // Calculate size - - const codedMosaicCreation = MosaicCreationTransactionBuffer.endMosaicCreationTransactionBuffer(builder); - builder.finish(codedMosaicCreation); - - const bytes = builder.asUint8Array(); - - const schema = durationProvided ? MosaicCreationTransactionSchema : MosaicCreationTransactionSchemaNoDuration; - return new MosaicCreationTransaction(bytes, schema); - } -} diff --git a/src/infrastructure/builders/MosaicGlobalRestrictionTransaction.ts b/src/infrastructure/builders/MosaicGlobalRestrictionTransaction.ts deleted file mode 100644 index 608cc0f2c0..0000000000 --- a/src/infrastructure/builders/MosaicGlobalRestrictionTransaction.ts +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/MosaicGlobalRestrictionTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicGlobalRestrictionTransactionBufferPackage from '../buffers/MosaicGlobalRestrictionTransactionBuffer'; -import MosaicGlobalRestrictionTransactionSchema from '../schemas/MosaicGlobalRestrictionTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - MosaicGlobalRestrictionTransactionBuffer, -} = MosaicGlobalRestrictionTransactionBufferPackage.Buffers; - -export default class MosaicGlobalRestrictionTransaction extends VerifiableTransaction { - constructor(bytes, schema) { - super(bytes, schema); - } -} -// tslint:disable-next-line: max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - referenceMosaicId: any; - restrictionKey: any; - previousRestrictionValue: any; - previousRestrictionType: any; - newRestrictionValue: any; - newRestrictionType: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_GLOBAL_RESTRICTION; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionKey(restrictionKey) { - this.restrictionKey = restrictionKey; - return this; - } - - addPreviousRestrictionValue(previousRestrictionValue) { - this.previousRestrictionValue = previousRestrictionValue; - return this; - } - - addPreviousRestrictionType(previousRestrictionType) { - this.previousRestrictionType = previousRestrictionType; - return this; - } - - addNewRestrictionValue(newRestrictionValue) { - this.newRestrictionValue = newRestrictionValue; - return this; - } - - addNewRestrictionType(newRestrictionType) { - this.newRestrictionType = newRestrictionType; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - addReferenceMosaicId(referenceMosaicId) { - this.referenceMosaicId = referenceMosaicId; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicGlobalRestrictionTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicGlobalRestrictionTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicGlobalRestrictionTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicGlobalRestrictionTransactionBuffer - .createFeeVector(builder, this.maxFee); - const mosaicIdVector = MosaicGlobalRestrictionTransactionBuffer - .createMosaicIdVector(builder, this.mosaicId); - const referenceMosaicIdVector = MosaicGlobalRestrictionTransactionBuffer - .createReferenceMosaicIdVector(builder, this.referenceMosaicId); - const restrictionKeyVector = MosaicGlobalRestrictionTransactionBuffer - .createRestrictionKeyVector(builder, this.restrictionKey); - const previousRestrictionValueVector = MosaicGlobalRestrictionTransactionBuffer - .createPreviousRestrictionValueVector(builder, this.previousRestrictionValue); - const newRestrictionValueVector = MosaicGlobalRestrictionTransactionBuffer - .createNewRestrictionValueVector(builder, this.newRestrictionValue); - - MosaicGlobalRestrictionTransactionBuffer.startMosaicGlobalRestrictionTransactionBuffer(builder); - MosaicGlobalRestrictionTransactionBuffer.addSize(builder, 162); - MosaicGlobalRestrictionTransactionBuffer.addSignature(builder, signatureVector); - MosaicGlobalRestrictionTransactionBuffer.addSigner(builder, signerVector); - MosaicGlobalRestrictionTransactionBuffer.addVersion(builder, this.version); - MosaicGlobalRestrictionTransactionBuffer.addType(builder, this.type); - MosaicGlobalRestrictionTransactionBuffer.addFee(builder, feeVector); - MosaicGlobalRestrictionTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicGlobalRestrictionTransactionBuffer.addMosaicId(builder, mosaicIdVector); - MosaicGlobalRestrictionTransactionBuffer.addReferenceMosaicId(builder, referenceMosaicIdVector); - MosaicGlobalRestrictionTransactionBuffer.addRestrictionKey(builder, restrictionKeyVector); - MosaicGlobalRestrictionTransactionBuffer.addPreviousRestrictionValue(builder, previousRestrictionValueVector); - MosaicGlobalRestrictionTransactionBuffer.addPreviousRestrictionType(builder, this.previousRestrictionType); - MosaicGlobalRestrictionTransactionBuffer.addNewRestrictionValue(builder, newRestrictionValueVector); - MosaicGlobalRestrictionTransactionBuffer.addNewRestrictionType(builder, this.newRestrictionType); - - // Calculate size - - const codedMosaicGlobalRestriction = - MosaicGlobalRestrictionTransactionBuffer.endMosaicGlobalRestrictionTransactionBuffer(builder); - builder.finish(codedMosaicGlobalRestriction); - - const bytes = builder.asUint8Array(); - - const schema = MosaicGlobalRestrictionTransactionSchema; - return new MosaicGlobalRestrictionTransaction(bytes, schema); - } -} diff --git a/src/infrastructure/builders/MosaicSupplyChangeTransaction.ts b/src/infrastructure/builders/MosaicSupplyChangeTransaction.ts deleted file mode 100644 index cfff8db53c..0000000000 --- a/src/infrastructure/builders/MosaicSupplyChangeTransaction.ts +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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 { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicSupplyChangeTransactionBufferPackage from '../buffers/MosaicSupplyChangeTransactionBuffer'; -import MosaicSupplyChangeTransactionSchema from '../schemas/MosaicSupplyChangeTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - MosaicSupplyChangeTransactionBuffer, -} = MosaicSupplyChangeTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -/** - * @module transactions/MosaicSupplyChangeTransaction - */ -export default class MosaicSupplyChangeTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, MosaicSupplyChangeTransactionSchema); - } -} -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - direction: any; - delta: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_SUPPLY_CHANGE; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - addDirection(direction) { - this.direction = direction; - return this; - } - - addDelta(delta) { - this.delta = delta; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicSupplyChangeTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicSupplyChangeTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicSupplyChangeTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicSupplyChangeTransactionBuffer - .createFeeVector(builder, this.maxFee); - const mosaicIdVector = MosaicSupplyChangeTransactionBuffer - .createFeeVector(builder, this.mosaicId); - const deltaVector = MosaicSupplyChangeTransactionBuffer - .createFeeVector(builder, this.delta); - - MosaicSupplyChangeTransactionBuffer.startMosaicSupplyChangeTransactionBuffer(builder); - MosaicSupplyChangeTransactionBuffer.addSize(builder, 137); - MosaicSupplyChangeTransactionBuffer.addSignature(builder, signatureVector); - MosaicSupplyChangeTransactionBuffer.addSigner(builder, signerVector); - MosaicSupplyChangeTransactionBuffer.addVersion(builder, this.version); - MosaicSupplyChangeTransactionBuffer.addType(builder, this.type); - MosaicSupplyChangeTransactionBuffer.addFee(builder, feeVector); - MosaicSupplyChangeTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicSupplyChangeTransactionBuffer.addMosaicId(builder, mosaicIdVector); - MosaicSupplyChangeTransactionBuffer.addDirection(builder, this.direction); - MosaicSupplyChangeTransactionBuffer.addDelta(builder, deltaVector); - - // Calculate size - const codedMosaicChangeSupply = MosaicSupplyChangeTransactionBuffer.endMosaicSupplyChangeTransactionBuffer(builder); - builder.finish(codedMosaicChangeSupply); - - const bytes = builder.asUint8Array(); - return new MosaicSupplyChangeTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/MultisigModificationTransaction.ts b/src/infrastructure/builders/MultisigModificationTransaction.ts deleted file mode 100644 index a11dbfdeb5..0000000000 --- a/src/infrastructure/builders/MultisigModificationTransaction.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* - * 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 { Convert as convert } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import MultisigModificationTransactionBufferPackage from '../buffers/MultisigModificationTransactionBuffer'; -import MultisigModificationTransactionSchema from '../schemas/MultisigModificationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - MultisigModificationTransactionBuffer, - CosignatoryModificationBuffer, -} = MultisigModificationTransactionBufferPackage.Buffers; - -/** - * @module transactions/MultisigModificationTransaction - */ -export default class MultisigModificationTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, MultisigModificationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - minRemovalDelta: any; - minApprovalDelta: any; - modifications: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MODIFY_MULTISIG_ACCOUNT; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addMinRemovalDelta(minRemovalDelta) { - this.minRemovalDelta = minRemovalDelta; - return this; - } - - addMinApprovalDelta(minApprovalDelta) { - this.minApprovalDelta = minApprovalDelta; - return this; - } - - addModifications(modifications) { - this.modifications = modifications; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create modifications - const modificationsArray: any = []; - this.modifications.forEach((modification) => { - const cosignatoryPublicKeyVector = CosignatoryModificationBuffer - .createCosignatoryPublicKeyVector(builder, convert.hexToUint8(modification.cosignatoryPublicKey)); - CosignatoryModificationBuffer.startCosignatoryModificationBuffer(builder); - CosignatoryModificationBuffer.addType(builder, modification.type); - CosignatoryModificationBuffer.addCosignatoryPublicKey(builder, cosignatoryPublicKeyVector); - modificationsArray.push(CosignatoryModificationBuffer.endCosignatoryModificationBuffer(builder)); - }); - - // Create vectors - const signatureVector = MultisigModificationTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MultisigModificationTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MultisigModificationTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MultisigModificationTransactionBuffer - .createFeeVector(builder, this.maxFee); - const modificationsVector = MultisigModificationTransactionBuffer - .createModificationsVector(builder, modificationsArray); - - MultisigModificationTransactionBuffer.startMultisigModificationTransactionBuffer(builder); - MultisigModificationTransactionBuffer.addSize(builder, 123 + (33 * this.modifications.length)); - MultisigModificationTransactionBuffer.addSignature(builder, signatureVector); - MultisigModificationTransactionBuffer.addSigner(builder, signerVector); - MultisigModificationTransactionBuffer.addVersion(builder, this.version); - MultisigModificationTransactionBuffer.addType(builder, this.type); - MultisigModificationTransactionBuffer.addFee(builder, feeVector); - MultisigModificationTransactionBuffer.addDeadline(builder, deadlineVector); - MultisigModificationTransactionBuffer.addMinRemovalDelta(builder, this.minRemovalDelta); - MultisigModificationTransactionBuffer.addMinApprovalDelta(builder, this.minApprovalDelta); - MultisigModificationTransactionBuffer.addNumModifications(builder, this.modifications.length); - MultisigModificationTransactionBuffer.addModifications(builder, modificationsVector); - - // Calculate size - const codedMultisigAggregate = MultisigModificationTransactionBuffer - .endMultisigModificationTransactionBuffer(builder); - builder.finish(codedMultisigAggregate); - - const bytes = builder.asUint8Array(); - return new MultisigModificationTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/NamespaceCreationTransaction.ts b/src/infrastructure/builders/NamespaceCreationTransaction.ts deleted file mode 100644 index 0cf2ba5d67..0000000000 --- a/src/infrastructure/builders/NamespaceCreationTransaction.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/NamespaceCreationTransaction - */ -import { Convert as convert } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import * as NamespaceCreationTransactionBufferPackage from '../buffers/NamespaceCreationTransactionBuffer'; -import NamespaceCreationTransactionSchema from '../schemas/NamespaceCreationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - NamespaceCreationTransactionBuffer, -} = NamespaceCreationTransactionBufferPackage.default.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -export default class NamespaceCreationTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, NamespaceCreationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - namespaceType: any; - duration: any; - parentId: any; - namespaceId: any; - namespaceName: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.REGISTER_NAMESPACE; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addNamespaceType(namespaceType) { - this.namespaceType = namespaceType; - return this; - } - - addDuration(duration) { - this.duration = duration; - return this; - } - - addParentId(parentId) { - this.parentId = parentId; - return this; - } - - addNamespaceId(namespaceId) { - this.namespaceId = namespaceId; - return this; - } - - addNamespaceName(namespaceName) { - this.namespaceName = namespaceName; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - const namespaceNameLength = convert.utf8ToHex(this.namespaceName).length / 2; - - // create vectors - const signatureVector = NamespaceCreationTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = NamespaceCreationTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = NamespaceCreationTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = NamespaceCreationTransactionBuffer - .createFeeVector(builder, this.maxFee); - const parentIdVector = 1 === this.namespaceType ? this.parentId : this.duration; - const durationParentIdVector = NamespaceCreationTransactionBuffer - .createDurationParentIdVector(builder, parentIdVector); - const namespaceIdVector = NamespaceCreationTransactionBuffer - .createNamespaceIdVector(builder, this.namespaceId); - - const name = builder.createString(this.namespaceName); - - NamespaceCreationTransactionBuffer.startNamespaceCreationTransactionBuffer(builder); - NamespaceCreationTransactionBuffer.addSize(builder, 138 + namespaceNameLength); - NamespaceCreationTransactionBuffer.addSignature(builder, signatureVector); - NamespaceCreationTransactionBuffer.addSigner(builder, signerVector); - NamespaceCreationTransactionBuffer.addVersion(builder, this.version); - NamespaceCreationTransactionBuffer.addType(builder, this.type); - NamespaceCreationTransactionBuffer.addFee(builder, feeVector); - NamespaceCreationTransactionBuffer.addDeadline(builder, deadlineVector); - NamespaceCreationTransactionBuffer.addNamespaceType(builder, this.namespaceType); - NamespaceCreationTransactionBuffer.addDurationParentId(builder, durationParentIdVector); - NamespaceCreationTransactionBuffer.addNamespaceId(builder, namespaceIdVector); - NamespaceCreationTransactionBuffer.addNamespaceNameSize(builder, namespaceNameLength); - NamespaceCreationTransactionBuffer.addNamespaceName(builder, name); - - // Calculate size - const codedNamespace = NamespaceCreationTransactionBuffer.endNamespaceCreationTransactionBuffer(builder); - builder.finish(codedNamespace); - - const bytes = builder.asUint8Array(); - return new NamespaceCreationTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/SecretLockTransaction.ts b/src/infrastructure/builders/SecretLockTransaction.ts deleted file mode 100644 index 5e66e40c9b..0000000000 --- a/src/infrastructure/builders/SecretLockTransaction.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/SecretLockTransaction - */ -import { Convert as convert, RawAddress as address } from '../../core/format'; -import * as SecretLockTransactionBufferPackage from '../../infrastructure/buffers/SecretLockTransactionBuffer'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; -import SecretLockTransactionSchema from '../../infrastructure/schemas/SecretLockTransactionSchema'; -import { TransactionType } from '../../model/transaction/TransactionType'; - -import {flatbuffers} from 'flatbuffers'; - -const { - SecretLockTransactionBuffer, -} = SecretLockTransactionBufferPackage.default.Buffers; - -export default class SecretLockTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, SecretLockTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - mosaicAmount: any; - duration: any; - hashAlgorithm: any; - secret: any; - recipient: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.SECRET_LOCK; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - addMosaicAmount(mosaicAmount) { - this.mosaicAmount = mosaicAmount; - return this; - } - - addDuration(duration) { - this.duration = duration; - return this; - } - - addHashAlgorithm(hashAlgorithm) { - this.hashAlgorithm = hashAlgorithm; - return this; - } - - addSecret(secret) { - this.secret = secret; - return this; - } - - addRecipient(recipient) { - this.recipient = address.stringToAddress(recipient); - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = SecretLockTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = SecretLockTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = SecretLockTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = SecretLockTransactionBuffer.createFeeVector(builder, this.maxFee); - const mosaicIdVector = SecretLockTransactionBuffer.createMosaicIdVector(builder, this.mosaicId); - const mosaicAmountVector = SecretLockTransactionBuffer.createMosaicAmountVector(builder, this.mosaicAmount); - const durationVector = SecretLockTransactionBuffer.createDurationVector(builder, this.duration); - const byteSecret = convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); - const secretVector = SecretLockTransactionBuffer.createSecretVector(builder, byteSecret); - const recipientVector = SecretLockTransactionBuffer.createRecipientVector(builder, this.recipient); - - SecretLockTransactionBuffer.startSecretLockTransactionBuffer(builder); - SecretLockTransactionBuffer.addSize(builder, 202); - SecretLockTransactionBuffer.addSignature(builder, signatureVector); - SecretLockTransactionBuffer.addSigner(builder, signerVector); - SecretLockTransactionBuffer.addVersion(builder, this.version); - SecretLockTransactionBuffer.addType(builder, this.type); - SecretLockTransactionBuffer.addFee(builder, feeVector); - SecretLockTransactionBuffer.addDeadline(builder, deadlineVector); - SecretLockTransactionBuffer.addMosaicId(builder, mosaicIdVector); - SecretLockTransactionBuffer.addMosaicAmount(builder, mosaicAmountVector); - SecretLockTransactionBuffer.addDuration(builder, durationVector); - SecretLockTransactionBuffer.addHashAlgorithm(builder, this.hashAlgorithm); - SecretLockTransactionBuffer.addSecret(builder, secretVector); - SecretLockTransactionBuffer.addRecipient(builder, recipientVector); - - const codedSecretLock = SecretLockTransactionBuffer.endSecretLockTransactionBuffer(builder); - builder.finish(codedSecretLock); - - const bytes = builder.asUint8Array(); - return new SecretLockTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/SecretProofTransaction.ts b/src/infrastructure/builders/SecretProofTransaction.ts deleted file mode 100644 index 619e037173..0000000000 --- a/src/infrastructure/builders/SecretProofTransaction.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/SecretProofTransaction - */ -import { Convert as convert, RawAddress as address } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import * as SecretProofTransactionBufferPackage from '../buffers/SecretProofTransactionBuffer'; -import SecretProofTransactionSchema from '../schemas/SecretProofTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - SecretProofTransactionBuffer, -} = SecretProofTransactionBufferPackage.default.Buffers; - -export default class SecretProofTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, SecretProofTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - hashAlgorithm: any; - secret: any; - recipient: any; - proof: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.SECRET_PROOF; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addHashAlgorithm(hashAlgorithm) { - this.hashAlgorithm = hashAlgorithm; - return this; - } - - addSecret(secret) { - this.secret = secret; - return this; - } - addRecipient(recipient) { - this.recipient = address.stringToAddress(recipient); - return this; - } - - addProof(proof) { - this.proof = proof; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = SecretProofTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = SecretProofTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = SecretProofTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = SecretProofTransactionBuffer.createFeeVector(builder, this.maxFee); - const byteSecret = convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); - const secretVector = SecretProofTransactionBuffer.createSecretVector(builder, byteSecret); - const recipientVector = SecretProofTransactionBuffer.createRecipientVector(builder, this.recipient); - const byteProof = convert.hexToUint8(this.proof); - const proofVector = SecretProofTransactionBuffer.createProofVector(builder, byteProof); - - SecretProofTransactionBuffer.startSecretProofTransactionBuffer(builder); - SecretProofTransactionBuffer.addSize(builder, 180 + byteProof.length); - SecretProofTransactionBuffer.addSignature(builder, signatureVector); - SecretProofTransactionBuffer.addSigner(builder, signerVector); - SecretProofTransactionBuffer.addVersion(builder, this.version); - SecretProofTransactionBuffer.addType(builder, this.type); - SecretProofTransactionBuffer.addFee(builder, feeVector); - SecretProofTransactionBuffer.addDeadline(builder, deadlineVector); - SecretProofTransactionBuffer.addHashAlgorithm(builder, this.hashAlgorithm); - SecretProofTransactionBuffer.addSecret(builder, secretVector); - SecretProofTransactionBuffer.addRecipient(builder, recipientVector); - SecretProofTransactionBuffer.addProofSize(builder, byteProof.length); - SecretProofTransactionBuffer.addProof(builder, proofVector); - - const codedSecretProof = SecretProofTransactionBuffer.endSecretProofTransactionBuffer(builder); - builder.finish(codedSecretProof); - - const bytes = builder.asUint8Array(); - return new SecretProofTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/TransferTransaction.ts b/src/infrastructure/builders/TransferTransaction.ts deleted file mode 100644 index 0153d44a91..0000000000 --- a/src/infrastructure/builders/TransferTransaction.ts +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/TransferTransaction - */ -import { Convert as convert, RawAddress as address} from '../../core/format'; -import * as TransferTransactionBufferPackage from '../../infrastructure/buffers/TransferTransactionBuffer'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; -import TransferTransactionSchema from '../../infrastructure/schemas/TransferTransactionSchema'; -import { TransactionType } from '../../model/transaction/TransactionType'; - -import {flatbuffers} from 'flatbuffers'; - -const { - TransferTransactionBuffer, - MessageBuffer, - MosaicBuffer, -} = TransferTransactionBufferPackage.default.Buffers; - -export default class TransferTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, TransferTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - recipient: any; - message: any; - mosaics: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.TRANSFER; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRecipient(recipient) { - if (/^[0-9a-fA-F]{16}$/.test(recipient)) { - // received hexadecimal notation of namespaceId (alias) - this.recipient = address.aliasToRecipient(convert.hexToUint8(recipient)); - } else { - // received recipient address - this.recipient = address.stringToAddress(recipient); - } - return this; - } - - addMessage(message) { - this.message = message; - return this; - } - - addMosaics(mosaics) { - this.mosaics = mosaics.sort((a, b) => { - if (Number(a.id[1]) > b.id[1]) { return 1; } else if (a.id[1] < b.id[1]) { return -1; } - return 0; - }); - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - // Constants - - // Create message - const bytePayload = convert.hexToUint8(convert.utf8ToHex(this.message.payload)); - const payload = MessageBuffer.createPayloadVector(builder, bytePayload); - MessageBuffer.startMessageBuffer(builder); - MessageBuffer.addType(builder, this.message.type); - MessageBuffer.addPayload(builder, payload); - const message = MessageBuffer.endMessageBuffer(builder); - - // Create mosaics - const mosaics: any = []; - this.mosaics.forEach(mosaic => { - const id = MosaicBuffer.createIdVector(builder, mosaic.id); - const amount = MosaicBuffer.createAmountVector(builder, mosaic.amount); - MosaicBuffer.startMosaicBuffer(builder); - MosaicBuffer.addId(builder, id); - MosaicBuffer.addAmount(builder, amount); - mosaics.push(MosaicBuffer.endMosaicBuffer(builder)); - }); - - // Create vectors - const signatureVector = TransferTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = TransferTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = TransferTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = TransferTransactionBuffer.createFeeVector(builder, this.maxFee); - const recipientVector = TransferTransactionBuffer.createRecipientVector(builder, this.recipient); - const mosaicsVector = TransferTransactionBuffer.createMosaicsVector(builder, mosaics); - - TransferTransactionBuffer.startTransferTransactionBuffer(builder); - TransferTransactionBuffer.addSize(builder, 149 + (16 * this.mosaics.length) + bytePayload.length); - TransferTransactionBuffer.addSignature(builder, signatureVector); - TransferTransactionBuffer.addSigner(builder, signerVector); - TransferTransactionBuffer.addVersion(builder, this.version); - TransferTransactionBuffer.addType(builder, this.type); - TransferTransactionBuffer.addFee(builder, feeVector); - TransferTransactionBuffer.addDeadline(builder, deadlineVector); - TransferTransactionBuffer.addRecipient(builder, recipientVector); - TransferTransactionBuffer.addNumMosaics(builder, this.mosaics.length); - TransferTransactionBuffer.addMessageSize(builder, bytePayload.length + 1); - TransferTransactionBuffer.addMessage(builder, message); - TransferTransactionBuffer.addMosaics(builder, mosaicsVector); - - // Calculate size - - const codedTransfer = TransferTransactionBuffer.endTransferTransactionBuffer(builder); - builder.finish(codedTransfer); - - const bytes = builder.asUint8Array(); - return new TransferTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/VerifiableTransaction.ts b/src/infrastructure/builders/VerifiableTransaction.ts deleted file mode 100644 index d83b079d59..0000000000 --- a/src/infrastructure/builders/VerifiableTransaction.ts +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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 { KeyPair, SignSchema } from '../../core/crypto'; -import { SHA3Hasher as sha3Hasher } from '../../core/crypto/SHA3Hasher'; -import { Convert as convert } from '../../core/format'; - -/** - * VerifiableTransaction - * @module transactions/VerifiableTransaction - * @version 1.0.0 - */ -export class VerifiableTransaction { - bytes: any; - schema: any; - /** - * @constructor - * @param {Uint8Array} bytes Uint8Array after flatbuffers.build.asUint8Array() - * @param {module:schema/Schema} schema Schema definition corresponding to flatbuffer Schema - */ - constructor(bytes, schema) { - this.bytes = bytes; - this.schema = schema; - } - - /** - * @param {string} transactionPayload HexString Payload - * @param {string} generationHash Network generation hash byte - * @returns {*|string} Returns Transaction Payload hash - */ - static createTransactionHash(transactionPayload, generationHash) { - const byteBuffer = Array.from(convert.hexToUint8(transactionPayload)); - const signingBytes = byteBuffer - .slice(4, 36) - .concat(byteBuffer - .slice(4 + 64, 4 + 64 + 32)) - .concat(generationHash) - .concat(byteBuffer - .splice(4 + 64 + 32, byteBuffer.length)); - - const hash = new Uint8Array(32); - - sha3Hasher.func(hash, signingBytes, 32); - - return convert.uint8ToHex(hash); - } - - /** - * @param {KeyPair } keyPair KeyPair instance - * @param {string} generationHash Network generation hash hex - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {module:model/TransactionPayload} - Signed Transaction Payload - */ - signTransaction(keyPair, generationHash, signSchema: SignSchema = SignSchema.SHA3) { - const generationHashBytes = Array.from(convert.hexToUint8(generationHash)); - const byteBuffer = this.serialize(); - const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); - const keyPairEncoded = KeyPair.createKeyPairFromPrivateKeyString(keyPair.privateKey, signSchema); - const signature = Array.from(KeyPair.sign(keyPair, new Uint8Array(signingBytes), signSchema)); - const signedTransactionBuffer = byteBuffer - .splice(0, 4) - .concat(signature) - .concat(Array.from(keyPairEncoded.publicKey)) - .concat(byteBuffer - .splice(64 + 32, byteBuffer.length)); - const payload = convert.uint8ToHex(signedTransactionBuffer); - return { - payload, - hash: VerifiableTransaction.createTransactionHash(payload, generationHashBytes), - }; - } - - serialize() { - return this.schema.serialize(Array.from(this.bytes)); - } - - /** - * @returns {string} - Serialized Transaction Payload - */ - serializeUnsignedTransaction() { - return convert.uint8ToHex(this.serialize()); - } - - /** - * @param {KeyPair} keyPair KeyPair instance - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {module:model/TransactionPayload} Returns TransactionPayload instance - */ - signCosignatoriesTransaction(keyPair, signSchema: SignSchema = SignSchema.SHA3) { - const signature = KeyPair.sign(keyPair, new Uint8Array(this.bytes), signSchema); - return { - parentHash: convert.uint8ToHex(this.bytes), - signature: convert.uint8ToHex(signature), - signer: keyPair.publicKey, - }; - } - - /** - * Converts the transaction into AggregateTransaction compatible - * @param {string} [_signer] Signer public key - * @returns {Array.<*>} AggregateTransaction bytes - */ - toAggregateTransaction(_signer) { - const signer = convert.hexToUint8(_signer); - let resultBytes = this.schema.serialize(Array.from(this.bytes)); - resultBytes.splice(0, 4 + 64 + 32); - resultBytes = Array.from(signer).concat(resultBytes); - resultBytes.splice(32 + 2 + 2, 16); - return Array.from((new Uint8Array([ - (resultBytes.length + 4 & 0x000000ff), - (resultBytes.length + 4 & 0x0000ff00) >> 8, - (resultBytes.length + 4 & 0x00ff0000) >> 16, - (resultBytes.length + 4 & 0xff000000) >> 24, - ]))).concat(resultBytes); - } -} diff --git a/src/infrastructure/builders/VerificableTransactionBuilder.ts b/src/infrastructure/builders/VerificableTransactionBuilder.ts deleted file mode 100644 index a63c9cb9ab..0000000000 --- a/src/infrastructure/builders/VerificableTransactionBuilder.ts +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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'; - -const { - flatbuffers -} = require('flatbuffers'); - -/** - * @module transactions/VerifiableTransactionBuilder - */ - -/** - * @callback LambdaBuilder - * @param {flatbuffers.Builder} builder - * @return {void} - */ - -export default class VerifiableTransactionBuilder { - bytes: any; - schema: any - /** - * @param {LambdaBuilder} lambda Callback - * @returns {VerifiableTransactionBuilder} Returns self instance - */ - addTransaction(lambda) { - const builder = new flatbuffers.Builder(1); - - lambda(builder); - - this.bytes = builder.asUint8Array(); - return this; - } - - /** - * @param {module:schema/Schema} schema Schema corresponding with flatbuffers Schema used on addTransaction - * @returns {VerifiableTransactionBuilder} Returns self instance - */ - addSchema(schema) { - this.schema = schema; - return this; - } - - /** - * @returns {VerifiableTransaction} Returns VerifiableTransaction instance - */ - build() { - return new VerifiableTransaction(this.bytes, this.schema); - } -} diff --git a/src/infrastructure/schemas/AccountLinkTransactionSchema.ts b/src/infrastructure/schemas/AccountLinkTransactionSchema.ts deleted file mode 100644 index 5a0e3be1ba..0000000000 --- a/src/infrastructure/schemas/AccountLinkTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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/AccountLinkTransaction - */ - -/** - * Account Link schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('remoteAccountKey'), - ubyte('linkAction') -]); -export default schema; diff --git a/src/infrastructure/schemas/AccountRestrictionsAddressModificationTransactionSchema.ts b/src/infrastructure/schemas/AccountRestrictionsAddressModificationTransactionSchema.ts deleted file mode 100644 index f08fd0cda3..0000000000 --- a/src/infrastructure/schemas/AccountRestrictionsAddressModificationTransactionSchema.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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, - ushort, - tableArray, - uint -} from './Schema'; - -/** - * @module schema/AccountRestrictionsAddressModificationTransactionSchema - */ - -/** - * Account restriction address 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('restrictionType'), - ubyte('modificationCount'), - tableArray('modifications', [ - ubyte('modificationType'), - array('value', TypeSize.BYTE) - ]) -]); diff --git a/src/infrastructure/schemas/AccountRestrictionsEntityTypeModificationTransactionSchema.ts b/src/infrastructure/schemas/AccountRestrictionsEntityTypeModificationTransactionSchema.ts deleted file mode 100644 index 6d9090a5c0..0000000000 --- a/src/infrastructure/schemas/AccountRestrictionsEntityTypeModificationTransactionSchema.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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, - ushort, - tableArray, - uint -} from './Schema'; - -/** - * @module schema/AccountRestrictionsEntityTypeModificationTransactionSchema - */ - -/** - * Account restrictions address 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('restrictionType'), - ubyte('modificationCount'), - tableArray('modifications', [ - ubyte('modificationType'), - ushort('value') - ]) -]); diff --git a/src/infrastructure/schemas/AccountRestrictionsMosaicModificationTransactionSchema.ts b/src/infrastructure/schemas/AccountRestrictionsMosaicModificationTransactionSchema.ts deleted file mode 100644 index 557c38898e..0000000000 --- a/src/infrastructure/schemas/AccountRestrictionsMosaicModificationTransactionSchema.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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, - ushort, - tableArray, - uint -} from './Schema'; - -/** - * @module schema/AccountRestrictionsMosaicModificationTransactionSchema - */ - -/** - * Account restrictions address 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('restrictionType'), - ubyte('modificationCount'), - tableArray('modifications', [ - ubyte('modificationType'), - array('value', TypeSize.INT) - ]) -]); diff --git a/src/infrastructure/schemas/AddressAliasTransactionSchema.ts b/src/infrastructure/schemas/AddressAliasTransactionSchema.ts deleted file mode 100644 index ef01e3eadd..0000000000 --- a/src/infrastructure/schemas/AddressAliasTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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('aliasAction'), - array('namespaceId', TypeSize.INT), - array('address', TypeSize.BYTE) -]); diff --git a/src/infrastructure/schemas/AggregateTransactionSchema.ts b/src/infrastructure/schemas/AggregateTransactionSchema.ts deleted file mode 100644 index f27bc0e142..0000000000 --- a/src/infrastructure/schemas/AggregateTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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, - uint, - ushort -} from './Schema'; - -/** - * @module schema/AggregateTransactionSchema - */ - -/** - * Aggregate transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - uint('transactionsSize'), - array('transactions') -]); - -export default schema; diff --git a/src/infrastructure/schemas/HashLockTransactionSchema.ts b/src/infrastructure/schemas/HashLockTransactionSchema.ts deleted file mode 100644 index 2efbf4ffaa..0000000000 --- a/src/infrastructure/schemas/HashLockTransactionSchema.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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, - uint, - ushort -} from './Schema'; - -/** - * @module schema/HashLockTransactionSchema - */ - -/** - * Hash lock transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('mosaicId', TypeSize.INT), - array('mosaicAmount', TypeSize.INT), - array('duration', TypeSize.INT), - array('hash') -]); -export default schema; diff --git a/src/infrastructure/schemas/MosaicAddressRestrictionTransactionSchema.ts b/src/infrastructure/schemas/MosaicAddressRestrictionTransactionSchema.ts deleted file mode 100644 index 18123110e1..0000000000 --- a/src/infrastructure/schemas/MosaicAddressRestrictionTransactionSchema.ts +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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/MosaicAddressRestrictionTransactionSchema - */ - -/** - * Account Link 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), - array('mosaicId', TypeSize.INT), - array('restrictionKey', TypeSize.INT), - array('targetAddress', TypeSize.BYTE), - array('previousRestrictionValue', TypeSize.INT), - array('newRestrictionValue', TypeSize.INT), -]); diff --git a/src/infrastructure/schemas/MosaicAliasTransactionSchema.ts b/src/infrastructure/schemas/MosaicAliasTransactionSchema.ts deleted file mode 100644 index 37b827b192..0000000000 --- a/src/infrastructure/schemas/MosaicAliasTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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('aliasAction'), - array('namespaceId', TypeSize.INT), - array('mosaicId', TypeSize.INT) -]); diff --git a/src/infrastructure/schemas/MosaicCreationTransactionSchema.ts b/src/infrastructure/schemas/MosaicCreationTransactionSchema.ts deleted file mode 100644 index e9d947652a..0000000000 --- a/src/infrastructure/schemas/MosaicCreationTransactionSchema.ts +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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/MosaicCreationTransactionSchema - */ - -/** - * Mosaic definition creation transaction schema - * @const {module:schema/Schema} - */ -export const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('nonce', TypeSize.BYTE), - array('mosaicId', TypeSize.INT), - ubyte('numOptionalProperties'), - ubyte('flags'), - ubyte('divisibility'), - ubyte('indicateDuration'), - array('duration', TypeSize.INT) -]); - -export const schemaNoDuration = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('nonce', TypeSize.BYTE), - array('mosaicId', TypeSize.INT), - ubyte('numOptionalProperties'), - ubyte('flags'), - ubyte('divisibility') -]); diff --git a/src/infrastructure/schemas/MosaicGlobalRestrictionTransactionSchema.ts b/src/infrastructure/schemas/MosaicGlobalRestrictionTransactionSchema.ts deleted file mode 100644 index d5be82b1ec..0000000000 --- a/src/infrastructure/schemas/MosaicGlobalRestrictionTransactionSchema.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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/MosaicGlobalRestrictionTransactionSchema - */ - -/** - * Account Link 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), - array('mosaicId', TypeSize.INT), - array('referenceMosaicId', TypeSize.INT), - array('restrictionKey', TypeSize.INT), - array('previousRestrictionValue', TypeSize.INT), - ubyte('previousRestrictionType'), - array('newRestrictionValue', TypeSize.INT), - ubyte('newRestrictionType'), - -]); diff --git a/src/infrastructure/schemas/MosaicSupplyChangeTransactionSchema.ts b/src/infrastructure/schemas/MosaicSupplyChangeTransactionSchema.ts deleted file mode 100644 index 19df7503b8..0000000000 --- a/src/infrastructure/schemas/MosaicSupplyChangeTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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/MosaicSupplyChangeTransactionSchema - */ - -/** - * Mosaic supply change 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), - array('mosaicId', TypeSize.INT), - ubyte('direction'), - array('delta', TypeSize.INT) -]); diff --git a/src/infrastructure/schemas/MultisigModificationTransactionSchema.ts b/src/infrastructure/schemas/MultisigModificationTransactionSchema.ts deleted file mode 100644 index 91beb8efc6..0000000000 --- a/src/infrastructure/schemas/MultisigModificationTransactionSchema.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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, - tableArray, - TypeSize, - ubyte, - uint, - ushort -} from './Schema'; - -/** - * @module schema/MultigAggregateModificationTransactionSchema - */ - -/** - * Multisig aggregate modification 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('minRemovalDelta'), - ubyte('minApprovalDelta'), - ubyte('numModifications'), - tableArray('modifications', [ - ubyte('type'), - array('cosignatoryPublicKey') - ]) -]); diff --git a/src/infrastructure/schemas/NamespaceCreationTransactionSchema.ts b/src/infrastructure/schemas/NamespaceCreationTransactionSchema.ts deleted file mode 100644 index 7694dddc5e..0000000000 --- a/src/infrastructure/schemas/NamespaceCreationTransactionSchema.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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, - string, - TypeSize, - ubyte, - uint, - ushort -} from './Schema'; - -/** - * @module schema/NamespaceCreationTransactionSchema - */ - -/** - * Provision namespace 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('namespaceType'), - array('durationParentId', TypeSize.INT), - array('namespaceId', TypeSize.INT), - ubyte('namespaceNameSize'), - string('name') -]); diff --git a/src/infrastructure/schemas/Schema.ts b/src/infrastructure/schemas/Schema.ts deleted file mode 100644 index 212378e39e..0000000000 --- a/src/infrastructure/schemas/Schema.ts +++ /dev/null @@ -1,374 +0,0 @@ -/* - * 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. - */ - -/* eslint-disable no-use-before-define */ - -/** - * In bytes - * @type {{BYTE: number, SHORT: number, INT: number}} - */ -export const TypeSize = { - BYTE: 1, - SHORT: 2, - INT: 4, -}; - -/** - * @param {string} name Attribute name - * @returns {ScalarAttribute} return ScalarAttribute Instance - */ -export const ubyte = (name) => { - return new ScalarAttribute(name, TypeSize.BYTE); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const byte = (name) => { - return new ScalarAttribute(name, TypeSize.BYTE); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const ushort = (name) => { - return new ScalarAttribute(name, TypeSize.SHORT); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const short = (name) => { - return new ScalarAttribute(name, TypeSize.SHORT); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const uint = (name) => { - return new ScalarAttribute(name, TypeSize.INT); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const int = (name) => { - return new ScalarAttribute(name, TypeSize.INT); -}; - -/** - * - * @param {string} name Attribute Name - * @param {number} typeSize Attribute Byte Size - * @returns {ArrayAttribute} ArrayAttribute Instance - */ -export const array = (name, typeSize = TypeSize.BYTE) => { - return new ArrayAttribute(name, typeSize); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ArrayAttribute} ArrayAttribute Instance - */ -export const string = (name) => { - return array(name); -}; - -/** - * - * @param {string} name Attribute Name - * @param {module:schema/Schema} schema Table Specific Schema definition - * @returns {TableAttribute} TableAttribute Instance - */ -export const table = (name, schema) => { - return new TableAttribute(name, schema); -}; - -/** - * - * @param {string} name Attribute Name - * @param {module:schema/Schema} schema Schema Definition - * @returns {TableArrayAttribute} TableAttribute Instance - */ -export const tableArray = (name, schema) => { - return new TableArrayAttribute(name, schema); -}; - -/* eslint-disable */ -const readInt32 = (offset, bytes) => { - return bytes[offset] | bytes[offset + 1] << 8 | bytes[offset + 2] << 16 | bytes[offset + 3] << 24; -}; - -const readInt16 = (offset, bytes) => { - return bytes[offset] | bytes[offset + 1] << 8; -}; - -const __offset = (val0, fieldPos, bytes) => { - const vtable = val0 - readInt32(val0, bytes); - return fieldPos < readInt16(vtable, bytes) ? readInt16(vtable + fieldPos, bytes) : 0; -}; - -const __vector_length = (offset, bytes) => { - return readInt32(offset + readInt32(offset, bytes), bytes); -}; - -const __indirect = (offset, bytes) => { - return offset + readInt32(offset, bytes); -}; - -const __vector = (offset, bytes) => { - return offset + readInt32(offset, bytes) + 4; -}; - -const findVector = (val0, fieldPos, bytes, size) => { - const offset = __offset(val0, fieldPos, bytes); - const offsetLong = offset + val0; - const vecStart = __vector(offsetLong, bytes); - const vecLength = __vector_length(offsetLong, bytes) * (size ? size : 1); - return offset ? bytes.slice(vecStart, vecStart + vecLength) : 0; -}; - -const findParam = (val0, fieldPos, bytes, numBytes) => { - const offset = __offset(val0, fieldPos, bytes); - return offset ? bytes.slice(offset + val0, offset + val0 + numBytes) : 0; -}; - -const findObjectStartPosition = (val0, fieldPos, bytes) => { - const offset = __offset(val0, fieldPos, bytes); - return __indirect(offset + val0, bytes); -}; - -const findArrayLength = (val0, fieldPos, bytes) => { - const offset = __offset(val0, fieldPos, bytes); - return offset ? __vector_length(val0 + offset, bytes) : 0; -}; - -const findObjectArrayElementStartPosition = (val0, fieldPos, bytes, index) => { - const offset = __offset(val0, fieldPos, bytes); - const vector = __vector(val0 + offset, bytes); - return __indirect(vector + index * 4, bytes); -}; - -/** - * Schema - * @module schema/Schema - */ -export class Schema { - schemaDefinition; - /** - * @constructor - * @param {Array.} schemaDefinition Schema Definition - */ - constructor(schemaDefinition) { - this.schemaDefinition = schemaDefinition; - } - - /** - * - * @param {Uint8Array} bytes flatbuffers bytes - * @returns {Uint8Array} catapult buffer - */ - serialize(bytes) { - let i = 0; - let resultBytes = []; - while (i < this.schemaDefinition.length) { - resultBytes = resultBytes.concat(this.schemaDefinition[i].serialize(bytes, 4 + (i * 2))); - i++; - } - return resultBytes; - } - - /** - * @param {Uint8Array} bytes flatbuffer bytes - * @returns {Array} Array with field name + payload - */ - debugSerialize(bytes) { - let i = 0; - let result: any = []; - while (i < this.schemaDefinition.length) { - result = result.concat({ - name: this.schemaDefinition[i].name, - bytes: this.schemaDefinition[i].debugSerialize(bytes, 4 + i * 2), - }); - i++; - } - return result; - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Attribute { - name: any; - /** - * @constructor - * @param {string} name schema attribute name - */ - constructor(name) { - this.name = name; - } - - /** - * - * @param {Uint8Array} buffer flatbuffer bytes - * @param {number} position attribute possition in flatbuffer bytes - * @param {number} val0 position in case that it is an inner object - */ - serialize(buffer, position, val0 = undefined) { - throw new Error('Unimplemented method'); - } - - /** - * @suppress warnings - * @param {Uint8Array} buffer buffer flatbuffer bytes - * @param {number} position attribute possition in flatbuffer bytes - * @param {number} val0 position in case that it is an inner object - */ - debugSerialize(buffer, position, val0 = undefined) { - throw new Error('Unimplemented method'); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class ScalarAttribute extends Attribute { - typeSize: any; - name: any; - /** - * @constructor - * @param {string} name schema attribute name - * @param {number} typeSize - */ - constructor(name, typeSize) { - super(name); - this.typeSize = typeSize; - } - - serialize(buffer, position, val0 = undefined) { - return findParam(val0 ? val0 : buffer[0], position, buffer, this.typeSize); - } - - debugSerialize(buffer, position, val0 = undefined) { - return { - name: this.name, - bytes: this.serialize(buffer, position, val0), - }; - } -} - -// tslint:disable-next-line:max-classes-per-file -export class ArrayAttribute extends Attribute { - typeSize: any; - name: any; - /** - * @constructor - * @param name - {string} - * @param typeSize - {TypeSize} - */ - constructor(name, typeSize) { - super(name); - this.typeSize = typeSize; - } - - serialize(buffer, position, val0 = undefined) { - return findVector(val0 ? val0 : buffer[0], position, buffer, this.typeSize); - } - - debugSerialize(buffer, position, val0 = undefined) { - return { - name: this.name, - bytes: this.serialize(buffer, position, val0), - }; - } -} - -// tslint:disable-next-line:max-classes-per-file -export class TableAttribute extends Attribute { - schema: any; - name: any; - /** - * - * @param {string} name - * @param {module:schema/Schema} schema - */ - constructor(name, schema) { - super(name); - this.schema = schema; - } - - serialize(bytes, position, val0 = undefined) { - let result = []; - const messageStartPosition = findObjectStartPosition(val0 ? val0 : bytes[0], position, bytes); - let i = 0; - while (i < this.schema.length) { - result = result.concat(this.schema[i].serialize(bytes, 4 + i * 2, messageStartPosition)); - i++; - } - return result; - } - - debugSerialize(buffer, position, val0 = undefined) { - return { - name: this.name, - bytes: this.serialize(buffer, position, val0), - }; - } -} - -// tslint:disable-next-line:max-classes-per-file -export class TableArrayAttribute extends Attribute { - schema: any; - name: any; - /** - * @constructor - * @param {string} name - * @param {module:schema/Schema} schema - */ - constructor(name, schema) { - super(name); - this.schema = schema; - } - - serialize(bytes, position, val0 = undefined) { - let result = []; - const arrayLength = findArrayLength(val0 ? val0 : bytes[0], position, bytes); - let i = 0; - while (i < arrayLength) { - const startArrayPosition = findObjectArrayElementStartPosition(val0 ? val0 : bytes[0], position, bytes, i); - for (let j = 0; j < this.schema.length; ++j) { - result = result.concat(this.schema[j].serialize(bytes, 4 + j * 2, startArrayPosition)); - } - i++; - } - return result; - } - - debugSerialize(buffer, position, val0 = undefined) { - return { - name: this.name, - bytes: this.serialize(buffer, position, val0), - }; - } -} diff --git a/src/infrastructure/schemas/SecretLockTransactionSchema.ts b/src/infrastructure/schemas/SecretLockTransactionSchema.ts deleted file mode 100644 index 046f02c178..0000000000 --- a/src/infrastructure/schemas/SecretLockTransactionSchema.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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/SecretLockTransactionSchema - */ - -/** - * Secret lock transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('mosaicId', TypeSize.INT), - array('mosaicAmount', TypeSize.INT), - array('duration', TypeSize.INT), - ubyte('hashAlgorithm'), - array('secret'), - array('recipient') -]); -export default schema; diff --git a/src/infrastructure/schemas/SecretProofTransactionSchema.ts b/src/infrastructure/schemas/SecretProofTransactionSchema.ts deleted file mode 100644 index db03f6eaf4..0000000000 --- a/src/infrastructure/schemas/SecretProofTransactionSchema.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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/SecretProofTransactionSchema - */ - -/** - * Secret proof transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - ubyte('hashAlgorithm'), - array('secret'), - array('recipient'), - ushort('proofSize'), - array('proof') -]); -export default schema; diff --git a/src/infrastructure/schemas/TransferTransactionSchema.ts b/src/infrastructure/schemas/TransferTransactionSchema.ts deleted file mode 100644 index eb8efdfd4e..0000000000 --- a/src/infrastructure/schemas/TransferTransactionSchema.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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, - table, - tableArray, - TypeSize, - ubyte, - uint, - ushort -} from './Schema'; - -/** - * @module schema/TransferTransactionSchema - */ - -/** - * Transfer transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('recipient'), - ushort('messageSize'), - ubyte('numMosaics'), - table('message', [ - ubyte('type'), - array('payload') - ]), - tableArray('mosaics', [ - array('id', TypeSize.INT), - array('amount', TypeSize.INT) - ]) -]); -export default schema; diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index b1198243fd..6491749d4c 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -190,27 +190,21 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N case TransactionType.MOSAIC_DEFINITION: const mosaicDefMosaicNonceLength = 8; const mosaicDefMosaicIdLength = 16; - const mosaicDefPropsNumLength = 2; const mosaicDefPropsFlagsLength = 2; const mosaicDefDivisibilityLength = 2; - const mosaicDefDurationIndLength = 2; const mosaicDefDurationLength = 16; const mosaicIdOffset = mosaicDefMosaicNonceLength; - const propsOffset = mosaicIdOffset + mosaicDefMosaicIdLength; - const flagsOffset = propsOffset + mosaicDefPropsNumLength; + const flagsOffset = mosaicIdOffset + mosaicDefMosaicIdLength; const divisibilityOffset = flagsOffset + mosaicDefPropsFlagsLength; - const durationIndOffset = divisibilityOffset + mosaicDefDivisibilityLength; - const durationOffset = durationIndOffset + mosaicDefDurationIndLength; + const durationOffset = divisibilityOffset + mosaicDefDivisibilityLength; // read bytes const mosaicNonce = transactionData.substring(0, mosaicDefMosaicNonceLength); - const mosaicId = transactionData.substring(mosaicIdOffset, propsOffset); - const props = transactionData.substring(propsOffset, flagsOffset); + const mosaicId = transactionData.substring(mosaicIdOffset, flagsOffset); const flags = parseInt(convert.uint8ToHex(convert.hexToUint8( transactionData.substring(flagsOffset, divisibilityOffset)).reverse()), 16); - const divisibility = transactionData.substring(divisibilityOffset, durationIndOffset); - const durationInd = transactionData.substring(durationIndOffset, durationOffset); + const divisibility = transactionData.substring(divisibilityOffset, durationOffset); const duration = transactionData.substring(durationOffset); const regexArray = mosaicNonce.match(/.{1,2}/g); diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index fd4200205c..150cd213b6 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -15,13 +15,10 @@ */ import { Convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; @@ -106,20 +103,6 @@ export class AccountAddressRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRestrictionType(this.restrictionType) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index bd0a0303db..58584444b2 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountLinkTransaction'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/AccountLinkTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder'; @@ -105,20 +103,6 @@ export class AccountLinkTransaction extends Transaction { return byteSize + bytePublicKey + byteLinkAction; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRemoteAccountKey(this.remoteAccountKey) - .addLinkAction(this.linkAction) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index efe54c41d8..be182d398b 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -105,20 +103,6 @@ export class AccountMosaicRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRestrictionType(this.restrictionType) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index b42d33e3ab..3ee53a4b4d 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -104,20 +102,6 @@ export class AccountOperationRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRestrictionType(this.restrictionType) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 98a416a6d3..1ad4e6b61f 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AddressAliasTransaction'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; import { AddressDto } from '../../infrastructure/catbuffer/AddressDto'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -121,21 +119,6 @@ export class AddressAliasTransaction extends Transaction { return byteSize + byteActionType + byteNamespaceId + byteAddress; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addAliasAction(this.aliasAction) - .addNamespaceId(this.namespaceId.id.toDTO()) - .addAddress(this.address.plain()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 797eb757e5..608559f663 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -14,10 +14,8 @@ * limitations under the License. */ -import { SignSchema } from '../../core/crypto'; +import { KeyPair, SignSchema } from '../../core/crypto'; import { Convert } from '../../core/format'; -import { AggregateTransaction as AggregatedTransactionCore} from '../../infrastructure/builders/AggregateTransaction'; -import { Builder } from '../../infrastructure/builders/AggregateTransaction'; import { AggregateTransactionBuilder } from '../../infrastructure/catbuffer/AggregateTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { CosignatureBuilder } from '../../infrastructure/catbuffer/CosignatureBuilder'; @@ -31,6 +29,7 @@ import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AggregateTransactionCosignature } from './AggregateTransactionCosignature'; import { CosignatureSignedTransaction } from './CosignatureSignedTransaction'; +import { CosignatureTransaction } from './CosignatureTransaction'; import { Deadline } from './Deadline'; import { InnerTransaction } from './InnerTransaction'; import { SignedTransaction } from './SignedTransaction'; @@ -123,21 +122,6 @@ export class AggregateTransaction extends Transaction { ); } - /** - * @internal - * @returns {AggregateTransaction} - */ - public buildTransaction(): AggregatedTransactionCore { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addType(this.type) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addTransactions(this.innerTransactions.map((transaction) => { - return transaction.aggregateTransaction(); - })).build(); - } - /** * @internal * Sign transaction with cosignatories creating a new SignedTransaction @@ -150,11 +134,23 @@ export class AggregateTransaction extends Transaction { public signTransactionWithCosignatories(initiatorAccount: Account, cosignatories: Account[], generationHash: string, - signSchema: SignSchema = SignSchema.SHA3) { - const aggregateTransaction = this.buildTransaction(); - const signedTransactionRaw = aggregateTransaction - .signTransactionWithCosigners(initiatorAccount, cosignatories, generationHash, signSchema); - return new SignedTransaction(signedTransactionRaw.payload, signedTransactionRaw.hash, initiatorAccount.publicKey, + signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { + const signedTransaction = this.signWith(initiatorAccount, generationHash, signSchema); + const transactionHashBytes = Convert.hexToUint8(signedTransaction.hash); + let signedPayload = signedTransaction.payload; + cosignatories.forEach((cosigner) => { + const signature = KeyPair.sign(cosigner, transactionHashBytes, signSchema); + signedPayload += cosigner.publicKey + Convert.uint8ToHex(signature); + }); + + // Calculate new size + const size = `00000000${(signedPayload.length / 2).toString(16)}`; + const formatedSize = size.substr(size.length - 8, size.length); + const littleEndianSize = formatedSize.substr(6, 2) + formatedSize.substr(4, 2) + + formatedSize.substr(2, 2) + formatedSize.substr(0, 2); + + signedPayload = littleEndianSize + signedPayload.substr(8, signedPayload.length - 8); + return new SignedTransaction(signedPayload, signedTransaction.hash, initiatorAccount.publicKey, this.type, this.networkType); } @@ -171,13 +167,21 @@ export class AggregateTransaction extends Transaction { public signTransactionGivenSignatures(initiatorAccount: Account, cosignatureSignedTransactions: CosignatureSignedTransaction[], generationHash: string, - signSchema: SignSchema= SignSchema.SHA3) { - const aggregateTransaction = this.buildTransaction(); - const signedTransactionRaw = aggregateTransaction.signTransactionGivenSignatures(initiatorAccount, - cosignatureSignedTransactions, - generationHash, - signSchema); - return new SignedTransaction(signedTransactionRaw.payload, signedTransactionRaw.hash, initiatorAccount.publicKey, + signSchema: SignSchema= SignSchema.SHA3): SignedTransaction { + const signedTransaction = this.signWith(initiatorAccount, generationHash, signSchema); + let signedPayload = signedTransaction.payload; + cosignatureSignedTransactions.forEach((cosignedTransaction) => { + signedPayload += cosignedTransaction.signer + cosignedTransaction.signature; + }); + + // Calculate new size + const size = `00000000${(signedPayload.length / 2).toString(16)}`; + const formatedSize = size.substr(size.length - 8, size.length); + const littleEndianSize = formatedSize.substr(6, 2) + formatedSize.substr(4, 2) + + formatedSize.substr(2, 2) + formatedSize.substr(0, 2); + + signedPayload = littleEndianSize + signedPayload.substr(8, signedPayload.length - 8); + return new SignedTransaction(signedPayload, signedTransaction.hash, initiatorAccount.publicKey, this.type, this.networkType); } @@ -237,9 +241,6 @@ export class AggregateTransaction extends Transaction { transactions = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); }); - console.log('cosignatures', Convert.uint8ToHex(cosignatures)); - console.log('transactions', Convert.uint8ToHex(transactions)); - const transactionBuilder = new AggregateTransactionBuilder( new SignatureDto(signatureBuffer), new KeyDto(signerBuffer), diff --git a/src/model/transaction/CosignatureTransaction.ts b/src/model/transaction/CosignatureTransaction.ts index d1b6ddc5b5..62e4a248ed 100644 --- a/src/model/transaction/CosignatureTransaction.ts +++ b/src/model/transaction/CosignatureTransaction.ts @@ -14,13 +14,12 @@ * limitations under the License. */ -import { SignSchema } from '../../core/crypto'; +import { KeyPair, SignSchema } from '../../core/crypto'; import { Convert } from '../../core/format/Convert'; -import {CosignatureTransaction as CosignaturetransactionLibrary} from '../../infrastructure/builders/CosignatureTransaction'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import {Account} from '../account/Account'; import {AggregateTransaction} from './AggregateTransaction'; import {CosignatureSignedTransaction} from './CosignatureSignedTransaction'; +import { Transaction } from './Transaction'; /** * Cosignature transaction is used to sign an aggregate transactions with missing cosignatures. @@ -41,9 +40,9 @@ export class CosignatureTransaction { * @param transactionToCosign - Transaction to cosign. * @returns {CosignatureTransaction} */ - public static create(transactionToCosign: AggregateTransaction) { + public static create(transactionToCosign: AggregateTransaction): CosignatureTransaction { if (transactionToCosign.isUnannounced()) { - throw new Error('transaction to cosign should be announced first'); + throw new Error('Transaction to cosign should be announced first'); } return new CosignatureTransaction(transactionToCosign); } @@ -64,12 +63,14 @@ export class CosignatureTransaction { /** * For aggregated complete transaction, cosignatories are gathered off chain announced. */ - const transactionHash = VerifiableTransaction.createTransactionHash(payload, Array.from(Convert.hexToUint8(generationHash))); - const aggregateSignatureTransaction = new CosignaturetransactionLibrary(transactionHash); - const signedTransactionRaw = aggregateSignatureTransaction.signCosignatoriesTransaction(account, signSchema); - return new CosignatureSignedTransaction(signedTransactionRaw.parentHash, - signedTransactionRaw.signature, - signedTransactionRaw.signer); + const transactionHash = Transaction.createTransactionHash(payload, Array.from(Convert.hexToUint8(generationHash))); + const hashBytes = Convert.hexToUint8(transactionHash); + const signature = KeyPair.sign(account, new Uint8Array(hashBytes), signSchema); + return new CosignatureSignedTransaction( + Convert.uint8ToHex(hashBytes), + Convert.uint8ToHex(signature), + account.publicKey, + ); } /** @@ -80,10 +81,16 @@ export class CosignatureTransaction { * @returns {CosignatureSignedTransaction} */ public signWith(account: Account, signSchema: SignSchema = SignSchema.SHA3): CosignatureSignedTransaction { - const aggregateSignatureTransaction = new CosignaturetransactionLibrary(this.transactionToCosign.transactionInfo!.hash); - const signedTransactionRaw = aggregateSignatureTransaction.signCosignatoriesTransaction(account, signSchema); - return new CosignatureSignedTransaction(signedTransactionRaw.parentHash, - signedTransactionRaw.signature, - signedTransactionRaw.signer); + if (!this.transactionToCosign.transactionInfo!.hash) { + throw new Error('Transaction to cosign should be announced first'); + } + const hash = this.transactionToCosign.transactionInfo!.hash; + const hashBytes = Convert.hexToUint8(hash ? hash : ''); + const signature = KeyPair.sign(account, new Uint8Array(hashBytes), signSchema); + return new CosignatureSignedTransaction( + hash ? hash : '', + Convert.uint8ToHex(signature), + account.publicKey, + ); } } diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index e34bb40489..b36810cf05 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/HashLockTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedHashLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder'; @@ -131,23 +129,6 @@ export class LockFundsTransaction extends Transaction { return byteSize + byteMosaicId + byteAmount + byteDuration + byteHash; } - /** - * @internal - * @return {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addType(this.type) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaic.id.id.toDTO()) - .addMosaicAmount(this.mosaic.amount.toDTO()) - .addDuration(this.duration.toDTO()) - .addHash(this.hash) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index fa1e35dfef..6fb31645ba 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -15,10 +15,9 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MultisigModificationTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { CosignatoryModificationBuilder } from '../../infrastructure/catbuffer/CosignatoryModificationBuilder'; +import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { MultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -32,7 +31,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; /** * Modify multisig account transactions are part of the NEM's multisig account system. @@ -125,21 +123,6 @@ export class ModifyMultisigAccountTransaction extends Transaction { return byteSize + byteRemovalDelta + byteApprovalDelta + byteNumModifications + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMinApprovalDelta(this.minApprovalDelta) - .addMinRemovalDelta(this.minRemovalDelta) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index 819d69c43c..f366fc0aed 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MosaicAddressRestrictionTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -142,23 +140,6 @@ export class MosaicAddressRestrictionTransaction extends Transaction { byteTargetAddress + bytePreviousRestrictionValue + byteNewRestrictionValue; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaicId.id.toDTO()) - .addRestrictionKey(this.restrictionKey.toDTO()) - .addTargetAddress(this.targetAddress.plain()) - .addPreviousRestrictionValue(this.previousRestrictionValue.toDTO()) - .addNewRestrictionValue(this.newRestrictionValue.toDTO()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index f822b73505..acffa89de0 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MosaicAliasTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; @@ -117,21 +115,6 @@ export class MosaicAliasTransaction extends Transaction { return byteSize + byteType + byteNamespaceId + byteMosaicId; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addAliasAction(this.aliasAction) - .addNamespaceId(this.namespaceId.id.toDTO()) - .addMosaicId(this.mosaicId.id.toDTO()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index c0adbd1e8b..9ebbf03fe6 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MosaicCreationTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedMosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder'; @@ -158,35 +156,6 @@ export class MosaicDefinitionTransaction extends Transaction { return GeneratorUtils.readUint32At(this.nonce.toDTO(), 0); } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - let mosaicDefinitionTransaction = new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addDivisibility(this.mosaicProperties.divisibility) - .addDuration(this.mosaicProperties.duration ? this.mosaicProperties.duration.toDTO() : []) - .addNonce(this.nonce.toDTO()) - .addMosaicId(this.mosaicId.id.toDTO()); - - if (this.mosaicProperties.supplyMutable === true) { - mosaicDefinitionTransaction = mosaicDefinitionTransaction.addSupplyMutable(); - } - - if (this.mosaicProperties.transferable === true) { - mosaicDefinitionTransaction = mosaicDefinitionTransaction.addTransferability(); - } - - if (this.mosaicProperties.restrictable === true) { - mosaicDefinitionTransaction = mosaicDefinitionTransaction.addRestrictable(); - } - - return mosaicDefinitionTransaction.build(); - } - /** * @internal * @returns {Uint8Array} @@ -207,7 +176,7 @@ export class MosaicDefinitionTransaction extends Transaction { this.getMosaicFlagValue(), this.mosaicProperties.divisibility, new BlockDurationDto(this.mosaicProperties.duration ? - this.mosaicProperties.duration.toDTO() : []), + this.mosaicProperties.duration.toDTO() : UInt64.fromUint(0).toDTO()), ); return transactionBuilder.serialize(); } @@ -226,7 +195,7 @@ export class MosaicDefinitionTransaction extends Transaction { this.getMosaicFlagValue(), this.mosaicProperties.divisibility, new BlockDurationDto(this.mosaicProperties.duration ? - this.mosaicProperties.duration.toDTO() : []), + this.mosaicProperties.duration.toDTO() : UInt64.fromUint(0).toDTO()), ); return transactionBuilder.serialize(); } diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index 7b4f757efc..9081fa5dbc 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MosaicGlobalRestrictionTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicGlobalRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -162,25 +160,6 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { bytePreviousRestrictionType; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaicId.id.toDTO()) - .addReferenceMosaicId(this.referenceMosaicId.id.toDTO()) - .addRestrictionKey(this.restrictionKey.toDTO()) - .addPreviousRestrictionValue(this.previousRestrictionValue.toDTO()) - .addPreviousRestrictionType(this.previousRestrictionType) - .addNewRestrictionValue(this.newRestrictionValue.toDTO()) - .addNewRestrictionType(this.newRestrictionType) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index be4f3a89a3..03f0137241 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { Builder } from '../../infrastructure/builders/MosaicSupplyChangeTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -33,7 +32,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { Convert } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -118,21 +116,6 @@ export class MosaicSupplyChangeTransaction extends Transaction { return byteSize + byteMosaicId + byteDirection + byteDelta; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaicId.id.toDTO()) - .addDirection(this.direction) - .addDelta(this.delta.toDTO()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index 0cdcae2aa6..3089126e25 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert, Convert as convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/NamespaceCreationTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedNamespaceRegistrationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder'; @@ -168,28 +166,6 @@ export class RegisterNamespaceTransaction extends Transaction { return byteSize + byteType + byteDurationParentId + byteNamespaceId + byteNameSize + byteName; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - let registerNamespacetransaction = new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addNamespaceType(this.namespaceType) - .addNamespaceId(this.namespaceId.id.toDTO()) - .addNamespaceName(this.namespaceName); - - if (this.namespaceType === NamespaceType.RootNamespace) { - registerNamespacetransaction = registerNamespacetransaction.addDuration(this.duration!.toDTO()); - } else { - registerNamespacetransaction = registerNamespacetransaction.addParentId(this.parentId!.id.toDTO()); - } - - return registerNamespacetransaction.build(); - } - /** * @internal * @returns {Uint8Array} @@ -238,7 +214,7 @@ export class RegisterNamespaceTransaction extends Transaction { transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), - TransactionType.SECRET_LOCK.valueOf(), + TransactionType.REGISTER_NAMESPACE.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), new BlockDurationDto(this.duration!.toDTO()), @@ -248,7 +224,7 @@ export class RegisterNamespaceTransaction extends Transaction { transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), - TransactionType.SECRET_LOCK.valueOf(), + TransactionType.REGISTER_NAMESPACE.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), undefined, diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index e65187384d..5efbe3c3fe 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -14,8 +14,6 @@ * limitations under the License. */ import { Convert as convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/SecretLockTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedSecretLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder'; @@ -155,25 +153,6 @@ export class SecretLockTransaction extends Transaction { return convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addType(this.type) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaic.id.id.toDTO()) - .addMosaicAmount(this.mosaic.amount.toDTO()) - .addDuration(this.duration.toDTO()) - .addHashAlgorithm(this.hashType) - .addSecret(this.secret) - .addRecipient(this.recipient.plain()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index 41df6b207b..cbca7576b2 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert, Convert as convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/SecretProofTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedSecretProofTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; @@ -140,23 +138,6 @@ export class SecretProofTransaction extends Transaction { return convert.hexToUint8(this.proof); } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addType(this.type) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addHashAlgorithm(this.hashType) - .addSecret(this.secret) - .addRecipient(this.recipient.plain()) - .addProof(this.proof) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index ca2fbbce44..29d3ae1b3d 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -16,7 +16,6 @@ import { KeyPair, SHA3Hasher, SignSchema } from '../../core/crypto'; import { Convert } from '../../core/format'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { SerializeTransactionToJSON } from '../../infrastructure/transaction/SerializeTransactionToJSON'; import { Account } from '../account/Account'; import { PublicAccount } from '../account/PublicAccount'; @@ -81,9 +80,27 @@ export abstract class Transaction { } /** - * @internal + * Generate transaction hash hex + * @param {string} transactionPayload HexString Payload + * @param {Array} generationHashBuffer Network generation hash byte + * @returns {string} Returns Transaction Payload hash */ - protected abstract buildTransaction(): VerifiableTransaction; + public static createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { + const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); + const signingBytes = byteBuffer + .slice(4, 36) + .concat(byteBuffer + .slice(4 + 64, 4 + 64 + 32)) + .concat(generationHashBuffer) + .concat(byteBuffer + .splice(4 + 64 + 32, byteBuffer.length)); + + const hash = new Uint8Array(32); + + SHA3Hasher.func(hash, signingBytes, 32); + + return Convert.uint8ToHex(hash); + } /** * @internal @@ -104,25 +121,6 @@ export abstract class Transaction { * @returns {SignedTransaction} */ public signWith(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { - const transaction = this.buildTransaction(); - const signedTransactionRaw = transaction.signTransaction(account, generationHash, signSchema); - return new SignedTransaction( - signedTransactionRaw.payload, - signedTransactionRaw.hash, - account.publicKey, - this.type, - this.networkType); - } - - /** - * @internal - * Serialize and sign transaction creating a new SignedTransaction - * @param account - The account to sign the transaction - * @param generationHash - Network generation hash hex - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {SignedTransaction} - */ - public signWithCatbuffer(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { const generationHashBytes = Array.from(Convert.hexToUint8(generationHash)); const byteBuffer = Array.from(this.generateBytes()); const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); @@ -137,41 +135,28 @@ export abstract class Transaction { const payload = Convert.uint8ToHex(signedTransactionBuffer); return new SignedTransaction( payload, - this.createTransactionHash(payload, generationHashBytes), + Transaction.createTransactionHash(payload, generationHashBytes), account.publicKey, this.type, this.networkType); } /** - * Generate transaction hash hex - * @param {string} transactionPayload HexString Payload - * @param {Array} generationHashBuffer Network generation hash byte - * @returns {string} Returns Transaction Payload hash - */ - public createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { - const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); - const signingBytes = byteBuffer - .slice(4, 36) - .concat(byteBuffer - .slice(4 + 64, 4 + 64 + 32)) - .concat(generationHashBuffer) - .concat(byteBuffer - .splice(4 + 64 + 32, byteBuffer.length)); - - const hash = new Uint8Array(32); - - SHA3Hasher.func(hash, signingBytes, 32); - - return Convert.uint8ToHex(hash); - } - - /** - * @internal - * @returns {Array} + * Converts the transaction into AggregateTransaction compatible + * @returns {Array.<*>} AggregateTransaction bytes */ public aggregateTransaction(): number[] { - return this.buildTransaction().toAggregateTransaction(this.signer!.publicKey); + const signer = Convert.hexToUint8(this.signer!.publicKey); + let resultBytes = Array.from(this.generateBytes()); + resultBytes.splice(0, 4 + 64 + 32); + resultBytes = Array.from(signer).concat(resultBytes); + resultBytes.splice(32 + 2 + 2, 16); + return Array.from((new Uint8Array([ + (resultBytes.length + 4 & 0x000000ff), + (resultBytes.length + 4 & 0x0000ff00) >> 8, + (resultBytes.length + 4 & 0x00ff0000) >> 16, + (resultBytes.length + 4 & 0xff000000) >> 24, + ]))).concat(resultBytes); } /** @@ -278,9 +263,8 @@ export abstract class Transaction { * @returns {string} * @memberof Transaction */ - public serialize() { - const transaction = this.buildTransaction(); - return transaction.serializeUnsignedTransaction(); + public serialize(): string { + return Convert.uint8ToHex(this.generateBytes()); } /** diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 6714fd7904..c78253b040 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -16,8 +16,6 @@ import { Convert, Convert as convert } from '../../core/format'; import { RawAddress } from '../../core/format/RawAddress'; -import { Builder } from '../../infrastructure/builders/TransferTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedTransferTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedTransferTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; @@ -145,6 +143,22 @@ export class TransferTransaction extends Transaction { return GeneratorUtils.concatTypedArrays(typeBuffer, payloadBuffer); } + /** + * Return unresolved address bytes of the recipient + * @internal + * @returns {string} + */ + public getRecipientBytes(): Uint8Array { + const recipient = this.recipientToString(); + if (/^[0-9a-fA-F]{16}$/.test(recipient)) { + // received hexadecimal notation of namespaceId (alias) + return RawAddress.aliasToRecipient(convert.hexToUint8(recipient)); + } else { + // received recipient address + return RawAddress.stringToAddress(recipient); + } + } + /** * @override Transaction.size() * @description get the byte size of a TransferTransaction @@ -167,21 +181,6 @@ export class TransferTransaction extends Transaction { return byteSize + byteRecipient + byteNumMosaics + bytePayload + byteMosaics; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRecipient(this.recipientToString()) - .addMosaics(this.mosaics.map((mosaic) => mosaic.toDTO())) - .addMessage(this.message) - .build(); - } - /** * @internal * @returns {Uint8Array} @@ -197,7 +196,7 @@ export class TransferTransaction extends Transaction { TransactionType.TRANSFER.valueOf(), new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), - new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), + new UnresolvedAddressDto(this.getRecipientBytes()), this.getMessageBuffer(), this.sortMosaics().map((mosaic) => { return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index 0d5b8c8b25..68c65c8eae 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountLinkTransaction', () => { expect(accountLinkTransaction.linkAction).to.be.equal(0); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); - const signedTransaction = accountLinkTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = accountLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 36dd3232a1..6291870102 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -162,7 +162,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = addressRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -204,7 +204,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = mosaicRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -246,7 +246,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = operationRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index 2721b583d9..59b1ce1144 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -80,12 +80,12 @@ describe('AddressAliasTransaction', () => { expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = addressAliasTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = addressAliasTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('002AD8FC018D9A49E19050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + )).to.be.equal('012AD8FC018D9A49E19050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); }); diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index d6a4c714aa..9334b7a15a 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -106,7 +106,7 @@ describe('AggregateTransaction', () => { NetworkType.MIJIN_TEST, []); - const signedTransaction = aggregateTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); @@ -166,12 +166,12 @@ describe('AggregateTransaction', () => { const signedTransaction = aggregateTransaction.signWith(account, generationHash); - expect(signedTransaction.payload.substring(0, 8)).to.be.equal('BC000000'); - expect(signedTransaction.payload.substring(240, 256)).to.be.equal('4000000040000000'); + expect(signedTransaction.payload.substring(0, 8)).to.be.equal('BA000000'); + expect(signedTransaction.payload.substring(240, 256)).to.be.equal('3E0000003E000000'); expect(signedTransaction.payload.substring( 320, signedTransaction.payload.length, - )).to.be.equal('01904D41E6DE84B8010000000000000001070302E803000000000000'); + )).to.be.equal('01904D41E6DE84B801000000000000000703E803000000000000'); }); it('should createComplete an AggregateTransaction object with MosaicSupplyChangeTransaction', () => { diff --git a/test/model/transaction/LockFundsTransaction.spec.ts b/test/model/transaction/LockFundsTransaction.spec.ts index df3583f1d7..779e6166d7 100644 --- a/test/model/transaction/LockFundsTransaction.spec.ts +++ b/test/model/transaction/LockFundsTransaction.spec.ts @@ -118,7 +118,7 @@ describe('LockFundsTransaction', () => { signedTransaction, NetworkType.MIJIN_TEST, ); - const signedTx = lockFundsTransaction.signWithCatbuffer(account, generationHash); + const signedTx = lockFundsTransaction.signWith(account, generationHash); expect(signedTx.payload.substring( 136, diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index f6232022da..041a685b6b 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -110,7 +110,7 @@ describe('ModifyMultisigAccountTransaction', () => { expect(modifyMultisigAccountTransaction.modifications[1].cosignatoryPublicAccount.publicKey) .to.be.equal('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); - const signedTransaction = modifyMultisigAccountTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts index 02aad2fc65..947904ce56 100644 --- a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts @@ -47,7 +47,7 @@ describe('MosaicAddressRestrictionTransaction', () => { expect(mosaicAddressRestrictionTransaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(8).toHex()); expect(mosaicAddressRestrictionTransaction.targetAddress.plain()).to.be.equal(account.address.plain()); - const signedTransaction = mosaicAddressRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicAddressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index a9314a0c54..34184eff95 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -80,12 +80,12 @@ describe('MosaicAliasTransaction', () => { expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); expect(mosaicAliasTransaction.mosaicId.id.higher).to.be.equal(3405110546); - const signedTransaction = mosaicAliasTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('002AD8FC018D9A49E14CCCD78612DDF5CA'); + )).to.be.equal('012AD8FC018D9A49E14CCCD78612DDF5CA'); }); diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index 688506516b..f444278cbe 100644 --- a/test/model/transaction/MosaicDefinitionTransaction.spec.ts +++ b/test/model/transaction/MosaicDefinitionTransaction.spec.ts @@ -64,7 +64,7 @@ describe('MosaicDefinitionTransaction', () => { duration: UInt64.fromUint(1000), }), NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(mosaicDefinitionTransaction.maxFee.higher).to.be.equal(0); @@ -93,7 +93,7 @@ describe('MosaicDefinitionTransaction', () => { expect(mosaicDefinitionTransaction.mosaicProperties.transferable).to.be.equal(true); expect(mosaicDefinitionTransaction.mosaicProperties.restrictable).to.be.equal(true); - const signedTransaction = mosaicDefinitionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -129,7 +129,7 @@ describe('MosaicDefinitionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('E6DE84B8010000000000000001000302E803000000000000'); + )).to.be.equal('E6DE84B801000000000000000003E803000000000000'); }); @@ -175,7 +175,7 @@ describe('MosaicDefinitionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('E6DE84B80100000000000000000003'); + )).to.be.equal('E6DE84B8010000000000000000030000000000000000'); }); }); diff --git a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts index 9e436d2fea..39c409bd22 100644 --- a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts @@ -54,7 +54,7 @@ describe('MosaicGlobalRestrictionTransaction', () => { expect(mosaicGlobalRestrictionTransaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.EQ); expect(mosaicGlobalRestrictionTransaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); - const signedTransaction = mosaicGlobalRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/RegisterNamespaceTransaction.spec.ts b/test/model/transaction/RegisterNamespaceTransaction.spec.ts index db497c73b9..dcd12d95f7 100644 --- a/test/model/transaction/RegisterNamespaceTransaction.spec.ts +++ b/test/model/transaction/RegisterNamespaceTransaction.spec.ts @@ -66,7 +66,7 @@ describe('RegisterNamespaceTransaction', () => { expect(registerNamespaceTransaction.duration!.lower).to.be.equal(1000); expect(registerNamespaceTransaction.duration!.higher).to.be.equal(0); - const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -83,7 +83,7 @@ describe('RegisterNamespaceTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/SecretLockTransaction.spec.ts b/test/model/transaction/SecretLockTransaction.spec.ts index 9f240dda47..9b5a00780d 100644 --- a/test/model/transaction/SecretLockTransaction.spec.ts +++ b/test/model/transaction/SecretLockTransaction.spec.ts @@ -101,7 +101,7 @@ describe('SecretLockTransaction', () => { recipient, NetworkType.MIJIN_TEST, ); - const signedTx = secretLockTransaction.signWithCatbuffer(account, generationHash); + const signedTx = secretLockTransaction.signWith(account, generationHash); expect(signedTx.payload.substring( 240, signedTx.payload.length, diff --git a/test/model/transaction/SecretProofTransaction.spec.ts b/test/model/transaction/SecretProofTransaction.spec.ts index 8712f1ca9e..951b1ab8f0 100644 --- a/test/model/transaction/SecretProofTransaction.spec.ts +++ b/test/model/transaction/SecretProofTransaction.spec.ts @@ -203,7 +203,7 @@ describe('SecretProofTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTx = secretProofTransaction.signWithCatbuffer(account, generationHash); + const signedTx = secretProofTransaction.signWith(account, generationHash); expect(signedTx.payload.substring( 240, signedTx.payload.length, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index 6f53048623..d0baad099a 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -15,7 +15,6 @@ */ import { expect } from 'chai'; -import { VerifiableTransaction } from '../../../src/infrastructure/builders/VerifiableTransaction'; import { Account } from '../../../src/model/account/Account'; import { Address } from '../../../src/model/account/Address'; import { NetworkType } from '../../../src/model/blockchain/NetworkType'; @@ -235,10 +234,6 @@ class FakeTransaction extends Transaction { throw new Error('Method not implemented.'); } - protected buildTransaction(): VerifiableTransaction { - throw new Error('Method not implemented.'); - } - protected generateBytes(): Uint8Array { throw new Error('Not implemented'); } diff --git a/test/model/transaction/TransferTransaction.spec.ts b/test/model/transaction/TransferTransaction.spec.ts index 63d8bb880c..969bf81a1b 100644 --- a/test/model/transaction/TransferTransaction.spec.ts +++ b/test/model/transaction/TransferTransaction.spec.ts @@ -210,7 +210,7 @@ describe('TransferTransaction', () => { expect(transferTransaction.recipient).to.be.instanceof(Address); expect((transferTransaction.recipient as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = transferTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = transferTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, From 0cc91f403fd2ef9ba95d472b515a5bd727fb8482 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 12:15:35 +0100 Subject: [PATCH 17/98] updated action types value --- src/model/account/RestrictionModificationType.ts | 4 ++-- src/model/mosaic/MosaicSupplyType.ts | 4 ++-- src/model/namespace/AliasAction.ts | 6 +++--- src/model/transaction/LinkAction.ts | 4 ++-- .../transaction/MultisigCosignatoryModificationType.ts | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/model/account/RestrictionModificationType.ts b/src/model/account/RestrictionModificationType.ts index b4aabd8151..a9aa625500 100644 --- a/src/model/account/RestrictionModificationType.ts +++ b/src/model/account/RestrictionModificationType.ts @@ -18,6 +18,6 @@ * Account restriction modification type */ export enum RestrictionModificationType { - Add = 0x00, - Remove = 0x01, + Add = 0x01, + Remove = 0x00, } diff --git a/src/model/mosaic/MosaicSupplyType.ts b/src/model/mosaic/MosaicSupplyType.ts index c5cf2655fa..0f28e995b0 100644 --- a/src/model/mosaic/MosaicSupplyType.ts +++ b/src/model/mosaic/MosaicSupplyType.ts @@ -20,6 +20,6 @@ * 1: Decrease in supply. */ export enum MosaicSupplyType { - Decrease = 0, - Increase = 1, + Decrease = 0x00, + Increase = 0x01, } diff --git a/src/model/namespace/AliasAction.ts b/src/model/namespace/AliasAction.ts index ae709efd97..b107b0d65d 100644 --- a/src/model/namespace/AliasAction.ts +++ b/src/model/namespace/AliasAction.ts @@ -19,7 +19,7 @@ * 0: Link an alias. * 1: Unlink an alias. */ -export enum AliasAction { - Link = 0, - Unlink = 1, +export enum AliasActionType { + Link = 0x01, + Unlink = 0x00, } diff --git a/src/model/transaction/LinkAction.ts b/src/model/transaction/LinkAction.ts index 678e1bb87d..212a0a9c80 100644 --- a/src/model/transaction/LinkAction.ts +++ b/src/model/transaction/LinkAction.ts @@ -15,6 +15,6 @@ */ export enum LinkAction { - Link = 0, - Unlink = 1, + Link = 0x01, + Unlink = 0x00, } diff --git a/src/model/transaction/MultisigCosignatoryModificationType.ts b/src/model/transaction/MultisigCosignatoryModificationType.ts index 7aa92781f7..2edfa42d01 100644 --- a/src/model/transaction/MultisigCosignatoryModificationType.ts +++ b/src/model/transaction/MultisigCosignatoryModificationType.ts @@ -20,6 +20,6 @@ * 1: Remove cosignatory. */ export enum MultisigCosignatoryModificationType { - Add = 0, - Remove = 1, + Add = 0x01, + Remove = 0x00, } From 1b266030da42af50f5269ad2d498df752eec9b45 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 12:16:52 +0100 Subject: [PATCH 18/98] restored network config for e2e --- e2e/conf/network.conf | 66 +++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index 79f895aecf..150443d82d 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -1,54 +1,54 @@ { - "apiUrl": "http://c2.nem.ninja:3000", - "generationHash": "57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6", + "apiUrl": "http://localhost:3000", + "generationHash": "5E34C898234E17E8553359D4DEAA123742C323F4C42758C511E6CC805934853E", "testAccount": { - "privateKey": "E1C8521608F4896CA26A0C2DE739310EA4B06861D126CF4D6922064678A1969B", - "address": "SAKT3CKHCYIG5BBOPTSY2WXSVPBSLIA67AEOX4ND", - "publicKey": "9F784BF20318AE3CA6246C0EC2207FE095FFF7A84B6787E7E3C2CE4C3B92A2EA" + "privateKey": "C422CC3C9257A1568036E1726E64EB5923C8363A13D4344F9E66CD89C8789BC7", + "address": "SAMA2UEQNAQ45DWYDNJVLPWKQJDAHFZIVLWACIGN", + "publicKey": "8A78C9E9B0E59D0F74C0D47AB29FBD523C706293A3FA9CD9FE0EEB2C10EA924A" }, "multisigAccount": { - "privateKey": "A9CEAA617D0B7D9DEBE9F96BD63CCF68A49950BB315CB9A4169FC6AAA1EC9E28", - "address": "SDWY3PYN4ZZO4S4EBEY2UPSSZUPGZH2G2LQMUSEU", - "publicKey": "8A613468924B8771779C7E4C889205A9BE6CAE0B9435B4BCC8E79A8DD8571608" + "privateKey": "F6815438AE34F95F2CF364B4679D16F3602CA2107073C0709738BAB457B09A45", + "publicKey": "FAF3F9FD3E32EB43273E5351BAE705D0179D37CBDCC4DD78A0C73232DD3EF32C", + "address": "SDC4BXKIIDBQA2CY6RPRFO3WLC5OZHLKLJJ3NFEH" }, "cosignatoryAccount": { - "privateKey": "8CBAA7491B7DC1070BECBC4F60AE55F4A272DA1DAD1D502DB016E142993817BA", - "address": "SB7Q5A3KEKFEWBPBTC6RFKU6Q2L4V7DM4ZNE4A7A", - "publicKey": "61B8EB2C02F3D3731A8EF6FE4CCD6BC84615BABA09CA3E891C0D2542096E6AD3" + "privateKey": "F48EA053D7D2B47DC518FDD69B338D34C819D9AC51E8754378F2D86FC29783C7", + "publicKey": "D9FB51DDFA64CC56D7AEBB32976DA8A3A72C8C7D02838AA1041046FA0883EBC6", + "address": "SCHNSELDJ7JN5MPHBOKHNBR2QRST4GOGEMS4XZNE" }, "cosignatory2Account": { - "privateKey": "60380027EBE63A5D60F6156F5637685172331705160783FF2F9D93C1E5A8622B", - "address": "SCM47E3JVPHOFWLSMNX3RKQQQIB3JUBR7MTX4M4P", - "publicKey": "3D9996683A0FA460D13288B846DF68A9B6C0C1F14EC2E43907DF8D84DC87B9C2" + "privateKey": "E697E9E0D849ACD3BD9379E80C4E953B23375112C28D983AF94160AD269BE327", + "publicKey": "2B4598150E66B26D991FA56FAF691C539FD1A92EBEA99E2AF91808B9C7C4316F", + "address": "SAWZITCY4TCOFBSSINFO4DQZTRBSB5W5OBSQE237" }, "cosignatory3Account": { - "privateKey": "E39CE241F730CD190658AFDB5F3896628F92D7BC35D88435D148BED88C6CC844", - "address": "SDEVG5MU4MEGJ72NSBC7PKMK7JCJKN7QB3DOVARJ", - "publicKey": "422697046582D8B8063931B7327D0C06FA454B416F6A5C000922EC5BA546F4B2" + "privateKey": "3F42F4308B3EA912A9FE482D6DD04CCFD8D37E4397BF9655AA2EF36894491CAB", + "publicKey": "26A339827614E7AEE9DB427323AA3A49A48456AA5656D9A2E1B50FF93DE90756", + "address": "SCGYYXGL3TLZBOA5TUCCQYIM6NSYSLVCBVHGYKKW" }, "cosignatory4Account": { - "privateKey": "0EA7E63C96FC580AD5EE85ED3C77A96B421F7C8BF75A83AB889313114C9082F2", - "address": "SCBNKMD23J7BO3Q42SEGP4LXGVJYSDPUESSEWGWZ", - "publicKey": "3A225A2C7C7D95279E74D420728D2DA2A176DE036B67909074AEF5F2DCFAF31C" + "privateKey": "53D6A6659A200DAF4930AD4C8A3B5B28ECAAA1F643E990C0A41C0B8EC9B3D05A", + "publicKey": "F721863CC533C3DF4429A957F822B986C81E62A91726A3E3BD0B861FA42F757D", + "address": "SD3JPQ2KXMQKLVOHJV7GTOYV73CL72ZSEOW7RIWE" }, "testAccount2": { - "privateKey": "A084418D937627BCDA19B277D8610C845124149FA18AABE96A17D56A2EA7FB8B", - "address": "SBF5HY3T7SXIBCSK4V4WNS4LS4QUMESMVNBCD2AQ", - "publicKey": "1C4B44400FDC933860B1949A5AEA756F19A36D73C4634699E49C3E7275EFA54F" + "privateKey": "F0AB1010EFEE19EE5373719881DF5123C13E643C519655F7E97347BFF77175BF", + "publicKey": "9DBF67474D6E1F8B131B4EB1F5BA0595AFFAE1123607BC1048F342193D7E669F", + "address": "SDBC4JE7GTJAKN2XJCQWWRJMYA35AFOYQBATXOUA" }, "testAccount3": { - "privateKey": "8C9E72C5D8964A19174B478B65BD4B7F2AFD8F92C05AE45B15A9EDF222EC8CA8", - "address": "SDY65GIMMOF7GZGGART66QGS6ELWDTQT55JJOF42", - "publicKey": "B8320002C5CF64D855F073F2387FB18F13E7A04FA57FC3743694B04579104F98" + "privateKey": "61C3C8F24E3708CFE17A64B66EBD29D747326DBF7962EBEE9340439725C04F11", + "publicKey": "399C1D18FDE3293DCF7BF522626266663C83453BDF7D38C9E96AFC795C07E0A2", + "address": "SC7PPZRJMEMQ7S32PURJTTNHOATDYQ4NPRFOAOUO" }, "testAccountNoBalance": { - "privateKey": "CE4E6B1113EF8999ED79A027A4F3255C367BC2E40417E27E614FB7C12E42BDFA", - "address": "SDNMDW5TXIORKRXQ7F3QORRW4KUAK4ALQ7JWX2KJ", - "publicKey": "92658FE642AEAF1B766D0F4FE4E263C3A0E069735836383D31A70E2B7801358B" + "privateKey": "6530E5ED4B6D32CB9AF2EE09D2889DC781C569B83C137854EDC7773B057074A1", + "publicKey": "559019D82C4CACAAE616A024544251D58BB4464CD36407224475A577F9649E78", + "address": "SCQP4B6BDNH5MZHTLL2ZNXIPYSLD5BU4NDXBZXNK" }, "harvestingAccount": { - "privateKey": "9999630E4AE5CA5675A703F3268084EB9A9B477A8C519D66465D5D21830E691A", - "address": "SC2PGQO5WV4QZRAQHJDNQ2Q5IFWA2D3VLFEFFZHC", - "publicKey": "74771A0B0B920D787F4F8242926C348007B23062910DE99C7E56AA79D4D7B90A" + "privateKey": "AF39DCC819388A2CE9DC0922730D7579588571A63F349A0FB1BC44807C926E53", + "publicKey": "FAEDB16763F22870B75BF934EA5F2792BDF109EC0C504718DDCBD92DF13C2628", + "address": "SCNPFCWFV2FYQVMU5HMJJTMADRZ3LRXVA76F56N2" } -} +} \ No newline at end of file From 1f6e049d7a326eae8e99fbc80c5612538fd9e280 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 12:22:36 +0100 Subject: [PATCH 19/98] Fixed unit tests after swapping action type value --- test/core/utils/TransactionMapping.spec.ts | 2 +- test/model/transaction/AccountLinkTransaction.spec.ts | 10 +++++----- .../transaction/AccountRestrictionTransaction.spec.ts | 6 +++--- test/model/transaction/AggregateTransaction.spec.ts | 4 ++-- .../ModifyMultisigAccountTransaction.spec.ts | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index ee1576a54e..9fda5bf317 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -499,7 +499,7 @@ describe('TransactionMapping - createFromPayload', () => { const signedTransaction = accountLinkTransaction.signWith(account, generationHash); const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AccountLinkTransaction; - expect(transaction.linkAction).to.be.equal(0); + expect(transaction.linkAction).to.be.equal(1); expect(transaction.remoteAccountKey).to.be.equal(account.publicKey); }); diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index 68c65c8eae..ec2fe1630d 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -48,7 +48,7 @@ describe('AccountLinkTransaction', () => { account.publicKey, LinkAction.Link, NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(accountLinkTransaction.maxFee.higher).to.be.equal(0); @@ -63,7 +63,7 @@ describe('AccountLinkTransaction', () => { NetworkType.MIJIN_TEST, ); - expect(accountLinkTransaction.linkAction).to.be.equal(0); + expect(accountLinkTransaction.linkAction).to.be.equal(1); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); const signedTransaction = accountLinkTransaction.signWith(account, generationHash); @@ -71,7 +71,7 @@ describe('AccountLinkTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE00'); + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE01'); }); it('should create an AccountLinkTransaction object with unlink action', () => { @@ -82,7 +82,7 @@ describe('AccountLinkTransaction', () => { NetworkType.MIJIN_TEST, ); - expect(accountLinkTransaction.linkAction).to.be.equal(1); + expect(accountLinkTransaction.linkAction).to.be.equal(0); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); const signedTransaction = accountLinkTransaction.signWith(account, generationHash); @@ -90,7 +90,7 @@ describe('AccountLinkTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE01'); + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE00'); }); describe('size', () => { diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 6291870102..550ee81fc1 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -167,7 +167,7 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('0101009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + )).to.be.equal('0101019050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); }); @@ -209,7 +209,7 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('0201004CCCD78612DDF5CA'); + )).to.be.equal('0201014CCCD78612DDF5CA'); }); @@ -251,7 +251,7 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('0401004E42'); + )).to.be.equal('0401014E42'); }); }); diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 9334b7a15a..072302eba9 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -232,8 +232,8 @@ describe('AggregateTransaction', () => { expect(signedTransaction.payload.substring( 320, signedTransaction.payload.length, - )).to.be.equal('0190554101020200B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC240' + - '0B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); + )).to.be.equal('0190554101020201B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC2401B1B5581FC81A69' + + '70DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); }); it('should createComplete an AggregateTransaction object with different cosignatories', () => { diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index 041a685b6b..00afd72d47 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -115,8 +115,8 @@ describe('ModifyMultisigAccountTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('01020200B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC' + - '6EC2400B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); + )).to.be.equal('01020201B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC2401B1' + + 'B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); }); From 4a270f5dc64caf5871c1c423ef7780c48dc7cfed Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 14 Aug 2019 12:02:30 +0100 Subject: [PATCH 20/98] Fixed merged conflic issues --- src/model/namespace/AliasAction.ts | 2 +- src/model/transaction/AddressAliasTransaction.ts | 4 ++-- src/model/transaction/ModifyMultisigAccountTransaction.ts | 4 ++-- src/model/transaction/MosaicAliasTransaction.ts | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/model/namespace/AliasAction.ts b/src/model/namespace/AliasAction.ts index b107b0d65d..7d81578751 100644 --- a/src/model/namespace/AliasAction.ts +++ b/src/model/namespace/AliasAction.ts @@ -19,7 +19,7 @@ * 0: Link an alias. * 1: Unlink an alias. */ -export enum AliasActionType { +export enum AliasAction { Link = 0x01, Unlink = 0x00, } diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 1ad4e6b61f..1faaeaa7dc 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -134,7 +134,7 @@ export class AddressAliasTransaction extends Transaction { TransactionType.ADDRESS_ALIAS.valueOf(), new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), - this.actionType.valueOf(), + this.aliasAction.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), new AddressDto(RawAddress.stringToAddress(this.address.plain())), ); @@ -150,7 +150,7 @@ export class AddressAliasTransaction extends Transaction { new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ADDRESS_ALIAS.valueOf(), - this.actionType.valueOf(), + this.aliasAction.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), new AddressDto(RawAddress.stringToAddress(this.address.plain())), ); diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index 6fb31645ba..835b117f13 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -142,7 +142,7 @@ export class ModifyMultisigAccountTransaction extends Transaction { this.minApprovalDelta, this.modifications.map((modification) => { return new CosignatoryModificationBuilder( - modification.type.valueOf(), + modification.modificiationType.valueOf(), new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)), ); }), @@ -163,7 +163,7 @@ export class ModifyMultisigAccountTransaction extends Transaction { this.minApprovalDelta, this.modifications.map((modification) => { return new CosignatoryModificationBuilder( - modification.type.valueOf(), + modification.modificiationType.valueOf(), new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)), ); }), diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index acffa89de0..447d5530ad 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -130,7 +130,7 @@ export class MosaicAliasTransaction extends Transaction { TransactionType.MOSAIC_ALIAS.valueOf(), new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), - this.actionType.valueOf(), + this.aliasAction.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), new MosaicIdDto(this.mosaicId.id.toDTO()), ); @@ -146,7 +146,7 @@ export class MosaicAliasTransaction extends Transaction { new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_ALIAS.valueOf(), - this.actionType.valueOf(), + this.aliasAction.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), new MosaicIdDto(this.mosaicId.id.toDTO()), ); From af4bd943171b42c635f2c2d0bad30ee53ebf972e Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 31 Jul 2019 19:33:40 +0100 Subject: [PATCH 21/98] Renamed RestrictionType to AccountRestrictionType --- e2e/infrastructure/AccountHttp.spec.ts | 6 ++-- e2e/infrastructure/TransactionHttp.spec.ts | 14 +++++----- src/core/utils/DtoMapping.ts | 14 +++++----- src/model/account/AccountRestriction.ts | 4 +-- ...ctionType.ts => AccountRestrictionType.ts} | 2 +- src/model/model.ts | 2 +- ...dressRestrictionModificationTransaction.ts | 6 ++-- ...osaicRestrictionModificationTransaction.ts | 6 ++-- ...ationRestrictionModificationTransaction.ts | 6 ++-- .../AccountRestrictionTransaction.ts | 14 +++++----- test/core/utils/TransactionMapping.spec.ts | 28 +++++++++---------- .../SerializeTransactionToJSON.spec.ts | 14 +++++----- test/model/account/AccountRestriction.spec.ts | 4 +-- .../model/account/AccountRestrictions.spec.ts | 4 +-- .../account/AccountRestrictionsInfo.spec.ts | 4 +-- .../AccountRestrictionTransaction.spec.ts | 22 +++++++-------- 16 files changed, 75 insertions(+), 75 deletions(-) rename src/model/account/{RestrictionType.ts => AccountRestrictionType.ts} (96%) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index d4f5242763..4925e44552 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -19,10 +19,10 @@ import {assert, expect} from 'chai'; import {AccountHttp} from '../../src/infrastructure/AccountHttp'; import { Listener, TransactionHttp } from '../../src/infrastructure/infrastructure'; import { Account } from '../../src/model/account/Account'; +import { AccountRestrictionType } from '../../src/model/account/AccountRestrictionType'; import {Address} from '../../src/model/account/Address'; import {PublicAccount} from '../../src/model/account/PublicAccount'; import { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../src/model/account/RestrictionType'; import {NetworkType} from '../../src/model/blockchain/NetworkType'; import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; import { AliasAction } from '../../src/model/namespace/AliasAction'; @@ -200,7 +200,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); @@ -426,7 +426,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 2ad8b0be8d..dc056d7c98 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -25,8 +25,8 @@ import { NamespaceHttp } from '../../src/infrastructure/infrastructure'; import {Listener} from '../../src/infrastructure/Listener'; import {TransactionHttp} from '../../src/infrastructure/TransactionHttp'; import {Account} from '../../src/model/account/Account'; +import { AccountRestrictionType } from '../../src/model/account/AccountRestrictionType'; import { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../src/model/account/RestrictionType'; import {NetworkType} from '../../src/model/blockchain/NetworkType'; import { Mosaic } from '../../src/model/mosaic/Mosaic'; import {MosaicId} from '../../src/model/mosaic/MosaicId'; @@ -404,7 +404,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -441,7 +441,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -479,7 +479,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockMosaic, + AccountRestrictionType.BlockMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -516,7 +516,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockMosaic, + AccountRestrictionType.BlockMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -554,7 +554,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockTransaction, + AccountRestrictionType.BlockTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -591,7 +591,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockTransaction, + AccountRestrictionType.BlockTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); diff --git a/src/core/utils/DtoMapping.ts b/src/core/utils/DtoMapping.ts index 9a0e2b77d1..2babb31068 100644 --- a/src/core/utils/DtoMapping.ts +++ b/src/core/utils/DtoMapping.ts @@ -17,8 +17,8 @@ import { AccountRestriction } from '../../model/account/AccountRestriction'; import { AccountRestrictions } from '../../model/account/AccountRestrictions'; import { AccountRestrictionsInfo } from '../../model/account/AccountRestrictionsInfo'; +import { AccountRestrictionType } from '../../model/account/AccountRestrictionType'; import { Address } from '../../model/account/Address'; -import { RestrictionType } from '../../model/account/RestrictionType'; import { MosaicId } from '../../model/mosaic/MosaicId'; export class DtoMapping { @@ -34,16 +34,16 @@ export class DtoMapping { new AccountRestrictions(Address.createFromEncoded(accountRestrictions.accountRestrictions.address), accountRestrictions.accountRestrictions.restrictions.map((prop) => { switch (prop.restrictionType) { - case RestrictionType.AllowAddress: - case RestrictionType.BlockAddress: + case AccountRestrictionType.AllowAddress: + case AccountRestrictionType.BlockAddress: return new AccountRestriction(prop.restrictionType, prop.values.map((value) => Address.createFromEncoded(value))); - case RestrictionType.AllowMosaic: - case RestrictionType.BlockMosaic: + case AccountRestrictionType.AllowMosaic: + case AccountRestrictionType.BlockMosaic: return new AccountRestriction(prop.restrictionType, prop.values.map((value) => new MosaicId(value))); - case RestrictionType.AllowTransaction: - case RestrictionType.BlockTransaction: + case AccountRestrictionType.AllowTransaction: + case AccountRestrictionType.BlockTransaction: return new AccountRestriction(prop.restrictionType, prop.values); default: throw new Error(`Invalid restriction type: ${prop.restrictionType}`); diff --git a/src/model/account/AccountRestriction.ts b/src/model/account/AccountRestriction.ts index 7eb6928f11..47bf9a345c 100644 --- a/src/model/account/AccountRestriction.ts +++ b/src/model/account/AccountRestriction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RestrictionType } from './RestrictionType'; +import { AccountRestrictionType } from './AccountRestrictionType'; /** * Account restriction structure describes restriction information. */ @@ -29,7 +29,7 @@ export class AccountRestriction { /** * Account restriction type */ - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, /** * Restriction values. */ diff --git a/src/model/account/RestrictionType.ts b/src/model/account/AccountRestrictionType.ts similarity index 96% rename from src/model/account/RestrictionType.ts rename to src/model/account/AccountRestrictionType.ts index aa7d236ed0..93b503b5af 100644 --- a/src/model/account/RestrictionType.ts +++ b/src/model/account/AccountRestrictionType.ts @@ -23,7 +23,7 @@ * 0x80 + type The restriction is interpreted as a blocking operation. */ -export enum RestrictionType { +export enum AccountRestrictionType { AllowAddress = 0x01, AllowMosaic = 0x02, AllowTransaction = 0x04, diff --git a/src/model/model.ts b/src/model/model.ts index ec948eca39..2c0c7a755b 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -28,7 +28,7 @@ export * from './account/AccountRestrictions'; export * from './account/AccountRestrictionsInfo'; export * from './account/AccountRestriction'; export * from './account/RestrictionModificationType'; -export * from './account/RestrictionType'; +export * from './account/AccountRestrictionType'; export * from './account/AccountNames'; // Blockchain diff --git a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts b/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts index 3a9d99f813..822bc9d284 100644 --- a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts @@ -16,8 +16,8 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { PublicAccount } from '../account/PublicAccount'; -import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; @@ -39,7 +39,7 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio * @returns {AccountAddressRestrictionModificationTransaction} */ public static create(deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountAddressRestrictionModificationTransaction { @@ -66,7 +66,7 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, diff --git a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts b/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts index 3a32656795..9de6449f61 100644 --- a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts @@ -16,8 +16,8 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { PublicAccount } from '../account/PublicAccount'; -import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; @@ -39,7 +39,7 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction * @returns {AccountAddressRestrictionModificationTransaction} */ public static create(deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountMosaicRestrictionModificationTransaction { @@ -66,7 +66,7 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, diff --git a/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts b/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts index 38160cc79d..45788393e3 100644 --- a/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts @@ -16,8 +16,8 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { PublicAccount } from '../account/PublicAccount'; -import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; @@ -39,7 +39,7 @@ export class AccountOperationRestrictionModificationTransaction extends Transact * @returns {AccountOperationRestrictionModificationTransaction} */ public static create(deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountOperationRestrictionModificationTransaction { @@ -66,7 +66,7 @@ export class AccountOperationRestrictionModificationTransaction extends Transact version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, diff --git a/src/model/transaction/AccountRestrictionTransaction.ts b/src/model/transaction/AccountRestrictionTransaction.ts index 7e0f26c313..2bb4aceaf4 100644 --- a/src/model/transaction/AccountRestrictionTransaction.ts +++ b/src/model/transaction/AccountRestrictionTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RestrictionType } from '../account/RestrictionType'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountAddressRestrictionModificationTransaction } from './AccountAddressRestrictionModificationTransaction'; @@ -36,12 +36,12 @@ export class AccountRestrictionTransaction { */ public static createAddressRestrictionModificationTransaction( deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountAddressRestrictionModificationTransaction { - if (![RestrictionType.AllowAddress, RestrictionType.BlockAddress].includes(restrictionType)) { + if (![AccountRestrictionType.AllowAddress, AccountRestrictionType.BlockAddress].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountAddressRestrictionModificationTransaction.create( @@ -64,12 +64,12 @@ export class AccountRestrictionTransaction { */ public static createMosaicRestrictionModificationTransaction( deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountMosaicRestrictionModificationTransaction { - if (![RestrictionType.AllowMosaic, RestrictionType.BlockMosaic].includes(restrictionType)) { + if (![AccountRestrictionType.AllowMosaic, AccountRestrictionType.BlockMosaic].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountMosaicRestrictionModificationTransaction.create( @@ -92,12 +92,12 @@ export class AccountRestrictionTransaction { */ public static createOperationRestrictionModificationTransaction( deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountOperationRestrictionModificationTransaction { - if (![RestrictionType.AllowTransaction, RestrictionType.BlockTransaction].includes(restrictionType)) { + if (![AccountRestrictionType.AllowTransaction, AccountRestrictionType.BlockTransaction].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountOperationRestrictionModificationTransaction.create( diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index b3653114f1..11f1b23e3c 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -20,10 +20,10 @@ import { sha3_256 } from 'js-sha3'; import {Convert as convert} from '../../../src/core/format'; import { TransactionMapping } from '../../../src/core/utils/TransactionMapping'; import { Account } from '../../../src/model/account/Account'; +import { AccountRestrictionType } from '../../../src/model/account/AccountRestrictionType'; import { Address } from '../../../src/model/account/Address'; import { PublicAccount } from '../../../src/model/account/PublicAccount'; import { RestrictionModificationType } from '../../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../../src/model/account/RestrictionType'; import { NetworkType } from '../../../src/model/blockchain/NetworkType'; import { EncryptedMessage } from '../../../src/model/model'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; @@ -35,7 +35,7 @@ import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrency import { AliasAction } from '../../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { NamespaceType } from '../../../src/model/namespace/NamespaceType'; -import { AccountAddressRestrictionModificationTransaction } from '../../../src/model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionModificationTransaction } from'../../../src/model/transaction/AccountAddressRestrictionModificationTransaction'; import { AccountLinkTransaction } from '../../../src/model/transaction/AccountLinkTransaction'; import { AccountMosaicRestrictionModificationTransaction } from '../../../src/model/transaction/AccountMosaicRestrictionModificationTransaction'; import { AccountRestrictionModification } from '../../../src/model/transaction/AccountRestrictionModification'; @@ -79,7 +79,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -89,7 +89,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); }); @@ -102,7 +102,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -111,7 +111,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowMosaic); expect(transaction.modifications[0].value[0]).to.be.equal(2262289484); expect(transaction.modifications[0].value[1]).to.be.equal(3405110546); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); @@ -125,7 +125,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -134,7 +134,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction); expect(transaction.modifications[0].value).to.be.equal(operation); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -666,7 +666,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -675,7 +675,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(addressRestrictionTransaction.toJSON()) as AccountAddressRestrictionModificationTransaction; expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -687,7 +687,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -696,7 +696,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(mosaicRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC); - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowMosaic); expect(transaction.modifications.length).to.be.equal(1); }); @@ -708,7 +708,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -717,7 +717,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(operationRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction); expect(transaction.modifications.length).to.be.equal(1); }); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 2f3ce56962..2fe89a589a 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -18,10 +18,10 @@ import { expect } from 'chai'; import { sha3_256 } from 'js-sha3'; import {Convert as convert} from '../../src/core/format'; import { Account } from '../../src/model/account/Account'; +import { AccountRestrictionType } from '../../src/model/account/AccountRestrictionType'; import { Address } from '../../src/model/account/Address'; import { PublicAccount } from '../../src/model/account/PublicAccount'; import { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../src/model/account/RestrictionType'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; @@ -83,7 +83,7 @@ describe('SerializeTransactionToJSON', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -91,7 +91,7 @@ describe('SerializeTransactionToJSON', () => { const json = addressRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS); - expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -103,7 +103,7 @@ describe('SerializeTransactionToJSON', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -111,7 +111,7 @@ describe('SerializeTransactionToJSON', () => { const json = mosaicRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC); - expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowMosaic); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -123,7 +123,7 @@ describe('SerializeTransactionToJSON', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -131,7 +131,7 @@ describe('SerializeTransactionToJSON', () => { const json = operationRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); - expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction); expect(json.transaction.modifications.length).to.be.equal(1); }); diff --git a/test/model/account/AccountRestriction.spec.ts b/test/model/account/AccountRestriction.spec.ts index 5bc3e189b6..d41a0e73a6 100644 --- a/test/model/account/AccountRestriction.spec.ts +++ b/test/model/account/AccountRestriction.spec.ts @@ -17,13 +17,13 @@ import {deepEqual} from 'assert'; import {expect} from 'chai'; import { AccountRestriction } from '../../../src/model/account/AccountRestriction'; +import { AccountRestrictionType } from '../../../src/model/account/AccountRestrictionType'; import { Address } from '../../../src/model/account/Address'; -import { RestrictionType } from '../../../src/model/account/RestrictionType'; describe('AccountRestriction', () => { it('should createComplete an AccountRestriction object', () => { const accountRestrictionDTO = { - restrictionType: RestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowAddress, values: ['906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'], }; diff --git a/test/model/account/AccountRestrictions.spec.ts b/test/model/account/AccountRestrictions.spec.ts index 1ad76d7daa..8b30a7451b 100644 --- a/test/model/account/AccountRestrictions.spec.ts +++ b/test/model/account/AccountRestrictions.spec.ts @@ -17,7 +17,7 @@ import {deepEqual} from 'assert'; import {expect} from 'chai'; import {Address} from '../../../src/model/account/Address'; -import { AccountRestrictions, RestrictionModificationType, RestrictionType, AccountRestriction } from '../../../src/model/model'; +import { AccountRestriction, AccountRestrictions, AccountRestrictionType, RestrictionModificationType } from '../../../src/model/model'; describe('AccountRestrictions', () => { @@ -25,7 +25,7 @@ describe('AccountRestrictions', () => { const accountRestrictionsDTO = { address: Address.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'), restrictions: [{ - restrictionType: RestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/account/AccountRestrictionsInfo.spec.ts b/test/model/account/AccountRestrictionsInfo.spec.ts index 01ac4771f9..981817bcea 100644 --- a/test/model/account/AccountRestrictionsInfo.spec.ts +++ b/test/model/account/AccountRestrictionsInfo.spec.ts @@ -18,9 +18,9 @@ import {deepEqual} from 'assert'; import { AccountRestriction } from '../../../src/model/account/AccountRestriction'; import { AccountRestrictions } from '../../../src/model/account/AccountRestrictions'; import { AccountRestrictionsInfo } from '../../../src/model/account/AccountRestrictionsInfo'; +import { AccountRestrictionType } from '../../../src/model/account/AccountRestrictionType'; import {Address} from '../../../src/model/account/Address'; import { RestrictionModificationType } from '../../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../../src/model/account/RestrictionType'; describe('AccountRestrictionsInfo', () => { @@ -31,7 +31,7 @@ describe('AccountRestrictionsInfo', () => { accountRestrictions: { address: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', restrictions: [{ - restrictionType: RestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 04ef489a07..8f83e951f3 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -16,9 +16,9 @@ import {expect} from 'chai'; import {Account} from '../../../src/model/account/Account'; +import { AccountRestrictionType } from '../../../src/model/account/AccountRestrictionType'; import {Address} from '../../../src/model/account/Address'; import { RestrictionModificationType } from '../../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../../src/model/account/RestrictionType'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {MosaicId} from '../../../src/model/mosaic/MosaicId'; import { AccountRestrictionModification } from '../../../src/model/transaction/AccountRestrictionModification'; @@ -74,7 +74,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -90,7 +90,7 @@ describe('AccountRestrictionTransaction', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -105,7 +105,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -121,7 +121,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -138,7 +138,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -157,7 +157,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -182,7 +182,7 @@ describe('AccountRestrictionTransaction', () => { expect(() => { AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.Sentinel, + AccountRestrictionType.Sentinel, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -199,7 +199,7 @@ describe('AccountRestrictionTransaction', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -224,7 +224,7 @@ describe('AccountRestrictionTransaction', () => { expect(() => { AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.Sentinel, + AccountRestrictionType.Sentinel, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -241,7 +241,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); From e339f331f4c9124ae00aac4def9c5ea916121eb1 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 2 Aug 2019 10:15:35 +0100 Subject: [PATCH 22/98] Refactored AccountRestrictionType --- e2e/infrastructure/AccountHttp.spec.ts | 4 +- e2e/infrastructure/TransactionHttp.spec.ts | 8 +- src/core/utils/DtoMapping.ts | 12 ++- src/model/account/AccountRestrictionType.ts | 89 ++++++++++++++++--- .../AccountRestrictionTransaction.ts | 12 ++- test/core/utils/TransactionMapping.spec.ts | 16 ++-- .../SerializeTransactionToJSON.spec.ts | 8 +- test/model/account/AccountRestriction.spec.ts | 2 +- .../model/account/AccountRestrictions.spec.ts | 2 +- .../account/AccountRestrictionsInfo.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 12 +-- 11 files changed, 120 insertions(+), 47 deletions(-) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 4925e44552..c190d8c0ae 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -200,7 +200,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); @@ -426,7 +426,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index dc056d7c98..60ec20592d 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -404,7 +404,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -441,7 +441,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -554,7 +554,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockTransaction, + AccountRestrictionType.BlockIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -591,7 +591,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockTransaction, + AccountRestrictionType.BlockIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); diff --git a/src/core/utils/DtoMapping.ts b/src/core/utils/DtoMapping.ts index 2babb31068..7670b1815e 100644 --- a/src/core/utils/DtoMapping.ts +++ b/src/core/utils/DtoMapping.ts @@ -34,16 +34,20 @@ export class DtoMapping { new AccountRestrictions(Address.createFromEncoded(accountRestrictions.accountRestrictions.address), accountRestrictions.accountRestrictions.restrictions.map((prop) => { switch (prop.restrictionType) { - case AccountRestrictionType.AllowAddress: - case AccountRestrictionType.BlockAddress: + case AccountRestrictionType.AllowIncomingAddress: + case AccountRestrictionType.BlockIncomingAddress: + case AccountRestrictionType.AllowOutgoingAddress: + case AccountRestrictionType.BlockOutgoingAddress: return new AccountRestriction(prop.restrictionType, prop.values.map((value) => Address.createFromEncoded(value))); case AccountRestrictionType.AllowMosaic: case AccountRestrictionType.BlockMosaic: return new AccountRestriction(prop.restrictionType, prop.values.map((value) => new MosaicId(value))); - case AccountRestrictionType.AllowTransaction: - case AccountRestrictionType.BlockTransaction: + case AccountRestrictionType.AllowIncomingTransactionType: + case AccountRestrictionType.AllowOutgoingTransactionType: + case AccountRestrictionType.BlockIncomingTransactionType: + case AccountRestrictionType.BlockOutgoingTransactionType: return new AccountRestriction(prop.restrictionType, prop.values); default: throw new Error(`Invalid restriction type: ${prop.restrictionType}`); diff --git a/src/model/account/AccountRestrictionType.ts b/src/model/account/AccountRestrictionType.ts index 93b503b5af..757c1fde75 100644 --- a/src/model/account/AccountRestrictionType.ts +++ b/src/model/account/AccountRestrictionType.ts @@ -1,7 +1,7 @@ /* * Copyright 2019 NEM * - * Licensed under the Apache License, Version 2.0 (the "License"); + * 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 * @@ -16,19 +16,82 @@ /** * Account restriction type - * 0x01 The restriction type is an address. - * 0x02 The restriction type is mosaic id. - * 0x03 The restriction type is a transaction type. - * 0x04 restriction type sentinel. - * 0x80 + type The restriction is interpreted as a blocking operation. + * 0x01 Account restriction type is an address. + * 0x02 Account restriction type is a mosaic id. + * 0x04 Account restriction type is a transaction type. + * 0x05 restriction type sentinel. + * 0x40 Account restriction is interpreted as outgoing restriction. + * 0x80 Account restriction is interpreted as blocking operation. */ -export enum AccountRestrictionType { - AllowAddress = 0x01, - AllowMosaic = 0x02, - AllowTransaction = 0x04, + // !!This enum will be deprecated once catbuffer code applied. +enum AccountRestrictionTypeEnum { + Address = 0x01, + Mosaic = 0x02, + TransactionType = 0x04, Sentinel = 0x05, - BlockAddress = (0x80 + 0x01), - BlockMosaic = (0x80 + 0x02), - BlockTransaction = (0x80 + 0x04), + Outgoing = 0x40, + Block = 0x80, +} + +export enum AccountRestrictionType { + /** + * Allow only incoming transactions from a given address. + */ + AllowIncomingAddress = AccountRestrictionTypeEnum.Address, + + /** + * Allow only incoming transactions containing a a given mosaic identifier. + */ + AllowMosaic = AccountRestrictionTypeEnum.Mosaic, + + /** + * Allow only outgoing transactions with a given transaction type. + */ + AllowIncomingTransactionType = AccountRestrictionTypeEnum.TransactionType, + + /** + * Allow only outgoing transactions to a given address. + */ + AllowOutgoingAddress = (AccountRestrictionTypeEnum.Address + AccountRestrictionTypeEnum.Outgoing), + + /** + * Allow only outgoing transactions with a given transaction type. + */ + AllowOutgoingTransactionType = (AccountRestrictionTypeEnum.TransactionType + + AccountRestrictionTypeEnum.Outgoing), + + /** + * Block incoming transactions from a given address. + */ + BlockIncomingAddress = (AccountRestrictionTypeEnum.Address + AccountRestrictionTypeEnum.Block), + + /** + * Block incoming transactions containing a given mosaic identifier. + */ + BlockMosaic = (AccountRestrictionTypeEnum.Mosaic + AccountRestrictionTypeEnum.Block), + + /** + * Block incoming transactions with a given transaction type. + */ + BlockIncomingTransactionType = (AccountRestrictionTypeEnum.TransactionType + + AccountRestrictionTypeEnum.Block), + + /** + * Block outgoing transactions from a given address. + */ + BlockOutgoingAddress = (AccountRestrictionTypeEnum.Address + + AccountRestrictionTypeEnum.Block + + AccountRestrictionTypeEnum.Outgoing), + /** + * Block outgoing transactions with a given transaction type. + */ + BlockOutgoingTransactionType = (AccountRestrictionTypeEnum.TransactionType + + AccountRestrictionTypeEnum.Block + + AccountRestrictionTypeEnum.Outgoing), + + /** + * Account restriction sentinel. + */ + Sentinel = AccountRestrictionTypeEnum.Sentinel, } diff --git a/src/model/transaction/AccountRestrictionTransaction.ts b/src/model/transaction/AccountRestrictionTransaction.ts index 2bb4aceaf4..1ebbbf7849 100644 --- a/src/model/transaction/AccountRestrictionTransaction.ts +++ b/src/model/transaction/AccountRestrictionTransaction.ts @@ -41,7 +41,10 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountAddressRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowAddress, AccountRestrictionType.BlockAddress].includes(restrictionType)) { + if (![AccountRestrictionType.AllowIncomingAddress, + AccountRestrictionType.AllowOutgoingAddress, + AccountRestrictionType.BlockOutgoingAddress, + AccountRestrictionType.BlockIncomingAddress].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountAddressRestrictionModificationTransaction.create( @@ -69,7 +72,7 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountMosaicRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowMosaic, AccountRestrictionType.BlockMosaic].includes(restrictionType)) { + if (![AccountRestrictionType.AllowMosaic,AccountRestrictionType.BlockMosaic].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountMosaicRestrictionModificationTransaction.create( @@ -97,7 +100,10 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountOperationRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowTransaction, AccountRestrictionType.BlockTransaction].includes(restrictionType)) { + if (![AccountRestrictionType.AllowIncomingTransactionType, + AccountRestrictionType.AllowOutgoingTransactionType, + AccountRestrictionType.BlockOutgoingTransactionType, + AccountRestrictionType.BlockOutgoingTransactionType].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountOperationRestrictionModificationTransaction.create( diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index 11f1b23e3c..29d45b2c40 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -79,7 +79,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -89,7 +89,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); }); @@ -125,7 +125,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -134,7 +134,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType); expect(transaction.modifications[0].value).to.be.equal(operation); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -666,7 +666,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -675,7 +675,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(addressRestrictionTransaction.toJSON()) as AccountAddressRestrictionModificationTransaction; expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -708,7 +708,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -717,7 +717,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(operationRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); - expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType); expect(transaction.modifications.length).to.be.equal(1); }); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 2fe89a589a..1559522ba3 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -83,7 +83,7 @@ describe('SerializeTransactionToJSON', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -91,7 +91,7 @@ describe('SerializeTransactionToJSON', () => { const json = addressRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS); - expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -123,7 +123,7 @@ describe('SerializeTransactionToJSON', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -131,7 +131,7 @@ describe('SerializeTransactionToJSON', () => { const json = operationRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); - expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType); expect(json.transaction.modifications.length).to.be.equal(1); }); diff --git a/test/model/account/AccountRestriction.spec.ts b/test/model/account/AccountRestriction.spec.ts index d41a0e73a6..11defe8b1c 100644 --- a/test/model/account/AccountRestriction.spec.ts +++ b/test/model/account/AccountRestriction.spec.ts @@ -23,7 +23,7 @@ describe('AccountRestriction', () => { it('should createComplete an AccountRestriction object', () => { const accountRestrictionDTO = { - restrictionType: AccountRestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowIncomingAddress, values: ['906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'], }; diff --git a/test/model/account/AccountRestrictions.spec.ts b/test/model/account/AccountRestrictions.spec.ts index 8b30a7451b..0ed43b4f0b 100644 --- a/test/model/account/AccountRestrictions.spec.ts +++ b/test/model/account/AccountRestrictions.spec.ts @@ -25,7 +25,7 @@ describe('AccountRestrictions', () => { const accountRestrictionsDTO = { address: Address.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'), restrictions: [{ - restrictionType: AccountRestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowIncomingAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/account/AccountRestrictionsInfo.spec.ts b/test/model/account/AccountRestrictionsInfo.spec.ts index 981817bcea..f4291f2468 100644 --- a/test/model/account/AccountRestrictionsInfo.spec.ts +++ b/test/model/account/AccountRestrictionsInfo.spec.ts @@ -31,7 +31,7 @@ describe('AccountRestrictionsInfo', () => { accountRestrictions: { address: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', restrictions: [{ - restrictionType: AccountRestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowIncomingAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 8f83e951f3..59ccd31d5d 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -74,7 +74,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -105,7 +105,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -121,7 +121,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -138,7 +138,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -157,7 +157,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -241,7 +241,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); From 9db1e9064b6f0be6c0eacbe25ed990a41ae58790 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 5 Aug 2019 14:41:38 +0100 Subject: [PATCH 23/98] Updated tests --- e2e/infrastructure/TransactionHttp.spec.ts | 161 ++++++++++++++++- .../AccountRestrictionTransaction.spec.ts | 162 +++++++++++++++--- 2 files changed, 299 insertions(+), 24 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 60ec20592d..5e22d114e3 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -387,7 +387,83 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Address', () => { + describe('AccountRestrictionTransaction - Outgoing Address', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + + it('standalone', (done) => { + const addressRestrictionFilter = AccountRestrictionModification.createForAddress( + RestrictionModificationType.Add, + account3.address, + ); + const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingAddress, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + const signedTransaction = addressModification.signWith(account, generationHash); + + listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionModificationTransaction) => { + expect(transaction.modifications, 'Modifications').not.to.be.undefined; + expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; + expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; + expect(transaction.restrictionType, 'RestrictionType').not.to.be.undefined; + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + describe('AccountRestrictionTransaction - Outgoing Address', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('aggregate', (done) => { + const addressRestrictionFilter = AccountRestrictionModification.createForAddress( + RestrictionModificationType.Remove, + account3.address, + ); + const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingAddress, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [addressModification.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + listener.confirmed(account.address).subscribe((transaction: Transaction) => { + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + + describe('AccountRestrictionTransaction - Incoming Address', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -425,7 +501,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Address', () => { + describe('AccountRestrictionTransaction - Incoming Address', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -537,7 +613,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Operation', () => { + describe('AccountRestrictionTransaction - Incoming Operation', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -575,7 +651,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Operation', () => { + describe('AccountRestrictionTransaction - Incoming Operation', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -612,6 +688,83 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); + + describe('AccountRestrictionTransaction - Outgoing Operation', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + + it('standalone', (done) => { + const operationRestrictionFilter = AccountRestrictionModification.createForOperation( + RestrictionModificationType.Add, + TransactionType.LINK_ACCOUNT, + ); + const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingTransactionType, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + const signedTransaction = addressModification.signWith(account3, generationHash); + + listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionModificationTransaction) => { + expect(transaction.modifications, 'Modifications').not.to.be.undefined; + expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; + expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; + expect(transaction.restrictionType, 'RestrictionType').not.to.be.undefined; + done(); + }); + listener.status(account3.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + describe('AccountRestrictionTransaction - Outgoing Operation', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('aggregate', (done) => { + const operationRestrictionFilter = AccountRestrictionModification.createForOperation( + RestrictionModificationType.Remove, + TransactionType.LINK_ACCOUNT, + ); + const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingTransactionType, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [addressModification.toAggregate(account3.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = aggregateTransaction.signWith(account3, generationHash); + listener.confirmed(account3.address).subscribe((transaction: Transaction) => { + done(); + }); + listener.status(account3.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + describe('AccountLinkTransaction', () => { let listener: Listener; before (() => { diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 59ccd31d5d..eeb10081ff 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -148,7 +148,7 @@ describe('AccountRestrictionTransaction', () => { expect(addressRestrictionTransaction.maxFee.lower).to.be.equal(1); }); - it('should create address restriction transaction', () => { + it('should create allow incmoing address restriction transaction', () => { const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); const addressRestrictionFilter = AccountRestrictionModification.createForAddress( @@ -179,15 +179,24 @@ describe('AccountRestrictionTransaction', () => { address, ); - expect(() => { - AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( - Deadline.create(), - AccountRestrictionType.Sentinel, - [addressRestrictionFilter], - NetworkType.MIJIN_TEST, - ); - }).to.throw(Error, 'Restriction type is not allowed.'); - + const invalidType = [AccountRestrictionType.AllowIncomingTransactionType, + AccountRestrictionType.AllowMosaic, + AccountRestrictionType.AllowOutgoingTransactionType, + AccountRestrictionType.BlockIncomingTransactionType, + AccountRestrictionType.BlockMosaic, + AccountRestrictionType.BlockOutgoingTransactionType, + AccountRestrictionType.Sentinel, + ]; + invalidType.forEach((type) => { + expect(() => { + AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + type, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'Restriction type is not allowed.'); + }); }); it('should create mosaic restriction transaction', () => { @@ -213,7 +222,7 @@ describe('AccountRestrictionTransaction', () => { }); - it('should throw exception when create mosaic restriction transaction with wrong type', () => { + it('should throw exception when create account mosaic restriction transaction with wrong type', () => { const mosaicId = new MosaicId([2262289484, 3405110546]); const mosaicRestrictionFilter = AccountRestrictionModification.createForMosaic( @@ -221,15 +230,26 @@ describe('AccountRestrictionTransaction', () => { mosaicId, ); - expect(() => { - AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( - Deadline.create(), - AccountRestrictionType.Sentinel, - [mosaicRestrictionFilter], - NetworkType.MIJIN_TEST, - ); - }).to.throw(Error, 'Restriction type is not allowed.'); - + const invalidType = [AccountRestrictionType.AllowIncomingTransactionType, + AccountRestrictionType.AllowIncomingAddress, + AccountRestrictionType.AllowOutgoingTransactionType, + AccountRestrictionType.BlockIncomingTransactionType, + AccountRestrictionType.AllowOutgoingAddress, + AccountRestrictionType.BlockOutgoingTransactionType, + AccountRestrictionType.BlockIncomingAddress, + AccountRestrictionType.BlockOutgoingAddress, + AccountRestrictionType.Sentinel, + ]; + invalidType.forEach((type) => { + expect(() => { + AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( + Deadline.create(), + type, + [mosaicRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'Restriction type is not allowed.'); + }); }); it('should create operation restriction transaction', () => { @@ -254,4 +274,106 @@ describe('AccountRestrictionTransaction', () => { )).to.be.equal('0401004E42'); }); + + it('should throw exception when create account operation restriction transaction with wrong type', () => { + + const operation = TransactionType.ADDRESS_ALIAS; + const operationRestrictionFilter = AccountRestrictionModification.createForOperation( + RestrictionModificationType.Add, + operation, + ); + + const invalidType = [AccountRestrictionType.AllowIncomingAddress, + AccountRestrictionType.AllowMosaic, + AccountRestrictionType.BlockMosaic, + AccountRestrictionType.AllowOutgoingAddress, + AccountRestrictionType.BlockIncomingAddress, + AccountRestrictionType.BlockOutgoingAddress, + AccountRestrictionType.Sentinel, + ]; + invalidType.forEach((type) => { + expect(() => { + AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + type, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'Restriction type is not allowed.'); + }); + }); + + it('should create outgoing address restriction transaction', () => { + + const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const addressRestrictionFilter = AccountRestrictionModification.createForAddress( + RestrictionModificationType.Add, + address, + ); + let addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.AllowOutgoingAddress, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + + let signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('4101009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + + addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingAddress, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + + signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('C101009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + + }); + + it('should create outgoing operation restriction transaction', () => { + + const operation = TransactionType.ADDRESS_ALIAS; + const operationRestrictionFilter = AccountRestrictionModification.createForOperation( + RestrictionModificationType.Add, + operation, + ); + let operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.AllowOutgoingTransactionType, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + + let signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('4401004E42'); + + operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingTransactionType, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + + signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('C401004E42'); + + }); }); From 77747865cf50f33d91caec4b839207368ea00767 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 15 Aug 2019 12:12:33 +0100 Subject: [PATCH 24/98] Refactored TransactionMapping - createTransactionFromPayload now use catbuffer --- src/core/format/Convert.ts | 18 + src/core/utils/TransactionMapping.ts | 14 +- .../catbuffer/GeneratorUtils.ts | 172 +++--- .../CreateTransactionFromPayload.ts | 498 ++---------------- .../AccountAddressRestrictionTransaction.ts | 35 +- .../transaction/AccountLinkTransaction.ts | 26 + .../AccountMosaicRestrictionTransaction.ts | 33 ++ .../AccountOperationRestrictionTransaction.ts | 32 ++ .../transaction/AddressAliasTransaction.ts | 29 +- src/model/transaction/AggregateTransaction.ts | 60 ++- src/model/transaction/LockFundsTransaction.ts | 32 ++ .../ModifyMultisigAccountTransaction.ts | 36 ++ .../MosaicAddressRestrictionTransaction.ts | 30 ++ .../transaction/MosaicAliasTransaction.ts | 27 + .../MosaicDefinitionTransaction.ts | 34 ++ .../MosaicGlobalRestrictionTransaction.ts | 32 ++ .../MosaicSupplyChangeTransaction.ts | 28 + .../RegisterNamespaceTransaction.ts | 36 ++ .../transaction/SecretLockTransaction.ts | 36 +- .../transaction/SecretProofTransaction.ts | 29 + src/model/transaction/TransferTransaction.ts | 40 ++ 21 files changed, 714 insertions(+), 563 deletions(-) diff --git a/src/core/format/Convert.ts b/src/core/format/Convert.ts index f45b7b9eac..7d9939d084 100644 --- a/src/core/format/Convert.ts +++ b/src/core/format/Convert.ts @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { decode } from 'utf8'; import * as utilities from './Utilities'; export class Convert { @@ -172,4 +173,21 @@ export class Convert { } return result; } + + /** + * @internal decode hex to uft8 string + * @param hex - Hex input + * @returns {string} + */ + public static decodeHex = (hex: string): string => { + let str = ''; + for (let i = 0; i < hex.length; i += 2) { + str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); + } + try { + return decode(str); + } catch (e) { + return str; + } + } } diff --git a/src/core/utils/TransactionMapping.ts b/src/core/utils/TransactionMapping.ts index 7c13ae044f..7c4c36a0e4 100644 --- a/src/core/utils/TransactionMapping.ts +++ b/src/core/utils/TransactionMapping.ts @@ -16,7 +16,9 @@ import { CreateTransactionFromDTO } from '../../infrastructure/transaction/CreateTransactionFromDTO'; import { CreateTransactionFromPayload } from '../../infrastructure/transaction/CreateTransactionFromPayload'; +import { InnerTransaction } from '../../model/transaction/InnerTransaction'; import { Transaction } from '../../model/transaction/Transaction'; +import { SignSchema } from '../crypto/SignSchema'; export class TransactionMapping { @@ -31,10 +33,14 @@ export class TransactionMapping { /** * Create transaction class from payload binary. - * @param {string} dataBytes The transaction json object. - * @returns {module: model/transaction/transaction} The transaction class. + * @param {string} payload The transaction binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} The transaction class. */ - public static createFromPayload(dataBytes: string): Transaction { - return CreateTransactionFromPayload(dataBytes); + public static createFromPayload(payload: string, + isEmbedded = false, + signSchema = SignSchema.SHA3): Transaction | InnerTransaction { + return CreateTransactionFromPayload(payload, isEmbedded, signSchema); } } diff --git a/src/infrastructure/catbuffer/GeneratorUtils.ts b/src/infrastructure/catbuffer/GeneratorUtils.ts index 437c32d117..7e95285569 100644 --- a/src/infrastructure/catbuffer/GeneratorUtils.ts +++ b/src/infrastructure/catbuffer/GeneratorUtils.ts @@ -1,119 +1,117 @@ // tslint:disable: jsdoc-format /** -*** Copyright (c) 2016-present, -*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. -*** -*** This file is part of Catapult. -*** -*** Catapult is free software: you can redistribute it and/or modify -*** it under the terms of the GNU Lesser General Public License as published by -*** the Free Software Foundation, either version 3 of the License, or -*** (at your option) any later version. -*** -*** Catapult is distributed in the hope that it will be useful, -*** but WITHOUT ANY WARRANTY; without even the implied warranty of -*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -*** GNU Lesser General Public License for more details. -*** -*** You should have received a copy of the GNU Lesser General Public License -*** along with Catapult. If not, see . -**/ + *** Copyright (c) 2016-present, + *** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. + *** + *** This file is part of Catapult. + *** + *** Catapult is free software: you can redistribute it and/or modify + *** it under the terms of the GNU Lesser General Public License as published by + *** the Free Software Foundation, either version 3 of the License, or + *** (at your option) any later version. + *** + *** Catapult is distributed in the hope that it will be useful, + *** but WITHOUT ANY WARRANTY; without even the implied warranty of + *** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *** GNU Lesser General Public License for more details. + *** + *** You should have received a copy of the GNU Lesser General Public License + *** along with Catapult. If not, see . + **/ /** * Generator utility class. */ export class GeneratorUtils { - /** + /** * Converts a (64bit) uint8 array into a number array. * @param {Uint8Array} input A uint8 array. * @returns {number[]} The uint64 representation of the input. */ - public static bufferToUint64 (input: Uint8Array): number[] { + public static bufferToUint64(input: Uint8Array): number[] { if (8 !== input.length) { throw Error(`byte array has unexpected size '${input.length}'`); - } - input = input.reverse(); - return [GeneratorUtils.readUint32At(input, 0), GeneratorUtils.readUint32At(input, 4)]; - } - - /** + } + input = input.reverse(); + const view = new DataView(input.buffer); + return [view.getUint32(4), view.getUint32(0)]; + } + + /** * Read buffer into 32bits integer at given index. * @param {Uint8Array} bytes A uint8 array. - * @param {number} index Index. + * @param {number} index Index. * @returns {number} 32bits integer. */ - public static readUint32At(bytes: Uint8Array, index: number): number { - return (bytes[index] + (bytes[index + 1] << 8) + (bytes[index + 2] << 16) + (bytes[index + 3] << 24)) >>> 0; - } + public static readUint32At(bytes: Uint8Array, index: number): number { + return (bytes[index] + (bytes[index + 1] << 8) + (bytes[index + 2] << 16) + (bytes[index + 3] << 24)) >>> 0; + } - /** + /** * Write uint to buffer * @param {number} uintValue A uint8 array. - * @param {number} bufferSize Buffer size. + * @param {number} bufferSize Buffer size. * @returns {Uint8Array} */ - public static uintToBuffer (uintValue: number, bufferSize: number): Uint8Array { - const buffer = new ArrayBuffer(bufferSize); - const dataView = new DataView(buffer); - if (1 === bufferSize) - dataView.setUint8(0, uintValue); - - else if (2 === bufferSize) - dataView.setUint16(0, uintValue, true); - - else if (4 === bufferSize) - dataView.setUint32(0, uintValue, true); - - else - throw new Error('Unexpected bufferSize'); - - return new Uint8Array(buffer); - } + public static uintToBuffer(uintValue: number, bufferSize: number): Uint8Array { + const buffer = new ArrayBuffer(bufferSize); + const dataView = new DataView(buffer); + if (1 === bufferSize) { + dataView.setUint8(0, uintValue); + } else if (2 === bufferSize) { + dataView.setUint16(0, uintValue, true); + } else if (4 === bufferSize) { + dataView.setUint32(0, uintValue, true); + } else { + throw new Error('Unexpected bufferSize'); + } + + return new Uint8Array(buffer); + } - /** + /** * Write uint to buffer * @param {Uint8Array} buffer A uint8 array. * @returns {number} */ - public static bufferToUint(buffer: Uint8Array): number { - const dataView = new DataView(buffer.buffer); - if (1 === buffer.byteLength) - return dataView.getUint8(0); - - else if (2 === buffer.byteLength) - return dataView.getUint16(0, true); - - else if (4 === buffer.byteLength) - return dataView.getUint32(0, true); - - throw new Error('Unexpected buffer size'); - }; + public static bufferToUint(buffer: Uint8Array): number { + const dataView = new DataView(buffer.buffer); + if (1 === buffer.byteLength) { + return dataView.getUint8(0); + } else if (2 === buffer.byteLength) { + return dataView.getUint16(0, true); + } else if (4 === buffer.byteLength) { + return dataView.getUint32(0, true); + } - /** + throw new Error('Unexpected buffer size'); + } + + /** * Write Uint64 to buffer * @param {number} uintValue Uint64 (number[]). * @returns {Uint8Array} */ - public static uint64ToBuffer(uintValue: number[]): Uint8Array { - const uint32Array = new Uint32Array(uintValue); - return new Uint8Array(uint32Array.buffer); - } + public static uint64ToBuffer(uintValue: number[]): Uint8Array { + const uint32Array = new Uint32Array(uintValue); + return new Uint8Array(uint32Array.buffer); + } - /** + /** * Concatenate two arrays * @param {Uint8Array} array1 A Uint8Array. - * @param {Uint8Array} array2 A Uint8Array. + * @param {Uint8Array} array2 A Uint8Array. * @returns {Uint8Array} */ - public static concatTypedArrays(array1: Uint8Array, array2: Uint8Array): Uint8Array { - const newArray = new Uint8Array(array1.length + array2.length); - newArray.set(array1); - newArray.set(array2, array1.length); - return newArray; - } + public static concatTypedArrays(array1: Uint8Array, array2: Uint8Array): Uint8Array { + const newArray = new Uint8Array(array1.length + array2.length); + newArray.set(array1); + newArray.set(array2, array1.length); + return newArray; + } - /** Converts an unsigned byte to a signed byte with the same binary representation. + /** Converts an unsigned byte to a signed byte with the same binary representation. * @param {number} input An unsigned byte. * @returns {number} A signed byte with the same binary representation as the input. * @@ -125,17 +123,17 @@ export class GeneratorUtils { return input << 24 >> 24; } - /** Get bytes by given sub array size. - * @param {Uint8Array} binary Binary bytes array. + /** Get bytes by given sub array size. + * @param {Uint8Array} binary Binary bytes array. * @param {number} size Subarray size. - * @returns {Uint8Array} + * @returns {Uint8Array} * */ - public static getBytes(binary: Uint8Array, size: number): Uint8Array { - if (size > binary.length) - throw new RangeError(); - - const bytes = binary.slice(0, size); - return bytes; - } + public static getBytes(binary: Uint8Array, size: number): Uint8Array { + if (size > binary.length) { + throw new RangeError(); + } + const bytes = binary.slice(0, size); + return bytes; + } } diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index 6491749d4c..3f79ea2d5e 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -14,524 +14,88 @@ * limitations under the License. */ -import {decode} from 'utf8'; +import { SignSchema } from '../../core/crypto'; import { Convert as convert } from '../../core/format'; -import { Address } from '../../model/account/Address'; -import { PublicAccount } from '../../model/account/PublicAccount'; -import { NetworkType } from '../../model/blockchain/NetworkType'; -import { Mosaic } from '../../model/mosaic/Mosaic'; -import { MosaicId } from '../../model/mosaic/MosaicId'; -import { MosaicNonce } from '../../model/mosaic/MosaicNonce'; -import { MosaicProperties } from '../../model/mosaic/MosaicProperties'; -import { NamespaceId } from '../../model/namespace/NamespaceId'; -import { NamespaceType } from '../../model/namespace/NamespaceType'; +import { InnerTransaction } from '../../model/model'; import { AccountAddressRestrictionTransaction } from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; import { AccountMosaicRestrictionTransaction } from '../../model/transaction/AccountMosaicRestrictionTransaction'; import { AccountOperationRestrictionTransaction } from '../../model/transaction/AccountOperationRestrictionTransaction'; -import { AccountRestrictionModification } from '../../model/transaction/AccountRestrictionModification'; import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction'; import { AggregateTransaction } from '../../model/transaction/AggregateTransaction'; -import { AggregateTransactionCosignature } from '../../model/transaction/AggregateTransactionCosignature'; -import { Deadline } from '../../model/transaction/Deadline'; -import { EncryptedMessage } from '../../model/transaction/EncryptedMessage'; -import { HashType } from '../../model/transaction/HashType'; import { LockFundsTransaction } from '../../model/transaction/LockFundsTransaction'; -import { Message } from '../../model/transaction/Message'; -import { MessageType } from '../../model/transaction/MessageType'; import { ModifyMultisigAccountTransaction } from '../../model/transaction/ModifyMultisigAccountTransaction'; import { MosaicAddressRestrictionTransaction } from '../../model/transaction/MosaicAddressRestrictionTransaction'; import { MosaicAliasTransaction } from '../../model/transaction/MosaicAliasTransaction'; import { MosaicDefinitionTransaction } from '../../model/transaction/MosaicDefinitionTransaction'; import { MosaicGlobalRestrictionTransaction } from '../../model/transaction/MosaicGlobalRestrictionTransaction'; import { MosaicSupplyChangeTransaction } from '../../model/transaction/MosaicSupplyChangeTransaction'; -import { MultisigCosignatoryModification } from '../../model/transaction/MultisigCosignatoryModification'; -import { PlainMessage } from '../../model/transaction/PlainMessage'; import { RegisterNamespaceTransaction } from '../../model/transaction/RegisterNamespaceTransaction'; import { SecretLockTransaction } from '../../model/transaction/SecretLockTransaction'; import { SecretProofTransaction } from '../../model/transaction/SecretProofTransaction'; -import { SignedTransaction } from '../../model/transaction/SignedTransaction'; import { Transaction } from '../../model/transaction/Transaction'; import { TransactionType } from '../../model/transaction/TransactionType'; import { TransferTransaction } from '../../model/transaction/TransferTransaction'; -import { UInt64 } from '../../model/UInt64'; +import { EmbeddedTransactionBuilder } from '../catbuffer/EmbeddedTransactionBuilder'; +import { TransactionBuilder } from '../catbuffer/TransactionBuilder'; /** * @internal - * @param transactionBinary - The transaction binary data - * @returns {Transaction} + * @param payload - The transaction binary data + * @param isEmbedded - Is the transaction an embedded inner transaction + * @param signSchema - The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} * @constructor */ -export const CreateTransactionFromPayload = (transactionBinary: string): Transaction => { - // Transaction byte size data - const sizeLength = 8; - const signatureLength = 128; - const publicKeyLength = 64; - const versionLength = 4; - const typeLength = 4; - const feeLength = 16; - const deadlineLength = 16; - - // Transaction byte data positions - const signatureOffset = sizeLength; - const publicKeyOffset = signatureOffset + signatureLength; - const versionOffset = publicKeyOffset + publicKeyLength; - const typeOffset = versionOffset + versionLength; - const feeOffset = typeOffset + typeLength; - const deadlineOffset = feeOffset + feeLength; - const transactionOffset = deadlineOffset + deadlineLength; - - // Transaction byte data - const networkType = extractNetwork(transactionBinary.substring(versionOffset, typeOffset)); - const type = extractTransactionTypeFromHex(transactionBinary.substring(typeOffset, feeOffset)); - const deadline = UInt64.fromHex(reverse(transactionBinary.substring(deadlineOffset, transactionOffset))).toDTO(); - const transactionData = transactionBinary.substring(transactionOffset); - - return CreateTransaction(type, transactionData, networkType, deadline); -}; - -/** - * @internal - * @param type - Transaction type - * @param transactionData - Details per specific transaction type - * @param networkType - Network type - * @param deadline - Deadline - * @returns {Transaction} - */ -const CreateTransaction = (type: number, transactionData: string, networkType: NetworkType, deadline: number[]): Transaction => { +export const CreateTransactionFromPayload = (payload: string, + isEmbedded = false, + signSchema = SignSchema.SHA3): Transaction | InnerTransaction => { + const transactionBuilder = isEmbedded ? EmbeddedTransactionBuilder.loadFromBinary(convert.hexToUint8(payload)) : + TransactionBuilder.loadFromBinary(convert.hexToUint8(payload)); + const type = transactionBuilder.getType().valueOf(); switch (type) { case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: case TransactionType.ACCOUNT_RESTRICTION_OPERATION: case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: - const propertyTypeLength = 2; - - const modificationCountOffset = propertyTypeLength; - const modificationArrayOffset = modificationCountOffset + propertyTypeLength; - - // read bytes - const propertyType = transactionData.substring(0, propertyTypeLength); - const modifications = transactionData.substring(modificationArrayOffset, transactionData.length); - const modificationArray = modifications.match(/.{1,52}/g); - switch (type) { case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: - const t = AccountAddressRestrictionTransaction.create( - Deadline.createFromDTO(deadline), - parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), - modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( - parseInt(convert.uint8ToHex(convert.hexToUint8(modification.substring(0, 2)).reverse()), 16), - Address.createFromEncoded(modification.substring(2, modification.length)).plain(), - )) : [], - networkType, - ); - return t; + return AccountAddressRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: - return AccountMosaicRestrictionTransaction.create( - Deadline.createFromDTO(deadline), - parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), - modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( - parseInt(convert.uint8ToHex(convert.hexToUint8(modification.substring(0, 2)).reverse()), 16), - UInt64.fromHex(reverse(modification.substring(2, modification.length))).toDTO(), - )) : [], - networkType, - ); + return AccountMosaicRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.ACCOUNT_RESTRICTION_OPERATION: - return AccountOperationRestrictionTransaction.create( - Deadline.createFromDTO(deadline), - parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), - modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( - parseInt(convert.uint8ToHex(convert.hexToUint8(modification.substring(0, 2)).reverse()), 16), - parseInt(convert.uint8ToHex(convert.hexToUint8( - modification.substring(2, modification.length)).reverse()), 16), - )) : [], - networkType, - ); + return AccountOperationRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); } throw new Error ('Account restriction transaction type not recognised.'); case TransactionType.LINK_ACCOUNT: - // read bytes - const remoteAccountKey = transactionData.substring(0, 64); - const linkAction = transactionData.substring(64, 66); - - return AccountLinkTransaction.create( - Deadline.createFromDTO(deadline), - remoteAccountKey, - parseInt(convert.uint8ToHex(convert.hexToUint8(linkAction).reverse()), 16), - networkType, - ); + return AccountLinkTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.ADDRESS_ALIAS: - // read bytes - const addressAliasAction = transactionData.substring(0, 2); - const addressAliasNamespaceId = transactionData.substring(2, 18); - const addressAliasAddress = transactionData.substring(18); - - return AddressAliasTransaction.create( - Deadline.createFromDTO(deadline), - parseInt(convert.uint8ToHex(convert.hexToUint8(addressAliasAction).reverse()), 16), - new NamespaceId(UInt64.fromHex(reverse(addressAliasNamespaceId)).toDTO()), - Address.createFromEncoded(addressAliasAddress), - networkType, - ); + return AddressAliasTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MOSAIC_ALIAS: - const mosaicAliasActionLength = 2; - - // read bytes - const mosaicAliasAction = transactionData.substring(0, mosaicAliasActionLength); - const mosaicAliasNamespaceId = transactionData.substring(mosaicAliasActionLength, 18); - const mosaicAliasMosaicId = transactionData.substring(18); - - return MosaicAliasTransaction.create( - Deadline.createFromDTO(deadline), - parseInt(convert.uint8ToHex(convert.hexToUint8(mosaicAliasAction).reverse()), 16), - new NamespaceId(UInt64.fromHex(reverse(mosaicAliasNamespaceId)).toDTO()), - new MosaicId(UInt64.fromHex(reverse(mosaicAliasMosaicId)).toDTO()), - networkType, - ); + return MosaicAliasTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MOSAIC_DEFINITION: - const mosaicDefMosaicNonceLength = 8; - const mosaicDefMosaicIdLength = 16; - const mosaicDefPropsFlagsLength = 2; - const mosaicDefDivisibilityLength = 2; - const mosaicDefDurationLength = 16; - - const mosaicIdOffset = mosaicDefMosaicNonceLength; - const flagsOffset = mosaicIdOffset + mosaicDefMosaicIdLength; - const divisibilityOffset = flagsOffset + mosaicDefPropsFlagsLength; - const durationOffset = divisibilityOffset + mosaicDefDivisibilityLength; - - // read bytes - const mosaicNonce = transactionData.substring(0, mosaicDefMosaicNonceLength); - const mosaicId = transactionData.substring(mosaicIdOffset, flagsOffset); - const flags = parseInt(convert.uint8ToHex(convert.hexToUint8( - transactionData.substring(flagsOffset, divisibilityOffset)).reverse()), 16); - const divisibility = transactionData.substring(divisibilityOffset, durationOffset); - const duration = transactionData.substring(durationOffset); - - const regexArray = mosaicNonce.match(/.{1,2}/g); - - const nonceArray = regexArray ? regexArray.map((n) => { - return parseInt(convert.uint8ToHex(convert.hexToUint8(n).reverse()), 16); - }) : []; - - return MosaicDefinitionTransaction.create( - Deadline.createFromDTO(deadline), - new MosaicNonce(new Uint8Array(nonceArray)), - new MosaicId(UInt64.fromHex(reverse(mosaicId)).toDTO()), - MosaicProperties.create({ - supplyMutable: (flags & 1) === 1, - transferable: (flags & 2) === 2, - divisibility: parseInt(convert.uint8ToHex(convert.hexToUint8(divisibility).reverse()), 16), - restrictable: (flags & 4) === 4, - duration: duration ? UInt64.fromHex(reverse(duration)) : undefined, - }), - networkType, - ); + return MosaicDefinitionTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MOSAIC_SUPPLY_CHANGE: - // read bytes - const mosaicSupMosaicId = transactionData.substring(0, 16); - const mosaicSupDirection = transactionData.substring(16, 18); - const delta = transactionData.substring(18, 34); - - return MosaicSupplyChangeTransaction.create( - Deadline.createFromDTO(deadline), - new MosaicId(UInt64.fromHex(reverse(mosaicSupMosaicId)).toDTO()), - parseInt(convert.uint8ToHex(convert.hexToUint8(mosaicSupDirection).reverse()), 16), - UInt64.fromHex(reverse(delta)), - networkType, - ); + return MosaicSupplyChangeTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.REGISTER_NAMESPACE: - // read bytes - const namespaceType = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(0, 2)).reverse()), 16); - const nameSpaceDurationParentId = transactionData.substring(2, 18); - const nameSpaceId = transactionData.substring(18, 34); - const nameSize = transactionData.substring(34, 36); - const nameSpaceName = transactionData.substring(36); - - return namespaceType === NamespaceType.RootNamespace ? - RegisterNamespaceTransaction.createRootNamespace( - Deadline.createFromDTO(deadline), - decodeHex(nameSpaceName), - UInt64.fromHex(reverse(nameSpaceDurationParentId)), - networkType, - ) : RegisterNamespaceTransaction.createSubNamespace( - Deadline.createFromDTO(deadline), - decodeHex(nameSpaceName), - new NamespaceId(UInt64.fromHex(reverse(nameSpaceDurationParentId)).toDTO()), - networkType, - ); + return RegisterNamespaceTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.TRANSFER: - // read bytes - const transferRecipient = transactionData.substring(0, 50); - const transferMessageSize = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(50, 54)).reverse()), 16); - - const transferMessageAndMosaicSubString = transactionData.substring(56); - const transferMessageType = parseInt(convert.uint8ToHex(convert.hexToUint8( - transferMessageAndMosaicSubString.substring(0, 2)).reverse()), 16); - const transferMessage = transferMessageAndMosaicSubString.substring(2, (transferMessageSize - 1) * 2 + 2); - const transferMosaic = transferMessageAndMosaicSubString.substring(transferMessageSize * 2); - const transferMosaicArray = transferMosaic.match(/.{1,32}/g); - - return TransferTransaction.create( - Deadline.createFromDTO(deadline), - Address.createFromEncoded(transferRecipient), - transferMosaicArray ? transferMosaicArray.map((mosaic) => new Mosaic( - new MosaicId(UInt64.fromHex(reverse(mosaic.substring(0, 16))).toDTO()), - UInt64.fromHex(reverse(mosaic.substring(16))), - )) : [], - extractMessage(transferMessageType, transferMessage), - networkType, - ); + return TransferTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.SECRET_LOCK: - // read bytes - const secretLockMosaic = transactionData.substring(0, 32); - const secretLockDuration = transactionData.substring(32, 48); - const secretLockHashAlgorithm = parseInt(convert.uint8ToHex(convert.hexToUint8( - transactionData.substring(48, 50)).reverse()), 16); - const secretLockSecret = transactionData.substring(50, transactionData.length - 50); - const secretLockRecipient = transactionData.substring(transactionData.length - 50); - - return SecretLockTransaction.create( - Deadline.createFromDTO(deadline), - new Mosaic( - new MosaicId(UInt64.fromHex(reverse(secretLockMosaic.substring(0, 16))).toDTO()), - UInt64.fromHex(reverse(secretLockMosaic.substring(16))), - ), - UInt64.fromHex(reverse(secretLockDuration)), - secretLockHashAlgorithm, - secretLockSecret, - Address.createFromEncoded(secretLockRecipient), - networkType, - ); + return SecretLockTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.SECRET_PROOF: - // read bytes - const secretProofHashAlgorithm = parseInt(convert.uint8ToHex(convert.hexToUint8( - transactionData.substring(0, 2)).reverse()), 16); - - const secretProofSecretLength = 64; - const secretProofSecret = transactionData.substring(2, 66); - const secretProofRecipient = transactionData.substring(66, 116); - const secretProofSize = transactionData.substring(116, 120); - const secretProofProof = transactionData.substring(120); - - return SecretProofTransaction.create( - Deadline.createFromDTO(deadline), - secretProofHashAlgorithm, - secretProofSecret, - Address.createFromEncoded(secretProofRecipient), - secretProofProof, - networkType, - ); + return SecretProofTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MODIFY_MULTISIG_ACCOUNT: - // read bytes - const minRemovalDelta = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(0, 2)).reverse()), 16); - const minApprovalDelta = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(2, 4)).reverse()), 16); - const modificationsCount = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(4, 6)).reverse()), 16); - - const multiSigModificationSubString = transactionData.substring(6); - const multiSigModificationArray = multiSigModificationSubString.match(/.{1,66}/g); - - return ModifyMultisigAccountTransaction.create( - Deadline.createFromDTO(deadline), - minApprovalDelta, - minRemovalDelta, - multiSigModificationArray ? multiSigModificationArray.map((modification) => new MultisigCosignatoryModification( - parseInt(convert.uint8ToHex(convert.hexToUint8(modification.substring(0, 2)).reverse()), 16), - PublicAccount.createFromPublicKey(modification.substring(2), networkType), - )) : [], - networkType, - ); + return ModifyMultisigAccountTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.LOCK: - // read bytes - const hashLockMosaic = transactionData.substring(0, 32); - const hashLockDuration = transactionData.substring(32, 48); - const hashLockHash = transactionData.substring(48); - - return LockFundsTransaction.create( - Deadline.createFromDTO(deadline), - new Mosaic( - new MosaicId(UInt64.fromHex(reverse(hashLockMosaic.substring(0, 16))).toDTO()), - UInt64.fromHex(reverse(hashLockMosaic.substring(16))), - ), - UInt64.fromHex(reverse(hashLockDuration)), - new SignedTransaction('', hashLockHash, '', TransactionType.AGGREGATE_BONDED, networkType), - networkType, - ); + return LockFundsTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MOSAIC_GLOBAL_RESTRICTION: - // read bytes - const globalRestrictionMosaicId = transactionData.substring(0, 16); - const globalRestrictionReferenceMosaicId = transactionData.substring(16, 32); - const globalRestrictionRestrictionKey = transactionData.substring(32, 48); - const globalRestrictionPrevValue = transactionData.substring(48, 64); - const globalRestrictionPrevType = transactionData.substring(64, 66); - const globalRestrictionNewValue = transactionData.substring(66, 82); - const globalRestrictionNewType = transactionData.substring(82, 84); - - return MosaicGlobalRestrictionTransaction.create( - Deadline.createFromDTO(deadline), - new MosaicId(UInt64.fromHex(reverse(globalRestrictionMosaicId)).toDTO()), - new MosaicId(UInt64.fromHex(reverse(globalRestrictionReferenceMosaicId)).toDTO()), - UInt64.fromHex(reverse(globalRestrictionRestrictionKey)), - UInt64.fromHex(reverse(globalRestrictionPrevValue)), - parseInt(convert.uint8ToHex(convert.hexToUint8(globalRestrictionPrevType).reverse()), 16), - UInt64.fromHex(reverse(globalRestrictionNewValue)), - parseInt(convert.uint8ToHex(convert.hexToUint8(globalRestrictionNewType).reverse()), 16), - networkType, - ); + return MosaicGlobalRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MOSAIC_ADDRESS_RESTRICTION: - // read bytes - const addressRestrictionMosaicId = transactionData.substring(0, 16); - const addressRestrictionRestrictionKey = transactionData.substring(16, 32); - const addressRestrictionTargetAddress = transactionData.substring(32, 82); - const addressRestrictionPrevValue = transactionData.substring(82, 98); - const addressRestrictionNewValue = transactionData.substring(98, 114); - - return MosaicAddressRestrictionTransaction.create( - Deadline.createFromDTO(deadline), - new MosaicId(UInt64.fromHex(reverse(addressRestrictionMosaicId)).toDTO()), - UInt64.fromHex(reverse(addressRestrictionRestrictionKey)), - Address.createFromEncoded(addressRestrictionTargetAddress), - UInt64.fromHex(reverse(addressRestrictionPrevValue)), - UInt64.fromHex(reverse(addressRestrictionNewValue)), - networkType, - ); + return MosaicAddressRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.AGGREGATE_COMPLETE: - // read bytes - const payloadSize = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(0, 8)).reverse()), 16) * 2; - const cosignatures = transactionData.substring(payloadSize + 8); - - const innerTransactionArray = parseInnerTransactionFromBinary(transactionData.substring(8, payloadSize + 8)); - const consignatureArray = cosignatures.match(/.{1,192}/g); - - return AggregateTransaction.createComplete( - Deadline.createFromDTO(deadline), - innerTransactionArray.map((innerTransaction) => { - const transaction = CreateTransaction( - extractTransactionTypeFromHex(innerTransaction.substring(68, 72)), - innerTransaction.substring(72), - networkType, - deadline, - ); - return transaction.toAggregate(PublicAccount.createFromPublicKey(innerTransaction.substring(0, 64), networkType)); - }), - networkType, - consignatureArray ? consignatureArray.map((cosignature) => new AggregateTransactionCosignature( - cosignature.substring(64, 192), - PublicAccount.createFromPublicKey(cosignature.substring(0, 64), networkType), - )) : [], - ); case TransactionType.AGGREGATE_BONDED: - const bondedPayloadSize = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(0, 8)).reverse()), 16) * 2; - const bondedCosignatures = transactionData.substring(bondedPayloadSize + 8); - - const bondedInnerTransactionArray = parseInnerTransactionFromBinary(transactionData.substring(8, bondedPayloadSize + 8)); - const bondedConsignatureArray = bondedCosignatures.match(/.{1,192}/g); - - return AggregateTransaction.createBonded( - Deadline.createFromDTO(deadline), - bondedInnerTransactionArray.map((innerTransaction) => { - const transaction = CreateTransaction( - extractTransactionTypeFromHex(innerTransaction.substring(68, 72)), - innerTransaction.substring(72), - networkType, - deadline, - ); - return transaction.toAggregate(PublicAccount.createFromPublicKey(innerTransaction.substring(0, 64), networkType)); - }), - networkType, - bondedConsignatureArray ? bondedConsignatureArray.map((cosignature) => new AggregateTransactionCosignature( - cosignature.substring(64, 192), - PublicAccount.createFromPublicKey(cosignature.substring(0, 64), networkType), - )) : [], - ); + return AggregateTransaction.createFromPayload(payload, signSchema); default: throw new Error ('Transaction type not implemented yet.'); } }; - -/** - * @internal - * @param hexValue - Transaction type in hex - * @returns {number} - */ -const extractTransactionTypeFromHex = (hexValue: string): number => { - return parseInt(convert.uint8ToHex(convert.hexToUint8(hexValue).reverse()), 16); -}; - -/** - * @internal - * @param versionHex - Transaction version in hex - * @returns {NetworkType} - */ -const extractNetwork = (versionHex: string): NetworkType => { - const networkType = convert.hexToUint8(versionHex)[1]; - if (networkType === NetworkType.MAIN_NET) { - return NetworkType.MAIN_NET; - } else if (networkType === NetworkType.TEST_NET) { - return NetworkType.TEST_NET; - } else if (networkType === NetworkType.MIJIN) { - return NetworkType.MIJIN; - } else if (networkType === NetworkType.MIJIN_TEST) { - return NetworkType.MIJIN_TEST; - } - throw new Error('Unimplemented network type'); -}; - -/** - * @internal - * @param hex - * @returns {string} - */ -const reverse = (hex: string): string => { - return convert.uint8ToHex(convert.hexToUint8(hex).reverse()); -}; - -/** - * @internal - * @param innerTransactionBinary - Inner transaction binary data - * @returns {Array} - */ -const parseInnerTransactionFromBinary = (innerTransactionBinary: string): string[] => { - const embeddedTransaction: string[] = []; - let innerBinary = innerTransactionBinary; - - while (innerBinary.length) { - const payloadSize = parseInt(convert.uint8ToHex(convert.hexToUint8(innerBinary.substring(0, 8)).reverse()), 16) * 2; - const innerTransaction = innerBinary.substring(8, payloadSize); - embeddedTransaction.push(innerTransaction); - innerBinary = innerBinary.substring(payloadSize); - } - return embeddedTransaction; -}; - -/** - * @internal - * @param hex - Hex input - * @returns {string} - */ -const decodeHex = (hex: string): string => { - let str = ''; - for (let i = 0; i < hex.length; i += 2) { - str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); - } - try { - return decode(str); - } catch (e) { - return str; - } -}; - -/** - * @internal - * @param messageType - Message Type - * @param payload - Message Payload - * @returns {Message} - */ -const extractMessage = (messageType: MessageType, payload: string): Message => { - if (messageType === MessageType.PlainMessage) { - return PlainMessage.createFromPayload(payload); - } else if (messageType === MessageType.EncryptedMessage) { - return EncryptedMessage.createFromPayload(payload); - } else { - throw new Error('Invalid message type'); - } -}; diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index 150cd213b6..417dafba7b 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -14,21 +14,24 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, RawAddress } from '../../core/format'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; +import { EmbeddedAccountAddressRestrictionTransactionBuilder }from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; +import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -82,6 +85,36 @@ export class AccountAddressRestrictionTransaction extends Transaction { networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAccountAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AccountAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AccountAddressRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as AccountAddressRestrictionTransactionBuilder).getDeadline().timestamp), + builder.getRestrictionType().valueOf(), + builder.getModifications().map((modification) => { + return AccountRestrictionModification.createForAddress( + modification.modificationAction.valueOf(), + Address.createFromEncoded(Convert.uint8ToHex(modification.value.unresolvedAddress)), + ); + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountAddressRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AccountAddressRestrictionTransaction diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index 58584444b2..f1cb351b7a 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/AccountLinkTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -26,6 +27,7 @@ import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { LinkAction } from './LinkAction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; @@ -87,6 +89,30 @@ export class AccountLinkTransaction extends Transaction { super(TransactionType.LINK_ACCOUNT, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAccountLinkTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AccountLinkTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AccountLinkTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as AccountLinkTransactionBuilder).getDeadline().timestamp), + Convert.uint8ToHex(builder.getRemoteAccountPublicKey().key), + builder.getLinkAction().valueOf(), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountLinkTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AccountLinkTransaction diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index be182d398b..ba7170a2cf 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; @@ -26,9 +27,11 @@ import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/Unresolved import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; +import { MosaicId } from '../mosaic/MosaicId'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -82,6 +85,36 @@ export class AccountMosaicRestrictionTransaction extends Transaction { networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAccountMosaicRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AccountMosaicRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AccountMosaicRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as AccountMosaicRestrictionTransactionBuilder).getDeadline().timestamp), + builder.getRestrictionType().valueOf(), + builder.getModifications().map((modification) => { + return AccountRestrictionModification.createForMosaic( + modification.modificationAction.valueOf(), + new MosaicId(modification.value.unresolvedMosaicId), + ); + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountMosaicRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AccountMosaicRestrictionTransaction diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index 3ee53a4b4d..df1aced4e7 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; @@ -28,6 +29,7 @@ import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -81,6 +83,36 @@ export class AccountOperationRestrictionTransaction extends Transaction { networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAccountOperationRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AccountOperationRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AccountOperationRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as AccountOperationRestrictionTransactionBuilder).getDeadline().timestamp), + builder.getRestrictionType().valueOf(), + builder.getModifications().map((modification) => { + return AccountRestrictionModification.createForOperation( + modification.modificationAction.valueOf(), + modification.value.valueOf(), + ); + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountOperationRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AccountOperationRestrictionTransaction diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 1faaeaa7dc..3975b926dc 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -14,12 +14,12 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, RawAddress } from '../../core/format'; import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; import { AddressDto } from '../../infrastructure/catbuffer/AddressDto'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -31,6 +31,7 @@ import { AliasAction } from '../namespace/AliasAction'; import { NamespaceId } from '../namespace/NamespaceId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -102,6 +103,32 @@ export class AddressAliasTransaction extends Transaction { super(TransactionType.ADDRESS_ALIAS, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAddressAliasTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AddressAliasTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AddressAliasTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as AddressAliasTransactionBuilder).getDeadline().timestamp), + builder.getAliasAction().valueOf(), + new NamespaceId(builder.getNamespaceId().namespaceId), + Address.createFromEncoded( + Convert.uint8ToHex(builder.getAddress().address)), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AddressAliasTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AddressAliasTransaction diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 608559f663..76eac2be1a 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -23,6 +23,7 @@ import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { CreateTransactionFromPayload } from '../../infrastructure/transaction/CreateTransactionFromPayload'; import { Account } from '../account/Account'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -122,6 +123,61 @@ export class AggregateTransaction extends Transaction { ); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {AggregateTransaction} + */ + public static createFromPayload(payload: string, signSchema: SignSchema = SignSchema.SHA3): AggregateTransaction { + const builder = AggregateTransactionBuilder + .loadFromBinary(Convert.hexToUint8(payload)); + const type = builder.getType().valueOf(); + const innerTransactionHex = Convert.uint8ToHex(builder.getTransactions()); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const consignaturesHex = Convert.uint8ToHex(builder.getCosignatures()); + + /** + * Get inner transactions array + */ + const embeddedTransactionArray: string[] = []; + let innerBinary = innerTransactionHex; + while (innerBinary.length) { + const payloadSize = parseInt(Convert.uint8ToHex(Convert.hexToUint8(innerBinary.substring(0, 8)).reverse()), 16) * 2; + const innerTransaction = innerBinary.substring(0, payloadSize); + embeddedTransactionArray.push(innerTransaction); + innerBinary = innerBinary.substring(payloadSize); + } + + /** + * Get cosignatures + */ + const consignatureArray = consignaturesHex.match(/.{1,192}/g); + const consignatures = consignatureArray ? consignatureArray.map((cosignature) => + new AggregateTransactionCosignature( + cosignature.substring(64, 192), + PublicAccount.createFromPublicKey(cosignature.substring(0, 64), networkType, signSchema), + )) : []; + + return type === TransactionType.AGGREGATE_COMPLETE ? + AggregateTransaction.createComplete( + Deadline.createFromDTO(builder.deadline.timestamp), + embeddedTransactionArray.map((transactionRaw) => { + return CreateTransactionFromPayload(transactionRaw, true, signSchema) as InnerTransaction; + }), + networkType, + consignatures, + new UInt64(builder.fee.amount), + ) : AggregateTransaction.createBonded( + Deadline.createFromDTO(builder.deadline.timestamp), + embeddedTransactionArray.map((transactionRaw) => { + return CreateTransactionFromPayload(transactionRaw, true, signSchema) as InnerTransaction; + }), + networkType, + consignatures, + new UInt64(builder.fee.amount), + ); + } /** * @internal * Sign transaction with cosignatories creating a new SignedTransaction @@ -230,7 +286,7 @@ export class AggregateTransaction extends Transaction { transactions = GeneratorUtils.concatTypedArrays(transactions, transactionByte); }); - const cosignatures = Uint8Array.from([]); + let cosignatures = Uint8Array.from([]); this.cosignatures.forEach((cosignature) => { const signerBytes = Convert.hexToUint8(cosignature.signer.publicKey); const signatureBytes = Convert.hexToUint8(cosignature.signature); @@ -238,7 +294,7 @@ export class AggregateTransaction extends Transaction { new KeyDto(signerBytes), new SignatureDto(signatureBytes), ).serialize(); - transactions = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); + cosignatures = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); }); const transactionBuilder = new AggregateTransactionBuilder( diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index b36810cf05..96088b7ec0 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; @@ -28,8 +29,10 @@ import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/Unresolved import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { Mosaic } from '../mosaic/Mosaic'; +import { MosaicId } from '../mosaic/MosaicId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { SignedTransaction } from './SignedTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; @@ -111,6 +114,35 @@ export class LockFundsTransaction extends Transaction { } } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedHashLockTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + HashLockTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = LockFundsTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as HashLockTransactionBuilder).getDeadline().timestamp), + new Mosaic( + new MosaicId(builder.getMosaic().mosaicId.unresolvedMosaicId), + new UInt64(builder.getMosaic().amount.amount), + ), + new UInt64(builder.getDuration().blockDuration), + new SignedTransaction('', Convert.uint8ToHex(builder.getHash().hash256), '', + TransactionType.AGGREGATE_BONDED, networkType), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as HashLockTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a LockFundsTransaction diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index 835b117f13..23dce96d81 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { CosignatoryModificationBuilder } from '../../infrastructure/catbuffer/CosignatoryModificationBuilder'; @@ -26,6 +27,7 @@ import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { MultisigCosignatoryModification } from './MultisigCosignatoryModification'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; @@ -101,6 +103,40 @@ export class ModifyMultisigAccountTransaction extends Transaction { super(TransactionType.MODIFY_MULTISIG_ACCOUNT, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMultisigAccountModificationTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MultisigAccountModificationTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = ModifyMultisigAccountTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as MultisigAccountModificationTransactionBuilder).getDeadline().timestamp), + builder.getMinApprovalDelta(), + builder.getMinRemovalDelta(), + builder.getModifications().map((modification) => { + return new MultisigCosignatoryModification( + modification.modificationAction.valueOf(), + PublicAccount.createFromPublicKey( + Convert.uint8ToHex(modification.cosignatoryPublicKey.key), + networkType, + ), + ); + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MultisigAccountModificationTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a ModifyMultisigAccountTransaction diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index f366fc0aed..3f1877838a 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, RawAddress } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder'; @@ -29,6 +30,7 @@ import { NetworkType } from '../blockchain/NetworkType'; import { MosaicId } from '../mosaic/MosaicId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -119,6 +121,34 @@ export class MosaicAddressRestrictionTransaction extends Transaction { super(TransactionType.MOSAIC_ADDRESS_RESTRICTION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMosaicAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MosaicAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = MosaicAddressRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as MosaicAddressRestrictionTransactionBuilder).getDeadline().timestamp), + new MosaicId(builder.getMosaicId().unresolvedMosaicId), + new UInt64(builder.getRestrictionKey()), + Address.createFromEncoded(Convert.uint8ToHex(builder.getTargetAddress().unresolvedAddress)), + new UInt64(builder.getPreviousRestrictionValue()), + new UInt64(builder.getNewRestrictionValue()), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MosaicAddressRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a MosaicDefinitionTransaction diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index 447d5530ad..6d7cae3183 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder'; @@ -31,6 +32,7 @@ import { AliasAction } from '../namespace/AliasAction'; import { NamespaceId } from '../namespace/NamespaceId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -98,6 +100,31 @@ export class MosaicAliasTransaction extends Transaction { super(TransactionType.MOSAIC_ALIAS, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMosaicAliasTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MosaicAliasTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = MosaicAliasTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as MosaicAliasTransactionBuilder).getDeadline().timestamp), + builder.getAliasAction().valueOf(), + new NamespaceId(builder.getNamespaceId().namespaceId), + new MosaicId(builder.getMosaicId().mosaicId), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MosaicAliasTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a MosaicAliasTransaction diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 9ebbf03fe6..1616044875 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; @@ -33,6 +34,7 @@ import { MosaicNonce } from '../mosaic/MosaicNonce'; import { MosaicProperties } from '../mosaic/MosaicProperties'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -104,6 +106,38 @@ export class MosaicDefinitionTransaction extends Transaction { super(TransactionType.MOSAIC_DEFINITION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMosaicDefinitionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MosaicDefinitionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = MosaicDefinitionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as MosaicDefinitionTransactionBuilder).getDeadline().timestamp), + new MosaicNonce(builder.getNonce().serialize()), + new MosaicId(builder.getId().mosaicId), + MosaicProperties.create({ + supplyMutable: (builder.getFlags() & 1) === 1, + transferable: (builder.getFlags() & 2) === 2, + divisibility: builder.getDivisibility(), + restrictable: (builder.getFlags() & 4) === 4, + duration: new UInt64(builder.getDuration().blockDuration), + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MosaicDefinitionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a MosaicDefinitionTransaction diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index 9081fa5dbc..c7e36df0d2 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicGlobalRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder'; @@ -29,6 +30,7 @@ import { MosaicId } from '../mosaic/MosaicId'; import { MosaicRestrictionType } from '../mosaic/MosaicRestrictionType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -136,6 +138,36 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { super(TransactionType.MOSAIC_GLOBAL_RESTRICTION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMosaicGlobalRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MosaicGlobalRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = MosaicGlobalRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as MosaicGlobalRestrictionTransactionBuilder).getDeadline().timestamp), + new MosaicId(builder.getMosaicId().unresolvedMosaicId), + new MosaicId(builder.getReferenceMosaicId().unresolvedMosaicId), + new UInt64(builder.getRestrictionKey()), + new UInt64(builder.getPreviousRestrictionValue()), + builder.getPreviousRestrictionType().valueOf(), + new UInt64(builder.getNewRestrictionValue()), + builder.getNewRestrictionType().valueOf(), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MosaicGlobalRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a MosaicDefinitionTransaction diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index 03f0137241..1ee6fc22d7 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder'; @@ -28,6 +29,7 @@ import { MosaicId } from '../mosaic/MosaicId'; import { MosaicSupplyType } from '../mosaic/MosaicSupplyType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -99,6 +101,32 @@ export class MosaicSupplyChangeTransaction extends Transaction { super(TransactionType.MOSAIC_SUPPLY_CHANGE, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMosaicSupplyChangeTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MosaicSupplyChangeTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = MosaicSupplyChangeTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as MosaicSupplyChangeTransactionBuilder).getDeadline().timestamp), + new MosaicId(builder.getMosaicId().unresolvedMosaicId), + builder.getAction().valueOf(), + new UInt64(builder.getDelta().amount), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MosaicSupplyChangeTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a MosaicSupplyChangeTransaction diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index 3089126e25..6c63a6c4e5 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, Convert as convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; @@ -30,6 +31,7 @@ import { NamespaceId } from '../namespace/NamespaceId'; import { NamespaceType } from '../namespace/NamespaceType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -145,6 +147,40 @@ export class RegisterNamespaceTransaction extends Transaction { super(TransactionType.REGISTER_NAMESPACE, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedNamespaceRegistrationTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + NamespaceRegistrationTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const namespaceType = builder.getRegistrationType().valueOf(); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = namespaceType === NamespaceType.RootNamespace ? + RegisterNamespaceTransaction.createRootNamespace( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as NamespaceRegistrationTransactionBuilder).getDeadline().timestamp), + Convert.decodeHex(Convert.uint8ToHex(builder.getName())), + new UInt64(builder.getDuration()!.blockDuration), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as NamespaceRegistrationTransactionBuilder).fee.amount), + ) : RegisterNamespaceTransaction.createSubNamespace( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as NamespaceRegistrationTransactionBuilder).getDeadline().timestamp), + Convert.decodeHex(Convert.uint8ToHex(builder.getName())), + new NamespaceId(builder.getParentId()!.namespaceId), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as NamespaceRegistrationTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a RegisterNamespaceTransaction diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index 5efbe3c3fe..6dd679613e 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -13,7 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Convert as convert, RawAddress } from '../../core/format'; +import { SignSchema } from '../../core/crypto/SignSchema'; +import { Convert, Convert as convert, RawAddress } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedSecretLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder'; @@ -30,9 +31,11 @@ import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { Mosaic } from '../mosaic/Mosaic'; +import { MosaicId } from '../mosaic/MosaicId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; import { HashType, HashTypeLengthValidator } from './HashType'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -122,6 +125,37 @@ export class SecretLockTransaction extends Transaction { } } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedSecretLockTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + SecretLockTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = SecretLockTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as SecretLockTransactionBuilder).getDeadline().timestamp), + new Mosaic( + new MosaicId(builder.getMosaic().mosaicId.unresolvedMosaicId), + new UInt64(builder.getMosaic().amount.amount), + ), + new UInt64(builder.getDuration().blockDuration), + builder.getHashAlgorithm().valueOf(), + Convert.uint8ToHex(builder.getSecret().hash256), + Address.createFromEncoded(Convert.uint8ToHex(builder.getRecipient().unresolvedAddress)), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as SecretLockTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a SecretLockTransaction diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index cbca7576b2..0752efa2f1 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, Convert as convert, RawAddress } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedSecretProofTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder'; @@ -30,6 +31,7 @@ import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; import { HashType, HashTypeLengthValidator } from './HashType'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -99,6 +101,33 @@ export class SecretProofTransaction extends Transaction { } } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedSecretProofTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + SecretProofTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = SecretProofTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as SecretProofTransactionBuilder).getDeadline().timestamp), + builder.getHashAlgorithm().valueOf(), + Convert.uint8ToHex(builder.getSecret().hash256), + Address.createFromEncoded(Convert.uint8ToHex(builder.getRecipient().unresolvedAddress)), + Convert.uint8ToHex(builder.getProof()), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as SecretProofTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a SecretProofTransaction diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index c78253b040..2826509990 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, Convert as convert } from '../../core/format'; import { RawAddress } from '../../core/format/RawAddress'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -31,10 +32,15 @@ import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { Mosaic } from '../mosaic/Mosaic'; +import { MosaicId } from '../mosaic/MosaicId'; import { NamespaceId } from '../namespace/NamespaceId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { EncryptedMessage } from './EncryptedMessage'; +import { InnerTransaction } from './InnerTransaction'; import { Message } from './Message'; +import { MessageType } from './MessageType'; +import { PlainMessage } from './PlainMessage'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -103,6 +109,40 @@ export class TransferTransaction extends Transaction { super(TransactionType.TRANSFER, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedTransferTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + TransferTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const messageType = builder.getMessage()[0]; + const messageHex = Convert.uint8ToHex(builder.getMessage()).substring(2); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = TransferTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as TransferTransactionBuilder).getDeadline().timestamp), + Address.createFromEncoded(Convert.uint8ToHex(builder.getRecipient().unresolvedAddress)), + builder.getMosaics().map((mosaic) => { + return new Mosaic( + new MosaicId(mosaic.mosaicId.unresolvedMosaicId), + new UInt64(mosaic.amount.amount)); + }), + messageType === MessageType.PlainMessage ? + PlainMessage.createFromPayload(messageHex) : + EncryptedMessage.createFromPayload(messageHex), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as TransferTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * Return the string notation for the set recipient * @internal From 7794317021af2278f5b5ae7dd4cfed7e2d9c67b6 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 15 Aug 2019 12:31:17 +0100 Subject: [PATCH 25/98] Removed `this.` in decodeBlock in Utilities.ts --- src/core/format/Utilities.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/format/Utilities.ts b/src/core/format/Utilities.ts index 90a2180655..332433afff 100644 --- a/src/core/format/Utilities.ts +++ b/src/core/format/Utilities.ts @@ -168,8 +168,8 @@ export const decodeChar = (c) => { }; export const decodeBlock = (input, inputOffset, output, outputOffset) => { - const bytes = new Uint8Array(this.Encoded_Block_Size); - for (let i = 0; i < this.Encoded_Block_Size; ++i) { + const bytes = new Uint8Array(Encoded_Block_Size); + for (let i = 0; i < Encoded_Block_Size; ++i) { bytes[i] = decodeChar(input[inputOffset + i]); } From 503c27887a34f0f4b529a8769f6038bbf4173607 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 15 Aug 2019 13:47:11 +0100 Subject: [PATCH 26/98] Added `addTransactions` to aggregate transactions Added unit tests --- src/model/transaction/AggregateTransaction.ts | 11 ++++++++ .../transaction/AggregateTransaction.spec.ts | 27 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 495ba89fb8..26ace13e3b 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -115,6 +115,17 @@ export class AggregateTransaction extends Transaction { ); } + /** + * @description add inner transactions to current list + * @param {InnerTransaction[]} transaction + * @returns {AggregateTransaction} + * @memberof AggregateTransaction + */ + public addTransactions(transactions: InnerTransaction[]): AggregateTransaction { + const innerTransactions = this.innerTransactions.concat(transactions); + return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {innerTransactions}); + } + /** * @internal * @returns {AggregateTransaction} diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index ab53059940..5cf09cf275 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -454,6 +454,33 @@ describe('AggregateTransaction', () => { expect(standardCosignedTransaction.hash).to.be.equal(signedTransaction.hash); }); + it('Should be able to add innertransactions to current aggregate tx', () => { + const transferTx1 = TransferTransaction.create(Deadline.create(), + account.address, + [], + PlainMessage.create('a to b'), + NetworkType.MIJIN_TEST); + const transferTx2 = TransferTransaction.create(Deadline.create(), + account.address, + [], + PlainMessage.create('b to a'), + NetworkType.MIJIN_TEST); + let aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [transferTx1.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + + expect(aggregateTransaction.type).to.be.equal(TransactionType.AGGREGATE_COMPLETE); + expect(aggregateTransaction.innerTransactions.length).to.be.equal(1); + + aggregateTransaction = aggregateTransaction.addTransactions([transferTx2.toAggregate(account.publicAccount)]); + + expect(aggregateTransaction.type).to.be.equal(TransactionType.AGGREGATE_COMPLETE); + expect(aggregateTransaction.innerTransactions.length).to.be.equal(2); + }); + describe('size', () => { it('should return 282 for AggregateTransaction byte size with TransferTransaction with 1 mosaic and message NEM', () => { const transaction = TransferTransaction.create( From 355689d587c2dbd2910ccc790370bf8844fb574d Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 19 Aug 2019 10:43:56 +0100 Subject: [PATCH 27/98] Applied generated aggregate transaction from catbuffer-generator --- .../AggregateBondedTransactionBuilder.ts | 112 +++++++++++++++ .../AggregateCompleteTransactionBuilder.ts | 112 +++++++++++++++ .../AggregateTransactionBodyBuilder.ts | 102 ++++++++++++++ .../catbuffer/AggregateTransactionBuilder.ts | 132 ------------------ .../catbuffer/CosignatureBuilder.ts | 30 ++-- .../catbuffer/DetachedCosignatureBuilder.ts | 46 +++--- src/infrastructure/catbuffer/EntityTypeDto.ts | 106 +++++--------- .../catbuffer/GeneratorUtils.ts | 55 ++++---- src/model/transaction/AggregateTransaction.ts | 36 +++-- 9 files changed, 449 insertions(+), 282 deletions(-) create mode 100644 src/infrastructure/catbuffer/AggregateBondedTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AggregateCompleteTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AggregateTransactionBodyBuilder.ts delete mode 100644 src/infrastructure/catbuffer/AggregateTransactionBuilder.ts diff --git a/src/infrastructure/catbuffer/AggregateBondedTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateBondedTransactionBuilder.ts new file mode 100644 index 0000000000..af3e1e2ed0 --- /dev/null +++ b/src/infrastructure/catbuffer/AggregateBondedTransactionBuilder.ts @@ -0,0 +1,112 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AggregateTransactionBodyBuilder } from './AggregateTransactionBodyBuilder'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for an aggregate bonded transaction. */ +export class AggregateBondedTransactionBuilder extends TransactionBuilder { + /** Aggregate transaction body. */ + aggregateTransactionBody: AggregateTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param transactions Sub-transaction data (transactions are variable sized and payload size is in bytes). + * @param cosignatures Cosignatures data (fills remaining body space after transactions). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, transactions: Uint8Array, cosignatures: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + this.aggregateTransactionBody = new AggregateTransactionBodyBuilder(transactions, cosignatures); + } + + /** + * Creates an instance of AggregateBondedTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AggregateBondedTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AggregateBondedTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const aggregateTransactionBody = AggregateTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, aggregateTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AggregateBondedTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, aggregateTransactionBody.transactions, aggregateTransactionBody.cosignatures); + } + + /** + * Gets sub-transaction data (transactions are variable sized and payload size is in bytes). + * + * @return Sub-transaction data (transactions are variable sized and payload size is in bytes). + */ + public getTransactions(): Uint8Array { + return this.aggregateTransactionBody.getTransactions(); + } + + /** + * Gets cosignatures data (fills remaining body space after transactions). + * + * @return Cosignatures data (fills remaining body space after transactions). + */ + public getCosignatures(): Uint8Array { + return this.aggregateTransactionBody.getCosignatures(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.aggregateTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const aggregateTransactionBodyBytes = this.aggregateTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, aggregateTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AggregateCompleteTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateCompleteTransactionBuilder.ts new file mode 100644 index 0000000000..a68fd86f07 --- /dev/null +++ b/src/infrastructure/catbuffer/AggregateCompleteTransactionBuilder.ts @@ -0,0 +1,112 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AggregateTransactionBodyBuilder } from './AggregateTransactionBodyBuilder'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for an aggregate complete transaction. */ +export class AggregateCompleteTransactionBuilder extends TransactionBuilder { + /** Aggregate transaction body. */ + aggregateTransactionBody: AggregateTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param transactions Sub-transaction data (transactions are variable sized and payload size is in bytes). + * @param cosignatures Cosignatures data (fills remaining body space after transactions). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, transactions: Uint8Array, cosignatures: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + this.aggregateTransactionBody = new AggregateTransactionBodyBuilder(transactions, cosignatures); + } + + /** + * Creates an instance of AggregateCompleteTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AggregateCompleteTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AggregateCompleteTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const aggregateTransactionBody = AggregateTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, aggregateTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AggregateCompleteTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, aggregateTransactionBody.transactions, aggregateTransactionBody.cosignatures); + } + + /** + * Gets sub-transaction data (transactions are variable sized and payload size is in bytes). + * + * @return Sub-transaction data (transactions are variable sized and payload size is in bytes). + */ + public getTransactions(): Uint8Array { + return this.aggregateTransactionBody.getTransactions(); + } + + /** + * Gets cosignatures data (fills remaining body space after transactions). + * + * @return Cosignatures data (fills remaining body space after transactions). + */ + public getCosignatures(): Uint8Array { + return this.aggregateTransactionBody.getCosignatures(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.aggregateTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const aggregateTransactionBodyBytes = this.aggregateTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, aggregateTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AggregateTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AggregateTransactionBodyBuilder.ts new file mode 100644 index 0000000000..4d84e86f79 --- /dev/null +++ b/src/infrastructure/catbuffer/AggregateTransactionBodyBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for an aggregate transaction. */ +export class AggregateTransactionBodyBuilder { + /** Sub-transaction data (transactions are variable sized and payload size is in bytes). */ + transactions: Uint8Array; + /** Cosignatures data (fills remaining body space after transactions). */ + cosignatures: Uint8Array; + + /** + * Constructor. + * + * @param transactions Sub-transaction data (transactions are variable sized and payload size is in bytes). + * @param cosignatures Cosignatures data (fills remaining body space after transactions). + */ + public constructor(transactions: Uint8Array, cosignatures: Uint8Array) { + this.transactions = transactions; + this.cosignatures = cosignatures; + } + + /** + * Creates an instance of AggregateTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AggregateTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AggregateTransactionBodyBuilder { + const byteArray = Array.from(payload); + const payloadSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + const transactions = GeneratorUtils.getBytes(Uint8Array.from(byteArray), payloadSize); + byteArray.splice(0, payloadSize); + const cosignatures = Uint8Array.from(byteArray); + return new AggregateTransactionBodyBuilder(transactions, cosignatures); + } + + /** + * Gets sub-transaction data (transactions are variable sized and payload size is in bytes). + * + * @return Sub-transaction data (transactions are variable sized and payload size is in bytes). + */ + public getTransactions(): Uint8Array { + return this.transactions; + } + + /** + * Gets cosignatures data (fills remaining body space after transactions). + * + * @return Cosignatures data (fills remaining body space after transactions). + */ + public getCosignatures(): Uint8Array { + return this.cosignatures; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 4; // payloadSize + size += this.transactions.length; + size += this.cosignatures.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const payloadSizeBytes = GeneratorUtils.uintToBuffer(this.transactions.length, 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.transactions); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.cosignatures); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts deleted file mode 100644 index 20462d8514..0000000000 --- a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts +++ /dev/null @@ -1,132 +0,0 @@ -// tslint:disable: jsdoc-format -/** -*** Copyright (c) 2016-present, -*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. -*** -*** This file is part of Catapult. -*** -*** Catapult is free software: you can redistribute it and/or modify -*** it under the terms of the GNU Lesser General Public License as published by -*** the Free Software Foundation, either version 3 of the License, or -*** (at your option) any later version. -*** -*** Catapult is distributed in the hope that it will be useful, -*** but WITHOUT ANY WARRANTY; without even the implied warranty of -*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -*** GNU Lesser General Public License for more details. -*** -*** You should have received a copy of the GNU Lesser General Public License -*** along with Catapult. If not, see . -**/ - -import { AmountDto } from './AmountDto'; -import { EntityTypeDto } from './EntityTypeDto'; -import { GeneratorUtils } from './GeneratorUtils'; -import { KeyDto } from './KeyDto'; -import { SignatureDto } from './SignatureDto'; -import { TimestampDto } from './TimestampDto'; -import { TransactionBuilder } from './TransactionBuilder'; - -/** binary layout for an aggregate transaction. */ -export class AggregateTransactionBuilder extends TransactionBuilder { - /** embedded transactions. */ - transactions: Uint8Array; - /** cosignatures. */ - cosignatures: Uint8Array; - - /** - * Constructor. - * - * @param signature entity signature. - * @param signer entity signer's public key. - * @param version entity version. - * @param type entity type. - * @param fee transaction fee. - * @param deadline transaction deadline. - * @param transactions embedded transactions. - * @param cosignatures cosignatures. - */ - public constructor( - signature: SignatureDto, - signer: KeyDto, - version: number, - type: EntityTypeDto, - fee: AmountDto, - deadline: TimestampDto, - transactions: Uint8Array, - cosignatures: Uint8Array) { - super(signature, signer, version, type, fee, deadline); - this.transactions = transactions; - this.cosignatures = cosignatures; - } - - /** - * loadFromBinary - Create an instance of AggregateTransactionBuilder from a stream. - * - * @param Uint8Array Byte to use to serialize the object. - * @return An instance of AggregateTransactionBuilder. - */ - public static loadFromBinary(payload: Uint8Array): AggregateTransactionBuilder { - const byteArray = Array.from(payload); - const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); - byteArray.splice(0, superObject.getSize()); - const payloadSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); - byteArray.splice(0, 4); - const transactions = GeneratorUtils.getBytes(Uint8Array.from(byteArray), payloadSize); - byteArray.splice(0, transactions.length); - const cosignatures = Uint8Array.from(byteArray); - // tslint:disable-next-line: max-line-length - return new AggregateTransactionBuilder(superObject.signature, superObject.signer, superObject.version, - superObject.type, superObject.fee, superObject.deadline, - transactions, cosignatures); - } - - /** - * Get embedded transactions. - * - * @return embedded transactions. - */ - public getTransactions(): Uint8Array { - return this.transactions; - } - - /** - * Get cosignatures. - * - * @return cosignatures. - */ - public getCosignatures(): Uint8Array { - return this.cosignatures; - } - - /** - * Get the size of the object. - * - * @return Size in bytes. - */ - public getSize(): number { - let size: number = super.getSize(); - size += 4; // payloadSize - size += this.transactions.length; - size += this.cosignatures.length; - return size; - } - - /** - * Serialize the object to bytes. - * - * @return Serialized bytes. - */ - public serialize(): Uint8Array { - let newArray = Uint8Array.from([]); - const superBytes = super.serialize(); - newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); - const payloadSizeBytes = GeneratorUtils.uintToBuffer(this.transactions.length, 4); - newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes); - const transactionBytes = this.transactions; - newArray = GeneratorUtils.concatTypedArrays(newArray, transactionBytes); - const cosignaturesBytes = this.cosignatures; - newArray = GeneratorUtils.concatTypedArrays(newArray, cosignaturesBytes); - return newArray; - } -} diff --git a/src/infrastructure/catbuffer/CosignatureBuilder.ts b/src/infrastructure/catbuffer/CosignatureBuilder.ts index 5e0ba7a43c..447524c2f6 100644 --- a/src/infrastructure/catbuffer/CosignatureBuilder.ts +++ b/src/infrastructure/catbuffer/CosignatureBuilder.ts @@ -23,29 +23,29 @@ import { GeneratorUtils } from './GeneratorUtils'; import { KeyDto } from './KeyDto'; import { SignatureDto } from './SignatureDto'; -/** a cosignature. */ +/** Cosignature attached to an aggregate transaction. */ export class CosignatureBuilder { - /** cosigner public key. */ + /** Cosigner public key. */ signer: KeyDto; - /** cosigner signature. */ + /** Cosigner signature. */ signature: SignatureDto; /** * Constructor. * - * @param signer cosigner public key. - * @param signature cosigner signature. + * @param signer Cosigner public key. + * @param signature Cosigner signature. */ - public constructor(signer: KeyDto, signature: SignatureDto) { + public constructor(signer: KeyDto, signature: SignatureDto) { this.signer = signer; this.signature = signature; } /** - * loadFromBinary - Create an instance of CosignatureBuilder from a stream. + * Creates an instance of CosignatureBuilder from binary payload. * - * @param payload Byte to use to serialize the object. - * @return An instance of CosignatureBuilder. + * @param payload Byte payload to use to serialize the object. + * @return Instance of CosignatureBuilder. */ public static loadFromBinary(payload: Uint8Array): CosignatureBuilder { const byteArray = Array.from(payload); @@ -57,25 +57,25 @@ export class CosignatureBuilder { } /** - * Get cosigner public key. + * Gets cosigner public key. * - * @return cosigner public key. + * @return Cosigner public key. */ public getSigner(): KeyDto { return this.signer; } /** - * Get cosigner signature. + * Gets cosigner signature. * - * @return cosigner signature. + * @return Cosigner signature. */ public getSignature(): SignatureDto { return this.signature; } /** - * Get the size of the object. + * Gets the size of the object. * * @return Size in bytes. */ @@ -87,7 +87,7 @@ export class CosignatureBuilder { } /** - * Serialize the object to bytes. + * Serializes an object to bytes. * * @return Serialized bytes. */ diff --git a/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts b/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts index 58a3152ed0..f10107ee30 100644 --- a/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts +++ b/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts @@ -19,77 +19,73 @@ *** along with Catapult. If not, see . **/ +import { CosignatureBuilder } from './CosignatureBuilder'; import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; import { KeyDto } from './KeyDto'; import { SignatureDto } from './SignatureDto'; -import { CosignatureBuilder } from './CosignatureBuilder'; -import { Hash256Dto } from './Hash256Dto'; -/** a detached cosignature. */ +/** Cosignature detached from an aggregate transaction. */ export class DetachedCosignatureBuilder extends CosignatureBuilder { - /** hash of the corresponding parent. */ + /** Hash of the aggregate transaction that is signed by this cosignature. */ parentHash: Hash256Dto; /** * Constructor. * - * @param signer cosigner public key. - * @param signature cosigner signature. - * @param parentHash hash of the corresponding parent. + * @param signer Cosigner public key. + * @param signature Cosigner signature. + * @param parentHash Hash of the aggregate transaction that is signed by this cosignature. */ - public constructor(signer: KeyDto, signature: SignatureDto, parentHash: Hash256Dto) { + public constructor(signer: KeyDto, signature: SignatureDto, parentHash: Hash256Dto) { super(signer, signature); this.parentHash = parentHash; } /** - * loadFromBinary - Create an instance of DetachedCosignatureBuilder from a stream. + * Creates an instance of DetachedCosignatureBuilder from binary payload. * - * @param payload Byte to use to serialize the object. - * @return An instance of DetachedCosignatureBuilder. + * @param payload Byte payload to use to serialize the object. + * @return Instance of DetachedCosignatureBuilder. */ public static loadFromBinary(payload: Uint8Array): DetachedCosignatureBuilder { const byteArray = Array.from(payload); - const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); - byteArray.splice(0, signer.getSize()); - const signature = SignatureDto.loadFromBinary(Uint8Array.from(byteArray)); - byteArray.splice(0, signature.getSize()); + const superObject = CosignatureBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); const parentHash = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); byteArray.splice(0, parentHash.getSize()); - return new DetachedCosignatureBuilder(signer, signature, parentHash); + return new DetachedCosignatureBuilder(superObject.signer, superObject.signature, parentHash); } /** - * Get hash of the corresponding parent. + * Gets hash of the aggregate transaction that is signed by this cosignature. * - * @return hash of the corresponding parent. + * @return Hash of the aggregate transaction that is signed by this cosignature. */ public getParentHash(): Hash256Dto { return this.parentHash; } /** - * Get the size of the object. + * Gets the size of the object. * * @return Size in bytes. */ public getSize(): number { - let size = super.getSize(); + let size: number = super.getSize(); size += this.parentHash.getSize(); return size; } /** - * Serialize the object to bytes. + * Serializes an object to bytes. * * @return Serialized bytes. */ public serialize(): Uint8Array { let newArray = Uint8Array.from([]); - const signerBytes = this.signer.serialize(); - newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); - const signatureBytes = this.signature.serialize(); - newArray = GeneratorUtils.concatTypedArrays(newArray, signatureBytes); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); const parentHashBytes = this.parentHash.serialize(); newArray = GeneratorUtils.concatTypedArrays(newArray, parentHashBytes); return newArray; diff --git a/src/infrastructure/catbuffer/EntityTypeDto.ts b/src/infrastructure/catbuffer/EntityTypeDto.ts index 52e1c55a94..921a115ce9 100644 --- a/src/infrastructure/catbuffer/EntityTypeDto.ts +++ b/src/infrastructure/catbuffer/EntityTypeDto.ts @@ -25,109 +25,67 @@ export enum EntityTypeDto { /** Reserved entity type. */ RESERVED = 0, /** - * Transfer Transaction transaction type. - * @type {number} + * Account address restriction transaction. */ - TRANSFER = 0x4154, - + ACCOUNT_ADDRESS_RESTRICTION_TRANSACTION = 0x4150, /** - * Register namespace transaction type. - * @type {number} + * Account mosaic restriction transaction. */ - REGISTER_NAMESPACE = 0x414E, - + ACCOUNT_MOSAIC_RESTRICTION_TRANSACTION = 0x4250, /** - * Address alias transaction type - * @type {number} + * Account operation restriction transaction. */ - ADDRESS_ALIAS = 0x424E, - + ACCOUNT_OPERATION_RESTRICTION_TRANSACTION = 0x4350, /** - * Mosaic alias transaction type - * @type {number} + * Account link transaction. */ - MOSAIC_ALIAS = 0x434E, - + ACCOUNT_LINK_TRANSACTION = 0x414C, /** - * Mosaic definition transaction type. - * @type {number} + * Address alias transaction. */ - MOSAIC_DEFINITION = 0x414D, - + ADDRESS_ALIAS_TRANSACTION = 0x424E, /** - * Mosaic supply change transaction. - * @type {number} + * Aggregate bonded transaction. */ - MOSAIC_SUPPLY_CHANGE = 0x424D, - + AGGREGATE_BONDED_TRANSACTION = 0x4241, /** - * Modify multisig account transaction type. - * @type {number} + * Aggregate complete transaction. */ - MODIFY_MULTISIG_ACCOUNT = 0x4155, - + AGGREGATE_COMPLETE_TRANSACTION = 0x4141, /** - * Aggregate complete transaction type. - * @type {number} + * Hash lock transaction. */ - AGGREGATE_COMPLETE = 0x4141, - + HASH_LOCK_TRANSACTION = 0x4148, /** - * Aggregate bonded transaction type + * Modify multisig account transaction. */ - AGGREGATE_BONDED = 0x4241, - + MODIFY_MULTISIG_ACCOUNT_TRANSACTION = 0x4155, /** - * Lock transaction type - * @type {number} + * Mosaic definition transaction. */ - LOCK = 0x4148, - + MOSAIC_DEFINITION_TRANSACTION = 0x414D, /** - * Secret Lock Transaction type - * @type {number} - */ - SECRET_LOCK = 0x4152, - - /** - * Secret Proof transaction type - * @type {number} + * Mosaic supply change transaction. */ - SECRET_PROOF = 0x4252, - + MOSAIC_SUPPLY_CHANGE_TRANSACTION = 0x424D, /** - * Account restriction address transaction type - * @type {number} + * Mosaic alias transaction. */ - ACCOUNT_RESTRICTION_ADDRESS = 0x4150, - + MOSAIC_ALIAS_TRANSACTION = 0x434E, /** - * Account restriction mosaic transaction type - * @type {number} + * Register namespace transaction. */ - ACCOUNT_RESTRICTION_MOSAIC = 0x4250, - + REGISTER_NAMESPACE_TRANSACTION = 0x414E, /** - * Account restriction operation transaction type - * @type {number} + * Secret lock transaction. */ - ACCOUNT_RESTRICTION_OPERATION = 0x4350, - + SECRET_LOCK_TRANSACTION = 0x4152, /** - * Link account transaction type - * @type {number} + * Secret Proof transaction. */ - LINK_ACCOUNT = 0x414C, - - /** - * Mosaic address restriction type - * @type {number} - */ - MOSAIC_ADDRESS_RESTRICTION = 0x4251, - + SECRET_PROOF_TRANSACTION = 0x4252, /** - * Mosaic global restriction type - * @type {number} + * Transfer transaction. */ - MOSAIC_GLOBAL_RESTRICTION = 0x4151, + TRANSFER_TRANSACTION = 0x4154, } diff --git a/src/infrastructure/catbuffer/GeneratorUtils.ts b/src/infrastructure/catbuffer/GeneratorUtils.ts index 7e95285569..f1f8ecb3d3 100644 --- a/src/infrastructure/catbuffer/GeneratorUtils.ts +++ b/src/infrastructure/catbuffer/GeneratorUtils.ts @@ -25,7 +25,8 @@ export class GeneratorUtils { /** - * Converts a (64bit) uint8 array into a number array. + * Convert a UInt8Array input into an array of 2 numbers. + * Numbers in the returned array are cast to UInt32. * @param {Uint8Array} input A uint8 array. * @returns {number[]} The uint64 representation of the input. */ @@ -39,7 +40,7 @@ export class GeneratorUtils { } /** - * Read buffer into 32bits integer at given index. + * Read 4 bytes as a uint32 value from buffer bytes starting at given index. * @param {Uint8Array} bytes A uint8 array. * @param {number} index Index. * @returns {number} 32bits integer. @@ -49,7 +50,7 @@ export class GeneratorUtils { } /** - * Write uint to buffer + * Convert uint value into buffer * @param {number} uintValue A uint8 array. * @param {number} bufferSize Buffer size. * @returns {Uint8Array} @@ -57,39 +58,45 @@ export class GeneratorUtils { public static uintToBuffer(uintValue: number, bufferSize: number): Uint8Array { const buffer = new ArrayBuffer(bufferSize); const dataView = new DataView(buffer); - if (1 === bufferSize) { - dataView.setUint8(0, uintValue); - } else if (2 === bufferSize) { - dataView.setUint16(0, uintValue, true); - } else if (4 === bufferSize) { - dataView.setUint32(0, uintValue, true); - } else { - throw new Error('Unexpected bufferSize'); + try { + if (1 === bufferSize) { + dataView.setUint8(0, uintValue); + } else if (2 === bufferSize) { + dataView.setUint16(0, uintValue, true); + } else if (4 === bufferSize) { + dataView.setUint32(0, uintValue, true); + } else { + throw new Error('Unexpected bufferSize'); + } + return new Uint8Array(buffer); + } catch (e) { + throw new Error(`Converting uint value ${uintValue} into buffer with error: ${e}`); } - - return new Uint8Array(buffer); } /** - * Write uint to buffer + * Convert uint8 array buffer into number * @param {Uint8Array} buffer A uint8 array. * @returns {number} */ public static bufferToUint(buffer: Uint8Array): number { const dataView = new DataView(buffer.buffer); - if (1 === buffer.byteLength) { - return dataView.getUint8(0); - } else if (2 === buffer.byteLength) { - return dataView.getUint16(0, true); - } else if (4 === buffer.byteLength) { - return dataView.getUint32(0, true); - } - - throw new Error('Unexpected buffer size'); + try { + if (1 === buffer.byteLength) { + return dataView.getUint8(0); + } else if (2 === buffer.byteLength) { + return dataView.getUint16(0, true); + } else if (4 === buffer.byteLength) { + return dataView.getUint32(0, true); + } + throw new Error('Unexpected buffer size'); + } catch (e) { + throw new Error(`Converting buffer into number with error: ${e}`); + } } /** - * Write Uint64 to buffer + * Convert unit64 into buffer * @param {number} uintValue Uint64 (number[]). * @returns {Uint8Array} */ diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 76eac2be1a..ccc5579a04 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -16,7 +16,8 @@ import { KeyPair, SignSchema } from '../../core/crypto'; import { Convert } from '../../core/format'; -import { AggregateTransactionBuilder } from '../../infrastructure/catbuffer/AggregateTransactionBuilder'; +import { AggregateBondedTransactionBuilder } from '../../infrastructure/catbuffer/AggregateBondedTransactionBuilder'; +import { AggregateCompleteTransactionBuilder } from '../../infrastructure/catbuffer/AggregateCompleteTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { CosignatureBuilder } from '../../infrastructure/catbuffer/CosignatureBuilder'; import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; @@ -130,7 +131,7 @@ export class AggregateTransaction extends Transaction { * @returns {AggregateTransaction} */ public static createFromPayload(payload: string, signSchema: SignSchema = SignSchema.SHA3): AggregateTransaction { - const builder = AggregateTransactionBuilder + const builder = AggregateCompleteTransactionBuilder .loadFromBinary(Convert.hexToUint8(payload)); const type = builder.getType().valueOf(); const innerTransactionHex = Convert.uint8ToHex(builder.getTransactions()); @@ -297,16 +298,27 @@ export class AggregateTransaction extends Transaction { cosignatures = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); }); - const transactionBuilder = new AggregateTransactionBuilder( - new SignatureDto(signatureBuffer), - new KeyDto(signerBuffer), - this.versionToDTO(), - this.type.valueOf(), - new AmountDto(this.maxFee.toDTO()), - new TimestampDto(this.deadline.toDTO()), - transactions, - cosignatures, - ); + const transactionBuilder = this.type === TransactionType.AGGREGATE_COMPLETE ? + new AggregateCompleteTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + this.type.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + transactions, + cosignatures, + ) : + new AggregateBondedTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + this.type.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + transactions, + cosignatures, + ); return transactionBuilder.serialize(); } From 0787adf7ee0ed4c3f146f20dc81a9bfd95144404 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 19 Aug 2019 20:58:08 +0100 Subject: [PATCH 28/98] Fixed aggregate transaction creatFromPayload - Catbuffer use separate builder class for Complete and Bonded - Added unit tests --- src/model/transaction/AggregateTransaction.ts | 11 +++++--- test/core/utils/TransactionMapping.spec.ts | 2 ++ .../transaction/AggregateTransaction.spec.ts | 27 +++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index ccc5579a04..591fa6182e 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -131,9 +131,14 @@ export class AggregateTransaction extends Transaction { * @returns {AggregateTransaction} */ public static createFromPayload(payload: string, signSchema: SignSchema = SignSchema.SHA3): AggregateTransaction { - const builder = AggregateCompleteTransactionBuilder - .loadFromBinary(Convert.hexToUint8(payload)); - const type = builder.getType().valueOf(); + /** + * Get transaction type from the payload hex + * As buffer uses separate builder class for Complete and bonded + */ + const type = parseInt(Convert.uint8ToHex(Convert.hexToUint8(payload.substring(204, 208)).reverse()), 16); + const builder = type === TransactionType.AGGREGATE_COMPLETE ? + AggregateCompleteTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AggregateBondedTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); const innerTransactionHex = Convert.uint8ToHex(builder.getTransactions()); const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; const consignaturesHex = Convert.uint8ToHex(builder.getCosignatures()); diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index d07628b97e..7f80ee3375 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -439,6 +439,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AggregateTransaction; + expect(transaction.type).to.be.equal(TransactionType.AGGREGATE_COMPLETE); expect(transaction.innerTransactions[0].type).to.be.equal(TransactionType.TRANSFER); }); @@ -461,6 +462,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AggregateTransaction; + expect(transaction.type).to.be.equal(TransactionType.AGGREGATE_BONDED); expect(transaction.innerTransactions[0].type).to.be.equal(TransactionType.TRANSFER); }); diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 072302eba9..f26df17f9b 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -265,6 +265,33 @@ describe('AggregateTransaction', () => { }); + it('should createBonded an AggregateTransaction object with TransferTransaction', () => { + const transferTransaction = TransferTransaction.create( + Deadline.create(), + Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + [], + PlainMessage.create('test-message'), + NetworkType.MIJIN_TEST, + ); + + const aggregateTransaction = AggregateTransaction.createBonded( + Deadline.create(2, ChronoUnit.MINUTES), + [transferTransaction.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); + expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); + expect(signedTransaction.payload.substring(204, 208)).to.be.equal('4142'); + expect(signedTransaction.payload.substring( + 320, + signedTransaction.payload.length, + )).to.be.equal('019054419050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000000746573742D6D657373616765'); + }); + it('should validate if accounts have signed an aggregate transaction', () => { const aggregateTransactionDTO = { meta: { From 24a8909f457c2801fa374dbcc90273e83838c7fd Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 15 Aug 2019 13:47:11 +0100 Subject: [PATCH 29/98] Added `addTransactions` to aggregate transactions Added unit tests --- src/model/transaction/AggregateTransaction.ts | 11 ++++++++ .../transaction/AggregateTransaction.spec.ts | 27 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 495ba89fb8..26ace13e3b 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -115,6 +115,17 @@ export class AggregateTransaction extends Transaction { ); } + /** + * @description add inner transactions to current list + * @param {InnerTransaction[]} transaction + * @returns {AggregateTransaction} + * @memberof AggregateTransaction + */ + public addTransactions(transactions: InnerTransaction[]): AggregateTransaction { + const innerTransactions = this.innerTransactions.concat(transactions); + return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {innerTransactions}); + } + /** * @internal * @returns {AggregateTransaction} diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index ab53059940..5cf09cf275 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -454,6 +454,33 @@ describe('AggregateTransaction', () => { expect(standardCosignedTransaction.hash).to.be.equal(signedTransaction.hash); }); + it('Should be able to add innertransactions to current aggregate tx', () => { + const transferTx1 = TransferTransaction.create(Deadline.create(), + account.address, + [], + PlainMessage.create('a to b'), + NetworkType.MIJIN_TEST); + const transferTx2 = TransferTransaction.create(Deadline.create(), + account.address, + [], + PlainMessage.create('b to a'), + NetworkType.MIJIN_TEST); + let aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [transferTx1.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + + expect(aggregateTransaction.type).to.be.equal(TransactionType.AGGREGATE_COMPLETE); + expect(aggregateTransaction.innerTransactions.length).to.be.equal(1); + + aggregateTransaction = aggregateTransaction.addTransactions([transferTx2.toAggregate(account.publicAccount)]); + + expect(aggregateTransaction.type).to.be.equal(TransactionType.AGGREGATE_COMPLETE); + expect(aggregateTransaction.innerTransactions.length).to.be.equal(2); + }); + describe('size', () => { it('should return 282 for AggregateTransaction byte size with TransferTransaction with 1 mosaic and message NEM', () => { const transaction = TransferTransaction.create( From 050bdeffe0cb9599fc8b3a059dcade2c653fca20 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 15 Aug 2019 12:31:17 +0100 Subject: [PATCH 30/98] Removed `this.` in decodeBlock in Utilities.ts --- src/core/format/Utilities.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/format/Utilities.ts b/src/core/format/Utilities.ts index 90a2180655..332433afff 100644 --- a/src/core/format/Utilities.ts +++ b/src/core/format/Utilities.ts @@ -168,8 +168,8 @@ export const decodeChar = (c) => { }; export const decodeBlock = (input, inputOffset, output, outputOffset) => { - const bytes = new Uint8Array(this.Encoded_Block_Size); - for (let i = 0; i < this.Encoded_Block_Size; ++i) { + const bytes = new Uint8Array(Encoded_Block_Size); + for (let i = 0; i < Encoded_Block_Size; ++i) { bytes[i] = decodeChar(input[inputOffset + i]); } From eee44efc0f248f91288689ad335f5acbd2914167 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 31 Jul 2019 19:33:40 +0100 Subject: [PATCH 31/98] Renamed RestrictionType to AccountRestrictionType --- e2e/infrastructure/AccountHttp.spec.ts | 5 ++-- e2e/infrastructure/TransactionHttp.spec.ts | 14 +++++----- src/core/utils/DtoMapping.ts | 14 +++++----- src/model/account/AccountRestriction.ts | 4 +-- ...ctionType.ts => AccountRestrictionType.ts} | 2 +- src/model/model.ts | 2 +- ...dressRestrictionModificationTransaction.ts | 6 ++--- ...osaicRestrictionModificationTransaction.ts | 6 ++--- ...ationRestrictionModificationTransaction.ts | 6 ++--- .../AccountRestrictionTransaction.ts | 14 +++++----- test/core/utils/TransactionMapping.spec.ts | 26 +++++++++---------- .../SerializeTransactionToJSON.spec.ts | 14 +++++----- test/model/account/AccountRestriction.spec.ts | 4 +-- .../model/account/AccountRestrictions.spec.ts | 4 +-- .../account/AccountRestrictionsInfo.spec.ts | 4 +-- .../AccountRestrictionTransaction.spec.ts | 22 ++++++++-------- 16 files changed, 74 insertions(+), 73 deletions(-) rename src/model/account/{RestrictionType.ts => AccountRestrictionType.ts} (96%) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index d4f5242763..a3f96ca7e1 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -19,6 +19,7 @@ import {assert, expect} from 'chai'; import {AccountHttp} from '../../src/infrastructure/AccountHttp'; import { Listener, TransactionHttp } from '../../src/infrastructure/infrastructure'; import { Account } from '../../src/model/account/Account'; +import { AccountRestrictionType } from '../../src/model/account/AccountRestrictionType'; import {Address} from '../../src/model/account/Address'; import {PublicAccount} from '../../src/model/account/PublicAccount'; import { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType'; @@ -200,7 +201,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); @@ -426,7 +427,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 2ad8b0be8d..dc056d7c98 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -25,8 +25,8 @@ import { NamespaceHttp } from '../../src/infrastructure/infrastructure'; import {Listener} from '../../src/infrastructure/Listener'; import {TransactionHttp} from '../../src/infrastructure/TransactionHttp'; import {Account} from '../../src/model/account/Account'; +import { AccountRestrictionType } from '../../src/model/account/AccountRestrictionType'; import { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../src/model/account/RestrictionType'; import {NetworkType} from '../../src/model/blockchain/NetworkType'; import { Mosaic } from '../../src/model/mosaic/Mosaic'; import {MosaicId} from '../../src/model/mosaic/MosaicId'; @@ -404,7 +404,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -441,7 +441,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -479,7 +479,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockMosaic, + AccountRestrictionType.BlockMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -516,7 +516,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockMosaic, + AccountRestrictionType.BlockMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -554,7 +554,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockTransaction, + AccountRestrictionType.BlockTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -591,7 +591,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockTransaction, + AccountRestrictionType.BlockTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); diff --git a/src/core/utils/DtoMapping.ts b/src/core/utils/DtoMapping.ts index 9a0e2b77d1..2babb31068 100644 --- a/src/core/utils/DtoMapping.ts +++ b/src/core/utils/DtoMapping.ts @@ -17,8 +17,8 @@ import { AccountRestriction } from '../../model/account/AccountRestriction'; import { AccountRestrictions } from '../../model/account/AccountRestrictions'; import { AccountRestrictionsInfo } from '../../model/account/AccountRestrictionsInfo'; +import { AccountRestrictionType } from '../../model/account/AccountRestrictionType'; import { Address } from '../../model/account/Address'; -import { RestrictionType } from '../../model/account/RestrictionType'; import { MosaicId } from '../../model/mosaic/MosaicId'; export class DtoMapping { @@ -34,16 +34,16 @@ export class DtoMapping { new AccountRestrictions(Address.createFromEncoded(accountRestrictions.accountRestrictions.address), accountRestrictions.accountRestrictions.restrictions.map((prop) => { switch (prop.restrictionType) { - case RestrictionType.AllowAddress: - case RestrictionType.BlockAddress: + case AccountRestrictionType.AllowAddress: + case AccountRestrictionType.BlockAddress: return new AccountRestriction(prop.restrictionType, prop.values.map((value) => Address.createFromEncoded(value))); - case RestrictionType.AllowMosaic: - case RestrictionType.BlockMosaic: + case AccountRestrictionType.AllowMosaic: + case AccountRestrictionType.BlockMosaic: return new AccountRestriction(prop.restrictionType, prop.values.map((value) => new MosaicId(value))); - case RestrictionType.AllowTransaction: - case RestrictionType.BlockTransaction: + case AccountRestrictionType.AllowTransaction: + case AccountRestrictionType.BlockTransaction: return new AccountRestriction(prop.restrictionType, prop.values); default: throw new Error(`Invalid restriction type: ${prop.restrictionType}`); diff --git a/src/model/account/AccountRestriction.ts b/src/model/account/AccountRestriction.ts index 7eb6928f11..47bf9a345c 100644 --- a/src/model/account/AccountRestriction.ts +++ b/src/model/account/AccountRestriction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RestrictionType } from './RestrictionType'; +import { AccountRestrictionType } from './AccountRestrictionType'; /** * Account restriction structure describes restriction information. */ @@ -29,7 +29,7 @@ export class AccountRestriction { /** * Account restriction type */ - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, /** * Restriction values. */ diff --git a/src/model/account/RestrictionType.ts b/src/model/account/AccountRestrictionType.ts similarity index 96% rename from src/model/account/RestrictionType.ts rename to src/model/account/AccountRestrictionType.ts index aa7d236ed0..93b503b5af 100644 --- a/src/model/account/RestrictionType.ts +++ b/src/model/account/AccountRestrictionType.ts @@ -23,7 +23,7 @@ * 0x80 + type The restriction is interpreted as a blocking operation. */ -export enum RestrictionType { +export enum AccountRestrictionType { AllowAddress = 0x01, AllowMosaic = 0x02, AllowTransaction = 0x04, diff --git a/src/model/model.ts b/src/model/model.ts index ec948eca39..2c0c7a755b 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -28,7 +28,7 @@ export * from './account/AccountRestrictions'; export * from './account/AccountRestrictionsInfo'; export * from './account/AccountRestriction'; export * from './account/RestrictionModificationType'; -export * from './account/RestrictionType'; +export * from './account/AccountRestrictionType'; export * from './account/AccountNames'; // Blockchain diff --git a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts b/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts index 3a9d99f813..822bc9d284 100644 --- a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts @@ -16,8 +16,8 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { PublicAccount } from '../account/PublicAccount'; -import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; @@ -39,7 +39,7 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio * @returns {AccountAddressRestrictionModificationTransaction} */ public static create(deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountAddressRestrictionModificationTransaction { @@ -66,7 +66,7 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, diff --git a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts b/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts index 3a32656795..9de6449f61 100644 --- a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts @@ -16,8 +16,8 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { PublicAccount } from '../account/PublicAccount'; -import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; @@ -39,7 +39,7 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction * @returns {AccountAddressRestrictionModificationTransaction} */ public static create(deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountMosaicRestrictionModificationTransaction { @@ -66,7 +66,7 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, diff --git a/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts b/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts index 38160cc79d..45788393e3 100644 --- a/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts @@ -16,8 +16,8 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { PublicAccount } from '../account/PublicAccount'; -import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; @@ -39,7 +39,7 @@ export class AccountOperationRestrictionModificationTransaction extends Transact * @returns {AccountOperationRestrictionModificationTransaction} */ public static create(deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountOperationRestrictionModificationTransaction { @@ -66,7 +66,7 @@ export class AccountOperationRestrictionModificationTransaction extends Transact version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, diff --git a/src/model/transaction/AccountRestrictionTransaction.ts b/src/model/transaction/AccountRestrictionTransaction.ts index 7e0f26c313..2bb4aceaf4 100644 --- a/src/model/transaction/AccountRestrictionTransaction.ts +++ b/src/model/transaction/AccountRestrictionTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RestrictionType } from '../account/RestrictionType'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountAddressRestrictionModificationTransaction } from './AccountAddressRestrictionModificationTransaction'; @@ -36,12 +36,12 @@ export class AccountRestrictionTransaction { */ public static createAddressRestrictionModificationTransaction( deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountAddressRestrictionModificationTransaction { - if (![RestrictionType.AllowAddress, RestrictionType.BlockAddress].includes(restrictionType)) { + if (![AccountRestrictionType.AllowAddress, AccountRestrictionType.BlockAddress].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountAddressRestrictionModificationTransaction.create( @@ -64,12 +64,12 @@ export class AccountRestrictionTransaction { */ public static createMosaicRestrictionModificationTransaction( deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountMosaicRestrictionModificationTransaction { - if (![RestrictionType.AllowMosaic, RestrictionType.BlockMosaic].includes(restrictionType)) { + if (![AccountRestrictionType.AllowMosaic, AccountRestrictionType.BlockMosaic].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountMosaicRestrictionModificationTransaction.create( @@ -92,12 +92,12 @@ export class AccountRestrictionTransaction { */ public static createOperationRestrictionModificationTransaction( deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountOperationRestrictionModificationTransaction { - if (![RestrictionType.AllowTransaction, RestrictionType.BlockTransaction].includes(restrictionType)) { + if (![AccountRestrictionType.AllowTransaction, AccountRestrictionType.BlockTransaction].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountOperationRestrictionModificationTransaction.create( diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index b3653114f1..3e45e2f359 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -20,10 +20,10 @@ import { sha3_256 } from 'js-sha3'; import {Convert as convert} from '../../../src/core/format'; import { TransactionMapping } from '../../../src/core/utils/TransactionMapping'; import { Account } from '../../../src/model/account/Account'; +import { AccountRestrictionType } from '../../../src/model/account/AccountRestrictionType'; import { Address } from '../../../src/model/account/Address'; import { PublicAccount } from '../../../src/model/account/PublicAccount'; import { RestrictionModificationType } from '../../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../../src/model/account/RestrictionType'; import { NetworkType } from '../../../src/model/blockchain/NetworkType'; import { EncryptedMessage } from '../../../src/model/model'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; @@ -35,7 +35,7 @@ import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrency import { AliasAction } from '../../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { NamespaceType } from '../../../src/model/namespace/NamespaceType'; -import { AccountAddressRestrictionModificationTransaction } from '../../../src/model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionModificationTransaction } from'../../../src/model/transaction/AccountAddressRestrictionModificationTransaction'; import { AccountLinkTransaction } from '../../../src/model/transaction/AccountLinkTransaction'; import { AccountMosaicRestrictionModificationTransaction } from '../../../src/model/transaction/AccountMosaicRestrictionModificationTransaction'; import { AccountRestrictionModification } from '../../../src/model/transaction/AccountRestrictionModification'; @@ -79,7 +79,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -89,7 +89,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); }); @@ -102,7 +102,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -111,7 +111,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowMosaic); expect(transaction.modifications[0].value[0]).to.be.equal(2262289484); expect(transaction.modifications[0].value[1]).to.be.equal(3405110546); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); @@ -125,7 +125,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -666,7 +666,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -675,7 +675,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(addressRestrictionTransaction.toJSON()) as AccountAddressRestrictionModificationTransaction; expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -687,7 +687,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -696,7 +696,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(mosaicRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC); - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowMosaic); expect(transaction.modifications.length).to.be.equal(1); }); @@ -708,7 +708,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -717,7 +717,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(operationRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction); expect(transaction.modifications.length).to.be.equal(1); }); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 2f3ce56962..2fe89a589a 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -18,10 +18,10 @@ import { expect } from 'chai'; import { sha3_256 } from 'js-sha3'; import {Convert as convert} from '../../src/core/format'; import { Account } from '../../src/model/account/Account'; +import { AccountRestrictionType } from '../../src/model/account/AccountRestrictionType'; import { Address } from '../../src/model/account/Address'; import { PublicAccount } from '../../src/model/account/PublicAccount'; import { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../src/model/account/RestrictionType'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; @@ -83,7 +83,7 @@ describe('SerializeTransactionToJSON', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -91,7 +91,7 @@ describe('SerializeTransactionToJSON', () => { const json = addressRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS); - expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -103,7 +103,7 @@ describe('SerializeTransactionToJSON', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -111,7 +111,7 @@ describe('SerializeTransactionToJSON', () => { const json = mosaicRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC); - expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowMosaic); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -123,7 +123,7 @@ describe('SerializeTransactionToJSON', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -131,7 +131,7 @@ describe('SerializeTransactionToJSON', () => { const json = operationRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); - expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction); expect(json.transaction.modifications.length).to.be.equal(1); }); diff --git a/test/model/account/AccountRestriction.spec.ts b/test/model/account/AccountRestriction.spec.ts index 5bc3e189b6..d41a0e73a6 100644 --- a/test/model/account/AccountRestriction.spec.ts +++ b/test/model/account/AccountRestriction.spec.ts @@ -17,13 +17,13 @@ import {deepEqual} from 'assert'; import {expect} from 'chai'; import { AccountRestriction } from '../../../src/model/account/AccountRestriction'; +import { AccountRestrictionType } from '../../../src/model/account/AccountRestrictionType'; import { Address } from '../../../src/model/account/Address'; -import { RestrictionType } from '../../../src/model/account/RestrictionType'; describe('AccountRestriction', () => { it('should createComplete an AccountRestriction object', () => { const accountRestrictionDTO = { - restrictionType: RestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowAddress, values: ['906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'], }; diff --git a/test/model/account/AccountRestrictions.spec.ts b/test/model/account/AccountRestrictions.spec.ts index 1ad76d7daa..8b30a7451b 100644 --- a/test/model/account/AccountRestrictions.spec.ts +++ b/test/model/account/AccountRestrictions.spec.ts @@ -17,7 +17,7 @@ import {deepEqual} from 'assert'; import {expect} from 'chai'; import {Address} from '../../../src/model/account/Address'; -import { AccountRestrictions, RestrictionModificationType, RestrictionType, AccountRestriction } from '../../../src/model/model'; +import { AccountRestriction, AccountRestrictions, AccountRestrictionType, RestrictionModificationType } from '../../../src/model/model'; describe('AccountRestrictions', () => { @@ -25,7 +25,7 @@ describe('AccountRestrictions', () => { const accountRestrictionsDTO = { address: Address.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'), restrictions: [{ - restrictionType: RestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/account/AccountRestrictionsInfo.spec.ts b/test/model/account/AccountRestrictionsInfo.spec.ts index 01ac4771f9..981817bcea 100644 --- a/test/model/account/AccountRestrictionsInfo.spec.ts +++ b/test/model/account/AccountRestrictionsInfo.spec.ts @@ -18,9 +18,9 @@ import {deepEqual} from 'assert'; import { AccountRestriction } from '../../../src/model/account/AccountRestriction'; import { AccountRestrictions } from '../../../src/model/account/AccountRestrictions'; import { AccountRestrictionsInfo } from '../../../src/model/account/AccountRestrictionsInfo'; +import { AccountRestrictionType } from '../../../src/model/account/AccountRestrictionType'; import {Address} from '../../../src/model/account/Address'; import { RestrictionModificationType } from '../../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../../src/model/account/RestrictionType'; describe('AccountRestrictionsInfo', () => { @@ -31,7 +31,7 @@ describe('AccountRestrictionsInfo', () => { accountRestrictions: { address: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', restrictions: [{ - restrictionType: RestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 04ef489a07..8f83e951f3 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -16,9 +16,9 @@ import {expect} from 'chai'; import {Account} from '../../../src/model/account/Account'; +import { AccountRestrictionType } from '../../../src/model/account/AccountRestrictionType'; import {Address} from '../../../src/model/account/Address'; import { RestrictionModificationType } from '../../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../../src/model/account/RestrictionType'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {MosaicId} from '../../../src/model/mosaic/MosaicId'; import { AccountRestrictionModification } from '../../../src/model/transaction/AccountRestrictionModification'; @@ -74,7 +74,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -90,7 +90,7 @@ describe('AccountRestrictionTransaction', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -105,7 +105,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -121,7 +121,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -138,7 +138,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -157,7 +157,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -182,7 +182,7 @@ describe('AccountRestrictionTransaction', () => { expect(() => { AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.Sentinel, + AccountRestrictionType.Sentinel, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -199,7 +199,7 @@ describe('AccountRestrictionTransaction', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -224,7 +224,7 @@ describe('AccountRestrictionTransaction', () => { expect(() => { AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.Sentinel, + AccountRestrictionType.Sentinel, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -241,7 +241,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowTransaction, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); From 51f43f54ca73574a97dba63bb49d51bf41250d1c Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 2 Aug 2019 10:15:35 +0100 Subject: [PATCH 32/98] Refactored AccountRestrictionType --- e2e/infrastructure/AccountHttp.spec.ts | 4 +- e2e/infrastructure/TransactionHttp.spec.ts | 8 +- src/core/utils/DtoMapping.ts | 12 ++- src/model/account/AccountRestrictionType.ts | 89 ++++++++++++++++--- .../AccountRestrictionTransaction.ts | 12 ++- test/core/utils/TransactionMapping.spec.ts | 16 ++-- .../SerializeTransactionToJSON.spec.ts | 8 +- test/model/account/AccountRestriction.spec.ts | 2 +- .../model/account/AccountRestrictions.spec.ts | 2 +- .../account/AccountRestrictionsInfo.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 12 +-- 11 files changed, 120 insertions(+), 47 deletions(-) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index a3f96ca7e1..ba12110edf 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -201,7 +201,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); @@ -427,7 +427,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index dc056d7c98..60ec20592d 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -404,7 +404,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -441,7 +441,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -554,7 +554,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockTransaction, + AccountRestrictionType.BlockIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -591,7 +591,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.BlockTransaction, + AccountRestrictionType.BlockIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); diff --git a/src/core/utils/DtoMapping.ts b/src/core/utils/DtoMapping.ts index 2babb31068..7670b1815e 100644 --- a/src/core/utils/DtoMapping.ts +++ b/src/core/utils/DtoMapping.ts @@ -34,16 +34,20 @@ export class DtoMapping { new AccountRestrictions(Address.createFromEncoded(accountRestrictions.accountRestrictions.address), accountRestrictions.accountRestrictions.restrictions.map((prop) => { switch (prop.restrictionType) { - case AccountRestrictionType.AllowAddress: - case AccountRestrictionType.BlockAddress: + case AccountRestrictionType.AllowIncomingAddress: + case AccountRestrictionType.BlockIncomingAddress: + case AccountRestrictionType.AllowOutgoingAddress: + case AccountRestrictionType.BlockOutgoingAddress: return new AccountRestriction(prop.restrictionType, prop.values.map((value) => Address.createFromEncoded(value))); case AccountRestrictionType.AllowMosaic: case AccountRestrictionType.BlockMosaic: return new AccountRestriction(prop.restrictionType, prop.values.map((value) => new MosaicId(value))); - case AccountRestrictionType.AllowTransaction: - case AccountRestrictionType.BlockTransaction: + case AccountRestrictionType.AllowIncomingTransactionType: + case AccountRestrictionType.AllowOutgoingTransactionType: + case AccountRestrictionType.BlockIncomingTransactionType: + case AccountRestrictionType.BlockOutgoingTransactionType: return new AccountRestriction(prop.restrictionType, prop.values); default: throw new Error(`Invalid restriction type: ${prop.restrictionType}`); diff --git a/src/model/account/AccountRestrictionType.ts b/src/model/account/AccountRestrictionType.ts index 93b503b5af..757c1fde75 100644 --- a/src/model/account/AccountRestrictionType.ts +++ b/src/model/account/AccountRestrictionType.ts @@ -1,7 +1,7 @@ /* * Copyright 2019 NEM * - * Licensed under the Apache License, Version 2.0 (the "License"); + * 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 * @@ -16,19 +16,82 @@ /** * Account restriction type - * 0x01 The restriction type is an address. - * 0x02 The restriction type is mosaic id. - * 0x03 The restriction type is a transaction type. - * 0x04 restriction type sentinel. - * 0x80 + type The restriction is interpreted as a blocking operation. + * 0x01 Account restriction type is an address. + * 0x02 Account restriction type is a mosaic id. + * 0x04 Account restriction type is a transaction type. + * 0x05 restriction type sentinel. + * 0x40 Account restriction is interpreted as outgoing restriction. + * 0x80 Account restriction is interpreted as blocking operation. */ -export enum AccountRestrictionType { - AllowAddress = 0x01, - AllowMosaic = 0x02, - AllowTransaction = 0x04, + // !!This enum will be deprecated once catbuffer code applied. +enum AccountRestrictionTypeEnum { + Address = 0x01, + Mosaic = 0x02, + TransactionType = 0x04, Sentinel = 0x05, - BlockAddress = (0x80 + 0x01), - BlockMosaic = (0x80 + 0x02), - BlockTransaction = (0x80 + 0x04), + Outgoing = 0x40, + Block = 0x80, +} + +export enum AccountRestrictionType { + /** + * Allow only incoming transactions from a given address. + */ + AllowIncomingAddress = AccountRestrictionTypeEnum.Address, + + /** + * Allow only incoming transactions containing a a given mosaic identifier. + */ + AllowMosaic = AccountRestrictionTypeEnum.Mosaic, + + /** + * Allow only outgoing transactions with a given transaction type. + */ + AllowIncomingTransactionType = AccountRestrictionTypeEnum.TransactionType, + + /** + * Allow only outgoing transactions to a given address. + */ + AllowOutgoingAddress = (AccountRestrictionTypeEnum.Address + AccountRestrictionTypeEnum.Outgoing), + + /** + * Allow only outgoing transactions with a given transaction type. + */ + AllowOutgoingTransactionType = (AccountRestrictionTypeEnum.TransactionType + + AccountRestrictionTypeEnum.Outgoing), + + /** + * Block incoming transactions from a given address. + */ + BlockIncomingAddress = (AccountRestrictionTypeEnum.Address + AccountRestrictionTypeEnum.Block), + + /** + * Block incoming transactions containing a given mosaic identifier. + */ + BlockMosaic = (AccountRestrictionTypeEnum.Mosaic + AccountRestrictionTypeEnum.Block), + + /** + * Block incoming transactions with a given transaction type. + */ + BlockIncomingTransactionType = (AccountRestrictionTypeEnum.TransactionType + + AccountRestrictionTypeEnum.Block), + + /** + * Block outgoing transactions from a given address. + */ + BlockOutgoingAddress = (AccountRestrictionTypeEnum.Address + + AccountRestrictionTypeEnum.Block + + AccountRestrictionTypeEnum.Outgoing), + /** + * Block outgoing transactions with a given transaction type. + */ + BlockOutgoingTransactionType = (AccountRestrictionTypeEnum.TransactionType + + AccountRestrictionTypeEnum.Block + + AccountRestrictionTypeEnum.Outgoing), + + /** + * Account restriction sentinel. + */ + Sentinel = AccountRestrictionTypeEnum.Sentinel, } diff --git a/src/model/transaction/AccountRestrictionTransaction.ts b/src/model/transaction/AccountRestrictionTransaction.ts index 2bb4aceaf4..1ebbbf7849 100644 --- a/src/model/transaction/AccountRestrictionTransaction.ts +++ b/src/model/transaction/AccountRestrictionTransaction.ts @@ -41,7 +41,10 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountAddressRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowAddress, AccountRestrictionType.BlockAddress].includes(restrictionType)) { + if (![AccountRestrictionType.AllowIncomingAddress, + AccountRestrictionType.AllowOutgoingAddress, + AccountRestrictionType.BlockOutgoingAddress, + AccountRestrictionType.BlockIncomingAddress].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountAddressRestrictionModificationTransaction.create( @@ -69,7 +72,7 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountMosaicRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowMosaic, AccountRestrictionType.BlockMosaic].includes(restrictionType)) { + if (![AccountRestrictionType.AllowMosaic,AccountRestrictionType.BlockMosaic].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountMosaicRestrictionModificationTransaction.create( @@ -97,7 +100,10 @@ export class AccountRestrictionTransaction { networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), ): AccountOperationRestrictionModificationTransaction { - if (![AccountRestrictionType.AllowTransaction, AccountRestrictionType.BlockTransaction].includes(restrictionType)) { + if (![AccountRestrictionType.AllowIncomingTransactionType, + AccountRestrictionType.AllowOutgoingTransactionType, + AccountRestrictionType.BlockOutgoingTransactionType, + AccountRestrictionType.BlockOutgoingTransactionType].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } return AccountOperationRestrictionModificationTransaction.create( diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index 3e45e2f359..29d45b2c40 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -79,7 +79,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -89,7 +89,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); }); @@ -125,7 +125,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -134,7 +134,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType); expect(transaction.modifications[0].value).to.be.equal(operation); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -666,7 +666,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -675,7 +675,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(addressRestrictionTransaction.toJSON()) as AccountAddressRestrictionModificationTransaction; expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -708,7 +708,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -717,7 +717,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(operationRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); - expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType); expect(transaction.modifications.length).to.be.equal(1); }); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 2fe89a589a..1559522ba3 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -83,7 +83,7 @@ describe('SerializeTransactionToJSON', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -91,7 +91,7 @@ describe('SerializeTransactionToJSON', () => { const json = addressRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS); - expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -123,7 +123,7 @@ describe('SerializeTransactionToJSON', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -131,7 +131,7 @@ describe('SerializeTransactionToJSON', () => { const json = operationRestrictionTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); - expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction); + expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType); expect(json.transaction.modifications.length).to.be.equal(1); }); diff --git a/test/model/account/AccountRestriction.spec.ts b/test/model/account/AccountRestriction.spec.ts index d41a0e73a6..11defe8b1c 100644 --- a/test/model/account/AccountRestriction.spec.ts +++ b/test/model/account/AccountRestriction.spec.ts @@ -23,7 +23,7 @@ describe('AccountRestriction', () => { it('should createComplete an AccountRestriction object', () => { const accountRestrictionDTO = { - restrictionType: AccountRestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowIncomingAddress, values: ['906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'], }; diff --git a/test/model/account/AccountRestrictions.spec.ts b/test/model/account/AccountRestrictions.spec.ts index 8b30a7451b..0ed43b4f0b 100644 --- a/test/model/account/AccountRestrictions.spec.ts +++ b/test/model/account/AccountRestrictions.spec.ts @@ -25,7 +25,7 @@ describe('AccountRestrictions', () => { const accountRestrictionsDTO = { address: Address.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'), restrictions: [{ - restrictionType: AccountRestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowIncomingAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/account/AccountRestrictionsInfo.spec.ts b/test/model/account/AccountRestrictionsInfo.spec.ts index 981817bcea..f4291f2468 100644 --- a/test/model/account/AccountRestrictionsInfo.spec.ts +++ b/test/model/account/AccountRestrictionsInfo.spec.ts @@ -31,7 +31,7 @@ describe('AccountRestrictionsInfo', () => { accountRestrictions: { address: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', restrictions: [{ - restrictionType: AccountRestrictionType.AllowAddress, + restrictionType: AccountRestrictionType.AllowIncomingAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 8f83e951f3..59ccd31d5d 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -74,7 +74,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -105,7 +105,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -121,7 +121,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -138,7 +138,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -157,7 +157,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -241,7 +241,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - AccountRestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); From 77218582881675cd3ae3e0b3be8e79e42e9a1969 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 5 Aug 2019 14:41:38 +0100 Subject: [PATCH 33/98] Updated tests --- e2e/infrastructure/TransactionHttp.spec.ts | 161 ++++++++++++++++- .../AccountRestrictionTransaction.spec.ts | 162 +++++++++++++++--- 2 files changed, 299 insertions(+), 24 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 60ec20592d..5e22d114e3 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -387,7 +387,83 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Address', () => { + describe('AccountRestrictionTransaction - Outgoing Address', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + + it('standalone', (done) => { + const addressRestrictionFilter = AccountRestrictionModification.createForAddress( + RestrictionModificationType.Add, + account3.address, + ); + const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingAddress, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + const signedTransaction = addressModification.signWith(account, generationHash); + + listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionModificationTransaction) => { + expect(transaction.modifications, 'Modifications').not.to.be.undefined; + expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; + expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; + expect(transaction.restrictionType, 'RestrictionType').not.to.be.undefined; + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + describe('AccountRestrictionTransaction - Outgoing Address', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('aggregate', (done) => { + const addressRestrictionFilter = AccountRestrictionModification.createForAddress( + RestrictionModificationType.Remove, + account3.address, + ); + const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingAddress, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [addressModification.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + listener.confirmed(account.address).subscribe((transaction: Transaction) => { + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + + describe('AccountRestrictionTransaction - Incoming Address', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -425,7 +501,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Address', () => { + describe('AccountRestrictionTransaction - Incoming Address', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -537,7 +613,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Operation', () => { + describe('AccountRestrictionTransaction - Incoming Operation', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -575,7 +651,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Operation', () => { + describe('AccountRestrictionTransaction - Incoming Operation', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -612,6 +688,83 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); + + describe('AccountRestrictionTransaction - Outgoing Operation', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + + it('standalone', (done) => { + const operationRestrictionFilter = AccountRestrictionModification.createForOperation( + RestrictionModificationType.Add, + TransactionType.LINK_ACCOUNT, + ); + const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingTransactionType, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + const signedTransaction = addressModification.signWith(account3, generationHash); + + listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionModificationTransaction) => { + expect(transaction.modifications, 'Modifications').not.to.be.undefined; + expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; + expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; + expect(transaction.restrictionType, 'RestrictionType').not.to.be.undefined; + done(); + }); + listener.status(account3.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + describe('AccountRestrictionTransaction - Outgoing Operation', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('aggregate', (done) => { + const operationRestrictionFilter = AccountRestrictionModification.createForOperation( + RestrictionModificationType.Remove, + TransactionType.LINK_ACCOUNT, + ); + const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingTransactionType, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [addressModification.toAggregate(account3.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = aggregateTransaction.signWith(account3, generationHash); + listener.confirmed(account3.address).subscribe((transaction: Transaction) => { + done(); + }); + listener.status(account3.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + describe('AccountLinkTransaction', () => { let listener: Listener; before (() => { diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 59ccd31d5d..eeb10081ff 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -148,7 +148,7 @@ describe('AccountRestrictionTransaction', () => { expect(addressRestrictionTransaction.maxFee.lower).to.be.equal(1); }); - it('should create address restriction transaction', () => { + it('should create allow incmoing address restriction transaction', () => { const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); const addressRestrictionFilter = AccountRestrictionModification.createForAddress( @@ -179,15 +179,24 @@ describe('AccountRestrictionTransaction', () => { address, ); - expect(() => { - AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( - Deadline.create(), - AccountRestrictionType.Sentinel, - [addressRestrictionFilter], - NetworkType.MIJIN_TEST, - ); - }).to.throw(Error, 'Restriction type is not allowed.'); - + const invalidType = [AccountRestrictionType.AllowIncomingTransactionType, + AccountRestrictionType.AllowMosaic, + AccountRestrictionType.AllowOutgoingTransactionType, + AccountRestrictionType.BlockIncomingTransactionType, + AccountRestrictionType.BlockMosaic, + AccountRestrictionType.BlockOutgoingTransactionType, + AccountRestrictionType.Sentinel, + ]; + invalidType.forEach((type) => { + expect(() => { + AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + type, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'Restriction type is not allowed.'); + }); }); it('should create mosaic restriction transaction', () => { @@ -213,7 +222,7 @@ describe('AccountRestrictionTransaction', () => { }); - it('should throw exception when create mosaic restriction transaction with wrong type', () => { + it('should throw exception when create account mosaic restriction transaction with wrong type', () => { const mosaicId = new MosaicId([2262289484, 3405110546]); const mosaicRestrictionFilter = AccountRestrictionModification.createForMosaic( @@ -221,15 +230,26 @@ describe('AccountRestrictionTransaction', () => { mosaicId, ); - expect(() => { - AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( - Deadline.create(), - AccountRestrictionType.Sentinel, - [mosaicRestrictionFilter], - NetworkType.MIJIN_TEST, - ); - }).to.throw(Error, 'Restriction type is not allowed.'); - + const invalidType = [AccountRestrictionType.AllowIncomingTransactionType, + AccountRestrictionType.AllowIncomingAddress, + AccountRestrictionType.AllowOutgoingTransactionType, + AccountRestrictionType.BlockIncomingTransactionType, + AccountRestrictionType.AllowOutgoingAddress, + AccountRestrictionType.BlockOutgoingTransactionType, + AccountRestrictionType.BlockIncomingAddress, + AccountRestrictionType.BlockOutgoingAddress, + AccountRestrictionType.Sentinel, + ]; + invalidType.forEach((type) => { + expect(() => { + AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( + Deadline.create(), + type, + [mosaicRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'Restriction type is not allowed.'); + }); }); it('should create operation restriction transaction', () => { @@ -254,4 +274,106 @@ describe('AccountRestrictionTransaction', () => { )).to.be.equal('0401004E42'); }); + + it('should throw exception when create account operation restriction transaction with wrong type', () => { + + const operation = TransactionType.ADDRESS_ALIAS; + const operationRestrictionFilter = AccountRestrictionModification.createForOperation( + RestrictionModificationType.Add, + operation, + ); + + const invalidType = [AccountRestrictionType.AllowIncomingAddress, + AccountRestrictionType.AllowMosaic, + AccountRestrictionType.BlockMosaic, + AccountRestrictionType.AllowOutgoingAddress, + AccountRestrictionType.BlockIncomingAddress, + AccountRestrictionType.BlockOutgoingAddress, + AccountRestrictionType.Sentinel, + ]; + invalidType.forEach((type) => { + expect(() => { + AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + type, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'Restriction type is not allowed.'); + }); + }); + + it('should create outgoing address restriction transaction', () => { + + const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const addressRestrictionFilter = AccountRestrictionModification.createForAddress( + RestrictionModificationType.Add, + address, + ); + let addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.AllowOutgoingAddress, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + + let signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('4101009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + + addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingAddress, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + + signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('C101009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + + }); + + it('should create outgoing operation restriction transaction', () => { + + const operation = TransactionType.ADDRESS_ALIAS; + const operationRestrictionFilter = AccountRestrictionModification.createForOperation( + RestrictionModificationType.Add, + operation, + ); + let operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.AllowOutgoingTransactionType, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + + let signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('4401004E42'); + + operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( + Deadline.create(), + AccountRestrictionType.BlockOutgoingTransactionType, + [operationRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + + signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('C401004E42'); + + }); }); From 2583f86e16b14f15060d2538f1bdd25684491cfe Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 31 Jul 2019 19:33:40 +0100 Subject: [PATCH 34/98] Renamed RestrictionType to AccountRestrictionType --- e2e/infrastructure/AccountHttp.spec.ts | 5 +- src/model/account/AccountRestrictionType.ts | 97 --------------------- 2 files changed, 4 insertions(+), 98 deletions(-) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index ba12110edf..c8c2f0b13a 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -23,7 +23,6 @@ import { AccountRestrictionType } from '../../src/model/account/AccountRestricti import {Address} from '../../src/model/account/Address'; import {PublicAccount} from '../../src/model/account/PublicAccount'; import { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType'; -import { RestrictionType } from '../../src/model/account/RestrictionType'; import {NetworkType} from '../../src/model/blockchain/NetworkType'; import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; import { AliasAction } from '../../src/model/namespace/AliasAction'; @@ -427,7 +426,11 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), +<<<<<<< HEAD AccountRestrictionType.BlockIncomingAddress, +======= + AccountRestrictionType.BlockAddress, +>>>>>>> Renamed RestrictionType to AccountRestrictionType [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/src/model/account/AccountRestrictionType.ts b/src/model/account/AccountRestrictionType.ts index 757c1fde75..e69de29bb2 100644 --- a/src/model/account/AccountRestrictionType.ts +++ b/src/model/account/AccountRestrictionType.ts @@ -1,97 +0,0 @@ -/* - * 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. - */ - -/** - * Account restriction type - * 0x01 Account restriction type is an address. - * 0x02 Account restriction type is a mosaic id. - * 0x04 Account restriction type is a transaction type. - * 0x05 restriction type sentinel. - * 0x40 Account restriction is interpreted as outgoing restriction. - * 0x80 Account restriction is interpreted as blocking operation. - */ - - // !!This enum will be deprecated once catbuffer code applied. -enum AccountRestrictionTypeEnum { - Address = 0x01, - Mosaic = 0x02, - TransactionType = 0x04, - Sentinel = 0x05, - Outgoing = 0x40, - Block = 0x80, -} - -export enum AccountRestrictionType { - /** - * Allow only incoming transactions from a given address. - */ - AllowIncomingAddress = AccountRestrictionTypeEnum.Address, - - /** - * Allow only incoming transactions containing a a given mosaic identifier. - */ - AllowMosaic = AccountRestrictionTypeEnum.Mosaic, - - /** - * Allow only outgoing transactions with a given transaction type. - */ - AllowIncomingTransactionType = AccountRestrictionTypeEnum.TransactionType, - - /** - * Allow only outgoing transactions to a given address. - */ - AllowOutgoingAddress = (AccountRestrictionTypeEnum.Address + AccountRestrictionTypeEnum.Outgoing), - - /** - * Allow only outgoing transactions with a given transaction type. - */ - AllowOutgoingTransactionType = (AccountRestrictionTypeEnum.TransactionType + - AccountRestrictionTypeEnum.Outgoing), - - /** - * Block incoming transactions from a given address. - */ - BlockIncomingAddress = (AccountRestrictionTypeEnum.Address + AccountRestrictionTypeEnum.Block), - - /** - * Block incoming transactions containing a given mosaic identifier. - */ - BlockMosaic = (AccountRestrictionTypeEnum.Mosaic + AccountRestrictionTypeEnum.Block), - - /** - * Block incoming transactions with a given transaction type. - */ - BlockIncomingTransactionType = (AccountRestrictionTypeEnum.TransactionType + - AccountRestrictionTypeEnum.Block), - - /** - * Block outgoing transactions from a given address. - */ - BlockOutgoingAddress = (AccountRestrictionTypeEnum.Address + - AccountRestrictionTypeEnum.Block + - AccountRestrictionTypeEnum.Outgoing), - /** - * Block outgoing transactions with a given transaction type. - */ - BlockOutgoingTransactionType = (AccountRestrictionTypeEnum.TransactionType + - AccountRestrictionTypeEnum.Block + - AccountRestrictionTypeEnum.Outgoing), - - /** - * Account restriction sentinel. - */ - Sentinel = AccountRestrictionTypeEnum.Sentinel, -} From c62ab70abda9ddec48f0c0f16e7da6555c5234d7 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 2 Aug 2019 10:15:35 +0100 Subject: [PATCH 35/98] Refactored AccountRestrictionType --- e2e/infrastructure/AccountHttp.spec.ts | 4 + src/model/account/AccountRestrictionType.ts | 97 +++++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index c8c2f0b13a..4d14a03a82 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -426,11 +426,15 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), +<<<<<<< HEAD <<<<<<< HEAD AccountRestrictionType.BlockIncomingAddress, ======= AccountRestrictionType.BlockAddress, >>>>>>> Renamed RestrictionType to AccountRestrictionType +======= + AccountRestrictionType.BlockIncomingAddress, +>>>>>>> Refactored AccountRestrictionType [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/src/model/account/AccountRestrictionType.ts b/src/model/account/AccountRestrictionType.ts index e69de29bb2..757c1fde75 100644 --- a/src/model/account/AccountRestrictionType.ts +++ b/src/model/account/AccountRestrictionType.ts @@ -0,0 +1,97 @@ +/* + * 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. + */ + +/** + * Account restriction type + * 0x01 Account restriction type is an address. + * 0x02 Account restriction type is a mosaic id. + * 0x04 Account restriction type is a transaction type. + * 0x05 restriction type sentinel. + * 0x40 Account restriction is interpreted as outgoing restriction. + * 0x80 Account restriction is interpreted as blocking operation. + */ + + // !!This enum will be deprecated once catbuffer code applied. +enum AccountRestrictionTypeEnum { + Address = 0x01, + Mosaic = 0x02, + TransactionType = 0x04, + Sentinel = 0x05, + Outgoing = 0x40, + Block = 0x80, +} + +export enum AccountRestrictionType { + /** + * Allow only incoming transactions from a given address. + */ + AllowIncomingAddress = AccountRestrictionTypeEnum.Address, + + /** + * Allow only incoming transactions containing a a given mosaic identifier. + */ + AllowMosaic = AccountRestrictionTypeEnum.Mosaic, + + /** + * Allow only outgoing transactions with a given transaction type. + */ + AllowIncomingTransactionType = AccountRestrictionTypeEnum.TransactionType, + + /** + * Allow only outgoing transactions to a given address. + */ + AllowOutgoingAddress = (AccountRestrictionTypeEnum.Address + AccountRestrictionTypeEnum.Outgoing), + + /** + * Allow only outgoing transactions with a given transaction type. + */ + AllowOutgoingTransactionType = (AccountRestrictionTypeEnum.TransactionType + + AccountRestrictionTypeEnum.Outgoing), + + /** + * Block incoming transactions from a given address. + */ + BlockIncomingAddress = (AccountRestrictionTypeEnum.Address + AccountRestrictionTypeEnum.Block), + + /** + * Block incoming transactions containing a given mosaic identifier. + */ + BlockMosaic = (AccountRestrictionTypeEnum.Mosaic + AccountRestrictionTypeEnum.Block), + + /** + * Block incoming transactions with a given transaction type. + */ + BlockIncomingTransactionType = (AccountRestrictionTypeEnum.TransactionType + + AccountRestrictionTypeEnum.Block), + + /** + * Block outgoing transactions from a given address. + */ + BlockOutgoingAddress = (AccountRestrictionTypeEnum.Address + + AccountRestrictionTypeEnum.Block + + AccountRestrictionTypeEnum.Outgoing), + /** + * Block outgoing transactions with a given transaction type. + */ + BlockOutgoingTransactionType = (AccountRestrictionTypeEnum.TransactionType + + AccountRestrictionTypeEnum.Block + + AccountRestrictionTypeEnum.Outgoing), + + /** + * Account restriction sentinel. + */ + Sentinel = AccountRestrictionTypeEnum.Sentinel, +} From ed196f2820a412304606ff090860df931a940c9d Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 20 Aug 2019 20:13:14 +0100 Subject: [PATCH 36/98] Fixed merge issues --- e2e/infrastructure/AccountHttp.spec.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 4d14a03a82..c190d8c0ae 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -426,15 +426,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), -<<<<<<< HEAD -<<<<<<< HEAD AccountRestrictionType.BlockIncomingAddress, -======= - AccountRestrictionType.BlockAddress, ->>>>>>> Renamed RestrictionType to AccountRestrictionType -======= - AccountRestrictionType.BlockIncomingAddress, ->>>>>>> Refactored AccountRestrictionType [addressPropertyFilter], NetworkType.MIJIN_TEST, ); From 960def5f5fdc460948103c7a7fdb715fa07cfc57 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 21:43:04 +0100 Subject: [PATCH 37/98] Added ts catbuffer codes (without aggregateTx) Appended new signwithCatbuffer method in Transaction (temp) Applied catbuffer builders on standalone transaction (builder) Updated unit tests --- e2e/infrastructure/TransactionHttp.spec.ts | 12 +- src/infrastructure/QueryParams.ts | 1 - .../AccountRestrictionsAddressTransaction.ts | 2 +- ...ccountRestrictionsEntityTypeTransaction.ts | 2 +- .../AccountRestrictionsMosaicTransaction.ts | 2 +- ...ntAddressRestrictionModificationBuilder.ts | 91 ++++++++ ...ddressRestrictionTransactionBodyBuilder.ts | 114 ++++++++++ ...untAddressRestrictionTransactionBuilder.ts | 116 +++++++++++ .../catbuffer/AccountLinkActionDto.ts | 29 +++ .../AccountLinkTransactionBodyBuilder.ts | 102 +++++++++ .../AccountLinkTransactionBuilder.ts | 113 ++++++++++ .../AccountMetadataTransactionBodyBuilder.ts | 147 +++++++++++++ .../AccountMetadataTransactionBuilder.ts | 139 +++++++++++++ ...untMosaicRestrictionModificationBuilder.ts | 91 ++++++++ ...MosaicRestrictionTransactionBodyBuilder.ts | 114 ++++++++++ ...ountMosaicRestrictionTransactionBuilder.ts | 116 +++++++++++ ...OperationRestrictionModificationBuilder.ts | 91 ++++++++ ...rationRestrictionTransactionBodyBuilder.ts | 114 ++++++++++ ...tOperationRestrictionTransactionBuilder.ts | 116 +++++++++++ ...AccountRestrictionModificationActionDto.ts | 29 +++ .../AccountRestrictionModificationBuilder.ts | 83 ++++++++ .../catbuffer/AccountRestrictionTypeDto.ts | 35 ++++ .../AddressAliasTransactionBodyBuilder.ts | 121 +++++++++++ .../AddressAliasTransactionBuilder.ts | 125 +++++++++++ src/infrastructure/catbuffer/AddressDto.ts | 79 +++++++ .../catbuffer/AliasActionDto.ts | 29 +++ src/infrastructure/catbuffer/AmountDto.ts | 80 ++++++++ .../catbuffer/BlockDurationDto.ts | 80 ++++++++ .../CosignatoryModificationActionDto.ts | 29 +++ .../CosignatoryModificationBuilder.ts | 102 +++++++++ ...untAddressRestrictionTransactionBuilder.ts | 110 ++++++++++ .../EmbeddedAccountLinkTransactionBuilder.ts | 107 ++++++++++ ...beddedAccountMetadataTransactionBuilder.ts | 133 ++++++++++++ ...ountMosaicRestrictionTransactionBuilder.ts | 110 ++++++++++ ...tOperationRestrictionTransactionBuilder.ts | 110 ++++++++++ .../EmbeddedAddressAliasTransactionBuilder.ts | 119 +++++++++++ .../EmbeddedHashLockTransactionBuilder.ts | 119 +++++++++++ ...aicAddressRestrictionTransactionBuilder.ts | 140 +++++++++++++ .../EmbeddedMosaicAliasTransactionBuilder.ts | 119 +++++++++++ ...eddedMosaicDefinitionTransactionBuilder.ts | 141 +++++++++++++ ...saicGlobalRestrictionTransactionBuilder.ts | 160 +++++++++++++++ ...mbeddedMosaicMetadataTransactionBuilder.ts | 144 +++++++++++++ ...dedMosaicSupplyChangeTransactionBuilder.ts | 120 +++++++++++ ...igAccountModificationTransactionBuilder.ts | 119 +++++++++++ ...ddedNamespaceMetadataTransactionBuilder.ts | 145 +++++++++++++ ...NamespaceRegistrationTransactionBuilder.ts | 143 +++++++++++++ .../EmbeddedSecretLockTransactionBuilder.ts | 142 +++++++++++++ .../EmbeddedSecretProofTransactionBuilder.ts | 129 ++++++++++++ .../catbuffer/EmbeddedTransactionBuilder.ts | 127 ++++++++++++ .../EmbeddedTransferTransactionBuilder.ts | 118 +++++++++++ src/infrastructure/catbuffer/EntityTypeDto.ts | 133 ++++++++++++ .../catbuffer/GeneratorUtils.ts | 141 +++++++++++++ src/infrastructure/catbuffer/Hash256Dto.ts | 79 +++++++ src/infrastructure/catbuffer/Hash512Dto.ts | 79 +++++++ .../HashLockTransactionBodyBuilder.ts | 121 +++++++++++ .../catbuffer/HashLockTransactionBuilder.ts | 125 +++++++++++ src/infrastructure/catbuffer/KeyDto.ts | 79 +++++++ .../catbuffer/LockHashAlgorithmDto.ts | 33 +++ ...ddressRestrictionTransactionBodyBuilder.ts | 158 ++++++++++++++ ...aicAddressRestrictionTransactionBuilder.ts | 146 +++++++++++++ .../MosaicAliasTransactionBodyBuilder.ts | 121 +++++++++++ .../MosaicAliasTransactionBuilder.ts | 125 +++++++++++ src/infrastructure/catbuffer/MosaicBuilder.ts | 102 +++++++++ .../MosaicDefinitionTransactionBodyBuilder.ts | 158 ++++++++++++++ .../MosaicDefinitionTransactionBuilder.ts | 147 +++++++++++++ .../catbuffer/MosaicFlagsDto.ts | 33 +++ ...GlobalRestrictionTransactionBodyBuilder.ts | 194 ++++++++++++++++++ ...saicGlobalRestrictionTransactionBuilder.ts | 166 +++++++++++++++ src/infrastructure/catbuffer/MosaicIdDto.ts | 80 ++++++++ .../MosaicMetadataTransactionBodyBuilder.ts | 168 +++++++++++++++ .../MosaicMetadataTransactionBuilder.ts | 150 ++++++++++++++ .../catbuffer/MosaicNonceDto.ts | 80 ++++++++ .../catbuffer/MosaicRestrictionTypeDto.ts | 39 ++++ .../catbuffer/MosaicSupplyChangeActionDto.ts | 29 +++ ...osaicSupplyChangeTransactionBodyBuilder.ts | 121 +++++++++++ .../MosaicSupplyChangeTransactionBuilder.ts | 125 +++++++++++ ...countModificationTransactionBodyBuilder.ts | 131 ++++++++++++ ...igAccountModificationTransactionBuilder.ts | 125 +++++++++++ .../catbuffer/NamespaceIdDto.ts | 80 ++++++++ ...NamespaceMetadataTransactionBodyBuilder.ts | 168 +++++++++++++++ .../NamespaceMetadataTransactionBuilder.ts | 151 ++++++++++++++ ...spaceRegistrationTransactionBodyBuilder.ts | 188 +++++++++++++++++ ...NamespaceRegistrationTransactionBuilder.ts | 149 ++++++++++++++ .../catbuffer/NamespaceRegistrationTypeDto.ts | 29 +++ .../SecretLockTransactionBodyBuilder.ts | 160 +++++++++++++++ .../catbuffer/SecretLockTransactionBuilder.ts | 148 +++++++++++++ .../SecretProofTransactionBodyBuilder.ts | 144 +++++++++++++ .../SecretProofTransactionBuilder.ts | 135 ++++++++++++ src/infrastructure/catbuffer/SignatureDto.ts | 79 +++++++ src/infrastructure/catbuffer/TimestampDto.ts | 80 ++++++++ .../catbuffer/TransactionBuilder.ts | 185 +++++++++++++++++ .../TransferTransactionBodyBuilder.ts | 135 ++++++++++++ .../catbuffer/TransferTransactionBuilder.ts | 124 +++++++++++ .../catbuffer/UnresolvedAddressDto.ts | 79 +++++++ .../catbuffer/UnresolvedMosaicBuilder.ts | 102 +++++++++ .../catbuffer/UnresolvedMosaicIdDto.ts | 80 ++++++++ .../transaction/CreateTransactionFromDTO.ts | 18 +- .../CreateTransactionFromPayload.ts | 24 +-- .../transaction/SerializeTransactionToJSON.ts | 24 +-- src/model/model.ts | 6 +- src/model/mosaic/MosaicFlag.ts | 25 +++ ...> AccountAddressRestrictionTransaction.ts} | 50 ++++- .../transaction/AccountLinkTransaction.ts | 27 +++ ...=> AccountMosaicRestrictionTransaction.ts} | 49 ++++- ...AccountOperationRestrictionTransaction.ts} | 46 ++++- .../AccountRestrictionTransaction.ts | 22 +- .../transaction/AddressAliasTransaction.ts | 30 +++ src/model/transaction/AggregateTransaction.ts | 10 +- src/model/transaction/LockFundsTransaction.ts | 7 + .../ModifyMultisigAccountTransaction.ts | 35 +++- .../MosaicAddressRestrictionTransaction.ts | 7 + .../transaction/MosaicAliasTransaction.ts | 29 +++ .../MosaicDefinitionTransaction.ts | 68 ++++++ .../MosaicGlobalRestrictionTransaction.ts | 7 + .../MosaicSupplyChangeTransaction.ts | 27 +++ .../RegisterNamespaceTransaction.ts | 7 + .../transaction/SecretLockTransaction.ts | 46 ++++- .../transaction/SecretProofTransaction.ts | 50 ++++- src/model/transaction/Transaction.ts | 62 +++++- src/model/transaction/TransactionType.ts | 42 ++-- src/model/transaction/TransactionVersion.ts | 4 +- src/model/transaction/TransferTransaction.ts | 61 +++++- test/core/utils/TransactionMapping.spec.ts | 21 +- .../SerializeTransactionToJSON.spec.ts | 6 +- .../AccountLinkTransaction.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 12 +- .../AddressAliasTransaction.spec.ts | 2 +- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- .../MosaicAliasTransaction.spec.ts | 4 +- .../MosaicDefinitionTransaction.spec.ts | 4 +- .../transaction/SecretLockTransaction.spec.ts | 31 ++- .../SecretProofTransaction.spec.ts | 22 +- test/model/transaction/Transaction.spec.ts | 4 + .../transaction/TransferTransaction.spec.ts | 28 ++- 134 files changed, 11044 insertions(+), 140 deletions(-) create mode 100644 src/infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountLinkActionDto.ts create mode 100644 src/infrastructure/catbuffer/AccountLinkTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountLinkTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMetadataTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountRestrictionModificationActionDto.ts create mode 100644 src/infrastructure/catbuffer/AccountRestrictionModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountRestrictionTypeDto.ts create mode 100644 src/infrastructure/catbuffer/AddressAliasTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AddressAliasTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AddressDto.ts create mode 100644 src/infrastructure/catbuffer/AliasActionDto.ts create mode 100644 src/infrastructure/catbuffer/AmountDto.ts create mode 100644 src/infrastructure/catbuffer/BlockDurationDto.ts create mode 100644 src/infrastructure/catbuffer/CosignatoryModificationActionDto.ts create mode 100644 src/infrastructure/catbuffer/CosignatoryModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedTransferTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EntityTypeDto.ts create mode 100644 src/infrastructure/catbuffer/GeneratorUtils.ts create mode 100644 src/infrastructure/catbuffer/Hash256Dto.ts create mode 100644 src/infrastructure/catbuffer/Hash512Dto.ts create mode 100644 src/infrastructure/catbuffer/HashLockTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/HashLockTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/KeyDto.ts create mode 100644 src/infrastructure/catbuffer/LockHashAlgorithmDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicAliasTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicAliasTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicDefinitionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicDefinitionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicFlagsDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicIdDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicMetadataTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicNonceDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicRestrictionTypeDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicSupplyChangeActionDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MultisigAccountModificationTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceIdDto.ts create mode 100644 src/infrastructure/catbuffer/NamespaceMetadataTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceRegistrationTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceRegistrationTypeDto.ts create mode 100644 src/infrastructure/catbuffer/SecretLockTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/SecretLockTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/SecretProofTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/SecretProofTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/SignatureDto.ts create mode 100644 src/infrastructure/catbuffer/TimestampDto.ts create mode 100644 src/infrastructure/catbuffer/TransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/TransferTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/TransferTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/UnresolvedAddressDto.ts create mode 100644 src/infrastructure/catbuffer/UnresolvedMosaicBuilder.ts create mode 100644 src/infrastructure/catbuffer/UnresolvedMosaicIdDto.ts create mode 100644 src/model/mosaic/MosaicFlag.ts rename src/model/transaction/{AccountAddressRestrictionModificationTransaction.ts => AccountAddressRestrictionTransaction.ts} (64%) rename src/model/transaction/{AccountMosaicRestrictionModificationTransaction.ts => AccountMosaicRestrictionTransaction.ts} (65%) rename src/model/transaction/{AccountOperationRestrictionModificationTransaction.ts => AccountOperationRestrictionTransaction.ts} (67%) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 2ad8b0be8d..d15c87fd4b 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -37,10 +37,10 @@ import {MosaicSupplyType} from '../../src/model/mosaic/MosaicSupplyType'; import {NetworkCurrencyMosaic} from '../../src/model/mosaic/NetworkCurrencyMosaic'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; -import { AccountAddressRestrictionModificationTransaction } from '../../src/model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from '../../src/model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../src/model/transaction/AccountLinkTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from '../../src/model/transaction/AccountMosaicRestrictionModificationTransaction'; -import { AccountOperationRestrictionModificationTransaction } from '../../src/model/transaction/AccountOperationRestrictionModificationTransaction'; +import { AccountMosaicRestrictionTransaction } from '../../src/model/transaction/AccountMosaicRestrictionTransaction'; +import { AccountOperationRestrictionTransaction } from '../../src/model/transaction/AccountOperationRestrictionTransaction'; import { AccountRestrictionModification } from '../../src/model/transaction/AccountRestrictionModification'; import { AccountRestrictionTransaction } from '../../src/model/transaction/AccountRestrictionTransaction'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; @@ -410,7 +410,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = addressModification.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionModificationTransaction) => { + listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionTransaction) => { expect(transaction.modifications, 'Modifications').not.to.be.undefined; expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; @@ -485,7 +485,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = addressModification.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AccountMosaicRestrictionModificationTransaction) => { + listener.confirmed(account.address).subscribe((transaction: AccountMosaicRestrictionTransaction) => { expect(transaction.modifications, 'Modifications').not.to.be.undefined; expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; @@ -560,7 +560,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = addressModification.signWith(account3, generationHash); - listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionModificationTransaction) => { + listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionTransaction) => { expect(transaction.modifications, 'Modifications').not.to.be.undefined; expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; diff --git a/src/infrastructure/QueryParams.ts b/src/infrastructure/QueryParams.ts index b1644cf2b3..ee41206d80 100644 --- a/src/infrastructure/QueryParams.ts +++ b/src/infrastructure/QueryParams.ts @@ -22,7 +22,6 @@ export enum Order { DESC = '-id', } - /** * The query params structure describes pagination params for requests. * diff --git a/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts b/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts index 452e4c30b7..bd355c6b94 100644 --- a/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts +++ b/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts @@ -45,7 +45,7 @@ export class Builder { modifications: any; constructor() { this.maxFee = [0, 0]; - this.type = TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS; + this.type = TransactionType.ACCOUNT_RESTRICTION_ADDRESS; } addFee(maxFee) { diff --git a/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts b/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts index edfed292ba..6973e8ccc4 100644 --- a/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts +++ b/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts @@ -45,7 +45,7 @@ export class Builder { modifications: any; constructor() { this.maxFee = [0, 0]; - this.type = TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION; + this.type = TransactionType.ACCOUNT_RESTRICTION_OPERATION; } addFee(maxFee) { diff --git a/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts b/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts index ec97bcc02e..da9338deb4 100644 --- a/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts +++ b/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts @@ -45,7 +45,7 @@ export class Builder { modifications: any; constructor() { this.maxFee = [0, 0]; - this.type = TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC; + this.type = TransactionType.ACCOUNT_RESTRICTION_MOSAIC; } addFee(maxFee) { diff --git a/src/infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder.ts b/src/infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder.ts new file mode 100644 index 0000000000..b8c508eb76 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder.ts @@ -0,0 +1,91 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountRestrictionModificationActionDto } from './AccountRestrictionModificationActionDto'; +import { AccountRestrictionModificationBuilder } from './AccountRestrictionModificationBuilder'; +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; + +/** Account address restriction modification. */ +export class AccountAddressRestrictionModificationBuilder extends AccountRestrictionModificationBuilder { + /** Address restriction value. */ + value: UnresolvedAddressDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + * @param value Address restriction value. + */ + public constructor(modificationAction: AccountRestrictionModificationActionDto, value: UnresolvedAddressDto) { + super(modificationAction); + this.value = value; + } + + /** + * Creates an instance of AccountAddressRestrictionModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountAddressRestrictionModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountAddressRestrictionModificationBuilder { + const byteArray = Array.from(payload); + const superObject = AccountRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const value = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, value.getSize()); + return new AccountAddressRestrictionModificationBuilder(superObject.modificationAction, value); + } + + /** + * Gets address restriction value. + * + * @return Address restriction value. + */ + public getValue(): UnresolvedAddressDto { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.value.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const valueBytes = this.value.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..fcc36e1509 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,114 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountAddressRestrictionModificationBuilder } from './AccountAddressRestrictionModificationBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for an account address restriction transaction. */ +export class AccountAddressRestrictionTransactionBodyBuilder { + /** Account restriction type. */ + restrictionType: AccountRestrictionTypeDto; + /** Account restriction modifications. */ + modifications: AccountAddressRestrictionModificationBuilder[]; + + /** + * Constructor. + * + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(restrictionType: AccountRestrictionTypeDto, modifications: AccountAddressRestrictionModificationBuilder[]) { + this.restrictionType = restrictionType; + this.modifications = modifications; + } + + /** + * Creates an instance of AccountAddressRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountAddressRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountAddressRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const restrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modificationsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modifications: AccountAddressRestrictionModificationBuilder[] = []; + for (let i = 0; i < modificationsCount; i++) { + const item = AccountAddressRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + modifications.push(item); + byteArray.splice(0, item.getSize()); + } + return new AccountAddressRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.restrictionType; + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountAddressRestrictionModificationBuilder[] { + return this.modifications; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // restrictionType + size += 1; // modificationsCount + this.modifications.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const restrictionTypeBytes = GeneratorUtils.uintToBuffer(this.restrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionTypeBytes); + const modificationsCountBytes = GeneratorUtils.uintToBuffer(this.modifications.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsCountBytes); + this.modifications.forEach((item) => { + const modificationsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..a20f98b7c6 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder.ts @@ -0,0 +1,116 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountAddressRestrictionModificationBuilder } from './AccountAddressRestrictionModificationBuilder'; +import { AccountAddressRestrictionTransactionBodyBuilder } from './AccountAddressRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account address restriction transaction. */ +export class AccountAddressRestrictionTransactionBuilder extends TransactionBuilder { + /** Account address restriction transaction body. */ + accountAddressRestrictionTransactionBody: AccountAddressRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountAddressRestrictionModificationBuilder[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.accountAddressRestrictionTransactionBody = new AccountAddressRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of AccountAddressRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountAddressRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountAddressRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountAddressRestrictionTransactionBody = AccountAddressRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountAddressRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountAddressRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountAddressRestrictionTransactionBody.restrictionType, accountAddressRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountAddressRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountAddressRestrictionModificationBuilder[] { + return this.accountAddressRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountAddressRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountAddressRestrictionTransactionBodyBytes = this.accountAddressRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountAddressRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountLinkActionDto.ts b/src/infrastructure/catbuffer/AccountLinkActionDto.ts new file mode 100644 index 0000000000..196ab88465 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountLinkActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of account link actions. */ +export enum AccountLinkActionDto { + /** Unlink account. */ + UNLINK = 0, + /** Link account. */ + LINK = 1, +} diff --git a/src/infrastructure/catbuffer/AccountLinkTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountLinkTransactionBodyBuilder.ts new file mode 100644 index 0000000000..bddb0b8579 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountLinkTransactionBodyBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountLinkActionDto } from './AccountLinkActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an account link transaction. */ +export class AccountLinkTransactionBodyBuilder { + /** Remote account public key. */ + remoteAccountPublicKey: KeyDto; + /** Account link action. */ + linkAction: AccountLinkActionDto; + + /** + * Constructor. + * + * @param remoteAccountPublicKey Remote account public key. + * @param linkAction Account link action. + */ + public constructor(remoteAccountPublicKey: KeyDto, linkAction: AccountLinkActionDto) { + this.remoteAccountPublicKey = remoteAccountPublicKey; + this.linkAction = linkAction; + } + + /** + * Creates an instance of AccountLinkTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountLinkTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountLinkTransactionBodyBuilder { + const byteArray = Array.from(payload); + const remoteAccountPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, remoteAccountPublicKey.getSize()); + const linkAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + return new AccountLinkTransactionBodyBuilder(remoteAccountPublicKey, linkAction); + } + + /** + * Gets remote account public key. + * + * @return Remote account public key. + */ + public getRemoteAccountPublicKey(): KeyDto { + return this.remoteAccountPublicKey; + } + + /** + * Gets account link action. + * + * @return Account link action. + */ + public getLinkAction(): AccountLinkActionDto { + return this.linkAction; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.remoteAccountPublicKey.getSize(); + size += 1; // linkAction + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const remoteAccountPublicKeyBytes = this.remoteAccountPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, remoteAccountPublicKeyBytes); + const linkActionBytes = GeneratorUtils.uintToBuffer(this.linkAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, linkActionBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountLinkTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountLinkTransactionBuilder.ts new file mode 100644 index 0000000000..13aecd9155 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountLinkTransactionBuilder.ts @@ -0,0 +1,113 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountLinkActionDto } from './AccountLinkActionDto'; +import { AccountLinkTransactionBodyBuilder } from './AccountLinkTransactionBodyBuilder'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account link transaction. */ +export class AccountLinkTransactionBuilder extends TransactionBuilder { + /** Account link transaction body. */ + accountLinkTransactionBody: AccountLinkTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param remoteAccountPublicKey Remote account public key. + * @param linkAction Account link action. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, remoteAccountPublicKey: KeyDto, linkAction: AccountLinkActionDto) { + super(signature, signer, version, type, fee, deadline); + this.accountLinkTransactionBody = new AccountLinkTransactionBodyBuilder(remoteAccountPublicKey, linkAction); + } + + /** + * Creates an instance of AccountLinkTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountLinkTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountLinkTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const accountLinkTransactionBody = AccountLinkTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountLinkTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountLinkTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountLinkTransactionBody.remoteAccountPublicKey, accountLinkTransactionBody.linkAction); + } + + /** + * Gets remote account public key. + * + * @return Remote account public key. + */ + public getRemoteAccountPublicKey(): KeyDto { + return this.accountLinkTransactionBody.getRemoteAccountPublicKey(); + } + + /** + * Gets account link action. + * + * @return Account link action. + */ + public getLinkAction(): AccountLinkActionDto { + return this.accountLinkTransactionBody.getLinkAction(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountLinkTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountLinkTransactionBodyBytes = this.accountLinkTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountLinkTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMetadataTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountMetadataTransactionBodyBuilder.ts new file mode 100644 index 0000000000..32353f22c9 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMetadataTransactionBodyBuilder.ts @@ -0,0 +1,147 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an account metadata transaction. */ +export class AccountMetadataTransactionBodyBuilder { + /** Metadata target public key. */ + targetPublicKey: KeyDto; + /** Metadata key scoped to source, target and type. */ + scopedMetadataKey: number[]; + /** Change in value size in bytes. */ + valueSizeDelta: number; + /** Difference between existing value and new value \note when there is no existing value, new value is same this value \note when there is an existing value, new value is calculated as xor(previous-value, value). */ + value: Uint8Array; + + /** + * Constructor. + * + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public constructor(targetPublicKey: KeyDto, scopedMetadataKey: number[], valueSizeDelta: number, value: Uint8Array) { + this.targetPublicKey = targetPublicKey; + this.scopedMetadataKey = scopedMetadataKey; + this.valueSizeDelta = valueSizeDelta; + this.value = value; + } + + /** + * Creates an instance of AccountMetadataTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMetadataTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMetadataTransactionBodyBuilder { + const byteArray = Array.from(payload); + const targetPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetPublicKey.getSize()); + const scopedMetadataKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const valueSizeDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const valueSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const value = GeneratorUtils.getBytes(Uint8Array.from(byteArray), valueSize); + byteArray.splice(0, valueSize); + return new AccountMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, valueSizeDelta, value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.targetPublicKey; + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.scopedMetadataKey; + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.valueSizeDelta; + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.targetPublicKey.getSize(); + size += 8; // scopedMetadataKey + size += 2; // valueSizeDelta + size += 2; // valueSize + size += this.value.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const targetPublicKeyBytes = this.targetPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetPublicKeyBytes); + const scopedMetadataKeyBytes = GeneratorUtils.uint64ToBuffer(this.getScopedMetadataKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, scopedMetadataKeyBytes); + const valueSizeDeltaBytes = GeneratorUtils.uintToBuffer(this.getValueSizeDelta(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeDeltaBytes); + const valueSizeBytes = GeneratorUtils.uintToBuffer(this.value.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.value); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..84daaea40a --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMetadataTransactionBuilder.ts @@ -0,0 +1,139 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMetadataTransactionBodyBuilder } from './AccountMetadataTransactionBodyBuilder'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account metadata transaction. */ +export class AccountMetadataTransactionBuilder extends TransactionBuilder { + /** Account metadata transaction body. */ + accountMetadataTransactionBody: AccountMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], valueSizeDelta: number, value: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.accountMetadataTransactionBody = new AccountMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, valueSizeDelta, value); + } + + /** + * Creates an instance of AccountMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const accountMetadataTransactionBody = AccountMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountMetadataTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountMetadataTransactionBody.targetPublicKey, accountMetadataTransactionBody.scopedMetadataKey, accountMetadataTransactionBody.valueSizeDelta, accountMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.accountMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.accountMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.accountMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.accountMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountMetadataTransactionBodyBytes = this.accountMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder.ts b/src/infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder.ts new file mode 100644 index 0000000000..29abdc38c8 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder.ts @@ -0,0 +1,91 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountRestrictionModificationActionDto } from './AccountRestrictionModificationActionDto'; +import { AccountRestrictionModificationBuilder } from './AccountRestrictionModificationBuilder'; +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Account mosaic restriction modification. */ +export class AccountMosaicRestrictionModificationBuilder extends AccountRestrictionModificationBuilder { + /** Mosaic identifier restriction value. */ + value: UnresolvedMosaicIdDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + * @param value Mosaic identifier restriction value. + */ + public constructor(modificationAction: AccountRestrictionModificationActionDto, value: UnresolvedMosaicIdDto) { + super(modificationAction); + this.value = value; + } + + /** + * Creates an instance of AccountMosaicRestrictionModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMosaicRestrictionModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMosaicRestrictionModificationBuilder { + const byteArray = Array.from(payload); + const superObject = AccountRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const value = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, value.getSize()); + return new AccountMosaicRestrictionModificationBuilder(superObject.modificationAction, value); + } + + /** + * Gets mosaic identifier restriction value. + * + * @return Mosaic identifier restriction value. + */ + public getValue(): UnresolvedMosaicIdDto { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.value.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const valueBytes = this.value.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..c094bdc1c2 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,114 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMosaicRestrictionModificationBuilder } from './AccountMosaicRestrictionModificationBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for an account mosaic restriction transaction. */ +export class AccountMosaicRestrictionTransactionBodyBuilder { + /** Account restriction type. */ + restrictionType: AccountRestrictionTypeDto; + /** Account restriction modifications. */ + modifications: AccountMosaicRestrictionModificationBuilder[]; + + /** + * Constructor. + * + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(restrictionType: AccountRestrictionTypeDto, modifications: AccountMosaicRestrictionModificationBuilder[]) { + this.restrictionType = restrictionType; + this.modifications = modifications; + } + + /** + * Creates an instance of AccountMosaicRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMosaicRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMosaicRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const restrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modificationsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modifications: AccountMosaicRestrictionModificationBuilder[] = []; + for (let i = 0; i < modificationsCount; i++) { + const item = AccountMosaicRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + modifications.push(item); + byteArray.splice(0, item.getSize()); + } + return new AccountMosaicRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.restrictionType; + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountMosaicRestrictionModificationBuilder[] { + return this.modifications; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // restrictionType + size += 1; // modificationsCount + this.modifications.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const restrictionTypeBytes = GeneratorUtils.uintToBuffer(this.restrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionTypeBytes); + const modificationsCountBytes = GeneratorUtils.uintToBuffer(this.modifications.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsCountBytes); + this.modifications.forEach((item) => { + const modificationsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..8b2f79a57e --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder.ts @@ -0,0 +1,116 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMosaicRestrictionModificationBuilder } from './AccountMosaicRestrictionModificationBuilder'; +import { AccountMosaicRestrictionTransactionBodyBuilder } from './AccountMosaicRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account mosaic restriction transaction. */ +export class AccountMosaicRestrictionTransactionBuilder extends TransactionBuilder { + /** Account mosaic restriction transaction body. */ + accountMosaicRestrictionTransactionBody: AccountMosaicRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountMosaicRestrictionModificationBuilder[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.accountMosaicRestrictionTransactionBody = new AccountMosaicRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of AccountMosaicRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMosaicRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMosaicRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountMosaicRestrictionTransactionBody = AccountMosaicRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountMosaicRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountMosaicRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountMosaicRestrictionTransactionBody.restrictionType, accountMosaicRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountMosaicRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountMosaicRestrictionModificationBuilder[] { + return this.accountMosaicRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountMosaicRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountMosaicRestrictionTransactionBodyBytes = this.accountMosaicRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountMosaicRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder.ts b/src/infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder.ts new file mode 100644 index 0000000000..669bfc4dce --- /dev/null +++ b/src/infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder.ts @@ -0,0 +1,91 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountRestrictionModificationActionDto } from './AccountRestrictionModificationActionDto'; +import { AccountRestrictionModificationBuilder } from './AccountRestrictionModificationBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Account operation restriction modification. */ +export class AccountOperationRestrictionModificationBuilder extends AccountRestrictionModificationBuilder { + /** Transaction type restriction value. */ + value: EntityTypeDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + * @param value Transaction type restriction value. + */ + public constructor(modificationAction: AccountRestrictionModificationActionDto, value: EntityTypeDto) { + super(modificationAction); + this.value = value; + } + + /** + * Creates an instance of AccountOperationRestrictionModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountOperationRestrictionModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountOperationRestrictionModificationBuilder { + const byteArray = Array.from(payload); + const superObject = AccountRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const value = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + return new AccountOperationRestrictionModificationBuilder(superObject.modificationAction, value); + } + + /** + * Gets transaction type restriction value. + * + * @return Transaction type restriction value. + */ + public getValue(): EntityTypeDto { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += 2; // value + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const valueBytes = GeneratorUtils.uintToBuffer(this.value, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..dd505b0b5f --- /dev/null +++ b/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,114 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountOperationRestrictionModificationBuilder } from './AccountOperationRestrictionModificationBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for an account operation restriction transaction. */ +export class AccountOperationRestrictionTransactionBodyBuilder { + /** Account restriction type. */ + restrictionType: AccountRestrictionTypeDto; + /** Account restriction modifications. */ + modifications: AccountOperationRestrictionModificationBuilder[]; + + /** + * Constructor. + * + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(restrictionType: AccountRestrictionTypeDto, modifications: AccountOperationRestrictionModificationBuilder[]) { + this.restrictionType = restrictionType; + this.modifications = modifications; + } + + /** + * Creates an instance of AccountOperationRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountOperationRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountOperationRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const restrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modificationsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modifications: AccountOperationRestrictionModificationBuilder[] = []; + for (let i = 0; i < modificationsCount; i++) { + const item = AccountOperationRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + modifications.push(item); + byteArray.splice(0, item.getSize()); + } + return new AccountOperationRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.restrictionType; + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountOperationRestrictionModificationBuilder[] { + return this.modifications; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // restrictionType + size += 1; // modificationsCount + this.modifications.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const restrictionTypeBytes = GeneratorUtils.uintToBuffer(this.restrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionTypeBytes); + const modificationsCountBytes = GeneratorUtils.uintToBuffer(this.modifications.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsCountBytes); + this.modifications.forEach((item) => { + const modificationsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..2f5795b732 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder.ts @@ -0,0 +1,116 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountOperationRestrictionModificationBuilder } from './AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBodyBuilder } from './AccountOperationRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account operation restriction transaction. */ +export class AccountOperationRestrictionTransactionBuilder extends TransactionBuilder { + /** Account operation restriction transaction body. */ + accountOperationRestrictionTransactionBody: AccountOperationRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountOperationRestrictionModificationBuilder[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.accountOperationRestrictionTransactionBody = new AccountOperationRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of AccountOperationRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountOperationRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountOperationRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountOperationRestrictionTransactionBody = AccountOperationRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountOperationRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountOperationRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountOperationRestrictionTransactionBody.restrictionType, accountOperationRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountOperationRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountOperationRestrictionModificationBuilder[] { + return this.accountOperationRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountOperationRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountOperationRestrictionTransactionBodyBytes = this.accountOperationRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountOperationRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountRestrictionModificationActionDto.ts b/src/infrastructure/catbuffer/AccountRestrictionModificationActionDto.ts new file mode 100644 index 0000000000..84da076601 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountRestrictionModificationActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of account restriction modification actions. */ +export enum AccountRestrictionModificationActionDto { + /** Remove account restriction value. */ + DEL = 0, + /** Add account restriction value. */ + ADD = 1, +} diff --git a/src/infrastructure/catbuffer/AccountRestrictionModificationBuilder.ts b/src/infrastructure/catbuffer/AccountRestrictionModificationBuilder.ts new file mode 100644 index 0000000000..286901d4c9 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountRestrictionModificationBuilder.ts @@ -0,0 +1,83 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountRestrictionModificationActionDto } from './AccountRestrictionModificationActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Account restriction basic modification. */ +export class AccountRestrictionModificationBuilder { + /** Modification action. */ + modificationAction: AccountRestrictionModificationActionDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + */ + public constructor(modificationAction: AccountRestrictionModificationActionDto) { + this.modificationAction = modificationAction; + } + + /** + * Creates an instance of AccountRestrictionModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountRestrictionModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountRestrictionModificationBuilder { + const byteArray = Array.from(payload); + const modificationAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + return new AccountRestrictionModificationBuilder(modificationAction); + } + + /** + * Gets modification action. + * + * @return Modification action. + */ + public getModificationAction(): AccountRestrictionModificationActionDto { + return this.modificationAction; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // modificationAction + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const modificationActionBytes = GeneratorUtils.uintToBuffer(this.modificationAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationActionBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountRestrictionTypeDto.ts b/src/infrastructure/catbuffer/AccountRestrictionTypeDto.ts new file mode 100644 index 0000000000..2d9cc2d061 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountRestrictionTypeDto.ts @@ -0,0 +1,35 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of account restriction types. */ +export enum AccountRestrictionTypeDto { + /** Restriction type is an address. */ + ADDRESS = 1, + /** Restriction type is a mosaic identifier. */ + MOSAIC_ID = 2, + /** Restriction type is a transaction type. */ + TRANSACTION_TYPE = 4, + /** Restriction is interpreted as outgoing. */ + OUTGOING = 64, + /** Restriction is interpreted as blocking operation. */ + BLOCK = 128, +} diff --git a/src/infrastructure/catbuffer/AddressAliasTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AddressAliasTransactionBodyBuilder.ts new file mode 100644 index 0000000000..0cdb182cc0 --- /dev/null +++ b/src/infrastructure/catbuffer/AddressAliasTransactionBodyBuilder.ts @@ -0,0 +1,121 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AddressDto } from './AddressDto'; +import { AliasActionDto } from './AliasActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for an address alias transaction. */ +export class AddressAliasTransactionBodyBuilder { + /** Alias action. */ + aliasAction: AliasActionDto; + /** Identifier of the namespace that will become an alias. */ + namespaceId: NamespaceIdDto; + /** Aliased address. */ + address: AddressDto; + + /** + * Constructor. + * + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param address Aliased address. + */ + public constructor(aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, address: AddressDto) { + this.aliasAction = aliasAction; + this.namespaceId = namespaceId; + this.address = address; + } + + /** + * Creates an instance of AddressAliasTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AddressAliasTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AddressAliasTransactionBodyBuilder { + const byteArray = Array.from(payload); + const aliasAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const namespaceId = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceId.getSize()); + const address = AddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, address.getSize()); + return new AddressAliasTransactionBodyBuilder(aliasAction, namespaceId, address); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.aliasAction; + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.namespaceId; + } + + /** + * Gets aliased address. + * + * @return Aliased address. + */ + public getAddress(): AddressDto { + return this.address; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // aliasAction + size += this.namespaceId.getSize(); + size += this.address.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const aliasActionBytes = GeneratorUtils.uintToBuffer(this.aliasAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, aliasActionBytes); + const namespaceIdBytes = this.namespaceId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceIdBytes); + const addressBytes = this.address.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, addressBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AddressAliasTransactionBuilder.ts b/src/infrastructure/catbuffer/AddressAliasTransactionBuilder.ts new file mode 100644 index 0000000000..a1b64702cc --- /dev/null +++ b/src/infrastructure/catbuffer/AddressAliasTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; +import { AddressDto } from './AddressDto'; +import { AliasActionDto } from './AliasActionDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded address alias transaction. */ +export class AddressAliasTransactionBuilder extends TransactionBuilder { + /** Address alias transaction body. */ + addressAliasTransactionBody: AddressAliasTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param address Aliased address. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, address: AddressDto) { + super(signature, signer, version, type, fee, deadline); + this.addressAliasTransactionBody = new AddressAliasTransactionBodyBuilder(aliasAction, namespaceId, address); + } + + /** + * Creates an instance of AddressAliasTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AddressAliasTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AddressAliasTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const addressAliasTransactionBody = AddressAliasTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, addressAliasTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AddressAliasTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, addressAliasTransactionBody.aliasAction, addressAliasTransactionBody.namespaceId, addressAliasTransactionBody.address); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.addressAliasTransactionBody.getAliasAction(); + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.addressAliasTransactionBody.getNamespaceId(); + } + + /** + * Gets aliased address. + * + * @return Aliased address. + */ + public getAddress(): AddressDto { + return this.addressAliasTransactionBody.getAddress(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.addressAliasTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const addressAliasTransactionBodyBytes = this.addressAliasTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, addressAliasTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AddressDto.ts b/src/infrastructure/catbuffer/AddressDto.ts new file mode 100644 index 0000000000..16214f53dc --- /dev/null +++ b/src/infrastructure/catbuffer/AddressDto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Address. */ +export class AddressDto { + /** Address. */ + address: Uint8Array; + + /** + * Constructor. + * + * @param address Address. + */ + constructor(address: Uint8Array) { + this.address = address; + } + + /** + * Creates an instance of AddressDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AddressDto. + */ + public static loadFromBinary(payload: Uint8Array): AddressDto { + const byteArray = Array.from(payload); + const address = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 25); + byteArray.splice(0, 25); + return new AddressDto(address); + } + + /** + * Gets Address. + * + * @return Address. + */ + public getAddress(): Uint8Array { + return this.address; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 25; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.address); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AliasActionDto.ts b/src/infrastructure/catbuffer/AliasActionDto.ts new file mode 100644 index 0000000000..58cd769ca8 --- /dev/null +++ b/src/infrastructure/catbuffer/AliasActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of alias actions. */ +export enum AliasActionDto { + /** Unlink alias. */ + UNLINK = 0, + /** Link alias. */ + LINK = 1, +} diff --git a/src/infrastructure/catbuffer/AmountDto.ts b/src/infrastructure/catbuffer/AmountDto.ts new file mode 100644 index 0000000000..b1e3c31731 --- /dev/null +++ b/src/infrastructure/catbuffer/AmountDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Amount. */ +export class AmountDto { + /** Amount. */ + amount: number[]; + + /** + * Constructor. + * + * @param amount Amount. + */ + constructor(amount: number[]) { + this.amount = amount; + } + + /** + * Creates an instance of AmountDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AmountDto. + */ + public static loadFromBinary(payload: Uint8Array): AmountDto { + const byteArray = Array.from(payload); + const amount = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new AmountDto(amount); + } + + /** + * Gets Amount. + * + * @return Amount. + */ + public getAmount(): number[] { + return this.amount; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const amountBytes = GeneratorUtils.uint64ToBuffer(this.getAmount()); + newArray = GeneratorUtils.concatTypedArrays(newArray, amountBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/BlockDurationDto.ts b/src/infrastructure/catbuffer/BlockDurationDto.ts new file mode 100644 index 0000000000..dfc232ebdc --- /dev/null +++ b/src/infrastructure/catbuffer/BlockDurationDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Block duration. */ +export class BlockDurationDto { + /** Block duration. */ + blockDuration: number[]; + + /** + * Constructor. + * + * @param blockDuration Block duration. + */ + constructor(blockDuration: number[]) { + this.blockDuration = blockDuration; + } + + /** + * Creates an instance of BlockDurationDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of BlockDurationDto. + */ + public static loadFromBinary(payload: Uint8Array): BlockDurationDto { + const byteArray = Array.from(payload); + const blockDuration = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new BlockDurationDto(blockDuration); + } + + /** + * Gets Block duration. + * + * @return Block duration. + */ + public getBlockDuration(): number[] { + return this.blockDuration; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const blockDurationBytes = GeneratorUtils.uint64ToBuffer(this.getBlockDuration()); + newArray = GeneratorUtils.concatTypedArrays(newArray, blockDurationBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/CosignatoryModificationActionDto.ts b/src/infrastructure/catbuffer/CosignatoryModificationActionDto.ts new file mode 100644 index 0000000000..c428422d9a --- /dev/null +++ b/src/infrastructure/catbuffer/CosignatoryModificationActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of cosignatory modification actions. */ +export enum CosignatoryModificationActionDto { + /** Remove cosignatory. */ + DEL = 0, + /** Add cosignatory. */ + ADD = 1, +} diff --git a/src/infrastructure/catbuffer/CosignatoryModificationBuilder.ts b/src/infrastructure/catbuffer/CosignatoryModificationBuilder.ts new file mode 100644 index 0000000000..8413b779db --- /dev/null +++ b/src/infrastructure/catbuffer/CosignatoryModificationBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { CosignatoryModificationActionDto } from './CosignatoryModificationActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for a cosignatory modification. */ +export class CosignatoryModificationBuilder { + /** Modification action. */ + modificationAction: CosignatoryModificationActionDto; + /** Cosignatory account public key. */ + cosignatoryPublicKey: KeyDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + * @param cosignatoryPublicKey Cosignatory account public key. + */ + public constructor(modificationAction: CosignatoryModificationActionDto, cosignatoryPublicKey: KeyDto) { + this.modificationAction = modificationAction; + this.cosignatoryPublicKey = cosignatoryPublicKey; + } + + /** + * Creates an instance of CosignatoryModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of CosignatoryModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): CosignatoryModificationBuilder { + const byteArray = Array.from(payload); + const modificationAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const cosignatoryPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, cosignatoryPublicKey.getSize()); + return new CosignatoryModificationBuilder(modificationAction, cosignatoryPublicKey); + } + + /** + * Gets modification action. + * + * @return Modification action. + */ + public getModificationAction(): CosignatoryModificationActionDto { + return this.modificationAction; + } + + /** + * Gets cosignatory account public key. + * + * @return Cosignatory account public key. + */ + public getCosignatoryPublicKey(): KeyDto { + return this.cosignatoryPublicKey; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // modificationAction + size += this.cosignatoryPublicKey.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const modificationActionBytes = GeneratorUtils.uintToBuffer(this.modificationAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationActionBytes); + const cosignatoryPublicKeyBytes = this.cosignatoryPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, cosignatoryPublicKeyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..af18bf390d --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder.ts @@ -0,0 +1,110 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountAddressRestrictionModificationBuilder } from './AccountAddressRestrictionModificationBuilder'; +import { AccountAddressRestrictionTransactionBodyBuilder } from './AccountAddressRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account address restriction transaction. */ +export class EmbeddedAccountAddressRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account address restriction transaction body. */ + accountAddressRestrictionTransactionBody: AccountAddressRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountAddressRestrictionModificationBuilder[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.accountAddressRestrictionTransactionBody = new AccountAddressRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of EmbeddedAccountAddressRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountAddressRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountAddressRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountAddressRestrictionTransactionBody = AccountAddressRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountAddressRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountAddressRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountAddressRestrictionTransactionBody.restrictionType, accountAddressRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountAddressRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountAddressRestrictionModificationBuilder[] { + return this.accountAddressRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountAddressRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountAddressRestrictionTransactionBodyBytes = this.accountAddressRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountAddressRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder.ts new file mode 100644 index 0000000000..c2219f36bb --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder.ts @@ -0,0 +1,107 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountLinkActionDto } from './AccountLinkActionDto'; +import { AccountLinkTransactionBodyBuilder } from './AccountLinkTransactionBodyBuilder'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account link transaction. */ +export class EmbeddedAccountLinkTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account link transaction body. */ + accountLinkTransactionBody: AccountLinkTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param remoteAccountPublicKey Remote account public key. + * @param linkAction Account link action. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, remoteAccountPublicKey: KeyDto, linkAction: AccountLinkActionDto) { + super(signer, version, type); + this.accountLinkTransactionBody = new AccountLinkTransactionBodyBuilder(remoteAccountPublicKey, linkAction); + } + + /** + * Creates an instance of EmbeddedAccountLinkTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountLinkTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountLinkTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const accountLinkTransactionBody = AccountLinkTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountLinkTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountLinkTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountLinkTransactionBody.remoteAccountPublicKey, accountLinkTransactionBody.linkAction); + } + + /** + * Gets remote account public key. + * + * @return Remote account public key. + */ + public getRemoteAccountPublicKey(): KeyDto { + return this.accountLinkTransactionBody.getRemoteAccountPublicKey(); + } + + /** + * Gets account link action. + * + * @return Account link action. + */ + public getLinkAction(): AccountLinkActionDto { + return this.accountLinkTransactionBody.getLinkAction(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountLinkTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountLinkTransactionBodyBytes = this.accountLinkTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountLinkTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..ec9f33ca7f --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder.ts @@ -0,0 +1,133 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMetadataTransactionBodyBuilder } from './AccountMetadataTransactionBodyBuilder'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account metadata transaction. */ +export class EmbeddedAccountMetadataTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account metadata transaction body. */ + accountMetadataTransactionBody: AccountMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], valueSizeDelta: number, value: Uint8Array) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.accountMetadataTransactionBody = new AccountMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, valueSizeDelta, value); + } + + /** + * Creates an instance of EmbeddedAccountMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const accountMetadataTransactionBody = AccountMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountMetadataTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountMetadataTransactionBody.targetPublicKey, accountMetadataTransactionBody.scopedMetadataKey, accountMetadataTransactionBody.valueSizeDelta, accountMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.accountMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.accountMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.accountMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.accountMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountMetadataTransactionBodyBytes = this.accountMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..d97d085545 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder.ts @@ -0,0 +1,110 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMosaicRestrictionModificationBuilder } from './AccountMosaicRestrictionModificationBuilder'; +import { AccountMosaicRestrictionTransactionBodyBuilder } from './AccountMosaicRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account mosaic restriction transaction. */ +export class EmbeddedAccountMosaicRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account mosaic restriction transaction body. */ + accountMosaicRestrictionTransactionBody: AccountMosaicRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountMosaicRestrictionModificationBuilder[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.accountMosaicRestrictionTransactionBody = new AccountMosaicRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of EmbeddedAccountMosaicRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountMosaicRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountMosaicRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountMosaicRestrictionTransactionBody = AccountMosaicRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountMosaicRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountMosaicRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountMosaicRestrictionTransactionBody.restrictionType, accountMosaicRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountMosaicRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountMosaicRestrictionModificationBuilder[] { + return this.accountMosaicRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountMosaicRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountMosaicRestrictionTransactionBodyBytes = this.accountMosaicRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountMosaicRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..c4de2fb15c --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder.ts @@ -0,0 +1,110 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountOperationRestrictionModificationBuilder } from './AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBodyBuilder } from './AccountOperationRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account operation restriction transaction. */ +export class EmbeddedAccountOperationRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account operation restriction transaction body. */ + accountOperationRestrictionTransactionBody: AccountOperationRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountOperationRestrictionModificationBuilder[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.accountOperationRestrictionTransactionBody = new AccountOperationRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of EmbeddedAccountOperationRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountOperationRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountOperationRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountOperationRestrictionTransactionBody = AccountOperationRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountOperationRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountOperationRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountOperationRestrictionTransactionBody.restrictionType, accountOperationRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountOperationRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountOperationRestrictionModificationBuilder[] { + return this.accountOperationRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountOperationRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountOperationRestrictionTransactionBodyBytes = this.accountOperationRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountOperationRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder.ts new file mode 100644 index 0000000000..7532500571 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder.ts @@ -0,0 +1,119 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; +import { AddressDto } from './AddressDto'; +import { AliasActionDto } from './AliasActionDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for an embedded address alias transaction. */ +export class EmbeddedAddressAliasTransactionBuilder extends EmbeddedTransactionBuilder { + /** Address alias transaction body. */ + addressAliasTransactionBody: AddressAliasTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param address Aliased address. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, address: AddressDto) { + super(signer, version, type); + this.addressAliasTransactionBody = new AddressAliasTransactionBodyBuilder(aliasAction, namespaceId, address); + } + + /** + * Creates an instance of EmbeddedAddressAliasTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAddressAliasTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAddressAliasTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const addressAliasTransactionBody = AddressAliasTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, addressAliasTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAddressAliasTransactionBuilder(superObject.signer, superObject.version, superObject.type, addressAliasTransactionBody.aliasAction, addressAliasTransactionBody.namespaceId, addressAliasTransactionBody.address); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.addressAliasTransactionBody.getAliasAction(); + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.addressAliasTransactionBody.getNamespaceId(); + } + + /** + * Gets aliased address. + * + * @return Aliased address. + */ + public getAddress(): AddressDto { + return this.addressAliasTransactionBody.getAddress(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.addressAliasTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const addressAliasTransactionBodyBytes = this.addressAliasTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, addressAliasTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder.ts new file mode 100644 index 0000000000..e91a7e98b4 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder.ts @@ -0,0 +1,119 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { HashLockTransactionBodyBuilder } from './HashLockTransactionBodyBuilder'; +import { KeyDto } from './KeyDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for an embedded hash lock transaction. */ +export class EmbeddedHashLockTransactionBuilder extends EmbeddedTransactionBuilder { + /** Hash lock transaction body. */ + hashLockTransactionBody: HashLockTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaic Lock mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hash Lock hash. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hash: Hash256Dto) { + super(signer, version, type); + this.hashLockTransactionBody = new HashLockTransactionBodyBuilder(mosaic, duration, hash); + } + + /** + * Creates an instance of EmbeddedHashLockTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedHashLockTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedHashLockTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const hashLockTransactionBody = HashLockTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, hashLockTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedHashLockTransactionBuilder(superObject.signer, superObject.version, superObject.type, hashLockTransactionBody.mosaic, hashLockTransactionBody.duration, hashLockTransactionBody.hash); + } + + /** + * Gets lock mosaic. + * + * @return Lock mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.hashLockTransactionBody.getMosaic(); + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.hashLockTransactionBody.getDuration(); + } + + /** + * Gets lock hash. + * + * @return Lock hash. + */ + public getHash(): Hash256Dto { + return this.hashLockTransactionBody.getHash(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.hashLockTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const hashLockTransactionBodyBytes = this.hashLockTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashLockTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..ead5de2075 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder.ts @@ -0,0 +1,140 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicAddressRestrictionTransactionBodyBuilder } from './MosaicAddressRestrictionTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an embedded mosaic address restriction transaction. */ +export class EmbeddedMosaicAddressRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic address restriction transaction body. */ + mosaicAddressRestrictionTransactionBody: MosaicAddressRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaicId Identifier of the mosaic to which the restriction applies. + * @param restrictionKey Restriction key. + * @param targetAddress Address being restricted. + * @param previousRestrictionValue Previous restriction value. + * @param newRestrictionValue New restriction value. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], targetAddress: UnresolvedAddressDto, previousRestrictionValue: number[], newRestrictionValue: number[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.mosaicAddressRestrictionTransactionBody = new MosaicAddressRestrictionTransactionBodyBuilder(mosaicId, restrictionKey, targetAddress, previousRestrictionValue, newRestrictionValue); + } + + /** + * Creates an instance of EmbeddedMosaicAddressRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicAddressRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicAddressRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicAddressRestrictionTransactionBody = MosaicAddressRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicAddressRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicAddressRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicAddressRestrictionTransactionBody.mosaicId, mosaicAddressRestrictionTransactionBody.restrictionKey, mosaicAddressRestrictionTransactionBody.targetAddress, mosaicAddressRestrictionTransactionBody.previousRestrictionValue, mosaicAddressRestrictionTransactionBody.newRestrictionValue); + } + + /** + * Gets identifier of the mosaic to which the restriction applies. + * + * @return Identifier of the mosaic to which the restriction applies. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicAddressRestrictionTransactionBody.getMosaicId(); + } + + /** + * Gets restriction key. + * + * @return Restriction key. + */ + public getRestrictionKey(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getRestrictionKey(); + } + + /** + * Gets address being restricted. + * + * @return Address being restricted. + */ + public getTargetAddress(): UnresolvedAddressDto { + return this.mosaicAddressRestrictionTransactionBody.getTargetAddress(); + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getPreviousRestrictionValue(); + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getNewRestrictionValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicAddressRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicAddressRestrictionTransactionBodyBytes = this.mosaicAddressRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicAddressRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder.ts new file mode 100644 index 0000000000..635b59964f --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder.ts @@ -0,0 +1,119 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AliasActionDto } from './AliasActionDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicAliasTransactionBodyBuilder } from './MosaicAliasTransactionBodyBuilder'; +import { MosaicIdDto } from './MosaicIdDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for an embedded mosaic alias transaction. */ +export class EmbeddedMosaicAliasTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic alias transaction body. */ + mosaicAliasTransactionBody: MosaicAliasTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param mosaicId Aliased mosaic identifier. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, mosaicId: MosaicIdDto) { + super(signer, version, type); + this.mosaicAliasTransactionBody = new MosaicAliasTransactionBodyBuilder(aliasAction, namespaceId, mosaicId); + } + + /** + * Creates an instance of EmbeddedMosaicAliasTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicAliasTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicAliasTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const mosaicAliasTransactionBody = MosaicAliasTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicAliasTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicAliasTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicAliasTransactionBody.aliasAction, mosaicAliasTransactionBody.namespaceId, mosaicAliasTransactionBody.mosaicId); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.mosaicAliasTransactionBody.getAliasAction(); + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.mosaicAliasTransactionBody.getNamespaceId(); + } + + /** + * Gets aliased mosaic identifier. + * + * @return Aliased mosaic identifier. + */ + public getMosaicId(): MosaicIdDto { + return this.mosaicAliasTransactionBody.getMosaicId(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicAliasTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicAliasTransactionBodyBytes = this.mosaicAliasTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicAliasTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder.ts new file mode 100644 index 0000000000..ad46a89813 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder.ts @@ -0,0 +1,141 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicDefinitionTransactionBodyBuilder } from './MosaicDefinitionTransactionBodyBuilder'; +import { MosaicIdDto } from './MosaicIdDto'; +import { MosaicNonceDto } from './MosaicNonceDto'; + +/** Binary layout for an embedded mosaic definition transaction. */ +export class EmbeddedMosaicDefinitionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic definition transaction body. */ + mosaicDefinitionTransactionBody: MosaicDefinitionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param nonce Mosaic nonce. + * @param id Mosaic identifier. + * @param flags Mosaic flags. + * @param divisibility Mosaic divisibility. + * @param duration Mosaic duration. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, nonce: MosaicNonceDto, id: MosaicIdDto, flags: number, divisibility: number, duration: BlockDurationDto) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.mosaicDefinitionTransactionBody = new MosaicDefinitionTransactionBodyBuilder(nonce, id, flags, divisibility, duration); + } + + /** + * Creates an instance of EmbeddedMosaicDefinitionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicDefinitionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicDefinitionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicDefinitionTransactionBody = MosaicDefinitionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicDefinitionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicDefinitionTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicDefinitionTransactionBody.nonce, mosaicDefinitionTransactionBody.id, mosaicDefinitionTransactionBody.flags, mosaicDefinitionTransactionBody.divisibility, mosaicDefinitionTransactionBody.duration); + } + + /** + * Gets mosaic nonce. + * + * @return Mosaic nonce. + */ + public getNonce(): MosaicNonceDto { + return this.mosaicDefinitionTransactionBody.getNonce(); + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getId(): MosaicIdDto { + return this.mosaicDefinitionTransactionBody.getId(); + } + + /** + * Gets mosaic flags. + * + * @return Mosaic flags. + */ + public getFlags(): number { + return this.mosaicDefinitionTransactionBody.getFlags(); + } + + /** + * Gets mosaic divisibility. + * + * @return Mosaic divisibility. + */ + public getDivisibility(): number { + return this.mosaicDefinitionTransactionBody.getDivisibility(); + } + + /** + * Gets mosaic duration. + * + * @return Mosaic duration. + */ + public getDuration(): BlockDurationDto { + return this.mosaicDefinitionTransactionBody.getDuration(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicDefinitionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicDefinitionTransactionBodyBytes = this.mosaicDefinitionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicDefinitionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..224df49b31 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder.ts @@ -0,0 +1,160 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicGlobalRestrictionTransactionBodyBuilder } from './MosaicGlobalRestrictionTransactionBodyBuilder'; +import { MosaicRestrictionTypeDto } from './MosaicRestrictionTypeDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an embedded mosaic global restriction transaction. */ +export class EmbeddedMosaicGlobalRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic global restriction transaction body. */ + mosaicGlobalRestrictionTransactionBody: MosaicGlobalRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaicId Identifier of the mosaic being restricted. + * @param referenceMosaicId Identifier of the mosaic providing the restriction key. + * @param restrictionKey Restriction key relative to the reference mosaic identifier. + * @param previousRestrictionValue Previous restriction value. + * @param previousRestrictionType Previous restriction type. + * @param newRestrictionValue New restriction value. + * @param newRestrictionType New restriction type. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaicId: UnresolvedMosaicIdDto, referenceMosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], previousRestrictionValue: number[], previousRestrictionType: MosaicRestrictionTypeDto, newRestrictionValue: number[], newRestrictionType: MosaicRestrictionTypeDto) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.mosaicGlobalRestrictionTransactionBody = new MosaicGlobalRestrictionTransactionBodyBuilder(mosaicId, referenceMosaicId, restrictionKey, previousRestrictionValue, previousRestrictionType, newRestrictionValue, newRestrictionType); + } + + /** + * Creates an instance of EmbeddedMosaicGlobalRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicGlobalRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicGlobalRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicGlobalRestrictionTransactionBody = MosaicGlobalRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicGlobalRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicGlobalRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicGlobalRestrictionTransactionBody.mosaicId, mosaicGlobalRestrictionTransactionBody.referenceMosaicId, mosaicGlobalRestrictionTransactionBody.restrictionKey, mosaicGlobalRestrictionTransactionBody.previousRestrictionValue, mosaicGlobalRestrictionTransactionBody.previousRestrictionType, mosaicGlobalRestrictionTransactionBody.newRestrictionValue, mosaicGlobalRestrictionTransactionBody.newRestrictionType); + } + + /** + * Gets identifier of the mosaic being restricted. + * + * @return Identifier of the mosaic being restricted. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicGlobalRestrictionTransactionBody.getMosaicId(); + } + + /** + * Gets identifier of the mosaic providing the restriction key. + * + * @return Identifier of the mosaic providing the restriction key. + */ + public getReferenceMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicGlobalRestrictionTransactionBody.getReferenceMosaicId(); + } + + /** + * Gets restriction key relative to the reference mosaic identifier. + * + * @return Restriction key relative to the reference mosaic identifier. + */ + public getRestrictionKey(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getRestrictionKey(); + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getPreviousRestrictionValue(); + } + + /** + * Gets previous restriction type. + * + * @return Previous restriction type. + */ + public getPreviousRestrictionType(): MosaicRestrictionTypeDto { + return this.mosaicGlobalRestrictionTransactionBody.getPreviousRestrictionType(); + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getNewRestrictionValue(); + } + + /** + * Gets new restriction type. + * + * @return New restriction type. + */ + public getNewRestrictionType(): MosaicRestrictionTypeDto { + return this.mosaicGlobalRestrictionTransactionBody.getNewRestrictionType(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicGlobalRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicGlobalRestrictionTransactionBodyBytes = this.mosaicGlobalRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicGlobalRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..378bec0bf3 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder.ts @@ -0,0 +1,144 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicMetadataTransactionBodyBuilder } from './MosaicMetadataTransactionBodyBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an embedded mosaic metadata transaction. */ +export class EmbeddedMosaicMetadataTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic metadata transaction body. */ + mosaicMetadataTransactionBody: MosaicMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetMosaicId Target mosaic identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], targetMosaicId: UnresolvedMosaicIdDto, valueSizeDelta: number, value: Uint8Array) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.mosaicMetadataTransactionBody = new MosaicMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetMosaicId, valueSizeDelta, value); + } + + /** + * Creates an instance of EmbeddedMosaicMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const mosaicMetadataTransactionBody = MosaicMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicMetadataTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicMetadataTransactionBody.targetPublicKey, mosaicMetadataTransactionBody.scopedMetadataKey, mosaicMetadataTransactionBody.targetMosaicId, mosaicMetadataTransactionBody.valueSizeDelta, mosaicMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.mosaicMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.mosaicMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets target mosaic identifier. + * + * @return Target mosaic identifier. + */ + public getTargetMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicMetadataTransactionBody.getTargetMosaicId(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.mosaicMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.mosaicMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicMetadataTransactionBodyBytes = this.mosaicMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder.ts new file mode 100644 index 0000000000..6f66b59522 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder.ts @@ -0,0 +1,120 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicSupplyChangeActionDto } from './MosaicSupplyChangeActionDto'; +import { MosaicSupplyChangeTransactionBodyBuilder } from './MosaicSupplyChangeTransactionBodyBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an embedded mosaic supply change transaction. */ +export class EmbeddedMosaicSupplyChangeTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic supply change transaction body. */ + mosaicSupplyChangeTransactionBody: MosaicSupplyChangeTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaicId Affected mosaic identifier. + * @param action Supply change action. + * @param delta Change amount. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaicId: UnresolvedMosaicIdDto, action: MosaicSupplyChangeActionDto, delta: AmountDto) { + super(signer, version, type); + this.mosaicSupplyChangeTransactionBody = new MosaicSupplyChangeTransactionBodyBuilder(mosaicId, action, delta); + } + + /** + * Creates an instance of EmbeddedMosaicSupplyChangeTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicSupplyChangeTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicSupplyChangeTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicSupplyChangeTransactionBody = MosaicSupplyChangeTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicSupplyChangeTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicSupplyChangeTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicSupplyChangeTransactionBody.mosaicId, mosaicSupplyChangeTransactionBody.action, mosaicSupplyChangeTransactionBody.delta); + } + + /** + * Gets affected mosaic identifier. + * + * @return Affected mosaic identifier. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicSupplyChangeTransactionBody.getMosaicId(); + } + + /** + * Gets supply change action. + * + * @return Supply change action. + */ + public getAction(): MosaicSupplyChangeActionDto { + return this.mosaicSupplyChangeTransactionBody.getAction(); + } + + /** + * Gets change amount. + * + * @return Change amount. + */ + public getDelta(): AmountDto { + return this.mosaicSupplyChangeTransactionBody.getDelta(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicSupplyChangeTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicSupplyChangeTransactionBodyBytes = this.mosaicSupplyChangeTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicSupplyChangeTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder.ts new file mode 100644 index 0000000000..b2de331994 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder.ts @@ -0,0 +1,119 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { CosignatoryModificationBuilder } from './CosignatoryModificationBuilder'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MultisigAccountModificationTransactionBodyBuilder } from './MultisigAccountModificationTransactionBodyBuilder'; + +/** Binary layout for an embedded multisig account modification transaction. */ +export class EmbeddedMultisigAccountModificationTransactionBuilder extends EmbeddedTransactionBuilder { + /** Multisig account modification transaction body. */ + multisigAccountModificationTransactionBody: MultisigAccountModificationTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param minRemovalDelta Relative change of the minimal number of cosignatories required when removing an account. + * @param minApprovalDelta Relative change of the minimal number of cosignatories required when approving a transaction. + * @param modifications Attached cosignatory modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, minRemovalDelta: number, minApprovalDelta: number, modifications: CosignatoryModificationBuilder[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.multisigAccountModificationTransactionBody = new MultisigAccountModificationTransactionBodyBuilder(minRemovalDelta, minApprovalDelta, modifications); + } + + /** + * Creates an instance of EmbeddedMultisigAccountModificationTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMultisigAccountModificationTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMultisigAccountModificationTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const multisigAccountModificationTransactionBody = MultisigAccountModificationTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, multisigAccountModificationTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMultisigAccountModificationTransactionBuilder(superObject.signer, superObject.version, superObject.type, multisigAccountModificationTransactionBody.minRemovalDelta, multisigAccountModificationTransactionBody.minApprovalDelta, multisigAccountModificationTransactionBody.modifications); + } + + /** + * Gets relative change of the minimal number of cosignatories required when removing an account. + * + * @return Relative change of the minimal number of cosignatories required when removing an account. + */ + public getMinRemovalDelta(): number { + return this.multisigAccountModificationTransactionBody.getMinRemovalDelta(); + } + + /** + * Gets relative change of the minimal number of cosignatories required when approving a transaction. + * + * @return Relative change of the minimal number of cosignatories required when approving a transaction. + */ + public getMinApprovalDelta(): number { + return this.multisigAccountModificationTransactionBody.getMinApprovalDelta(); + } + + /** + * Gets attached cosignatory modifications. + * + * @return Attached cosignatory modifications. + */ + public getModifications(): CosignatoryModificationBuilder[] { + return this.multisigAccountModificationTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.multisigAccountModificationTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const multisigAccountModificationTransactionBodyBytes = this.multisigAccountModificationTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, multisigAccountModificationTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..1d4bbe606c --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder.ts @@ -0,0 +1,145 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceMetadataTransactionBodyBuilder } from './NamespaceMetadataTransactionBodyBuilder'; + +/** Binary layout for an embedded namespace metadata transaction. */ +export class EmbeddedNamespaceMetadataTransactionBuilder extends EmbeddedTransactionBuilder { + /** Namespace metadata transaction body. */ + namespaceMetadataTransactionBody: NamespaceMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetNamespaceId Target namespace identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], targetNamespaceId: NamespaceIdDto, valueSizeDelta: number, value: Uint8Array) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.namespaceMetadataTransactionBody = new NamespaceMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetNamespaceId, valueSizeDelta, value); + } + + /** + * Creates an instance of EmbeddedNamespaceMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedNamespaceMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedNamespaceMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const namespaceMetadataTransactionBody = NamespaceMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedNamespaceMetadataTransactionBuilder(superObject.signer, superObject.version, superObject.type, namespaceMetadataTransactionBody.targetPublicKey, namespaceMetadataTransactionBody.scopedMetadataKey, namespaceMetadataTransactionBody.targetNamespaceId, namespaceMetadataTransactionBody.valueSizeDelta, namespaceMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.namespaceMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.namespaceMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets target namespace identifier. + * + * @return Target namespace identifier. + */ + public getTargetNamespaceId(): NamespaceIdDto { + return this.namespaceMetadataTransactionBody.getTargetNamespaceId(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.namespaceMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.namespaceMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.namespaceMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const namespaceMetadataTransactionBodyBytes = this.namespaceMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder.ts new file mode 100644 index 0000000000..29d51b3fb1 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder.ts @@ -0,0 +1,143 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceRegistrationTransactionBodyBuilder } from './NamespaceRegistrationTransactionBodyBuilder'; +import { NamespaceRegistrationTypeDto } from './NamespaceRegistrationTypeDto'; + +/** Binary layout for an embedded namespace registration transaction. */ +export class EmbeddedNamespaceRegistrationTransactionBuilder extends EmbeddedTransactionBuilder { + /** Namespace registration transaction body. */ + namespaceRegistrationTransactionBody: NamespaceRegistrationTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param duration Namespace duration. + * @param parentId Parent namespace identifier. + * @param id Namespace identifier. + * @param name Namespace name. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, id: NamespaceIdDto, name: Uint8Array, duration?: BlockDurationDto, parentId?: NamespaceIdDto) { + super(signer, version, type); + if ((duration && parentId) || (!duration && !parentId)) { + throw new Error('Invalid conditional parameters'); + } + // tslint:disable-next-line: max-line-length + this.namespaceRegistrationTransactionBody = new NamespaceRegistrationTransactionBodyBuilder(id, name, duration, parentId); + } + + /** + * Creates an instance of EmbeddedNamespaceRegistrationTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedNamespaceRegistrationTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedNamespaceRegistrationTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const namespaceRegistrationTransactionBody = NamespaceRegistrationTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceRegistrationTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedNamespaceRegistrationTransactionBuilder(superObject.signer, superObject.version, superObject.type, namespaceRegistrationTransactionBody.id, namespaceRegistrationTransactionBody.name, namespaceRegistrationTransactionBody.duration, namespaceRegistrationTransactionBody.parentId); + } + + /** + * Gets namespace registration type. + * + * @return Namespace registration type. + */ + public getRegistrationType(): NamespaceRegistrationTypeDto { + return this.namespaceRegistrationTransactionBody.getRegistrationType(); + } + + /** + * Gets namespace duration. + * + * @return Namespace duration. + */ + public getDuration(): BlockDurationDto | undefined { + return this.namespaceRegistrationTransactionBody.getDuration(); + } + + /** + * Gets parent namespace identifier. + * + * @return Parent namespace identifier. + */ + public getParentId(): NamespaceIdDto | undefined { + return this.namespaceRegistrationTransactionBody.getParentId(); + } + + /** + * Gets namespace identifier. + * + * @return Namespace identifier. + */ + public getId(): NamespaceIdDto { + return this.namespaceRegistrationTransactionBody.getId(); + } + + /** + * Gets namespace name. + * + * @return Namespace name. + */ + public getName(): Uint8Array { + return this.namespaceRegistrationTransactionBody.getName(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.namespaceRegistrationTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const namespaceRegistrationTransactionBodyBytes = this.namespaceRegistrationTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceRegistrationTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder.ts new file mode 100644 index 0000000000..e8f4c80213 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder.ts @@ -0,0 +1,142 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { KeyDto } from './KeyDto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { SecretLockTransactionBodyBuilder } from './SecretLockTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for an embedded secret lock transaction. */ +export class EmbeddedSecretLockTransactionBuilder extends EmbeddedTransactionBuilder { + /** Secret lock transaction body. */ + secretLockTransactionBody: SecretLockTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaic Locked mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Locked mosaic recipient. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.secretLockTransactionBody = new SecretLockTransactionBodyBuilder(mosaic, duration, hashAlgorithm, secret, recipient); + } + + /** + * Creates an instance of EmbeddedSecretLockTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedSecretLockTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedSecretLockTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const secretLockTransactionBody = SecretLockTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secretLockTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedSecretLockTransactionBuilder(superObject.signer, superObject.version, superObject.type, secretLockTransactionBody.mosaic, secretLockTransactionBody.duration, secretLockTransactionBody.hashAlgorithm, secretLockTransactionBody.secret, secretLockTransactionBody.recipient); + } + + /** + * Gets locked mosaic. + * + * @return Locked mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.secretLockTransactionBody.getMosaic(); + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.secretLockTransactionBody.getDuration(); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.secretLockTransactionBody.getHashAlgorithm(); + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secretLockTransactionBody.getSecret(); + } + + /** + * Gets locked mosaic recipient. + * + * @return Locked mosaic recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.secretLockTransactionBody.getRecipient(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.secretLockTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const secretLockTransactionBodyBytes = this.secretLockTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretLockTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder.ts new file mode 100644 index 0000000000..58d0df9188 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder.ts @@ -0,0 +1,129 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { KeyDto } from './KeyDto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { SecretProofTransactionBodyBuilder } from './SecretProofTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; + +/** Binary layout for an embedded secret proof transaction. */ +export class EmbeddedSecretProofTransactionBuilder extends EmbeddedTransactionBuilder { + /** Secret proof transaction body. */ + secretProofTransactionBody: SecretProofTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Recipient. + * @param proof Proof data. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto, proof: Uint8Array) { + super(signer, version, type); + this.secretProofTransactionBody = new SecretProofTransactionBodyBuilder(hashAlgorithm, secret, recipient, proof); + } + + /** + * Creates an instance of EmbeddedSecretProofTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedSecretProofTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedSecretProofTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const secretProofTransactionBody = SecretProofTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secretProofTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedSecretProofTransactionBuilder(superObject.signer, superObject.version, superObject.type, secretProofTransactionBody.hashAlgorithm, secretProofTransactionBody.secret, secretProofTransactionBody.recipient, secretProofTransactionBody.proof); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.secretProofTransactionBody.getHashAlgorithm(); + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secretProofTransactionBody.getSecret(); + } + + /** + * Gets recipient. + * + * @return Recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.secretProofTransactionBody.getRecipient(); + } + + /** + * Gets proof data. + * + * @return Proof data. + */ + public getProof(): Uint8Array { + return this.secretProofTransactionBody.getProof(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.secretProofTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const secretProofTransactionBodyBytes = this.secretProofTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretProofTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedTransactionBuilder.ts new file mode 100644 index 0000000000..836a8cda5d --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedTransactionBuilder.ts @@ -0,0 +1,127 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded transaction. */ +export class EmbeddedTransactionBuilder { + /** Entity size. */ + size = 0; + /** Entity signer's public key. */ + signer: KeyDto; + /** Entity version. */ + version: number; + /** Entity type. */ + type: EntityTypeDto; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + */ + public constructor(signer: KeyDto, version: number, type: EntityTypeDto) { + this.signer = signer; + this.version = version; + this.type = type; + } + + /** + * Creates an instance of EmbeddedTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedTransactionBuilder { + const byteArray = Array.from(payload); + const size = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signer.getSize()); + const version = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const type = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + return new EmbeddedTransactionBuilder(signer, version, type); + } + + /** + * Gets entity signer's public key. + * + * @return Entity signer's public key. + */ + public getSigner(): KeyDto { + return this.signer; + } + + /** + * Gets entity version. + * + * @return Entity version. + */ + public getVersion(): number { + return this.version; + } + + /** + * Gets entity type. + * + * @return Entity type. + */ + public getType(): EntityTypeDto { + return this.type; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 4; // size + size += this.signer.getSize(); + size += 2; // version + size += 2; // type + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const sizeBytes = GeneratorUtils.uintToBuffer(this.getSize(), 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, sizeBytes); + const signerBytes = this.signer.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); + const versionBytes = GeneratorUtils.uintToBuffer(this.getVersion(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, versionBytes); + const typeBytes = GeneratorUtils.uintToBuffer(this.type, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, typeBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedTransferTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedTransferTransactionBuilder.ts new file mode 100644 index 0000000000..f4402345ef --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedTransferTransactionBuilder.ts @@ -0,0 +1,118 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { TransferTransactionBodyBuilder } from './TransferTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for an embedded transfer transaction. */ +export class EmbeddedTransferTransactionBuilder extends EmbeddedTransactionBuilder { + /** Transfer transaction body. */ + transferTransactionBody: TransferTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param recipient Transaction recipient. + * @param message Transaction message. + * @param mosaics Attached mosaics. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, recipient: UnresolvedAddressDto, message: Uint8Array, mosaics: UnresolvedMosaicBuilder[]) { + super(signer, version, type); + this.transferTransactionBody = new TransferTransactionBodyBuilder(recipient, message, mosaics); + } + + /** + * Creates an instance of EmbeddedTransferTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedTransferTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedTransferTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const transferTransactionBody = TransferTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, transferTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedTransferTransactionBuilder(superObject.signer, superObject.version, superObject.type, transferTransactionBody.recipient, transferTransactionBody.message, transferTransactionBody.mosaics); + } + + /** + * Gets transaction recipient. + * + * @return Transaction recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.transferTransactionBody.getRecipient(); + } + + /** + * Gets transaction message. + * + * @return Transaction message. + */ + public getMessage(): Uint8Array { + return this.transferTransactionBody.getMessage(); + } + + /** + * Gets attached mosaics. + * + * @return Attached mosaics. + */ + public getMosaics(): UnresolvedMosaicBuilder[] { + return this.transferTransactionBody.getMosaics(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.transferTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const transferTransactionBodyBytes = this.transferTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, transferTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EntityTypeDto.ts b/src/infrastructure/catbuffer/EntityTypeDto.ts new file mode 100644 index 0000000000..52e1c55a94 --- /dev/null +++ b/src/infrastructure/catbuffer/EntityTypeDto.ts @@ -0,0 +1,133 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of entity types. */ +export enum EntityTypeDto { + /** Reserved entity type. */ + RESERVED = 0, + /** + * Transfer Transaction transaction type. + * @type {number} + */ + TRANSFER = 0x4154, + + /** + * Register namespace transaction type. + * @type {number} + */ + REGISTER_NAMESPACE = 0x414E, + + /** + * Address alias transaction type + * @type {number} + */ + ADDRESS_ALIAS = 0x424E, + + /** + * Mosaic alias transaction type + * @type {number} + */ + MOSAIC_ALIAS = 0x434E, + + /** + * Mosaic definition transaction type. + * @type {number} + */ + MOSAIC_DEFINITION = 0x414D, + + /** + * Mosaic supply change transaction. + * @type {number} + */ + MOSAIC_SUPPLY_CHANGE = 0x424D, + + /** + * Modify multisig account transaction type. + * @type {number} + */ + MODIFY_MULTISIG_ACCOUNT = 0x4155, + + /** + * Aggregate complete transaction type. + * @type {number} + */ + AGGREGATE_COMPLETE = 0x4141, + + /** + * Aggregate bonded transaction type + */ + AGGREGATE_BONDED = 0x4241, + + /** + * Lock transaction type + * @type {number} + */ + LOCK = 0x4148, + + /** + * Secret Lock Transaction type + * @type {number} + */ + SECRET_LOCK = 0x4152, + + /** + * Secret Proof transaction type + * @type {number} + */ + SECRET_PROOF = 0x4252, + + /** + * Account restriction address transaction type + * @type {number} + */ + ACCOUNT_RESTRICTION_ADDRESS = 0x4150, + + /** + * Account restriction mosaic transaction type + * @type {number} + */ + ACCOUNT_RESTRICTION_MOSAIC = 0x4250, + + /** + * Account restriction operation transaction type + * @type {number} + */ + ACCOUNT_RESTRICTION_OPERATION = 0x4350, + + /** + * Link account transaction type + * @type {number} + */ + LINK_ACCOUNT = 0x414C, + + /** + * Mosaic address restriction type + * @type {number} + */ + MOSAIC_ADDRESS_RESTRICTION = 0x4251, + + /** + * Mosaic global restriction type + * @type {number} + */ + MOSAIC_GLOBAL_RESTRICTION = 0x4151, +} diff --git a/src/infrastructure/catbuffer/GeneratorUtils.ts b/src/infrastructure/catbuffer/GeneratorUtils.ts new file mode 100644 index 0000000000..437c32d117 --- /dev/null +++ b/src/infrastructure/catbuffer/GeneratorUtils.ts @@ -0,0 +1,141 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +/** + * Generator utility class. + */ +export class GeneratorUtils { + + /** + * Converts a (64bit) uint8 array into a number array. + * @param {Uint8Array} input A uint8 array. + * @returns {number[]} The uint64 representation of the input. + */ + public static bufferToUint64 (input: Uint8Array): number[] { + if (8 !== input.length) { + throw Error(`byte array has unexpected size '${input.length}'`); + } + input = input.reverse(); + return [GeneratorUtils.readUint32At(input, 0), GeneratorUtils.readUint32At(input, 4)]; + } + + /** + * Read buffer into 32bits integer at given index. + * @param {Uint8Array} bytes A uint8 array. + * @param {number} index Index. + * @returns {number} 32bits integer. + */ + public static readUint32At(bytes: Uint8Array, index: number): number { + return (bytes[index] + (bytes[index + 1] << 8) + (bytes[index + 2] << 16) + (bytes[index + 3] << 24)) >>> 0; + } + + /** + * Write uint to buffer + * @param {number} uintValue A uint8 array. + * @param {number} bufferSize Buffer size. + * @returns {Uint8Array} + */ + public static uintToBuffer (uintValue: number, bufferSize: number): Uint8Array { + const buffer = new ArrayBuffer(bufferSize); + const dataView = new DataView(buffer); + if (1 === bufferSize) + dataView.setUint8(0, uintValue); + + else if (2 === bufferSize) + dataView.setUint16(0, uintValue, true); + + else if (4 === bufferSize) + dataView.setUint32(0, uintValue, true); + + else + throw new Error('Unexpected bufferSize'); + + return new Uint8Array(buffer); + } + + /** + * Write uint to buffer + * @param {Uint8Array} buffer A uint8 array. + * @returns {number} + */ + public static bufferToUint(buffer: Uint8Array): number { + const dataView = new DataView(buffer.buffer); + if (1 === buffer.byteLength) + return dataView.getUint8(0); + + else if (2 === buffer.byteLength) + return dataView.getUint16(0, true); + + else if (4 === buffer.byteLength) + return dataView.getUint32(0, true); + + throw new Error('Unexpected buffer size'); + }; + + /** + * Write Uint64 to buffer + * @param {number} uintValue Uint64 (number[]). + * @returns {Uint8Array} + */ + public static uint64ToBuffer(uintValue: number[]): Uint8Array { + const uint32Array = new Uint32Array(uintValue); + return new Uint8Array(uint32Array.buffer); + } + + /** + * Concatenate two arrays + * @param {Uint8Array} array1 A Uint8Array. + * @param {Uint8Array} array2 A Uint8Array. + * @returns {Uint8Array} + */ + public static concatTypedArrays(array1: Uint8Array, array2: Uint8Array): Uint8Array { + const newArray = new Uint8Array(array1.length + array2.length); + newArray.set(array1); + newArray.set(array2, array1.length); + return newArray; + } + + /** Converts an unsigned byte to a signed byte with the same binary representation. + * @param {number} input An unsigned byte. + * @returns {number} A signed byte with the same binary representation as the input. + * + */ + public static uint8ToInt8 = (input: number): number => { + if (0xFF < input) { + throw Error(`input '${input}' is out of range`); + } + return input << 24 >> 24; + } + + /** Get bytes by given sub array size. + * @param {Uint8Array} binary Binary bytes array. + * @param {number} size Subarray size. + * @returns {Uint8Array} + * + */ + public static getBytes(binary: Uint8Array, size: number): Uint8Array { + if (size > binary.length) + throw new RangeError(); + + const bytes = binary.slice(0, size); + return bytes; + } +} diff --git a/src/infrastructure/catbuffer/Hash256Dto.ts b/src/infrastructure/catbuffer/Hash256Dto.ts new file mode 100644 index 0000000000..0f09dfda19 --- /dev/null +++ b/src/infrastructure/catbuffer/Hash256Dto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Hash256. */ +export class Hash256Dto { + /** Hash256. */ + hash256: Uint8Array; + + /** + * Constructor. + * + * @param hash256 Hash256. + */ + constructor(hash256: Uint8Array) { + this.hash256 = hash256; + } + + /** + * Creates an instance of Hash256Dto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of Hash256Dto. + */ + public static loadFromBinary(payload: Uint8Array): Hash256Dto { + const byteArray = Array.from(payload); + const hash256 = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 32); + byteArray.splice(0, 32); + return new Hash256Dto(hash256); + } + + /** + * Gets Hash256. + * + * @return Hash256. + */ + public getHash256(): Uint8Array { + return this.hash256; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 32; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.hash256); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/Hash512Dto.ts b/src/infrastructure/catbuffer/Hash512Dto.ts new file mode 100644 index 0000000000..1455eb7623 --- /dev/null +++ b/src/infrastructure/catbuffer/Hash512Dto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Hash512. */ +export class Hash512Dto { + /** Hash512. */ + hash512: Uint8Array; + + /** + * Constructor. + * + * @param hash512 Hash512. + */ + constructor(hash512: Uint8Array) { + this.hash512 = hash512; + } + + /** + * Creates an instance of Hash512Dto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of Hash512Dto. + */ + public static loadFromBinary(payload: Uint8Array): Hash512Dto { + const byteArray = Array.from(payload); + const hash512 = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 64); + byteArray.splice(0, 64); + return new Hash512Dto(hash512); + } + + /** + * Gets Hash512. + * + * @return Hash512. + */ + public getHash512(): Uint8Array { + return this.hash512; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 64; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.hash512); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/HashLockTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/HashLockTransactionBodyBuilder.ts new file mode 100644 index 0000000000..26d8158335 --- /dev/null +++ b/src/infrastructure/catbuffer/HashLockTransactionBodyBuilder.ts @@ -0,0 +1,121 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a hash lock transaction. */ +export class HashLockTransactionBodyBuilder { + /** Lock mosaic. */ + mosaic: UnresolvedMosaicBuilder; + /** Number of blocks for which a lock should be valid. */ + duration: BlockDurationDto; + /** Lock hash. */ + hash: Hash256Dto; + + /** + * Constructor. + * + * @param mosaic Lock mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hash Lock hash. + */ + public constructor(mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hash: Hash256Dto) { + this.mosaic = mosaic; + this.duration = duration; + this.hash = hash; + } + + /** + * Creates an instance of HashLockTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of HashLockTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): HashLockTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaic = UnresolvedMosaicBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaic.getSize()); + const duration = BlockDurationDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, duration.getSize()); + const hash = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, hash.getSize()); + return new HashLockTransactionBodyBuilder(mosaic, duration, hash); + } + + /** + * Gets lock mosaic. + * + * @return Lock mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.mosaic; + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.duration; + } + + /** + * Gets lock hash. + * + * @return Lock hash. + */ + public getHash(): Hash256Dto { + return this.hash; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaic.getSize(); + size += this.duration.getSize(); + size += this.hash.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicBytes = this.mosaic.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicBytes); + const durationBytes = this.duration.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, durationBytes); + const hashBytes = this.hash.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/HashLockTransactionBuilder.ts b/src/infrastructure/catbuffer/HashLockTransactionBuilder.ts new file mode 100644 index 0000000000..b6c5b9643f --- /dev/null +++ b/src/infrastructure/catbuffer/HashLockTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { BlockDurationDto } from './BlockDurationDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { HashLockTransactionBodyBuilder } from './HashLockTransactionBodyBuilder'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a non-embedded hash lock transaction. */ +export class HashLockTransactionBuilder extends TransactionBuilder { + /** Hash lock transaction body. */ + hashLockTransactionBody: HashLockTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaic Lock mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hash Lock hash. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hash: Hash256Dto) { + super(signature, signer, version, type, fee, deadline); + this.hashLockTransactionBody = new HashLockTransactionBodyBuilder(mosaic, duration, hash); + } + + /** + * Creates an instance of HashLockTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of HashLockTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): HashLockTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const hashLockTransactionBody = HashLockTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, hashLockTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new HashLockTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, hashLockTransactionBody.mosaic, hashLockTransactionBody.duration, hashLockTransactionBody.hash); + } + + /** + * Gets lock mosaic. + * + * @return Lock mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.hashLockTransactionBody.getMosaic(); + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.hashLockTransactionBody.getDuration(); + } + + /** + * Gets lock hash. + * + * @return Lock hash. + */ + public getHash(): Hash256Dto { + return this.hashLockTransactionBody.getHash(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.hashLockTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const hashLockTransactionBodyBytes = this.hashLockTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashLockTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/KeyDto.ts b/src/infrastructure/catbuffer/KeyDto.ts new file mode 100644 index 0000000000..ea1fb55242 --- /dev/null +++ b/src/infrastructure/catbuffer/KeyDto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Key. */ +export class KeyDto { + /** Key. */ + key: Uint8Array; + + /** + * Constructor. + * + * @param key Key. + */ + constructor(key: Uint8Array) { + this.key = key; + } + + /** + * Creates an instance of KeyDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of KeyDto. + */ + public static loadFromBinary(payload: Uint8Array): KeyDto { + const byteArray = Array.from(payload); + const key = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 32); + byteArray.splice(0, 32); + return new KeyDto(key); + } + + /** + * Gets Key. + * + * @return Key. + */ + public getKey(): Uint8Array { + return this.key; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 32; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.key); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/LockHashAlgorithmDto.ts b/src/infrastructure/catbuffer/LockHashAlgorithmDto.ts new file mode 100644 index 0000000000..46ed416098 --- /dev/null +++ b/src/infrastructure/catbuffer/LockHashAlgorithmDto.ts @@ -0,0 +1,33 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of lock hash algorithms. */ +export enum LockHashAlgorithmDto { + /** Input is hashed using sha-3 256. */ + SHA3_256 = 0, + /** Input is hashed using keccak 256. */ + KECCAK_256 = 1, + /** Input is hashed twice: first with sha-256 and then with ripemd-160 (bitcoin's OP_HASH160). */ + HASH_160 = 2, + /** Input is hashed twice with sha-256 (bitcoin's OP_HASH256). */ + HASH_256 = 3, +} diff --git a/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..2572bae2f0 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,158 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a mosaic address restriction transaction. */ +export class MosaicAddressRestrictionTransactionBodyBuilder { + /** Identifier of the mosaic to which the restriction applies. */ + mosaicId: UnresolvedMosaicIdDto; + /** Restriction key. */ + restrictionKey: number[]; + /** Address being restricted. */ + targetAddress: UnresolvedAddressDto; + /** Previous restriction value. */ + previousRestrictionValue: number[]; + /** New restriction value. */ + newRestrictionValue: number[]; + + /** + * Constructor. + * + * @param mosaicId Identifier of the mosaic to which the restriction applies. + * @param restrictionKey Restriction key. + * @param targetAddress Address being restricted. + * @param previousRestrictionValue Previous restriction value. + * @param newRestrictionValue New restriction value. + */ + // tslint:disable-next-line: max-line-length + public constructor(mosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], targetAddress: UnresolvedAddressDto, previousRestrictionValue: number[], newRestrictionValue: number[]) { + this.mosaicId = mosaicId; + this.restrictionKey = restrictionKey; + this.targetAddress = targetAddress; + this.previousRestrictionValue = previousRestrictionValue; + this.newRestrictionValue = newRestrictionValue; + } + + /** + * Creates an instance of MosaicAddressRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicAddressRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicAddressRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const restrictionKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const targetAddress = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetAddress.getSize()); + const previousRestrictionValue = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const newRestrictionValue = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + // tslint:disable-next-line: max-line-length + return new MosaicAddressRestrictionTransactionBodyBuilder(mosaicId, restrictionKey, targetAddress, previousRestrictionValue, newRestrictionValue); + } + + /** + * Gets identifier of the mosaic to which the restriction applies. + * + * @return Identifier of the mosaic to which the restriction applies. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicId; + } + + /** + * Gets restriction key. + * + * @return Restriction key. + */ + public getRestrictionKey(): number[] { + return this.restrictionKey; + } + + /** + * Gets address being restricted. + * + * @return Address being restricted. + */ + public getTargetAddress(): UnresolvedAddressDto { + return this.targetAddress; + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.previousRestrictionValue; + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.newRestrictionValue; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += 8; // restrictionKey + size += this.targetAddress.getSize(); + size += 8; // previousRestrictionValue + size += 8; // newRestrictionValue + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const restrictionKeyBytes = GeneratorUtils.uint64ToBuffer(this.getRestrictionKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionKeyBytes); + const targetAddressBytes = this.targetAddress.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetAddressBytes); + const previousRestrictionValueBytes = GeneratorUtils.uint64ToBuffer(this.getPreviousRestrictionValue()); + newArray = GeneratorUtils.concatTypedArrays(newArray, previousRestrictionValueBytes); + const newRestrictionValueBytes = GeneratorUtils.uint64ToBuffer(this.getNewRestrictionValue()); + newArray = GeneratorUtils.concatTypedArrays(newArray, newRestrictionValueBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..ba0d6b5d7e --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder.ts @@ -0,0 +1,146 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicAddressRestrictionTransactionBodyBuilder } from './MosaicAddressRestrictionTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a non-embedded mosaic address restriction transaction. */ +export class MosaicAddressRestrictionTransactionBuilder extends TransactionBuilder { + /** Mosaic address restriction transaction body. */ + mosaicAddressRestrictionTransactionBody: MosaicAddressRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaicId Identifier of the mosaic to which the restriction applies. + * @param restrictionKey Restriction key. + * @param targetAddress Address being restricted. + * @param previousRestrictionValue Previous restriction value. + * @param newRestrictionValue New restriction value. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], targetAddress: UnresolvedAddressDto, previousRestrictionValue: number[], newRestrictionValue: number[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.mosaicAddressRestrictionTransactionBody = new MosaicAddressRestrictionTransactionBodyBuilder(mosaicId, restrictionKey, targetAddress, previousRestrictionValue, newRestrictionValue); + } + + /** + * Creates an instance of MosaicAddressRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicAddressRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicAddressRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicAddressRestrictionTransactionBody = MosaicAddressRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicAddressRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicAddressRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicAddressRestrictionTransactionBody.mosaicId, mosaicAddressRestrictionTransactionBody.restrictionKey, mosaicAddressRestrictionTransactionBody.targetAddress, mosaicAddressRestrictionTransactionBody.previousRestrictionValue, mosaicAddressRestrictionTransactionBody.newRestrictionValue); + } + + /** + * Gets identifier of the mosaic to which the restriction applies. + * + * @return Identifier of the mosaic to which the restriction applies. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicAddressRestrictionTransactionBody.getMosaicId(); + } + + /** + * Gets restriction key. + * + * @return Restriction key. + */ + public getRestrictionKey(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getRestrictionKey(); + } + + /** + * Gets address being restricted. + * + * @return Address being restricted. + */ + public getTargetAddress(): UnresolvedAddressDto { + return this.mosaicAddressRestrictionTransactionBody.getTargetAddress(); + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getPreviousRestrictionValue(); + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getNewRestrictionValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicAddressRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicAddressRestrictionTransactionBodyBytes = this.mosaicAddressRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicAddressRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicAliasTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicAliasTransactionBodyBuilder.ts new file mode 100644 index 0000000000..6c411a6ecb --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicAliasTransactionBodyBuilder.ts @@ -0,0 +1,121 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AliasActionDto } from './AliasActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicIdDto } from './MosaicIdDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for an mosaic alias transaction. */ +export class MosaicAliasTransactionBodyBuilder { + /** Alias action. */ + aliasAction: AliasActionDto; + /** Identifier of the namespace that will become an alias. */ + namespaceId: NamespaceIdDto; + /** Aliased mosaic identifier. */ + mosaicId: MosaicIdDto; + + /** + * Constructor. + * + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param mosaicId Aliased mosaic identifier. + */ + public constructor(aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, mosaicId: MosaicIdDto) { + this.aliasAction = aliasAction; + this.namespaceId = namespaceId; + this.mosaicId = mosaicId; + } + + /** + * Creates an instance of MosaicAliasTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicAliasTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicAliasTransactionBodyBuilder { + const byteArray = Array.from(payload); + const aliasAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const namespaceId = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceId.getSize()); + const mosaicId = MosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + return new MosaicAliasTransactionBodyBuilder(aliasAction, namespaceId, mosaicId); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.aliasAction; + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.namespaceId; + } + + /** + * Gets aliased mosaic identifier. + * + * @return Aliased mosaic identifier. + */ + public getMosaicId(): MosaicIdDto { + return this.mosaicId; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // aliasAction + size += this.namespaceId.getSize(); + size += this.mosaicId.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const aliasActionBytes = GeneratorUtils.uintToBuffer(this.aliasAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, aliasActionBytes); + const namespaceIdBytes = this.namespaceId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceIdBytes); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicAliasTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicAliasTransactionBuilder.ts new file mode 100644 index 0000000000..d126fef24c --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicAliasTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AliasActionDto } from './AliasActionDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicAliasTransactionBodyBuilder } from './MosaicAliasTransactionBodyBuilder'; +import { MosaicIdDto } from './MosaicIdDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded mosaic alias transaction. */ +export class MosaicAliasTransactionBuilder extends TransactionBuilder { + /** Mosaic alias transaction body. */ + mosaicAliasTransactionBody: MosaicAliasTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param mosaicId Aliased mosaic identifier. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, mosaicId: MosaicIdDto) { + super(signature, signer, version, type, fee, deadline); + this.mosaicAliasTransactionBody = new MosaicAliasTransactionBodyBuilder(aliasAction, namespaceId, mosaicId); + } + + /** + * Creates an instance of MosaicAliasTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicAliasTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicAliasTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const mosaicAliasTransactionBody = MosaicAliasTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicAliasTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicAliasTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicAliasTransactionBody.aliasAction, mosaicAliasTransactionBody.namespaceId, mosaicAliasTransactionBody.mosaicId); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.mosaicAliasTransactionBody.getAliasAction(); + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.mosaicAliasTransactionBody.getNamespaceId(); + } + + /** + * Gets aliased mosaic identifier. + * + * @return Aliased mosaic identifier. + */ + public getMosaicId(): MosaicIdDto { + return this.mosaicAliasTransactionBody.getMosaicId(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicAliasTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicAliasTransactionBodyBytes = this.mosaicAliasTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicAliasTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicBuilder.ts b/src/infrastructure/catbuffer/MosaicBuilder.ts new file mode 100644 index 0000000000..dc2ac60e87 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicIdDto } from './MosaicIdDto'; + +/** Binary layout for a mosaic. */ +export class MosaicBuilder { + /** Mosaic identifier. */ + mosaicId: MosaicIdDto; + /** Mosaic amount. */ + amount: AmountDto; + + /** + * Constructor. + * + * @param mosaicId Mosaic identifier. + * @param amount Mosaic amount. + */ + public constructor(mosaicId: MosaicIdDto, amount: AmountDto) { + this.mosaicId = mosaicId; + this.amount = amount; + } + + /** + * Creates an instance of MosaicBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicBuilder { + const byteArray = Array.from(payload); + const mosaicId = MosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const amount = AmountDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, amount.getSize()); + return new MosaicBuilder(mosaicId, amount); + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getMosaicId(): MosaicIdDto { + return this.mosaicId; + } + + /** + * Gets mosaic amount. + * + * @return Mosaic amount. + */ + public getAmount(): AmountDto { + return this.amount; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += this.amount.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const amountBytes = this.amount.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, amountBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicDefinitionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicDefinitionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..b82254e5f7 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicDefinitionTransactionBodyBuilder.ts @@ -0,0 +1,158 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicIdDto } from './MosaicIdDto'; +import { MosaicNonceDto } from './MosaicNonceDto'; + +/** Binary layout for a mosaic definition transaction. */ +export class MosaicDefinitionTransactionBodyBuilder { + /** Mosaic nonce. */ + nonce: MosaicNonceDto; + /** Mosaic identifier. */ + id: MosaicIdDto; + /** Mosaic flags. */ + flags: number; + /** Mosaic divisibility. */ + divisibility: number; + /** Mosaic duration. */ + duration: BlockDurationDto; + + /** + * Constructor. + * + * @param nonce Mosaic nonce. + * @param id Mosaic identifier. + * @param flags Mosaic flags. + * @param divisibility Mosaic divisibility. + * @param duration Mosaic duration. + */ + // tslint:disable-next-line: max-line-length + public constructor(nonce: MosaicNonceDto, id: MosaicIdDto, flags: number, divisibility: number, duration: BlockDurationDto) { + this.nonce = nonce; + this.id = id; + this.flags = flags; + this.divisibility = divisibility; + this.duration = duration; + } + + /** + * Creates an instance of MosaicDefinitionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicDefinitionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicDefinitionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const nonce = MosaicNonceDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, nonce.getSize()); + const id = MosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, id.getSize()); + const flags = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const divisibility = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const duration = BlockDurationDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, duration.getSize()); + return new MosaicDefinitionTransactionBodyBuilder(nonce, id, flags, divisibility, duration); + } + + /** + * Gets mosaic nonce. + * + * @return Mosaic nonce. + */ + public getNonce(): MosaicNonceDto { + return this.nonce; + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getId(): MosaicIdDto { + return this.id; + } + + /** + * Gets mosaic flags. + * + * @return Mosaic flags. + */ + public getFlags(): number { + return this.flags; + } + + /** + * Gets mosaic divisibility. + * + * @return Mosaic divisibility. + */ + public getDivisibility(): number { + return this.divisibility; + } + + /** + * Gets mosaic duration. + * + * @return Mosaic duration. + */ + public getDuration(): BlockDurationDto { + return this.duration; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.nonce.getSize(); + size += this.id.getSize(); + size += 1; // flags + size += 1; // divisibility + size += this.duration.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const nonceBytes = this.nonce.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, nonceBytes); + const idBytes = this.id.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, idBytes); + const flagsBytes = GeneratorUtils.uintToBuffer(this.getFlags(), 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, flagsBytes); + const divisibilityBytes = GeneratorUtils.uintToBuffer(this.getDivisibility(), 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, divisibilityBytes); + const durationBytes = this.duration.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, durationBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicDefinitionTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicDefinitionTransactionBuilder.ts new file mode 100644 index 0000000000..a32b33b5d9 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicDefinitionTransactionBuilder.ts @@ -0,0 +1,147 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { BlockDurationDto } from './BlockDurationDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicDefinitionTransactionBodyBuilder } from './MosaicDefinitionTransactionBodyBuilder'; +import { MosaicIdDto } from './MosaicIdDto'; +import { MosaicNonceDto } from './MosaicNonceDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded mosaic definition transaction. */ +export class MosaicDefinitionTransactionBuilder extends TransactionBuilder { + /** Mosaic definition transaction body. */ + mosaicDefinitionTransactionBody: MosaicDefinitionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param nonce Mosaic nonce. + * @param id Mosaic identifier. + * @param flags Mosaic flags. + * @param divisibility Mosaic divisibility. + * @param duration Mosaic duration. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, nonce: MosaicNonceDto, id: MosaicIdDto, flags: number, divisibility: number, duration: BlockDurationDto) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.mosaicDefinitionTransactionBody = new MosaicDefinitionTransactionBodyBuilder(nonce, id, flags, divisibility, duration); + } + + /** + * Creates an instance of MosaicDefinitionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicDefinitionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicDefinitionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicDefinitionTransactionBody = MosaicDefinitionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicDefinitionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicDefinitionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicDefinitionTransactionBody.nonce, mosaicDefinitionTransactionBody.id, mosaicDefinitionTransactionBody.flags, mosaicDefinitionTransactionBody.divisibility, mosaicDefinitionTransactionBody.duration); + } + + /** + * Gets mosaic nonce. + * + * @return Mosaic nonce. + */ + public getNonce(): MosaicNonceDto { + return this.mosaicDefinitionTransactionBody.getNonce(); + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getId(): MosaicIdDto { + return this.mosaicDefinitionTransactionBody.getId(); + } + + /** + * Gets mosaic flags. + * + * @return Mosaic flags. + */ + public getFlags(): number { + return this.mosaicDefinitionTransactionBody.getFlags(); + } + + /** + * Gets mosaic divisibility. + * + * @return Mosaic divisibility. + */ + public getDivisibility(): number { + return this.mosaicDefinitionTransactionBody.getDivisibility(); + } + + /** + * Gets mosaic duration. + * + * @return Mosaic duration. + */ + public getDuration(): BlockDurationDto { + return this.mosaicDefinitionTransactionBody.getDuration(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicDefinitionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicDefinitionTransactionBodyBytes = this.mosaicDefinitionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicDefinitionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicFlagsDto.ts b/src/infrastructure/catbuffer/MosaicFlagsDto.ts new file mode 100644 index 0000000000..11a740ab03 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicFlagsDto.ts @@ -0,0 +1,33 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of mosaic property flags. */ +export enum MosaicFlagsDto { + /** No flags present. */ + NONE = 0, + /** Mosaic supports supply changes even when mosaic owner owns partial supply. */ + SUPPLY_MUTABLE = 1, + /** Mosaic supports transfers between arbitrary accounts \note when not set, mosaic can only be transferred to and from mosaic owner. */ + TRANSFERABLE = 2, + /** Mosaic supports custom restrictions configured by mosaic owner. */ + RESTRICTABLE = 4, +} diff --git a/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..09f3fd4e5e --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,194 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicRestrictionTypeDto } from './MosaicRestrictionTypeDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a mosaic global restriction transaction. */ +export class MosaicGlobalRestrictionTransactionBodyBuilder { + /** Identifier of the mosaic being restricted. */ + mosaicId: UnresolvedMosaicIdDto; + /** Identifier of the mosaic providing the restriction key. */ + referenceMosaicId: UnresolvedMosaicIdDto; + /** Restriction key relative to the reference mosaic identifier. */ + restrictionKey: number[]; + /** Previous restriction value. */ + previousRestrictionValue: number[]; + /** Previous restriction type. */ + previousRestrictionType: MosaicRestrictionTypeDto; + /** New restriction value. */ + newRestrictionValue: number[]; + /** New restriction type. */ + newRestrictionType: MosaicRestrictionTypeDto; + + /** + * Constructor. + * + * @param mosaicId Identifier of the mosaic being restricted. + * @param referenceMosaicId Identifier of the mosaic providing the restriction key. + * @param restrictionKey Restriction key relative to the reference mosaic identifier. + * @param previousRestrictionValue Previous restriction value. + * @param previousRestrictionType Previous restriction type. + * @param newRestrictionValue New restriction value. + * @param newRestrictionType New restriction type. + */ + // tslint:disable-next-line: max-line-length + public constructor(mosaicId: UnresolvedMosaicIdDto, referenceMosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], previousRestrictionValue: number[], previousRestrictionType: MosaicRestrictionTypeDto, newRestrictionValue: number[], newRestrictionType: MosaicRestrictionTypeDto) { + this.mosaicId = mosaicId; + this.referenceMosaicId = referenceMosaicId; + this.restrictionKey = restrictionKey; + this.previousRestrictionValue = previousRestrictionValue; + this.previousRestrictionType = previousRestrictionType; + this.newRestrictionValue = newRestrictionValue; + this.newRestrictionType = newRestrictionType; + } + + /** + * Creates an instance of MosaicGlobalRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicGlobalRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicGlobalRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const referenceMosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, referenceMosaicId.getSize()); + const restrictionKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const previousRestrictionValue = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const previousRestrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const newRestrictionValue = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const newRestrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + // tslint:disable-next-line: max-line-length + return new MosaicGlobalRestrictionTransactionBodyBuilder(mosaicId, referenceMosaicId, restrictionKey, previousRestrictionValue, previousRestrictionType, newRestrictionValue, newRestrictionType); + } + + /** + * Gets identifier of the mosaic being restricted. + * + * @return Identifier of the mosaic being restricted. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicId; + } + + /** + * Gets identifier of the mosaic providing the restriction key. + * + * @return Identifier of the mosaic providing the restriction key. + */ + public getReferenceMosaicId(): UnresolvedMosaicIdDto { + return this.referenceMosaicId; + } + + /** + * Gets restriction key relative to the reference mosaic identifier. + * + * @return Restriction key relative to the reference mosaic identifier. + */ + public getRestrictionKey(): number[] { + return this.restrictionKey; + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.previousRestrictionValue; + } + + /** + * Gets previous restriction type. + * + * @return Previous restriction type. + */ + public getPreviousRestrictionType(): MosaicRestrictionTypeDto { + return this.previousRestrictionType; + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.newRestrictionValue; + } + + /** + * Gets new restriction type. + * + * @return New restriction type. + */ + public getNewRestrictionType(): MosaicRestrictionTypeDto { + return this.newRestrictionType; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += this.referenceMosaicId.getSize(); + size += 8; // restrictionKey + size += 8; // previousRestrictionValue + size += 1; // previousRestrictionType + size += 8; // newRestrictionValue + size += 1; // newRestrictionType + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const referenceMosaicIdBytes = this.referenceMosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, referenceMosaicIdBytes); + const restrictionKeyBytes = GeneratorUtils.uint64ToBuffer(this.getRestrictionKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionKeyBytes); + const previousRestrictionValueBytes = GeneratorUtils.uint64ToBuffer(this.getPreviousRestrictionValue()); + newArray = GeneratorUtils.concatTypedArrays(newArray, previousRestrictionValueBytes); + const previousRestrictionTypeBytes = GeneratorUtils.uintToBuffer(this.previousRestrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, previousRestrictionTypeBytes); + const newRestrictionValueBytes = GeneratorUtils.uint64ToBuffer(this.getNewRestrictionValue()); + newArray = GeneratorUtils.concatTypedArrays(newArray, newRestrictionValueBytes); + const newRestrictionTypeBytes = GeneratorUtils.uintToBuffer(this.newRestrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, newRestrictionTypeBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..e84414e6e2 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder.ts @@ -0,0 +1,166 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicGlobalRestrictionTransactionBodyBuilder } from './MosaicGlobalRestrictionTransactionBodyBuilder'; +import { MosaicRestrictionTypeDto } from './MosaicRestrictionTypeDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a non-embedded mosaic global restriction transaction. */ +export class MosaicGlobalRestrictionTransactionBuilder extends TransactionBuilder { + /** Mosaic global restriction transaction body. */ + mosaicGlobalRestrictionTransactionBody: MosaicGlobalRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaicId Identifier of the mosaic being restricted. + * @param referenceMosaicId Identifier of the mosaic providing the restriction key. + * @param restrictionKey Restriction key relative to the reference mosaic identifier. + * @param previousRestrictionValue Previous restriction value. + * @param previousRestrictionType Previous restriction type. + * @param newRestrictionValue New restriction value. + * @param newRestrictionType New restriction type. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaicId: UnresolvedMosaicIdDto, referenceMosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], previousRestrictionValue: number[], previousRestrictionType: MosaicRestrictionTypeDto, newRestrictionValue: number[], newRestrictionType: MosaicRestrictionTypeDto) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.mosaicGlobalRestrictionTransactionBody = new MosaicGlobalRestrictionTransactionBodyBuilder(mosaicId, referenceMosaicId, restrictionKey, previousRestrictionValue, previousRestrictionType, newRestrictionValue, newRestrictionType); + } + + /** + * Creates an instance of MosaicGlobalRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicGlobalRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicGlobalRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicGlobalRestrictionTransactionBody = MosaicGlobalRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicGlobalRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicGlobalRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicGlobalRestrictionTransactionBody.mosaicId, mosaicGlobalRestrictionTransactionBody.referenceMosaicId, mosaicGlobalRestrictionTransactionBody.restrictionKey, mosaicGlobalRestrictionTransactionBody.previousRestrictionValue, mosaicGlobalRestrictionTransactionBody.previousRestrictionType, mosaicGlobalRestrictionTransactionBody.newRestrictionValue, mosaicGlobalRestrictionTransactionBody.newRestrictionType); + } + + /** + * Gets identifier of the mosaic being restricted. + * + * @return Identifier of the mosaic being restricted. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicGlobalRestrictionTransactionBody.getMosaicId(); + } + + /** + * Gets identifier of the mosaic providing the restriction key. + * + * @return Identifier of the mosaic providing the restriction key. + */ + public getReferenceMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicGlobalRestrictionTransactionBody.getReferenceMosaicId(); + } + + /** + * Gets restriction key relative to the reference mosaic identifier. + * + * @return Restriction key relative to the reference mosaic identifier. + */ + public getRestrictionKey(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getRestrictionKey(); + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getPreviousRestrictionValue(); + } + + /** + * Gets previous restriction type. + * + * @return Previous restriction type. + */ + public getPreviousRestrictionType(): MosaicRestrictionTypeDto { + return this.mosaicGlobalRestrictionTransactionBody.getPreviousRestrictionType(); + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getNewRestrictionValue(); + } + + /** + * Gets new restriction type. + * + * @return New restriction type. + */ + public getNewRestrictionType(): MosaicRestrictionTypeDto { + return this.mosaicGlobalRestrictionTransactionBody.getNewRestrictionType(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicGlobalRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicGlobalRestrictionTransactionBodyBytes = this.mosaicGlobalRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicGlobalRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicIdDto.ts b/src/infrastructure/catbuffer/MosaicIdDto.ts new file mode 100644 index 0000000000..dd88e70b01 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicIdDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Mosaic id. */ +export class MosaicIdDto { + /** Mosaic id. */ + mosaicId: number[]; + + /** + * Constructor. + * + * @param mosaicId Mosaic id. + */ + constructor(mosaicId: number[]) { + this.mosaicId = mosaicId; + } + + /** + * Creates an instance of MosaicIdDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicIdDto. + */ + public static loadFromBinary(payload: Uint8Array): MosaicIdDto { + const byteArray = Array.from(payload); + const mosaicId = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new MosaicIdDto(mosaicId); + } + + /** + * Gets Mosaic id. + * + * @return Mosaic id. + */ + public getMosaicId(): number[] { + return this.mosaicId; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = GeneratorUtils.uint64ToBuffer(this.getMosaicId()); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicMetadataTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicMetadataTransactionBodyBuilder.ts new file mode 100644 index 0000000000..a4ee75bcbc --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicMetadataTransactionBodyBuilder.ts @@ -0,0 +1,168 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a mosaic metadata transaction. */ +export class MosaicMetadataTransactionBodyBuilder { + /** Metadata target public key. */ + targetPublicKey: KeyDto; + /** Metadata key scoped to source, target and type. */ + scopedMetadataKey: number[]; + /** Target mosaic identifier. */ + targetMosaicId: UnresolvedMosaicIdDto; + /** Change in value size in bytes. */ + valueSizeDelta: number; + /** Difference between existing value and new value \note when there is no existing value, new value is same this value \note when there is an existing value, new value is calculated as xor(previous-value, value). */ + value: Uint8Array; + + /** + * Constructor. + * + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetMosaicId Target mosaic identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(targetPublicKey: KeyDto, scopedMetadataKey: number[], targetMosaicId: UnresolvedMosaicIdDto, valueSizeDelta: number, value: Uint8Array) { + this.targetPublicKey = targetPublicKey; + this.scopedMetadataKey = scopedMetadataKey; + this.targetMosaicId = targetMosaicId; + this.valueSizeDelta = valueSizeDelta; + this.value = value; + } + + /** + * Creates an instance of MosaicMetadataTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicMetadataTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicMetadataTransactionBodyBuilder { + const byteArray = Array.from(payload); + const targetPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetPublicKey.getSize()); + const scopedMetadataKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const targetMosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetMosaicId.getSize()); + const valueSizeDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const valueSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const value = GeneratorUtils.getBytes(Uint8Array.from(byteArray), valueSize); + byteArray.splice(0, valueSize); + // tslint:disable-next-line: max-line-length + return new MosaicMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetMosaicId, valueSizeDelta, value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.targetPublicKey; + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.scopedMetadataKey; + } + + /** + * Gets target mosaic identifier. + * + * @return Target mosaic identifier. + */ + public getTargetMosaicId(): UnresolvedMosaicIdDto { + return this.targetMosaicId; + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.valueSizeDelta; + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.targetPublicKey.getSize(); + size += 8; // scopedMetadataKey + size += this.targetMosaicId.getSize(); + size += 2; // valueSizeDelta + size += 2; // valueSize + size += this.value.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const targetPublicKeyBytes = this.targetPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetPublicKeyBytes); + const scopedMetadataKeyBytes = GeneratorUtils.uint64ToBuffer(this.getScopedMetadataKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, scopedMetadataKeyBytes); + const targetMosaicIdBytes = this.targetMosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetMosaicIdBytes); + const valueSizeDeltaBytes = GeneratorUtils.uintToBuffer(this.getValueSizeDelta(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeDeltaBytes); + const valueSizeBytes = GeneratorUtils.uintToBuffer(this.value.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.value); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..1a5866a030 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicMetadataTransactionBuilder.ts @@ -0,0 +1,150 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicMetadataTransactionBodyBuilder } from './MosaicMetadataTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a non-embedded mosaic metadata transaction. */ +export class MosaicMetadataTransactionBuilder extends TransactionBuilder { + /** Mosaic metadata transaction body. */ + mosaicMetadataTransactionBody: MosaicMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetMosaicId Target mosaic identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], targetMosaicId: UnresolvedMosaicIdDto, valueSizeDelta: number, value: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.mosaicMetadataTransactionBody = new MosaicMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetMosaicId, valueSizeDelta, value); + } + + /** + * Creates an instance of MosaicMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const mosaicMetadataTransactionBody = MosaicMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicMetadataTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicMetadataTransactionBody.targetPublicKey, mosaicMetadataTransactionBody.scopedMetadataKey, mosaicMetadataTransactionBody.targetMosaicId, mosaicMetadataTransactionBody.valueSizeDelta, mosaicMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.mosaicMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.mosaicMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets target mosaic identifier. + * + * @return Target mosaic identifier. + */ + public getTargetMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicMetadataTransactionBody.getTargetMosaicId(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.mosaicMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.mosaicMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicMetadataTransactionBodyBytes = this.mosaicMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicNonceDto.ts b/src/infrastructure/catbuffer/MosaicNonceDto.ts new file mode 100644 index 0000000000..82db3703e0 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicNonceDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Mosaic nonce. */ +export class MosaicNonceDto { + /** Mosaic nonce. */ + mosaicNonce: number; + + /** + * Constructor. + * + * @param mosaicNonce Mosaic nonce. + */ + constructor(mosaicNonce: number) { + this.mosaicNonce = mosaicNonce; + } + + /** + * Creates an instance of MosaicNonceDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicNonceDto. + */ + public static loadFromBinary(payload: Uint8Array): MosaicNonceDto { + const byteArray = Array.from(payload); + const mosaicNonce = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + return new MosaicNonceDto(mosaicNonce); + } + + /** + * Gets Mosaic nonce. + * + * @return Mosaic nonce. + */ + public getMosaicNonce(): number { + return this.mosaicNonce; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 4; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicNonceBytes = GeneratorUtils.uintToBuffer(this.getMosaicNonce(), 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicNonceBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicRestrictionTypeDto.ts b/src/infrastructure/catbuffer/MosaicRestrictionTypeDto.ts new file mode 100644 index 0000000000..78b5f8d179 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicRestrictionTypeDto.ts @@ -0,0 +1,39 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of mosaic restriction types. */ +export enum MosaicRestrictionTypeDto { + /** Uninitialized value indicating no restriction. */ + NONE = 0, + /** Allow if equal. */ + EQ = 1, + /** Allow if not equal. */ + NE = 2, + /** Allow if less than. */ + LT = 3, + /** Allow if less than or equal. */ + LE = 4, + /** Allow if greater than. */ + GT = 5, + /** Allow if greater than or equal. */ + GE = 6, +} diff --git a/src/infrastructure/catbuffer/MosaicSupplyChangeActionDto.ts b/src/infrastructure/catbuffer/MosaicSupplyChangeActionDto.ts new file mode 100644 index 0000000000..eafa2d5b4e --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicSupplyChangeActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of mosaic supply change actions. */ +export enum MosaicSupplyChangeActionDto { + /** Decreases the supply. */ + DECREASE = 0, + /** Increases the supply. */ + INCREASE = 1, +} diff --git a/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBodyBuilder.ts new file mode 100644 index 0000000000..6e9a680728 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBodyBuilder.ts @@ -0,0 +1,121 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicSupplyChangeActionDto } from './MosaicSupplyChangeActionDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a mosaic supply change transaction. */ +export class MosaicSupplyChangeTransactionBodyBuilder { + /** Affected mosaic identifier. */ + mosaicId: UnresolvedMosaicIdDto; + /** Supply change action. */ + action: MosaicSupplyChangeActionDto; + /** Change amount. */ + delta: AmountDto; + + /** + * Constructor. + * + * @param mosaicId Affected mosaic identifier. + * @param action Supply change action. + * @param delta Change amount. + */ + public constructor(mosaicId: UnresolvedMosaicIdDto, action: MosaicSupplyChangeActionDto, delta: AmountDto) { + this.mosaicId = mosaicId; + this.action = action; + this.delta = delta; + } + + /** + * Creates an instance of MosaicSupplyChangeTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicSupplyChangeTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicSupplyChangeTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const action = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const delta = AmountDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, delta.getSize()); + return new MosaicSupplyChangeTransactionBodyBuilder(mosaicId, action, delta); + } + + /** + * Gets affected mosaic identifier. + * + * @return Affected mosaic identifier. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicId; + } + + /** + * Gets supply change action. + * + * @return Supply change action. + */ + public getAction(): MosaicSupplyChangeActionDto { + return this.action; + } + + /** + * Gets change amount. + * + * @return Change amount. + */ + public getDelta(): AmountDto { + return this.delta; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += 1; // action + size += this.delta.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const actionBytes = GeneratorUtils.uintToBuffer(this.action, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, actionBytes); + const deltaBytes = this.delta.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, deltaBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder.ts new file mode 100644 index 0000000000..ae1c675729 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicSupplyChangeActionDto } from './MosaicSupplyChangeActionDto'; +import { MosaicSupplyChangeTransactionBodyBuilder } from './MosaicSupplyChangeTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a non-embedded mosaic supply change transaction. */ +export class MosaicSupplyChangeTransactionBuilder extends TransactionBuilder { + /** Mosaic supply change transaction body. */ + mosaicSupplyChangeTransactionBody: MosaicSupplyChangeTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaicId Affected mosaic identifier. + * @param action Supply change action. + * @param delta Change amount. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaicId: UnresolvedMosaicIdDto, action: MosaicSupplyChangeActionDto, delta: AmountDto) { + super(signature, signer, version, type, fee, deadline); + this.mosaicSupplyChangeTransactionBody = new MosaicSupplyChangeTransactionBodyBuilder(mosaicId, action, delta); + } + + /** + * Creates an instance of MosaicSupplyChangeTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicSupplyChangeTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicSupplyChangeTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicSupplyChangeTransactionBody = MosaicSupplyChangeTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicSupplyChangeTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicSupplyChangeTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicSupplyChangeTransactionBody.mosaicId, mosaicSupplyChangeTransactionBody.action, mosaicSupplyChangeTransactionBody.delta); + } + + /** + * Gets affected mosaic identifier. + * + * @return Affected mosaic identifier. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicSupplyChangeTransactionBody.getMosaicId(); + } + + /** + * Gets supply change action. + * + * @return Supply change action. + */ + public getAction(): MosaicSupplyChangeActionDto { + return this.mosaicSupplyChangeTransactionBody.getAction(); + } + + /** + * Gets change amount. + * + * @return Change amount. + */ + public getDelta(): AmountDto { + return this.mosaicSupplyChangeTransactionBody.getDelta(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicSupplyChangeTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicSupplyChangeTransactionBodyBytes = this.mosaicSupplyChangeTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicSupplyChangeTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBodyBuilder.ts new file mode 100644 index 0000000000..9f646f89cb --- /dev/null +++ b/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBodyBuilder.ts @@ -0,0 +1,131 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { CosignatoryModificationBuilder } from './CosignatoryModificationBuilder'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for a multisig account modification transaction. */ +export class MultisigAccountModificationTransactionBodyBuilder { + /** Relative change of the minimal number of cosignatories required when removing an account. */ + minRemovalDelta: number; + /** Relative change of the minimal number of cosignatories required when approving a transaction. */ + minApprovalDelta: number; + /** Attached cosignatory modifications. */ + modifications: CosignatoryModificationBuilder[]; + + /** + * Constructor. + * + * @param minRemovalDelta Relative change of the minimal number of cosignatories required when removing an account. + * @param minApprovalDelta Relative change of the minimal number of cosignatories required when approving a transaction. + * @param modifications Attached cosignatory modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(minRemovalDelta: number, minApprovalDelta: number, modifications: CosignatoryModificationBuilder[]) { + this.minRemovalDelta = minRemovalDelta; + this.minApprovalDelta = minApprovalDelta; + this.modifications = modifications; + } + + /** + * Creates an instance of MultisigAccountModificationTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MultisigAccountModificationTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MultisigAccountModificationTransactionBodyBuilder { + const byteArray = Array.from(payload); + const minRemovalDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const minApprovalDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modificationsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modifications: CosignatoryModificationBuilder[] = []; + for (let i = 0; i < modificationsCount; i++) { + const item = CosignatoryModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + modifications.push(item); + byteArray.splice(0, item.getSize()); + } + return new MultisigAccountModificationTransactionBodyBuilder(minRemovalDelta, minApprovalDelta, modifications); + } + + /** + * Gets relative change of the minimal number of cosignatories required when removing an account. + * + * @return Relative change of the minimal number of cosignatories required when removing an account. + */ + public getMinRemovalDelta(): number { + return this.minRemovalDelta; + } + + /** + * Gets relative change of the minimal number of cosignatories required when approving a transaction. + * + * @return Relative change of the minimal number of cosignatories required when approving a transaction. + */ + public getMinApprovalDelta(): number { + return this.minApprovalDelta; + } + + /** + * Gets attached cosignatory modifications. + * + * @return Attached cosignatory modifications. + */ + public getModifications(): CosignatoryModificationBuilder[] { + return this.modifications; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // minRemovalDelta + size += 1; // minApprovalDelta + size += 1; // modificationsCount + this.modifications.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const minRemovalDeltaBytes = GeneratorUtils.uintToBuffer(this.getMinRemovalDelta(), 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, minRemovalDeltaBytes); + const minApprovalDeltaBytes = GeneratorUtils.uintToBuffer(this.getMinApprovalDelta(), 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, minApprovalDeltaBytes); + const modificationsCountBytes = GeneratorUtils.uintToBuffer(this.modifications.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsCountBytes); + this.modifications.forEach((item) => { + const modificationsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder.ts b/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder.ts new file mode 100644 index 0000000000..4405bdc6ca --- /dev/null +++ b/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { CosignatoryModificationBuilder } from './CosignatoryModificationBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MultisigAccountModificationTransactionBodyBuilder } from './MultisigAccountModificationTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded multisig account modification transaction. */ +export class MultisigAccountModificationTransactionBuilder extends TransactionBuilder { + /** Multisig account modification transaction body. */ + multisigAccountModificationTransactionBody: MultisigAccountModificationTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param minRemovalDelta Relative change of the minimal number of cosignatories required when removing an account. + * @param minApprovalDelta Relative change of the minimal number of cosignatories required when approving a transaction. + * @param modifications Attached cosignatory modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, minRemovalDelta: number, minApprovalDelta: number, modifications: CosignatoryModificationBuilder[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.multisigAccountModificationTransactionBody = new MultisigAccountModificationTransactionBodyBuilder(minRemovalDelta, minApprovalDelta, modifications); + } + + /** + * Creates an instance of MultisigAccountModificationTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MultisigAccountModificationTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MultisigAccountModificationTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const multisigAccountModificationTransactionBody = MultisigAccountModificationTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, multisigAccountModificationTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MultisigAccountModificationTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, multisigAccountModificationTransactionBody.minRemovalDelta, multisigAccountModificationTransactionBody.minApprovalDelta, multisigAccountModificationTransactionBody.modifications); + } + + /** + * Gets relative change of the minimal number of cosignatories required when removing an account. + * + * @return Relative change of the minimal number of cosignatories required when removing an account. + */ + public getMinRemovalDelta(): number { + return this.multisigAccountModificationTransactionBody.getMinRemovalDelta(); + } + + /** + * Gets relative change of the minimal number of cosignatories required when approving a transaction. + * + * @return Relative change of the minimal number of cosignatories required when approving a transaction. + */ + public getMinApprovalDelta(): number { + return this.multisigAccountModificationTransactionBody.getMinApprovalDelta(); + } + + /** + * Gets attached cosignatory modifications. + * + * @return Attached cosignatory modifications. + */ + public getModifications(): CosignatoryModificationBuilder[] { + return this.multisigAccountModificationTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.multisigAccountModificationTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const multisigAccountModificationTransactionBodyBytes = this.multisigAccountModificationTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, multisigAccountModificationTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceIdDto.ts b/src/infrastructure/catbuffer/NamespaceIdDto.ts new file mode 100644 index 0000000000..498f63dbe3 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceIdDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Namespace id. */ +export class NamespaceIdDto { + /** Namespace id. */ + namespaceId: number[]; + + /** + * Constructor. + * + * @param namespaceId Namespace id. + */ + constructor(namespaceId: number[]) { + this.namespaceId = namespaceId; + } + + /** + * Creates an instance of NamespaceIdDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceIdDto. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceIdDto { + const byteArray = Array.from(payload); + const namespaceId = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new NamespaceIdDto(namespaceId); + } + + /** + * Gets Namespace id. + * + * @return Namespace id. + */ + public getNamespaceId(): number[] { + return this.namespaceId; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const namespaceIdBytes = GeneratorUtils.uint64ToBuffer(this.getNamespaceId()); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceIdBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceMetadataTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/NamespaceMetadataTransactionBodyBuilder.ts new file mode 100644 index 0000000000..f460ab3c25 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceMetadataTransactionBodyBuilder.ts @@ -0,0 +1,168 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for a namespace metadata transaction. */ +export class NamespaceMetadataTransactionBodyBuilder { + /** Metadata target public key. */ + targetPublicKey: KeyDto; + /** Metadata key scoped to source, target and type. */ + scopedMetadataKey: number[]; + /** Target namespace identifier. */ + targetNamespaceId: NamespaceIdDto; + /** Change in value size in bytes. */ + valueSizeDelta: number; + /** Difference between existing value and new value \note when there is no existing value, new value is same this value \note when there is an existing value, new value is calculated as xor(previous-value, value). */ + value: Uint8Array; + + /** + * Constructor. + * + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetNamespaceId Target namespace identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(targetPublicKey: KeyDto, scopedMetadataKey: number[], targetNamespaceId: NamespaceIdDto, valueSizeDelta: number, value: Uint8Array) { + this.targetPublicKey = targetPublicKey; + this.scopedMetadataKey = scopedMetadataKey; + this.targetNamespaceId = targetNamespaceId; + this.valueSizeDelta = valueSizeDelta; + this.value = value; + } + + /** + * Creates an instance of NamespaceMetadataTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceMetadataTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceMetadataTransactionBodyBuilder { + const byteArray = Array.from(payload); + const targetPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetPublicKey.getSize()); + const scopedMetadataKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const targetNamespaceId = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetNamespaceId.getSize()); + const valueSizeDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const valueSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const value = GeneratorUtils.getBytes(Uint8Array.from(byteArray), valueSize); + byteArray.splice(0, valueSize); + // tslint:disable-next-line: max-line-length + return new NamespaceMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetNamespaceId, valueSizeDelta, value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.targetPublicKey; + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.scopedMetadataKey; + } + + /** + * Gets target namespace identifier. + * + * @return Target namespace identifier. + */ + public getTargetNamespaceId(): NamespaceIdDto { + return this.targetNamespaceId; + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.valueSizeDelta; + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.targetPublicKey.getSize(); + size += 8; // scopedMetadataKey + size += this.targetNamespaceId.getSize(); + size += 2; // valueSizeDelta + size += 2; // valueSize + size += this.value.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const targetPublicKeyBytes = this.targetPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetPublicKeyBytes); + const scopedMetadataKeyBytes = GeneratorUtils.uint64ToBuffer(this.getScopedMetadataKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, scopedMetadataKeyBytes); + const targetNamespaceIdBytes = this.targetNamespaceId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetNamespaceIdBytes); + const valueSizeDeltaBytes = GeneratorUtils.uintToBuffer(this.getValueSizeDelta(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeDeltaBytes); + const valueSizeBytes = GeneratorUtils.uintToBuffer(this.value.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.value); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/NamespaceMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..6b4b2e4885 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceMetadataTransactionBuilder.ts @@ -0,0 +1,151 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceMetadataTransactionBodyBuilder } from './NamespaceMetadataTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded namespace metadata transaction. */ +export class NamespaceMetadataTransactionBuilder extends TransactionBuilder { + /** Namespace metadata transaction body. */ + namespaceMetadataTransactionBody: NamespaceMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetNamespaceId Target namespace identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], targetNamespaceId: NamespaceIdDto, valueSizeDelta: number, value: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.namespaceMetadataTransactionBody = new NamespaceMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetNamespaceId, valueSizeDelta, value); + } + + /** + * Creates an instance of NamespaceMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const namespaceMetadataTransactionBody = NamespaceMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new NamespaceMetadataTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, namespaceMetadataTransactionBody.targetPublicKey, namespaceMetadataTransactionBody.scopedMetadataKey, namespaceMetadataTransactionBody.targetNamespaceId, namespaceMetadataTransactionBody.valueSizeDelta, namespaceMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.namespaceMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.namespaceMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets target namespace identifier. + * + * @return Target namespace identifier. + */ + public getTargetNamespaceId(): NamespaceIdDto { + return this.namespaceMetadataTransactionBody.getTargetNamespaceId(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.namespaceMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.namespaceMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.namespaceMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const namespaceMetadataTransactionBodyBytes = this.namespaceMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBodyBuilder.ts new file mode 100644 index 0000000000..465636812f --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBodyBuilder.ts @@ -0,0 +1,188 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceRegistrationTypeDto } from './NamespaceRegistrationTypeDto'; + +/** Binary layout for a namespace registration transaction. */ +export class NamespaceRegistrationTransactionBodyBuilder { + /** Namespace registration type. */ + registrationType: NamespaceRegistrationTypeDto; + /** Namespace duration. */ + duration?: BlockDurationDto; + /** Parent namespace identifier. */ + parentId?: NamespaceIdDto; + /** Namespace identifier. */ + id: NamespaceIdDto; + /** Namespace name. */ + name: Uint8Array; + + /** + * Constructor. + * + * @param duration Namespace duration. + * @param parentId Parent namespace identifier. + * @param id Namespace identifier. + * @param name Namespace name. + */ + public constructor(id: NamespaceIdDto, name: Uint8Array, duration?: BlockDurationDto, parentId?: NamespaceIdDto) { + if ((duration && parentId) || (!duration && !parentId)) { + throw new Error('Invalid conditional parameters'); + } + this.duration = duration; + this.parentId = parentId; + this.id = id; + this.name = name; + if (duration) { + this.registrationType = NamespaceRegistrationTypeDto.ROOT; + } + if (parentId) { + this.registrationType = NamespaceRegistrationTypeDto.CHILD; + } + } + + /** + * Creates an instance of NamespaceRegistrationTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceRegistrationTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceRegistrationTransactionBodyBuilder { + const byteArray = Array.from(payload); + const registrationType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + let duration; + if (registrationType === NamespaceRegistrationTypeDto.ROOT) { + duration = BlockDurationDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, duration.getSize()); + } + let parentId; + if (registrationType === NamespaceRegistrationTypeDto.CHILD) { + parentId = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, parentId.getSize()); + } + const id = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, id.getSize()); + const nameSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const name = GeneratorUtils.getBytes(Uint8Array.from(byteArray), nameSize); + byteArray.splice(0, nameSize); + return new NamespaceRegistrationTransactionBodyBuilder(id, name, duration, parentId); + } + + /** + * Gets namespace registration type. + * + * @return Namespace registration type. + */ + public getRegistrationType(): NamespaceRegistrationTypeDto { + return this.registrationType; + } + + /** + * Gets namespace duration. + * + * @return Namespace duration. + */ + public getDuration(): BlockDurationDto | undefined { + if (this.registrationType !== NamespaceRegistrationTypeDto.ROOT) { + throw new Error('registrationType is not set to ROOT.'); + } + return this.duration; + } + + /** + * Gets parent namespace identifier. + * + * @return Parent namespace identifier. + */ + public getParentId(): NamespaceIdDto | undefined { + if (this.registrationType !== NamespaceRegistrationTypeDto.CHILD) { + throw new Error('registrationType is not set to CHILD.'); + } + return this.parentId; + } + + /** + * Gets namespace identifier. + * + * @return Namespace identifier. + */ + public getId(): NamespaceIdDto { + return this.id; + } + + /** + * Gets namespace name. + * + * @return Namespace name. + */ + public getName(): Uint8Array { + return this.name; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // registrationType + if (this.registrationType === NamespaceRegistrationTypeDto.ROOT) { + size += this.duration!.getSize(); + } + if (this.registrationType === NamespaceRegistrationTypeDto.CHILD) { + size += this.parentId!.getSize(); + } + size += this.id.getSize(); + size += 1; // nameSize + size += this.name.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const registrationTypeBytes = GeneratorUtils.uintToBuffer(this.registrationType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, registrationTypeBytes); + if (this.registrationType === NamespaceRegistrationTypeDto.ROOT) { + const durationBytes = this.duration!.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, durationBytes); + } + if (this.registrationType === NamespaceRegistrationTypeDto.CHILD) { + const parentIdBytes = this.parentId!.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, parentIdBytes); + } + const idBytes = this.id.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, idBytes); + const nameSizeBytes = GeneratorUtils.uintToBuffer(this.name.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, nameSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.name); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder.ts b/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder.ts new file mode 100644 index 0000000000..a9e96db248 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder.ts @@ -0,0 +1,149 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { BlockDurationDto } from './BlockDurationDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceRegistrationTransactionBodyBuilder } from './NamespaceRegistrationTransactionBodyBuilder'; +import { NamespaceRegistrationTypeDto } from './NamespaceRegistrationTypeDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded namespace registration transaction. */ +export class NamespaceRegistrationTransactionBuilder extends TransactionBuilder { + /** Namespace registration transaction body. */ + namespaceRegistrationTransactionBody: NamespaceRegistrationTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param duration Namespace duration. + * @param parentId Parent namespace identifier. + * @param id Namespace identifier. + * @param name Namespace name. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, id: NamespaceIdDto, name: Uint8Array, duration?: BlockDurationDto, parentId?: NamespaceIdDto) { + super(signature, signer, version, type, fee, deadline); + if ((duration && parentId) || (!duration && !parentId)) { + throw new Error('Invalid conditional parameters'); + } + // tslint:disable-next-line: max-line-length + this.namespaceRegistrationTransactionBody = new NamespaceRegistrationTransactionBodyBuilder(id, name, duration, parentId); + } + + /** + * Creates an instance of NamespaceRegistrationTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceRegistrationTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceRegistrationTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const namespaceRegistrationTransactionBody = NamespaceRegistrationTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceRegistrationTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new NamespaceRegistrationTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, namespaceRegistrationTransactionBody.id, namespaceRegistrationTransactionBody.name, namespaceRegistrationTransactionBody.duration, namespaceRegistrationTransactionBody.parentId); + } + + /** + * Gets namespace registration type. + * + * @return Namespace registration type. + */ + public getRegistrationType(): NamespaceRegistrationTypeDto { + return this.namespaceRegistrationTransactionBody.getRegistrationType(); + } + + /** + * Gets namespace duration. + * + * @return Namespace duration. + */ + public getDuration(): BlockDurationDto | undefined { + return this.namespaceRegistrationTransactionBody.getDuration(); + } + + /** + * Gets parent namespace identifier. + * + * @return Parent namespace identifier. + */ + public getParentId(): NamespaceIdDto | undefined { + return this.namespaceRegistrationTransactionBody.getParentId(); + } + + /** + * Gets namespace identifier. + * + * @return Namespace identifier. + */ + public getId(): NamespaceIdDto { + return this.namespaceRegistrationTransactionBody.getId(); + } + + /** + * Gets namespace name. + * + * @return Namespace name. + */ + public getName(): Uint8Array { + return this.namespaceRegistrationTransactionBody.getName(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.namespaceRegistrationTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const namespaceRegistrationTransactionBodyBytes = this.namespaceRegistrationTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceRegistrationTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceRegistrationTypeDto.ts b/src/infrastructure/catbuffer/NamespaceRegistrationTypeDto.ts new file mode 100644 index 0000000000..349db68025 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceRegistrationTypeDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of namespace registration types. */ +export enum NamespaceRegistrationTypeDto { + /** Root namespace. */ + ROOT = 0, + /** Child namespace. */ + CHILD = 1, +} diff --git a/src/infrastructure/catbuffer/SecretLockTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/SecretLockTransactionBodyBuilder.ts new file mode 100644 index 0000000000..a38da76d77 --- /dev/null +++ b/src/infrastructure/catbuffer/SecretLockTransactionBodyBuilder.ts @@ -0,0 +1,160 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a secret lock transaction. */ +export class SecretLockTransactionBodyBuilder { + /** Locked mosaic. */ + mosaic: UnresolvedMosaicBuilder; + /** Number of blocks for which a lock should be valid. */ + duration: BlockDurationDto; + /** Hash algorithm. */ + hashAlgorithm: LockHashAlgorithmDto; + /** Secret. */ + secret: Hash256Dto; + /** Locked mosaic recipient. */ + recipient: UnresolvedAddressDto; + + /** + * Constructor. + * + * @param mosaic Locked mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Locked mosaic recipient. + */ + // tslint:disable-next-line: max-line-length + public constructor(mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto) { + this.mosaic = mosaic; + this.duration = duration; + this.hashAlgorithm = hashAlgorithm; + this.secret = secret; + this.recipient = recipient; + } + + /** + * Creates an instance of SecretLockTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SecretLockTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): SecretLockTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaic = UnresolvedMosaicBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaic.getSize()); + const duration = BlockDurationDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, duration.getSize()); + const hashAlgorithm = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const secret = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secret.getSize()); + const recipient = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, recipient.getSize()); + return new SecretLockTransactionBodyBuilder(mosaic, duration, hashAlgorithm, secret, recipient); + } + + /** + * Gets locked mosaic. + * + * @return Locked mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.mosaic; + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.duration; + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.hashAlgorithm; + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secret; + } + + /** + * Gets locked mosaic recipient. + * + * @return Locked mosaic recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.recipient; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaic.getSize(); + size += this.duration.getSize(); + size += 1; // hashAlgorithm + size += this.secret.getSize(); + size += this.recipient.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicBytes = this.mosaic.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicBytes); + const durationBytes = this.duration.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, durationBytes); + const hashAlgorithmBytes = GeneratorUtils.uintToBuffer(this.hashAlgorithm, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashAlgorithmBytes); + const secretBytes = this.secret.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretBytes); + const recipientBytes = this.recipient.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, recipientBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/SecretLockTransactionBuilder.ts b/src/infrastructure/catbuffer/SecretLockTransactionBuilder.ts new file mode 100644 index 0000000000..3f99ae1dd0 --- /dev/null +++ b/src/infrastructure/catbuffer/SecretLockTransactionBuilder.ts @@ -0,0 +1,148 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { BlockDurationDto } from './BlockDurationDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { KeyDto } from './KeyDto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { SecretLockTransactionBodyBuilder } from './SecretLockTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a non-embedded secret lock transaction. */ +export class SecretLockTransactionBuilder extends TransactionBuilder { + /** Secret lock transaction body. */ + secretLockTransactionBody: SecretLockTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaic Locked mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Locked mosaic recipient. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.secretLockTransactionBody = new SecretLockTransactionBodyBuilder(mosaic, duration, hashAlgorithm, secret, recipient); + } + + /** + * Creates an instance of SecretLockTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SecretLockTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): SecretLockTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const secretLockTransactionBody = SecretLockTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secretLockTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new SecretLockTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, secretLockTransactionBody.mosaic, secretLockTransactionBody.duration, secretLockTransactionBody.hashAlgorithm, secretLockTransactionBody.secret, secretLockTransactionBody.recipient); + } + + /** + * Gets locked mosaic. + * + * @return Locked mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.secretLockTransactionBody.getMosaic(); + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.secretLockTransactionBody.getDuration(); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.secretLockTransactionBody.getHashAlgorithm(); + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secretLockTransactionBody.getSecret(); + } + + /** + * Gets locked mosaic recipient. + * + * @return Locked mosaic recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.secretLockTransactionBody.getRecipient(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.secretLockTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const secretLockTransactionBodyBytes = this.secretLockTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretLockTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/SecretProofTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/SecretProofTransactionBodyBuilder.ts new file mode 100644 index 0000000000..ba7a2a1fa2 --- /dev/null +++ b/src/infrastructure/catbuffer/SecretProofTransactionBodyBuilder.ts @@ -0,0 +1,144 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; + +/** Binary layout for a secret proof transaction. */ +export class SecretProofTransactionBodyBuilder { + /** Hash algorithm. */ + hashAlgorithm: LockHashAlgorithmDto; + /** Secret. */ + secret: Hash256Dto; + /** Recipient. */ + recipient: UnresolvedAddressDto; + /** Proof data. */ + proof: Uint8Array; + + /** + * Constructor. + * + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Recipient. + * @param proof Proof data. + */ + // tslint:disable-next-line: max-line-length + public constructor(hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto, proof: Uint8Array) { + this.hashAlgorithm = hashAlgorithm; + this.secret = secret; + this.recipient = recipient; + this.proof = proof; + } + + /** + * Creates an instance of SecretProofTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SecretProofTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): SecretProofTransactionBodyBuilder { + const byteArray = Array.from(payload); + const hashAlgorithm = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const secret = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secret.getSize()); + const recipient = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, recipient.getSize()); + const proofSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const proof = GeneratorUtils.getBytes(Uint8Array.from(byteArray), proofSize); + byteArray.splice(0, proofSize); + return new SecretProofTransactionBodyBuilder(hashAlgorithm, secret, recipient, proof); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.hashAlgorithm; + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secret; + } + + /** + * Gets recipient. + * + * @return Recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.recipient; + } + + /** + * Gets proof data. + * + * @return Proof data. + */ + public getProof(): Uint8Array { + return this.proof; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // hashAlgorithm + size += this.secret.getSize(); + size += this.recipient.getSize(); + size += 2; // proofSize + size += this.proof.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const hashAlgorithmBytes = GeneratorUtils.uintToBuffer(this.hashAlgorithm, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashAlgorithmBytes); + const secretBytes = this.secret.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretBytes); + const recipientBytes = this.recipient.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, recipientBytes); + const proofSizeBytes = GeneratorUtils.uintToBuffer(this.proof.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, proofSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.proof); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/SecretProofTransactionBuilder.ts b/src/infrastructure/catbuffer/SecretProofTransactionBuilder.ts new file mode 100644 index 0000000000..445a74e418 --- /dev/null +++ b/src/infrastructure/catbuffer/SecretProofTransactionBuilder.ts @@ -0,0 +1,135 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { KeyDto } from './KeyDto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { SecretProofTransactionBodyBuilder } from './SecretProofTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; + +/** Binary layout for a non-embedded secret proof transaction. */ +export class SecretProofTransactionBuilder extends TransactionBuilder { + /** Secret proof transaction body. */ + secretProofTransactionBody: SecretProofTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Recipient. + * @param proof Proof data. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto, proof: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + this.secretProofTransactionBody = new SecretProofTransactionBodyBuilder(hashAlgorithm, secret, recipient, proof); + } + + /** + * Creates an instance of SecretProofTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SecretProofTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): SecretProofTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const secretProofTransactionBody = SecretProofTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secretProofTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new SecretProofTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, secretProofTransactionBody.hashAlgorithm, secretProofTransactionBody.secret, secretProofTransactionBody.recipient, secretProofTransactionBody.proof); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.secretProofTransactionBody.getHashAlgorithm(); + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secretProofTransactionBody.getSecret(); + } + + /** + * Gets recipient. + * + * @return Recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.secretProofTransactionBody.getRecipient(); + } + + /** + * Gets proof data. + * + * @return Proof data. + */ + public getProof(): Uint8Array { + return this.secretProofTransactionBody.getProof(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.secretProofTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const secretProofTransactionBodyBytes = this.secretProofTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretProofTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/SignatureDto.ts b/src/infrastructure/catbuffer/SignatureDto.ts new file mode 100644 index 0000000000..307efb2b50 --- /dev/null +++ b/src/infrastructure/catbuffer/SignatureDto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Signature. */ +export class SignatureDto { + /** Signature. */ + signature: Uint8Array; + + /** + * Constructor. + * + * @param signature Signature. + */ + constructor(signature: Uint8Array) { + this.signature = signature; + } + + /** + * Creates an instance of SignatureDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SignatureDto. + */ + public static loadFromBinary(payload: Uint8Array): SignatureDto { + const byteArray = Array.from(payload); + const signature = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 64); + byteArray.splice(0, 64); + return new SignatureDto(signature); + } + + /** + * Gets Signature. + * + * @return Signature. + */ + public getSignature(): Uint8Array { + return this.signature; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 64; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.signature); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/TimestampDto.ts b/src/infrastructure/catbuffer/TimestampDto.ts new file mode 100644 index 0000000000..af3de24b9e --- /dev/null +++ b/src/infrastructure/catbuffer/TimestampDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Timestamp. */ +export class TimestampDto { + /** Timestamp. */ + timestamp: number[]; + + /** + * Constructor. + * + * @param timestamp Timestamp. + */ + constructor(timestamp: number[]) { + this.timestamp = timestamp; + } + + /** + * Creates an instance of TimestampDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of TimestampDto. + */ + public static loadFromBinary(payload: Uint8Array): TimestampDto { + const byteArray = Array.from(payload); + const timestamp = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new TimestampDto(timestamp); + } + + /** + * Gets Timestamp. + * + * @return Timestamp. + */ + public getTimestamp(): number[] { + return this.timestamp; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const timestampBytes = GeneratorUtils.uint64ToBuffer(this.getTimestamp()); + newArray = GeneratorUtils.concatTypedArrays(newArray, timestampBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/TransactionBuilder.ts b/src/infrastructure/catbuffer/TransactionBuilder.ts new file mode 100644 index 0000000000..e50a3024be --- /dev/null +++ b/src/infrastructure/catbuffer/TransactionBuilder.ts @@ -0,0 +1,185 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; + +/** Binary layout for a transaction. */ +export class TransactionBuilder { + /** Entity size. */ + size = 0; + /** Entity signature. */ + signature: SignatureDto; + /** Entity signer's public key. */ + signer: KeyDto; + /** Entity version. */ + version: number; + /** Entity type. */ + type: EntityTypeDto; + /** Transaction fee. */ + fee: AmountDto; + /** Transaction deadline. */ + deadline: TimestampDto; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto) { + this.signature = signature; + this.signer = signer; + this.version = version; + this.type = type; + this.fee = fee; + this.deadline = deadline; + } + + /** + * Creates an instance of TransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of TransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): TransactionBuilder { + const byteArray = Array.from(payload); + const size = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + const signature = SignatureDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signature.getSize()); + const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signer.getSize()); + const version = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const type = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const fee = AmountDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, fee.getSize()); + const deadline = TimestampDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, deadline.getSize()); + return new TransactionBuilder(signature, signer, version, type, fee, deadline); + } + + /** + * Gets entity signature. + * + * @return Entity signature. + */ + public getSignature(): SignatureDto { + return this.signature; + } + + /** + * Gets entity signer's public key. + * + * @return Entity signer's public key. + */ + public getSigner(): KeyDto { + return this.signer; + } + + /** + * Gets entity version. + * + * @return Entity version. + */ + public getVersion(): number { + return this.version; + } + + /** + * Gets entity type. + * + * @return Entity type. + */ + public getType(): EntityTypeDto { + return this.type; + } + + /** + * Gets transaction fee.. + * + * @return Transaction fee. + */ + public getFee(): AmountDto { + return this.fee; + } + + /** + * Gets transaction deadline. + * + * @return Transaction deadline. + */ + public getDeadline(): TimestampDto { + return this.deadline; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 4; // size + size += this.signature.getSize(); + size += this.signer.getSize(); + size += 2; // version + size += 2; // type + size += this.fee.getSize(); + size += this.deadline.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const sizeBytes = GeneratorUtils.uintToBuffer(this.getSize(), 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, sizeBytes); + const signatureBytes = this.signature.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signatureBytes); + const signerBytes = this.signer.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); + const versionBytes = GeneratorUtils.uintToBuffer(this.getVersion(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, versionBytes); + const typeBytes = GeneratorUtils.uintToBuffer(this.type, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, typeBytes); + const feeBytes = this.fee.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, feeBytes); + const deadlineBytes = this.deadline.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, deadlineBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/TransferTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/TransferTransactionBodyBuilder.ts new file mode 100644 index 0000000000..e0ee7daed1 --- /dev/null +++ b/src/infrastructure/catbuffer/TransferTransactionBodyBuilder.ts @@ -0,0 +1,135 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a transfer transaction. */ +export class TransferTransactionBodyBuilder { + /** Transaction recipient. */ + recipient: UnresolvedAddressDto; + /** Transaction message. */ + message: Uint8Array; + /** Attached mosaics. */ + mosaics: UnresolvedMosaicBuilder[]; + + /** + * Constructor. + * + * @param recipient Transaction recipient. + * @param message Transaction message. + * @param mosaics Attached mosaics. + */ + public constructor(recipient: UnresolvedAddressDto, message: Uint8Array, mosaics: UnresolvedMosaicBuilder[]) { + this.recipient = recipient; + this.message = message; + this.mosaics = mosaics; + } + + /** + * Creates an instance of TransferTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of TransferTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): TransferTransactionBodyBuilder { + const byteArray = Array.from(payload); + const recipient = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, recipient.getSize()); + const messageSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const mosaicsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const message = GeneratorUtils.getBytes(Uint8Array.from(byteArray), messageSize); + byteArray.splice(0, messageSize); + const mosaics: UnresolvedMosaicBuilder[] = []; + for (let i = 0; i < mosaicsCount; i++) { + const item = UnresolvedMosaicBuilder.loadFromBinary(Uint8Array.from(byteArray)); + mosaics.push(item); + byteArray.splice(0, item.getSize()); + } + return new TransferTransactionBodyBuilder(recipient, message, mosaics); + } + + /** + * Gets transaction recipient. + * + * @return Transaction recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.recipient; + } + + /** + * Gets transaction message. + * + * @return Transaction message. + */ + public getMessage(): Uint8Array { + return this.message; + } + + /** + * Gets attached mosaics. + * + * @return Attached mosaics. + */ + public getMosaics(): UnresolvedMosaicBuilder[] { + return this.mosaics; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.recipient.getSize(); + size += 2; // messageSize + size += 1; // mosaicsCount + size += this.message.length; + this.mosaics.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const recipientBytes = this.recipient.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, recipientBytes); + const messageSizeBytes = GeneratorUtils.uintToBuffer(this.message.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, messageSizeBytes); + const mosaicsCountBytes = GeneratorUtils.uintToBuffer(this.mosaics.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicsCountBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.message); + this.mosaics.forEach((item) => { + const mosaicsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/TransferTransactionBuilder.ts b/src/infrastructure/catbuffer/TransferTransactionBuilder.ts new file mode 100644 index 0000000000..722d79409a --- /dev/null +++ b/src/infrastructure/catbuffer/TransferTransactionBuilder.ts @@ -0,0 +1,124 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { TransferTransactionBodyBuilder } from './TransferTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a non-embedded transfer transaction. */ +export class TransferTransactionBuilder extends TransactionBuilder { + /** Transfer transaction body. */ + transferTransactionBody: TransferTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param recipient Transaction recipient. + * @param message Transaction message. + * @param mosaics Attached mosaics. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, recipient: UnresolvedAddressDto, message: Uint8Array, mosaics: UnresolvedMosaicBuilder[]) { + super(signature, signer, version, type, fee, deadline); + this.transferTransactionBody = new TransferTransactionBodyBuilder(recipient, message, mosaics); + } + + /** + * Creates an instance of TransferTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of TransferTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): TransferTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const transferTransactionBody = TransferTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, transferTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new TransferTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, transferTransactionBody.recipient, transferTransactionBody.message, transferTransactionBody.mosaics); + } + + /** + * Gets transaction recipient. + * + * @return Transaction recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.transferTransactionBody.getRecipient(); + } + + /** + * Gets transaction message. + * + * @return Transaction message. + */ + public getMessage(): Uint8Array { + return this.transferTransactionBody.getMessage(); + } + + /** + * Gets attached mosaics. + * + * @return Attached mosaics. + */ + public getMosaics(): UnresolvedMosaicBuilder[] { + return this.transferTransactionBody.getMosaics(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.transferTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const transferTransactionBodyBytes = this.transferTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, transferTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/UnresolvedAddressDto.ts b/src/infrastructure/catbuffer/UnresolvedAddressDto.ts new file mode 100644 index 0000000000..2a0748d76d --- /dev/null +++ b/src/infrastructure/catbuffer/UnresolvedAddressDto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Unresolved address. */ +export class UnresolvedAddressDto { + /** Unresolved address. */ + unresolvedAddress: Uint8Array; + + /** + * Constructor. + * + * @param unresolvedAddress Unresolved address. + */ + constructor(unresolvedAddress: Uint8Array) { + this.unresolvedAddress = unresolvedAddress; + } + + /** + * Creates an instance of UnresolvedAddressDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of UnresolvedAddressDto. + */ + public static loadFromBinary(payload: Uint8Array): UnresolvedAddressDto { + const byteArray = Array.from(payload); + const unresolvedAddress = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 25); + byteArray.splice(0, 25); + return new UnresolvedAddressDto(unresolvedAddress); + } + + /** + * Gets Unresolved address. + * + * @return Unresolved address. + */ + public getUnresolvedAddress(): Uint8Array { + return this.unresolvedAddress; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 25; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.unresolvedAddress); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/UnresolvedMosaicBuilder.ts b/src/infrastructure/catbuffer/UnresolvedMosaicBuilder.ts new file mode 100644 index 0000000000..5091228ad9 --- /dev/null +++ b/src/infrastructure/catbuffer/UnresolvedMosaicBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an unresolved mosaic. */ +export class UnresolvedMosaicBuilder { + /** Mosaic identifier. */ + mosaicId: UnresolvedMosaicIdDto; + /** Mosaic amount. */ + amount: AmountDto; + + /** + * Constructor. + * + * @param mosaicId Mosaic identifier. + * @param amount Mosaic amount. + */ + public constructor(mosaicId: UnresolvedMosaicIdDto, amount: AmountDto) { + this.mosaicId = mosaicId; + this.amount = amount; + } + + /** + * Creates an instance of UnresolvedMosaicBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of UnresolvedMosaicBuilder. + */ + public static loadFromBinary(payload: Uint8Array): UnresolvedMosaicBuilder { + const byteArray = Array.from(payload); + const mosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const amount = AmountDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, amount.getSize()); + return new UnresolvedMosaicBuilder(mosaicId, amount); + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicId; + } + + /** + * Gets mosaic amount. + * + * @return Mosaic amount. + */ + public getAmount(): AmountDto { + return this.amount; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += this.amount.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const amountBytes = this.amount.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, amountBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/UnresolvedMosaicIdDto.ts b/src/infrastructure/catbuffer/UnresolvedMosaicIdDto.ts new file mode 100644 index 0000000000..8b49a58aea --- /dev/null +++ b/src/infrastructure/catbuffer/UnresolvedMosaicIdDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Unresolved mosaic id. */ +export class UnresolvedMosaicIdDto { + /** Unresolved mosaic id. */ + unresolvedMosaicId: number[]; + + /** + * Constructor. + * + * @param unresolvedMosaicId Unresolved mosaic id. + */ + constructor(unresolvedMosaicId: number[]) { + this.unresolvedMosaicId = unresolvedMosaicId; + } + + /** + * Creates an instance of UnresolvedMosaicIdDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of UnresolvedMosaicIdDto. + */ + public static loadFromBinary(payload: Uint8Array): UnresolvedMosaicIdDto { + const byteArray = Array.from(payload); + const unresolvedMosaicId = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new UnresolvedMosaicIdDto(unresolvedMosaicId); + } + + /** + * Gets Unresolved mosaic id. + * + * @return Unresolved mosaic id. + */ + public getUnresolvedMosaicId(): number[] { + return this.unresolvedMosaicId; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const unresolvedMosaicIdBytes = GeneratorUtils.uint64ToBuffer(this.getUnresolvedMosaicId()); + newArray = GeneratorUtils.concatTypedArrays(newArray, unresolvedMosaicIdBytes); + return newArray; + } +} diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index 2205ed1d37..e6a1e3d7ae 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -24,10 +24,10 @@ import {MosaicId} from '../../model/mosaic/MosaicId'; import {MosaicProperties} from '../../model/mosaic/MosaicProperties'; import { MosaicPropertyType } from '../../model/mosaic/MosaicPropertyType'; import {NamespaceId} from '../../model/namespace/NamespaceId'; -import {AccountAddressRestrictionModificationTransaction} from '../../model/transaction/AccountAddressRestrictionModificationTransaction'; +import {AccountAddressRestrictionTransaction} from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; -import {AccountMosaicRestrictionModificationTransaction} from '../../model/transaction/AccountMosaicRestrictionModificationTransaction'; -import {AccountOperationRestrictionModificationTransaction} from '../../model/transaction/AccountOperationRestrictionModificationTransaction'; +import {AccountMosaicRestrictionTransaction} from '../../model/transaction/AccountMosaicRestrictionTransaction'; +import {AccountOperationRestrictionTransaction} from '../../model/transaction/AccountOperationRestrictionTransaction'; import {AccountRestrictionModification} from '../../model/transaction/AccountRestrictionModification'; import {AddressAliasTransaction} from '../../model/transaction/AddressAliasTransaction'; import {AggregateTransaction} from '../../model/transaction/AggregateTransaction'; @@ -280,8 +280,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr extractNetworkType(transactionDTO.version)) : undefined, transactionInfo, ); - } else if (transactionDTO.type === TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS) { - return new AccountAddressRestrictionModificationTransaction( + } else if (transactionDTO.type === TransactionType.ACCOUNT_RESTRICTION_ADDRESS) { + return new AccountAddressRestrictionTransaction( extractNetworkType(transactionDTO.version), extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), @@ -296,8 +296,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr extractNetworkType(transactionDTO.version)) : undefined, transactionInfo, ); - } else if (transactionDTO.type === TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION) { - return new AccountOperationRestrictionModificationTransaction( + } else if (transactionDTO.type === TransactionType.ACCOUNT_RESTRICTION_OPERATION) { + return new AccountOperationRestrictionTransaction( extractNetworkType(transactionDTO.version), extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), @@ -312,8 +312,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr extractNetworkType(transactionDTO.version)) : undefined, transactionInfo, ); - } else if (transactionDTO.type === TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC) { - return new AccountMosaicRestrictionModificationTransaction( + } else if (transactionDTO.type === TransactionType.ACCOUNT_RESTRICTION_MOSAIC) { + return new AccountMosaicRestrictionTransaction( extractNetworkType(transactionDTO.version), extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index afe17f162a..b1198243fd 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -25,10 +25,10 @@ import { MosaicNonce } from '../../model/mosaic/MosaicNonce'; import { MosaicProperties } from '../../model/mosaic/MosaicProperties'; import { NamespaceId } from '../../model/namespace/NamespaceId'; import { NamespaceType } from '../../model/namespace/NamespaceType'; -import { AccountAddressRestrictionModificationTransaction } from '../../model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from '../../model/transaction/AccountMosaicRestrictionModificationTransaction'; -import { AccountOperationRestrictionModificationTransaction } from '../../model/transaction/AccountOperationRestrictionModificationTransaction'; +import { AccountMosaicRestrictionTransaction } from '../../model/transaction/AccountMosaicRestrictionTransaction'; +import { AccountOperationRestrictionTransaction } from '../../model/transaction/AccountOperationRestrictionTransaction'; import { AccountRestrictionModification } from '../../model/transaction/AccountRestrictionModification'; import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction'; import { AggregateTransaction } from '../../model/transaction/AggregateTransaction'; @@ -100,9 +100,9 @@ export const CreateTransactionFromPayload = (transactionBinary: string): Transac */ const CreateTransaction = (type: number, transactionData: string, networkType: NetworkType, deadline: number[]): Transaction => { switch (type) { - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS: - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION: - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC: + case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: + case TransactionType.ACCOUNT_RESTRICTION_OPERATION: + case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: const propertyTypeLength = 2; const modificationCountOffset = propertyTypeLength; @@ -114,8 +114,8 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N const modificationArray = modifications.match(/.{1,52}/g); switch (type) { - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS: - const t = AccountAddressRestrictionModificationTransaction.create( + case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: + const t = AccountAddressRestrictionTransaction.create( Deadline.createFromDTO(deadline), parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( @@ -125,8 +125,8 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N networkType, ); return t; - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC: - return AccountMosaicRestrictionModificationTransaction.create( + case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: + return AccountMosaicRestrictionTransaction.create( Deadline.createFromDTO(deadline), parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( @@ -135,8 +135,8 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N )) : [], networkType, ); - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION: - return AccountOperationRestrictionModificationTransaction.create( + case TransactionType.ACCOUNT_RESTRICTION_OPERATION: + return AccountOperationRestrictionTransaction.create( Deadline.createFromDTO(deadline), parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index 4802bbd278..4ba47f1e4c 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -14,10 +14,10 @@ * limitations under the License. */ -import { AccountAddressRestrictionModificationTransaction } from '../../model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from '../../model/transaction/AccountMosaicRestrictionModificationTransaction'; -import { AccountOperationRestrictionModificationTransaction } from '../../model/transaction/AccountOperationRestrictionModificationTransaction'; +import { AccountMosaicRestrictionTransaction } from '../../model/transaction/AccountMosaicRestrictionTransaction'; +import { AccountOperationRestrictionTransaction } from '../../model/transaction/AccountOperationRestrictionTransaction'; import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction'; import { AggregateTransaction } from '../../model/transaction/AggregateTransaction'; import { LockFundsTransaction } from '../../model/transaction/LockFundsTransaction'; @@ -70,26 +70,26 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { duration: (transaction as LockFundsTransaction).duration.toDTO(), hash: (transaction as LockFundsTransaction).hash, }; - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS: + case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: return { - restrictionType: (transaction as AccountAddressRestrictionModificationTransaction).restrictionType, - modifications: (transaction as AccountAddressRestrictionModificationTransaction). + restrictionType: (transaction as AccountAddressRestrictionTransaction).restrictionType, + modifications: (transaction as AccountAddressRestrictionTransaction). modifications.map((modification) => { return modification.toDTO(); }), }; - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION: + case TransactionType.ACCOUNT_RESTRICTION_OPERATION: return { - restrictionType: (transaction as AccountOperationRestrictionModificationTransaction).restrictionType, - modifications: (transaction as AccountOperationRestrictionModificationTransaction). + restrictionType: (transaction as AccountOperationRestrictionTransaction).restrictionType, + modifications: (transaction as AccountOperationRestrictionTransaction). modifications.map((modification) => { return modification.toDTO(); }), }; - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC: + case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: return { - restrictionType: (transaction as AccountMosaicRestrictionModificationTransaction).restrictionType, - modifications: (transaction as AccountMosaicRestrictionModificationTransaction).modifications.map((modification) => { + restrictionType: (transaction as AccountMosaicRestrictionTransaction).restrictionType, + modifications: (transaction as AccountMosaicRestrictionTransaction).modifications.map((modification) => { return modification.toDTO(); }), }; diff --git a/src/model/model.ts b/src/model/model.ts index ec948eca39..06d3767f14 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -92,9 +92,9 @@ export * from './receipt/Statement'; // Transaction export * from './transaction/AccountLinkTransaction'; export * from './transaction/AccountRestrictionTransaction'; -export * from './transaction/AccountAddressRestrictionModificationTransaction'; -export * from './transaction/AccountOperationRestrictionModificationTransaction'; -export * from './transaction/AccountMosaicRestrictionModificationTransaction'; +export * from './transaction/AccountAddressRestrictionTransaction'; +export * from './transaction/AccountMosaicRestrictionTransaction'; +export * from './transaction/AccountMosaicRestrictionTransaction'; export * from './transaction/AccountRestrictionModification'; export * from './transaction/AddressAliasTransaction'; export * from './transaction/AggregateTransaction'; diff --git a/src/model/mosaic/MosaicFlag.ts b/src/model/mosaic/MosaicFlag.ts new file mode 100644 index 0000000000..dcf6a8b500 --- /dev/null +++ b/src/model/mosaic/MosaicFlag.ts @@ -0,0 +1,25 @@ +/* + * Copyright 2018 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. + */ +export enum MosaicFlags { + /** No flags present. */ + NONE = 0, + /** Mosaic supports supply changes even when mosaic owner owns partial supply. */ + SUPPLY_MUTABLE = 1, + /** Mosaic supports transfers between arbitrary accounts \note when not set, mosaic can only be transferred to and from mosaic owner. */ + TRANSFERABLE = 2, + /** Mosaic supports custom restrictions configured by mosaic owner. */ + RESTRICTABLE = 4, +} diff --git a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts similarity index 64% rename from src/model/transaction/AccountAddressRestrictionModificationTransaction.ts rename to src/model/transaction/AccountAddressRestrictionTransaction.ts index 3a9d99f813..243b4ff560 100644 --- a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -14,8 +14,17 @@ * limitations under the License. */ +import { RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; +import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; @@ -27,7 +36,7 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -export class AccountAddressRestrictionModificationTransaction extends Transaction { +export class AccountAddressRestrictionTransaction extends Transaction { /** * Create a modify account address restriction transaction object @@ -36,15 +45,15 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio * @param modifications - The array of modifications. * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountAddressRestrictionModificationTransaction} + * @returns {AccountAddressRestrictionTransaction} */ public static create(deadline: Deadline, restrictionType: RestrictionType, modifications: Array>, networkType: NetworkType, - maxFee: UInt64 = new UInt64([0, 0])): AccountAddressRestrictionModificationTransaction { - return new AccountAddressRestrictionModificationTransaction(networkType, - TransactionVersion.MODIFY_ACCOUNT_RESTRICTION_ADDRESS, + maxFee: UInt64 = new UInt64([0, 0])): AccountAddressRestrictionTransaction { + return new AccountAddressRestrictionTransaction(networkType, + TransactionVersion.ACCOUNT_RESTRICTION_ADDRESS, deadline, maxFee, restrictionType, @@ -71,15 +80,15 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio signature?: string, signer?: PublicAccount, transactionInfo?: TransactionInfo) { - super(TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS, + super(TransactionType.ACCOUNT_RESTRICTION_ADDRESS, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } /** * @override Transaction.size() - * @description get the byte size of a AccountAddressRestrictionModificationTransaction + * @description get the byte size of a AccountAddressRestrictionTransaction * @returns {number} - * @memberof AccountAddressRestrictionModificationTransaction + * @memberof AccountAddressRestrictionTransaction */ public get size(): number { const byteSize = super.size; @@ -110,4 +119,29 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountAddressRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountAddressRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedAddressDto(RawAddress.stringToAddress(modification.value)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index 78915b03a3..41e00509b0 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -14,8 +14,15 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountLinkTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/AccountLinkTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; @@ -111,4 +118,24 @@ export class AccountLinkTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountLinkTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.LINK_ACCOUNT.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new KeyDto(Convert.hexToUint8(this.remoteAccountKey)), + this.linkAction.valueOf(), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts similarity index 65% rename from src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts rename to src/model/transaction/AccountMosaicRestrictionTransaction.ts index 3a32656795..cfac1c3ea1 100644 --- a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -16,6 +16,14 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; +import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; @@ -27,7 +35,7 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -export class AccountMosaicRestrictionModificationTransaction extends Transaction { +export class AccountMosaicRestrictionTransaction extends Transaction { /** * Create a modify account mosaic restriction transaction object @@ -36,15 +44,15 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction * @param modifications - The array of modifications. * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountAddressRestrictionModificationTransaction} + * @returns {AccountAddressRestrictionTransaction} */ public static create(deadline: Deadline, restrictionType: RestrictionType, modifications: Array>, networkType: NetworkType, - maxFee: UInt64 = new UInt64([0, 0])): AccountMosaicRestrictionModificationTransaction { - return new AccountMosaicRestrictionModificationTransaction(networkType, - TransactionVersion.MODIFY_ACCOUNT_RESTRICTION_MOSAIC, + maxFee: UInt64 = new UInt64([0, 0])): AccountMosaicRestrictionTransaction { + return new AccountMosaicRestrictionTransaction(networkType, + TransactionVersion.ACCOUNT_RESTRICTION_MOSAIC, deadline, maxFee, restrictionType, @@ -71,15 +79,15 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction signature?: string, signer?: PublicAccount, transactionInfo?: TransactionInfo) { - super(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC, + super(TransactionType.ACCOUNT_RESTRICTION_MOSAIC, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } /** * @override Transaction.size() - * @description get the byte size of a AccountMosaicRestrictionModificationTransaction + * @description get the byte size of a AccountMosaicRestrictionTransaction * @returns {number} - * @memberof AccountMosaicRestrictionModificationTransaction + * @memberof AccountMosaicRestrictionTransaction */ public get size(): number { const byteSize = super.size; @@ -110,4 +118,29 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountMosaicRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_MOSAIC.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountMosaicRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedMosaicIdDto(modification.value), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts similarity index 67% rename from src/model/transaction/AccountOperationRestrictionModificationTransaction.ts rename to src/model/transaction/AccountOperationRestrictionTransaction.ts index 38160cc79d..4ed72af488 100644 --- a/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -26,8 +26,15 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; -export class AccountOperationRestrictionModificationTransaction extends Transaction { +export class AccountOperationRestrictionTransaction extends Transaction { /** * Create a modify account operation restriction type transaction object @@ -36,14 +43,14 @@ export class AccountOperationRestrictionModificationTransaction extends Transact * @param modifications - The array of modifications. * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountOperationRestrictionModificationTransaction} + * @returns {AccountOperationRestrictionTransaction} */ public static create(deadline: Deadline, restrictionType: RestrictionType, modifications: Array>, networkType: NetworkType, - maxFee: UInt64 = new UInt64([0, 0])): AccountOperationRestrictionModificationTransaction { - return new AccountOperationRestrictionModificationTransaction(networkType, + maxFee: UInt64 = new UInt64([0, 0])): AccountOperationRestrictionTransaction { + return new AccountOperationRestrictionTransaction(networkType, TransactionVersion.MODIFY_ACCOUNT_RESTRICTION_ENTITY_TYPE, deadline, maxFee, @@ -71,15 +78,15 @@ export class AccountOperationRestrictionModificationTransaction extends Transact signature?: string, signer?: PublicAccount, transactionInfo?: TransactionInfo) { - super(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION, + super(TransactionType.ACCOUNT_RESTRICTION_OPERATION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } /** * @override Transaction.size() - * @description get the byte size of a AccountOperationRestrictionModificationTransaction + * @description get the byte size of a AccountOperationRestrictionTransaction * @returns {number} - * @memberof AccountOperationRestrictionModificationTransaction + * @memberof AccountOperationRestrictionTransaction */ public get size(): number { const byteSize = super.size; @@ -110,4 +117,29 @@ export class AccountOperationRestrictionModificationTransaction extends Transact .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountOperationRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_OPERATION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountOperationRestrictionModificationBuilder( + modification.modificationType.valueOf(), + modification.value.valueOf(), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountRestrictionTransaction.ts b/src/model/transaction/AccountRestrictionTransaction.ts index 7e0f26c313..e1a718141e 100644 --- a/src/model/transaction/AccountRestrictionTransaction.ts +++ b/src/model/transaction/AccountRestrictionTransaction.ts @@ -17,9 +17,9 @@ import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; -import { AccountAddressRestrictionModificationTransaction } from './AccountAddressRestrictionModificationTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from './AccountMosaicRestrictionModificationTransaction'; -import { AccountOperationRestrictionModificationTransaction } from './AccountOperationRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from './AccountAddressRestrictionTransaction'; +import { AccountMosaicRestrictionTransaction } from './AccountMosaicRestrictionTransaction'; +import { AccountOperationRestrictionTransaction } from './AccountOperationRestrictionTransaction'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; import { TransactionType } from './TransactionType'; @@ -32,7 +32,7 @@ export class AccountRestrictionTransaction { * @param modification - array of address modifications * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountAddressRestrictionModificationTransaction} + * @returns {AccountAddressRestrictionTransaction} */ public static createAddressRestrictionModificationTransaction( deadline: Deadline, @@ -40,11 +40,11 @@ export class AccountRestrictionTransaction { modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), - ): AccountAddressRestrictionModificationTransaction { + ): AccountAddressRestrictionTransaction { if (![RestrictionType.AllowAddress, RestrictionType.BlockAddress].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } - return AccountAddressRestrictionModificationTransaction.create( + return AccountAddressRestrictionTransaction.create( deadline, restrictionType, modifications, @@ -60,7 +60,7 @@ export class AccountRestrictionTransaction { * @param modification - array of mosaic modifications * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountMosaicRestrictionModificationTransaction} + * @returns {AccountMosaicRestrictionTransaction} */ public static createMosaicRestrictionModificationTransaction( deadline: Deadline, @@ -68,11 +68,11 @@ export class AccountRestrictionTransaction { modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), - ): AccountMosaicRestrictionModificationTransaction { + ): AccountMosaicRestrictionTransaction { if (![RestrictionType.AllowMosaic, RestrictionType.BlockMosaic].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } - return AccountMosaicRestrictionModificationTransaction.create( + return AccountMosaicRestrictionTransaction.create( deadline, restrictionType, modifications, @@ -96,11 +96,11 @@ export class AccountRestrictionTransaction { modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), - ): AccountOperationRestrictionModificationTransaction { + ): AccountOperationRestrictionTransaction { if (![RestrictionType.AllowTransaction, RestrictionType.BlockTransaction].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } - return AccountOperationRestrictionModificationTransaction.create( + return AccountOperationRestrictionTransaction.create( deadline, restrictionType, modifications, diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index c52a9efbed..b1b449dc69 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -16,6 +16,14 @@ import { Builder } from '../../infrastructure/builders/AddressAliasTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; +import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; +import { AddressDto } from '../../infrastructure/catbuffer/AddressDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -27,6 +35,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { RawAddress } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -126,4 +135,25 @@ export class AddressAliasTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AddressAliasTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ADDRESS_ALIAS.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new AddressDto(RawAddress.stringToAddress(this.address.plain())), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 495ba89fb8..016f66fd8e 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -203,4 +203,12 @@ export class AggregateTransaction extends Transaction { return byteSize + byteTransactionsSize + byteTransactions; } -} \ No newline at end of file + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } +} diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index 4036654043..9ad23c1a60 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -137,4 +137,11 @@ export class LockFundsTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index e8afe30251..dbc22505a7 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -14,8 +14,15 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MultisigModificationTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { CosignatoryModificationBuilder } from '../../infrastructure/catbuffer/CosignatoryModificationBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; @@ -112,7 +119,7 @@ export class ModifyMultisigAccountTransaction extends Transaction { // each modification contains : // - 1 byte for modificationType // - 32 bytes for cosignatoryPublicKey - const byteModifications = 33 * this.modifications.length + const byteModifications = 33 * this.modifications.length; return byteSize + byteRemovalDelta + byteApprovalDelta + byteNumModifications + byteModifications; } @@ -132,4 +139,30 @@ export class ModifyMultisigAccountTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MultisigAccountModificationTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MODIFY_MULTISIG_ACCOUNT.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.minRemovalDelta, + this.minApprovalDelta, + this.modifications.map((modification) => { + return new CosignatoryModificationBuilder( + modification.type.valueOf(), + new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index 8c03b28ab6..3bc49806c6 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -150,4 +150,11 @@ export class MosaicAddressRestrictionTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index 8220ccea1e..2ae1588994 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -16,6 +16,14 @@ import { Builder } from '../../infrastructure/builders/MosaicAliasTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/MosaicAliasTransactionBuilder'; +import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; +import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { MosaicId } from '../mosaic/MosaicId'; @@ -122,4 +130,25 @@ export class MosaicAliasTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicAliasTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_ALIAS.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index b82844ab41..7a41faddf9 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -27,6 +27,19 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; +import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; +import { MosaicFlagsDto } from '../../infrastructure/catbuffer/MosaicFlagsDto'; +import { MosaicFlags } from '../mosaic/MosaicFlag'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { Convert } from '../../core/format'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; /** * Before a mosaic can be created or transferred, a corresponding definition of the mosaic has to be created and published to the network. @@ -115,6 +128,37 @@ export class MosaicDefinitionTransaction extends Transaction { return byteSize + byteNonce + byteMosaicId + byteNumProps + byteFlags + byteDivisibility + byteDurationSize + byteDuration; } + /** + * @description get the calculated mosaic flag value + * @returns {number} + * @memberof MosaicDefinitionTransaction + */ + public getMosaicFlagValue(): number { + let flag = MosaicFlags.NONE; + if (this.mosaicProperties.supplyMutable === true) { + flag += MosaicFlags.SUPPLY_MUTABLE; + } + + if (this.mosaicProperties.transferable === true) { + flag += MosaicFlags.TRANSFERABLE; + } + + if (this.mosaicProperties.restrictable === true) { + flag += MosaicFlags.RESTRICTABLE; + } + + return flag.valueOf(); + } + + /** + * @description Get mosaic nonce int value + * @returns {number} + * @memberof MosaicDefinitionTransaction + */ + public getMosaicNonceIntValue(): number { + return GeneratorUtils.readUint32At(this.nonce.toDTO(), 0); + } + /** * @internal * @returns {VerifiableTransaction} @@ -144,4 +188,28 @@ export class MosaicDefinitionTransaction extends Transaction { return mosaicDefinitionTransaction.build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicDefinitionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_DEFINITION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new MosaicNonceDto(this.getMosaicNonceIntValue()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + this.getMosaicFlagValue(), + this.mosaicProperties.divisibility, + new BlockDurationDto(this.mosaicProperties.duration ? + this.mosaicProperties.duration.toDTO() : []), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index 7530eba330..7cbb7a55d5 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -173,4 +173,11 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index 39b33d8318..b53fbd92d3 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -16,6 +16,12 @@ import { Builder } from '../../infrastructure/builders/MosaicSupplyChangeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { MosaicId } from '../mosaic/MosaicId'; @@ -125,4 +131,25 @@ export class MosaicSupplyChangeTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicSupplyChangeTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_SUPPLY_CHANGE.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + this.direction.valueOf(), + new AmountDto(this.delta.toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index da05639507..f1f29cd6a2 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -182,4 +182,11 @@ export class RegisterNamespaceTransaction extends Transaction { return registerNamespacetransaction.build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index 6862dc7a3b..9e02785071 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -13,9 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Convert as convert } from '../../core/format'; +import { Convert as convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/SecretLockTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SecretLockTransactionBuilder } from '../../infrastructure/catbuffer/SecretLockTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from '../../infrastructure/catbuffer/UnresolvedMosaicBuilder'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -134,6 +145,15 @@ export class SecretLockTransaction extends Transaction { return byteSize + byteMosaicId + byteAmount + byteDuration + byteAlgorithm + byteRecipient + byteSecret; } + /** + * @description Get secret bytes + * @returns {Uint8Array} + * @memberof SecretLockTransaction + */ + public getSecretByte(): Uint8Array { + return convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); + } + /** * @internal * @returns {VerifiableTransaction} @@ -153,4 +173,28 @@ export class SecretLockTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new SecretLockTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_LOCK.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), + new AmountDto(this.mosaic.amount.toDTO())), + new BlockDurationDto(this.duration.toDTO()), + this.hashType.valueOf(), + new Hash256Dto(this.getSecretByte()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipient.plain())), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index cf41678857..588638fcc6 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -14,9 +14,17 @@ * limitations under the License. */ -import { Convert as convert } from '../../core/format'; +import { Convert, Convert as convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/SecretProofTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SecretProofTransactionBuilder } from '../../infrastructure/catbuffer/SecretProofTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -113,6 +121,24 @@ export class SecretProofTransaction extends Transaction { return byteSize + byteAlgorithm + byteSecret + byteRecipient + byteProofSize + byteProof; } + /** + * @description Get secret bytes + * @returns {Uint8Array} + * @memberof SecretLockTransaction + */ + public getSecretByte(): Uint8Array { + return convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); + } + + /** + * @description Get proof bytes + * @returns {Uint8Array} + * @memberof SecretLockTransaction + */ + public getProofByte(): Uint8Array { + return convert.hexToUint8(this.proof); + } + /** * @internal * @returns {VerifiableTransaction} @@ -130,4 +156,26 @@ export class SecretProofTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new SecretProofTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_PROOF.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.hashType.valueOf(), + new Hash256Dto(this.getSecretByte()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipient.plain())), + this.getProofByte(), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index 63fb543965..0bc6786fb3 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -import { SignSchema } from '../../core/crypto'; +import { KeyPair, SHA3Hasher, SignSchema } from '../../core/crypto'; +import { Convert } from '../../core/format'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { SerializeTransactionToJSON } from '../../infrastructure/transaction/SerializeTransactionToJSON'; import { Account } from '../account/Account'; @@ -79,6 +80,16 @@ export abstract class Transaction { public readonly transactionInfo?: TransactionInfo | AggregateTransactionInfo) { } + /** + * @internal + */ + protected abstract buildTransaction(): VerifiableTransaction; + + /** + * @internal + */ + protected abstract generateBytes(): Uint8Array; + /** * @internal * Serialize and sign transaction creating a new SignedTransaction @@ -100,8 +111,55 @@ export abstract class Transaction { /** * @internal + * Serialize and sign transaction creating a new SignedTransaction + * @param account - The account to sign the transaction + * @param generationHash - Network generation hash hex + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {SignedTransaction} */ - protected abstract buildTransaction(): VerifiableTransaction; + public signWithCatbuffer(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { + const generationHashBytes = Array.from(Convert.hexToUint8(generationHash)); + const byteBuffer = Array.from(this.generateBytes()); + const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); + const keyPairEncoded = KeyPair.createKeyPairFromPrivateKeyString(account.privateKey, signSchema); + const signature = Array.from(KeyPair.sign(account, new Uint8Array(signingBytes), signSchema)); + const signedTransactionBuffer = byteBuffer + .splice(0, 4) + .concat(signature) + .concat(Array.from(keyPairEncoded.publicKey)) + .concat(byteBuffer + .splice(64 + 32, byteBuffer.length)); + const payload = Convert.uint8ToHex(signedTransactionBuffer); + return new SignedTransaction( + payload, + this.createTransactionHash(payload, generationHashBytes), + account.publicKey, + this.type, + this.networkType); + } + + /** + * Generate transaction hash hex + * @param {string} transactionPayload HexString Payload + * @param {Array} generationHashBuffer Network generation hash byte + * @returns {string} Returns Transaction Payload hash + */ + public createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { + const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); + const signingBytes = byteBuffer + .slice(4, 36) + .concat(byteBuffer + .slice(4 + 64, 4 + 64 + 32)) + .concat(generationHashBuffer) + .concat(byteBuffer + .splice(4 + 64 + 32, byteBuffer.length)); + + const hash = new Uint8Array(32); + + SHA3Hasher.func(hash, signingBytes, 32); + + return Convert.uint8ToHex(hash); + } /** * @internal diff --git a/src/model/transaction/TransactionType.ts b/src/model/transaction/TransactionType.ts index 7b2b000adf..9d571f0855 100644 --- a/src/model/transaction/TransactionType.ts +++ b/src/model/transaction/TransactionType.ts @@ -15,114 +15,116 @@ */ /** - * Static class containing transaction type constants. + * Enum containing transaction type constants. */ -export class TransactionType { +export enum TransactionType { + /** Reserved entity type. */ + RESERVED = 0, /** * Transfer Transaction transaction type. * @type {number} */ - public static readonly TRANSFER = 0x4154; + TRANSFER = 0x4154, /** * Register namespace transaction type. * @type {number} */ - public static readonly REGISTER_NAMESPACE = 0x414E; + REGISTER_NAMESPACE = 0x414E, /** * Address alias transaction type * @type {number} */ - public static readonly ADDRESS_ALIAS = 0x424E; + ADDRESS_ALIAS = 0x424E, /** * Mosaic alias transaction type * @type {number} */ - public static readonly MOSAIC_ALIAS = 0x434E; + MOSAIC_ALIAS = 0x434E, /** * Mosaic definition transaction type. * @type {number} */ - public static readonly MOSAIC_DEFINITION = 0x414D; + MOSAIC_DEFINITION = 0x414D, /** * Mosaic supply change transaction. * @type {number} */ - public static readonly MOSAIC_SUPPLY_CHANGE = 0x424D; + MOSAIC_SUPPLY_CHANGE = 0x424D, /** * Modify multisig account transaction type. * @type {number} */ - public static readonly MODIFY_MULTISIG_ACCOUNT = 0x4155; + MODIFY_MULTISIG_ACCOUNT = 0x4155, /** * Aggregate complete transaction type. * @type {number} */ - public static readonly AGGREGATE_COMPLETE = 0x4141; + AGGREGATE_COMPLETE = 0x4141, /** * Aggregate bonded transaction type */ - public static readonly AGGREGATE_BONDED = 0x4241; + AGGREGATE_BONDED = 0x4241, /** * Lock transaction type * @type {number} */ - public static readonly LOCK = 0x4148; + LOCK = 0x4148, /** * Secret Lock Transaction type * @type {number} */ - public static readonly SECRET_LOCK = 0x4152; + SECRET_LOCK = 0x4152, /** * Secret Proof transaction type * @type {number} */ - public static readonly SECRET_PROOF = 0x4252; + SECRET_PROOF = 0x4252, /** * Account restriction address transaction type * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_ADDRESS = 0x4150; + ACCOUNT_RESTRICTION_ADDRESS = 0x4150, /** * Account restriction mosaic transaction type * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_MOSAIC = 0x4250; + ACCOUNT_RESTRICTION_MOSAIC = 0x4250, /** * Account restriction operation transaction type * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_OPERATION = 0x4350; + ACCOUNT_RESTRICTION_OPERATION = 0x4350, /** * Link account transaction type * @type {number} */ - public static readonly LINK_ACCOUNT = 0x414C; + LINK_ACCOUNT = 0x414C, /** * Mosaic address restriction type * @type {number} */ - public static readonly MOSAIC_ADDRESS_RESTRICTION = 0x4251; + MOSAIC_ADDRESS_RESTRICTION = 0x4251, /** * Mosaic global restriction type * @type {number} */ - public static readonly MOSAIC_GLOBAL_RESTRICTION = 0x4151; + MOSAIC_GLOBAL_RESTRICTION = 0x4151, } diff --git a/src/model/transaction/TransactionVersion.ts b/src/model/transaction/TransactionVersion.ts index 953c35e096..71087ac326 100644 --- a/src/model/transaction/TransactionVersion.ts +++ b/src/model/transaction/TransactionVersion.ts @@ -116,13 +116,13 @@ export class TransactionVersion { * Account Restriction address transaction version * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_ADDRESS = 0x01; + public static readonly ACCOUNT_RESTRICTION_ADDRESS = 0x01; /** * Account Restriction mosaic transaction version * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_MOSAIC = 0x01; + public static readonly ACCOUNT_RESTRICTION_MOSAIC = 0x01; /** * Account Restriction operation transaction version diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 880374187d..31dea94577 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -14,9 +14,20 @@ * limitations under the License. */ -import { Convert as convert } from '../../core/format'; +import { Convert, Convert as convert } from '../../core/format'; +import { RawAddress } from '../../core/format/RawAddress'; import { Builder } from '../../infrastructure/builders/TransferTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { TransferTransactionBuilder } from '../../infrastructure/catbuffer/TransferTransactionBuilder'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from '../../infrastructure/catbuffer/UnresolvedMosaicBuilder'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -109,6 +120,30 @@ export class TransferTransaction extends Transaction { return (this.recipient as Address).plain(); } + /** + * Return sorted mosaic arrays + * @internal + * @returns {Mosaic[]} + */ + public sortMosaics(): Mosaic[] { + const sortedMosaics = this.mosaics.sort((a, b) => { + if (Number(a.id[1]) > b.id[1]) { return 1; } else if (a.id[1] < b.id[1]) { return -1; } + return 0; + }); + return sortedMosaics; + } + + /** + * Return message buffer + * @internal + * @returns {Uint8Array} + */ + public getMessageBuffer(): Uint8Array { + const payloadBuffer = Convert.hexToUint8(Convert.utf8ToHex(this.message.payload)); + const typeBuffer = GeneratorUtils.uintToBuffer(this.message.type, 1); + return GeneratorUtils.concatTypedArrays(typeBuffer, payloadBuffer); + } + /** * @override Transaction.size() * @description get the byte size of a TransferTransaction @@ -146,4 +181,28 @@ export class TransferTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new TransferTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.TRANSFER.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), + this.getMessageBuffer(), + this.sortMosaics().map((mosaic) => { + return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), + new AmountDto(mosaic.amount.toDTO())); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index b3653114f1..1061991cb6 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -35,9 +35,9 @@ import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrency import { AliasAction } from '../../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { NamespaceType } from '../../../src/model/namespace/NamespaceType'; -import { AccountAddressRestrictionModificationTransaction } from '../../../src/model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from '../../../src/model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../../src/model/transaction/AccountLinkTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from '../../../src/model/transaction/AccountMosaicRestrictionModificationTransaction'; +import { AccountMosaicRestrictionTransaction } from '../../../src/model/transaction/AccountMosaicRestrictionTransaction'; import { AccountRestrictionModification } from '../../../src/model/transaction/AccountRestrictionModification'; import { AccountRestrictionTransaction } from '../../../src/model/transaction/AccountRestrictionTransaction'; import { AddressAliasTransaction } from '../../../src/model/transaction/AddressAliasTransaction'; @@ -87,7 +87,7 @@ describe('TransactionMapping - createFromPayload', () => { const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); const transaction = TransactionMapping - .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; + .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionTransaction; expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); @@ -110,7 +110,7 @@ describe('TransactionMapping - createFromPayload', () => { const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); const transaction = TransactionMapping - .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; + .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionTransaction; expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); expect(transaction.modifications[0].value[0]).to.be.equal(2262289484); expect(transaction.modifications[0].value[1]).to.be.equal(3405110546); @@ -132,8 +132,7 @@ describe('TransactionMapping - createFromPayload', () => { const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); - const transaction = TransactionMapping - .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; + const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AccountAddressRestrictionTransaction; expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); expect(transaction.modifications[0].value).to.be.equal(operation); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); @@ -672,7 +671,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const transaction = - TransactionMapping.createFromDTO(addressRestrictionTransaction.toJSON()) as AccountAddressRestrictionModificationTransaction; + TransactionMapping.createFromDTO(addressRestrictionTransaction.toJSON()) as AccountAddressRestrictionTransaction; expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); @@ -693,9 +692,9 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const transaction = - TransactionMapping.createFromDTO(mosaicRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; + TransactionMapping.createFromDTO(mosaicRestrictionTransaction.toJSON()) as AccountMosaicRestrictionTransaction; - expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC); + expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_MOSAIC); expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); expect(transaction.modifications.length).to.be.equal(1); }); @@ -714,9 +713,9 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const transaction = - TransactionMapping.createFromDTO(operationRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; + TransactionMapping.createFromDTO(operationRestrictionTransaction.toJSON()) as AccountMosaicRestrictionTransaction; - expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); + expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_OPERATION); expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); expect(transaction.modifications.length).to.be.equal(1); }); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 2f3ce56962..90aaa81936 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -90,7 +90,7 @@ describe('SerializeTransactionToJSON', () => { const json = addressRestrictionTransaction.toJSON(); - expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS); + expect(json.transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_ADDRESS); expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowAddress); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -110,7 +110,7 @@ describe('SerializeTransactionToJSON', () => { const json = mosaicRestrictionTransaction.toJSON(); - expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC); + expect(json.transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_MOSAIC); expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -130,7 +130,7 @@ describe('SerializeTransactionToJSON', () => { const json = operationRestrictionTransaction.toJSON(); - expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); + expect(json.transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_OPERATION); expect(json.transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction); expect(json.transaction.modifications.length).to.be.equal(1); }); diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index 68c65c8eae..0d5b8c8b25 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountLinkTransaction', () => { expect(accountLinkTransaction.linkAction).to.be.equal(0); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); - const signedTransaction = accountLinkTransaction.signWith(account, generationHash); + const signedTransaction = accountLinkTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 04ef489a07..36dd3232a1 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountRestrictionTransaction', () => { }); describe('size', () => { - it('should return 148 for AccountAddressRestrictionModificationTransaction transaction byte size with 1 modification', () => { + it('should return 148 for AccountAddressRestrictionTransaction transaction byte size with 1 modification', () => { const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); const addressRestrictionFilter = AccountRestrictionModification.createForAddress( RestrictionModificationType.Add, @@ -82,7 +82,7 @@ describe('AccountRestrictionTransaction', () => { expect(addressRestrictionTransaction.size).to.be.equal(148); }); - it('should return 131 for AccountMosaicRestrictionModificationTransaction transaction byte size with 1 modification', () => { + it('should return 131 for AccountMosaicRestrictionTransaction transaction byte size with 1 modification', () => { const mosaicId = new MosaicId([2262289484, 3405110546]); const mosaicRestrictionFilter = AccountRestrictionModification.createForMosaic( RestrictionModificationType.Add, @@ -97,7 +97,7 @@ describe('AccountRestrictionTransaction', () => { expect(mosaicRestrictionTransaction.size).to.be.equal(131); }); - it('should return 125 for AccountOperationRestrictionModificationTransaction transaction byte size with 1 modification', () => { + it('should return 125 for AccountOperationRestrictionTransaction transaction byte size with 1 modification', () => { const operation = TransactionType.ADDRESS_ALIAS; const operationRestrictionFilter = AccountRestrictionModification.createForOperation( RestrictionModificationType.Add, @@ -162,7 +162,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = addressRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -204,7 +204,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -246,7 +246,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = operationRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index 3111de06cb..2721b583d9 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('AddressAliasTransaction', () => { expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = addressAliasTransaction.signWith(account, generationHash); + const signedTransaction = addressAliasTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index f6065c02b3..c1c549a0b6 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -110,7 +110,7 @@ describe('ModifyMultisigAccountTransaction', () => { expect(modifyMultisigAccountTransaction.modifications[1].cosignatoryPublicAccount.publicKey) .to.be.equal('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); - const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); + const signedTransaction = modifyMultisigAccountTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index 0cf1077609..a9314a0c54 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -56,7 +56,7 @@ describe('MosaicAliasTransaction', () => { namespaceId, mosaicId, NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(mosaicAliasTransaction.maxFee.higher).to.be.equal(0); @@ -80,7 +80,7 @@ describe('MosaicAliasTransaction', () => { expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); expect(mosaicAliasTransaction.mosaicId.id.higher).to.be.equal(3405110546); - const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); + const signedTransaction = mosaicAliasTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index 5c15bafa89..688506516b 100644 --- a/test/model/transaction/MosaicDefinitionTransaction.spec.ts +++ b/test/model/transaction/MosaicDefinitionTransaction.spec.ts @@ -93,12 +93,12 @@ describe('MosaicDefinitionTransaction', () => { expect(mosaicDefinitionTransaction.mosaicProperties.transferable).to.be.equal(true); expect(mosaicDefinitionTransaction.mosaicProperties.restrictable).to.be.equal(true); - const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicDefinitionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('E6DE84B8010000000000000001070302E803000000000000'); + )).to.be.equal('E6DE84B801000000000000000703E803000000000000'); }); diff --git a/test/model/transaction/SecretLockTransaction.spec.ts b/test/model/transaction/SecretLockTransaction.spec.ts index 26bbd11ede..9f240dda47 100644 --- a/test/model/transaction/SecretLockTransaction.spec.ts +++ b/test/model/transaction/SecretLockTransaction.spec.ts @@ -18,6 +18,7 @@ import {expect} from 'chai'; import * as CryptoJS from 'crypto-js'; import {keccak_256, sha3_256} from 'js-sha3'; import {Convert as convert} from '../../../src/core/format'; +import { Account } from '../../../src/model/account/Account'; import {Address} from '../../../src/model/account/Address'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; @@ -25,9 +26,14 @@ import {Deadline} from '../../../src/model/transaction/Deadline'; import {HashType} from '../../../src/model/transaction/HashType'; import {SecretLockTransaction} from '../../../src/model/transaction/SecretLockTransaction'; import {UInt64} from '../../../src/model/UInt64'; +import { TestingAccount } from '../../conf/conf.spec'; describe('SecretLockTransaction', () => { - + let account: Account; + const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; + before(() => { + account = TestingAccount; + }); it('should default maxFee field be set to 0', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; const recipient = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); @@ -56,7 +62,7 @@ describe('SecretLockTransaction', () => { sha3_256.create().update(convert.hexToUint8(proof)).hex(), recipient, NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(secretLockTransaction.maxFee.higher).to.be.equal(0); @@ -83,6 +89,27 @@ describe('SecretLockTransaction', () => { expect(secretLockTransaction.recipient).to.be.equal(recipient); }); + it('should be created and sign SecretLock Transaction', () => { + const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; + const recipient = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + NetworkCurrencyMosaic.createAbsolute(10), + UInt64.fromUint(100), + HashType.Op_Sha3_256, + sha3_256.create().update(convert.hexToUint8(proof)).hex(), + recipient, + NetworkType.MIJIN_TEST, + ); + const signedTx = secretLockTransaction.signWithCatbuffer(account, generationHash); + expect(signedTx.payload.substring( + 240, + signedTx.payload.length, + )).to.be.equal( + '44B262C46CEABB850A000000000000006400000000000000009B3155B37159DA50AA52D5967C509B41' + + '0F5A36A3B1E31ECB5AC76675D79B4A5E90C2337113E6D8F15B56E0821149299F340C01706FC1CAD6CB'); + }); + it('should throw exception when the input is not related to HashTyp: Op_Sha3_256', () => { expect(() => { const recipient = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); diff --git a/test/model/transaction/SecretProofTransaction.spec.ts b/test/model/transaction/SecretProofTransaction.spec.ts index 6ee0b3aaab..8712f1ca9e 100644 --- a/test/model/transaction/SecretProofTransaction.spec.ts +++ b/test/model/transaction/SecretProofTransaction.spec.ts @@ -27,7 +27,7 @@ import { TestingAccount } from '../../conf/conf.spec'; describe('SecretProofTransaction', () => { let account: Account; - + const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; before(() => { account = TestingAccount; }); @@ -191,4 +191,24 @@ describe('SecretProofTransaction', () => { expect(secretProofTransaction.size).to.be.equal(212); }); }); + + it('should create and sign SecretProof Transaction', () => { + const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; + const secretProofTransaction = SecretProofTransaction.create( + Deadline.create(), + HashType.Op_Sha3_256, + sha3_256.create().update(convert.hexToUint8(proof)).hex(), + account.address, + proof, + NetworkType.MIJIN_TEST, + ); + + const signedTx = secretProofTransaction.signWithCatbuffer(account, generationHash); + expect(signedTx.payload.substring( + 240, + signedTx.payload.length, + )).to.be.equal( + '009B3155B37159DA50AA52D5967C509B410F5A36A3B1E31ECB5AC76675D79B4A5E90A75B6B63D31BDA938' + + '08727940F24699AECDDF17C568508BA2000B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'); + }); }); diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index c378c39c32..8e8b4cc9d4 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -238,4 +238,8 @@ class FakeTransaction extends Transaction { protected buildTransaction(): VerifiableTransaction { throw new Error('Method not implemented.'); } + + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/test/model/transaction/TransferTransaction.spec.ts b/test/model/transaction/TransferTransaction.spec.ts index 31e063be36..63d8bb880c 100644 --- a/test/model/transaction/TransferTransaction.spec.ts +++ b/test/model/transaction/TransferTransaction.spec.ts @@ -53,7 +53,7 @@ describe('TransferTransaction', () => { [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(transferTransaction.maxFee.higher).to.be.equal(0); @@ -193,4 +193,30 @@ describe('TransferTransaction', () => { expect(transaction.size).to.be.equal(158); }); }); + + it('should create TransferTransaction and sign using catbuffer', () => { + const transferTransaction = TransferTransaction.create( + Deadline.create(), + Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + [ + NetworkCurrencyMosaic.createRelative(100), + ], + PlainMessage.create('test-message'), + NetworkType.MIJIN_TEST, + ); + + expect(transferTransaction.message.payload).to.be.equal('test-message'); + expect(transferTransaction.mosaics.length).to.be.equal(1); + expect(transferTransaction.recipient).to.be.instanceof(Address); + expect((transferTransaction.recipient as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + + const signedTransaction = transferTransaction.signWithCatbuffer(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal( + '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000100746573742D6D657373616765' + + '44B262C46CEABB8500E1F50500000000'); + }); }); From b91aafbb2c4e3248b6fa01e2054fb99b49a3ba2d Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 22:38:29 +0100 Subject: [PATCH 38/98] Manually added aggregate transaction builder --- .../catbuffer/AggregateTransactionBuilder.ts | 136 ++++++++++++++++++ .../catbuffer/CosignatureBuilder.ts | 102 +++++++++++++ .../catbuffer/DetachedCosignatureBuilder.ts | 97 +++++++++++++ 3 files changed, 335 insertions(+) create mode 100644 src/infrastructure/catbuffer/AggregateTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/CosignatureBuilder.ts create mode 100644 src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts diff --git a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts new file mode 100644 index 0000000000..64b11c499f --- /dev/null +++ b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts @@ -0,0 +1,136 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; +import { AddressDto } from './AddressDto'; +import { AliasActionDto } from './AliasActionDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** binary layout for an aggregate transaction. */ +export class AggregateTransactionBuilder extends TransactionBuilder { + /** embedded transactions. */ + transactions: Uint8Array; + /** cosignatures. */ + cosignatures: Uint8Array; + + /** + * Constructor. + * + * @param signature entity signature. + * @param signer entity signer's public key. + * @param version entity version. + * @param type entity type. + * @param fee transaction fee. + * @param deadline transaction deadline. + * @param transactions embedded transactions. + * @param cosignatures cosignatures. + */ + public constructor( + signature: SignatureDto, + signer: KeyDto, + version: number, + type: EntityTypeDto, + fee: AmountDto, + deadline: TimestampDto, + transactions: Uint8Array, + cosignatures: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + this.transactions = transactions; + this.cosignatures = cosignatures; + } + + /** + * loadFromBinary - Create an instance of AggregateTransactionBuilder from a stream. + * + * @param Uint8Array Byte to use to serialize the object. + * @return An instance of AggregateTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AggregateTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const payloadSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + const transactions = GeneratorUtils.getBytes(Uint8Array.from(byteArray), payloadSize); + byteArray.splice(0, transactions.length); + const cosignatures = Uint8Array.from(byteArray); + // tslint:disable-next-line: max-line-length + return new AggregateTransactionBuilder(superObject.signature, superObject.signer, superObject.version, + superObject.type, superObject.fee, superObject.deadline, + transactions, cosignatures); + } + + /** + * Get embedded transactions. + * + * @return embedded transactions. + */ + public getTransactions(): Uint8Array { + return this.transactions; + } + + /** + * Get cosignatures. + * + * @return cosignatures. + */ + public getCosignatures(): Uint8Array { + return this.cosignatures; + } + + /** + * Get the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += 4; // payloadSize + size += this.transactions.length; + size += this.cosignatures.length; + return size; + } + + /** + * Serialize the object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const payloadSizeBytes = GeneratorUtils.uintToBuffer(this.transactions.length, 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes); + const transactionBytes = this.transactions; + newArray = GeneratorUtils.concatTypedArrays(newArray, transactionBytes); + const cosignaturesBytes = this.transactions; + newArray = GeneratorUtils.concatTypedArrays(newArray, cosignaturesBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/CosignatureBuilder.ts b/src/infrastructure/catbuffer/CosignatureBuilder.ts new file mode 100644 index 0000000000..5e0ba7a43c --- /dev/null +++ b/src/infrastructure/catbuffer/CosignatureBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; + +/** a cosignature. */ +export class CosignatureBuilder { + /** cosigner public key. */ + signer: KeyDto; + /** cosigner signature. */ + signature: SignatureDto; + + /** + * Constructor. + * + * @param signer cosigner public key. + * @param signature cosigner signature. + */ + public constructor(signer: KeyDto, signature: SignatureDto) { + this.signer = signer; + this.signature = signature; + } + + /** + * loadFromBinary - Create an instance of CosignatureBuilder from a stream. + * + * @param payload Byte to use to serialize the object. + * @return An instance of CosignatureBuilder. + */ + public static loadFromBinary(payload: Uint8Array): CosignatureBuilder { + const byteArray = Array.from(payload); + const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signer.getSize()); + const signature = SignatureDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signature.getSize()); + return new CosignatureBuilder(signer, signature); + } + + /** + * Get cosigner public key. + * + * @return cosigner public key. + */ + public getSigner(): KeyDto { + return this.signer; + } + + /** + * Get cosigner signature. + * + * @return cosigner signature. + */ + public getSignature(): SignatureDto { + return this.signature; + } + + /** + * Get the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.signer.getSize(); + size += this.signature.getSize(); + return size; + } + + /** + * Serialize the object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const signerBytes = this.signer.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); + const signatureBytes = this.signature.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signatureBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts b/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts new file mode 100644 index 0000000000..58a3152ed0 --- /dev/null +++ b/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts @@ -0,0 +1,97 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { CosignatureBuilder } from './CosignatureBuilder'; +import { Hash256Dto } from './Hash256Dto'; + +/** a detached cosignature. */ +export class DetachedCosignatureBuilder extends CosignatureBuilder { + /** hash of the corresponding parent. */ + parentHash: Hash256Dto; + + /** + * Constructor. + * + * @param signer cosigner public key. + * @param signature cosigner signature. + * @param parentHash hash of the corresponding parent. + */ + public constructor(signer: KeyDto, signature: SignatureDto, parentHash: Hash256Dto) { + super(signer, signature); + this.parentHash = parentHash; + } + + /** + * loadFromBinary - Create an instance of DetachedCosignatureBuilder from a stream. + * + * @param payload Byte to use to serialize the object. + * @return An instance of DetachedCosignatureBuilder. + */ + public static loadFromBinary(payload: Uint8Array): DetachedCosignatureBuilder { + const byteArray = Array.from(payload); + const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signer.getSize()); + const signature = SignatureDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signature.getSize()); + const parentHash = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, parentHash.getSize()); + return new DetachedCosignatureBuilder(signer, signature, parentHash); + } + + /** + * Get hash of the corresponding parent. + * + * @return hash of the corresponding parent. + */ + public getParentHash(): Hash256Dto { + return this.parentHash; + } + + /** + * Get the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = super.getSize(); + size += this.parentHash.getSize(); + return size; + } + + /** + * Serialize the object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const signerBytes = this.signer.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); + const signatureBytes = this.signature.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signatureBytes); + const parentHashBytes = this.parentHash.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, parentHashBytes); + return newArray; + } +} From 17a4ab357ec0a633fd3f402f381da1c801b9f4d6 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 23:43:48 +0100 Subject: [PATCH 39/98] Added embedded transaction builders --- .../AccountAddressRestrictionTransaction.ts | 23 ++++++ .../transaction/AccountLinkTransaction.ts | 18 +++++ .../AccountMosaicRestrictionTransaction.ts | 23 ++++++ .../AccountOperationRestrictionTransaction.ts | 36 +++++++-- .../transaction/AddressAliasTransaction.ts | 21 +++++- src/model/transaction/AggregateTransaction.ts | 8 ++ src/model/transaction/LockFundsTransaction.ts | 47 +++++++++++- .../ModifyMultisigAccountTransaction.ts | 24 ++++++ .../MosaicAddressRestrictionTransaction.ts | 47 +++++++++++- .../transaction/MosaicAliasTransaction.ts | 19 +++++ .../MosaicDefinitionTransaction.ts | 45 ++++++++---- .../MosaicGlobalRestrictionTransaction.ts | 49 ++++++++++++- .../MosaicSupplyChangeTransaction.ts | 19 +++++ .../RegisterNamespaceTransaction.ts | 73 ++++++++++++++++++- .../transaction/SecretLockTransaction.ts | 22 ++++++ .../transaction/SecretProofTransaction.ts | 20 +++++ src/model/transaction/Transaction.ts | 5 ++ src/model/transaction/TransferTransaction.ts | 21 ++++++ .../transaction/LockFundsTransaction.spec.ts | 30 +++++++- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- ...osaicAddressRestrictionTransaction.spec.ts | 2 +- ...MosaicGlobalRestrictionTransaction.spec.ts | 2 +- .../RegisterNamespaceTransaction.spec.ts | 4 +- test/model/transaction/Transaction.spec.ts | 4 + 24 files changed, 531 insertions(+), 33 deletions(-) diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index 243b4ff560..de89c65970 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -20,6 +20,7 @@ import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTra import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -144,4 +145,26 @@ export class AccountAddressRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountAddressRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountAddressRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedAddressDto(RawAddress.stringToAddress(modification.value)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index 41e00509b0..0d8c60c32b 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -19,6 +19,7 @@ import { Builder } from '../../infrastructure/builders/AccountLinkTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/AccountLinkTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -138,4 +139,21 @@ export class AccountLinkTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountLinkTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.LINK_ACCOUNT.valueOf(), + new KeyDto(Convert.hexToUint8(this.remoteAccountKey)), + this.linkAction.valueOf(), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index cfac1c3ea1..f8275cf7eb 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -19,6 +19,7 @@ import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTra import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -143,4 +144,26 @@ export class AccountMosaicRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountMosaicRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_MOSAIC.valueOf(), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountMosaicRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedMosaicIdDto(modification.value), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index 4ed72af488..ac24764f6c 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -16,6 +16,13 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; @@ -26,13 +33,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; -import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; -import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; -import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; -import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; export class AccountOperationRestrictionTransaction extends Transaction { @@ -142,4 +142,26 @@ export class AccountOperationRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountOperationRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_OPERATION.valueOf(), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountOperationRestrictionModificationBuilder( + modification.modificationType.valueOf(), + modification.value.valueOf(), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index b1b449dc69..8be88d2be4 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -14,11 +14,13 @@ * limitations under the License. */ +import { RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AddressAliasTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; import { AddressDto } from '../../infrastructure/catbuffer/AddressDto'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; @@ -35,7 +37,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { RawAddress } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -156,4 +157,22 @@ export class AddressAliasTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAddressAliasTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ADDRESS_ALIAS.valueOf(), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new AddressDto(RawAddress.stringToAddress(this.address.plain())), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 016f66fd8e..5f94e1fe33 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -211,4 +211,12 @@ export class AggregateTransaction extends Transaction { protected generateBytes(): Uint8Array { throw new Error('Not implemented'); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index 9ad23c1a60..52027d141d 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -14,8 +14,19 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/HashLockTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EmbeddedHashLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder'; +import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; +import { HashLockTransactionBuilder } from '../../infrastructure/catbuffer/HashLockTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicBuilder } from '../../infrastructure/catbuffer/UnresolvedMosaicBuilder'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { Mosaic } from '../mosaic/Mosaic'; @@ -142,6 +153,40 @@ export class LockFundsTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new HashLockTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.LOCK.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), + new AmountDto(this.mosaic.amount.toDTO())), + new BlockDurationDto(this.duration.toDTO()), + new Hash256Dto(Convert.hexToUint8(this.hash)), + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedHashLockTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.LOCK.valueOf(), + new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), + new AmountDto(this.mosaic.amount.toDTO())), + new BlockDurationDto(this.duration.toDTO()), + new Hash256Dto(Convert.hexToUint8(this.hash)), + ); + return transactionBuilder.serialize(); } } diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index dbc22505a7..f33e7af077 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -32,6 +32,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; /** * Modify multisig account transactions are part of the NEM's multisig account system. @@ -165,4 +166,27 @@ export class ModifyMultisigAccountTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMultisigAccountModificationTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MODIFY_MULTISIG_ACCOUNT.valueOf(), + this.minRemovalDelta, + this.minApprovalDelta, + this.modifications.map((modification) => { + return new CosignatoryModificationBuilder( + modification.type.valueOf(), + new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index 3bc49806c6..b1c62e0167 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -14,8 +14,17 @@ * limitations under the License. */ +import { RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicAddressRestrictionTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -155,6 +164,42 @@ export class MosaicAddressRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicAddressRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_ADDRESS_RESTRICTION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + this.restrictionKey.toDTO(), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.targetAddress.plain())), + this.previousRestrictionValue.toDTO(), + this.newRestrictionValue.toDTO(), + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicAddressRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_ADDRESS_RESTRICTION.valueOf(), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + this.restrictionKey.toDTO(), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.targetAddress.plain())), + this.previousRestrictionValue.toDTO(), + this.newRestrictionValue.toDTO(), + ); + return transactionBuilder.serialize(); } } diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index 2ae1588994..6e2e600ff8 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -17,6 +17,7 @@ import { Builder } from '../../infrastructure/builders/MosaicAliasTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { MosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/MosaicAliasTransactionBuilder'; @@ -151,4 +152,22 @@ export class MosaicAliasTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicAliasTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_ALIAS.valueOf(), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 7a41faddf9..8ac6e76eb0 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -16,8 +16,19 @@ import { Builder } from '../../infrastructure/builders/MosaicCreationTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EmbeddedMosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; +import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; +import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; +import { MosaicFlags } from '../mosaic/MosaicFlag'; import { MosaicId } from '../mosaic/MosaicId'; import { MosaicNonce } from '../mosaic/MosaicNonce'; import { MosaicProperties } from '../mosaic/MosaicProperties'; @@ -27,19 +38,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; -import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; -import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; -import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; -import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; -import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; -import { MosaicFlagsDto } from '../../infrastructure/catbuffer/MosaicFlagsDto'; -import { MosaicFlags } from '../mosaic/MosaicFlag'; -import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; -import { Convert } from '../../core/format'; -import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; /** * Before a mosaic can be created or transferred, a corresponding definition of the mosaic has to be created and published to the network. @@ -212,4 +210,25 @@ export class MosaicDefinitionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicDefinitionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_DEFINITION.valueOf(), + new MosaicNonceDto(this.getMosaicNonceIntValue()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + this.getMosaicFlagValue(), + this.mosaicProperties.divisibility, + new BlockDurationDto(this.mosaicProperties.duration ? + this.mosaicProperties.duration.toDTO() : []), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index 7cbb7a55d5..b2d421dca3 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -16,6 +16,13 @@ import { Builder } from '../../infrastructure/builders/MosaicGlobalRestrictionTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicGlobalRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicGlobalRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -178,6 +185,46 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicGlobalRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_GLOBAL_RESTRICTION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + new UnresolvedMosaicIdDto(this.referenceMosaicId.id.toDTO()), + this.restrictionKey.toDTO(), + this.previousRestrictionValue.toDTO(), + this.previousRestrictionType.valueOf(), + this.newRestrictionValue.toDTO(), + this.newRestrictionType.valueOf(), + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicGlobalRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_GLOBAL_RESTRICTION.valueOf(), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + new UnresolvedMosaicIdDto(this.referenceMosaicId.id.toDTO()), + this.restrictionKey.toDTO(), + this.previousRestrictionValue.toDTO(), + this.previousRestrictionType.valueOf(), + this.newRestrictionValue.toDTO(), + this.newRestrictionType.valueOf(), + ); + return transactionBuilder.serialize(); } } diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index b53fbd92d3..cc58bda02e 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -17,6 +17,7 @@ import { Builder } from '../../infrastructure/builders/MosaicSupplyChangeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { MosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -152,4 +153,22 @@ export class MosaicSupplyChangeTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicSupplyChangeTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_SUPPLY_CHANGE.valueOf(), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + this.direction.valueOf(), + new AmountDto(this.delta.toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index f1f29cd6a2..627397bc69 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -14,9 +14,17 @@ * limitations under the License. */ -import { Convert as convert } from '../../core/format'; +import { Convert, Convert as convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/NamespaceCreationTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EmbeddedNamespaceRegistrationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; +import { NamespaceRegistrationTransactionBuilder } from '../../infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import {NamespaceMosaicIdGenerator} from '../../infrastructure/transaction/NamespaceMosaicIdGenerator'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -187,6 +195,67 @@ export class RegisterNamespaceTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + let transactionBuilder: NamespaceRegistrationTransactionBuilder; + if (this.namespaceType === NamespaceType.RootNamespace) { + transactionBuilder = new NamespaceRegistrationTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.REGISTER_NAMESPACE.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), + new BlockDurationDto(this.duration!.toDTO()), + undefined, + ); + } else { + transactionBuilder = new NamespaceRegistrationTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.REGISTER_NAMESPACE.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), + undefined, + new NamespaceIdDto(this.parentId!.id.toDTO()), + ); + } + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + let transactionBuilder: EmbeddedNamespaceRegistrationTransactionBuilder; + if (this.namespaceType === NamespaceType.RootNamespace) { + transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_LOCK.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), + new BlockDurationDto(this.duration!.toDTO()), + undefined, + ); + } else { + transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_LOCK.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), + undefined, + new NamespaceIdDto(this.parentId!.id.toDTO()), + ); + } + return transactionBuilder.serialize(); } } diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index 9e02785071..9c0efaab1e 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -18,6 +18,7 @@ import { Builder } from '../../infrastructure/builders/SecretLockTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EmbeddedSecretLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -197,4 +198,25 @@ export class SecretLockTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedSecretLockTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_LOCK.valueOf(), + new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), + new AmountDto(this.mosaic.amount.toDTO())), + new BlockDurationDto(this.duration.toDTO()), + this.hashType.valueOf(), + new Hash256Dto(this.getSecretByte()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipient.plain())), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index 588638fcc6..acc1c53d7b 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -18,6 +18,7 @@ import { Convert, Convert as convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/SecretProofTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedSecretProofTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -178,4 +179,23 @@ export class SecretProofTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedSecretProofTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_PROOF.valueOf(), + this.hashType.valueOf(), + new Hash256Dto(this.getSecretByte()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipient.plain())), + this.getProofByte(), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index 0bc6786fb3..ceea1ab24c 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -90,6 +90,11 @@ export abstract class Transaction { */ protected abstract generateBytes(): Uint8Array; + /** + * @internal + */ + protected abstract generateEmbeddedBytes(): Uint8Array; + /** * @internal * Serialize and sign transaction creating a new SignedTransaction diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 31dea94577..08b6b29cc2 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -19,6 +19,7 @@ import { RawAddress } from '../../core/format/RawAddress'; import { Builder } from '../../infrastructure/builders/TransferTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedTransferTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedTransferTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -205,4 +206,24 @@ export class TransferTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const transactionBuilder = new EmbeddedTransferTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.TRANSFER.valueOf(), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), + this.getMessageBuffer(), + this.sortMosaics().map((mosaic) => { + return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), + new AmountDto(mosaic.amount.toDTO())); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/test/model/transaction/LockFundsTransaction.spec.ts b/test/model/transaction/LockFundsTransaction.spec.ts index ebd56dc4e0..df3583f1d7 100644 --- a/test/model/transaction/LockFundsTransaction.spec.ts +++ b/test/model/transaction/LockFundsTransaction.spec.ts @@ -15,6 +15,7 @@ */ import {deepEqual} from 'assert'; import {expect} from 'chai'; +import {Account} from '../../../src/model/account/Account'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; import {AggregateTransaction} from '../../../src/model/transaction/AggregateTransaction'; @@ -24,8 +25,11 @@ import {UInt64} from '../../../src/model/UInt64'; import {TestingAccount} from '../../conf/conf.spec'; describe('LockFundsTransaction', () => { - const account = TestingAccount; + let account: Account; const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; + before(() => { + account = TestingAccount; + }); it('should default maxFee field be set to 0', () => { const aggregateTransaction = AggregateTransaction.createBonded( Deadline.create(), @@ -58,7 +62,7 @@ describe('LockFundsTransaction', () => { UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(lockFundsTransaction.maxFee.higher).to.be.equal(0); @@ -100,6 +104,28 @@ describe('LockFundsTransaction', () => { }).to.throw(Error); }); + it('should create and sign LockFundsTransaction', () => { + const aggregateTransaction = AggregateTransaction.createBonded( + Deadline.create(), + [], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = account.sign(aggregateTransaction, generationHash); + const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), + NetworkCurrencyMosaic.createRelative(10), + UInt64.fromUint(10), + signedTransaction, + NetworkType.MIJIN_TEST, + ); + const signedTx = lockFundsTransaction.signWithCatbuffer(account, generationHash); + + expect(signedTx.payload.substring( + 136, + signedTransaction.payload.length - 32, + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE0190484100000000'); + }); + describe('size', () => { it('should return 176 for LockFundsTransaction transaction byte size', () => { const aggregateTransaction = AggregateTransaction.createBonded( diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index c1c549a0b6..f6232022da 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -70,7 +70,7 @@ describe('ModifyMultisigAccountTransaction', () => { NetworkType.MIJIN_TEST), )], NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(modifyMultisigAccountTransaction.maxFee.higher).to.be.equal(0); diff --git a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts index 947904ce56..02aad2fc65 100644 --- a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts @@ -47,7 +47,7 @@ describe('MosaicAddressRestrictionTransaction', () => { expect(mosaicAddressRestrictionTransaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(8).toHex()); expect(mosaicAddressRestrictionTransaction.targetAddress.plain()).to.be.equal(account.address.plain()); - const signedTransaction = mosaicAddressRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicAddressRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts index 39c409bd22..9e436d2fea 100644 --- a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts @@ -54,7 +54,7 @@ describe('MosaicGlobalRestrictionTransaction', () => { expect(mosaicGlobalRestrictionTransaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.EQ); expect(mosaicGlobalRestrictionTransaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); - const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicGlobalRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/RegisterNamespaceTransaction.spec.ts b/test/model/transaction/RegisterNamespaceTransaction.spec.ts index dcd12d95f7..db497c73b9 100644 --- a/test/model/transaction/RegisterNamespaceTransaction.spec.ts +++ b/test/model/transaction/RegisterNamespaceTransaction.spec.ts @@ -66,7 +66,7 @@ describe('RegisterNamespaceTransaction', () => { expect(registerNamespaceTransaction.duration!.lower).to.be.equal(1000); expect(registerNamespaceTransaction.duration!.higher).to.be.equal(0); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -83,7 +83,7 @@ describe('RegisterNamespaceTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index 8e8b4cc9d4..6f53048623 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -242,4 +242,8 @@ class FakeTransaction extends Transaction { protected generateBytes(): Uint8Array { throw new Error('Not implemented'); } + + protected generateEmbeddedBytes(): Uint8Array { + throw new Error('Not implemented'); + } } From ba6b189a1980d7fa531d83d16147de7306b4a056 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 08:26:17 +0100 Subject: [PATCH 40/98] Applied catbuffer on aggregate transaction --- .../catbuffer/AggregateTransactionBuilder.ts | 6 +-- .../AccountAddressRestrictionTransaction.ts | 6 +-- .../transaction/AccountLinkTransaction.ts | 4 +- .../AccountMosaicRestrictionTransaction.ts | 6 +-- .../AccountOperationRestrictionTransaction.ts | 5 +- .../transaction/AddressAliasTransaction.ts | 6 +-- src/model/transaction/AggregateTransaction.ts | 47 +++++++++++++++++-- src/model/transaction/LockFundsTransaction.ts | 4 +- .../ModifyMultisigAccountTransaction.ts | 4 +- .../MosaicAddressRestrictionTransaction.ts | 6 +-- .../transaction/MosaicAliasTransaction.ts | 5 +- .../MosaicDefinitionTransaction.ts | 5 +- .../MosaicGlobalRestrictionTransaction.ts | 5 +- .../MosaicSupplyChangeTransaction.ts | 5 +- .../RegisterNamespaceTransaction.ts | 5 +- .../transaction/SecretLockTransaction.ts | 4 +- .../transaction/SecretProofTransaction.ts | 4 +- src/model/transaction/Transaction.ts | 9 ++++ src/model/transaction/TransferTransaction.ts | 3 +- .../transaction/AggregateTransaction.spec.ts | 2 +- 20 files changed, 81 insertions(+), 60 deletions(-) diff --git a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts index 64b11c499f..20462d8514 100644 --- a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts +++ b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts @@ -19,14 +19,10 @@ *** along with Catapult. If not, see . **/ -import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; -import { AddressDto } from './AddressDto'; -import { AliasActionDto } from './AliasActionDto'; import { AmountDto } from './AmountDto'; import { EntityTypeDto } from './EntityTypeDto'; import { GeneratorUtils } from './GeneratorUtils'; import { KeyDto } from './KeyDto'; -import { NamespaceIdDto } from './NamespaceIdDto'; import { SignatureDto } from './SignatureDto'; import { TimestampDto } from './TimestampDto'; import { TransactionBuilder } from './TransactionBuilder'; @@ -129,7 +125,7 @@ export class AggregateTransactionBuilder extends TransactionBuilder { newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes); const transactionBytes = this.transactions; newArray = GeneratorUtils.concatTypedArrays(newArray, transactionBytes); - const cosignaturesBytes = this.transactions; + const cosignaturesBytes = this.cosignatures; newArray = GeneratorUtils.concatTypedArrays(newArray, cosignaturesBytes); return newArray; } diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index de89c65970..fd4200205c 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RawAddress } from '../../core/format'; +import { Convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; @@ -151,10 +151,8 @@ export class AccountAddressRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountAddressRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), this.restrictionType.valueOf(), diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index 0d8c60c32b..bd0a0303db 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -145,10 +145,8 @@ export class AccountLinkTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountLinkTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.LINK_ACCOUNT.valueOf(), new KeyDto(Convert.hexToUint8(this.remoteAccountKey)), diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index f8275cf7eb..efe54c41d8 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -14,13 +14,13 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; @@ -150,10 +150,8 @@ export class AccountMosaicRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountMosaicRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ACCOUNT_RESTRICTION_MOSAIC.valueOf(), this.restrictionType.valueOf(), diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index ac24764f6c..b42d33e3ab 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; @@ -148,10 +149,8 @@ export class AccountOperationRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountOperationRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ACCOUNT_RESTRICTION_OPERATION.valueOf(), this.restrictionType.valueOf(), diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 8be88d2be4..98a416a6d3 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RawAddress } from '../../core/format'; +import { Convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AddressAliasTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; @@ -163,10 +163,8 @@ export class AddressAliasTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAddressAliasTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ADDRESS_ALIAS.valueOf(), this.actionType.valueOf(), diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 5f94e1fe33..797eb757e5 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -15,8 +15,16 @@ */ import { SignSchema } from '../../core/crypto'; -import { Builder } from '../../infrastructure/builders/AggregateTransaction'; +import { Convert } from '../../core/format'; import { AggregateTransaction as AggregatedTransactionCore} from '../../infrastructure/builders/AggregateTransaction'; +import { Builder } from '../../infrastructure/builders/AggregateTransaction'; +import { AggregateTransactionBuilder } from '../../infrastructure/catbuffer/AggregateTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { CosignatureBuilder } from '../../infrastructure/catbuffer/CosignatureBuilder'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { Account } from '../account/Account'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -209,7 +217,40 @@ export class AggregateTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + let transactions = Uint8Array.from([]); + this.innerTransactions.forEach((transaction) => { + const transactionByte = transaction.toAggregateTransactionBytes(); + transactions = GeneratorUtils.concatTypedArrays(transactions, transactionByte); + }); + + const cosignatures = Uint8Array.from([]); + this.cosignatures.forEach((cosignature) => { + const signerBytes = Convert.hexToUint8(cosignature.signer.publicKey); + const signatureBytes = Convert.hexToUint8(cosignature.signature); + const cosignatureBytes = new CosignatureBuilder( + new KeyDto(signerBytes), + new SignatureDto(signatureBytes), + ).serialize(); + transactions = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); + }); + + console.log('cosignatures', Convert.uint8ToHex(cosignatures)); + console.log('transactions', Convert.uint8ToHex(transactions)); + + const transactionBuilder = new AggregateTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + this.type.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + transactions, + cosignatures, + ); + return transactionBuilder.serialize(); } /** @@ -217,6 +258,6 @@ export class AggregateTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - throw new Error('Not implemented'); + throw new Error('Method not implemented'); } } diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index 52027d141d..e34bb40489 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -176,10 +176,8 @@ export class LockFundsTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedHashLockTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.LOCK.valueOf(), new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index f33e7af077..fa1e35dfef 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -172,10 +172,8 @@ export class ModifyMultisigAccountTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMultisigAccountModificationTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MODIFY_MULTISIG_ACCOUNT.valueOf(), this.minRemovalDelta, diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index b1c62e0167..819d69c43c 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RawAddress } from '../../core/format'; +import { Convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicAddressRestrictionTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -188,10 +188,8 @@ export class MosaicAddressRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicAddressRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_ADDRESS_RESTRICTION.valueOf(), new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index 6e2e600ff8..f822b73505 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicAliasTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -158,10 +159,8 @@ export class MosaicAliasTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicAliasTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_ALIAS.valueOf(), this.actionType.valueOf(), diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 8ac6e76eb0..c0adbd1e8b 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicCreationTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -216,10 +217,8 @@ export class MosaicDefinitionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicDefinitionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_DEFINITION.valueOf(), new MosaicNonceDto(this.getMosaicNonceIntValue()), diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index b2d421dca3..7b4f757efc 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicGlobalRestrictionTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -211,10 +212,8 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicGlobalRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_GLOBAL_RESTRICTION.valueOf(), new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index cc58bda02e..be4f3a89a3 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -33,6 +33,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { Convert } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -159,10 +160,8 @@ export class MosaicSupplyChangeTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicSupplyChangeTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_SUPPLY_CHANGE.valueOf(), new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index 627397bc69..0cdcae2aa6 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -233,11 +233,10 @@ export class RegisterNamespaceTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); let transactionBuilder: EmbeddedNamespaceRegistrationTransactionBuilder; if (this.namespaceType === NamespaceType.RootNamespace) { transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.SECRET_LOCK.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), @@ -247,7 +246,7 @@ export class RegisterNamespaceTransaction extends Transaction { ); } else { transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.SECRET_LOCK.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index 9c0efaab1e..e65187384d 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -204,10 +204,8 @@ export class SecretLockTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedSecretLockTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.SECRET_LOCK.valueOf(), new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index acc1c53d7b..41df6b207b 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -185,10 +185,8 @@ export class SecretProofTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedSecretProofTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.SECRET_PROOF.valueOf(), this.hashType.valueOf(), diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index ceea1ab24c..ca2fbbce44 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -186,6 +186,15 @@ export abstract class Transaction { return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {signer}); } + /** + * Takes a transaction and formats bytes to be included in an aggregate transaction. + * + * @return transaction with signer serialized to be part of an aggregate transaction + */ + public toAggregateTransactionBytes() { + return this.generateEmbeddedBytes(); + } + /** * Transaction pending to be included in a block * @returns {boolean} diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 08b6b29cc2..6714fd7904 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -212,9 +212,8 @@ export class TransferTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); const transactionBuilder = new EmbeddedTransferTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.TRANSFER.valueOf(), new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index ab53059940..d6a4c714aa 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -106,7 +106,7 @@ describe('AggregateTransaction', () => { NetworkType.MIJIN_TEST, []); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); + const signedTransaction = aggregateTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); From ccb154fb530864728b0b4d4d23598853ec4c5fbf Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 11:46:27 +0100 Subject: [PATCH 41/98] Removed old flatbuffer staffs --- e2e/conf/network.conf | 64 +- .../buffers/AccountLinkTransactionBuffer.ts | 425 ---------- ...untRestrictionsAddressTransactionBuffer.ts | 557 ------------- ...RestrictionsEntityTypeTransactionBuffer.ts | 520 ------------ ...ountRestrictionsMosaicTransactionBuffer.ts | 557 ------------- .../buffers/AddressAliasTransactionBuffer.ts | 479 ----------- .../buffers/AggregateTransactionBuffer.ts | 425 ---------- .../buffers/HashLockTransactionBuffer.ts | 571 ------------- ...saicAddressRestrictionTransactionBuffer.ts | 625 -------------- .../buffers/MosaicAliasTransactionBuffer.ts | 479 ----------- .../MosaicCreationTransactionBuffer.ts | 582 ------------- ...osaicGlobalRestrictionTransactionBuffer.ts | 657 --------------- .../MosaicSupplyChangeTransactionBuffer.ts | 479 ----------- .../MultisigModificationTransactionBuffer.ts | 571 ------------- .../NamespaceCreationTransactionBuffer.ts | 512 ------------ .../buffers/SecretLockTransactionBuffer.ts | 641 -------------- .../buffers/SecretProofTransactionBuffer.ts | 549 ------------ .../buffers/TransferTransactionBuffer.ts | 785 ------------------ .../builders/AccountLinkTransaction.ts | 110 --- .../AccountRestrictionsAddressTransaction.ts | 128 --- ...ccountRestrictionsEntityTypeTransaction.ts | 126 --- .../AccountRestrictionsMosaicTransaction.ts | 127 --- .../builders/AddressAliasTransaction.ts | 122 --- .../builders/AggregateTransaction.ts | 151 ---- .../builders/CosignatureTransaction.ts | 27 - src/infrastructure/builders/Deadline.ts | 22 - .../builders/HashLockTransaction.ts | 127 --- .../MosaicAddressRestrictionTransaction.ts | 146 ---- .../builders/MosaicAliasTransaction.ts | 122 --- .../builders/MosaicCreationTransaction.ts | 164 ---- .../MosaicGlobalRestrictionTransaction.ts | 159 ---- .../builders/MosaicSupplyChangeTransaction.ts | 120 --- .../MultisigModificationTransaction.ts | 134 --- .../builders/NamespaceCreationTransaction.ts | 142 ---- .../builders/SecretLockTransaction.ts | 142 ---- .../builders/SecretProofTransaction.ts | 127 --- .../builders/TransferTransaction.ts | 152 ---- .../builders/VerifiableTransaction.ts | 128 --- .../builders/VerificableTransactionBuilder.ts | 65 -- .../schemas/AccountLinkTransactionSchema.ts | 44 - ...onsAddressModificationTransactionSchema.ts | 48 -- ...EntityTypeModificationTransactionSchema.ts | 48 -- ...ionsMosaicModificationTransactionSchema.ts | 48 -- .../schemas/AddressAliasTransactionSchema.ts | 44 - .../schemas/AggregateTransactionSchema.ts | 44 - .../schemas/HashLockTransactionSchema.ts | 45 - ...saicAddressRestrictionTransactionSchema.ts | 46 - .../schemas/MosaicAliasTransactionSchema.ts | 44 - .../MosaicCreationTransactionSchema.ts | 63 -- ...osaicGlobalRestrictionTransactionSchema.ts | 49 -- .../MosaicSupplyChangeTransactionSchema.ts | 44 - .../MultisigModificationTransactionSchema.ts | 49 -- .../NamespaceCreationTransactionSchema.ts | 47 -- src/infrastructure/schemas/Schema.ts | 374 --------- .../schemas/SecretLockTransactionSchema.ts | 48 -- .../schemas/SecretProofTransactionSchema.ts | 47 -- .../schemas/TransferTransactionSchema.ts | 55 -- .../CreateTransactionFromPayload.ts | 14 +- src/model/namespace/AliasAction.ts | 6 +- .../AccountAddressRestrictionTransaction.ts | 17 - .../transaction/AccountLinkTransaction.ts | 16 - .../AccountMosaicRestrictionTransaction.ts | 16 - .../AccountOperationRestrictionTransaction.ts | 16 - .../transaction/AddressAliasTransaction.ts | 17 - src/model/transaction/AggregateTransaction.ts | 67 +- .../transaction/CosignatureTransaction.ts | 39 +- src/model/transaction/LockFundsTransaction.ts | 19 - .../ModifyMultisigAccountTransaction.ts | 19 +- .../MosaicAddressRestrictionTransaction.ts | 19 - .../transaction/MosaicAliasTransaction.ts | 17 - .../MosaicDefinitionTransaction.ts | 35 +- .../MosaicGlobalRestrictionTransaction.ts | 21 - .../MosaicSupplyChangeTransaction.ts | 19 +- .../RegisterNamespaceTransaction.ts | 28 +- .../transaction/SecretLockTransaction.ts | 21 - .../transaction/SecretProofTransaction.ts | 19 - src/model/transaction/Transaction.ts | 88 +- src/model/transaction/TransferTransaction.ts | 35 +- .../AccountLinkTransaction.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 6 +- .../AddressAliasTransaction.spec.ts | 4 +- .../transaction/AggregateTransaction.spec.ts | 8 +- .../transaction/LockFundsTransaction.spec.ts | 2 +- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- ...osaicAddressRestrictionTransaction.spec.ts | 2 +- .../MosaicAliasTransaction.spec.ts | 4 +- .../MosaicDefinitionTransaction.spec.ts | 8 +- ...MosaicGlobalRestrictionTransaction.spec.ts | 2 +- .../RegisterNamespaceTransaction.spec.ts | 4 +- .../transaction/SecretLockTransaction.spec.ts | 2 +- .../SecretProofTransaction.spec.ts | 2 +- test/model/transaction/Transaction.spec.ts | 5 - .../transaction/TransferTransaction.spec.ts | 2 +- 93 files changed, 180 insertions(+), 13629 deletions(-) delete mode 100644 src/infrastructure/buffers/AccountLinkTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AccountRestrictionsAddressTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AccountRestrictionsEntityTypeTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AccountRestrictionsMosaicTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AddressAliasTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AggregateTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/HashLockTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicAddressRestrictionTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicAliasTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicCreationTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicGlobalRestrictionTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicSupplyChangeTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MultisigModificationTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/NamespaceCreationTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/SecretLockTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/SecretProofTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/TransferTransactionBuffer.ts delete mode 100644 src/infrastructure/builders/AccountLinkTransaction.ts delete mode 100644 src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts delete mode 100644 src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts delete mode 100644 src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts delete mode 100644 src/infrastructure/builders/AddressAliasTransaction.ts delete mode 100644 src/infrastructure/builders/AggregateTransaction.ts delete mode 100644 src/infrastructure/builders/CosignatureTransaction.ts delete mode 100644 src/infrastructure/builders/Deadline.ts delete mode 100644 src/infrastructure/builders/HashLockTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicAddressRestrictionTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicAliasTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicCreationTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicGlobalRestrictionTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicSupplyChangeTransaction.ts delete mode 100644 src/infrastructure/builders/MultisigModificationTransaction.ts delete mode 100644 src/infrastructure/builders/NamespaceCreationTransaction.ts delete mode 100644 src/infrastructure/builders/SecretLockTransaction.ts delete mode 100644 src/infrastructure/builders/SecretProofTransaction.ts delete mode 100644 src/infrastructure/builders/TransferTransaction.ts delete mode 100644 src/infrastructure/builders/VerifiableTransaction.ts delete mode 100644 src/infrastructure/builders/VerificableTransactionBuilder.ts delete mode 100644 src/infrastructure/schemas/AccountLinkTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AccountRestrictionsAddressModificationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AccountRestrictionsEntityTypeModificationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AccountRestrictionsMosaicModificationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AddressAliasTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AggregateTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/HashLockTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicAddressRestrictionTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicAliasTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicCreationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicGlobalRestrictionTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicSupplyChangeTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MultisigModificationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/NamespaceCreationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/Schema.ts delete mode 100644 src/infrastructure/schemas/SecretLockTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/SecretProofTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/TransferTransactionSchema.ts diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index 95fa85d3c7..79f895aecf 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -1,54 +1,54 @@ { - "apiUrl": "http://localhost:3000", + "apiUrl": "http://c2.nem.ninja:3000", "generationHash": "57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6", "testAccount": { - "privateKey": "D242FB34C2C4DD36E995B9C865F93940065E326661BA5A4A247331D211FE3A3D", - "address": "SBMYYFIM6VGG45KWGSZLSXFHP74WVT7MOF6UYBHT", - "publicKey": "2FC3872A792933617D70E02AFF8FBDE152821A0DF0CA5FB04CB56FC3D21C8863" + "privateKey": "E1C8521608F4896CA26A0C2DE739310EA4B06861D126CF4D6922064678A1969B", + "address": "SAKT3CKHCYIG5BBOPTSY2WXSVPBSLIA67AEOX4ND", + "publicKey": "9F784BF20318AE3CA6246C0EC2207FE095FFF7A84B6787E7E3C2CE4C3B92A2EA" }, "multisigAccount": { - "privateKey": "6EBE2AB0584C816771B494B36B40EC6CE1A0024C37DC6056D89D570A21A70262", - "address": "SCJAK5N6ICIE3JGHV5SVDSSNM5RUZZVDWQJ5G76N", - "publicKey": "224556169645EFAB772BFE1B5665490334428017E5D86FB3C9DFC4070B2F16A6" + "privateKey": "A9CEAA617D0B7D9DEBE9F96BD63CCF68A49950BB315CB9A4169FC6AAA1EC9E28", + "address": "SDWY3PYN4ZZO4S4EBEY2UPSSZUPGZH2G2LQMUSEU", + "publicKey": "8A613468924B8771779C7E4C889205A9BE6CAE0B9435B4BCC8E79A8DD8571608" }, "cosignatoryAccount": { - "privateKey": "44C0044B36AEF44C7743C407CEE4B6FD801BF6B0652AB7799B0991FFD3A81E71", - "address": "SCPL4YCGZYCML5WUSCIVN5MQF5YZAAF4GMZJIEL4", - "publicKey": "76C1622C7FB58986E500228E8FFB30C606CAAFC1CD78E770E82C73DAB7BD7C9F" + "privateKey": "8CBAA7491B7DC1070BECBC4F60AE55F4A272DA1DAD1D502DB016E142993817BA", + "address": "SB7Q5A3KEKFEWBPBTC6RFKU6Q2L4V7DM4ZNE4A7A", + "publicKey": "61B8EB2C02F3D3731A8EF6FE4CCD6BC84615BABA09CA3E891C0D2542096E6AD3" }, "cosignatory2Account": { - "privateKey": "F7B3A64652BAE6DB00D8B7C45F9D1C9BE0DB9E02002111A0B547AE1E220B7DDC", - "address": "SBISV4QCGJ7SSOLG64DBNPWU6J7SSY64R22D2L3Q", - "publicKey": "B5C2611E32E16482B0B9811ABF906A1DE84184DED1D343790482F517C02FB01C" + "privateKey": "60380027EBE63A5D60F6156F5637685172331705160783FF2F9D93C1E5A8622B", + "address": "SCM47E3JVPHOFWLSMNX3RKQQQIB3JUBR7MTX4M4P", + "publicKey": "3D9996683A0FA460D13288B846DF68A9B6C0C1F14EC2E43907DF8D84DC87B9C2" }, "cosignatory3Account": { - "privateKey": "A7D6ED74CDDECBF621DDC63558433DB604FA800D138810B3DF9B4EC880D0705F", - "address": "SD2UY5LHIAAZDVKRHBOYSS4MTLHVTJVUTQPEGV2U", - "publicKey": "3A33DA75E00F643C49C57E8BD3282149911B06FF107C37F7AEDFED5532166BDA" + "privateKey": "E39CE241F730CD190658AFDB5F3896628F92D7BC35D88435D148BED88C6CC844", + "address": "SDEVG5MU4MEGJ72NSBC7PKMK7JCJKN7QB3DOVARJ", + "publicKey": "422697046582D8B8063931B7327D0C06FA454B416F6A5C000922EC5BA546F4B2" }, "cosignatory4Account": { - "privateKey": "D2A12301F5595869EFD5374B3372F0ED7EC26BF73A71D310950CC018D3FA0B03", - "address": "SD7PYMM2BTT4SGSITZ2MBQBK4SXIQQQV4ZOP46VF", - "publicKey": "FDE589878756C2287056EC8D7B2829D9C1FA6D389EBDC808034813FE7810AAB0" + "privateKey": "0EA7E63C96FC580AD5EE85ED3C77A96B421F7C8BF75A83AB889313114C9082F2", + "address": "SCBNKMD23J7BO3Q42SEGP4LXGVJYSDPUESSEWGWZ", + "publicKey": "3A225A2C7C7D95279E74D420728D2DA2A176DE036B67909074AEF5F2DCFAF31C" }, "testAccount2": { - "privateKey": "E5DCCEBDB01A8B03A7DB7BA5888E2E33FD4617B5F6FED48C4C09C0780F422713", - "address": "SBSBLBT7CIOQG6XUI7TRDMHV4TKS5O7QM3MWQYHL", - "publicKey": "5F14CD455A1C0B08073C657EFA09365921736C1ADAF0F0685848678AE966EE09" + "privateKey": "A084418D937627BCDA19B277D8610C845124149FA18AABE96A17D56A2EA7FB8B", + "address": "SBF5HY3T7SXIBCSK4V4WNS4LS4QUMESMVNBCD2AQ", + "publicKey": "1C4B44400FDC933860B1949A5AEA756F19A36D73C4634699E49C3E7275EFA54F" }, "testAccount3": { - "privateKey": "CA95470BEFF4487D692D501E5C41F86FAE9CE6DD15B7B64E150E42A18BDE9CF8", - "address": "SBCFDASM35I6JSLUPQMSX2WGJG55WOCNB53NNVPH", - "publicKey": "E97077A656D9E7F5679880D4950BBF2B3638B7ACE17C82CCB7881DE9BAF396C6" + "privateKey": "8C9E72C5D8964A19174B478B65BD4B7F2AFD8F92C05AE45B15A9EDF222EC8CA8", + "address": "SDY65GIMMOF7GZGGART66QGS6ELWDTQT55JJOF42", + "publicKey": "B8320002C5CF64D855F073F2387FB18F13E7A04FA57FC3743694B04579104F98" }, "testAccountNoBalance": { - "privateKey": "A0591F79F588758280DFB4823A47FCEEC6A551344F794FFDE3760A9D7E1DE348", - "address": "SC5NTT5APX2FAUS4VQUII3UTMAD7GHRFTLDQOEDW", - "publicKey": "6D652E480E5B2997A19D0C7485724693D79A63FCD591A948B40240BD196BA7D6" + "privateKey": "CE4E6B1113EF8999ED79A027A4F3255C367BC2E40417E27E614FB7C12E42BDFA", + "address": "SDNMDW5TXIORKRXQ7F3QORRW4KUAK4ALQ7JWX2KJ", + "publicKey": "92658FE642AEAF1B766D0F4FE4E263C3A0E069735836383D31A70E2B7801358B" }, "harvestingAccount": { - "privateKey": "0B9802C011DA2D61BCD203F4DC76C012898EE38BA54A7E030B86630A8FD43CA6", - "address": "SAALWHKCWH72J53M3M4LB6UYFGLQMAOXJACWJX2U", - "publicKey": "092CAAFEBCB51C64A7CE423050964492407B264CA306D063DBA927A2304C4DD8" + "privateKey": "9999630E4AE5CA5675A703F3268084EB9A9B477A8C519D66465D5D21830E691A", + "address": "SC2PGQO5WV4QZRAQHJDNQ2Q5IFWA2D3VLFEFFZHC", + "publicKey": "74771A0B0B920D787F4F8242926C348007B23062910DE99C7E56AA79D4D7B90A" } -} \ No newline at end of file +} diff --git a/src/infrastructure/buffers/AccountLinkTransactionBuffer.ts b/src/infrastructure/buffers/AccountLinkTransactionBuffer.ts deleted file mode 100644 index 30dde827ce..0000000000 --- a/src/infrastructure/buffers/AccountLinkTransactionBuffer.ts +++ /dev/null @@ -1,425 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.AccountLinkTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AccountLinkTransactionBuffer} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AccountLinkTransactionBuffer=} obj - * @returns {Catapult.Buffers.AccountLinkTransactionBuffer} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.getRootAsAccountLinkTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AccountLinkTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signerLength = function() { - let offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signerArray = function() { - let offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.version = function() { - let offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.type = function() { - let offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.fee = function(index) { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.feeLength = function() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.feeArray = function() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.deadline = function(index) { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.deadlineLength = function() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.deadlineArray = function() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.remoteAccountKey = function(index) { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.remoteAccountKeyLength = function() { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.remoteAccountKeyArray = function() { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.linkAction = function() { - const offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startAccountLinkTransactionBuffer = function(builder) { - builder.startObject(12); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} remoteAccountKey - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addRemoteAccountKey = function(builder, remoteAccountKeyOffset) { - builder.addFieldOffset(7, remoteAccountKeyOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createRemoteAccountKeyVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startRemoteAccountKeyVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} linkAction - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addLinkAction = function(builder, linkAction) { - builder.addFieldInt8(8, linkAction, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.endAccountLinkTransactionBuffer = function(builder) { - const offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.finishAccountLinkTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AccountRestrictionsAddressTransactionBuffer.ts b/src/infrastructure/buffers/AccountRestrictionsAddressTransactionBuffer.ts deleted file mode 100644 index 7f71878ffc..0000000000 --- a/src/infrastructure/buffers/AccountRestrictionsAddressTransactionBuffer.ts +++ /dev/null @@ -1,557 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.RestrictionAddressModificationBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.RestrictionAddressModificationBuffer} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.RestrictionAddressModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionAddressModificationBuffer} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.getRootAsRestrictionAddressModificationBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.RestrictionAddressModificationBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.modificationType = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.value = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.valueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.valueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.startRestrictionAddressModificationBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.addModificationType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} valueOffset - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.addValue = function(builder, valueOffset) { - builder.addFieldOffset(1, valueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.createValueVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.startValueVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.endRestrictionAddressModificationBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer=} obj - * @returns {Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.getRootAsAccountRestrictionsAddressTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.restrictionType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.modificationCount = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.RestrictionAddressModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionAddressModificationBuffer} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.modifications = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? (obj || new Catapult.Buffers.RestrictionAddressModificationBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.modificationsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startAccountRestrictionsAddressTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} restrictionType - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addRestrictionType = function(builder, restrictionType) { - builder.addFieldInt8(7, restrictionType, 0); -}; - - -/** - * @param {flatbuffers.Builder} builder - * @param {number} modificationCount - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addModificationCount = function(builder, modificationCount) { - builder.addFieldInt8(8, modificationCount, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} modificationsOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addModifications = function(builder, modificationsOffset) { - builder.addFieldOffset(9, modificationsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createModificationsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startModificationsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.endAccountRestrictionsAddressTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.finishAccountRestrictionsAddressTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AccountRestrictionsEntityTypeTransactionBuffer.ts b/src/infrastructure/buffers/AccountRestrictionsEntityTypeTransactionBuffer.ts deleted file mode 100644 index b842f8d776..0000000000 --- a/src/infrastructure/buffers/AccountRestrictionsEntityTypeTransactionBuffer.ts +++ /dev/null @@ -1,520 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.RestrictionEntityTypeModificationBuffer} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.RestrictionEntityTypeModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionEntityTypeModificationBuffer} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.getRootAsRestrictionEntityTypeModificationBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.RestrictionEntityTypeModificationBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.prototype.modificationType = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.prototype.value = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.startRestrictionEntityTypeModificationBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.addModificationType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} valueOffset - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.addValue = function(builder, valueOffset) { - builder.addFieldInt16(1, valueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.endRestrictionEntityTypeModificationBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer=} obj - * @returns {Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.getRootAsAccountRestrictionsEntityTypeTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.restrictionType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.modificationCount = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.RestrictionEntityTypeModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionEntityTypeModificationBuffer} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.modifications = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? (obj || new Catapult.Buffers.RestrictionEntityTypeModificationBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.modificationsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startAccountRestrictionsEntityTypeTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} restrictionType - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addRestrictionType = function(builder, restrictionType) { - builder.addFieldInt8(7, restrictionType, 0); -}; - - -/** - * @param {flatbuffers.Builder} builder - * @param {number} modificationCount - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addModificationCount = function(builder, modificationCount) { - builder.addFieldInt8(8, modificationCount, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} modificationsOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addModifications = function(builder, modificationsOffset) { - builder.addFieldOffset(9, modificationsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createModificationsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startModificationsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.endAccountRestrictionsEntityTypeTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.finishAccountRestrictionsEntityTypeTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AccountRestrictionsMosaicTransactionBuffer.ts b/src/infrastructure/buffers/AccountRestrictionsMosaicTransactionBuffer.ts deleted file mode 100644 index 2fde91933f..0000000000 --- a/src/infrastructure/buffers/AccountRestrictionsMosaicTransactionBuffer.ts +++ /dev/null @@ -1,557 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.RestrictionMosaicModificationBuffer} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.RestrictionMosaicModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionMosaicModificationBuffer} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.getRootAsRestrictionMosaicModificationBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.RestrictionMosaicModificationBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.modificationType = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.value = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.valueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.valueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.startRestrictionMosaicModificationBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.addModificationType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} valueOffset - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.addValue = function(builder, valueOffset) { - builder.addFieldOffset(1, valueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.createValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.startValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.endRestrictionMosaicModificationBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer=} obj - * @returns {Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.getRootAsAccountRestrictionsMosaicTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.restrictionType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.modificationCount = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.RestrictionMosaicModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionMosaicModificationBuffer} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.modifications = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? (obj || new Catapult.Buffers.RestrictionMosaicModificationBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.modificationsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startAccountRestrictionsMosaicTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} restrictionType - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addRestrictionType = function(builder, restrictionType) { - builder.addFieldInt8(7, restrictionType, 0); -}; - - -/** - * @param {flatbuffers.Builder} builder - * @param {number} modificationCount - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addModificationCount = function(builder, modificationCount) { - builder.addFieldInt8(8, modificationCount, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} modificationsOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addModifications = function(builder, modificationsOffset) { - builder.addFieldOffset(9, modificationsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createModificationsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startModificationsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.endAccountRestrictionsMosaicTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.finishAccountRestrictionsMosaicTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AddressAliasTransactionBuffer.ts b/src/infrastructure/buffers/AddressAliasTransactionBuffer.ts deleted file mode 100644 index 00aa5f0a78..0000000000 --- a/src/infrastructure/buffers/AddressAliasTransactionBuffer.ts +++ /dev/null @@ -1,479 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.AddressAliasTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AddressAliasTransactionBuffer} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AddressAliasTransactionBuffer=} obj - * @returns {Catapult.Buffers.AddressAliasTransactionBuffer} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.getRootAsAddressAliasTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AddressAliasTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.aliasAction = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.namespaceId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.namespaceIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.namespaceIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.address = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.addressLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.addressArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startAddressAliasTransactionBuffer = function(builder) { - builder.startObject(10); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} aliasAction - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addAliasAction = function(builder, aliasAction) { - builder.addFieldInt8(7, aliasAction, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deltaOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addNamespaceId = function(builder, namespaceIdOffset) { - builder.addFieldOffset(8, namespaceIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createNamespaceIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startNamespaceIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addAddress = function(builder, addressOffset) { - builder.addFieldOffset(9, addressOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createAddressVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startAddressVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.endAddressAliasTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.finishAddressAliasTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AggregateTransactionBuffer.ts b/src/infrastructure/buffers/AggregateTransactionBuffer.ts deleted file mode 100644 index e2f9f68e83..0000000000 --- a/src/infrastructure/buffers/AggregateTransactionBuffer.ts +++ /dev/null @@ -1,425 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.AggregateTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AggregateTransactionBuffer} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AggregateTransactionBuffer=} obj - * @returns {Catapult.Buffers.AggregateTransactionBuffer} - */ -Catapult.Buffers.AggregateTransactionBuffer.getRootAsAggregateTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AggregateTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.transactionsSize = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.transactions = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.transactionsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.transactionsArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AggregateTransactionBuffer.startAggregateTransactionBuffer = function(builder) { - builder.startObject(9); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AggregateTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AggregateTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AggregateTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} transactionsSize - */ -Catapult.Buffers.AggregateTransactionBuffer.addTransactionsSize = function(builder, transactionsSize) { - builder.addFieldInt32(7, transactionsSize, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} transactionsOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addTransactions = function(builder, transactionsOffset) { - builder.addFieldOffset(8, transactionsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createTransactionsVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startTransactionsVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.endAggregateTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AggregateTransactionBuffer.finishAggregateTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/HashLockTransactionBuffer.ts b/src/infrastructure/buffers/HashLockTransactionBuffer.ts deleted file mode 100644 index ed4f0d4d8d..0000000000 --- a/src/infrastructure/buffers/HashLockTransactionBuffer.ts +++ /dev/null @@ -1,571 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.HashLockTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.HashLockTransactionBuffer} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.HashLockTransactionBuffer=} obj - * @returns {Catapult.Buffers.HashLockTransactionBuffer} - */ -Catapult.Buffers.HashLockTransactionBuffer.getRootAsHashLockTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.HashLockTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicAmount = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicAmountLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicAmountArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.duration = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.durationLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.durationArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.hash = function(index) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.hashLength = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.hashArray = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.HashLockTransactionBuffer.startHashLockTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.HashLockTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.HashLockTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.HashLockTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicAmountOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addMosaicAmount = function(builder, mosaicAmountOffset) { - builder.addFieldOffset(8, mosaicAmountOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createMosaicAmountVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startMosaicAmountVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} durationOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addDuration = function(builder, durationOffset) { - builder.addFieldOffset(9, durationOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createDurationVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startDurationVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} hashOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addHash = function(builder, hashOffset) { - builder.addFieldOffset(10, hashOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createHashVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startHashVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.endHashLockTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.HashLockTransactionBuffer.finishHashLockTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicAddressRestrictionTransactionBuffer.ts b/src/infrastructure/buffers/MosaicAddressRestrictionTransactionBuffer.ts deleted file mode 100644 index a306031841..0000000000 --- a/src/infrastructure/buffers/MosaicAddressRestrictionTransactionBuffer.ts +++ /dev/null @@ -1,625 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.getRootAsMosaicAddressRestrictionTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.restrictionKey = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.restrictionKeyLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.restrictionKeyArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.targetAddress = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.targetAddressLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.targetAddressArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.previousRestrictionValue = function(index) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.previousRestrictionValueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.previousRestrictionValueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.newRestrictionValue = function(index) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.newRestrictionValueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.newRestrictionValueValueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startMosaicAddressRestrictionTransactionBuffer = function(builder) { - builder.startObject(14); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} restrictionKeyOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addRestrictionKey = function(builder, restrictionKeyOffset) { - builder.addFieldOffset(8, restrictionKeyOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createRestrictionKeyVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startRestrictionKeyVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} targetAddressOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addTargetAddress = function(builder, targetAddressOffset) { - builder.addFieldOffset(9, targetAddressOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createTargetAddressVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startTargetAddressVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} previousRestrictionValueOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addPreviousRestrictionValue = function(builder, previousRestrictionValueOffset) { - builder.addFieldOffset(10, previousRestrictionValueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createPreviousRestrictionValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startPreviousRestrictionValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} newRestrictionValueOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addNewRestrictionValue = function(builder, newRestrictionValueOffset) { - builder.addFieldOffset(11, newRestrictionValueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createNewRestrictionValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startNewRestrictionValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.endMosaicAddressRestrictionTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.finishMosaicAddressRestrictionTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicAliasTransactionBuffer.ts b/src/infrastructure/buffers/MosaicAliasTransactionBuffer.ts deleted file mode 100644 index 3632f14354..0000000000 --- a/src/infrastructure/buffers/MosaicAliasTransactionBuffer.ts +++ /dev/null @@ -1,479 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicAliasTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicAliasTransactionBuffer} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicAliasTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicAliasTransactionBuffer} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.getRootAsMosaicAliasTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicAliasTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.aliasAction = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.namespaceId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.namespaceIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.namespaceIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startMosaicAliasTransactionBuffer = function(builder) { - builder.startObject(10); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} aliasAction - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addAliasAction = function(builder, aliasAction) { - builder.addFieldInt8(7, aliasAction, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deltaOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addNamespaceId = function(builder, namespaceIdOffset) { - builder.addFieldOffset(8, namespaceIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createNamespaceIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startNamespaceIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(9, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.endMosaicAliasTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.finishMosaicAliasTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicCreationTransactionBuffer.ts b/src/infrastructure/buffers/MosaicCreationTransactionBuffer.ts deleted file mode 100644 index eef8821885..0000000000 --- a/src/infrastructure/buffers/MosaicCreationTransactionBuffer.ts +++ /dev/null @@ -1,582 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicCreationTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicCreationTransactionBuffer} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicCreationTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicCreationTransactionBuffer} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.getRootAsMosaicCreationTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicCreationTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.nonce = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.nonceLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.nonceArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.numOptionalProperties = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.flags = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.divisibility = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.indicateDuration = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.duration = function(index) { - var offset = this.bb.__offset(this.bb_pos, 30); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.durationLength = function() { - var offset = this.bb.__offset(this.bb_pos, 30); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.durationArray = function() { - var offset = this.bb.__offset(this.bb_pos, 30); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startMosaicCreationTransactionBuffer = function(builder) { - builder.startObject(14); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} nonce - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addNonce = function(builder, nonceOffset) { - - builder.addFieldOffset(7, nonceOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createNonceVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startNonceVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(8, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numOptionalProperties - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addNumOptionalProperties = function(builder, numOptionalProperties) { - builder.addFieldInt8(9, numOptionalProperties, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} flags - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addFlags = function(builder, flags) { - builder.addFieldInt8(10, flags, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} divisibility - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addDivisibility = function(builder, divisibility) { - builder.addFieldInt8(11, divisibility, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} indicateDuration - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addIndicateDuration = function(builder, indicateDuration) { - builder.addFieldInt8(12, indicateDuration, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} durationOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addDuration = function(builder, durationOffset) { - builder.addFieldOffset(13, durationOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createDurationVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startDurationVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.endMosaicCreationTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.finishMosaicCreationTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicGlobalRestrictionTransactionBuffer.ts b/src/infrastructure/buffers/MosaicGlobalRestrictionTransactionBuffer.ts deleted file mode 100644 index 794dfd3add..0000000000 --- a/src/infrastructure/buffers/MosaicGlobalRestrictionTransactionBuffer.ts +++ /dev/null @@ -1,657 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.getRootAsMosaicGlobalRestrictionTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.referenceMosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.referenceMosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.referenceMosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.restrictionKey = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.restrictionKeyLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.restrictionKeyArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.previousRestrictionValue = function(index) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.previousRestrictionValueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.previousRestrictionValueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.previousRestrictionType = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.newRestrictionValue = function(index) { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.newRestrictionValueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.newRestrictionValueValueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.newRestrictionValue = function() { - var offset = this.bb.__offset(this.bb_pos, 30); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startMosaicGlobalRestrictionTransactionBuffer = function(builder) { - builder.startObject(14); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} referenceMosaicIdOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addReferenceMosaicId = function(builder, referenceMosaicIdOffset) { - builder.addFieldOffset(8, referenceMosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createReferenceMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startReferenceMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} restrictionKeyOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addRestrictionKey = function(builder, restrictionKeyOffset) { - builder.addFieldOffset(9, restrictionKeyOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createRestrictionKeyVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startRestrictionKeyVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} previousRestrictionValueOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addPreviousRestrictionValue = function(builder, previousRestrictionValueOffset) { - builder.addFieldOffset(10, previousRestrictionValueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createPreviousRestrictionValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startPreviousRestrictionValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} previousRestrictionType - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addPreviousRestrictionType = function(builder, previousRestrictionType) { - builder.addFieldInt16(11, previousRestrictionType, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} newRestrictionValueOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addNewRestrictionValue = function(builder, newRestrictionValueOffset) { - builder.addFieldOffset(12, newRestrictionValueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createNewRestrictionValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startNewRestrictionValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} newRestrictionType - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addNewRestrictionType = function(builder, newRestrictionType) { - builder.addFieldInt16(13, newRestrictionType, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.endMosaicGlobalRestrictionTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.finishMosaicGlobalRestrictionTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicSupplyChangeTransactionBuffer.ts b/src/infrastructure/buffers/MosaicSupplyChangeTransactionBuffer.ts deleted file mode 100644 index 0297f46688..0000000000 --- a/src/infrastructure/buffers/MosaicSupplyChangeTransactionBuffer.ts +++ /dev/null @@ -1,479 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicSupplyChangeTransactionBuffer} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicSupplyChangeTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicSupplyChangeTransactionBuffer} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.getRootAsMosaicSupplyChangeTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicSupplyChangeTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.direction = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.delta = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deltaLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deltaArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startMosaicSupplyChangeTransactionBuffer = function(builder) { - builder.startObject(10); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} direction - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addDirection = function(builder, direction) { - builder.addFieldInt8(8, direction, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deltaOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addDelta = function(builder, deltaOffset) { - builder.addFieldOffset(9, deltaOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createDeltaVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startDeltaVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.endMosaicSupplyChangeTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.finishMosaicSupplyChangeTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MultisigModificationTransactionBuffer.ts b/src/infrastructure/buffers/MultisigModificationTransactionBuffer.ts deleted file mode 100644 index 14376de447..0000000000 --- a/src/infrastructure/buffers/MultisigModificationTransactionBuffer.ts +++ /dev/null @@ -1,571 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.CosignatoryModificationBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.CosignatoryModificationBuffer} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.CosignatoryModificationBuffer=} obj - * @returns {Catapult.Buffers.CosignatoryModificationBuffer} - */ -Catapult.Buffers.CosignatoryModificationBuffer.getRootAsCosignatoryModificationBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.CosignatoryModificationBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.cosignatoryPublicKey = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.cosignatoryPublicKeyLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.cosignatoryPublicKeyArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.CosignatoryModificationBuffer.startCosignatoryModificationBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.CosignatoryModificationBuffer.addType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} cosignatoryPublicKeyOffset - */ -Catapult.Buffers.CosignatoryModificationBuffer.addCosignatoryPublicKey = function(builder, cosignatoryPublicKeyOffset) { - builder.addFieldOffset(1, cosignatoryPublicKeyOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.CosignatoryModificationBuffer.createCosignatoryPublicKeyVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.CosignatoryModificationBuffer.startCosignatoryPublicKeyVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.CosignatoryModificationBuffer.endCosignatoryModificationBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.MultisigModificationTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MultisigModificationTransactionBuffer} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MultisigModificationTransactionBuffer=} obj - * @returns {Catapult.Buffers.MultisigModificationTransactionBuffer} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.getRootAsMultisigModificationTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MultisigModificationTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.minRemovalDelta = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.minApprovalDelta = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.numModifications = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.CosignatoryModificationBuffer=} obj - * @returns {Catapult.Buffers.CosignatoryModificationBuffer} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.modifications = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? (obj || new Catapult.Buffers.CosignatoryModificationBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.modificationsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startMultisigModificationTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} minRemovalDelta - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addMinRemovalDelta = function(builder, minRemovalDelta) { - builder.addFieldInt8(7, minRemovalDelta, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} minApprovalDelta - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addMinApprovalDelta = function(builder, minApprovalDelta) { - builder.addFieldInt8(8, minApprovalDelta, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numModifications - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addNumModifications = function(builder, numModifications) { - builder.addFieldInt8(9, numModifications, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} modificationsOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addModifications = function(builder, modificationsOffset) { - builder.addFieldOffset(10, modificationsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createModificationsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startModificationsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.endMultisigModificationTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.finishMultisigModificationTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/NamespaceCreationTransactionBuffer.ts b/src/infrastructure/buffers/NamespaceCreationTransactionBuffer.ts deleted file mode 100644 index 47e9657a44..0000000000 --- a/src/infrastructure/buffers/NamespaceCreationTransactionBuffer.ts +++ /dev/null @@ -1,512 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.NamespaceCreationTransactionBuffer} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.NamespaceCreationTransactionBuffer=} obj - * @returns {Catapult.Buffers.NamespaceCreationTransactionBuffer} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.getRootAsNamespaceCreationTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.NamespaceCreationTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.durationParentId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.durationParentIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.durationParentIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceNameSize = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Encoding=} optionalEncoding - * @returns {string|Uint8Array|null} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceName = function(optionalEncoding) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startNamespaceCreationTransactionBuffer = function(builder) { - builder.startObject(12); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} namespaceType - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addNamespaceType = function(builder, namespaceType) { - builder.addFieldInt8(7, namespaceType, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} durationParentIdOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addDurationParentId = function(builder, durationParentIdOffset) { - builder.addFieldOffset(8, durationParentIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createDurationParentIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startDurationParentIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} namespaceIdOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addNamespaceId = function(builder, namespaceIdOffset) { - builder.addFieldOffset(9, namespaceIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createNamespaceIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startNamespaceIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} namespaceNameSize - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addNamespaceNameSize = function(builder, namespaceNameSize) { - builder.addFieldInt8(10, namespaceNameSize, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} namespaceNameOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addNamespaceName = function(builder, namespaceNameOffset) { - builder.addFieldOffset(11, namespaceNameOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.endNamespaceCreationTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.finishNamespaceCreationTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/SecretLockTransactionBuffer.ts b/src/infrastructure/buffers/SecretLockTransactionBuffer.ts deleted file mode 100644 index 4036cdd4c2..0000000000 --- a/src/infrastructure/buffers/SecretLockTransactionBuffer.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.SecretLockTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.SecretLockTransactionBuffer} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.SecretLockTransactionBuffer=} obj - * @returns {Catapult.Buffers.SecretLockTransactionBuffer} - */ -Catapult.Buffers.SecretLockTransactionBuffer.getRootAsSecretLockTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.SecretLockTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicAmount = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicAmountLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicAmountArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.duration = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.durationLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.durationArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.hashAlgorithm = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.secret = function(index) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.secretLength = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.secretArray = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.recipient = function(index) { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.recipientLength = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.recipientArray = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.SecretLockTransactionBuffer.startSecretLockTransactionBuffer = function(builder) { - builder.startObject(13); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.SecretLockTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.SecretLockTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.SecretLockTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicAmountOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addMosaicAmount = function(builder, mosaicAmountOffset) { - builder.addFieldOffset(8, mosaicAmountOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createMosaicAmountVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startMosaicAmountVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} durationOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addDuration = function(builder, durationOffset) { - builder.addFieldOffset(9, durationOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createDurationVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startDurationVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} hashAlgorithm - */ -Catapult.Buffers.SecretLockTransactionBuffer.addHashAlgorithm = function(builder, hashAlgorithm) { - builder.addFieldInt8(10, hashAlgorithm, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} secretOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addSecret = function(builder, secretOffset) { - builder.addFieldOffset(11, secretOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createSecretVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startSecretVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} recipientOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addRecipient = function(builder, recipientOffset) { - builder.addFieldOffset(12, recipientOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createRecipientVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startRecipientVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.endSecretLockTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.SecretLockTransactionBuffer.finishSecretLockTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/SecretProofTransactionBuffer.ts b/src/infrastructure/buffers/SecretProofTransactionBuffer.ts deleted file mode 100644 index 570f57a886..0000000000 --- a/src/infrastructure/buffers/SecretProofTransactionBuffer.ts +++ /dev/null @@ -1,549 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.SecretProofTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.SecretProofTransactionBuffer} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.SecretProofTransactionBuffer=} obj - * @returns {Catapult.Buffers.SecretProofTransactionBuffer} - */ -Catapult.Buffers.SecretProofTransactionBuffer.getRootAsSecretProofTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.SecretProofTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.hashAlgorithm = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.secret = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.secretLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.secretArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.recipient = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.recipientLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.recipientArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.proofSize = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.proof = function(index) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.proofLength = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.proofArray = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.SecretProofTransactionBuffer.startSecretProofTransactionBuffer = function(builder) { - builder.startObject(12); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.SecretProofTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.SecretProofTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.SecretProofTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} hashAlgorithm - */ -Catapult.Buffers.SecretProofTransactionBuffer.addHashAlgorithm = function(builder, hashAlgorithm) { - builder.addFieldInt8(7, hashAlgorithm, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} secretOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addSecret = function(builder, secretOffset) { - builder.addFieldOffset(8, secretOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createSecretVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startSecretVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} recipientOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addRecipient = function(builder, recipientOffset) { - builder.addFieldOffset(9, recipientOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createRecipientVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startRecipientVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} proofSize - */ -Catapult.Buffers.SecretProofTransactionBuffer.addProofSize = function(builder, proofSize) { - builder.addFieldInt16(10, proofSize, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} proofOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addProof = function(builder, proofOffset) { - builder.addFieldOffset(11, proofOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createProofVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startProofVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.endSecretProofTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.SecretProofTransactionBuffer.finishSecretProofTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/TransferTransactionBuffer.ts b/src/infrastructure/buffers/TransferTransactionBuffer.ts deleted file mode 100644 index 05be19edfb..0000000000 --- a/src/infrastructure/buffers/TransferTransactionBuffer.ts +++ /dev/null @@ -1,785 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MessageBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MessageBuffer} - */ -Catapult.Buffers.MessageBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MessageBuffer=} obj - * @returns {Catapult.Buffers.MessageBuffer} - */ -Catapult.Buffers.MessageBuffer.getRootAsMessageBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MessageBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MessageBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MessageBuffer.prototype.payload = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MessageBuffer.prototype.payloadLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MessageBuffer.prototype.payloadArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MessageBuffer.startMessageBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MessageBuffer.addType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} payloadOffset - */ -Catapult.Buffers.MessageBuffer.addPayload = function(builder, payloadOffset) { - builder.addFieldOffset(1, payloadOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MessageBuffer.createPayloadVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MessageBuffer.startPayloadVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MessageBuffer.endMessageBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicBuffer} - */ -Catapult.Buffers.MosaicBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicBuffer=} obj - * @returns {Catapult.Buffers.MosaicBuffer} - */ -Catapult.Buffers.MosaicBuffer.getRootAsMosaicBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicBuffer.prototype.id = function(index) { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicBuffer.prototype.idLength = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicBuffer.prototype.idArray = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicBuffer.prototype.amount = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicBuffer.prototype.amountLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicBuffer.prototype.amountArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicBuffer.startMosaicBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} idOffset - */ -Catapult.Buffers.MosaicBuffer.addId = function(builder, idOffset) { - builder.addFieldOffset(0, idOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicBuffer.createIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicBuffer.startIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} amountOffset - */ -Catapult.Buffers.MosaicBuffer.addAmount = function(builder, amountOffset) { - builder.addFieldOffset(1, amountOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicBuffer.createAmountVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicBuffer.startAmountVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicBuffer.endMosaicBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.TransferTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.TransferTransactionBuffer} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.TransferTransactionBuffer=} obj - * @returns {Catapult.Buffers.TransferTransactionBuffer} - */ -Catapult.Buffers.TransferTransactionBuffer.getRootAsTransferTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.TransferTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.recipient = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.recipientLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.recipientArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.messageSize = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.numMosaics = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {Catapult.Buffers.MessageBuffer=} obj - * @returns {Catapult.Buffers.MessageBuffer|null} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.message = function(obj) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? (obj || new Catapult.Buffers.MessageBuffer).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.MosaicBuffer=} obj - * @returns {Catapult.Buffers.MosaicBuffer} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.mosaics = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? (obj || new Catapult.Buffers.MosaicBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.mosaicsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.TransferTransactionBuffer.startTransferTransactionBuffer = function(builder) { - builder.startObject(12); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.TransferTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.TransferTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.TransferTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} recipientOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addRecipient = function(builder, recipientOffset) { - builder.addFieldOffset(7, recipientOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createRecipientVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startRecipientVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} messageSize - */ -Catapult.Buffers.TransferTransactionBuffer.addMessageSize = function(builder, messageSize) { - builder.addFieldInt16(8, messageSize, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numMosaics - */ -Catapult.Buffers.TransferTransactionBuffer.addNumMosaics = function(builder, numMosaics) { - builder.addFieldInt8(9, numMosaics, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} messageOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addMessage = function(builder, messageOffset) { - builder.addFieldOffset(10, messageOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicsOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addMosaics = function(builder, mosaicsOffset) { - builder.addFieldOffset(11, mosaicsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createMosaicsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startMosaicsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.endTransferTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.TransferTransactionBuffer.finishTransferTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/builders/AccountLinkTransaction.ts b/src/infrastructure/builders/AccountLinkTransaction.ts deleted file mode 100644 index 15cdb7738c..0000000000 --- a/src/infrastructure/builders/AccountLinkTransaction.ts +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AccountLinkTransaction - */ -import { Convert as convert } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import AccountLinkTransactionBufferPackage from '../buffers/AccountLinkTransactionBuffer'; -import AccountLinkTransactionSchema from '../schemas/AccountLinkTransactionSchema'; -import {VerifiableTransaction} from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - AccountLinkTransactionBuffer, -} = AccountLinkTransactionBufferPackage.Buffers; - -export class AccountLinkTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AccountLinkTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - remoteAccountKey: any; - linkAction: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.LINK_ACCOUNT; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRemoteAccountKey(remoteAccountKey) { - this.remoteAccountKey = convert.hexToUint8(remoteAccountKey); - return this; - } - - addLinkAction(linkAction) { - this.linkAction = linkAction; - return this; - } - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = AccountLinkTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = AccountLinkTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = AccountLinkTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = AccountLinkTransactionBuffer.createFeeVector(builder, this.maxFee); - const remoteAccountKeyVector = AccountLinkTransactionBuffer.createRemoteAccountKeyVector(builder, this.remoteAccountKey); - - AccountLinkTransactionBuffer.startAccountLinkTransactionBuffer(builder); - AccountLinkTransactionBuffer.addSize(builder, 153); - AccountLinkTransactionBuffer.addSignature(builder, signatureVector); - AccountLinkTransactionBuffer.addSigner(builder, signerVector); - AccountLinkTransactionBuffer.addVersion(builder, this.version); - AccountLinkTransactionBuffer.addType(builder, this.type); - AccountLinkTransactionBuffer.addFee(builder, feeVector); - AccountLinkTransactionBuffer.addDeadline(builder, deadlineVector); - AccountLinkTransactionBuffer.addRemoteAccountKey(builder, remoteAccountKeyVector); - AccountLinkTransactionBuffer.addLinkAction(builder, this.linkAction); - - // Calculate size - - const codedTransfer = AccountLinkTransactionBuffer.endAccountLinkTransactionBuffer(builder); - builder.finish(codedTransfer); - - const bytes = builder.asUint8Array(); - return new AccountLinkTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts b/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts deleted file mode 100644 index bd355c6b94..0000000000 --- a/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AccountRestrictionsAddressTransaction - */ -import { RawAddress as address } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import AccountRestrictionsAddressTransactionBufferPackage from '../buffers/AccountRestrictionsAddressTransactionBuffer'; -import AccountRestrictionsAddressModificationTransactionSchema from '../schemas/AccountRestrictionsAddressModificationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; -const { - AccountRestrictionsAddressTransactionBuffer, - RestrictionAddressModificationBuffer, -} = AccountRestrictionsAddressTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -export default class AccountRestrictionsAddressTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AccountRestrictionsAddressModificationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - restrictionType: any; - modifications: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.ACCOUNT_RESTRICTION_ADDRESS; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionType(restrictionType) { - this.restrictionType = restrictionType; - return this; - } - - addModifications(modifications) { - this.modifications = modifications; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create modifications - const modificationsArray: any = []; - this.modifications.forEach((modification) => { - const addressModificationVector = RestrictionAddressModificationBuffer - .createValueVector(builder, address.stringToAddress(modification.value)); - RestrictionAddressModificationBuffer.startRestrictionAddressModificationBuffer(builder); - RestrictionAddressModificationBuffer.addModificationType(builder, modification.type); - RestrictionAddressModificationBuffer.addValue(builder, addressModificationVector); - modificationsArray.push(RestrictionAddressModificationBuffer.endRestrictionAddressModificationBuffer(builder)); - }); - - // Create vectors - const signatureVector = AccountRestrictionsAddressTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = AccountRestrictionsAddressTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = AccountRestrictionsAddressTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = AccountRestrictionsAddressTransactionBuffer - .createFeeVector(builder, this.maxFee); - const modificationVector = AccountRestrictionsAddressTransactionBuffer - .createModificationsVector(builder, modificationsArray); - - AccountRestrictionsAddressTransactionBuffer.startAccountRestrictionsAddressTransactionBuffer(builder); - AccountRestrictionsAddressTransactionBuffer.addSize(builder, 122 + (26 * this.modifications.length)); - AccountRestrictionsAddressTransactionBuffer.addSignature(builder, signatureVector); - AccountRestrictionsAddressTransactionBuffer.addSigner(builder, signerVector); - AccountRestrictionsAddressTransactionBuffer.addVersion(builder, this.version); - AccountRestrictionsAddressTransactionBuffer.addType(builder, this.type); - AccountRestrictionsAddressTransactionBuffer.addFee(builder, feeVector); - AccountRestrictionsAddressTransactionBuffer.addDeadline(builder, deadlineVector); - AccountRestrictionsAddressTransactionBuffer.addRestrictionType(builder, this.restrictionType); - AccountRestrictionsAddressTransactionBuffer.addModificationCount(builder, this.modifications.length); - AccountRestrictionsAddressTransactionBuffer.addModifications(builder, modificationVector); - - // Calculate size - const codedAccountRestrictionsAddress = - AccountRestrictionsAddressTransactionBuffer.endAccountRestrictionsAddressTransactionBuffer(builder); - builder.finish(codedAccountRestrictionsAddress); - - const bytes = builder.asUint8Array(); - - return new AccountRestrictionsAddressTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts b/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts deleted file mode 100644 index 6973e8ccc4..0000000000 --- a/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AccountRestrictionsEntityTypeTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import AccountRestrictionsEntityTypeTransactionBufferPackage from '../buffers/AccountRestrictionsEntityTypeTransactionBuffer'; -import AccountRestrictionsEntityTypeModificationTransactionSchema from '../schemas/AccountRestrictionsEntityTypeModificationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - AccountRestrictionsEntityTypeTransactionBuffer, - RestrictionEntityTypeModificationBuffer, -} = AccountRestrictionsEntityTypeTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -export default class AccountRestrictionsEntityTypeTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AccountRestrictionsEntityTypeModificationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - restrictionType: any; - modifications: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.ACCOUNT_RESTRICTION_OPERATION; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionType(restrictionType) { - this.restrictionType = restrictionType; - return this; - } - - addModifications(modifications) { - this.modifications = modifications; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create modifications - const modificationsArray: any = []; - this.modifications.forEach((modification) => { - RestrictionEntityTypeModificationBuffer.startRestrictionEntityTypeModificationBuffer(builder); - RestrictionEntityTypeModificationBuffer.addModificationType(builder, modification.type); - RestrictionEntityTypeModificationBuffer.addValue(builder, modification.value); - modificationsArray.push(RestrictionEntityTypeModificationBuffer.endRestrictionEntityTypeModificationBuffer(builder)); - }); - - // Create vectors - const signatureVector = AccountRestrictionsEntityTypeTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = AccountRestrictionsEntityTypeTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = AccountRestrictionsEntityTypeTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = AccountRestrictionsEntityTypeTransactionBuffer - .createFeeVector(builder, this.maxFee); - const modificationVector = AccountRestrictionsEntityTypeTransactionBuffer - .createModificationsVector(builder, modificationsArray); - - AccountRestrictionsEntityTypeTransactionBuffer.startAccountRestrictionsEntityTypeTransactionBuffer(builder); - AccountRestrictionsEntityTypeTransactionBuffer.addSize(builder, 122 + (3 * this.modifications.length)); - AccountRestrictionsEntityTypeTransactionBuffer.addSignature(builder, signatureVector); - AccountRestrictionsEntityTypeTransactionBuffer.addSigner(builder, signerVector); - AccountRestrictionsEntityTypeTransactionBuffer.addVersion(builder, this.version); - AccountRestrictionsEntityTypeTransactionBuffer.addType(builder, this.type); - AccountRestrictionsEntityTypeTransactionBuffer.addFee(builder, feeVector); - AccountRestrictionsEntityTypeTransactionBuffer.addDeadline(builder, deadlineVector); - AccountRestrictionsEntityTypeTransactionBuffer.addRestrictionType(builder, this.restrictionType); - AccountRestrictionsEntityTypeTransactionBuffer.addModificationCount(builder, this.modifications.length); - AccountRestrictionsEntityTypeTransactionBuffer.addModifications(builder, modificationVector); - - // Calculate size - const codedAccountRestrictionsAddress = AccountRestrictionsEntityTypeTransactionBuffer - .endAccountRestrictionsEntityTypeTransactionBuffer(builder); - builder.finish(codedAccountRestrictionsAddress); - - const bytes = builder.asUint8Array(); - - return new AccountRestrictionsEntityTypeTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts b/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts deleted file mode 100644 index da9338deb4..0000000000 --- a/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AccountRestrictionsMosaicTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import AccountRestrictionsMosaicTransactionBufferPackage from '../buffers/AccountRestrictionsMosaicTransactionBuffer'; -import AccountRestrictionsMosaicModificationTransactionSchema from '../schemas/AccountRestrictionsMosaicModificationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - AccountRestrictionsMosaicTransactionBuffer, - RestrictionMosaicModificationBuffer, -} = AccountRestrictionsMosaicTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -export default class AccountRestrictionsMosaicTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AccountRestrictionsMosaicModificationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - restrictionType: any; - modifications: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.ACCOUNT_RESTRICTION_MOSAIC; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionType(restrictionType) { - this.restrictionType = restrictionType; - return this; - } - - addModifications(modifications) { - this.modifications = modifications; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create modifications - const modificationsArray: any = []; - this.modifications.forEach((modification) => { - const addressModificationVector = RestrictionMosaicModificationBuffer - .createValueVector(builder, modification.value); - RestrictionMosaicModificationBuffer.startRestrictionMosaicModificationBuffer(builder); - RestrictionMosaicModificationBuffer.addModificationType(builder, modification.type); - RestrictionMosaicModificationBuffer.addValue(builder, addressModificationVector); - modificationsArray.push(RestrictionMosaicModificationBuffer.endRestrictionMosaicModificationBuffer(builder)); - }); - - // Create vectors - const signatureVector = AccountRestrictionsMosaicTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = AccountRestrictionsMosaicTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = AccountRestrictionsMosaicTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = AccountRestrictionsMosaicTransactionBuffer - .createFeeVector(builder, this.maxFee); - const modificationVector = AccountRestrictionsMosaicTransactionBuffer - .createModificationsVector(builder, modificationsArray); - - AccountRestrictionsMosaicTransactionBuffer.startAccountRestrictionsMosaicTransactionBuffer(builder); - AccountRestrictionsMosaicTransactionBuffer.addSize(builder, 122 + (9 * this.modifications.length)); - AccountRestrictionsMosaicTransactionBuffer.addSignature(builder, signatureVector); - AccountRestrictionsMosaicTransactionBuffer.addSigner(builder, signerVector); - AccountRestrictionsMosaicTransactionBuffer.addVersion(builder, this.version); - AccountRestrictionsMosaicTransactionBuffer.addType(builder, this.type); - AccountRestrictionsMosaicTransactionBuffer.addFee(builder, feeVector); - AccountRestrictionsMosaicTransactionBuffer.addDeadline(builder, deadlineVector); - AccountRestrictionsMosaicTransactionBuffer.addRestrictionType(builder, this.restrictionType); - AccountRestrictionsMosaicTransactionBuffer.addModificationCount(builder, this.modifications.length); - AccountRestrictionsMosaicTransactionBuffer.addModifications(builder, modificationVector); - - // Calculate size - const codedAccountRestrictionsMosaic = AccountRestrictionsMosaicTransactionBuffer.endAccountRestrictionsMosaicTransactionBuffer(builder); - builder.finish(codedAccountRestrictionsMosaic); - - const bytes = builder.asUint8Array(); - - return new AccountRestrictionsMosaicTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/AddressAliasTransaction.ts b/src/infrastructure/builders/AddressAliasTransaction.ts deleted file mode 100644 index bbbda06fb9..0000000000 --- a/src/infrastructure/builders/AddressAliasTransaction.ts +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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 { RawAddress as addressLibrary } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import AddressAliasTransactionBufferPackage from '../buffers/AddressAliasTransactionBuffer'; -import AddressAliasTransactionSchema from '../schemas/AddressAliasTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - AddressAliasTransactionBuffer, -} = AddressAliasTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -/** - * @module transactions/AddressAliasTransaction - */ -export class AddressAliasTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AddressAliasTransactionSchema); - } -} -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - address: any; - namespaceId: any; - aliasAction: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.ADDRESS_ALIAS; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addAliasAction(aliasAction) { - this.aliasAction = aliasAction; - return this; - } - - addNamespaceId(namespaceId) { - this.namespaceId = namespaceId; - return this; - } - - addAddress(address) { - this.address = addressLibrary.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.maxFee); - 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.addAliasAction(builder, this.aliasAction); - 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); - } -} diff --git a/src/infrastructure/builders/AggregateTransaction.ts b/src/infrastructure/builders/AggregateTransaction.ts deleted file mode 100644 index 8aae5a5e28..0000000000 --- a/src/infrastructure/builders/AggregateTransaction.ts +++ /dev/null @@ -1,151 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AggregateTransaction - */ -import { SignSchema } from '../../core/crypto'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import AggregateTransactionBufferPackage from '../buffers/AggregateTransactionBuffer'; -import AggregateTransactionSchema from '../schemas/AggregateTransactionSchema'; -import { CosignatureTransaction} from './CosignatureTransaction'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - AggregateTransactionBuffer, -} = AggregateTransactionBufferPackage.Buffers; - -export class AggregateTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AggregateTransactionSchema); - } - - signTransactionWithCosigners(initializer, cosigners, generationHash, signSchema: SignSchema = SignSchema.SHA3) { - const signedTransaction = this.signTransaction(initializer, generationHash, signSchema); - cosigners.forEach((cosigner) => { - const signatureTransaction = new CosignatureTransaction(signedTransaction.hash); - const signatureCosignTransaction = signatureTransaction.signCosignatoriesTransaction(cosigner, signSchema); - signedTransaction.payload = signedTransaction.payload + - signatureCosignTransaction.signer + signatureCosignTransaction.signature; - }); - - // Calculate new size - const size = `00000000${(signedTransaction.payload.length / 2).toString(16)}`; - const formatedSize = size.substr(size.length - 8, size.length); - const littleEndianSize = formatedSize.substr(6, 2) + formatedSize.substr(4, 2) + - formatedSize.substr(2, 2) + formatedSize.substr(0, 2); - - signedTransaction.payload = littleEndianSize + - signedTransaction.payload.substr(8, signedTransaction.payload.length - 8); - - return signedTransaction; - } - - signTransactionGivenSignatures(initializer, cosignedSignedTransactions, generationHash, signSchema = SignSchema.SHA3) { - const signedTransaction = this.signTransaction(initializer, generationHash, signSchema); - cosignedSignedTransactions.forEach((cosignedTransaction) => { - signedTransaction.payload = signedTransaction.payload + cosignedTransaction.signer + cosignedTransaction.signature; - }); - - // Calculate new size - const size = `00000000${(signedTransaction.payload.length / 2).toString(16)}`; - const formatedSize = size.substr(size.length - 8, size.length); - const littleEndianSize = formatedSize.substr(6, 2) + formatedSize.substr(4, 2) + - formatedSize.substr(2, 2) + formatedSize.substr(0, 2); - - signedTransaction.payload = littleEndianSize + - signedTransaction.payload.substr(8, signedTransaction.payload.length - 8); - - return signedTransaction; - } -} -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - transactions: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.AGGREGATE_COMPLETE; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addTransactions(transactions) { - let tmp = []; - for (let i = 0; i < transactions.length; ++i) { - tmp = tmp.concat(transactions[i]); - } - - this.transactions = tmp; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = AggregateTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)) - .map(Number.prototype.valueOf, 0)); - const signerVector = AggregateTransactionBuffer - .createSignerVector(builder, Array(...Array(32)) - .map(Number.prototype.valueOf, 0)); - const deadlineVector = AggregateTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = AggregateTransactionBuffer.createFeeVector(builder, this.maxFee); - const modificationsVector = AggregateTransactionBuffer.createTransactionsVector(builder, this.transactions); - - AggregateTransactionBuffer.startAggregateTransactionBuffer(builder); - AggregateTransactionBuffer.addSize(builder, 120 + 4 + this.transactions.length); - AggregateTransactionBuffer.addSignature(builder, signatureVector); - AggregateTransactionBuffer.addSigner(builder, signerVector); - AggregateTransactionBuffer.addVersion(builder, this.version); - AggregateTransactionBuffer.addType(builder, this.type); - AggregateTransactionBuffer.addFee(builder, feeVector); - AggregateTransactionBuffer.addDeadline(builder, deadlineVector); - AggregateTransactionBuffer.addTransactionsSize(builder, 0 !== this.transactions.length ? this.transactions.length : 4294967296); - AggregateTransactionBuffer.addTransactions(builder, modificationsVector); - - // Calculate size - const codedAggregate = AggregateTransactionBuffer.endAggregateTransactionBuffer(builder); - builder.finish(codedAggregate); - - const bytes = builder.asUint8Array(); - return new AggregateTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/CosignatureTransaction.ts b/src/infrastructure/builders/CosignatureTransaction.ts deleted file mode 100644 index 717041f910..0000000000 --- a/src/infrastructure/builders/CosignatureTransaction.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 { Convert as convert } from '../../core/format/Convert'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -/** - * @module transactions/AggregateSignatureTransaction - * @version 1.0.0 - */ -export class CosignatureTransaction extends VerifiableTransaction { - constructor(hash) { - super(convert.hexToUint8(hash), undefined); - } -} diff --git a/src/infrastructure/builders/Deadline.ts b/src/infrastructure/builders/Deadline.ts deleted file mode 100644 index 3b37923c5a..0000000000 --- a/src/infrastructure/builders/Deadline.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 { RawUInt64 as uint64 } from '../../core/format'; - -export default function deadline(deadlineParam) { - const NetworkTime = (new Date()).getTime() - 1459468800000; - const deadlineValue = deadlineParam || 60 * 60 * 1000; - return uint64.fromUint(deadlineValue + NetworkTime); -} \ No newline at end of file diff --git a/src/infrastructure/builders/HashLockTransaction.ts b/src/infrastructure/builders/HashLockTransaction.ts deleted file mode 100644 index 538454d3ea..0000000000 --- a/src/infrastructure/builders/HashLockTransaction.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/HashLockTransaction - */ -import { Convert as convert } from '../../core/format'; -import * as HashLockTransactionBufferPackage from '../buffers/HashLockTransactionBuffer'; -import HashLockTransactionSchema from '../schemas/HashLockTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; -import { TransactionType } from '../../model/transaction/TransactionType'; - -import {flatbuffers} from 'flatbuffers'; - -const { - HashLockTransactionBuffer, -} = HashLockTransactionBufferPackage.default.Buffers; - -export default class HashLockTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, HashLockTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - mosaicAmount: any; - duration: any; - hash: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.LOCK; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - addMosaicAmount(mosaicAmount) { - this.mosaicAmount = mosaicAmount; - return this; - } - - addDuration(duration) { - this.duration = duration; - return this; - } - - addHash(hash) { - this.hash = hash; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = HashLockTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = HashLockTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = HashLockTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = HashLockTransactionBuffer.createFeeVector(builder, this.maxFee); - const mosaicIdVector = HashLockTransactionBuffer.createMosaicIdVector(builder, this.mosaicId); - const mosaicAmountVector = HashLockTransactionBuffer.createMosaicAmountVector(builder, this.mosaicAmount); - const durationVector = HashLockTransactionBuffer.createDurationVector(builder, this.duration); - const byteHash = convert.hexToUint8(this.hash); - const hashVector = HashLockTransactionBuffer.createHashVector(builder, byteHash); - - HashLockTransactionBuffer.startHashLockTransactionBuffer(builder); - HashLockTransactionBuffer.addSize(builder, 176); - HashLockTransactionBuffer.addSignature(builder, signatureVector); - HashLockTransactionBuffer.addSigner(builder, signerVector); - HashLockTransactionBuffer.addVersion(builder, this.version); - HashLockTransactionBuffer.addType(builder, this.type); - HashLockTransactionBuffer.addFee(builder, feeVector); - HashLockTransactionBuffer.addDeadline(builder, deadlineVector); - HashLockTransactionBuffer.addMosaicId(builder, mosaicIdVector); - HashLockTransactionBuffer.addMosaicAmount(builder, mosaicAmountVector); - HashLockTransactionBuffer.addDuration(builder, durationVector); - HashLockTransactionBuffer.addHash(builder, hashVector); - - const codedHashLock = HashLockTransactionBuffer.endHashLockTransactionBuffer(builder); - builder.finish(codedHashLock); - - const bytes = builder.asUint8Array(); - return new HashLockTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/MosaicAddressRestrictionTransaction.ts b/src/infrastructure/builders/MosaicAddressRestrictionTransaction.ts deleted file mode 100644 index 0b214c496b..0000000000 --- a/src/infrastructure/builders/MosaicAddressRestrictionTransaction.ts +++ /dev/null @@ -1,146 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/MosaicAddressRestrictionTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicAddressRestrictionTransactionBufferPackage from '../buffers/MosaicAddressRestrictionTransactionBuffer'; -import MosaicAddressRestrictionTransactionSchema from '../schemas/MosaicAddressRestrictionTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; -import { RawAddress } from '../../core/format'; - -const { - MosaicAddressRestrictionTransactionBuffer, -} = MosaicAddressRestrictionTransactionBufferPackage.Buffers; - -export default class MosaicAddressRestrictionTransaction extends VerifiableTransaction { - constructor(bytes, schema) { - super(bytes, schema); - } -} -// tslint:disable-next-line: max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - restrictionKey: any; - targetAddress: any; - previousRestrictionValue: any; - newRestrictionValue: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_ADDRESS_RESTRICTION; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionKey(restrictionKey) { - this.restrictionKey = restrictionKey; - return this; - } - - addTargetAddress(targetAddress) { - this.targetAddress = RawAddress.stringToAddress(targetAddress); - return this; - } - - addPreviousRestrictionValue(previousRestrictionValue) { - this.previousRestrictionValue = previousRestrictionValue; - return this; - } - - addNewRestrictionValue(newRestrictionValue) { - this.newRestrictionValue = newRestrictionValue; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicAddressRestrictionTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicAddressRestrictionTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicAddressRestrictionTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicAddressRestrictionTransactionBuffer - .createFeeVector(builder, this.maxFee); - const mosaicIdVector = MosaicAddressRestrictionTransactionBuffer - .createMosaicIdVector(builder, this.mosaicId); - const restrictionKeyVector = MosaicAddressRestrictionTransactionBuffer - .createRestrictionKeyVector(builder, this.restrictionKey); - const targetAddressVector = MosaicAddressRestrictionTransactionBuffer - .createTargetAddressVector(builder, this.targetAddress); - const previousRestrictionValueVector = MosaicAddressRestrictionTransactionBuffer - .createPreviousRestrictionValueVector(builder, this.previousRestrictionValue); - const newRestrictionValueVector = MosaicAddressRestrictionTransactionBuffer - .createNewRestrictionValueVector(builder, this.newRestrictionValue); - - MosaicAddressRestrictionTransactionBuffer.startMosaicAddressRestrictionTransactionBuffer(builder); - MosaicAddressRestrictionTransactionBuffer.addSize(builder, 169); - MosaicAddressRestrictionTransactionBuffer.addSignature(builder, signatureVector); - MosaicAddressRestrictionTransactionBuffer.addSigner(builder, signerVector); - MosaicAddressRestrictionTransactionBuffer.addVersion(builder, this.version); - MosaicAddressRestrictionTransactionBuffer.addType(builder, this.type); - MosaicAddressRestrictionTransactionBuffer.addFee(builder, feeVector); - MosaicAddressRestrictionTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicAddressRestrictionTransactionBuffer.addMosaicId(builder, mosaicIdVector); - MosaicAddressRestrictionTransactionBuffer.addRestrictionKey(builder, restrictionKeyVector); - MosaicAddressRestrictionTransactionBuffer.addTargetAddress(builder, targetAddressVector); - MosaicAddressRestrictionTransactionBuffer.addPreviousRestrictionValue(builder, previousRestrictionValueVector); - MosaicAddressRestrictionTransactionBuffer.addNewRestrictionValue(builder, newRestrictionValueVector); - - // Calculate size - - const codedMosaicAddressRestriction = - MosaicAddressRestrictionTransactionBuffer.endMosaicAddressRestrictionTransactionBuffer(builder); - builder.finish(codedMosaicAddressRestriction); - - const bytes = builder.asUint8Array(); - - const schema = MosaicAddressRestrictionTransactionSchema; - return new MosaicAddressRestrictionTransaction(bytes, schema); - } -} diff --git a/src/infrastructure/builders/MosaicAliasTransaction.ts b/src/infrastructure/builders/MosaicAliasTransaction.ts deleted file mode 100644 index 7d3abcb45d..0000000000 --- a/src/infrastructure/builders/MosaicAliasTransaction.ts +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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 { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicAliasTransactionBufferPackage from '../buffers/MosaicAliasTransactionBuffer'; -import MosaicAliasTransactionSchema from '../schemas/MosaicAliasTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - MosaicAliasTransactionBuffer, -} = MosaicAliasTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -/** - * @module transactions/MosaicAliasTransaction - */ -export default class MosaicAliasTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, MosaicAliasTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - aliasAction: any; - namespaceId: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_ALIAS; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addAliasAction(aliasAction) { - this.aliasAction = aliasAction; - return this; - } - - addNamespaceId(namespaceId) { - this.namespaceId = namespaceId; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicAliasTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicAliasTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicAliasTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicAliasTransactionBuffer - .createFeeVector(builder, this.maxFee); - const namespaceIdVector = MosaicAliasTransactionBuffer - .createNamespaceIdVector(builder, this.namespaceId); - const mosaicIdVector = MosaicAliasTransactionBuffer - .createMosaicIdVector(builder, this.mosaicId); - - MosaicAliasTransactionBuffer.startMosaicAliasTransactionBuffer(builder); - MosaicAliasTransactionBuffer.addSize(builder, 137); - MosaicAliasTransactionBuffer.addSignature(builder, signatureVector); - MosaicAliasTransactionBuffer.addSigner(builder, signerVector); - MosaicAliasTransactionBuffer.addVersion(builder, this.version); - MosaicAliasTransactionBuffer.addType(builder, this.type); - MosaicAliasTransactionBuffer.addFee(builder, feeVector); - MosaicAliasTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicAliasTransactionBuffer.addAliasAction(builder, this.aliasAction); - MosaicAliasTransactionBuffer.addNamespaceId(builder, namespaceIdVector); - MosaicAliasTransactionBuffer.addMosaicId(builder, mosaicIdVector); - - // Calculate size - const codedMosaicChangeSupply = MosaicAliasTransactionBuffer.endMosaicAliasTransactionBuffer(builder); - builder.finish(codedMosaicChangeSupply); - - const bytes = builder.asUint8Array(); - - return new MosaicAliasTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/MosaicCreationTransaction.ts b/src/infrastructure/builders/MosaicCreationTransaction.ts deleted file mode 100644 index d74ba21660..0000000000 --- a/src/infrastructure/builders/MosaicCreationTransaction.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/MosaicCreationTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicCreationTransactionBufferPackage from '../buffers/MosaicCreationTransactionBuffer'; -import { - schema as MosaicCreationTransactionSchema, - schemaNoDuration as MosaicCreationTransactionSchemaNoDuration, -} from '../schemas/MosaicCreationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - MosaicCreationTransactionBuffer, -} = MosaicCreationTransactionBufferPackage.Buffers; - -export default class MosaicCreationTransaction extends VerifiableTransaction { - constructor(bytes, schema) { - super(bytes, schema); - } -} -// tslint:disable-next-line: max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - flags: any; - nonce: any; - divisibility: any; - duration: any; - constructor() { - this.flags = 0; - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_DEFINITION; - this.nonce = 0; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addNonce(nonce) { - this.nonce = nonce; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addDuration(duration) { - this.duration = duration; - return this; - } - - addDivisibility(divisibility) { - this.divisibility = divisibility; - return this; - } - - addSupplyMutable() { - this.flags += 1; - return this; - } - - addTransferability() { - this.flags += 2; - return this; - } - - addRestrictable() { - this.flags += 4; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicCreationTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicCreationTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicCreationTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicCreationTransactionBuffer - .createFeeVector(builder, this.maxFee); - const nonceVector = MosaicCreationTransactionBuffer - .createNonceVector(builder, this.nonce); - const mosaicIdVector = MosaicCreationTransactionBuffer - .createMosaicIdVector(builder, this.mosaicId); - - const durationVector = MosaicCreationTransactionBuffer - .createDurationVector(builder, this.duration); - - const durationProvided = 0 < this.duration.length; - - MosaicCreationTransactionBuffer.startMosaicCreationTransactionBuffer(builder); - MosaicCreationTransactionBuffer.addSize(builder, durationProvided ? 144 : 135); - MosaicCreationTransactionBuffer.addSignature(builder, signatureVector); - MosaicCreationTransactionBuffer.addSigner(builder, signerVector); - MosaicCreationTransactionBuffer.addVersion(builder, this.version); - MosaicCreationTransactionBuffer.addType(builder, this.type); - MosaicCreationTransactionBuffer.addFee(builder, feeVector); - MosaicCreationTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicCreationTransactionBuffer.addNonce(builder, nonceVector); - MosaicCreationTransactionBuffer.addMosaicId(builder, mosaicIdVector); - MosaicCreationTransactionBuffer.addNumOptionalProperties(builder, durationProvided ? 1 : 0); - MosaicCreationTransactionBuffer.addFlags(builder, this.flags); - - MosaicCreationTransactionBuffer.addDivisibility(builder, this.divisibility); - - if (durationProvided) { - MosaicCreationTransactionBuffer.addIndicateDuration(builder, 2); - MosaicCreationTransactionBuffer.addDuration(builder, durationVector); - } - - // Calculate size - - const codedMosaicCreation = MosaicCreationTransactionBuffer.endMosaicCreationTransactionBuffer(builder); - builder.finish(codedMosaicCreation); - - const bytes = builder.asUint8Array(); - - const schema = durationProvided ? MosaicCreationTransactionSchema : MosaicCreationTransactionSchemaNoDuration; - return new MosaicCreationTransaction(bytes, schema); - } -} diff --git a/src/infrastructure/builders/MosaicGlobalRestrictionTransaction.ts b/src/infrastructure/builders/MosaicGlobalRestrictionTransaction.ts deleted file mode 100644 index 608cc0f2c0..0000000000 --- a/src/infrastructure/builders/MosaicGlobalRestrictionTransaction.ts +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/MosaicGlobalRestrictionTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicGlobalRestrictionTransactionBufferPackage from '../buffers/MosaicGlobalRestrictionTransactionBuffer'; -import MosaicGlobalRestrictionTransactionSchema from '../schemas/MosaicGlobalRestrictionTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - MosaicGlobalRestrictionTransactionBuffer, -} = MosaicGlobalRestrictionTransactionBufferPackage.Buffers; - -export default class MosaicGlobalRestrictionTransaction extends VerifiableTransaction { - constructor(bytes, schema) { - super(bytes, schema); - } -} -// tslint:disable-next-line: max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - referenceMosaicId: any; - restrictionKey: any; - previousRestrictionValue: any; - previousRestrictionType: any; - newRestrictionValue: any; - newRestrictionType: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_GLOBAL_RESTRICTION; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionKey(restrictionKey) { - this.restrictionKey = restrictionKey; - return this; - } - - addPreviousRestrictionValue(previousRestrictionValue) { - this.previousRestrictionValue = previousRestrictionValue; - return this; - } - - addPreviousRestrictionType(previousRestrictionType) { - this.previousRestrictionType = previousRestrictionType; - return this; - } - - addNewRestrictionValue(newRestrictionValue) { - this.newRestrictionValue = newRestrictionValue; - return this; - } - - addNewRestrictionType(newRestrictionType) { - this.newRestrictionType = newRestrictionType; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - addReferenceMosaicId(referenceMosaicId) { - this.referenceMosaicId = referenceMosaicId; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicGlobalRestrictionTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicGlobalRestrictionTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicGlobalRestrictionTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicGlobalRestrictionTransactionBuffer - .createFeeVector(builder, this.maxFee); - const mosaicIdVector = MosaicGlobalRestrictionTransactionBuffer - .createMosaicIdVector(builder, this.mosaicId); - const referenceMosaicIdVector = MosaicGlobalRestrictionTransactionBuffer - .createReferenceMosaicIdVector(builder, this.referenceMosaicId); - const restrictionKeyVector = MosaicGlobalRestrictionTransactionBuffer - .createRestrictionKeyVector(builder, this.restrictionKey); - const previousRestrictionValueVector = MosaicGlobalRestrictionTransactionBuffer - .createPreviousRestrictionValueVector(builder, this.previousRestrictionValue); - const newRestrictionValueVector = MosaicGlobalRestrictionTransactionBuffer - .createNewRestrictionValueVector(builder, this.newRestrictionValue); - - MosaicGlobalRestrictionTransactionBuffer.startMosaicGlobalRestrictionTransactionBuffer(builder); - MosaicGlobalRestrictionTransactionBuffer.addSize(builder, 162); - MosaicGlobalRestrictionTransactionBuffer.addSignature(builder, signatureVector); - MosaicGlobalRestrictionTransactionBuffer.addSigner(builder, signerVector); - MosaicGlobalRestrictionTransactionBuffer.addVersion(builder, this.version); - MosaicGlobalRestrictionTransactionBuffer.addType(builder, this.type); - MosaicGlobalRestrictionTransactionBuffer.addFee(builder, feeVector); - MosaicGlobalRestrictionTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicGlobalRestrictionTransactionBuffer.addMosaicId(builder, mosaicIdVector); - MosaicGlobalRestrictionTransactionBuffer.addReferenceMosaicId(builder, referenceMosaicIdVector); - MosaicGlobalRestrictionTransactionBuffer.addRestrictionKey(builder, restrictionKeyVector); - MosaicGlobalRestrictionTransactionBuffer.addPreviousRestrictionValue(builder, previousRestrictionValueVector); - MosaicGlobalRestrictionTransactionBuffer.addPreviousRestrictionType(builder, this.previousRestrictionType); - MosaicGlobalRestrictionTransactionBuffer.addNewRestrictionValue(builder, newRestrictionValueVector); - MosaicGlobalRestrictionTransactionBuffer.addNewRestrictionType(builder, this.newRestrictionType); - - // Calculate size - - const codedMosaicGlobalRestriction = - MosaicGlobalRestrictionTransactionBuffer.endMosaicGlobalRestrictionTransactionBuffer(builder); - builder.finish(codedMosaicGlobalRestriction); - - const bytes = builder.asUint8Array(); - - const schema = MosaicGlobalRestrictionTransactionSchema; - return new MosaicGlobalRestrictionTransaction(bytes, schema); - } -} diff --git a/src/infrastructure/builders/MosaicSupplyChangeTransaction.ts b/src/infrastructure/builders/MosaicSupplyChangeTransaction.ts deleted file mode 100644 index cfff8db53c..0000000000 --- a/src/infrastructure/builders/MosaicSupplyChangeTransaction.ts +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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 { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicSupplyChangeTransactionBufferPackage from '../buffers/MosaicSupplyChangeTransactionBuffer'; -import MosaicSupplyChangeTransactionSchema from '../schemas/MosaicSupplyChangeTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - MosaicSupplyChangeTransactionBuffer, -} = MosaicSupplyChangeTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -/** - * @module transactions/MosaicSupplyChangeTransaction - */ -export default class MosaicSupplyChangeTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, MosaicSupplyChangeTransactionSchema); - } -} -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - direction: any; - delta: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_SUPPLY_CHANGE; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - addDirection(direction) { - this.direction = direction; - return this; - } - - addDelta(delta) { - this.delta = delta; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicSupplyChangeTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicSupplyChangeTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicSupplyChangeTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicSupplyChangeTransactionBuffer - .createFeeVector(builder, this.maxFee); - const mosaicIdVector = MosaicSupplyChangeTransactionBuffer - .createFeeVector(builder, this.mosaicId); - const deltaVector = MosaicSupplyChangeTransactionBuffer - .createFeeVector(builder, this.delta); - - MosaicSupplyChangeTransactionBuffer.startMosaicSupplyChangeTransactionBuffer(builder); - MosaicSupplyChangeTransactionBuffer.addSize(builder, 137); - MosaicSupplyChangeTransactionBuffer.addSignature(builder, signatureVector); - MosaicSupplyChangeTransactionBuffer.addSigner(builder, signerVector); - MosaicSupplyChangeTransactionBuffer.addVersion(builder, this.version); - MosaicSupplyChangeTransactionBuffer.addType(builder, this.type); - MosaicSupplyChangeTransactionBuffer.addFee(builder, feeVector); - MosaicSupplyChangeTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicSupplyChangeTransactionBuffer.addMosaicId(builder, mosaicIdVector); - MosaicSupplyChangeTransactionBuffer.addDirection(builder, this.direction); - MosaicSupplyChangeTransactionBuffer.addDelta(builder, deltaVector); - - // Calculate size - const codedMosaicChangeSupply = MosaicSupplyChangeTransactionBuffer.endMosaicSupplyChangeTransactionBuffer(builder); - builder.finish(codedMosaicChangeSupply); - - const bytes = builder.asUint8Array(); - return new MosaicSupplyChangeTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/MultisigModificationTransaction.ts b/src/infrastructure/builders/MultisigModificationTransaction.ts deleted file mode 100644 index a11dbfdeb5..0000000000 --- a/src/infrastructure/builders/MultisigModificationTransaction.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* - * 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 { Convert as convert } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import MultisigModificationTransactionBufferPackage from '../buffers/MultisigModificationTransactionBuffer'; -import MultisigModificationTransactionSchema from '../schemas/MultisigModificationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - MultisigModificationTransactionBuffer, - CosignatoryModificationBuffer, -} = MultisigModificationTransactionBufferPackage.Buffers; - -/** - * @module transactions/MultisigModificationTransaction - */ -export default class MultisigModificationTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, MultisigModificationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - minRemovalDelta: any; - minApprovalDelta: any; - modifications: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MODIFY_MULTISIG_ACCOUNT; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addMinRemovalDelta(minRemovalDelta) { - this.minRemovalDelta = minRemovalDelta; - return this; - } - - addMinApprovalDelta(minApprovalDelta) { - this.minApprovalDelta = minApprovalDelta; - return this; - } - - addModifications(modifications) { - this.modifications = modifications; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create modifications - const modificationsArray: any = []; - this.modifications.forEach((modification) => { - const cosignatoryPublicKeyVector = CosignatoryModificationBuffer - .createCosignatoryPublicKeyVector(builder, convert.hexToUint8(modification.cosignatoryPublicKey)); - CosignatoryModificationBuffer.startCosignatoryModificationBuffer(builder); - CosignatoryModificationBuffer.addType(builder, modification.type); - CosignatoryModificationBuffer.addCosignatoryPublicKey(builder, cosignatoryPublicKeyVector); - modificationsArray.push(CosignatoryModificationBuffer.endCosignatoryModificationBuffer(builder)); - }); - - // Create vectors - const signatureVector = MultisigModificationTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MultisigModificationTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MultisigModificationTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MultisigModificationTransactionBuffer - .createFeeVector(builder, this.maxFee); - const modificationsVector = MultisigModificationTransactionBuffer - .createModificationsVector(builder, modificationsArray); - - MultisigModificationTransactionBuffer.startMultisigModificationTransactionBuffer(builder); - MultisigModificationTransactionBuffer.addSize(builder, 123 + (33 * this.modifications.length)); - MultisigModificationTransactionBuffer.addSignature(builder, signatureVector); - MultisigModificationTransactionBuffer.addSigner(builder, signerVector); - MultisigModificationTransactionBuffer.addVersion(builder, this.version); - MultisigModificationTransactionBuffer.addType(builder, this.type); - MultisigModificationTransactionBuffer.addFee(builder, feeVector); - MultisigModificationTransactionBuffer.addDeadline(builder, deadlineVector); - MultisigModificationTransactionBuffer.addMinRemovalDelta(builder, this.minRemovalDelta); - MultisigModificationTransactionBuffer.addMinApprovalDelta(builder, this.minApprovalDelta); - MultisigModificationTransactionBuffer.addNumModifications(builder, this.modifications.length); - MultisigModificationTransactionBuffer.addModifications(builder, modificationsVector); - - // Calculate size - const codedMultisigAggregate = MultisigModificationTransactionBuffer - .endMultisigModificationTransactionBuffer(builder); - builder.finish(codedMultisigAggregate); - - const bytes = builder.asUint8Array(); - return new MultisigModificationTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/NamespaceCreationTransaction.ts b/src/infrastructure/builders/NamespaceCreationTransaction.ts deleted file mode 100644 index 0cf2ba5d67..0000000000 --- a/src/infrastructure/builders/NamespaceCreationTransaction.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/NamespaceCreationTransaction - */ -import { Convert as convert } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import * as NamespaceCreationTransactionBufferPackage from '../buffers/NamespaceCreationTransactionBuffer'; -import NamespaceCreationTransactionSchema from '../schemas/NamespaceCreationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - NamespaceCreationTransactionBuffer, -} = NamespaceCreationTransactionBufferPackage.default.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -export default class NamespaceCreationTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, NamespaceCreationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - namespaceType: any; - duration: any; - parentId: any; - namespaceId: any; - namespaceName: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.REGISTER_NAMESPACE; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addNamespaceType(namespaceType) { - this.namespaceType = namespaceType; - return this; - } - - addDuration(duration) { - this.duration = duration; - return this; - } - - addParentId(parentId) { - this.parentId = parentId; - return this; - } - - addNamespaceId(namespaceId) { - this.namespaceId = namespaceId; - return this; - } - - addNamespaceName(namespaceName) { - this.namespaceName = namespaceName; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - const namespaceNameLength = convert.utf8ToHex(this.namespaceName).length / 2; - - // create vectors - const signatureVector = NamespaceCreationTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = NamespaceCreationTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = NamespaceCreationTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = NamespaceCreationTransactionBuffer - .createFeeVector(builder, this.maxFee); - const parentIdVector = 1 === this.namespaceType ? this.parentId : this.duration; - const durationParentIdVector = NamespaceCreationTransactionBuffer - .createDurationParentIdVector(builder, parentIdVector); - const namespaceIdVector = NamespaceCreationTransactionBuffer - .createNamespaceIdVector(builder, this.namespaceId); - - const name = builder.createString(this.namespaceName); - - NamespaceCreationTransactionBuffer.startNamespaceCreationTransactionBuffer(builder); - NamespaceCreationTransactionBuffer.addSize(builder, 138 + namespaceNameLength); - NamespaceCreationTransactionBuffer.addSignature(builder, signatureVector); - NamespaceCreationTransactionBuffer.addSigner(builder, signerVector); - NamespaceCreationTransactionBuffer.addVersion(builder, this.version); - NamespaceCreationTransactionBuffer.addType(builder, this.type); - NamespaceCreationTransactionBuffer.addFee(builder, feeVector); - NamespaceCreationTransactionBuffer.addDeadline(builder, deadlineVector); - NamespaceCreationTransactionBuffer.addNamespaceType(builder, this.namespaceType); - NamespaceCreationTransactionBuffer.addDurationParentId(builder, durationParentIdVector); - NamespaceCreationTransactionBuffer.addNamespaceId(builder, namespaceIdVector); - NamespaceCreationTransactionBuffer.addNamespaceNameSize(builder, namespaceNameLength); - NamespaceCreationTransactionBuffer.addNamespaceName(builder, name); - - // Calculate size - const codedNamespace = NamespaceCreationTransactionBuffer.endNamespaceCreationTransactionBuffer(builder); - builder.finish(codedNamespace); - - const bytes = builder.asUint8Array(); - return new NamespaceCreationTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/SecretLockTransaction.ts b/src/infrastructure/builders/SecretLockTransaction.ts deleted file mode 100644 index 5e66e40c9b..0000000000 --- a/src/infrastructure/builders/SecretLockTransaction.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/SecretLockTransaction - */ -import { Convert as convert, RawAddress as address } from '../../core/format'; -import * as SecretLockTransactionBufferPackage from '../../infrastructure/buffers/SecretLockTransactionBuffer'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; -import SecretLockTransactionSchema from '../../infrastructure/schemas/SecretLockTransactionSchema'; -import { TransactionType } from '../../model/transaction/TransactionType'; - -import {flatbuffers} from 'flatbuffers'; - -const { - SecretLockTransactionBuffer, -} = SecretLockTransactionBufferPackage.default.Buffers; - -export default class SecretLockTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, SecretLockTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - mosaicAmount: any; - duration: any; - hashAlgorithm: any; - secret: any; - recipient: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.SECRET_LOCK; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - addMosaicAmount(mosaicAmount) { - this.mosaicAmount = mosaicAmount; - return this; - } - - addDuration(duration) { - this.duration = duration; - return this; - } - - addHashAlgorithm(hashAlgorithm) { - this.hashAlgorithm = hashAlgorithm; - return this; - } - - addSecret(secret) { - this.secret = secret; - return this; - } - - addRecipient(recipient) { - this.recipient = address.stringToAddress(recipient); - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = SecretLockTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = SecretLockTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = SecretLockTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = SecretLockTransactionBuffer.createFeeVector(builder, this.maxFee); - const mosaicIdVector = SecretLockTransactionBuffer.createMosaicIdVector(builder, this.mosaicId); - const mosaicAmountVector = SecretLockTransactionBuffer.createMosaicAmountVector(builder, this.mosaicAmount); - const durationVector = SecretLockTransactionBuffer.createDurationVector(builder, this.duration); - const byteSecret = convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); - const secretVector = SecretLockTransactionBuffer.createSecretVector(builder, byteSecret); - const recipientVector = SecretLockTransactionBuffer.createRecipientVector(builder, this.recipient); - - SecretLockTransactionBuffer.startSecretLockTransactionBuffer(builder); - SecretLockTransactionBuffer.addSize(builder, 202); - SecretLockTransactionBuffer.addSignature(builder, signatureVector); - SecretLockTransactionBuffer.addSigner(builder, signerVector); - SecretLockTransactionBuffer.addVersion(builder, this.version); - SecretLockTransactionBuffer.addType(builder, this.type); - SecretLockTransactionBuffer.addFee(builder, feeVector); - SecretLockTransactionBuffer.addDeadline(builder, deadlineVector); - SecretLockTransactionBuffer.addMosaicId(builder, mosaicIdVector); - SecretLockTransactionBuffer.addMosaicAmount(builder, mosaicAmountVector); - SecretLockTransactionBuffer.addDuration(builder, durationVector); - SecretLockTransactionBuffer.addHashAlgorithm(builder, this.hashAlgorithm); - SecretLockTransactionBuffer.addSecret(builder, secretVector); - SecretLockTransactionBuffer.addRecipient(builder, recipientVector); - - const codedSecretLock = SecretLockTransactionBuffer.endSecretLockTransactionBuffer(builder); - builder.finish(codedSecretLock); - - const bytes = builder.asUint8Array(); - return new SecretLockTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/SecretProofTransaction.ts b/src/infrastructure/builders/SecretProofTransaction.ts deleted file mode 100644 index 619e037173..0000000000 --- a/src/infrastructure/builders/SecretProofTransaction.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/SecretProofTransaction - */ -import { Convert as convert, RawAddress as address } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import * as SecretProofTransactionBufferPackage from '../buffers/SecretProofTransactionBuffer'; -import SecretProofTransactionSchema from '../schemas/SecretProofTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - SecretProofTransactionBuffer, -} = SecretProofTransactionBufferPackage.default.Buffers; - -export default class SecretProofTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, SecretProofTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - hashAlgorithm: any; - secret: any; - recipient: any; - proof: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.SECRET_PROOF; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addHashAlgorithm(hashAlgorithm) { - this.hashAlgorithm = hashAlgorithm; - return this; - } - - addSecret(secret) { - this.secret = secret; - return this; - } - addRecipient(recipient) { - this.recipient = address.stringToAddress(recipient); - return this; - } - - addProof(proof) { - this.proof = proof; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = SecretProofTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = SecretProofTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = SecretProofTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = SecretProofTransactionBuffer.createFeeVector(builder, this.maxFee); - const byteSecret = convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); - const secretVector = SecretProofTransactionBuffer.createSecretVector(builder, byteSecret); - const recipientVector = SecretProofTransactionBuffer.createRecipientVector(builder, this.recipient); - const byteProof = convert.hexToUint8(this.proof); - const proofVector = SecretProofTransactionBuffer.createProofVector(builder, byteProof); - - SecretProofTransactionBuffer.startSecretProofTransactionBuffer(builder); - SecretProofTransactionBuffer.addSize(builder, 180 + byteProof.length); - SecretProofTransactionBuffer.addSignature(builder, signatureVector); - SecretProofTransactionBuffer.addSigner(builder, signerVector); - SecretProofTransactionBuffer.addVersion(builder, this.version); - SecretProofTransactionBuffer.addType(builder, this.type); - SecretProofTransactionBuffer.addFee(builder, feeVector); - SecretProofTransactionBuffer.addDeadline(builder, deadlineVector); - SecretProofTransactionBuffer.addHashAlgorithm(builder, this.hashAlgorithm); - SecretProofTransactionBuffer.addSecret(builder, secretVector); - SecretProofTransactionBuffer.addRecipient(builder, recipientVector); - SecretProofTransactionBuffer.addProofSize(builder, byteProof.length); - SecretProofTransactionBuffer.addProof(builder, proofVector); - - const codedSecretProof = SecretProofTransactionBuffer.endSecretProofTransactionBuffer(builder); - builder.finish(codedSecretProof); - - const bytes = builder.asUint8Array(); - return new SecretProofTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/TransferTransaction.ts b/src/infrastructure/builders/TransferTransaction.ts deleted file mode 100644 index 0153d44a91..0000000000 --- a/src/infrastructure/builders/TransferTransaction.ts +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/TransferTransaction - */ -import { Convert as convert, RawAddress as address} from '../../core/format'; -import * as TransferTransactionBufferPackage from '../../infrastructure/buffers/TransferTransactionBuffer'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; -import TransferTransactionSchema from '../../infrastructure/schemas/TransferTransactionSchema'; -import { TransactionType } from '../../model/transaction/TransactionType'; - -import {flatbuffers} from 'flatbuffers'; - -const { - TransferTransactionBuffer, - MessageBuffer, - MosaicBuffer, -} = TransferTransactionBufferPackage.default.Buffers; - -export default class TransferTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, TransferTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - recipient: any; - message: any; - mosaics: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.TRANSFER; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRecipient(recipient) { - if (/^[0-9a-fA-F]{16}$/.test(recipient)) { - // received hexadecimal notation of namespaceId (alias) - this.recipient = address.aliasToRecipient(convert.hexToUint8(recipient)); - } else { - // received recipient address - this.recipient = address.stringToAddress(recipient); - } - return this; - } - - addMessage(message) { - this.message = message; - return this; - } - - addMosaics(mosaics) { - this.mosaics = mosaics.sort((a, b) => { - if (Number(a.id[1]) > b.id[1]) { return 1; } else if (a.id[1] < b.id[1]) { return -1; } - return 0; - }); - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - // Constants - - // Create message - const bytePayload = convert.hexToUint8(convert.utf8ToHex(this.message.payload)); - const payload = MessageBuffer.createPayloadVector(builder, bytePayload); - MessageBuffer.startMessageBuffer(builder); - MessageBuffer.addType(builder, this.message.type); - MessageBuffer.addPayload(builder, payload); - const message = MessageBuffer.endMessageBuffer(builder); - - // Create mosaics - const mosaics: any = []; - this.mosaics.forEach(mosaic => { - const id = MosaicBuffer.createIdVector(builder, mosaic.id); - const amount = MosaicBuffer.createAmountVector(builder, mosaic.amount); - MosaicBuffer.startMosaicBuffer(builder); - MosaicBuffer.addId(builder, id); - MosaicBuffer.addAmount(builder, amount); - mosaics.push(MosaicBuffer.endMosaicBuffer(builder)); - }); - - // Create vectors - const signatureVector = TransferTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = TransferTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = TransferTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = TransferTransactionBuffer.createFeeVector(builder, this.maxFee); - const recipientVector = TransferTransactionBuffer.createRecipientVector(builder, this.recipient); - const mosaicsVector = TransferTransactionBuffer.createMosaicsVector(builder, mosaics); - - TransferTransactionBuffer.startTransferTransactionBuffer(builder); - TransferTransactionBuffer.addSize(builder, 149 + (16 * this.mosaics.length) + bytePayload.length); - TransferTransactionBuffer.addSignature(builder, signatureVector); - TransferTransactionBuffer.addSigner(builder, signerVector); - TransferTransactionBuffer.addVersion(builder, this.version); - TransferTransactionBuffer.addType(builder, this.type); - TransferTransactionBuffer.addFee(builder, feeVector); - TransferTransactionBuffer.addDeadline(builder, deadlineVector); - TransferTransactionBuffer.addRecipient(builder, recipientVector); - TransferTransactionBuffer.addNumMosaics(builder, this.mosaics.length); - TransferTransactionBuffer.addMessageSize(builder, bytePayload.length + 1); - TransferTransactionBuffer.addMessage(builder, message); - TransferTransactionBuffer.addMosaics(builder, mosaicsVector); - - // Calculate size - - const codedTransfer = TransferTransactionBuffer.endTransferTransactionBuffer(builder); - builder.finish(codedTransfer); - - const bytes = builder.asUint8Array(); - return new TransferTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/VerifiableTransaction.ts b/src/infrastructure/builders/VerifiableTransaction.ts deleted file mode 100644 index d83b079d59..0000000000 --- a/src/infrastructure/builders/VerifiableTransaction.ts +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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 { KeyPair, SignSchema } from '../../core/crypto'; -import { SHA3Hasher as sha3Hasher } from '../../core/crypto/SHA3Hasher'; -import { Convert as convert } from '../../core/format'; - -/** - * VerifiableTransaction - * @module transactions/VerifiableTransaction - * @version 1.0.0 - */ -export class VerifiableTransaction { - bytes: any; - schema: any; - /** - * @constructor - * @param {Uint8Array} bytes Uint8Array after flatbuffers.build.asUint8Array() - * @param {module:schema/Schema} schema Schema definition corresponding to flatbuffer Schema - */ - constructor(bytes, schema) { - this.bytes = bytes; - this.schema = schema; - } - - /** - * @param {string} transactionPayload HexString Payload - * @param {string} generationHash Network generation hash byte - * @returns {*|string} Returns Transaction Payload hash - */ - static createTransactionHash(transactionPayload, generationHash) { - const byteBuffer = Array.from(convert.hexToUint8(transactionPayload)); - const signingBytes = byteBuffer - .slice(4, 36) - .concat(byteBuffer - .slice(4 + 64, 4 + 64 + 32)) - .concat(generationHash) - .concat(byteBuffer - .splice(4 + 64 + 32, byteBuffer.length)); - - const hash = new Uint8Array(32); - - sha3Hasher.func(hash, signingBytes, 32); - - return convert.uint8ToHex(hash); - } - - /** - * @param {KeyPair } keyPair KeyPair instance - * @param {string} generationHash Network generation hash hex - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {module:model/TransactionPayload} - Signed Transaction Payload - */ - signTransaction(keyPair, generationHash, signSchema: SignSchema = SignSchema.SHA3) { - const generationHashBytes = Array.from(convert.hexToUint8(generationHash)); - const byteBuffer = this.serialize(); - const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); - const keyPairEncoded = KeyPair.createKeyPairFromPrivateKeyString(keyPair.privateKey, signSchema); - const signature = Array.from(KeyPair.sign(keyPair, new Uint8Array(signingBytes), signSchema)); - const signedTransactionBuffer = byteBuffer - .splice(0, 4) - .concat(signature) - .concat(Array.from(keyPairEncoded.publicKey)) - .concat(byteBuffer - .splice(64 + 32, byteBuffer.length)); - const payload = convert.uint8ToHex(signedTransactionBuffer); - return { - payload, - hash: VerifiableTransaction.createTransactionHash(payload, generationHashBytes), - }; - } - - serialize() { - return this.schema.serialize(Array.from(this.bytes)); - } - - /** - * @returns {string} - Serialized Transaction Payload - */ - serializeUnsignedTransaction() { - return convert.uint8ToHex(this.serialize()); - } - - /** - * @param {KeyPair} keyPair KeyPair instance - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {module:model/TransactionPayload} Returns TransactionPayload instance - */ - signCosignatoriesTransaction(keyPair, signSchema: SignSchema = SignSchema.SHA3) { - const signature = KeyPair.sign(keyPair, new Uint8Array(this.bytes), signSchema); - return { - parentHash: convert.uint8ToHex(this.bytes), - signature: convert.uint8ToHex(signature), - signer: keyPair.publicKey, - }; - } - - /** - * Converts the transaction into AggregateTransaction compatible - * @param {string} [_signer] Signer public key - * @returns {Array.<*>} AggregateTransaction bytes - */ - toAggregateTransaction(_signer) { - const signer = convert.hexToUint8(_signer); - let resultBytes = this.schema.serialize(Array.from(this.bytes)); - resultBytes.splice(0, 4 + 64 + 32); - resultBytes = Array.from(signer).concat(resultBytes); - resultBytes.splice(32 + 2 + 2, 16); - return Array.from((new Uint8Array([ - (resultBytes.length + 4 & 0x000000ff), - (resultBytes.length + 4 & 0x0000ff00) >> 8, - (resultBytes.length + 4 & 0x00ff0000) >> 16, - (resultBytes.length + 4 & 0xff000000) >> 24, - ]))).concat(resultBytes); - } -} diff --git a/src/infrastructure/builders/VerificableTransactionBuilder.ts b/src/infrastructure/builders/VerificableTransactionBuilder.ts deleted file mode 100644 index a63c9cb9ab..0000000000 --- a/src/infrastructure/builders/VerificableTransactionBuilder.ts +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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'; - -const { - flatbuffers -} = require('flatbuffers'); - -/** - * @module transactions/VerifiableTransactionBuilder - */ - -/** - * @callback LambdaBuilder - * @param {flatbuffers.Builder} builder - * @return {void} - */ - -export default class VerifiableTransactionBuilder { - bytes: any; - schema: any - /** - * @param {LambdaBuilder} lambda Callback - * @returns {VerifiableTransactionBuilder} Returns self instance - */ - addTransaction(lambda) { - const builder = new flatbuffers.Builder(1); - - lambda(builder); - - this.bytes = builder.asUint8Array(); - return this; - } - - /** - * @param {module:schema/Schema} schema Schema corresponding with flatbuffers Schema used on addTransaction - * @returns {VerifiableTransactionBuilder} Returns self instance - */ - addSchema(schema) { - this.schema = schema; - return this; - } - - /** - * @returns {VerifiableTransaction} Returns VerifiableTransaction instance - */ - build() { - return new VerifiableTransaction(this.bytes, this.schema); - } -} diff --git a/src/infrastructure/schemas/AccountLinkTransactionSchema.ts b/src/infrastructure/schemas/AccountLinkTransactionSchema.ts deleted file mode 100644 index 5a0e3be1ba..0000000000 --- a/src/infrastructure/schemas/AccountLinkTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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/AccountLinkTransaction - */ - -/** - * Account Link schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('remoteAccountKey'), - ubyte('linkAction') -]); -export default schema; diff --git a/src/infrastructure/schemas/AccountRestrictionsAddressModificationTransactionSchema.ts b/src/infrastructure/schemas/AccountRestrictionsAddressModificationTransactionSchema.ts deleted file mode 100644 index f08fd0cda3..0000000000 --- a/src/infrastructure/schemas/AccountRestrictionsAddressModificationTransactionSchema.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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, - ushort, - tableArray, - uint -} from './Schema'; - -/** - * @module schema/AccountRestrictionsAddressModificationTransactionSchema - */ - -/** - * Account restriction address 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('restrictionType'), - ubyte('modificationCount'), - tableArray('modifications', [ - ubyte('modificationType'), - array('value', TypeSize.BYTE) - ]) -]); diff --git a/src/infrastructure/schemas/AccountRestrictionsEntityTypeModificationTransactionSchema.ts b/src/infrastructure/schemas/AccountRestrictionsEntityTypeModificationTransactionSchema.ts deleted file mode 100644 index 6d9090a5c0..0000000000 --- a/src/infrastructure/schemas/AccountRestrictionsEntityTypeModificationTransactionSchema.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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, - ushort, - tableArray, - uint -} from './Schema'; - -/** - * @module schema/AccountRestrictionsEntityTypeModificationTransactionSchema - */ - -/** - * Account restrictions address 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('restrictionType'), - ubyte('modificationCount'), - tableArray('modifications', [ - ubyte('modificationType'), - ushort('value') - ]) -]); diff --git a/src/infrastructure/schemas/AccountRestrictionsMosaicModificationTransactionSchema.ts b/src/infrastructure/schemas/AccountRestrictionsMosaicModificationTransactionSchema.ts deleted file mode 100644 index 557c38898e..0000000000 --- a/src/infrastructure/schemas/AccountRestrictionsMosaicModificationTransactionSchema.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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, - ushort, - tableArray, - uint -} from './Schema'; - -/** - * @module schema/AccountRestrictionsMosaicModificationTransactionSchema - */ - -/** - * Account restrictions address 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('restrictionType'), - ubyte('modificationCount'), - tableArray('modifications', [ - ubyte('modificationType'), - array('value', TypeSize.INT) - ]) -]); diff --git a/src/infrastructure/schemas/AddressAliasTransactionSchema.ts b/src/infrastructure/schemas/AddressAliasTransactionSchema.ts deleted file mode 100644 index ef01e3eadd..0000000000 --- a/src/infrastructure/schemas/AddressAliasTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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('aliasAction'), - array('namespaceId', TypeSize.INT), - array('address', TypeSize.BYTE) -]); diff --git a/src/infrastructure/schemas/AggregateTransactionSchema.ts b/src/infrastructure/schemas/AggregateTransactionSchema.ts deleted file mode 100644 index f27bc0e142..0000000000 --- a/src/infrastructure/schemas/AggregateTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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, - uint, - ushort -} from './Schema'; - -/** - * @module schema/AggregateTransactionSchema - */ - -/** - * Aggregate transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - uint('transactionsSize'), - array('transactions') -]); - -export default schema; diff --git a/src/infrastructure/schemas/HashLockTransactionSchema.ts b/src/infrastructure/schemas/HashLockTransactionSchema.ts deleted file mode 100644 index 2efbf4ffaa..0000000000 --- a/src/infrastructure/schemas/HashLockTransactionSchema.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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, - uint, - ushort -} from './Schema'; - -/** - * @module schema/HashLockTransactionSchema - */ - -/** - * Hash lock transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('mosaicId', TypeSize.INT), - array('mosaicAmount', TypeSize.INT), - array('duration', TypeSize.INT), - array('hash') -]); -export default schema; diff --git a/src/infrastructure/schemas/MosaicAddressRestrictionTransactionSchema.ts b/src/infrastructure/schemas/MosaicAddressRestrictionTransactionSchema.ts deleted file mode 100644 index 18123110e1..0000000000 --- a/src/infrastructure/schemas/MosaicAddressRestrictionTransactionSchema.ts +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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/MosaicAddressRestrictionTransactionSchema - */ - -/** - * Account Link 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), - array('mosaicId', TypeSize.INT), - array('restrictionKey', TypeSize.INT), - array('targetAddress', TypeSize.BYTE), - array('previousRestrictionValue', TypeSize.INT), - array('newRestrictionValue', TypeSize.INT), -]); diff --git a/src/infrastructure/schemas/MosaicAliasTransactionSchema.ts b/src/infrastructure/schemas/MosaicAliasTransactionSchema.ts deleted file mode 100644 index 37b827b192..0000000000 --- a/src/infrastructure/schemas/MosaicAliasTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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('aliasAction'), - array('namespaceId', TypeSize.INT), - array('mosaicId', TypeSize.INT) -]); diff --git a/src/infrastructure/schemas/MosaicCreationTransactionSchema.ts b/src/infrastructure/schemas/MosaicCreationTransactionSchema.ts deleted file mode 100644 index e9d947652a..0000000000 --- a/src/infrastructure/schemas/MosaicCreationTransactionSchema.ts +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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/MosaicCreationTransactionSchema - */ - -/** - * Mosaic definition creation transaction schema - * @const {module:schema/Schema} - */ -export const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('nonce', TypeSize.BYTE), - array('mosaicId', TypeSize.INT), - ubyte('numOptionalProperties'), - ubyte('flags'), - ubyte('divisibility'), - ubyte('indicateDuration'), - array('duration', TypeSize.INT) -]); - -export const schemaNoDuration = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('nonce', TypeSize.BYTE), - array('mosaicId', TypeSize.INT), - ubyte('numOptionalProperties'), - ubyte('flags'), - ubyte('divisibility') -]); diff --git a/src/infrastructure/schemas/MosaicGlobalRestrictionTransactionSchema.ts b/src/infrastructure/schemas/MosaicGlobalRestrictionTransactionSchema.ts deleted file mode 100644 index d5be82b1ec..0000000000 --- a/src/infrastructure/schemas/MosaicGlobalRestrictionTransactionSchema.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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/MosaicGlobalRestrictionTransactionSchema - */ - -/** - * Account Link 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), - array('mosaicId', TypeSize.INT), - array('referenceMosaicId', TypeSize.INT), - array('restrictionKey', TypeSize.INT), - array('previousRestrictionValue', TypeSize.INT), - ubyte('previousRestrictionType'), - array('newRestrictionValue', TypeSize.INT), - ubyte('newRestrictionType'), - -]); diff --git a/src/infrastructure/schemas/MosaicSupplyChangeTransactionSchema.ts b/src/infrastructure/schemas/MosaicSupplyChangeTransactionSchema.ts deleted file mode 100644 index 19df7503b8..0000000000 --- a/src/infrastructure/schemas/MosaicSupplyChangeTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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/MosaicSupplyChangeTransactionSchema - */ - -/** - * Mosaic supply change 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), - array('mosaicId', TypeSize.INT), - ubyte('direction'), - array('delta', TypeSize.INT) -]); diff --git a/src/infrastructure/schemas/MultisigModificationTransactionSchema.ts b/src/infrastructure/schemas/MultisigModificationTransactionSchema.ts deleted file mode 100644 index 91beb8efc6..0000000000 --- a/src/infrastructure/schemas/MultisigModificationTransactionSchema.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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, - tableArray, - TypeSize, - ubyte, - uint, - ushort -} from './Schema'; - -/** - * @module schema/MultigAggregateModificationTransactionSchema - */ - -/** - * Multisig aggregate modification 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('minRemovalDelta'), - ubyte('minApprovalDelta'), - ubyte('numModifications'), - tableArray('modifications', [ - ubyte('type'), - array('cosignatoryPublicKey') - ]) -]); diff --git a/src/infrastructure/schemas/NamespaceCreationTransactionSchema.ts b/src/infrastructure/schemas/NamespaceCreationTransactionSchema.ts deleted file mode 100644 index 7694dddc5e..0000000000 --- a/src/infrastructure/schemas/NamespaceCreationTransactionSchema.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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, - string, - TypeSize, - ubyte, - uint, - ushort -} from './Schema'; - -/** - * @module schema/NamespaceCreationTransactionSchema - */ - -/** - * Provision namespace 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('namespaceType'), - array('durationParentId', TypeSize.INT), - array('namespaceId', TypeSize.INT), - ubyte('namespaceNameSize'), - string('name') -]); diff --git a/src/infrastructure/schemas/Schema.ts b/src/infrastructure/schemas/Schema.ts deleted file mode 100644 index 212378e39e..0000000000 --- a/src/infrastructure/schemas/Schema.ts +++ /dev/null @@ -1,374 +0,0 @@ -/* - * 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. - */ - -/* eslint-disable no-use-before-define */ - -/** - * In bytes - * @type {{BYTE: number, SHORT: number, INT: number}} - */ -export const TypeSize = { - BYTE: 1, - SHORT: 2, - INT: 4, -}; - -/** - * @param {string} name Attribute name - * @returns {ScalarAttribute} return ScalarAttribute Instance - */ -export const ubyte = (name) => { - return new ScalarAttribute(name, TypeSize.BYTE); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const byte = (name) => { - return new ScalarAttribute(name, TypeSize.BYTE); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const ushort = (name) => { - return new ScalarAttribute(name, TypeSize.SHORT); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const short = (name) => { - return new ScalarAttribute(name, TypeSize.SHORT); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const uint = (name) => { - return new ScalarAttribute(name, TypeSize.INT); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const int = (name) => { - return new ScalarAttribute(name, TypeSize.INT); -}; - -/** - * - * @param {string} name Attribute Name - * @param {number} typeSize Attribute Byte Size - * @returns {ArrayAttribute} ArrayAttribute Instance - */ -export const array = (name, typeSize = TypeSize.BYTE) => { - return new ArrayAttribute(name, typeSize); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ArrayAttribute} ArrayAttribute Instance - */ -export const string = (name) => { - return array(name); -}; - -/** - * - * @param {string} name Attribute Name - * @param {module:schema/Schema} schema Table Specific Schema definition - * @returns {TableAttribute} TableAttribute Instance - */ -export const table = (name, schema) => { - return new TableAttribute(name, schema); -}; - -/** - * - * @param {string} name Attribute Name - * @param {module:schema/Schema} schema Schema Definition - * @returns {TableArrayAttribute} TableAttribute Instance - */ -export const tableArray = (name, schema) => { - return new TableArrayAttribute(name, schema); -}; - -/* eslint-disable */ -const readInt32 = (offset, bytes) => { - return bytes[offset] | bytes[offset + 1] << 8 | bytes[offset + 2] << 16 | bytes[offset + 3] << 24; -}; - -const readInt16 = (offset, bytes) => { - return bytes[offset] | bytes[offset + 1] << 8; -}; - -const __offset = (val0, fieldPos, bytes) => { - const vtable = val0 - readInt32(val0, bytes); - return fieldPos < readInt16(vtable, bytes) ? readInt16(vtable + fieldPos, bytes) : 0; -}; - -const __vector_length = (offset, bytes) => { - return readInt32(offset + readInt32(offset, bytes), bytes); -}; - -const __indirect = (offset, bytes) => { - return offset + readInt32(offset, bytes); -}; - -const __vector = (offset, bytes) => { - return offset + readInt32(offset, bytes) + 4; -}; - -const findVector = (val0, fieldPos, bytes, size) => { - const offset = __offset(val0, fieldPos, bytes); - const offsetLong = offset + val0; - const vecStart = __vector(offsetLong, bytes); - const vecLength = __vector_length(offsetLong, bytes) * (size ? size : 1); - return offset ? bytes.slice(vecStart, vecStart + vecLength) : 0; -}; - -const findParam = (val0, fieldPos, bytes, numBytes) => { - const offset = __offset(val0, fieldPos, bytes); - return offset ? bytes.slice(offset + val0, offset + val0 + numBytes) : 0; -}; - -const findObjectStartPosition = (val0, fieldPos, bytes) => { - const offset = __offset(val0, fieldPos, bytes); - return __indirect(offset + val0, bytes); -}; - -const findArrayLength = (val0, fieldPos, bytes) => { - const offset = __offset(val0, fieldPos, bytes); - return offset ? __vector_length(val0 + offset, bytes) : 0; -}; - -const findObjectArrayElementStartPosition = (val0, fieldPos, bytes, index) => { - const offset = __offset(val0, fieldPos, bytes); - const vector = __vector(val0 + offset, bytes); - return __indirect(vector + index * 4, bytes); -}; - -/** - * Schema - * @module schema/Schema - */ -export class Schema { - schemaDefinition; - /** - * @constructor - * @param {Array.} schemaDefinition Schema Definition - */ - constructor(schemaDefinition) { - this.schemaDefinition = schemaDefinition; - } - - /** - * - * @param {Uint8Array} bytes flatbuffers bytes - * @returns {Uint8Array} catapult buffer - */ - serialize(bytes) { - let i = 0; - let resultBytes = []; - while (i < this.schemaDefinition.length) { - resultBytes = resultBytes.concat(this.schemaDefinition[i].serialize(bytes, 4 + (i * 2))); - i++; - } - return resultBytes; - } - - /** - * @param {Uint8Array} bytes flatbuffer bytes - * @returns {Array} Array with field name + payload - */ - debugSerialize(bytes) { - let i = 0; - let result: any = []; - while (i < this.schemaDefinition.length) { - result = result.concat({ - name: this.schemaDefinition[i].name, - bytes: this.schemaDefinition[i].debugSerialize(bytes, 4 + i * 2), - }); - i++; - } - return result; - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Attribute { - name: any; - /** - * @constructor - * @param {string} name schema attribute name - */ - constructor(name) { - this.name = name; - } - - /** - * - * @param {Uint8Array} buffer flatbuffer bytes - * @param {number} position attribute possition in flatbuffer bytes - * @param {number} val0 position in case that it is an inner object - */ - serialize(buffer, position, val0 = undefined) { - throw new Error('Unimplemented method'); - } - - /** - * @suppress warnings - * @param {Uint8Array} buffer buffer flatbuffer bytes - * @param {number} position attribute possition in flatbuffer bytes - * @param {number} val0 position in case that it is an inner object - */ - debugSerialize(buffer, position, val0 = undefined) { - throw new Error('Unimplemented method'); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class ScalarAttribute extends Attribute { - typeSize: any; - name: any; - /** - * @constructor - * @param {string} name schema attribute name - * @param {number} typeSize - */ - constructor(name, typeSize) { - super(name); - this.typeSize = typeSize; - } - - serialize(buffer, position, val0 = undefined) { - return findParam(val0 ? val0 : buffer[0], position, buffer, this.typeSize); - } - - debugSerialize(buffer, position, val0 = undefined) { - return { - name: this.name, - bytes: this.serialize(buffer, position, val0), - }; - } -} - -// tslint:disable-next-line:max-classes-per-file -export class ArrayAttribute extends Attribute { - typeSize: any; - name: any; - /** - * @constructor - * @param name - {string} - * @param typeSize - {TypeSize} - */ - constructor(name, typeSize) { - super(name); - this.typeSize = typeSize; - } - - serialize(buffer, position, val0 = undefined) { - return findVector(val0 ? val0 : buffer[0], position, buffer, this.typeSize); - } - - debugSerialize(buffer, position, val0 = undefined) { - return { - name: this.name, - bytes: this.serialize(buffer, position, val0), - }; - } -} - -// tslint:disable-next-line:max-classes-per-file -export class TableAttribute extends Attribute { - schema: any; - name: any; - /** - * - * @param {string} name - * @param {module:schema/Schema} schema - */ - constructor(name, schema) { - super(name); - this.schema = schema; - } - - serialize(bytes, position, val0 = undefined) { - let result = []; - const messageStartPosition = findObjectStartPosition(val0 ? val0 : bytes[0], position, bytes); - let i = 0; - while (i < this.schema.length) { - result = result.concat(this.schema[i].serialize(bytes, 4 + i * 2, messageStartPosition)); - i++; - } - return result; - } - - debugSerialize(buffer, position, val0 = undefined) { - return { - name: this.name, - bytes: this.serialize(buffer, position, val0), - }; - } -} - -// tslint:disable-next-line:max-classes-per-file -export class TableArrayAttribute extends Attribute { - schema: any; - name: any; - /** - * @constructor - * @param {string} name - * @param {module:schema/Schema} schema - */ - constructor(name, schema) { - super(name); - this.schema = schema; - } - - serialize(bytes, position, val0 = undefined) { - let result = []; - const arrayLength = findArrayLength(val0 ? val0 : bytes[0], position, bytes); - let i = 0; - while (i < arrayLength) { - const startArrayPosition = findObjectArrayElementStartPosition(val0 ? val0 : bytes[0], position, bytes, i); - for (let j = 0; j < this.schema.length; ++j) { - result = result.concat(this.schema[j].serialize(bytes, 4 + j * 2, startArrayPosition)); - } - i++; - } - return result; - } - - debugSerialize(buffer, position, val0 = undefined) { - return { - name: this.name, - bytes: this.serialize(buffer, position, val0), - }; - } -} diff --git a/src/infrastructure/schemas/SecretLockTransactionSchema.ts b/src/infrastructure/schemas/SecretLockTransactionSchema.ts deleted file mode 100644 index 046f02c178..0000000000 --- a/src/infrastructure/schemas/SecretLockTransactionSchema.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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/SecretLockTransactionSchema - */ - -/** - * Secret lock transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('mosaicId', TypeSize.INT), - array('mosaicAmount', TypeSize.INT), - array('duration', TypeSize.INT), - ubyte('hashAlgorithm'), - array('secret'), - array('recipient') -]); -export default schema; diff --git a/src/infrastructure/schemas/SecretProofTransactionSchema.ts b/src/infrastructure/schemas/SecretProofTransactionSchema.ts deleted file mode 100644 index db03f6eaf4..0000000000 --- a/src/infrastructure/schemas/SecretProofTransactionSchema.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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/SecretProofTransactionSchema - */ - -/** - * Secret proof transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - ubyte('hashAlgorithm'), - array('secret'), - array('recipient'), - ushort('proofSize'), - array('proof') -]); -export default schema; diff --git a/src/infrastructure/schemas/TransferTransactionSchema.ts b/src/infrastructure/schemas/TransferTransactionSchema.ts deleted file mode 100644 index eb8efdfd4e..0000000000 --- a/src/infrastructure/schemas/TransferTransactionSchema.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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, - table, - tableArray, - TypeSize, - ubyte, - uint, - ushort -} from './Schema'; - -/** - * @module schema/TransferTransactionSchema - */ - -/** - * Transfer transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('recipient'), - ushort('messageSize'), - ubyte('numMosaics'), - table('message', [ - ubyte('type'), - array('payload') - ]), - tableArray('mosaics', [ - array('id', TypeSize.INT), - array('amount', TypeSize.INT) - ]) -]); -export default schema; diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index b1198243fd..6491749d4c 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -190,27 +190,21 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N case TransactionType.MOSAIC_DEFINITION: const mosaicDefMosaicNonceLength = 8; const mosaicDefMosaicIdLength = 16; - const mosaicDefPropsNumLength = 2; const mosaicDefPropsFlagsLength = 2; const mosaicDefDivisibilityLength = 2; - const mosaicDefDurationIndLength = 2; const mosaicDefDurationLength = 16; const mosaicIdOffset = mosaicDefMosaicNonceLength; - const propsOffset = mosaicIdOffset + mosaicDefMosaicIdLength; - const flagsOffset = propsOffset + mosaicDefPropsNumLength; + const flagsOffset = mosaicIdOffset + mosaicDefMosaicIdLength; const divisibilityOffset = flagsOffset + mosaicDefPropsFlagsLength; - const durationIndOffset = divisibilityOffset + mosaicDefDivisibilityLength; - const durationOffset = durationIndOffset + mosaicDefDurationIndLength; + const durationOffset = divisibilityOffset + mosaicDefDivisibilityLength; // read bytes const mosaicNonce = transactionData.substring(0, mosaicDefMosaicNonceLength); - const mosaicId = transactionData.substring(mosaicIdOffset, propsOffset); - const props = transactionData.substring(propsOffset, flagsOffset); + const mosaicId = transactionData.substring(mosaicIdOffset, flagsOffset); const flags = parseInt(convert.uint8ToHex(convert.hexToUint8( transactionData.substring(flagsOffset, divisibilityOffset)).reverse()), 16); - const divisibility = transactionData.substring(divisibilityOffset, durationIndOffset); - const durationInd = transactionData.substring(durationIndOffset, durationOffset); + const divisibility = transactionData.substring(divisibilityOffset, durationOffset); const duration = transactionData.substring(durationOffset); const regexArray = mosaicNonce.match(/.{1,2}/g); diff --git a/src/model/namespace/AliasAction.ts b/src/model/namespace/AliasAction.ts index ae709efd97..27669a1d91 100644 --- a/src/model/namespace/AliasAction.ts +++ b/src/model/namespace/AliasAction.ts @@ -19,7 +19,7 @@ * 0: Link an alias. * 1: Unlink an alias. */ -export enum AliasAction { - Link = 0, - Unlink = 1, +export enum AliasActionType { + Link = 1, + Unlink = 0, } diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index fd4200205c..150cd213b6 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -15,13 +15,10 @@ */ import { Convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; @@ -106,20 +103,6 @@ export class AccountAddressRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRestrictionType(this.restrictionType) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index bd0a0303db..58584444b2 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountLinkTransaction'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/AccountLinkTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder'; @@ -105,20 +103,6 @@ export class AccountLinkTransaction extends Transaction { return byteSize + bytePublicKey + byteLinkAction; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRemoteAccountKey(this.remoteAccountKey) - .addLinkAction(this.linkAction) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index efe54c41d8..be182d398b 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -105,20 +103,6 @@ export class AccountMosaicRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRestrictionType(this.restrictionType) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index b42d33e3ab..3ee53a4b4d 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -104,20 +102,6 @@ export class AccountOperationRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRestrictionType(this.restrictionType) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 98a416a6d3..1ad4e6b61f 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AddressAliasTransaction'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; import { AddressDto } from '../../infrastructure/catbuffer/AddressDto'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -121,21 +119,6 @@ export class AddressAliasTransaction extends Transaction { return byteSize + byteActionType + byteNamespaceId + byteAddress; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addAliasAction(this.aliasAction) - .addNamespaceId(this.namespaceId.id.toDTO()) - .addAddress(this.address.plain()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 797eb757e5..608559f663 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -14,10 +14,8 @@ * limitations under the License. */ -import { SignSchema } from '../../core/crypto'; +import { KeyPair, SignSchema } from '../../core/crypto'; import { Convert } from '../../core/format'; -import { AggregateTransaction as AggregatedTransactionCore} from '../../infrastructure/builders/AggregateTransaction'; -import { Builder } from '../../infrastructure/builders/AggregateTransaction'; import { AggregateTransactionBuilder } from '../../infrastructure/catbuffer/AggregateTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { CosignatureBuilder } from '../../infrastructure/catbuffer/CosignatureBuilder'; @@ -31,6 +29,7 @@ import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AggregateTransactionCosignature } from './AggregateTransactionCosignature'; import { CosignatureSignedTransaction } from './CosignatureSignedTransaction'; +import { CosignatureTransaction } from './CosignatureTransaction'; import { Deadline } from './Deadline'; import { InnerTransaction } from './InnerTransaction'; import { SignedTransaction } from './SignedTransaction'; @@ -123,21 +122,6 @@ export class AggregateTransaction extends Transaction { ); } - /** - * @internal - * @returns {AggregateTransaction} - */ - public buildTransaction(): AggregatedTransactionCore { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addType(this.type) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addTransactions(this.innerTransactions.map((transaction) => { - return transaction.aggregateTransaction(); - })).build(); - } - /** * @internal * Sign transaction with cosignatories creating a new SignedTransaction @@ -150,11 +134,23 @@ export class AggregateTransaction extends Transaction { public signTransactionWithCosignatories(initiatorAccount: Account, cosignatories: Account[], generationHash: string, - signSchema: SignSchema = SignSchema.SHA3) { - const aggregateTransaction = this.buildTransaction(); - const signedTransactionRaw = aggregateTransaction - .signTransactionWithCosigners(initiatorAccount, cosignatories, generationHash, signSchema); - return new SignedTransaction(signedTransactionRaw.payload, signedTransactionRaw.hash, initiatorAccount.publicKey, + signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { + const signedTransaction = this.signWith(initiatorAccount, generationHash, signSchema); + const transactionHashBytes = Convert.hexToUint8(signedTransaction.hash); + let signedPayload = signedTransaction.payload; + cosignatories.forEach((cosigner) => { + const signature = KeyPair.sign(cosigner, transactionHashBytes, signSchema); + signedPayload += cosigner.publicKey + Convert.uint8ToHex(signature); + }); + + // Calculate new size + const size = `00000000${(signedPayload.length / 2).toString(16)}`; + const formatedSize = size.substr(size.length - 8, size.length); + const littleEndianSize = formatedSize.substr(6, 2) + formatedSize.substr(4, 2) + + formatedSize.substr(2, 2) + formatedSize.substr(0, 2); + + signedPayload = littleEndianSize + signedPayload.substr(8, signedPayload.length - 8); + return new SignedTransaction(signedPayload, signedTransaction.hash, initiatorAccount.publicKey, this.type, this.networkType); } @@ -171,13 +167,21 @@ export class AggregateTransaction extends Transaction { public signTransactionGivenSignatures(initiatorAccount: Account, cosignatureSignedTransactions: CosignatureSignedTransaction[], generationHash: string, - signSchema: SignSchema= SignSchema.SHA3) { - const aggregateTransaction = this.buildTransaction(); - const signedTransactionRaw = aggregateTransaction.signTransactionGivenSignatures(initiatorAccount, - cosignatureSignedTransactions, - generationHash, - signSchema); - return new SignedTransaction(signedTransactionRaw.payload, signedTransactionRaw.hash, initiatorAccount.publicKey, + signSchema: SignSchema= SignSchema.SHA3): SignedTransaction { + const signedTransaction = this.signWith(initiatorAccount, generationHash, signSchema); + let signedPayload = signedTransaction.payload; + cosignatureSignedTransactions.forEach((cosignedTransaction) => { + signedPayload += cosignedTransaction.signer + cosignedTransaction.signature; + }); + + // Calculate new size + const size = `00000000${(signedPayload.length / 2).toString(16)}`; + const formatedSize = size.substr(size.length - 8, size.length); + const littleEndianSize = formatedSize.substr(6, 2) + formatedSize.substr(4, 2) + + formatedSize.substr(2, 2) + formatedSize.substr(0, 2); + + signedPayload = littleEndianSize + signedPayload.substr(8, signedPayload.length - 8); + return new SignedTransaction(signedPayload, signedTransaction.hash, initiatorAccount.publicKey, this.type, this.networkType); } @@ -237,9 +241,6 @@ export class AggregateTransaction extends Transaction { transactions = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); }); - console.log('cosignatures', Convert.uint8ToHex(cosignatures)); - console.log('transactions', Convert.uint8ToHex(transactions)); - const transactionBuilder = new AggregateTransactionBuilder( new SignatureDto(signatureBuffer), new KeyDto(signerBuffer), diff --git a/src/model/transaction/CosignatureTransaction.ts b/src/model/transaction/CosignatureTransaction.ts index d1b6ddc5b5..62e4a248ed 100644 --- a/src/model/transaction/CosignatureTransaction.ts +++ b/src/model/transaction/CosignatureTransaction.ts @@ -14,13 +14,12 @@ * limitations under the License. */ -import { SignSchema } from '../../core/crypto'; +import { KeyPair, SignSchema } from '../../core/crypto'; import { Convert } from '../../core/format/Convert'; -import {CosignatureTransaction as CosignaturetransactionLibrary} from '../../infrastructure/builders/CosignatureTransaction'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import {Account} from '../account/Account'; import {AggregateTransaction} from './AggregateTransaction'; import {CosignatureSignedTransaction} from './CosignatureSignedTransaction'; +import { Transaction } from './Transaction'; /** * Cosignature transaction is used to sign an aggregate transactions with missing cosignatures. @@ -41,9 +40,9 @@ export class CosignatureTransaction { * @param transactionToCosign - Transaction to cosign. * @returns {CosignatureTransaction} */ - public static create(transactionToCosign: AggregateTransaction) { + public static create(transactionToCosign: AggregateTransaction): CosignatureTransaction { if (transactionToCosign.isUnannounced()) { - throw new Error('transaction to cosign should be announced first'); + throw new Error('Transaction to cosign should be announced first'); } return new CosignatureTransaction(transactionToCosign); } @@ -64,12 +63,14 @@ export class CosignatureTransaction { /** * For aggregated complete transaction, cosignatories are gathered off chain announced. */ - const transactionHash = VerifiableTransaction.createTransactionHash(payload, Array.from(Convert.hexToUint8(generationHash))); - const aggregateSignatureTransaction = new CosignaturetransactionLibrary(transactionHash); - const signedTransactionRaw = aggregateSignatureTransaction.signCosignatoriesTransaction(account, signSchema); - return new CosignatureSignedTransaction(signedTransactionRaw.parentHash, - signedTransactionRaw.signature, - signedTransactionRaw.signer); + const transactionHash = Transaction.createTransactionHash(payload, Array.from(Convert.hexToUint8(generationHash))); + const hashBytes = Convert.hexToUint8(transactionHash); + const signature = KeyPair.sign(account, new Uint8Array(hashBytes), signSchema); + return new CosignatureSignedTransaction( + Convert.uint8ToHex(hashBytes), + Convert.uint8ToHex(signature), + account.publicKey, + ); } /** @@ -80,10 +81,16 @@ export class CosignatureTransaction { * @returns {CosignatureSignedTransaction} */ public signWith(account: Account, signSchema: SignSchema = SignSchema.SHA3): CosignatureSignedTransaction { - const aggregateSignatureTransaction = new CosignaturetransactionLibrary(this.transactionToCosign.transactionInfo!.hash); - const signedTransactionRaw = aggregateSignatureTransaction.signCosignatoriesTransaction(account, signSchema); - return new CosignatureSignedTransaction(signedTransactionRaw.parentHash, - signedTransactionRaw.signature, - signedTransactionRaw.signer); + if (!this.transactionToCosign.transactionInfo!.hash) { + throw new Error('Transaction to cosign should be announced first'); + } + const hash = this.transactionToCosign.transactionInfo!.hash; + const hashBytes = Convert.hexToUint8(hash ? hash : ''); + const signature = KeyPair.sign(account, new Uint8Array(hashBytes), signSchema); + return new CosignatureSignedTransaction( + hash ? hash : '', + Convert.uint8ToHex(signature), + account.publicKey, + ); } } diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index e34bb40489..b36810cf05 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/HashLockTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedHashLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder'; @@ -131,23 +129,6 @@ export class LockFundsTransaction extends Transaction { return byteSize + byteMosaicId + byteAmount + byteDuration + byteHash; } - /** - * @internal - * @return {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addType(this.type) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaic.id.id.toDTO()) - .addMosaicAmount(this.mosaic.amount.toDTO()) - .addDuration(this.duration.toDTO()) - .addHash(this.hash) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index fa1e35dfef..6fb31645ba 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -15,10 +15,9 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MultisigModificationTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { CosignatoryModificationBuilder } from '../../infrastructure/catbuffer/CosignatoryModificationBuilder'; +import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { MultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -32,7 +31,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; /** * Modify multisig account transactions are part of the NEM's multisig account system. @@ -125,21 +123,6 @@ export class ModifyMultisigAccountTransaction extends Transaction { return byteSize + byteRemovalDelta + byteApprovalDelta + byteNumModifications + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMinApprovalDelta(this.minApprovalDelta) - .addMinRemovalDelta(this.minRemovalDelta) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index 819d69c43c..f366fc0aed 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MosaicAddressRestrictionTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -142,23 +140,6 @@ export class MosaicAddressRestrictionTransaction extends Transaction { byteTargetAddress + bytePreviousRestrictionValue + byteNewRestrictionValue; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaicId.id.toDTO()) - .addRestrictionKey(this.restrictionKey.toDTO()) - .addTargetAddress(this.targetAddress.plain()) - .addPreviousRestrictionValue(this.previousRestrictionValue.toDTO()) - .addNewRestrictionValue(this.newRestrictionValue.toDTO()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index f822b73505..acffa89de0 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MosaicAliasTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; @@ -117,21 +115,6 @@ export class MosaicAliasTransaction extends Transaction { return byteSize + byteType + byteNamespaceId + byteMosaicId; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addAliasAction(this.aliasAction) - .addNamespaceId(this.namespaceId.id.toDTO()) - .addMosaicId(this.mosaicId.id.toDTO()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index c0adbd1e8b..9ebbf03fe6 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MosaicCreationTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedMosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder'; @@ -158,35 +156,6 @@ export class MosaicDefinitionTransaction extends Transaction { return GeneratorUtils.readUint32At(this.nonce.toDTO(), 0); } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - let mosaicDefinitionTransaction = new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addDivisibility(this.mosaicProperties.divisibility) - .addDuration(this.mosaicProperties.duration ? this.mosaicProperties.duration.toDTO() : []) - .addNonce(this.nonce.toDTO()) - .addMosaicId(this.mosaicId.id.toDTO()); - - if (this.mosaicProperties.supplyMutable === true) { - mosaicDefinitionTransaction = mosaicDefinitionTransaction.addSupplyMutable(); - } - - if (this.mosaicProperties.transferable === true) { - mosaicDefinitionTransaction = mosaicDefinitionTransaction.addTransferability(); - } - - if (this.mosaicProperties.restrictable === true) { - mosaicDefinitionTransaction = mosaicDefinitionTransaction.addRestrictable(); - } - - return mosaicDefinitionTransaction.build(); - } - /** * @internal * @returns {Uint8Array} @@ -207,7 +176,7 @@ export class MosaicDefinitionTransaction extends Transaction { this.getMosaicFlagValue(), this.mosaicProperties.divisibility, new BlockDurationDto(this.mosaicProperties.duration ? - this.mosaicProperties.duration.toDTO() : []), + this.mosaicProperties.duration.toDTO() : UInt64.fromUint(0).toDTO()), ); return transactionBuilder.serialize(); } @@ -226,7 +195,7 @@ export class MosaicDefinitionTransaction extends Transaction { this.getMosaicFlagValue(), this.mosaicProperties.divisibility, new BlockDurationDto(this.mosaicProperties.duration ? - this.mosaicProperties.duration.toDTO() : []), + this.mosaicProperties.duration.toDTO() : UInt64.fromUint(0).toDTO()), ); return transactionBuilder.serialize(); } diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index 7b4f757efc..9081fa5dbc 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MosaicGlobalRestrictionTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicGlobalRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -162,25 +160,6 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { bytePreviousRestrictionType; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaicId.id.toDTO()) - .addReferenceMosaicId(this.referenceMosaicId.id.toDTO()) - .addRestrictionKey(this.restrictionKey.toDTO()) - .addPreviousRestrictionValue(this.previousRestrictionValue.toDTO()) - .addPreviousRestrictionType(this.previousRestrictionType) - .addNewRestrictionValue(this.newRestrictionValue.toDTO()) - .addNewRestrictionType(this.newRestrictionType) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index be4f3a89a3..03f0137241 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { Builder } from '../../infrastructure/builders/MosaicSupplyChangeTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -33,7 +32,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { Convert } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -118,21 +116,6 @@ export class MosaicSupplyChangeTransaction extends Transaction { return byteSize + byteMosaicId + byteDirection + byteDelta; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaicId.id.toDTO()) - .addDirection(this.direction) - .addDelta(this.delta.toDTO()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index 0cdcae2aa6..3089126e25 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert, Convert as convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/NamespaceCreationTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedNamespaceRegistrationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder'; @@ -168,28 +166,6 @@ export class RegisterNamespaceTransaction extends Transaction { return byteSize + byteType + byteDurationParentId + byteNamespaceId + byteNameSize + byteName; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - let registerNamespacetransaction = new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addNamespaceType(this.namespaceType) - .addNamespaceId(this.namespaceId.id.toDTO()) - .addNamespaceName(this.namespaceName); - - if (this.namespaceType === NamespaceType.RootNamespace) { - registerNamespacetransaction = registerNamespacetransaction.addDuration(this.duration!.toDTO()); - } else { - registerNamespacetransaction = registerNamespacetransaction.addParentId(this.parentId!.id.toDTO()); - } - - return registerNamespacetransaction.build(); - } - /** * @internal * @returns {Uint8Array} @@ -238,7 +214,7 @@ export class RegisterNamespaceTransaction extends Transaction { transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), - TransactionType.SECRET_LOCK.valueOf(), + TransactionType.REGISTER_NAMESPACE.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), new BlockDurationDto(this.duration!.toDTO()), @@ -248,7 +224,7 @@ export class RegisterNamespaceTransaction extends Transaction { transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), - TransactionType.SECRET_LOCK.valueOf(), + TransactionType.REGISTER_NAMESPACE.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), undefined, diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index e65187384d..5efbe3c3fe 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -14,8 +14,6 @@ * limitations under the License. */ import { Convert as convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/SecretLockTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedSecretLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder'; @@ -155,25 +153,6 @@ export class SecretLockTransaction extends Transaction { return convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addType(this.type) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaic.id.id.toDTO()) - .addMosaicAmount(this.mosaic.amount.toDTO()) - .addDuration(this.duration.toDTO()) - .addHashAlgorithm(this.hashType) - .addSecret(this.secret) - .addRecipient(this.recipient.plain()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index 41df6b207b..cbca7576b2 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert, Convert as convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/SecretProofTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedSecretProofTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; @@ -140,23 +138,6 @@ export class SecretProofTransaction extends Transaction { return convert.hexToUint8(this.proof); } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addType(this.type) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addHashAlgorithm(this.hashType) - .addSecret(this.secret) - .addRecipient(this.recipient.plain()) - .addProof(this.proof) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index ca2fbbce44..29d3ae1b3d 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -16,7 +16,6 @@ import { KeyPair, SHA3Hasher, SignSchema } from '../../core/crypto'; import { Convert } from '../../core/format'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { SerializeTransactionToJSON } from '../../infrastructure/transaction/SerializeTransactionToJSON'; import { Account } from '../account/Account'; import { PublicAccount } from '../account/PublicAccount'; @@ -81,9 +80,27 @@ export abstract class Transaction { } /** - * @internal + * Generate transaction hash hex + * @param {string} transactionPayload HexString Payload + * @param {Array} generationHashBuffer Network generation hash byte + * @returns {string} Returns Transaction Payload hash */ - protected abstract buildTransaction(): VerifiableTransaction; + public static createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { + const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); + const signingBytes = byteBuffer + .slice(4, 36) + .concat(byteBuffer + .slice(4 + 64, 4 + 64 + 32)) + .concat(generationHashBuffer) + .concat(byteBuffer + .splice(4 + 64 + 32, byteBuffer.length)); + + const hash = new Uint8Array(32); + + SHA3Hasher.func(hash, signingBytes, 32); + + return Convert.uint8ToHex(hash); + } /** * @internal @@ -104,25 +121,6 @@ export abstract class Transaction { * @returns {SignedTransaction} */ public signWith(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { - const transaction = this.buildTransaction(); - const signedTransactionRaw = transaction.signTransaction(account, generationHash, signSchema); - return new SignedTransaction( - signedTransactionRaw.payload, - signedTransactionRaw.hash, - account.publicKey, - this.type, - this.networkType); - } - - /** - * @internal - * Serialize and sign transaction creating a new SignedTransaction - * @param account - The account to sign the transaction - * @param generationHash - Network generation hash hex - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {SignedTransaction} - */ - public signWithCatbuffer(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { const generationHashBytes = Array.from(Convert.hexToUint8(generationHash)); const byteBuffer = Array.from(this.generateBytes()); const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); @@ -137,41 +135,28 @@ export abstract class Transaction { const payload = Convert.uint8ToHex(signedTransactionBuffer); return new SignedTransaction( payload, - this.createTransactionHash(payload, generationHashBytes), + Transaction.createTransactionHash(payload, generationHashBytes), account.publicKey, this.type, this.networkType); } /** - * Generate transaction hash hex - * @param {string} transactionPayload HexString Payload - * @param {Array} generationHashBuffer Network generation hash byte - * @returns {string} Returns Transaction Payload hash - */ - public createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { - const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); - const signingBytes = byteBuffer - .slice(4, 36) - .concat(byteBuffer - .slice(4 + 64, 4 + 64 + 32)) - .concat(generationHashBuffer) - .concat(byteBuffer - .splice(4 + 64 + 32, byteBuffer.length)); - - const hash = new Uint8Array(32); - - SHA3Hasher.func(hash, signingBytes, 32); - - return Convert.uint8ToHex(hash); - } - - /** - * @internal - * @returns {Array} + * Converts the transaction into AggregateTransaction compatible + * @returns {Array.<*>} AggregateTransaction bytes */ public aggregateTransaction(): number[] { - return this.buildTransaction().toAggregateTransaction(this.signer!.publicKey); + const signer = Convert.hexToUint8(this.signer!.publicKey); + let resultBytes = Array.from(this.generateBytes()); + resultBytes.splice(0, 4 + 64 + 32); + resultBytes = Array.from(signer).concat(resultBytes); + resultBytes.splice(32 + 2 + 2, 16); + return Array.from((new Uint8Array([ + (resultBytes.length + 4 & 0x000000ff), + (resultBytes.length + 4 & 0x0000ff00) >> 8, + (resultBytes.length + 4 & 0x00ff0000) >> 16, + (resultBytes.length + 4 & 0xff000000) >> 24, + ]))).concat(resultBytes); } /** @@ -278,9 +263,8 @@ export abstract class Transaction { * @returns {string} * @memberof Transaction */ - public serialize() { - const transaction = this.buildTransaction(); - return transaction.serializeUnsignedTransaction(); + public serialize(): string { + return Convert.uint8ToHex(this.generateBytes()); } /** diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 6714fd7904..c78253b040 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -16,8 +16,6 @@ import { Convert, Convert as convert } from '../../core/format'; import { RawAddress } from '../../core/format/RawAddress'; -import { Builder } from '../../infrastructure/builders/TransferTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedTransferTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedTransferTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; @@ -145,6 +143,22 @@ export class TransferTransaction extends Transaction { return GeneratorUtils.concatTypedArrays(typeBuffer, payloadBuffer); } + /** + * Return unresolved address bytes of the recipient + * @internal + * @returns {string} + */ + public getRecipientBytes(): Uint8Array { + const recipient = this.recipientToString(); + if (/^[0-9a-fA-F]{16}$/.test(recipient)) { + // received hexadecimal notation of namespaceId (alias) + return RawAddress.aliasToRecipient(convert.hexToUint8(recipient)); + } else { + // received recipient address + return RawAddress.stringToAddress(recipient); + } + } + /** * @override Transaction.size() * @description get the byte size of a TransferTransaction @@ -167,21 +181,6 @@ export class TransferTransaction extends Transaction { return byteSize + byteRecipient + byteNumMosaics + bytePayload + byteMosaics; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRecipient(this.recipientToString()) - .addMosaics(this.mosaics.map((mosaic) => mosaic.toDTO())) - .addMessage(this.message) - .build(); - } - /** * @internal * @returns {Uint8Array} @@ -197,7 +196,7 @@ export class TransferTransaction extends Transaction { TransactionType.TRANSFER.valueOf(), new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), - new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), + new UnresolvedAddressDto(this.getRecipientBytes()), this.getMessageBuffer(), this.sortMosaics().map((mosaic) => { return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index 0d5b8c8b25..68c65c8eae 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountLinkTransaction', () => { expect(accountLinkTransaction.linkAction).to.be.equal(0); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); - const signedTransaction = accountLinkTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = accountLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 36dd3232a1..6291870102 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -162,7 +162,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = addressRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -204,7 +204,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = mosaicRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -246,7 +246,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = operationRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index 2721b583d9..59b1ce1144 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -80,12 +80,12 @@ describe('AddressAliasTransaction', () => { expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = addressAliasTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = addressAliasTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('002AD8FC018D9A49E19050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + )).to.be.equal('012AD8FC018D9A49E19050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); }); diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index d6a4c714aa..9334b7a15a 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -106,7 +106,7 @@ describe('AggregateTransaction', () => { NetworkType.MIJIN_TEST, []); - const signedTransaction = aggregateTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); @@ -166,12 +166,12 @@ describe('AggregateTransaction', () => { const signedTransaction = aggregateTransaction.signWith(account, generationHash); - expect(signedTransaction.payload.substring(0, 8)).to.be.equal('BC000000'); - expect(signedTransaction.payload.substring(240, 256)).to.be.equal('4000000040000000'); + expect(signedTransaction.payload.substring(0, 8)).to.be.equal('BA000000'); + expect(signedTransaction.payload.substring(240, 256)).to.be.equal('3E0000003E000000'); expect(signedTransaction.payload.substring( 320, signedTransaction.payload.length, - )).to.be.equal('01904D41E6DE84B8010000000000000001070302E803000000000000'); + )).to.be.equal('01904D41E6DE84B801000000000000000703E803000000000000'); }); it('should createComplete an AggregateTransaction object with MosaicSupplyChangeTransaction', () => { diff --git a/test/model/transaction/LockFundsTransaction.spec.ts b/test/model/transaction/LockFundsTransaction.spec.ts index df3583f1d7..779e6166d7 100644 --- a/test/model/transaction/LockFundsTransaction.spec.ts +++ b/test/model/transaction/LockFundsTransaction.spec.ts @@ -118,7 +118,7 @@ describe('LockFundsTransaction', () => { signedTransaction, NetworkType.MIJIN_TEST, ); - const signedTx = lockFundsTransaction.signWithCatbuffer(account, generationHash); + const signedTx = lockFundsTransaction.signWith(account, generationHash); expect(signedTx.payload.substring( 136, diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index f6232022da..041a685b6b 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -110,7 +110,7 @@ describe('ModifyMultisigAccountTransaction', () => { expect(modifyMultisigAccountTransaction.modifications[1].cosignatoryPublicAccount.publicKey) .to.be.equal('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); - const signedTransaction = modifyMultisigAccountTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts index 02aad2fc65..947904ce56 100644 --- a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts @@ -47,7 +47,7 @@ describe('MosaicAddressRestrictionTransaction', () => { expect(mosaicAddressRestrictionTransaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(8).toHex()); expect(mosaicAddressRestrictionTransaction.targetAddress.plain()).to.be.equal(account.address.plain()); - const signedTransaction = mosaicAddressRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicAddressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index a9314a0c54..34184eff95 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -80,12 +80,12 @@ describe('MosaicAliasTransaction', () => { expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); expect(mosaicAliasTransaction.mosaicId.id.higher).to.be.equal(3405110546); - const signedTransaction = mosaicAliasTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('002AD8FC018D9A49E14CCCD78612DDF5CA'); + )).to.be.equal('012AD8FC018D9A49E14CCCD78612DDF5CA'); }); diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index 688506516b..f444278cbe 100644 --- a/test/model/transaction/MosaicDefinitionTransaction.spec.ts +++ b/test/model/transaction/MosaicDefinitionTransaction.spec.ts @@ -64,7 +64,7 @@ describe('MosaicDefinitionTransaction', () => { duration: UInt64.fromUint(1000), }), NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(mosaicDefinitionTransaction.maxFee.higher).to.be.equal(0); @@ -93,7 +93,7 @@ describe('MosaicDefinitionTransaction', () => { expect(mosaicDefinitionTransaction.mosaicProperties.transferable).to.be.equal(true); expect(mosaicDefinitionTransaction.mosaicProperties.restrictable).to.be.equal(true); - const signedTransaction = mosaicDefinitionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -129,7 +129,7 @@ describe('MosaicDefinitionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('E6DE84B8010000000000000001000302E803000000000000'); + )).to.be.equal('E6DE84B801000000000000000003E803000000000000'); }); @@ -175,7 +175,7 @@ describe('MosaicDefinitionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('E6DE84B80100000000000000000003'); + )).to.be.equal('E6DE84B8010000000000000000030000000000000000'); }); }); diff --git a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts index 9e436d2fea..39c409bd22 100644 --- a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts @@ -54,7 +54,7 @@ describe('MosaicGlobalRestrictionTransaction', () => { expect(mosaicGlobalRestrictionTransaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.EQ); expect(mosaicGlobalRestrictionTransaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); - const signedTransaction = mosaicGlobalRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/RegisterNamespaceTransaction.spec.ts b/test/model/transaction/RegisterNamespaceTransaction.spec.ts index db497c73b9..dcd12d95f7 100644 --- a/test/model/transaction/RegisterNamespaceTransaction.spec.ts +++ b/test/model/transaction/RegisterNamespaceTransaction.spec.ts @@ -66,7 +66,7 @@ describe('RegisterNamespaceTransaction', () => { expect(registerNamespaceTransaction.duration!.lower).to.be.equal(1000); expect(registerNamespaceTransaction.duration!.higher).to.be.equal(0); - const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -83,7 +83,7 @@ describe('RegisterNamespaceTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/SecretLockTransaction.spec.ts b/test/model/transaction/SecretLockTransaction.spec.ts index 9f240dda47..9b5a00780d 100644 --- a/test/model/transaction/SecretLockTransaction.spec.ts +++ b/test/model/transaction/SecretLockTransaction.spec.ts @@ -101,7 +101,7 @@ describe('SecretLockTransaction', () => { recipient, NetworkType.MIJIN_TEST, ); - const signedTx = secretLockTransaction.signWithCatbuffer(account, generationHash); + const signedTx = secretLockTransaction.signWith(account, generationHash); expect(signedTx.payload.substring( 240, signedTx.payload.length, diff --git a/test/model/transaction/SecretProofTransaction.spec.ts b/test/model/transaction/SecretProofTransaction.spec.ts index 8712f1ca9e..951b1ab8f0 100644 --- a/test/model/transaction/SecretProofTransaction.spec.ts +++ b/test/model/transaction/SecretProofTransaction.spec.ts @@ -203,7 +203,7 @@ describe('SecretProofTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTx = secretProofTransaction.signWithCatbuffer(account, generationHash); + const signedTx = secretProofTransaction.signWith(account, generationHash); expect(signedTx.payload.substring( 240, signedTx.payload.length, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index 6f53048623..d0baad099a 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -15,7 +15,6 @@ */ import { expect } from 'chai'; -import { VerifiableTransaction } from '../../../src/infrastructure/builders/VerifiableTransaction'; import { Account } from '../../../src/model/account/Account'; import { Address } from '../../../src/model/account/Address'; import { NetworkType } from '../../../src/model/blockchain/NetworkType'; @@ -235,10 +234,6 @@ class FakeTransaction extends Transaction { throw new Error('Method not implemented.'); } - protected buildTransaction(): VerifiableTransaction { - throw new Error('Method not implemented.'); - } - protected generateBytes(): Uint8Array { throw new Error('Not implemented'); } diff --git a/test/model/transaction/TransferTransaction.spec.ts b/test/model/transaction/TransferTransaction.spec.ts index 63d8bb880c..969bf81a1b 100644 --- a/test/model/transaction/TransferTransaction.spec.ts +++ b/test/model/transaction/TransferTransaction.spec.ts @@ -210,7 +210,7 @@ describe('TransferTransaction', () => { expect(transferTransaction.recipient).to.be.instanceof(Address); expect((transferTransaction.recipient as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = transferTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = transferTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, From e8b5e8c83a122db3a32aad64d22257c74578c055 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 12:15:35 +0100 Subject: [PATCH 42/98] updated action types value --- src/model/account/RestrictionModificationType.ts | 4 ++-- src/model/mosaic/MosaicSupplyType.ts | 4 ++-- src/model/namespace/AliasAction.ts | 4 ++-- src/model/transaction/LinkAction.ts | 4 ++-- src/model/transaction/MultisigCosignatoryModificationType.ts | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/model/account/RestrictionModificationType.ts b/src/model/account/RestrictionModificationType.ts index b4aabd8151..a9aa625500 100644 --- a/src/model/account/RestrictionModificationType.ts +++ b/src/model/account/RestrictionModificationType.ts @@ -18,6 +18,6 @@ * Account restriction modification type */ export enum RestrictionModificationType { - Add = 0x00, - Remove = 0x01, + Add = 0x01, + Remove = 0x00, } diff --git a/src/model/mosaic/MosaicSupplyType.ts b/src/model/mosaic/MosaicSupplyType.ts index c5cf2655fa..0f28e995b0 100644 --- a/src/model/mosaic/MosaicSupplyType.ts +++ b/src/model/mosaic/MosaicSupplyType.ts @@ -20,6 +20,6 @@ * 1: Decrease in supply. */ export enum MosaicSupplyType { - Decrease = 0, - Increase = 1, + Decrease = 0x00, + Increase = 0x01, } diff --git a/src/model/namespace/AliasAction.ts b/src/model/namespace/AliasAction.ts index 27669a1d91..b107b0d65d 100644 --- a/src/model/namespace/AliasAction.ts +++ b/src/model/namespace/AliasAction.ts @@ -20,6 +20,6 @@ * 1: Unlink an alias. */ export enum AliasActionType { - Link = 1, - Unlink = 0, + Link = 0x01, + Unlink = 0x00, } diff --git a/src/model/transaction/LinkAction.ts b/src/model/transaction/LinkAction.ts index 678e1bb87d..212a0a9c80 100644 --- a/src/model/transaction/LinkAction.ts +++ b/src/model/transaction/LinkAction.ts @@ -15,6 +15,6 @@ */ export enum LinkAction { - Link = 0, - Unlink = 1, + Link = 0x01, + Unlink = 0x00, } diff --git a/src/model/transaction/MultisigCosignatoryModificationType.ts b/src/model/transaction/MultisigCosignatoryModificationType.ts index 7aa92781f7..2edfa42d01 100644 --- a/src/model/transaction/MultisigCosignatoryModificationType.ts +++ b/src/model/transaction/MultisigCosignatoryModificationType.ts @@ -20,6 +20,6 @@ * 1: Remove cosignatory. */ export enum MultisigCosignatoryModificationType { - Add = 0, - Remove = 1, + Add = 0x01, + Remove = 0x00, } From 3ff80fa29f2d1ad598ad1298e57737ba4e9e7025 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 12:16:52 +0100 Subject: [PATCH 43/98] restored network config for e2e --- e2e/conf/network.conf | 66 +++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index 79f895aecf..150443d82d 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -1,54 +1,54 @@ { - "apiUrl": "http://c2.nem.ninja:3000", - "generationHash": "57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6", + "apiUrl": "http://localhost:3000", + "generationHash": "5E34C898234E17E8553359D4DEAA123742C323F4C42758C511E6CC805934853E", "testAccount": { - "privateKey": "E1C8521608F4896CA26A0C2DE739310EA4B06861D126CF4D6922064678A1969B", - "address": "SAKT3CKHCYIG5BBOPTSY2WXSVPBSLIA67AEOX4ND", - "publicKey": "9F784BF20318AE3CA6246C0EC2207FE095FFF7A84B6787E7E3C2CE4C3B92A2EA" + "privateKey": "C422CC3C9257A1568036E1726E64EB5923C8363A13D4344F9E66CD89C8789BC7", + "address": "SAMA2UEQNAQ45DWYDNJVLPWKQJDAHFZIVLWACIGN", + "publicKey": "8A78C9E9B0E59D0F74C0D47AB29FBD523C706293A3FA9CD9FE0EEB2C10EA924A" }, "multisigAccount": { - "privateKey": "A9CEAA617D0B7D9DEBE9F96BD63CCF68A49950BB315CB9A4169FC6AAA1EC9E28", - "address": "SDWY3PYN4ZZO4S4EBEY2UPSSZUPGZH2G2LQMUSEU", - "publicKey": "8A613468924B8771779C7E4C889205A9BE6CAE0B9435B4BCC8E79A8DD8571608" + "privateKey": "F6815438AE34F95F2CF364B4679D16F3602CA2107073C0709738BAB457B09A45", + "publicKey": "FAF3F9FD3E32EB43273E5351BAE705D0179D37CBDCC4DD78A0C73232DD3EF32C", + "address": "SDC4BXKIIDBQA2CY6RPRFO3WLC5OZHLKLJJ3NFEH" }, "cosignatoryAccount": { - "privateKey": "8CBAA7491B7DC1070BECBC4F60AE55F4A272DA1DAD1D502DB016E142993817BA", - "address": "SB7Q5A3KEKFEWBPBTC6RFKU6Q2L4V7DM4ZNE4A7A", - "publicKey": "61B8EB2C02F3D3731A8EF6FE4CCD6BC84615BABA09CA3E891C0D2542096E6AD3" + "privateKey": "F48EA053D7D2B47DC518FDD69B338D34C819D9AC51E8754378F2D86FC29783C7", + "publicKey": "D9FB51DDFA64CC56D7AEBB32976DA8A3A72C8C7D02838AA1041046FA0883EBC6", + "address": "SCHNSELDJ7JN5MPHBOKHNBR2QRST4GOGEMS4XZNE" }, "cosignatory2Account": { - "privateKey": "60380027EBE63A5D60F6156F5637685172331705160783FF2F9D93C1E5A8622B", - "address": "SCM47E3JVPHOFWLSMNX3RKQQQIB3JUBR7MTX4M4P", - "publicKey": "3D9996683A0FA460D13288B846DF68A9B6C0C1F14EC2E43907DF8D84DC87B9C2" + "privateKey": "E697E9E0D849ACD3BD9379E80C4E953B23375112C28D983AF94160AD269BE327", + "publicKey": "2B4598150E66B26D991FA56FAF691C539FD1A92EBEA99E2AF91808B9C7C4316F", + "address": "SAWZITCY4TCOFBSSINFO4DQZTRBSB5W5OBSQE237" }, "cosignatory3Account": { - "privateKey": "E39CE241F730CD190658AFDB5F3896628F92D7BC35D88435D148BED88C6CC844", - "address": "SDEVG5MU4MEGJ72NSBC7PKMK7JCJKN7QB3DOVARJ", - "publicKey": "422697046582D8B8063931B7327D0C06FA454B416F6A5C000922EC5BA546F4B2" + "privateKey": "3F42F4308B3EA912A9FE482D6DD04CCFD8D37E4397BF9655AA2EF36894491CAB", + "publicKey": "26A339827614E7AEE9DB427323AA3A49A48456AA5656D9A2E1B50FF93DE90756", + "address": "SCGYYXGL3TLZBOA5TUCCQYIM6NSYSLVCBVHGYKKW" }, "cosignatory4Account": { - "privateKey": "0EA7E63C96FC580AD5EE85ED3C77A96B421F7C8BF75A83AB889313114C9082F2", - "address": "SCBNKMD23J7BO3Q42SEGP4LXGVJYSDPUESSEWGWZ", - "publicKey": "3A225A2C7C7D95279E74D420728D2DA2A176DE036B67909074AEF5F2DCFAF31C" + "privateKey": "53D6A6659A200DAF4930AD4C8A3B5B28ECAAA1F643E990C0A41C0B8EC9B3D05A", + "publicKey": "F721863CC533C3DF4429A957F822B986C81E62A91726A3E3BD0B861FA42F757D", + "address": "SD3JPQ2KXMQKLVOHJV7GTOYV73CL72ZSEOW7RIWE" }, "testAccount2": { - "privateKey": "A084418D937627BCDA19B277D8610C845124149FA18AABE96A17D56A2EA7FB8B", - "address": "SBF5HY3T7SXIBCSK4V4WNS4LS4QUMESMVNBCD2AQ", - "publicKey": "1C4B44400FDC933860B1949A5AEA756F19A36D73C4634699E49C3E7275EFA54F" + "privateKey": "F0AB1010EFEE19EE5373719881DF5123C13E643C519655F7E97347BFF77175BF", + "publicKey": "9DBF67474D6E1F8B131B4EB1F5BA0595AFFAE1123607BC1048F342193D7E669F", + "address": "SDBC4JE7GTJAKN2XJCQWWRJMYA35AFOYQBATXOUA" }, "testAccount3": { - "privateKey": "8C9E72C5D8964A19174B478B65BD4B7F2AFD8F92C05AE45B15A9EDF222EC8CA8", - "address": "SDY65GIMMOF7GZGGART66QGS6ELWDTQT55JJOF42", - "publicKey": "B8320002C5CF64D855F073F2387FB18F13E7A04FA57FC3743694B04579104F98" + "privateKey": "61C3C8F24E3708CFE17A64B66EBD29D747326DBF7962EBEE9340439725C04F11", + "publicKey": "399C1D18FDE3293DCF7BF522626266663C83453BDF7D38C9E96AFC795C07E0A2", + "address": "SC7PPZRJMEMQ7S32PURJTTNHOATDYQ4NPRFOAOUO" }, "testAccountNoBalance": { - "privateKey": "CE4E6B1113EF8999ED79A027A4F3255C367BC2E40417E27E614FB7C12E42BDFA", - "address": "SDNMDW5TXIORKRXQ7F3QORRW4KUAK4ALQ7JWX2KJ", - "publicKey": "92658FE642AEAF1B766D0F4FE4E263C3A0E069735836383D31A70E2B7801358B" + "privateKey": "6530E5ED4B6D32CB9AF2EE09D2889DC781C569B83C137854EDC7773B057074A1", + "publicKey": "559019D82C4CACAAE616A024544251D58BB4464CD36407224475A577F9649E78", + "address": "SCQP4B6BDNH5MZHTLL2ZNXIPYSLD5BU4NDXBZXNK" }, "harvestingAccount": { - "privateKey": "9999630E4AE5CA5675A703F3268084EB9A9B477A8C519D66465D5D21830E691A", - "address": "SC2PGQO5WV4QZRAQHJDNQ2Q5IFWA2D3VLFEFFZHC", - "publicKey": "74771A0B0B920D787F4F8242926C348007B23062910DE99C7E56AA79D4D7B90A" + "privateKey": "AF39DCC819388A2CE9DC0922730D7579588571A63F349A0FB1BC44807C926E53", + "publicKey": "FAEDB16763F22870B75BF934EA5F2792BDF109EC0C504718DDCBD92DF13C2628", + "address": "SCNPFCWFV2FYQVMU5HMJJTMADRZ3LRXVA76F56N2" } -} +} \ No newline at end of file From 18e0cae992c075158ce12628e8d991a292078cc4 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 12:22:36 +0100 Subject: [PATCH 44/98] Fixed unit tests after swapping action type value --- test/core/utils/TransactionMapping.spec.ts | 2 +- test/model/transaction/AccountLinkTransaction.spec.ts | 10 +++++----- .../transaction/AccountRestrictionTransaction.spec.ts | 6 +++--- test/model/transaction/AggregateTransaction.spec.ts | 4 ++-- .../ModifyMultisigAccountTransaction.spec.ts | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index 1061991cb6..d07628b97e 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -498,7 +498,7 @@ describe('TransactionMapping - createFromPayload', () => { const signedTransaction = accountLinkTransaction.signWith(account, generationHash); const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AccountLinkTransaction; - expect(transaction.linkAction).to.be.equal(0); + expect(transaction.linkAction).to.be.equal(1); expect(transaction.remoteAccountKey).to.be.equal(account.publicKey); }); diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index 68c65c8eae..ec2fe1630d 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -48,7 +48,7 @@ describe('AccountLinkTransaction', () => { account.publicKey, LinkAction.Link, NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(accountLinkTransaction.maxFee.higher).to.be.equal(0); @@ -63,7 +63,7 @@ describe('AccountLinkTransaction', () => { NetworkType.MIJIN_TEST, ); - expect(accountLinkTransaction.linkAction).to.be.equal(0); + expect(accountLinkTransaction.linkAction).to.be.equal(1); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); const signedTransaction = accountLinkTransaction.signWith(account, generationHash); @@ -71,7 +71,7 @@ describe('AccountLinkTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE00'); + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE01'); }); it('should create an AccountLinkTransaction object with unlink action', () => { @@ -82,7 +82,7 @@ describe('AccountLinkTransaction', () => { NetworkType.MIJIN_TEST, ); - expect(accountLinkTransaction.linkAction).to.be.equal(1); + expect(accountLinkTransaction.linkAction).to.be.equal(0); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); const signedTransaction = accountLinkTransaction.signWith(account, generationHash); @@ -90,7 +90,7 @@ describe('AccountLinkTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE01'); + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE00'); }); describe('size', () => { diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 6291870102..550ee81fc1 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -167,7 +167,7 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('0101009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + )).to.be.equal('0101019050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); }); @@ -209,7 +209,7 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('0201004CCCD78612DDF5CA'); + )).to.be.equal('0201014CCCD78612DDF5CA'); }); @@ -251,7 +251,7 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('0401004E42'); + )).to.be.equal('0401014E42'); }); }); diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 9334b7a15a..072302eba9 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -232,8 +232,8 @@ describe('AggregateTransaction', () => { expect(signedTransaction.payload.substring( 320, signedTransaction.payload.length, - )).to.be.equal('0190554101020200B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC240' + - '0B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); + )).to.be.equal('0190554101020201B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC2401B1B5581FC81A69' + + '70DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); }); it('should createComplete an AggregateTransaction object with different cosignatories', () => { diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index 041a685b6b..00afd72d47 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -115,8 +115,8 @@ describe('ModifyMultisigAccountTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('01020200B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC' + - '6EC2400B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); + )).to.be.equal('01020201B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC2401B1' + + 'B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); }); From 6c40ea5cb1b2c5966dce913e149dd1c855bc7b64 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 21:43:04 +0100 Subject: [PATCH 45/98] Added ts catbuffer codes (without aggregateTx) Appended new signwithCatbuffer method in Transaction (temp) Applied catbuffer builders on standalone transaction (builder) Updated unit tests --- .../AccountOperationRestrictionTransaction.ts | 7 ++ .../transaction/AddressAliasTransaction.ts | 1 + .../MosaicDefinitionTransaction.ts | 13 ++++ src/model/transaction/Transaction.ts | 66 ++++++++++++++++++- .../AccountLinkTransaction.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 6 +- .../AddressAliasTransaction.spec.ts | 2 +- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- .../MosaicAliasTransaction.spec.ts | 2 +- .../MosaicDefinitionTransaction.spec.ts | 2 +- test/model/transaction/Transaction.spec.ts | 4 ++ 11 files changed, 97 insertions(+), 10 deletions(-) diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index 3ee53a4b4d..07e19502f9 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -32,6 +32,13 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; export class AccountOperationRestrictionTransaction extends Transaction { diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 1ad4e6b61f..df00bd57bb 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -35,6 +35,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { RawAddress } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 9ebbf03fe6..e798b92770 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -37,6 +37,19 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; +import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; +import { MosaicFlagsDto } from '../../infrastructure/catbuffer/MosaicFlagsDto'; +import { MosaicFlags } from '../mosaic/MosaicFlag'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { Convert } from '../../core/format'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; /** * Before a mosaic can be created or transferred, a corresponding definition of the mosaic has to be created and published to the network. diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index 29d3ae1b3d..61dcccce4e 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -112,6 +112,16 @@ export abstract class Transaction { */ protected abstract generateEmbeddedBytes(): Uint8Array; + /** + * @internal + */ + protected abstract buildTransaction(): VerifiableTransaction; + + /** + * @internal + */ + protected abstract generateBytes(): Uint8Array; + /** * @internal * Serialize and sign transaction creating a new SignedTransaction @@ -142,8 +152,60 @@ export abstract class Transaction { } /** - * Converts the transaction into AggregateTransaction compatible - * @returns {Array.<*>} AggregateTransaction bytes + * @internal + * Serialize and sign transaction creating a new SignedTransaction + * @param account - The account to sign the transaction + * @param generationHash - Network generation hash hex + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {SignedTransaction} + */ + public signWithCatbuffer(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { + const generationHashBytes = Array.from(Convert.hexToUint8(generationHash)); + const byteBuffer = Array.from(this.generateBytes()); + const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); + const keyPairEncoded = KeyPair.createKeyPairFromPrivateKeyString(account.privateKey, signSchema); + const signature = Array.from(KeyPair.sign(account, new Uint8Array(signingBytes), signSchema)); + const signedTransactionBuffer = byteBuffer + .splice(0, 4) + .concat(signature) + .concat(Array.from(keyPairEncoded.publicKey)) + .concat(byteBuffer + .splice(64 + 32, byteBuffer.length)); + const payload = Convert.uint8ToHex(signedTransactionBuffer); + return new SignedTransaction( + payload, + this.createTransactionHash(payload, generationHashBytes), + account.publicKey, + this.type, + this.networkType); + } + + /** + * Generate transaction hash hex + * @param {string} transactionPayload HexString Payload + * @param {Array} generationHashBuffer Network generation hash byte + * @returns {string} Returns Transaction Payload hash + */ + public createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { + const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); + const signingBytes = byteBuffer + .slice(4, 36) + .concat(byteBuffer + .slice(4 + 64, 4 + 64 + 32)) + .concat(generationHashBuffer) + .concat(byteBuffer + .splice(4 + 64 + 32, byteBuffer.length)); + + const hash = new Uint8Array(32); + + SHA3Hasher.func(hash, signingBytes, 32); + + return Convert.uint8ToHex(hash); + } + + /** + * @internal + * @returns {Array} */ public aggregateTransaction(): number[] { const signer = Convert.hexToUint8(this.signer!.publicKey); diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index ec2fe1630d..a6e52cc69c 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountLinkTransaction', () => { expect(accountLinkTransaction.linkAction).to.be.equal(1); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); - const signedTransaction = accountLinkTransaction.signWith(account, generationHash); + const signedTransaction = accountLinkTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 550ee81fc1..5da071f34d 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -162,7 +162,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = addressRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -204,7 +204,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -246,7 +246,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = operationRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index 59b1ce1144..1229abc20b 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('AddressAliasTransaction', () => { expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = addressAliasTransaction.signWith(account, generationHash); + const signedTransaction = addressAliasTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index 00afd72d47..4943e33e1f 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -110,7 +110,7 @@ describe('ModifyMultisigAccountTransaction', () => { expect(modifyMultisigAccountTransaction.modifications[1].cosignatoryPublicAccount.publicKey) .to.be.equal('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); - const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); + const signedTransaction = modifyMultisigAccountTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index 34184eff95..e2b8fffd90 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('MosaicAliasTransaction', () => { expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); expect(mosaicAliasTransaction.mosaicId.id.higher).to.be.equal(3405110546); - const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); + const signedTransaction = mosaicAliasTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index f444278cbe..52481c3ee8 100644 --- a/test/model/transaction/MosaicDefinitionTransaction.spec.ts +++ b/test/model/transaction/MosaicDefinitionTransaction.spec.ts @@ -93,7 +93,7 @@ describe('MosaicDefinitionTransaction', () => { expect(mosaicDefinitionTransaction.mosaicProperties.transferable).to.be.equal(true); expect(mosaicDefinitionTransaction.mosaicProperties.restrictable).to.be.equal(true); - const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicDefinitionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index d0baad099a..7488e3ca3d 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -241,4 +241,8 @@ class FakeTransaction extends Transaction { protected generateEmbeddedBytes(): Uint8Array { throw new Error('Not implemented'); } + + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } From 37f4eb0126b763c49a4506d4d840392e571e627d Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 23:43:48 +0100 Subject: [PATCH 46/98] Added embedded transaction builders --- .../AccountOperationRestrictionTransaction.ts | 7 ---- .../transaction/AddressAliasTransaction.ts | 1 - src/model/transaction/AggregateTransaction.ts | 8 +++++ .../ModifyMultisigAccountTransaction.ts | 1 + .../MosaicDefinitionTransaction.ts | 34 ++++++++++++------- src/model/transaction/Transaction.ts | 5 +++ src/model/transaction/TransferTransaction.ts | 20 +++++++++++ ...osaicAddressRestrictionTransaction.spec.ts | 2 +- ...MosaicGlobalRestrictionTransaction.spec.ts | 2 +- .../RegisterNamespaceTransaction.spec.ts | 4 +-- test/model/transaction/Transaction.spec.ts | 4 +++ 11 files changed, 63 insertions(+), 25 deletions(-) diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index 07e19502f9..3ee53a4b4d 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -32,13 +32,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; -import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; -import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; -import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; -import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; export class AccountOperationRestrictionTransaction extends Transaction { diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index df00bd57bb..1ad4e6b61f 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -35,7 +35,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { RawAddress } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 608559f663..d30c0f3199 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -261,4 +261,12 @@ export class AggregateTransaction extends Transaction { protected generateEmbeddedBytes(): Uint8Array { throw new Error('Method not implemented'); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index 6fb31645ba..c4e78b7f8e 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -31,6 +31,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; /** * Modify multisig account transactions are part of the NEM's multisig account system. diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index e798b92770..80b500c37c 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -37,19 +37,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; -import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; -import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; -import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; -import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; -import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; -import { MosaicFlagsDto } from '../../infrastructure/catbuffer/MosaicFlagsDto'; -import { MosaicFlags } from '../mosaic/MosaicFlag'; -import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; -import { Convert } from '../../core/format'; -import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; /** * Before a mosaic can be created or transferred, a corresponding definition of the mosaic has to be created and published to the network. @@ -212,4 +199,25 @@ export class MosaicDefinitionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicDefinitionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_DEFINITION.valueOf(), + new MosaicNonceDto(this.getMosaicNonceIntValue()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + this.getMosaicFlagValue(), + this.mosaicProperties.divisibility, + new BlockDurationDto(this.mosaicProperties.duration ? + this.mosaicProperties.duration.toDTO() : []), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index 61dcccce4e..fa21463874 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -122,6 +122,11 @@ export abstract class Transaction { */ protected abstract generateBytes(): Uint8Array; + /** + * @internal + */ + protected abstract generateEmbeddedBytes(): Uint8Array; + /** * @internal * Serialize and sign transaction creating a new SignedTransaction diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index c78253b040..3be49fd266 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -224,4 +224,24 @@ export class TransferTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const transactionBuilder = new EmbeddedTransferTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.TRANSFER.valueOf(), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), + this.getMessageBuffer(), + this.sortMosaics().map((mosaic) => { + return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), + new AmountDto(mosaic.amount.toDTO())); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts index 947904ce56..02aad2fc65 100644 --- a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts @@ -47,7 +47,7 @@ describe('MosaicAddressRestrictionTransaction', () => { expect(mosaicAddressRestrictionTransaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(8).toHex()); expect(mosaicAddressRestrictionTransaction.targetAddress.plain()).to.be.equal(account.address.plain()); - const signedTransaction = mosaicAddressRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicAddressRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts index 39c409bd22..9e436d2fea 100644 --- a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts @@ -54,7 +54,7 @@ describe('MosaicGlobalRestrictionTransaction', () => { expect(mosaicGlobalRestrictionTransaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.EQ); expect(mosaicGlobalRestrictionTransaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); - const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicGlobalRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/RegisterNamespaceTransaction.spec.ts b/test/model/transaction/RegisterNamespaceTransaction.spec.ts index dcd12d95f7..db497c73b9 100644 --- a/test/model/transaction/RegisterNamespaceTransaction.spec.ts +++ b/test/model/transaction/RegisterNamespaceTransaction.spec.ts @@ -66,7 +66,7 @@ describe('RegisterNamespaceTransaction', () => { expect(registerNamespaceTransaction.duration!.lower).to.be.equal(1000); expect(registerNamespaceTransaction.duration!.higher).to.be.equal(0); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -83,7 +83,7 @@ describe('RegisterNamespaceTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index 7488e3ca3d..cec65bb6e0 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -245,4 +245,8 @@ class FakeTransaction extends Transaction { protected generateBytes(): Uint8Array { throw new Error('Not implemented'); } + + protected generateEmbeddedBytes(): Uint8Array { + throw new Error('Not implemented'); + } } From 4cab9e6cbff615ce06aa16b87ea8459ce02fa1be Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 08:26:17 +0100 Subject: [PATCH 47/98] Applied catbuffer on aggregate transaction --- src/model/transaction/AggregateTransaction.ts | 2 +- src/model/transaction/MosaicDefinitionTransaction.ts | 4 +--- src/model/transaction/MosaicSupplyChangeTransaction.ts | 1 + src/model/transaction/TransferTransaction.ts | 3 +-- test/model/transaction/AggregateTransaction.spec.ts | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index d30c0f3199..55796be64e 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -267,6 +267,6 @@ export class AggregateTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - throw new Error('Not implemented'); + throw new Error('Method not implemented'); } } diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 80b500c37c..03715779ea 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -205,10 +205,8 @@ export class MosaicDefinitionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicDefinitionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_DEFINITION.valueOf(), new MosaicNonceDto(this.getMosaicNonceIntValue()), diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index 03f0137241..09af28af07 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -32,6 +32,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { Convert } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 3be49fd266..84d69dd037 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -230,9 +230,8 @@ export class TransferTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); const transactionBuilder = new EmbeddedTransferTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.TRANSFER.valueOf(), new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 072302eba9..0da5aa60c9 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -106,7 +106,7 @@ describe('AggregateTransaction', () => { NetworkType.MIJIN_TEST, []); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); + const signedTransaction = aggregateTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); From a2655c1c0ea8edc6711588d8480d6f9285ca1210 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 11:46:27 +0100 Subject: [PATCH 48/98] Removed old flatbuffer staffs --- e2e/conf/network.conf | 2 +- .../ModifyMultisigAccountTransaction.ts | 1 - .../MosaicDefinitionTransaction.ts | 19 ----- .../MosaicSupplyChangeTransaction.ts | 1 - src/model/transaction/Transaction.ts | 71 +------------------ src/model/transaction/TransferTransaction.ts | 19 ----- .../AccountLinkTransaction.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 6 +- .../AddressAliasTransaction.spec.ts | 2 +- .../transaction/AggregateTransaction.spec.ts | 2 +- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- ...osaicAddressRestrictionTransaction.spec.ts | 2 +- .../MosaicAliasTransaction.spec.ts | 2 +- .../MosaicDefinitionTransaction.spec.ts | 2 +- ...MosaicGlobalRestrictionTransaction.spec.ts | 2 +- .../RegisterNamespaceTransaction.spec.ts | 4 +- test/model/transaction/Transaction.spec.ts | 8 --- 17 files changed, 16 insertions(+), 131 deletions(-) diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index 150443d82d..a19e2213f0 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -51,4 +51,4 @@ "publicKey": "FAEDB16763F22870B75BF934EA5F2792BDF109EC0C504718DDCBD92DF13C2628", "address": "SCNPFCWFV2FYQVMU5HMJJTMADRZ3LRXVA76F56N2" } -} \ No newline at end of file +} diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index c4e78b7f8e..6fb31645ba 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -31,7 +31,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; /** * Modify multisig account transactions are part of the NEM's multisig account system. diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 03715779ea..9ebbf03fe6 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -199,23 +199,4 @@ export class MosaicDefinitionTransaction extends Transaction { ); return transactionBuilder.serialize(); } - - /** - * @internal - * @returns {Uint8Array} - */ - protected generateEmbeddedBytes(): Uint8Array { - const transactionBuilder = new EmbeddedMosaicDefinitionTransactionBuilder( - new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), - this.versionToDTO(), - TransactionType.MOSAIC_DEFINITION.valueOf(), - new MosaicNonceDto(this.getMosaicNonceIntValue()), - new MosaicIdDto(this.mosaicId.id.toDTO()), - this.getMosaicFlagValue(), - this.mosaicProperties.divisibility, - new BlockDurationDto(this.mosaicProperties.duration ? - this.mosaicProperties.duration.toDTO() : []), - ); - return transactionBuilder.serialize(); - } } diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index 09af28af07..03f0137241 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -32,7 +32,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { Convert } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index fa21463874..29d3ae1b3d 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -112,21 +112,6 @@ export abstract class Transaction { */ protected abstract generateEmbeddedBytes(): Uint8Array; - /** - * @internal - */ - protected abstract buildTransaction(): VerifiableTransaction; - - /** - * @internal - */ - protected abstract generateBytes(): Uint8Array; - - /** - * @internal - */ - protected abstract generateEmbeddedBytes(): Uint8Array; - /** * @internal * Serialize and sign transaction creating a new SignedTransaction @@ -157,60 +142,8 @@ export abstract class Transaction { } /** - * @internal - * Serialize and sign transaction creating a new SignedTransaction - * @param account - The account to sign the transaction - * @param generationHash - Network generation hash hex - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {SignedTransaction} - */ - public signWithCatbuffer(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { - const generationHashBytes = Array.from(Convert.hexToUint8(generationHash)); - const byteBuffer = Array.from(this.generateBytes()); - const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); - const keyPairEncoded = KeyPair.createKeyPairFromPrivateKeyString(account.privateKey, signSchema); - const signature = Array.from(KeyPair.sign(account, new Uint8Array(signingBytes), signSchema)); - const signedTransactionBuffer = byteBuffer - .splice(0, 4) - .concat(signature) - .concat(Array.from(keyPairEncoded.publicKey)) - .concat(byteBuffer - .splice(64 + 32, byteBuffer.length)); - const payload = Convert.uint8ToHex(signedTransactionBuffer); - return new SignedTransaction( - payload, - this.createTransactionHash(payload, generationHashBytes), - account.publicKey, - this.type, - this.networkType); - } - - /** - * Generate transaction hash hex - * @param {string} transactionPayload HexString Payload - * @param {Array} generationHashBuffer Network generation hash byte - * @returns {string} Returns Transaction Payload hash - */ - public createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { - const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); - const signingBytes = byteBuffer - .slice(4, 36) - .concat(byteBuffer - .slice(4 + 64, 4 + 64 + 32)) - .concat(generationHashBuffer) - .concat(byteBuffer - .splice(4 + 64 + 32, byteBuffer.length)); - - const hash = new Uint8Array(32); - - SHA3Hasher.func(hash, signingBytes, 32); - - return Convert.uint8ToHex(hash); - } - - /** - * @internal - * @returns {Array} + * Converts the transaction into AggregateTransaction compatible + * @returns {Array.<*>} AggregateTransaction bytes */ public aggregateTransaction(): number[] { const signer = Convert.hexToUint8(this.signer!.publicKey); diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 84d69dd037..c78253b040 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -224,23 +224,4 @@ export class TransferTransaction extends Transaction { ); return transactionBuilder.serialize(); } - - /** - * @internal - * @returns {Uint8Array} - */ - protected generateEmbeddedBytes(): Uint8Array { - const transactionBuilder = new EmbeddedTransferTransactionBuilder( - new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), - this.versionToDTO(), - TransactionType.TRANSFER.valueOf(), - new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), - this.getMessageBuffer(), - this.sortMosaics().map((mosaic) => { - return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), - new AmountDto(mosaic.amount.toDTO())); - }), - ); - return transactionBuilder.serialize(); - } } diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index a6e52cc69c..ec2fe1630d 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountLinkTransaction', () => { expect(accountLinkTransaction.linkAction).to.be.equal(1); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); - const signedTransaction = accountLinkTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = accountLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 5da071f34d..550ee81fc1 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -162,7 +162,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = addressRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -204,7 +204,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = mosaicRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -246,7 +246,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = operationRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index 1229abc20b..59b1ce1144 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('AddressAliasTransaction', () => { expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = addressAliasTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = addressAliasTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 0da5aa60c9..072302eba9 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -106,7 +106,7 @@ describe('AggregateTransaction', () => { NetworkType.MIJIN_TEST, []); - const signedTransaction = aggregateTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index 4943e33e1f..00afd72d47 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -110,7 +110,7 @@ describe('ModifyMultisigAccountTransaction', () => { expect(modifyMultisigAccountTransaction.modifications[1].cosignatoryPublicAccount.publicKey) .to.be.equal('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); - const signedTransaction = modifyMultisigAccountTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts index 02aad2fc65..947904ce56 100644 --- a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts @@ -47,7 +47,7 @@ describe('MosaicAddressRestrictionTransaction', () => { expect(mosaicAddressRestrictionTransaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(8).toHex()); expect(mosaicAddressRestrictionTransaction.targetAddress.plain()).to.be.equal(account.address.plain()); - const signedTransaction = mosaicAddressRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicAddressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index e2b8fffd90..34184eff95 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('MosaicAliasTransaction', () => { expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); expect(mosaicAliasTransaction.mosaicId.id.higher).to.be.equal(3405110546); - const signedTransaction = mosaicAliasTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index 52481c3ee8..f444278cbe 100644 --- a/test/model/transaction/MosaicDefinitionTransaction.spec.ts +++ b/test/model/transaction/MosaicDefinitionTransaction.spec.ts @@ -93,7 +93,7 @@ describe('MosaicDefinitionTransaction', () => { expect(mosaicDefinitionTransaction.mosaicProperties.transferable).to.be.equal(true); expect(mosaicDefinitionTransaction.mosaicProperties.restrictable).to.be.equal(true); - const signedTransaction = mosaicDefinitionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts index 9e436d2fea..39c409bd22 100644 --- a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts @@ -54,7 +54,7 @@ describe('MosaicGlobalRestrictionTransaction', () => { expect(mosaicGlobalRestrictionTransaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.EQ); expect(mosaicGlobalRestrictionTransaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); - const signedTransaction = mosaicGlobalRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/RegisterNamespaceTransaction.spec.ts b/test/model/transaction/RegisterNamespaceTransaction.spec.ts index db497c73b9..dcd12d95f7 100644 --- a/test/model/transaction/RegisterNamespaceTransaction.spec.ts +++ b/test/model/transaction/RegisterNamespaceTransaction.spec.ts @@ -66,7 +66,7 @@ describe('RegisterNamespaceTransaction', () => { expect(registerNamespaceTransaction.duration!.lower).to.be.equal(1000); expect(registerNamespaceTransaction.duration!.higher).to.be.equal(0); - const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -83,7 +83,7 @@ describe('RegisterNamespaceTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index cec65bb6e0..d0baad099a 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -241,12 +241,4 @@ class FakeTransaction extends Transaction { protected generateEmbeddedBytes(): Uint8Array { throw new Error('Not implemented'); } - - protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); - } - - protected generateEmbeddedBytes(): Uint8Array { - throw new Error('Not implemented'); - } } From 27d95fc271d7490b27a69cf131cc7b20788c6866 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 12:16:52 +0100 Subject: [PATCH 49/98] restored network config for e2e --- e2e/conf/network.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index a19e2213f0..150443d82d 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -51,4 +51,4 @@ "publicKey": "FAEDB16763F22870B75BF934EA5F2792BDF109EC0C504718DDCBD92DF13C2628", "address": "SCNPFCWFV2FYQVMU5HMJJTMADRZ3LRXVA76F56N2" } -} +} \ No newline at end of file From 9dfc574922163752a8748a2037a1c3e7cedf9007 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 14 Aug 2019 12:02:30 +0100 Subject: [PATCH 50/98] Fixed merged conflic issues --- src/model/namespace/AliasAction.ts | 2 +- src/model/transaction/AddressAliasTransaction.ts | 4 ++-- src/model/transaction/ModifyMultisigAccountTransaction.ts | 4 ++-- src/model/transaction/MosaicAliasTransaction.ts | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/model/namespace/AliasAction.ts b/src/model/namespace/AliasAction.ts index b107b0d65d..7d81578751 100644 --- a/src/model/namespace/AliasAction.ts +++ b/src/model/namespace/AliasAction.ts @@ -19,7 +19,7 @@ * 0: Link an alias. * 1: Unlink an alias. */ -export enum AliasActionType { +export enum AliasAction { Link = 0x01, Unlink = 0x00, } diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 1ad4e6b61f..1faaeaa7dc 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -134,7 +134,7 @@ export class AddressAliasTransaction extends Transaction { TransactionType.ADDRESS_ALIAS.valueOf(), new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), - this.actionType.valueOf(), + this.aliasAction.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), new AddressDto(RawAddress.stringToAddress(this.address.plain())), ); @@ -150,7 +150,7 @@ export class AddressAliasTransaction extends Transaction { new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ADDRESS_ALIAS.valueOf(), - this.actionType.valueOf(), + this.aliasAction.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), new AddressDto(RawAddress.stringToAddress(this.address.plain())), ); diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index 6fb31645ba..835b117f13 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -142,7 +142,7 @@ export class ModifyMultisigAccountTransaction extends Transaction { this.minApprovalDelta, this.modifications.map((modification) => { return new CosignatoryModificationBuilder( - modification.type.valueOf(), + modification.modificiationType.valueOf(), new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)), ); }), @@ -163,7 +163,7 @@ export class ModifyMultisigAccountTransaction extends Transaction { this.minApprovalDelta, this.modifications.map((modification) => { return new CosignatoryModificationBuilder( - modification.type.valueOf(), + modification.modificiationType.valueOf(), new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)), ); }), diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index acffa89de0..447d5530ad 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -130,7 +130,7 @@ export class MosaicAliasTransaction extends Transaction { TransactionType.MOSAIC_ALIAS.valueOf(), new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), - this.actionType.valueOf(), + this.aliasAction.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), new MosaicIdDto(this.mosaicId.id.toDTO()), ); @@ -146,7 +146,7 @@ export class MosaicAliasTransaction extends Transaction { new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_ALIAS.valueOf(), - this.actionType.valueOf(), + this.aliasAction.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), new MosaicIdDto(this.mosaicId.id.toDTO()), ); From 9df0aa1e8c8702e6a38ae49f4eb155752133c361 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 15 Aug 2019 12:12:33 +0100 Subject: [PATCH 51/98] Refactored TransactionMapping - createTransactionFromPayload now use catbuffer --- src/core/format/Convert.ts | 18 + src/core/utils/TransactionMapping.ts | 14 +- .../catbuffer/GeneratorUtils.ts | 172 +++--- .../CreateTransactionFromPayload.ts | 498 ++---------------- .../AccountAddressRestrictionTransaction.ts | 35 +- .../transaction/AccountLinkTransaction.ts | 26 + .../AccountMosaicRestrictionTransaction.ts | 33 ++ .../AccountOperationRestrictionTransaction.ts | 32 ++ .../transaction/AddressAliasTransaction.ts | 29 +- src/model/transaction/AggregateTransaction.ts | 60 ++- src/model/transaction/LockFundsTransaction.ts | 32 ++ .../ModifyMultisigAccountTransaction.ts | 36 ++ .../MosaicAddressRestrictionTransaction.ts | 30 ++ .../transaction/MosaicAliasTransaction.ts | 27 + .../MosaicDefinitionTransaction.ts | 34 ++ .../MosaicGlobalRestrictionTransaction.ts | 32 ++ .../MosaicSupplyChangeTransaction.ts | 28 + .../RegisterNamespaceTransaction.ts | 36 ++ .../transaction/SecretLockTransaction.ts | 36 +- .../transaction/SecretProofTransaction.ts | 29 + src/model/transaction/TransferTransaction.ts | 40 ++ 21 files changed, 714 insertions(+), 563 deletions(-) diff --git a/src/core/format/Convert.ts b/src/core/format/Convert.ts index f45b7b9eac..7d9939d084 100644 --- a/src/core/format/Convert.ts +++ b/src/core/format/Convert.ts @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { decode } from 'utf8'; import * as utilities from './Utilities'; export class Convert { @@ -172,4 +173,21 @@ export class Convert { } return result; } + + /** + * @internal decode hex to uft8 string + * @param hex - Hex input + * @returns {string} + */ + public static decodeHex = (hex: string): string => { + let str = ''; + for (let i = 0; i < hex.length; i += 2) { + str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); + } + try { + return decode(str); + } catch (e) { + return str; + } + } } diff --git a/src/core/utils/TransactionMapping.ts b/src/core/utils/TransactionMapping.ts index 7c13ae044f..7c4c36a0e4 100644 --- a/src/core/utils/TransactionMapping.ts +++ b/src/core/utils/TransactionMapping.ts @@ -16,7 +16,9 @@ import { CreateTransactionFromDTO } from '../../infrastructure/transaction/CreateTransactionFromDTO'; import { CreateTransactionFromPayload } from '../../infrastructure/transaction/CreateTransactionFromPayload'; +import { InnerTransaction } from '../../model/transaction/InnerTransaction'; import { Transaction } from '../../model/transaction/Transaction'; +import { SignSchema } from '../crypto/SignSchema'; export class TransactionMapping { @@ -31,10 +33,14 @@ export class TransactionMapping { /** * Create transaction class from payload binary. - * @param {string} dataBytes The transaction json object. - * @returns {module: model/transaction/transaction} The transaction class. + * @param {string} payload The transaction binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} The transaction class. */ - public static createFromPayload(dataBytes: string): Transaction { - return CreateTransactionFromPayload(dataBytes); + public static createFromPayload(payload: string, + isEmbedded = false, + signSchema = SignSchema.SHA3): Transaction | InnerTransaction { + return CreateTransactionFromPayload(payload, isEmbedded, signSchema); } } diff --git a/src/infrastructure/catbuffer/GeneratorUtils.ts b/src/infrastructure/catbuffer/GeneratorUtils.ts index 437c32d117..7e95285569 100644 --- a/src/infrastructure/catbuffer/GeneratorUtils.ts +++ b/src/infrastructure/catbuffer/GeneratorUtils.ts @@ -1,119 +1,117 @@ // tslint:disable: jsdoc-format /** -*** Copyright (c) 2016-present, -*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. -*** -*** This file is part of Catapult. -*** -*** Catapult is free software: you can redistribute it and/or modify -*** it under the terms of the GNU Lesser General Public License as published by -*** the Free Software Foundation, either version 3 of the License, or -*** (at your option) any later version. -*** -*** Catapult is distributed in the hope that it will be useful, -*** but WITHOUT ANY WARRANTY; without even the implied warranty of -*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -*** GNU Lesser General Public License for more details. -*** -*** You should have received a copy of the GNU Lesser General Public License -*** along with Catapult. If not, see . -**/ + *** Copyright (c) 2016-present, + *** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. + *** + *** This file is part of Catapult. + *** + *** Catapult is free software: you can redistribute it and/or modify + *** it under the terms of the GNU Lesser General Public License as published by + *** the Free Software Foundation, either version 3 of the License, or + *** (at your option) any later version. + *** + *** Catapult is distributed in the hope that it will be useful, + *** but WITHOUT ANY WARRANTY; without even the implied warranty of + *** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *** GNU Lesser General Public License for more details. + *** + *** You should have received a copy of the GNU Lesser General Public License + *** along with Catapult. If not, see . + **/ /** * Generator utility class. */ export class GeneratorUtils { - /** + /** * Converts a (64bit) uint8 array into a number array. * @param {Uint8Array} input A uint8 array. * @returns {number[]} The uint64 representation of the input. */ - public static bufferToUint64 (input: Uint8Array): number[] { + public static bufferToUint64(input: Uint8Array): number[] { if (8 !== input.length) { throw Error(`byte array has unexpected size '${input.length}'`); - } - input = input.reverse(); - return [GeneratorUtils.readUint32At(input, 0), GeneratorUtils.readUint32At(input, 4)]; - } - - /** + } + input = input.reverse(); + const view = new DataView(input.buffer); + return [view.getUint32(4), view.getUint32(0)]; + } + + /** * Read buffer into 32bits integer at given index. * @param {Uint8Array} bytes A uint8 array. - * @param {number} index Index. + * @param {number} index Index. * @returns {number} 32bits integer. */ - public static readUint32At(bytes: Uint8Array, index: number): number { - return (bytes[index] + (bytes[index + 1] << 8) + (bytes[index + 2] << 16) + (bytes[index + 3] << 24)) >>> 0; - } + public static readUint32At(bytes: Uint8Array, index: number): number { + return (bytes[index] + (bytes[index + 1] << 8) + (bytes[index + 2] << 16) + (bytes[index + 3] << 24)) >>> 0; + } - /** + /** * Write uint to buffer * @param {number} uintValue A uint8 array. - * @param {number} bufferSize Buffer size. + * @param {number} bufferSize Buffer size. * @returns {Uint8Array} */ - public static uintToBuffer (uintValue: number, bufferSize: number): Uint8Array { - const buffer = new ArrayBuffer(bufferSize); - const dataView = new DataView(buffer); - if (1 === bufferSize) - dataView.setUint8(0, uintValue); - - else if (2 === bufferSize) - dataView.setUint16(0, uintValue, true); - - else if (4 === bufferSize) - dataView.setUint32(0, uintValue, true); - - else - throw new Error('Unexpected bufferSize'); - - return new Uint8Array(buffer); - } + public static uintToBuffer(uintValue: number, bufferSize: number): Uint8Array { + const buffer = new ArrayBuffer(bufferSize); + const dataView = new DataView(buffer); + if (1 === bufferSize) { + dataView.setUint8(0, uintValue); + } else if (2 === bufferSize) { + dataView.setUint16(0, uintValue, true); + } else if (4 === bufferSize) { + dataView.setUint32(0, uintValue, true); + } else { + throw new Error('Unexpected bufferSize'); + } + + return new Uint8Array(buffer); + } - /** + /** * Write uint to buffer * @param {Uint8Array} buffer A uint8 array. * @returns {number} */ - public static bufferToUint(buffer: Uint8Array): number { - const dataView = new DataView(buffer.buffer); - if (1 === buffer.byteLength) - return dataView.getUint8(0); - - else if (2 === buffer.byteLength) - return dataView.getUint16(0, true); - - else if (4 === buffer.byteLength) - return dataView.getUint32(0, true); - - throw new Error('Unexpected buffer size'); - }; + public static bufferToUint(buffer: Uint8Array): number { + const dataView = new DataView(buffer.buffer); + if (1 === buffer.byteLength) { + return dataView.getUint8(0); + } else if (2 === buffer.byteLength) { + return dataView.getUint16(0, true); + } else if (4 === buffer.byteLength) { + return dataView.getUint32(0, true); + } - /** + throw new Error('Unexpected buffer size'); + } + + /** * Write Uint64 to buffer * @param {number} uintValue Uint64 (number[]). * @returns {Uint8Array} */ - public static uint64ToBuffer(uintValue: number[]): Uint8Array { - const uint32Array = new Uint32Array(uintValue); - return new Uint8Array(uint32Array.buffer); - } + public static uint64ToBuffer(uintValue: number[]): Uint8Array { + const uint32Array = new Uint32Array(uintValue); + return new Uint8Array(uint32Array.buffer); + } - /** + /** * Concatenate two arrays * @param {Uint8Array} array1 A Uint8Array. - * @param {Uint8Array} array2 A Uint8Array. + * @param {Uint8Array} array2 A Uint8Array. * @returns {Uint8Array} */ - public static concatTypedArrays(array1: Uint8Array, array2: Uint8Array): Uint8Array { - const newArray = new Uint8Array(array1.length + array2.length); - newArray.set(array1); - newArray.set(array2, array1.length); - return newArray; - } + public static concatTypedArrays(array1: Uint8Array, array2: Uint8Array): Uint8Array { + const newArray = new Uint8Array(array1.length + array2.length); + newArray.set(array1); + newArray.set(array2, array1.length); + return newArray; + } - /** Converts an unsigned byte to a signed byte with the same binary representation. + /** Converts an unsigned byte to a signed byte with the same binary representation. * @param {number} input An unsigned byte. * @returns {number} A signed byte with the same binary representation as the input. * @@ -125,17 +123,17 @@ export class GeneratorUtils { return input << 24 >> 24; } - /** Get bytes by given sub array size. - * @param {Uint8Array} binary Binary bytes array. + /** Get bytes by given sub array size. + * @param {Uint8Array} binary Binary bytes array. * @param {number} size Subarray size. - * @returns {Uint8Array} + * @returns {Uint8Array} * */ - public static getBytes(binary: Uint8Array, size: number): Uint8Array { - if (size > binary.length) - throw new RangeError(); - - const bytes = binary.slice(0, size); - return bytes; - } + public static getBytes(binary: Uint8Array, size: number): Uint8Array { + if (size > binary.length) { + throw new RangeError(); + } + const bytes = binary.slice(0, size); + return bytes; + } } diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index 6491749d4c..3f79ea2d5e 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -14,524 +14,88 @@ * limitations under the License. */ -import {decode} from 'utf8'; +import { SignSchema } from '../../core/crypto'; import { Convert as convert } from '../../core/format'; -import { Address } from '../../model/account/Address'; -import { PublicAccount } from '../../model/account/PublicAccount'; -import { NetworkType } from '../../model/blockchain/NetworkType'; -import { Mosaic } from '../../model/mosaic/Mosaic'; -import { MosaicId } from '../../model/mosaic/MosaicId'; -import { MosaicNonce } from '../../model/mosaic/MosaicNonce'; -import { MosaicProperties } from '../../model/mosaic/MosaicProperties'; -import { NamespaceId } from '../../model/namespace/NamespaceId'; -import { NamespaceType } from '../../model/namespace/NamespaceType'; +import { InnerTransaction } from '../../model/model'; import { AccountAddressRestrictionTransaction } from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; import { AccountMosaicRestrictionTransaction } from '../../model/transaction/AccountMosaicRestrictionTransaction'; import { AccountOperationRestrictionTransaction } from '../../model/transaction/AccountOperationRestrictionTransaction'; -import { AccountRestrictionModification } from '../../model/transaction/AccountRestrictionModification'; import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction'; import { AggregateTransaction } from '../../model/transaction/AggregateTransaction'; -import { AggregateTransactionCosignature } from '../../model/transaction/AggregateTransactionCosignature'; -import { Deadline } from '../../model/transaction/Deadline'; -import { EncryptedMessage } from '../../model/transaction/EncryptedMessage'; -import { HashType } from '../../model/transaction/HashType'; import { LockFundsTransaction } from '../../model/transaction/LockFundsTransaction'; -import { Message } from '../../model/transaction/Message'; -import { MessageType } from '../../model/transaction/MessageType'; import { ModifyMultisigAccountTransaction } from '../../model/transaction/ModifyMultisigAccountTransaction'; import { MosaicAddressRestrictionTransaction } from '../../model/transaction/MosaicAddressRestrictionTransaction'; import { MosaicAliasTransaction } from '../../model/transaction/MosaicAliasTransaction'; import { MosaicDefinitionTransaction } from '../../model/transaction/MosaicDefinitionTransaction'; import { MosaicGlobalRestrictionTransaction } from '../../model/transaction/MosaicGlobalRestrictionTransaction'; import { MosaicSupplyChangeTransaction } from '../../model/transaction/MosaicSupplyChangeTransaction'; -import { MultisigCosignatoryModification } from '../../model/transaction/MultisigCosignatoryModification'; -import { PlainMessage } from '../../model/transaction/PlainMessage'; import { RegisterNamespaceTransaction } from '../../model/transaction/RegisterNamespaceTransaction'; import { SecretLockTransaction } from '../../model/transaction/SecretLockTransaction'; import { SecretProofTransaction } from '../../model/transaction/SecretProofTransaction'; -import { SignedTransaction } from '../../model/transaction/SignedTransaction'; import { Transaction } from '../../model/transaction/Transaction'; import { TransactionType } from '../../model/transaction/TransactionType'; import { TransferTransaction } from '../../model/transaction/TransferTransaction'; -import { UInt64 } from '../../model/UInt64'; +import { EmbeddedTransactionBuilder } from '../catbuffer/EmbeddedTransactionBuilder'; +import { TransactionBuilder } from '../catbuffer/TransactionBuilder'; /** * @internal - * @param transactionBinary - The transaction binary data - * @returns {Transaction} + * @param payload - The transaction binary data + * @param isEmbedded - Is the transaction an embedded inner transaction + * @param signSchema - The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} * @constructor */ -export const CreateTransactionFromPayload = (transactionBinary: string): Transaction => { - // Transaction byte size data - const sizeLength = 8; - const signatureLength = 128; - const publicKeyLength = 64; - const versionLength = 4; - const typeLength = 4; - const feeLength = 16; - const deadlineLength = 16; - - // Transaction byte data positions - const signatureOffset = sizeLength; - const publicKeyOffset = signatureOffset + signatureLength; - const versionOffset = publicKeyOffset + publicKeyLength; - const typeOffset = versionOffset + versionLength; - const feeOffset = typeOffset + typeLength; - const deadlineOffset = feeOffset + feeLength; - const transactionOffset = deadlineOffset + deadlineLength; - - // Transaction byte data - const networkType = extractNetwork(transactionBinary.substring(versionOffset, typeOffset)); - const type = extractTransactionTypeFromHex(transactionBinary.substring(typeOffset, feeOffset)); - const deadline = UInt64.fromHex(reverse(transactionBinary.substring(deadlineOffset, transactionOffset))).toDTO(); - const transactionData = transactionBinary.substring(transactionOffset); - - return CreateTransaction(type, transactionData, networkType, deadline); -}; - -/** - * @internal - * @param type - Transaction type - * @param transactionData - Details per specific transaction type - * @param networkType - Network type - * @param deadline - Deadline - * @returns {Transaction} - */ -const CreateTransaction = (type: number, transactionData: string, networkType: NetworkType, deadline: number[]): Transaction => { +export const CreateTransactionFromPayload = (payload: string, + isEmbedded = false, + signSchema = SignSchema.SHA3): Transaction | InnerTransaction => { + const transactionBuilder = isEmbedded ? EmbeddedTransactionBuilder.loadFromBinary(convert.hexToUint8(payload)) : + TransactionBuilder.loadFromBinary(convert.hexToUint8(payload)); + const type = transactionBuilder.getType().valueOf(); switch (type) { case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: case TransactionType.ACCOUNT_RESTRICTION_OPERATION: case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: - const propertyTypeLength = 2; - - const modificationCountOffset = propertyTypeLength; - const modificationArrayOffset = modificationCountOffset + propertyTypeLength; - - // read bytes - const propertyType = transactionData.substring(0, propertyTypeLength); - const modifications = transactionData.substring(modificationArrayOffset, transactionData.length); - const modificationArray = modifications.match(/.{1,52}/g); - switch (type) { case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: - const t = AccountAddressRestrictionTransaction.create( - Deadline.createFromDTO(deadline), - parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), - modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( - parseInt(convert.uint8ToHex(convert.hexToUint8(modification.substring(0, 2)).reverse()), 16), - Address.createFromEncoded(modification.substring(2, modification.length)).plain(), - )) : [], - networkType, - ); - return t; + return AccountAddressRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: - return AccountMosaicRestrictionTransaction.create( - Deadline.createFromDTO(deadline), - parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), - modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( - parseInt(convert.uint8ToHex(convert.hexToUint8(modification.substring(0, 2)).reverse()), 16), - UInt64.fromHex(reverse(modification.substring(2, modification.length))).toDTO(), - )) : [], - networkType, - ); + return AccountMosaicRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.ACCOUNT_RESTRICTION_OPERATION: - return AccountOperationRestrictionTransaction.create( - Deadline.createFromDTO(deadline), - parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), - modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( - parseInt(convert.uint8ToHex(convert.hexToUint8(modification.substring(0, 2)).reverse()), 16), - parseInt(convert.uint8ToHex(convert.hexToUint8( - modification.substring(2, modification.length)).reverse()), 16), - )) : [], - networkType, - ); + return AccountOperationRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); } throw new Error ('Account restriction transaction type not recognised.'); case TransactionType.LINK_ACCOUNT: - // read bytes - const remoteAccountKey = transactionData.substring(0, 64); - const linkAction = transactionData.substring(64, 66); - - return AccountLinkTransaction.create( - Deadline.createFromDTO(deadline), - remoteAccountKey, - parseInt(convert.uint8ToHex(convert.hexToUint8(linkAction).reverse()), 16), - networkType, - ); + return AccountLinkTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.ADDRESS_ALIAS: - // read bytes - const addressAliasAction = transactionData.substring(0, 2); - const addressAliasNamespaceId = transactionData.substring(2, 18); - const addressAliasAddress = transactionData.substring(18); - - return AddressAliasTransaction.create( - Deadline.createFromDTO(deadline), - parseInt(convert.uint8ToHex(convert.hexToUint8(addressAliasAction).reverse()), 16), - new NamespaceId(UInt64.fromHex(reverse(addressAliasNamespaceId)).toDTO()), - Address.createFromEncoded(addressAliasAddress), - networkType, - ); + return AddressAliasTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MOSAIC_ALIAS: - const mosaicAliasActionLength = 2; - - // read bytes - const mosaicAliasAction = transactionData.substring(0, mosaicAliasActionLength); - const mosaicAliasNamespaceId = transactionData.substring(mosaicAliasActionLength, 18); - const mosaicAliasMosaicId = transactionData.substring(18); - - return MosaicAliasTransaction.create( - Deadline.createFromDTO(deadline), - parseInt(convert.uint8ToHex(convert.hexToUint8(mosaicAliasAction).reverse()), 16), - new NamespaceId(UInt64.fromHex(reverse(mosaicAliasNamespaceId)).toDTO()), - new MosaicId(UInt64.fromHex(reverse(mosaicAliasMosaicId)).toDTO()), - networkType, - ); + return MosaicAliasTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MOSAIC_DEFINITION: - const mosaicDefMosaicNonceLength = 8; - const mosaicDefMosaicIdLength = 16; - const mosaicDefPropsFlagsLength = 2; - const mosaicDefDivisibilityLength = 2; - const mosaicDefDurationLength = 16; - - const mosaicIdOffset = mosaicDefMosaicNonceLength; - const flagsOffset = mosaicIdOffset + mosaicDefMosaicIdLength; - const divisibilityOffset = flagsOffset + mosaicDefPropsFlagsLength; - const durationOffset = divisibilityOffset + mosaicDefDivisibilityLength; - - // read bytes - const mosaicNonce = transactionData.substring(0, mosaicDefMosaicNonceLength); - const mosaicId = transactionData.substring(mosaicIdOffset, flagsOffset); - const flags = parseInt(convert.uint8ToHex(convert.hexToUint8( - transactionData.substring(flagsOffset, divisibilityOffset)).reverse()), 16); - const divisibility = transactionData.substring(divisibilityOffset, durationOffset); - const duration = transactionData.substring(durationOffset); - - const regexArray = mosaicNonce.match(/.{1,2}/g); - - const nonceArray = regexArray ? regexArray.map((n) => { - return parseInt(convert.uint8ToHex(convert.hexToUint8(n).reverse()), 16); - }) : []; - - return MosaicDefinitionTransaction.create( - Deadline.createFromDTO(deadline), - new MosaicNonce(new Uint8Array(nonceArray)), - new MosaicId(UInt64.fromHex(reverse(mosaicId)).toDTO()), - MosaicProperties.create({ - supplyMutable: (flags & 1) === 1, - transferable: (flags & 2) === 2, - divisibility: parseInt(convert.uint8ToHex(convert.hexToUint8(divisibility).reverse()), 16), - restrictable: (flags & 4) === 4, - duration: duration ? UInt64.fromHex(reverse(duration)) : undefined, - }), - networkType, - ); + return MosaicDefinitionTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MOSAIC_SUPPLY_CHANGE: - // read bytes - const mosaicSupMosaicId = transactionData.substring(0, 16); - const mosaicSupDirection = transactionData.substring(16, 18); - const delta = transactionData.substring(18, 34); - - return MosaicSupplyChangeTransaction.create( - Deadline.createFromDTO(deadline), - new MosaicId(UInt64.fromHex(reverse(mosaicSupMosaicId)).toDTO()), - parseInt(convert.uint8ToHex(convert.hexToUint8(mosaicSupDirection).reverse()), 16), - UInt64.fromHex(reverse(delta)), - networkType, - ); + return MosaicSupplyChangeTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.REGISTER_NAMESPACE: - // read bytes - const namespaceType = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(0, 2)).reverse()), 16); - const nameSpaceDurationParentId = transactionData.substring(2, 18); - const nameSpaceId = transactionData.substring(18, 34); - const nameSize = transactionData.substring(34, 36); - const nameSpaceName = transactionData.substring(36); - - return namespaceType === NamespaceType.RootNamespace ? - RegisterNamespaceTransaction.createRootNamespace( - Deadline.createFromDTO(deadline), - decodeHex(nameSpaceName), - UInt64.fromHex(reverse(nameSpaceDurationParentId)), - networkType, - ) : RegisterNamespaceTransaction.createSubNamespace( - Deadline.createFromDTO(deadline), - decodeHex(nameSpaceName), - new NamespaceId(UInt64.fromHex(reverse(nameSpaceDurationParentId)).toDTO()), - networkType, - ); + return RegisterNamespaceTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.TRANSFER: - // read bytes - const transferRecipient = transactionData.substring(0, 50); - const transferMessageSize = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(50, 54)).reverse()), 16); - - const transferMessageAndMosaicSubString = transactionData.substring(56); - const transferMessageType = parseInt(convert.uint8ToHex(convert.hexToUint8( - transferMessageAndMosaicSubString.substring(0, 2)).reverse()), 16); - const transferMessage = transferMessageAndMosaicSubString.substring(2, (transferMessageSize - 1) * 2 + 2); - const transferMosaic = transferMessageAndMosaicSubString.substring(transferMessageSize * 2); - const transferMosaicArray = transferMosaic.match(/.{1,32}/g); - - return TransferTransaction.create( - Deadline.createFromDTO(deadline), - Address.createFromEncoded(transferRecipient), - transferMosaicArray ? transferMosaicArray.map((mosaic) => new Mosaic( - new MosaicId(UInt64.fromHex(reverse(mosaic.substring(0, 16))).toDTO()), - UInt64.fromHex(reverse(mosaic.substring(16))), - )) : [], - extractMessage(transferMessageType, transferMessage), - networkType, - ); + return TransferTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.SECRET_LOCK: - // read bytes - const secretLockMosaic = transactionData.substring(0, 32); - const secretLockDuration = transactionData.substring(32, 48); - const secretLockHashAlgorithm = parseInt(convert.uint8ToHex(convert.hexToUint8( - transactionData.substring(48, 50)).reverse()), 16); - const secretLockSecret = transactionData.substring(50, transactionData.length - 50); - const secretLockRecipient = transactionData.substring(transactionData.length - 50); - - return SecretLockTransaction.create( - Deadline.createFromDTO(deadline), - new Mosaic( - new MosaicId(UInt64.fromHex(reverse(secretLockMosaic.substring(0, 16))).toDTO()), - UInt64.fromHex(reverse(secretLockMosaic.substring(16))), - ), - UInt64.fromHex(reverse(secretLockDuration)), - secretLockHashAlgorithm, - secretLockSecret, - Address.createFromEncoded(secretLockRecipient), - networkType, - ); + return SecretLockTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.SECRET_PROOF: - // read bytes - const secretProofHashAlgorithm = parseInt(convert.uint8ToHex(convert.hexToUint8( - transactionData.substring(0, 2)).reverse()), 16); - - const secretProofSecretLength = 64; - const secretProofSecret = transactionData.substring(2, 66); - const secretProofRecipient = transactionData.substring(66, 116); - const secretProofSize = transactionData.substring(116, 120); - const secretProofProof = transactionData.substring(120); - - return SecretProofTransaction.create( - Deadline.createFromDTO(deadline), - secretProofHashAlgorithm, - secretProofSecret, - Address.createFromEncoded(secretProofRecipient), - secretProofProof, - networkType, - ); + return SecretProofTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MODIFY_MULTISIG_ACCOUNT: - // read bytes - const minRemovalDelta = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(0, 2)).reverse()), 16); - const minApprovalDelta = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(2, 4)).reverse()), 16); - const modificationsCount = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(4, 6)).reverse()), 16); - - const multiSigModificationSubString = transactionData.substring(6); - const multiSigModificationArray = multiSigModificationSubString.match(/.{1,66}/g); - - return ModifyMultisigAccountTransaction.create( - Deadline.createFromDTO(deadline), - minApprovalDelta, - minRemovalDelta, - multiSigModificationArray ? multiSigModificationArray.map((modification) => new MultisigCosignatoryModification( - parseInt(convert.uint8ToHex(convert.hexToUint8(modification.substring(0, 2)).reverse()), 16), - PublicAccount.createFromPublicKey(modification.substring(2), networkType), - )) : [], - networkType, - ); + return ModifyMultisigAccountTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.LOCK: - // read bytes - const hashLockMosaic = transactionData.substring(0, 32); - const hashLockDuration = transactionData.substring(32, 48); - const hashLockHash = transactionData.substring(48); - - return LockFundsTransaction.create( - Deadline.createFromDTO(deadline), - new Mosaic( - new MosaicId(UInt64.fromHex(reverse(hashLockMosaic.substring(0, 16))).toDTO()), - UInt64.fromHex(reverse(hashLockMosaic.substring(16))), - ), - UInt64.fromHex(reverse(hashLockDuration)), - new SignedTransaction('', hashLockHash, '', TransactionType.AGGREGATE_BONDED, networkType), - networkType, - ); + return LockFundsTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MOSAIC_GLOBAL_RESTRICTION: - // read bytes - const globalRestrictionMosaicId = transactionData.substring(0, 16); - const globalRestrictionReferenceMosaicId = transactionData.substring(16, 32); - const globalRestrictionRestrictionKey = transactionData.substring(32, 48); - const globalRestrictionPrevValue = transactionData.substring(48, 64); - const globalRestrictionPrevType = transactionData.substring(64, 66); - const globalRestrictionNewValue = transactionData.substring(66, 82); - const globalRestrictionNewType = transactionData.substring(82, 84); - - return MosaicGlobalRestrictionTransaction.create( - Deadline.createFromDTO(deadline), - new MosaicId(UInt64.fromHex(reverse(globalRestrictionMosaicId)).toDTO()), - new MosaicId(UInt64.fromHex(reverse(globalRestrictionReferenceMosaicId)).toDTO()), - UInt64.fromHex(reverse(globalRestrictionRestrictionKey)), - UInt64.fromHex(reverse(globalRestrictionPrevValue)), - parseInt(convert.uint8ToHex(convert.hexToUint8(globalRestrictionPrevType).reverse()), 16), - UInt64.fromHex(reverse(globalRestrictionNewValue)), - parseInt(convert.uint8ToHex(convert.hexToUint8(globalRestrictionNewType).reverse()), 16), - networkType, - ); + return MosaicGlobalRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MOSAIC_ADDRESS_RESTRICTION: - // read bytes - const addressRestrictionMosaicId = transactionData.substring(0, 16); - const addressRestrictionRestrictionKey = transactionData.substring(16, 32); - const addressRestrictionTargetAddress = transactionData.substring(32, 82); - const addressRestrictionPrevValue = transactionData.substring(82, 98); - const addressRestrictionNewValue = transactionData.substring(98, 114); - - return MosaicAddressRestrictionTransaction.create( - Deadline.createFromDTO(deadline), - new MosaicId(UInt64.fromHex(reverse(addressRestrictionMosaicId)).toDTO()), - UInt64.fromHex(reverse(addressRestrictionRestrictionKey)), - Address.createFromEncoded(addressRestrictionTargetAddress), - UInt64.fromHex(reverse(addressRestrictionPrevValue)), - UInt64.fromHex(reverse(addressRestrictionNewValue)), - networkType, - ); + return MosaicAddressRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.AGGREGATE_COMPLETE: - // read bytes - const payloadSize = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(0, 8)).reverse()), 16) * 2; - const cosignatures = transactionData.substring(payloadSize + 8); - - const innerTransactionArray = parseInnerTransactionFromBinary(transactionData.substring(8, payloadSize + 8)); - const consignatureArray = cosignatures.match(/.{1,192}/g); - - return AggregateTransaction.createComplete( - Deadline.createFromDTO(deadline), - innerTransactionArray.map((innerTransaction) => { - const transaction = CreateTransaction( - extractTransactionTypeFromHex(innerTransaction.substring(68, 72)), - innerTransaction.substring(72), - networkType, - deadline, - ); - return transaction.toAggregate(PublicAccount.createFromPublicKey(innerTransaction.substring(0, 64), networkType)); - }), - networkType, - consignatureArray ? consignatureArray.map((cosignature) => new AggregateTransactionCosignature( - cosignature.substring(64, 192), - PublicAccount.createFromPublicKey(cosignature.substring(0, 64), networkType), - )) : [], - ); case TransactionType.AGGREGATE_BONDED: - const bondedPayloadSize = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(0, 8)).reverse()), 16) * 2; - const bondedCosignatures = transactionData.substring(bondedPayloadSize + 8); - - const bondedInnerTransactionArray = parseInnerTransactionFromBinary(transactionData.substring(8, bondedPayloadSize + 8)); - const bondedConsignatureArray = bondedCosignatures.match(/.{1,192}/g); - - return AggregateTransaction.createBonded( - Deadline.createFromDTO(deadline), - bondedInnerTransactionArray.map((innerTransaction) => { - const transaction = CreateTransaction( - extractTransactionTypeFromHex(innerTransaction.substring(68, 72)), - innerTransaction.substring(72), - networkType, - deadline, - ); - return transaction.toAggregate(PublicAccount.createFromPublicKey(innerTransaction.substring(0, 64), networkType)); - }), - networkType, - bondedConsignatureArray ? bondedConsignatureArray.map((cosignature) => new AggregateTransactionCosignature( - cosignature.substring(64, 192), - PublicAccount.createFromPublicKey(cosignature.substring(0, 64), networkType), - )) : [], - ); + return AggregateTransaction.createFromPayload(payload, signSchema); default: throw new Error ('Transaction type not implemented yet.'); } }; - -/** - * @internal - * @param hexValue - Transaction type in hex - * @returns {number} - */ -const extractTransactionTypeFromHex = (hexValue: string): number => { - return parseInt(convert.uint8ToHex(convert.hexToUint8(hexValue).reverse()), 16); -}; - -/** - * @internal - * @param versionHex - Transaction version in hex - * @returns {NetworkType} - */ -const extractNetwork = (versionHex: string): NetworkType => { - const networkType = convert.hexToUint8(versionHex)[1]; - if (networkType === NetworkType.MAIN_NET) { - return NetworkType.MAIN_NET; - } else if (networkType === NetworkType.TEST_NET) { - return NetworkType.TEST_NET; - } else if (networkType === NetworkType.MIJIN) { - return NetworkType.MIJIN; - } else if (networkType === NetworkType.MIJIN_TEST) { - return NetworkType.MIJIN_TEST; - } - throw new Error('Unimplemented network type'); -}; - -/** - * @internal - * @param hex - * @returns {string} - */ -const reverse = (hex: string): string => { - return convert.uint8ToHex(convert.hexToUint8(hex).reverse()); -}; - -/** - * @internal - * @param innerTransactionBinary - Inner transaction binary data - * @returns {Array} - */ -const parseInnerTransactionFromBinary = (innerTransactionBinary: string): string[] => { - const embeddedTransaction: string[] = []; - let innerBinary = innerTransactionBinary; - - while (innerBinary.length) { - const payloadSize = parseInt(convert.uint8ToHex(convert.hexToUint8(innerBinary.substring(0, 8)).reverse()), 16) * 2; - const innerTransaction = innerBinary.substring(8, payloadSize); - embeddedTransaction.push(innerTransaction); - innerBinary = innerBinary.substring(payloadSize); - } - return embeddedTransaction; -}; - -/** - * @internal - * @param hex - Hex input - * @returns {string} - */ -const decodeHex = (hex: string): string => { - let str = ''; - for (let i = 0; i < hex.length; i += 2) { - str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); - } - try { - return decode(str); - } catch (e) { - return str; - } -}; - -/** - * @internal - * @param messageType - Message Type - * @param payload - Message Payload - * @returns {Message} - */ -const extractMessage = (messageType: MessageType, payload: string): Message => { - if (messageType === MessageType.PlainMessage) { - return PlainMessage.createFromPayload(payload); - } else if (messageType === MessageType.EncryptedMessage) { - return EncryptedMessage.createFromPayload(payload); - } else { - throw new Error('Invalid message type'); - } -}; diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index 150cd213b6..417dafba7b 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -14,21 +14,24 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, RawAddress } from '../../core/format'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; +import { EmbeddedAccountAddressRestrictionTransactionBuilder }from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; +import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -82,6 +85,36 @@ export class AccountAddressRestrictionTransaction extends Transaction { networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAccountAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AccountAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AccountAddressRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as AccountAddressRestrictionTransactionBuilder).getDeadline().timestamp), + builder.getRestrictionType().valueOf(), + builder.getModifications().map((modification) => { + return AccountRestrictionModification.createForAddress( + modification.modificationAction.valueOf(), + Address.createFromEncoded(Convert.uint8ToHex(modification.value.unresolvedAddress)), + ); + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountAddressRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AccountAddressRestrictionTransaction diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index 58584444b2..f1cb351b7a 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/AccountLinkTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -26,6 +27,7 @@ import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { LinkAction } from './LinkAction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; @@ -87,6 +89,30 @@ export class AccountLinkTransaction extends Transaction { super(TransactionType.LINK_ACCOUNT, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAccountLinkTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AccountLinkTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AccountLinkTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as AccountLinkTransactionBuilder).getDeadline().timestamp), + Convert.uint8ToHex(builder.getRemoteAccountPublicKey().key), + builder.getLinkAction().valueOf(), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountLinkTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AccountLinkTransaction diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index be182d398b..ba7170a2cf 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; @@ -26,9 +27,11 @@ import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/Unresolved import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; +import { MosaicId } from '../mosaic/MosaicId'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -82,6 +85,36 @@ export class AccountMosaicRestrictionTransaction extends Transaction { networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAccountMosaicRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AccountMosaicRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AccountMosaicRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as AccountMosaicRestrictionTransactionBuilder).getDeadline().timestamp), + builder.getRestrictionType().valueOf(), + builder.getModifications().map((modification) => { + return AccountRestrictionModification.createForMosaic( + modification.modificationAction.valueOf(), + new MosaicId(modification.value.unresolvedMosaicId), + ); + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountMosaicRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AccountMosaicRestrictionTransaction diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index 3ee53a4b4d..df1aced4e7 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; @@ -28,6 +29,7 @@ import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -81,6 +83,36 @@ export class AccountOperationRestrictionTransaction extends Transaction { networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAccountOperationRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AccountOperationRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AccountOperationRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as AccountOperationRestrictionTransactionBuilder).getDeadline().timestamp), + builder.getRestrictionType().valueOf(), + builder.getModifications().map((modification) => { + return AccountRestrictionModification.createForOperation( + modification.modificationAction.valueOf(), + modification.value.valueOf(), + ); + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountOperationRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AccountOperationRestrictionTransaction diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 1faaeaa7dc..3975b926dc 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -14,12 +14,12 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, RawAddress } from '../../core/format'; import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; import { AddressDto } from '../../infrastructure/catbuffer/AddressDto'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -31,6 +31,7 @@ import { AliasAction } from '../namespace/AliasAction'; import { NamespaceId } from '../namespace/NamespaceId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -102,6 +103,32 @@ export class AddressAliasTransaction extends Transaction { super(TransactionType.ADDRESS_ALIAS, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAddressAliasTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AddressAliasTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AddressAliasTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as AddressAliasTransactionBuilder).getDeadline().timestamp), + builder.getAliasAction().valueOf(), + new NamespaceId(builder.getNamespaceId().namespaceId), + Address.createFromEncoded( + Convert.uint8ToHex(builder.getAddress().address)), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AddressAliasTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AddressAliasTransaction diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 55796be64e..cb3ee4d299 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -23,6 +23,7 @@ import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { CreateTransactionFromPayload } from '../../infrastructure/transaction/CreateTransactionFromPayload'; import { Account } from '../account/Account'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -122,6 +123,61 @@ export class AggregateTransaction extends Transaction { ); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {AggregateTransaction} + */ + public static createFromPayload(payload: string, signSchema: SignSchema = SignSchema.SHA3): AggregateTransaction { + const builder = AggregateTransactionBuilder + .loadFromBinary(Convert.hexToUint8(payload)); + const type = builder.getType().valueOf(); + const innerTransactionHex = Convert.uint8ToHex(builder.getTransactions()); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const consignaturesHex = Convert.uint8ToHex(builder.getCosignatures()); + + /** + * Get inner transactions array + */ + const embeddedTransactionArray: string[] = []; + let innerBinary = innerTransactionHex; + while (innerBinary.length) { + const payloadSize = parseInt(Convert.uint8ToHex(Convert.hexToUint8(innerBinary.substring(0, 8)).reverse()), 16) * 2; + const innerTransaction = innerBinary.substring(0, payloadSize); + embeddedTransactionArray.push(innerTransaction); + innerBinary = innerBinary.substring(payloadSize); + } + + /** + * Get cosignatures + */ + const consignatureArray = consignaturesHex.match(/.{1,192}/g); + const consignatures = consignatureArray ? consignatureArray.map((cosignature) => + new AggregateTransactionCosignature( + cosignature.substring(64, 192), + PublicAccount.createFromPublicKey(cosignature.substring(0, 64), networkType, signSchema), + )) : []; + + return type === TransactionType.AGGREGATE_COMPLETE ? + AggregateTransaction.createComplete( + Deadline.createFromDTO(builder.deadline.timestamp), + embeddedTransactionArray.map((transactionRaw) => { + return CreateTransactionFromPayload(transactionRaw, true, signSchema) as InnerTransaction; + }), + networkType, + consignatures, + new UInt64(builder.fee.amount), + ) : AggregateTransaction.createBonded( + Deadline.createFromDTO(builder.deadline.timestamp), + embeddedTransactionArray.map((transactionRaw) => { + return CreateTransactionFromPayload(transactionRaw, true, signSchema) as InnerTransaction; + }), + networkType, + consignatures, + new UInt64(builder.fee.amount), + ); + } /** * @internal * Sign transaction with cosignatories creating a new SignedTransaction @@ -230,7 +286,7 @@ export class AggregateTransaction extends Transaction { transactions = GeneratorUtils.concatTypedArrays(transactions, transactionByte); }); - const cosignatures = Uint8Array.from([]); + let cosignatures = Uint8Array.from([]); this.cosignatures.forEach((cosignature) => { const signerBytes = Convert.hexToUint8(cosignature.signer.publicKey); const signatureBytes = Convert.hexToUint8(cosignature.signature); @@ -238,7 +294,7 @@ export class AggregateTransaction extends Transaction { new KeyDto(signerBytes), new SignatureDto(signatureBytes), ).serialize(); - transactions = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); + cosignatures = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); }); const transactionBuilder = new AggregateTransactionBuilder( diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index b36810cf05..96088b7ec0 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; @@ -28,8 +29,10 @@ import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/Unresolved import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { Mosaic } from '../mosaic/Mosaic'; +import { MosaicId } from '../mosaic/MosaicId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { SignedTransaction } from './SignedTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; @@ -111,6 +114,35 @@ export class LockFundsTransaction extends Transaction { } } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedHashLockTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + HashLockTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = LockFundsTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as HashLockTransactionBuilder).getDeadline().timestamp), + new Mosaic( + new MosaicId(builder.getMosaic().mosaicId.unresolvedMosaicId), + new UInt64(builder.getMosaic().amount.amount), + ), + new UInt64(builder.getDuration().blockDuration), + new SignedTransaction('', Convert.uint8ToHex(builder.getHash().hash256), '', + TransactionType.AGGREGATE_BONDED, networkType), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as HashLockTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a LockFundsTransaction diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index 835b117f13..23dce96d81 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { CosignatoryModificationBuilder } from '../../infrastructure/catbuffer/CosignatoryModificationBuilder'; @@ -26,6 +27,7 @@ import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { MultisigCosignatoryModification } from './MultisigCosignatoryModification'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; @@ -101,6 +103,40 @@ export class ModifyMultisigAccountTransaction extends Transaction { super(TransactionType.MODIFY_MULTISIG_ACCOUNT, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMultisigAccountModificationTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MultisigAccountModificationTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = ModifyMultisigAccountTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as MultisigAccountModificationTransactionBuilder).getDeadline().timestamp), + builder.getMinApprovalDelta(), + builder.getMinRemovalDelta(), + builder.getModifications().map((modification) => { + return new MultisigCosignatoryModification( + modification.modificationAction.valueOf(), + PublicAccount.createFromPublicKey( + Convert.uint8ToHex(modification.cosignatoryPublicKey.key), + networkType, + ), + ); + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MultisigAccountModificationTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a ModifyMultisigAccountTransaction diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index f366fc0aed..3f1877838a 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, RawAddress } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder'; @@ -29,6 +30,7 @@ import { NetworkType } from '../blockchain/NetworkType'; import { MosaicId } from '../mosaic/MosaicId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -119,6 +121,34 @@ export class MosaicAddressRestrictionTransaction extends Transaction { super(TransactionType.MOSAIC_ADDRESS_RESTRICTION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMosaicAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MosaicAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = MosaicAddressRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as MosaicAddressRestrictionTransactionBuilder).getDeadline().timestamp), + new MosaicId(builder.getMosaicId().unresolvedMosaicId), + new UInt64(builder.getRestrictionKey()), + Address.createFromEncoded(Convert.uint8ToHex(builder.getTargetAddress().unresolvedAddress)), + new UInt64(builder.getPreviousRestrictionValue()), + new UInt64(builder.getNewRestrictionValue()), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MosaicAddressRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a MosaicDefinitionTransaction diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index 447d5530ad..6d7cae3183 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder'; @@ -31,6 +32,7 @@ import { AliasAction } from '../namespace/AliasAction'; import { NamespaceId } from '../namespace/NamespaceId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -98,6 +100,31 @@ export class MosaicAliasTransaction extends Transaction { super(TransactionType.MOSAIC_ALIAS, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMosaicAliasTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MosaicAliasTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = MosaicAliasTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as MosaicAliasTransactionBuilder).getDeadline().timestamp), + builder.getAliasAction().valueOf(), + new NamespaceId(builder.getNamespaceId().namespaceId), + new MosaicId(builder.getMosaicId().mosaicId), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MosaicAliasTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a MosaicAliasTransaction diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 9ebbf03fe6..1616044875 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; @@ -33,6 +34,7 @@ import { MosaicNonce } from '../mosaic/MosaicNonce'; import { MosaicProperties } from '../mosaic/MosaicProperties'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -104,6 +106,38 @@ export class MosaicDefinitionTransaction extends Transaction { super(TransactionType.MOSAIC_DEFINITION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMosaicDefinitionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MosaicDefinitionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = MosaicDefinitionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as MosaicDefinitionTransactionBuilder).getDeadline().timestamp), + new MosaicNonce(builder.getNonce().serialize()), + new MosaicId(builder.getId().mosaicId), + MosaicProperties.create({ + supplyMutable: (builder.getFlags() & 1) === 1, + transferable: (builder.getFlags() & 2) === 2, + divisibility: builder.getDivisibility(), + restrictable: (builder.getFlags() & 4) === 4, + duration: new UInt64(builder.getDuration().blockDuration), + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MosaicDefinitionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a MosaicDefinitionTransaction diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index 9081fa5dbc..c7e36df0d2 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicGlobalRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder'; @@ -29,6 +30,7 @@ import { MosaicId } from '../mosaic/MosaicId'; import { MosaicRestrictionType } from '../mosaic/MosaicRestrictionType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -136,6 +138,36 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { super(TransactionType.MOSAIC_GLOBAL_RESTRICTION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMosaicGlobalRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MosaicGlobalRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = MosaicGlobalRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as MosaicGlobalRestrictionTransactionBuilder).getDeadline().timestamp), + new MosaicId(builder.getMosaicId().unresolvedMosaicId), + new MosaicId(builder.getReferenceMosaicId().unresolvedMosaicId), + new UInt64(builder.getRestrictionKey()), + new UInt64(builder.getPreviousRestrictionValue()), + builder.getPreviousRestrictionType().valueOf(), + new UInt64(builder.getNewRestrictionValue()), + builder.getNewRestrictionType().valueOf(), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MosaicGlobalRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a MosaicDefinitionTransaction diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index 03f0137241..1ee6fc22d7 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder'; @@ -28,6 +29,7 @@ import { MosaicId } from '../mosaic/MosaicId'; import { MosaicSupplyType } from '../mosaic/MosaicSupplyType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -99,6 +101,32 @@ export class MosaicSupplyChangeTransaction extends Transaction { super(TransactionType.MOSAIC_SUPPLY_CHANGE, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMosaicSupplyChangeTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MosaicSupplyChangeTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = MosaicSupplyChangeTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as MosaicSupplyChangeTransactionBuilder).getDeadline().timestamp), + new MosaicId(builder.getMosaicId().unresolvedMosaicId), + builder.getAction().valueOf(), + new UInt64(builder.getDelta().amount), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MosaicSupplyChangeTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a MosaicSupplyChangeTransaction diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index 3089126e25..6c63a6c4e5 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, Convert as convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; @@ -30,6 +31,7 @@ import { NamespaceId } from '../namespace/NamespaceId'; import { NamespaceType } from '../namespace/NamespaceType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -145,6 +147,40 @@ export class RegisterNamespaceTransaction extends Transaction { super(TransactionType.REGISTER_NAMESPACE, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedNamespaceRegistrationTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + NamespaceRegistrationTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const namespaceType = builder.getRegistrationType().valueOf(); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = namespaceType === NamespaceType.RootNamespace ? + RegisterNamespaceTransaction.createRootNamespace( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as NamespaceRegistrationTransactionBuilder).getDeadline().timestamp), + Convert.decodeHex(Convert.uint8ToHex(builder.getName())), + new UInt64(builder.getDuration()!.blockDuration), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as NamespaceRegistrationTransactionBuilder).fee.amount), + ) : RegisterNamespaceTransaction.createSubNamespace( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as NamespaceRegistrationTransactionBuilder).getDeadline().timestamp), + Convert.decodeHex(Convert.uint8ToHex(builder.getName())), + new NamespaceId(builder.getParentId()!.namespaceId), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as NamespaceRegistrationTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a RegisterNamespaceTransaction diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index 5efbe3c3fe..6dd679613e 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -13,7 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Convert as convert, RawAddress } from '../../core/format'; +import { SignSchema } from '../../core/crypto/SignSchema'; +import { Convert, Convert as convert, RawAddress } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedSecretLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder'; @@ -30,9 +31,11 @@ import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { Mosaic } from '../mosaic/Mosaic'; +import { MosaicId } from '../mosaic/MosaicId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; import { HashType, HashTypeLengthValidator } from './HashType'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -122,6 +125,37 @@ export class SecretLockTransaction extends Transaction { } } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedSecretLockTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + SecretLockTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = SecretLockTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as SecretLockTransactionBuilder).getDeadline().timestamp), + new Mosaic( + new MosaicId(builder.getMosaic().mosaicId.unresolvedMosaicId), + new UInt64(builder.getMosaic().amount.amount), + ), + new UInt64(builder.getDuration().blockDuration), + builder.getHashAlgorithm().valueOf(), + Convert.uint8ToHex(builder.getSecret().hash256), + Address.createFromEncoded(Convert.uint8ToHex(builder.getRecipient().unresolvedAddress)), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as SecretLockTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a SecretLockTransaction diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index cbca7576b2..0752efa2f1 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, Convert as convert, RawAddress } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedSecretProofTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder'; @@ -30,6 +31,7 @@ import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; import { HashType, HashTypeLengthValidator } from './HashType'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -99,6 +101,33 @@ export class SecretProofTransaction extends Transaction { } } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedSecretProofTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + SecretProofTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = SecretProofTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as SecretProofTransactionBuilder).getDeadline().timestamp), + builder.getHashAlgorithm().valueOf(), + Convert.uint8ToHex(builder.getSecret().hash256), + Address.createFromEncoded(Convert.uint8ToHex(builder.getRecipient().unresolvedAddress)), + Convert.uint8ToHex(builder.getProof()), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as SecretProofTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a SecretProofTransaction diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index c78253b040..2826509990 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, Convert as convert } from '../../core/format'; import { RawAddress } from '../../core/format/RawAddress'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -31,10 +32,15 @@ import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { Mosaic } from '../mosaic/Mosaic'; +import { MosaicId } from '../mosaic/MosaicId'; import { NamespaceId } from '../namespace/NamespaceId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { EncryptedMessage } from './EncryptedMessage'; +import { InnerTransaction } from './InnerTransaction'; import { Message } from './Message'; +import { MessageType } from './MessageType'; +import { PlainMessage } from './PlainMessage'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -103,6 +109,40 @@ export class TransferTransaction extends Transaction { super(TransactionType.TRANSFER, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedTransferTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + TransferTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const messageType = builder.getMessage()[0]; + const messageHex = Convert.uint8ToHex(builder.getMessage()).substring(2); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = TransferTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as TransferTransactionBuilder).getDeadline().timestamp), + Address.createFromEncoded(Convert.uint8ToHex(builder.getRecipient().unresolvedAddress)), + builder.getMosaics().map((mosaic) => { + return new Mosaic( + new MosaicId(mosaic.mosaicId.unresolvedMosaicId), + new UInt64(mosaic.amount.amount)); + }), + messageType === MessageType.PlainMessage ? + PlainMessage.createFromPayload(messageHex) : + EncryptedMessage.createFromPayload(messageHex), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as TransferTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * Return the string notation for the set recipient * @internal From 0fb20711bbf89ef702d709dc892dd84e011d7e52 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 19 Aug 2019 10:43:56 +0100 Subject: [PATCH 52/98] Applied generated aggregate transaction from catbuffer-generator --- .../AggregateBondedTransactionBuilder.ts | 112 +++++++++++++++ .../AggregateCompleteTransactionBuilder.ts | 112 +++++++++++++++ .../AggregateTransactionBodyBuilder.ts | 102 ++++++++++++++ .../catbuffer/AggregateTransactionBuilder.ts | 132 ------------------ .../catbuffer/CosignatureBuilder.ts | 30 ++-- .../catbuffer/DetachedCosignatureBuilder.ts | 46 +++--- src/infrastructure/catbuffer/EntityTypeDto.ts | 106 +++++--------- .../catbuffer/GeneratorUtils.ts | 55 ++++---- src/model/transaction/AggregateTransaction.ts | 36 +++-- 9 files changed, 449 insertions(+), 282 deletions(-) create mode 100644 src/infrastructure/catbuffer/AggregateBondedTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AggregateCompleteTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AggregateTransactionBodyBuilder.ts delete mode 100644 src/infrastructure/catbuffer/AggregateTransactionBuilder.ts diff --git a/src/infrastructure/catbuffer/AggregateBondedTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateBondedTransactionBuilder.ts new file mode 100644 index 0000000000..af3e1e2ed0 --- /dev/null +++ b/src/infrastructure/catbuffer/AggregateBondedTransactionBuilder.ts @@ -0,0 +1,112 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AggregateTransactionBodyBuilder } from './AggregateTransactionBodyBuilder'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for an aggregate bonded transaction. */ +export class AggregateBondedTransactionBuilder extends TransactionBuilder { + /** Aggregate transaction body. */ + aggregateTransactionBody: AggregateTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param transactions Sub-transaction data (transactions are variable sized and payload size is in bytes). + * @param cosignatures Cosignatures data (fills remaining body space after transactions). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, transactions: Uint8Array, cosignatures: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + this.aggregateTransactionBody = new AggregateTransactionBodyBuilder(transactions, cosignatures); + } + + /** + * Creates an instance of AggregateBondedTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AggregateBondedTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AggregateBondedTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const aggregateTransactionBody = AggregateTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, aggregateTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AggregateBondedTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, aggregateTransactionBody.transactions, aggregateTransactionBody.cosignatures); + } + + /** + * Gets sub-transaction data (transactions are variable sized and payload size is in bytes). + * + * @return Sub-transaction data (transactions are variable sized and payload size is in bytes). + */ + public getTransactions(): Uint8Array { + return this.aggregateTransactionBody.getTransactions(); + } + + /** + * Gets cosignatures data (fills remaining body space after transactions). + * + * @return Cosignatures data (fills remaining body space after transactions). + */ + public getCosignatures(): Uint8Array { + return this.aggregateTransactionBody.getCosignatures(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.aggregateTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const aggregateTransactionBodyBytes = this.aggregateTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, aggregateTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AggregateCompleteTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateCompleteTransactionBuilder.ts new file mode 100644 index 0000000000..a68fd86f07 --- /dev/null +++ b/src/infrastructure/catbuffer/AggregateCompleteTransactionBuilder.ts @@ -0,0 +1,112 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AggregateTransactionBodyBuilder } from './AggregateTransactionBodyBuilder'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for an aggregate complete transaction. */ +export class AggregateCompleteTransactionBuilder extends TransactionBuilder { + /** Aggregate transaction body. */ + aggregateTransactionBody: AggregateTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param transactions Sub-transaction data (transactions are variable sized and payload size is in bytes). + * @param cosignatures Cosignatures data (fills remaining body space after transactions). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, transactions: Uint8Array, cosignatures: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + this.aggregateTransactionBody = new AggregateTransactionBodyBuilder(transactions, cosignatures); + } + + /** + * Creates an instance of AggregateCompleteTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AggregateCompleteTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AggregateCompleteTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const aggregateTransactionBody = AggregateTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, aggregateTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AggregateCompleteTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, aggregateTransactionBody.transactions, aggregateTransactionBody.cosignatures); + } + + /** + * Gets sub-transaction data (transactions are variable sized and payload size is in bytes). + * + * @return Sub-transaction data (transactions are variable sized and payload size is in bytes). + */ + public getTransactions(): Uint8Array { + return this.aggregateTransactionBody.getTransactions(); + } + + /** + * Gets cosignatures data (fills remaining body space after transactions). + * + * @return Cosignatures data (fills remaining body space after transactions). + */ + public getCosignatures(): Uint8Array { + return this.aggregateTransactionBody.getCosignatures(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.aggregateTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const aggregateTransactionBodyBytes = this.aggregateTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, aggregateTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AggregateTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AggregateTransactionBodyBuilder.ts new file mode 100644 index 0000000000..4d84e86f79 --- /dev/null +++ b/src/infrastructure/catbuffer/AggregateTransactionBodyBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for an aggregate transaction. */ +export class AggregateTransactionBodyBuilder { + /** Sub-transaction data (transactions are variable sized and payload size is in bytes). */ + transactions: Uint8Array; + /** Cosignatures data (fills remaining body space after transactions). */ + cosignatures: Uint8Array; + + /** + * Constructor. + * + * @param transactions Sub-transaction data (transactions are variable sized and payload size is in bytes). + * @param cosignatures Cosignatures data (fills remaining body space after transactions). + */ + public constructor(transactions: Uint8Array, cosignatures: Uint8Array) { + this.transactions = transactions; + this.cosignatures = cosignatures; + } + + /** + * Creates an instance of AggregateTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AggregateTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AggregateTransactionBodyBuilder { + const byteArray = Array.from(payload); + const payloadSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + const transactions = GeneratorUtils.getBytes(Uint8Array.from(byteArray), payloadSize); + byteArray.splice(0, payloadSize); + const cosignatures = Uint8Array.from(byteArray); + return new AggregateTransactionBodyBuilder(transactions, cosignatures); + } + + /** + * Gets sub-transaction data (transactions are variable sized and payload size is in bytes). + * + * @return Sub-transaction data (transactions are variable sized and payload size is in bytes). + */ + public getTransactions(): Uint8Array { + return this.transactions; + } + + /** + * Gets cosignatures data (fills remaining body space after transactions). + * + * @return Cosignatures data (fills remaining body space after transactions). + */ + public getCosignatures(): Uint8Array { + return this.cosignatures; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 4; // payloadSize + size += this.transactions.length; + size += this.cosignatures.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const payloadSizeBytes = GeneratorUtils.uintToBuffer(this.transactions.length, 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.transactions); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.cosignatures); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts deleted file mode 100644 index 20462d8514..0000000000 --- a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts +++ /dev/null @@ -1,132 +0,0 @@ -// tslint:disable: jsdoc-format -/** -*** Copyright (c) 2016-present, -*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. -*** -*** This file is part of Catapult. -*** -*** Catapult is free software: you can redistribute it and/or modify -*** it under the terms of the GNU Lesser General Public License as published by -*** the Free Software Foundation, either version 3 of the License, or -*** (at your option) any later version. -*** -*** Catapult is distributed in the hope that it will be useful, -*** but WITHOUT ANY WARRANTY; without even the implied warranty of -*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -*** GNU Lesser General Public License for more details. -*** -*** You should have received a copy of the GNU Lesser General Public License -*** along with Catapult. If not, see . -**/ - -import { AmountDto } from './AmountDto'; -import { EntityTypeDto } from './EntityTypeDto'; -import { GeneratorUtils } from './GeneratorUtils'; -import { KeyDto } from './KeyDto'; -import { SignatureDto } from './SignatureDto'; -import { TimestampDto } from './TimestampDto'; -import { TransactionBuilder } from './TransactionBuilder'; - -/** binary layout for an aggregate transaction. */ -export class AggregateTransactionBuilder extends TransactionBuilder { - /** embedded transactions. */ - transactions: Uint8Array; - /** cosignatures. */ - cosignatures: Uint8Array; - - /** - * Constructor. - * - * @param signature entity signature. - * @param signer entity signer's public key. - * @param version entity version. - * @param type entity type. - * @param fee transaction fee. - * @param deadline transaction deadline. - * @param transactions embedded transactions. - * @param cosignatures cosignatures. - */ - public constructor( - signature: SignatureDto, - signer: KeyDto, - version: number, - type: EntityTypeDto, - fee: AmountDto, - deadline: TimestampDto, - transactions: Uint8Array, - cosignatures: Uint8Array) { - super(signature, signer, version, type, fee, deadline); - this.transactions = transactions; - this.cosignatures = cosignatures; - } - - /** - * loadFromBinary - Create an instance of AggregateTransactionBuilder from a stream. - * - * @param Uint8Array Byte to use to serialize the object. - * @return An instance of AggregateTransactionBuilder. - */ - public static loadFromBinary(payload: Uint8Array): AggregateTransactionBuilder { - const byteArray = Array.from(payload); - const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); - byteArray.splice(0, superObject.getSize()); - const payloadSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); - byteArray.splice(0, 4); - const transactions = GeneratorUtils.getBytes(Uint8Array.from(byteArray), payloadSize); - byteArray.splice(0, transactions.length); - const cosignatures = Uint8Array.from(byteArray); - // tslint:disable-next-line: max-line-length - return new AggregateTransactionBuilder(superObject.signature, superObject.signer, superObject.version, - superObject.type, superObject.fee, superObject.deadline, - transactions, cosignatures); - } - - /** - * Get embedded transactions. - * - * @return embedded transactions. - */ - public getTransactions(): Uint8Array { - return this.transactions; - } - - /** - * Get cosignatures. - * - * @return cosignatures. - */ - public getCosignatures(): Uint8Array { - return this.cosignatures; - } - - /** - * Get the size of the object. - * - * @return Size in bytes. - */ - public getSize(): number { - let size: number = super.getSize(); - size += 4; // payloadSize - size += this.transactions.length; - size += this.cosignatures.length; - return size; - } - - /** - * Serialize the object to bytes. - * - * @return Serialized bytes. - */ - public serialize(): Uint8Array { - let newArray = Uint8Array.from([]); - const superBytes = super.serialize(); - newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); - const payloadSizeBytes = GeneratorUtils.uintToBuffer(this.transactions.length, 4); - newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes); - const transactionBytes = this.transactions; - newArray = GeneratorUtils.concatTypedArrays(newArray, transactionBytes); - const cosignaturesBytes = this.cosignatures; - newArray = GeneratorUtils.concatTypedArrays(newArray, cosignaturesBytes); - return newArray; - } -} diff --git a/src/infrastructure/catbuffer/CosignatureBuilder.ts b/src/infrastructure/catbuffer/CosignatureBuilder.ts index 5e0ba7a43c..447524c2f6 100644 --- a/src/infrastructure/catbuffer/CosignatureBuilder.ts +++ b/src/infrastructure/catbuffer/CosignatureBuilder.ts @@ -23,29 +23,29 @@ import { GeneratorUtils } from './GeneratorUtils'; import { KeyDto } from './KeyDto'; import { SignatureDto } from './SignatureDto'; -/** a cosignature. */ +/** Cosignature attached to an aggregate transaction. */ export class CosignatureBuilder { - /** cosigner public key. */ + /** Cosigner public key. */ signer: KeyDto; - /** cosigner signature. */ + /** Cosigner signature. */ signature: SignatureDto; /** * Constructor. * - * @param signer cosigner public key. - * @param signature cosigner signature. + * @param signer Cosigner public key. + * @param signature Cosigner signature. */ - public constructor(signer: KeyDto, signature: SignatureDto) { + public constructor(signer: KeyDto, signature: SignatureDto) { this.signer = signer; this.signature = signature; } /** - * loadFromBinary - Create an instance of CosignatureBuilder from a stream. + * Creates an instance of CosignatureBuilder from binary payload. * - * @param payload Byte to use to serialize the object. - * @return An instance of CosignatureBuilder. + * @param payload Byte payload to use to serialize the object. + * @return Instance of CosignatureBuilder. */ public static loadFromBinary(payload: Uint8Array): CosignatureBuilder { const byteArray = Array.from(payload); @@ -57,25 +57,25 @@ export class CosignatureBuilder { } /** - * Get cosigner public key. + * Gets cosigner public key. * - * @return cosigner public key. + * @return Cosigner public key. */ public getSigner(): KeyDto { return this.signer; } /** - * Get cosigner signature. + * Gets cosigner signature. * - * @return cosigner signature. + * @return Cosigner signature. */ public getSignature(): SignatureDto { return this.signature; } /** - * Get the size of the object. + * Gets the size of the object. * * @return Size in bytes. */ @@ -87,7 +87,7 @@ export class CosignatureBuilder { } /** - * Serialize the object to bytes. + * Serializes an object to bytes. * * @return Serialized bytes. */ diff --git a/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts b/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts index 58a3152ed0..f10107ee30 100644 --- a/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts +++ b/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts @@ -19,77 +19,73 @@ *** along with Catapult. If not, see . **/ +import { CosignatureBuilder } from './CosignatureBuilder'; import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; import { KeyDto } from './KeyDto'; import { SignatureDto } from './SignatureDto'; -import { CosignatureBuilder } from './CosignatureBuilder'; -import { Hash256Dto } from './Hash256Dto'; -/** a detached cosignature. */ +/** Cosignature detached from an aggregate transaction. */ export class DetachedCosignatureBuilder extends CosignatureBuilder { - /** hash of the corresponding parent. */ + /** Hash of the aggregate transaction that is signed by this cosignature. */ parentHash: Hash256Dto; /** * Constructor. * - * @param signer cosigner public key. - * @param signature cosigner signature. - * @param parentHash hash of the corresponding parent. + * @param signer Cosigner public key. + * @param signature Cosigner signature. + * @param parentHash Hash of the aggregate transaction that is signed by this cosignature. */ - public constructor(signer: KeyDto, signature: SignatureDto, parentHash: Hash256Dto) { + public constructor(signer: KeyDto, signature: SignatureDto, parentHash: Hash256Dto) { super(signer, signature); this.parentHash = parentHash; } /** - * loadFromBinary - Create an instance of DetachedCosignatureBuilder from a stream. + * Creates an instance of DetachedCosignatureBuilder from binary payload. * - * @param payload Byte to use to serialize the object. - * @return An instance of DetachedCosignatureBuilder. + * @param payload Byte payload to use to serialize the object. + * @return Instance of DetachedCosignatureBuilder. */ public static loadFromBinary(payload: Uint8Array): DetachedCosignatureBuilder { const byteArray = Array.from(payload); - const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); - byteArray.splice(0, signer.getSize()); - const signature = SignatureDto.loadFromBinary(Uint8Array.from(byteArray)); - byteArray.splice(0, signature.getSize()); + const superObject = CosignatureBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); const parentHash = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); byteArray.splice(0, parentHash.getSize()); - return new DetachedCosignatureBuilder(signer, signature, parentHash); + return new DetachedCosignatureBuilder(superObject.signer, superObject.signature, parentHash); } /** - * Get hash of the corresponding parent. + * Gets hash of the aggregate transaction that is signed by this cosignature. * - * @return hash of the corresponding parent. + * @return Hash of the aggregate transaction that is signed by this cosignature. */ public getParentHash(): Hash256Dto { return this.parentHash; } /** - * Get the size of the object. + * Gets the size of the object. * * @return Size in bytes. */ public getSize(): number { - let size = super.getSize(); + let size: number = super.getSize(); size += this.parentHash.getSize(); return size; } /** - * Serialize the object to bytes. + * Serializes an object to bytes. * * @return Serialized bytes. */ public serialize(): Uint8Array { let newArray = Uint8Array.from([]); - const signerBytes = this.signer.serialize(); - newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); - const signatureBytes = this.signature.serialize(); - newArray = GeneratorUtils.concatTypedArrays(newArray, signatureBytes); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); const parentHashBytes = this.parentHash.serialize(); newArray = GeneratorUtils.concatTypedArrays(newArray, parentHashBytes); return newArray; diff --git a/src/infrastructure/catbuffer/EntityTypeDto.ts b/src/infrastructure/catbuffer/EntityTypeDto.ts index 52e1c55a94..921a115ce9 100644 --- a/src/infrastructure/catbuffer/EntityTypeDto.ts +++ b/src/infrastructure/catbuffer/EntityTypeDto.ts @@ -25,109 +25,67 @@ export enum EntityTypeDto { /** Reserved entity type. */ RESERVED = 0, /** - * Transfer Transaction transaction type. - * @type {number} + * Account address restriction transaction. */ - TRANSFER = 0x4154, - + ACCOUNT_ADDRESS_RESTRICTION_TRANSACTION = 0x4150, /** - * Register namespace transaction type. - * @type {number} + * Account mosaic restriction transaction. */ - REGISTER_NAMESPACE = 0x414E, - + ACCOUNT_MOSAIC_RESTRICTION_TRANSACTION = 0x4250, /** - * Address alias transaction type - * @type {number} + * Account operation restriction transaction. */ - ADDRESS_ALIAS = 0x424E, - + ACCOUNT_OPERATION_RESTRICTION_TRANSACTION = 0x4350, /** - * Mosaic alias transaction type - * @type {number} + * Account link transaction. */ - MOSAIC_ALIAS = 0x434E, - + ACCOUNT_LINK_TRANSACTION = 0x414C, /** - * Mosaic definition transaction type. - * @type {number} + * Address alias transaction. */ - MOSAIC_DEFINITION = 0x414D, - + ADDRESS_ALIAS_TRANSACTION = 0x424E, /** - * Mosaic supply change transaction. - * @type {number} + * Aggregate bonded transaction. */ - MOSAIC_SUPPLY_CHANGE = 0x424D, - + AGGREGATE_BONDED_TRANSACTION = 0x4241, /** - * Modify multisig account transaction type. - * @type {number} + * Aggregate complete transaction. */ - MODIFY_MULTISIG_ACCOUNT = 0x4155, - + AGGREGATE_COMPLETE_TRANSACTION = 0x4141, /** - * Aggregate complete transaction type. - * @type {number} + * Hash lock transaction. */ - AGGREGATE_COMPLETE = 0x4141, - + HASH_LOCK_TRANSACTION = 0x4148, /** - * Aggregate bonded transaction type + * Modify multisig account transaction. */ - AGGREGATE_BONDED = 0x4241, - + MODIFY_MULTISIG_ACCOUNT_TRANSACTION = 0x4155, /** - * Lock transaction type - * @type {number} + * Mosaic definition transaction. */ - LOCK = 0x4148, - + MOSAIC_DEFINITION_TRANSACTION = 0x414D, /** - * Secret Lock Transaction type - * @type {number} - */ - SECRET_LOCK = 0x4152, - - /** - * Secret Proof transaction type - * @type {number} + * Mosaic supply change transaction. */ - SECRET_PROOF = 0x4252, - + MOSAIC_SUPPLY_CHANGE_TRANSACTION = 0x424D, /** - * Account restriction address transaction type - * @type {number} + * Mosaic alias transaction. */ - ACCOUNT_RESTRICTION_ADDRESS = 0x4150, - + MOSAIC_ALIAS_TRANSACTION = 0x434E, /** - * Account restriction mosaic transaction type - * @type {number} + * Register namespace transaction. */ - ACCOUNT_RESTRICTION_MOSAIC = 0x4250, - + REGISTER_NAMESPACE_TRANSACTION = 0x414E, /** - * Account restriction operation transaction type - * @type {number} + * Secret lock transaction. */ - ACCOUNT_RESTRICTION_OPERATION = 0x4350, - + SECRET_LOCK_TRANSACTION = 0x4152, /** - * Link account transaction type - * @type {number} + * Secret Proof transaction. */ - LINK_ACCOUNT = 0x414C, - - /** - * Mosaic address restriction type - * @type {number} - */ - MOSAIC_ADDRESS_RESTRICTION = 0x4251, - + SECRET_PROOF_TRANSACTION = 0x4252, /** - * Mosaic global restriction type - * @type {number} + * Transfer transaction. */ - MOSAIC_GLOBAL_RESTRICTION = 0x4151, + TRANSFER_TRANSACTION = 0x4154, } diff --git a/src/infrastructure/catbuffer/GeneratorUtils.ts b/src/infrastructure/catbuffer/GeneratorUtils.ts index 7e95285569..f1f8ecb3d3 100644 --- a/src/infrastructure/catbuffer/GeneratorUtils.ts +++ b/src/infrastructure/catbuffer/GeneratorUtils.ts @@ -25,7 +25,8 @@ export class GeneratorUtils { /** - * Converts a (64bit) uint8 array into a number array. + * Convert a UInt8Array input into an array of 2 numbers. + * Numbers in the returned array are cast to UInt32. * @param {Uint8Array} input A uint8 array. * @returns {number[]} The uint64 representation of the input. */ @@ -39,7 +40,7 @@ export class GeneratorUtils { } /** - * Read buffer into 32bits integer at given index. + * Read 4 bytes as a uint32 value from buffer bytes starting at given index. * @param {Uint8Array} bytes A uint8 array. * @param {number} index Index. * @returns {number} 32bits integer. @@ -49,7 +50,7 @@ export class GeneratorUtils { } /** - * Write uint to buffer + * Convert uint value into buffer * @param {number} uintValue A uint8 array. * @param {number} bufferSize Buffer size. * @returns {Uint8Array} @@ -57,39 +58,45 @@ export class GeneratorUtils { public static uintToBuffer(uintValue: number, bufferSize: number): Uint8Array { const buffer = new ArrayBuffer(bufferSize); const dataView = new DataView(buffer); - if (1 === bufferSize) { - dataView.setUint8(0, uintValue); - } else if (2 === bufferSize) { - dataView.setUint16(0, uintValue, true); - } else if (4 === bufferSize) { - dataView.setUint32(0, uintValue, true); - } else { - throw new Error('Unexpected bufferSize'); + try { + if (1 === bufferSize) { + dataView.setUint8(0, uintValue); + } else if (2 === bufferSize) { + dataView.setUint16(0, uintValue, true); + } else if (4 === bufferSize) { + dataView.setUint32(0, uintValue, true); + } else { + throw new Error('Unexpected bufferSize'); + } + return new Uint8Array(buffer); + } catch (e) { + throw new Error(`Converting uint value ${uintValue} into buffer with error: ${e}`); } - - return new Uint8Array(buffer); } /** - * Write uint to buffer + * Convert uint8 array buffer into number * @param {Uint8Array} buffer A uint8 array. * @returns {number} */ public static bufferToUint(buffer: Uint8Array): number { const dataView = new DataView(buffer.buffer); - if (1 === buffer.byteLength) { - return dataView.getUint8(0); - } else if (2 === buffer.byteLength) { - return dataView.getUint16(0, true); - } else if (4 === buffer.byteLength) { - return dataView.getUint32(0, true); - } - - throw new Error('Unexpected buffer size'); + try { + if (1 === buffer.byteLength) { + return dataView.getUint8(0); + } else if (2 === buffer.byteLength) { + return dataView.getUint16(0, true); + } else if (4 === buffer.byteLength) { + return dataView.getUint32(0, true); + } + throw new Error('Unexpected buffer size'); + } catch (e) { + throw new Error(`Converting buffer into number with error: ${e}`); + } } /** - * Write Uint64 to buffer + * Convert unit64 into buffer * @param {number} uintValue Uint64 (number[]). * @returns {Uint8Array} */ diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index cb3ee4d299..ba8affb7a7 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -16,7 +16,8 @@ import { KeyPair, SignSchema } from '../../core/crypto'; import { Convert } from '../../core/format'; -import { AggregateTransactionBuilder } from '../../infrastructure/catbuffer/AggregateTransactionBuilder'; +import { AggregateBondedTransactionBuilder } from '../../infrastructure/catbuffer/AggregateBondedTransactionBuilder'; +import { AggregateCompleteTransactionBuilder } from '../../infrastructure/catbuffer/AggregateCompleteTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { CosignatureBuilder } from '../../infrastructure/catbuffer/CosignatureBuilder'; import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; @@ -130,7 +131,7 @@ export class AggregateTransaction extends Transaction { * @returns {AggregateTransaction} */ public static createFromPayload(payload: string, signSchema: SignSchema = SignSchema.SHA3): AggregateTransaction { - const builder = AggregateTransactionBuilder + const builder = AggregateCompleteTransactionBuilder .loadFromBinary(Convert.hexToUint8(payload)); const type = builder.getType().valueOf(); const innerTransactionHex = Convert.uint8ToHex(builder.getTransactions()); @@ -297,16 +298,27 @@ export class AggregateTransaction extends Transaction { cosignatures = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); }); - const transactionBuilder = new AggregateTransactionBuilder( - new SignatureDto(signatureBuffer), - new KeyDto(signerBuffer), - this.versionToDTO(), - this.type.valueOf(), - new AmountDto(this.maxFee.toDTO()), - new TimestampDto(this.deadline.toDTO()), - transactions, - cosignatures, - ); + const transactionBuilder = this.type === TransactionType.AGGREGATE_COMPLETE ? + new AggregateCompleteTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + this.type.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + transactions, + cosignatures, + ) : + new AggregateBondedTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + this.type.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + transactions, + cosignatures, + ); return transactionBuilder.serialize(); } From 4ccde62c2aea55be28db346010acb675e8108569 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 19 Aug 2019 20:58:08 +0100 Subject: [PATCH 53/98] Fixed aggregate transaction creatFromPayload - Catbuffer use separate builder class for Complete and Bonded - Added unit tests --- src/model/transaction/AggregateTransaction.ts | 11 +++++--- test/core/utils/TransactionMapping.spec.ts | 2 ++ .../transaction/AggregateTransaction.spec.ts | 27 +++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index ba8affb7a7..06ed339e99 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -131,9 +131,14 @@ export class AggregateTransaction extends Transaction { * @returns {AggregateTransaction} */ public static createFromPayload(payload: string, signSchema: SignSchema = SignSchema.SHA3): AggregateTransaction { - const builder = AggregateCompleteTransactionBuilder - .loadFromBinary(Convert.hexToUint8(payload)); - const type = builder.getType().valueOf(); + /** + * Get transaction type from the payload hex + * As buffer uses separate builder class for Complete and bonded + */ + const type = parseInt(Convert.uint8ToHex(Convert.hexToUint8(payload.substring(204, 208)).reverse()), 16); + const builder = type === TransactionType.AGGREGATE_COMPLETE ? + AggregateCompleteTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AggregateBondedTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); const innerTransactionHex = Convert.uint8ToHex(builder.getTransactions()); const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; const consignaturesHex = Convert.uint8ToHex(builder.getCosignatures()); diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index d07628b97e..7f80ee3375 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -439,6 +439,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AggregateTransaction; + expect(transaction.type).to.be.equal(TransactionType.AGGREGATE_COMPLETE); expect(transaction.innerTransactions[0].type).to.be.equal(TransactionType.TRANSFER); }); @@ -461,6 +462,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AggregateTransaction; + expect(transaction.type).to.be.equal(TransactionType.AGGREGATE_BONDED); expect(transaction.innerTransactions[0].type).to.be.equal(TransactionType.TRANSFER); }); diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 072302eba9..f26df17f9b 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -265,6 +265,33 @@ describe('AggregateTransaction', () => { }); + it('should createBonded an AggregateTransaction object with TransferTransaction', () => { + const transferTransaction = TransferTransaction.create( + Deadline.create(), + Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + [], + PlainMessage.create('test-message'), + NetworkType.MIJIN_TEST, + ); + + const aggregateTransaction = AggregateTransaction.createBonded( + Deadline.create(2, ChronoUnit.MINUTES), + [transferTransaction.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); + expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); + expect(signedTransaction.payload.substring(204, 208)).to.be.equal('4142'); + expect(signedTransaction.payload.substring( + 320, + signedTransaction.payload.length, + )).to.be.equal('019054419050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000000746573742D6D657373616765'); + }); + it('should validate if accounts have signed an aggregate transaction', () => { const aggregateTransactionDTO = { meta: { From 2b17f55a18a12aee4beb9790fa612d8441db508d Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 20 Aug 2019 19:59:36 +0100 Subject: [PATCH 54/98] Added metadata transactions --- e2e/infrastructure/TransactionHttp.spec.ts | 301 +++++++++++++----- src/infrastructure/catbuffer/EntityTypeDto.ts | 12 + .../transaction/CreateTransactionFromDTO.ts | 50 +++ .../CreateTransactionFromPayload.ts | 9 + .../transaction/SerializeTransactionToJSON.ts | 33 ++ .../transaction/AccountMetadataTransaction.ts | 193 +++++++++++ .../transaction/MosaicMetadataTransaction.ts | 207 ++++++++++++ .../NamespaceMetaDataTransaction.ts | 208 ++++++++++++ src/model/transaction/TransactionType.ts | 18 ++ src/model/transaction/TransactionVersion.ts | 18 ++ test/core/utils/TransactionMapping.spec.ts | 134 ++++++++ .../AccountMetadataTransaction.spec.ts | 105 ++++++ .../MosaicMetadataTransaction.spec.ts | 112 +++++++ .../transaction/NamespaceMetadata.spec.ts | 112 +++++++ 14 files changed, 1431 insertions(+), 81 deletions(-) create mode 100644 src/model/transaction/AccountMetadataTransaction.ts create mode 100644 src/model/transaction/MosaicMetadataTransaction.ts create mode 100644 src/model/transaction/NamespaceMetaDataTransaction.ts create mode 100644 test/model/transaction/AccountMetadataTransaction.spec.ts create mode 100644 test/model/transaction/MosaicMetadataTransaction.spec.ts create mode 100644 test/model/transaction/NamespaceMetadata.spec.ts diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index d15c87fd4b..6b9e78d610 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -18,7 +18,7 @@ import * as CryptoJS from 'crypto-js'; import {ChronoUnit} from 'js-joda'; import {keccak_256, sha3_256} from 'js-sha3'; import {Crypto} from '../../src/core/crypto'; -import { Convert as convert } from '../../src/core/format'; +import { Convert as convert, Convert } from '../../src/core/format'; import { TransactionMapping } from '../../src/core/utils/TransactionMapping'; import {AccountHttp} from '../../src/infrastructure/AccountHttp'; import { NamespaceHttp } from '../../src/infrastructure/infrastructure'; @@ -66,6 +66,9 @@ import {Transaction} from '../../src/model/transaction/Transaction'; import {TransactionType} from '../../src/model/transaction/TransactionType'; import {TransferTransaction} from '../../src/model/transaction/TransferTransaction'; import {UInt64} from '../../src/model/UInt64'; +import { AccountMetadataTransaction } from '../../src/model/transaction/AccountMetadataTransaction'; +import { MosaicMetadataTransaction } from '../../src/model/transaction/MosaicMetadataTransaction'; +import { NamespaceMetadataTransaction } from '../../src/model/transaction/NamespaceMetaDataTransaction'; describe('TransactionHttp', () => { let transactionHash; let transactionId; @@ -208,6 +211,206 @@ describe('TransactionHttp', () => { }); }); + describe('AccountMetadataTransaction', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('aggregate', (done) => { + const accountMetadataTransaction = AccountMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + 10, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [accountMetadataTransaction.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + listener.confirmed(account.address).subscribe((transaction: AggregateTransaction) => { + transaction.innerTransactions.forEach((innerTx) => { + expect((innerTx as AccountMetadataTransaction).targetPublicKey, 'TargetPublicKey').not.to.be.undefined; + expect((innerTx as AccountMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; + expect((innerTx as AccountMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; + expect((innerTx as AccountMetadataTransaction).value, 'Value').not.to.be.undefined; + }); + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + + describe('MosaicMetadataTransaction', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('aggregate', (done) => { + const mosaicMetadataTransaction = MosaicMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + mosaicId, + 10, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [mosaicMetadataTransaction.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + listener.confirmed(account.address).subscribe((transaction: AggregateTransaction) => { + transaction.innerTransactions.forEach((innerTx) => { + expect((innerTx as MosaicMetadataTransaction).targetPublicKey, 'TargetPublicKey').not.to.be.undefined; + expect((innerTx as MosaicMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; + expect((innerTx as MosaicMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; + expect((innerTx as MosaicMetadataTransaction).value, 'Value').not.to.be.undefined; + expect((innerTx as MosaicMetadataTransaction).targetMosaicId, 'TargetMosaicId').not.to.be.undefined; + }); + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + + describe('RegisterNamespaceTransaction', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('standalone', (done) => { + const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); + const registerNamespaceTransaction = RegisterNamespaceTransaction.createRootNamespace( + Deadline.create(), + namespaceName, + UInt64.fromUint(1000), + NetworkType.MIJIN_TEST, + ); + namespaceId = new NamespaceId(namespaceName); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + listener.confirmed(account.address).subscribe((transaction: RegisterNamespaceTransaction) => { + expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; + expect(transaction.namespaceName, 'NamespaceName').not.to.be.undefined; + expect(transaction.namespaceType, 'NamespaceType').not.to.be.undefined; + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + + describe('RegisterNamespaceTransaction', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('aggregate', (done) => { + const registerNamespaceTransaction = RegisterNamespaceTransaction.createRootNamespace( + Deadline.create(), + 'root-test-namespace-' + Math.floor(Math.random() * 10000), + UInt64.fromUint(1000), + NetworkType.MIJIN_TEST, + ); + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [registerNamespaceTransaction.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + []); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + listener.confirmed(account.address).subscribe((transaction: Transaction) => { + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + + describe('NamespaceMetadataTransaction', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('aggregate', (done) => { + const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + namespaceId, + 10, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [namespaceMetadataTransaction.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + listener.confirmed(account.address).subscribe((transaction: AggregateTransaction) => { + transaction.innerTransactions.forEach((innerTx) => { + expect((innerTx as NamespaceMetadataTransaction).targetPublicKey, 'TargetPublicKey').not.to.be.undefined; + expect((innerTx as NamespaceMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; + expect((innerTx as NamespaceMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; + expect((innerTx as NamespaceMetadataTransaction).value, 'Value').not.to.be.undefined; + expect((innerTx as NamespaceMetadataTransaction).targetNamespaceId, 'TargetNamespaceId').not.to.be.undefined; + }); + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + describe('MosaicGlobalRestrictionTransaction', () => { let listener: Listener; before (() => { @@ -677,71 +880,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('RegisterNamespaceTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { - const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); - const registerNamespaceTransaction = RegisterNamespaceTransaction.createRootNamespace( - Deadline.create(), - namespaceName, - UInt64.fromUint(1000), - NetworkType.MIJIN_TEST, - ); - namespaceId = new NamespaceId(namespaceName); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: RegisterNamespaceTransaction) => { - expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; - expect(transaction.namespaceName, 'NamespaceName').not.to.be.undefined; - expect(transaction.namespaceType, 'NamespaceType').not.to.be.undefined; - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); - }); - }); - describe('RegisterNamespaceTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { - const registerNamespaceTransaction = RegisterNamespaceTransaction.createRootNamespace( - Deadline.create(), - 'root-test-namespace-' + Math.floor(Math.random() * 10000), - UInt64.fromUint(1000), - NetworkType.MIJIN_TEST, - ); - const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), - [registerNamespaceTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - []); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); - }); - }); + describe('AddressAliasTransaction', () => { let listener: Listener; before (() => { @@ -1381,7 +1520,7 @@ describe('TransactionHttp', () => { account2.address, NetworkType.MIJIN_TEST, ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { + listener.confirmed(account.address).subscribe(() => { listener.confirmed(account2.address).subscribe((transaction: SecretProofTransaction) => { expect(transaction.secret, 'Secret').not.to.be.undefined; expect(transaction.recipient, 'Recipient').not.to.be.undefined; @@ -1431,8 +1570,8 @@ describe('TransactionHttp', () => { account2.address, NetworkType.MIJIN_TEST, ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - listener.confirmed(account2.address).subscribe((transaction: Transaction) => { + listener.confirmed(account.address).subscribe(() => { + listener.confirmed(account2.address).subscribe(() => { done(); }); const secretProofTransaction = SecretProofTransaction.create( @@ -1479,8 +1618,8 @@ describe('TransactionHttp', () => { account2.address, NetworkType.MIJIN_TEST, ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - listener.confirmed(account2.address).subscribe((transaction: Transaction) => { + listener.confirmed(account.address).subscribe(() => { + listener.confirmed(account2.address).subscribe(() => { done(); }); const secretProofTransaction = SecretProofTransaction.create( @@ -1523,8 +1662,8 @@ describe('TransactionHttp', () => { account2.address, NetworkType.MIJIN_TEST, ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - listener.confirmed(account2.address).subscribe((transaction: Transaction) => { + listener.confirmed(account.address).subscribe(() => { + listener.confirmed(account2.address).subscribe(() => { done(); }); const secretProofTransaction = SecretProofTransaction.create( @@ -1573,8 +1712,8 @@ describe('TransactionHttp', () => { account2.address, NetworkType.MIJIN_TEST, ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - listener.confirmed(account2.address).subscribe((transaction: Transaction) => { + listener.confirmed(account.address).subscribe(() => { + listener.confirmed(account2.address).subscribe(() => { done(); }); listener.status(account2.address).subscribe((error) => { @@ -1625,8 +1764,8 @@ describe('TransactionHttp', () => { account2.address, NetworkType.MIJIN_TEST, ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - listener.confirmed(account2.address).subscribe((transaction: Transaction) => { + listener.confirmed(account.address).subscribe(() => { + listener.confirmed(account2.address).subscribe(() => { done(); }); listener.status(account2.address).subscribe((error) => { @@ -1680,8 +1819,8 @@ describe('TransactionHttp', () => { account2.address, NetworkType.MIJIN_TEST, ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - listener.confirmed(account2.address).subscribe((transaction: Transaction) => { + listener.confirmed(account.address).subscribe(() => { + listener.confirmed(account2.address).subscribe(() => { done(); }); listener.status(account2.address).subscribe((error) => { @@ -1731,8 +1870,8 @@ describe('TransactionHttp', () => { account2.address, NetworkType.MIJIN_TEST, ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - listener.confirmed(account2.address).subscribe((transaction: Transaction) => { + listener.confirmed(account.address).subscribe(() => { + listener.confirmed(account2.address).subscribe(() => { done(); }); listener.status(account2.address).subscribe((error) => { diff --git a/src/infrastructure/catbuffer/EntityTypeDto.ts b/src/infrastructure/catbuffer/EntityTypeDto.ts index 921a115ce9..56350b2507 100644 --- a/src/infrastructure/catbuffer/EntityTypeDto.ts +++ b/src/infrastructure/catbuffer/EntityTypeDto.ts @@ -28,6 +28,10 @@ export enum EntityTypeDto { * Account address restriction transaction. */ ACCOUNT_ADDRESS_RESTRICTION_TRANSACTION = 0x4150, + /** + * Account metadata transaction + */ + ACCOUNT_METADATA_TRANSACTION = 0x4144, /** * Account mosaic restriction transaction. */ @@ -64,6 +68,10 @@ export enum EntityTypeDto { * Mosaic definition transaction. */ MOSAIC_DEFINITION_TRANSACTION = 0x414D, + /** + * Mosaic metadata transaction. + */ + MOSAIC_METADATA_TRANSACTION = 0x4244, /** * Mosaic supply change transaction. */ @@ -72,6 +80,10 @@ export enum EntityTypeDto { * Mosaic alias transaction. */ MOSAIC_ALIAS_TRANSACTION = 0x434E, + /** + * Namespace metadata transaction. + */ + NAMESPACE_METADATA_TRANSACTION = 0x4344, /** * Register namespace transaction. */ diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index e6a1e3d7ae..d97e24bd4a 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -26,6 +26,7 @@ import { MosaicPropertyType } from '../../model/mosaic/MosaicPropertyType'; import {NamespaceId} from '../../model/namespace/NamespaceId'; import {AccountAddressRestrictionTransaction} from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; +import { AccountMetadataTransaction } from '../../model/transaction/AccountMetadataTransaction'; import {AccountMosaicRestrictionTransaction} from '../../model/transaction/AccountMosaicRestrictionTransaction'; import {AccountOperationRestrictionTransaction} from '../../model/transaction/AccountOperationRestrictionTransaction'; import {AccountRestrictionModification} from '../../model/transaction/AccountRestrictionModification'; @@ -42,8 +43,10 @@ import { MosaicAddressRestrictionTransaction } from '../../model/transaction/Mos import {MosaicAliasTransaction} from '../../model/transaction/MosaicAliasTransaction'; import {MosaicDefinitionTransaction} from '../../model/transaction/MosaicDefinitionTransaction'; import { MosaicGlobalRestrictionTransaction } from '../../model/transaction/MosaicGlobalRestrictionTransaction'; +import { MosaicMetadataTransaction } from '../../model/transaction/MosaicMetadataTransaction'; import {MosaicSupplyChangeTransaction} from '../../model/transaction/MosaicSupplyChangeTransaction'; import {MultisigCosignatoryModification} from '../../model/transaction/MultisigCosignatoryModification'; +import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetaDataTransaction'; import {EmptyMessage, PlainMessage} from '../../model/transaction/PlainMessage'; import {RegisterNamespaceTransaction} from '../../model/transaction/RegisterNamespaceTransaction'; import {SecretLockTransaction} from '../../model/transaction/SecretLockTransaction'; @@ -377,6 +380,53 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr extractNetworkType(transactionDTO.version)) : undefined, transactionInfo, ); + } else if (transactionDTO.type === TransactionType.ACCOUNT_METADATA_TRANSACTION) { + return new AccountMetadataTransaction( + extractNetworkType(transactionDTO.version), + extractTransactionVersion(transactionDTO.version), + Deadline.createFromDTO(transactionDTO.deadline), + new UInt64(transactionDTO.maxFee || [0, 0]), + transactionDTO.targetPublicKey, + new UInt64(transactionDTO.scopedMetadataKey), + transactionDTO.valueSizeDelta, + convert.hexToUint8(transactionDTO.value), + transactionDTO.signature, + transactionDTO.signer ? PublicAccount.createFromPublicKey(transactionDTO.signer, + extractNetworkType(transactionDTO.version)) : undefined, + transactionInfo, + ); + } else if (transactionDTO.type === TransactionType.MOSAIC_METADATA_TRANSACTION) { + return new MosaicMetadataTransaction( + extractNetworkType(transactionDTO.version), + extractTransactionVersion(transactionDTO.version), + Deadline.createFromDTO(transactionDTO.deadline), + new UInt64(transactionDTO.maxFee || [0, 0]), + transactionDTO.targetPublicKey, + new UInt64(transactionDTO.scopedMetadataKey), + new MosaicId(transactionDTO.targetMosaicId), + transactionDTO.valueSizeDelta, + convert.hexToUint8(transactionDTO.value), + transactionDTO.signature, + transactionDTO.signer ? PublicAccount.createFromPublicKey(transactionDTO.signer, + extractNetworkType(transactionDTO.version)) : undefined, + transactionInfo, + ); + } else if (transactionDTO.type === TransactionType.NAMESPACE_METADATA_TRANSACTION) { + return new NamespaceMetadataTransaction( + extractNetworkType(transactionDTO.version), + extractTransactionVersion(transactionDTO.version), + Deadline.createFromDTO(transactionDTO.deadline), + new UInt64(transactionDTO.maxFee || [0, 0]), + transactionDTO.targetPublicKey, + new UInt64(transactionDTO.scopedMetadataKey), + new NamespaceId(transactionDTO.targetNamespaceId), + transactionDTO.valueSizeDelta, + convert.hexToUint8(transactionDTO.value), + transactionDTO.signature, + transactionDTO.signer ? PublicAccount.createFromPublicKey(transactionDTO.signer, + extractNetworkType(transactionDTO.version)) : undefined, + transactionInfo, + ); } throw new Error('Unimplemented transaction with type ' + transactionDTO.type); }; diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index 3f79ea2d5e..87a5455da5 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -19,6 +19,7 @@ import { Convert as convert } from '../../core/format'; import { InnerTransaction } from '../../model/model'; import { AccountAddressRestrictionTransaction } from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; +import { AccountMetadataTransaction } from '../../model/transaction/AccountMetadataTransaction'; import { AccountMosaicRestrictionTransaction } from '../../model/transaction/AccountMosaicRestrictionTransaction'; import { AccountOperationRestrictionTransaction } from '../../model/transaction/AccountOperationRestrictionTransaction'; import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction'; @@ -29,7 +30,9 @@ import { MosaicAddressRestrictionTransaction } from '../../model/transaction/Mos import { MosaicAliasTransaction } from '../../model/transaction/MosaicAliasTransaction'; import { MosaicDefinitionTransaction } from '../../model/transaction/MosaicDefinitionTransaction'; import { MosaicGlobalRestrictionTransaction } from '../../model/transaction/MosaicGlobalRestrictionTransaction'; +import { MosaicMetadataTransaction } from '../../model/transaction/MosaicMetadataTransaction'; import { MosaicSupplyChangeTransaction } from '../../model/transaction/MosaicSupplyChangeTransaction'; +import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetaDataTransaction'; import { RegisterNamespaceTransaction } from '../../model/transaction/RegisterNamespaceTransaction'; import { SecretLockTransaction } from '../../model/transaction/SecretLockTransaction'; import { SecretProofTransaction } from '../../model/transaction/SecretProofTransaction'; @@ -92,6 +95,12 @@ export const CreateTransactionFromPayload = (payload: string, return MosaicGlobalRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MOSAIC_ADDRESS_RESTRICTION: return MosaicAddressRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); + case TransactionType.ACCOUNT_METADATA_TRANSACTION: + return AccountMetadataTransaction.createFromPayload(payload, isEmbedded, signSchema); + case TransactionType.MOSAIC_METADATA_TRANSACTION: + return MosaicMetadataTransaction.createFromPayload(payload, isEmbedded, signSchema); + case TransactionType.NAMESPACE_METADATA_TRANSACTION: + return NamespaceMetadataTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.AGGREGATE_COMPLETE: case TransactionType.AGGREGATE_BONDED: return AggregateTransaction.createFromPayload(payload, signSchema); diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index 4ba47f1e4c..ee68778a74 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -14,8 +14,10 @@ * limitations under the License. */ +import { Convert } from '../../core/format/Convert'; import { AccountAddressRestrictionTransaction } from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; +import { AccountMetadataTransaction } from '../../model/transaction/AccountMetadataTransaction'; import { AccountMosaicRestrictionTransaction } from '../../model/transaction/AccountMosaicRestrictionTransaction'; import { AccountOperationRestrictionTransaction } from '../../model/transaction/AccountOperationRestrictionTransaction'; import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction'; @@ -26,7 +28,9 @@ import { MosaicAddressRestrictionTransaction } from '../../model/transaction/Mos import { MosaicAliasTransaction } from '../../model/transaction/MosaicAliasTransaction'; import { MosaicDefinitionTransaction } from '../../model/transaction/MosaicDefinitionTransaction'; import { MosaicGlobalRestrictionTransaction } from '../../model/transaction/MosaicGlobalRestrictionTransaction'; +import { MosaicMetadataTransaction } from '../../model/transaction/MosaicMetadataTransaction'; import { MosaicSupplyChangeTransaction } from '../../model/transaction/MosaicSupplyChangeTransaction'; +import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetaDataTransaction'; import { RegisterNamespaceTransaction } from '../../model/transaction/RegisterNamespaceTransaction'; import { SecretLockTransaction } from '../../model/transaction/SecretLockTransaction'; import { SecretProofTransaction } from '../../model/transaction/SecretProofTransaction'; @@ -178,6 +182,35 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { previousRestrictionValue: (transaction as MosaicAddressRestrictionTransaction).previousRestrictionValue.toDTO(), newRestrictionValue: (transaction as MosaicAddressRestrictionTransaction).newRestrictionValue.toDTO(), + }; + case TransactionType.ACCOUNT_METADATA_TRANSACTION: + return { + targetPublicKey: (transaction as AccountMetadataTransaction).targetPublicKey, + scopedMetadataKey: (transaction as AccountMetadataTransaction).scopedMetadataKey.toDTO(), + valueSizeDelta: (transaction as AccountMetadataTransaction).valueSizeDelta, + valueSize: (transaction as AccountMetadataTransaction).value.length, + value: Convert.uint8ToHex((transaction as AccountMetadataTransaction).value), + + }; + case TransactionType.MOSAIC_METADATA_TRANSACTION: + return { + targetPublicKey: (transaction as MosaicMetadataTransaction).targetPublicKey, + scopedMetadataKey: (transaction as MosaicMetadataTransaction).scopedMetadataKey.toDTO(), + valueSizeDelta: (transaction as MosaicMetadataTransaction).valueSizeDelta, + targetMosaicId: (transaction as MosaicMetadataTransaction).targetMosaicId.id.toDTO(), + valueSize: (transaction as MosaicMetadataTransaction).value.length, + value: Convert.uint8ToHex((transaction as MosaicMetadataTransaction).value), + + }; + case TransactionType.NAMESPACE_METADATA_TRANSACTION: + return { + targetPublicKey: (transaction as NamespaceMetadataTransaction).targetPublicKey, + scopedMetadataKey: (transaction as NamespaceMetadataTransaction).scopedMetadataKey.toDTO(), + valueSizeDelta: (transaction as NamespaceMetadataTransaction).valueSizeDelta, + targetNamespaceId: (transaction as NamespaceMetadataTransaction).targetNamespaceId.id.toDTO(), + valueSize: (transaction as NamespaceMetadataTransaction).value.length, + value: Convert.uint8ToHex((transaction as NamespaceMetadataTransaction).value), + }; default: throw new Error ('Transaction type not implemented yet.'); diff --git a/src/model/transaction/AccountMetadataTransaction.ts b/src/model/transaction/AccountMetadataTransaction.ts new file mode 100644 index 0000000000..23120e9367 --- /dev/null +++ b/src/model/transaction/AccountMetadataTransaction.ts @@ -0,0 +1,193 @@ +/* + * 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 { SignSchema } from '../../core/crypto/SignSchema'; +import { Convert } from '../../core/format'; +import { AccountMetadataTransactionBuilder } from '../../infrastructure/catbuffer/AccountMetadataTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountMetadataTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { PublicAccount } from '../account/PublicAccount'; +import { NetworkType } from '../blockchain/NetworkType'; +import { UInt64 } from '../UInt64'; +import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; +import { Transaction } from './Transaction'; +import { TransactionInfo } from './TransactionInfo'; +import { TransactionType } from './TransactionType'; +import { TransactionVersion } from './TransactionVersion'; + +/** + * Announce an account metadata transaction to associate a key-value state to an account. + */ +export class AccountMetadataTransaction extends Transaction { + /** + * Create a account meta data transaction object + * @param deadline - transaction deadline + * @param targetPublicKey - Public key of the target account. + * @param scopedMetadataKey - Metadata key scoped to source, target and type. + * @param valueSizeDelta - Change in value size in bytes. + * @param value - Difference between the previous value and new value. + * You can calculate value as xor(previous-value, new-value). + * If there is no previous value, use directly the new value. + * @param maxFee - (Optional) Max fee defined by the sender + * @returns {AccountMetadataTransaction} + */ + public static create(deadline: Deadline, + targetPublicKey: string, + scopedMetadataKey: UInt64, + valueSizeDelta: number, + value: Uint8Array, + networkType: NetworkType, + maxFee: UInt64 = new UInt64([0, 0])): AccountMetadataTransaction { + return new AccountMetadataTransaction(networkType, + TransactionVersion.ACCOUNT_METADATA_TRANSACTION, + deadline, + maxFee, + targetPublicKey, + scopedMetadataKey, + valueSizeDelta, + value); + } + + /** + * @param networkType + * @param version + * @param deadline + * @param maxFee + * @param targetPublicKey + * @param scopedMetadataKey + * @param valueSizeDelta + * @param value + * @param signature + * @param signer + * @param transactionInfo + */ + constructor(networkType: NetworkType, + version: number, + deadline: Deadline, + maxFee: UInt64, + /** + * Public key of the target account. + */ + public readonly targetPublicKey: string, + /** + * Metadata key scoped to source, target and type. + */ + public readonly scopedMetadataKey: UInt64, + /** + * Change in value size in bytes. + */ + public readonly valueSizeDelta: number, + /** + * Difference between the previous value and new value. + */ + public readonly value: Uint8Array, + signature?: string, + signer?: PublicAccount, + transactionInfo?: TransactionInfo) { + super(TransactionType.ACCOUNT_METADATA_TRANSACTION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); + if (value.length > 1024) { + throw new Error('The maximum value size is 1024'); + } + } + + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAccountMetadataTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AccountMetadataTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AccountMetadataTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as AccountMetadataTransactionBuilder).getDeadline().timestamp), + Convert.uint8ToHex(builder.getTargetPublicKey().key), + new UInt64(builder.getScopedMetadataKey()), + builder.getValueSizeDelta(), + builder.getValue(), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountMetadataTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + + /** + * @override Transaction.size() + * @description get the byte size of a AccountLinkTransaction + * @returns {number} + * @memberof AccountLinkTransaction + */ + public get size(): number { + const byteSize = super.size; + + // set static byte size fields + const targetPublicKey = 32; + const byteScopedMetadataKey = 8; + const byteValueSizeDelta = 2; + + return byteSize + targetPublicKey + byteScopedMetadataKey + + byteValueSizeDelta + this.value.length; + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountMetadataTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_METADATA_TRANSACTION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + this.scopedMetadataKey.toDTO(), + this.valueSizeDelta, + this.value, + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const transactionBuilder = new EmbeddedAccountMetadataTransactionBuilder( + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), + this.versionToDTO(), + TransactionType.ACCOUNT_METADATA_TRANSACTION.valueOf(), + new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + this.scopedMetadataKey.toDTO(), + this.valueSizeDelta, + this.value, + ); + return transactionBuilder.serialize(); + } +} diff --git a/src/model/transaction/MosaicMetadataTransaction.ts b/src/model/transaction/MosaicMetadataTransaction.ts new file mode 100644 index 0000000000..78798f73a9 --- /dev/null +++ b/src/model/transaction/MosaicMetadataTransaction.ts @@ -0,0 +1,207 @@ +/* + * 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 { SignSchema } from '../../core/crypto/SignSchema'; +import { Convert } from '../../core/format'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicMetadataTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicMetadataTransactionBuilder } from '../../infrastructure/catbuffer/MosaicMetadataTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; +import { PublicAccount } from '../account/PublicAccount'; +import { NetworkType } from '../blockchain/NetworkType'; +import { MosaicId } from '../mosaic/MosaicId'; +import { UInt64 } from '../UInt64'; +import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; +import { Transaction } from './Transaction'; +import { TransactionInfo } from './TransactionInfo'; +import { TransactionType } from './TransactionType'; +import { TransactionVersion } from './TransactionVersion'; + +/** + * Announce an mosaic metadata transaction to associate a key-value state to an account. + */ +export class MosaicMetadataTransaction extends Transaction { + /** + * Create a mosaic meta data transaction object + * @param deadline - transaction deadline + * @param targetPublicKey - Public key of the target account. + * @param scopedMetadataKey - Metadata key scoped to source, target and type. + * @param targetMosaicId - Target mosaic identifier. + * @param valueSizeDelta - Change in value size in bytes. + * @param value - Difference between the previous value and new value. + * You can calculate value as xor(previous-value, new-value). + * If there is no previous value, use directly the new value. + * @param maxFee - (Optional) Max fee defined by the sender + * @returns {MosaicMetadataTransaction} + */ + public static create(deadline: Deadline, + targetPublicKey: string, + scopedMetadataKey: UInt64, + targetMosaicId: MosaicId, + valueSizeDelta: number, + value: Uint8Array, + networkType: NetworkType, + maxFee: UInt64 = new UInt64([0, 0])): MosaicMetadataTransaction { + return new MosaicMetadataTransaction(networkType, + TransactionVersion.MOSAIC_METADATA_TRANSACTION, + deadline, + maxFee, + targetPublicKey, + scopedMetadataKey, + targetMosaicId, + valueSizeDelta, + value); + } + + /** + * @param networkType + * @param version + * @param deadline + * @param maxFee + * @param targetPublicKey + * @param scopedMetadataKey + * @param targetMosaicId + * @param valueSizeDelta + * @param value + * @param signature + * @param signer + * @param transactionInfo + */ + constructor(networkType: NetworkType, + version: number, + deadline: Deadline, + maxFee: UInt64, + /** + * Public key of the target account. + */ + public readonly targetPublicKey: string, + /** + * Metadata key scoped to source, target and type. + */ + public readonly scopedMetadataKey: UInt64, + /** + * Target mosaic identifier. + */ + public readonly targetMosaicId: MosaicId, + /** + * Change in value size in bytes. + */ + public readonly valueSizeDelta: number, + /** + * Difference between the previous value and new value. + */ + public readonly value: Uint8Array, + signature?: string, + signer?: PublicAccount, + transactionInfo?: TransactionInfo) { + super(TransactionType.MOSAIC_METADATA_TRANSACTION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); + if (value.length > 1024) { + throw new Error('The maximum value size is 1024'); + } + } + + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMosaicMetadataTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MosaicMetadataTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = MosaicMetadataTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as MosaicMetadataTransactionBuilder).getDeadline().timestamp), + Convert.uint8ToHex(builder.getTargetPublicKey().key), + new UInt64(builder.getScopedMetadataKey()), + new MosaicId(builder.getTargetMosaicId().unresolvedMosaicId), + builder.getValueSizeDelta(), + builder.getValue(), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MosaicMetadataTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + + /** + * @override Transaction.size() + * @description get the byte size of a AccountLinkTransaction + * @returns {number} + * @memberof AccountLinkTransaction + */ + public get size(): number { + const byteSize = super.size; + + // set static byte size fields + const targetPublicKey = 32; + const byteScopedMetadataKey = 8; + const byteTargetMosaicId = 8; + const byteValueSizeDelta = 2; + + return byteSize + targetPublicKey + byteScopedMetadataKey + + byteTargetMosaicId + byteValueSizeDelta + this.value.length; + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicMetadataTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_METADATA_TRANSACTION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + this.scopedMetadataKey.toDTO(), + new UnresolvedMosaicIdDto(this.targetMosaicId.id.toDTO()), + this.valueSizeDelta, + this.value, + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const transactionBuilder = new EmbeddedMosaicMetadataTransactionBuilder( + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), + this.versionToDTO(), + TransactionType.MOSAIC_METADATA_TRANSACTION.valueOf(), + new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + this.scopedMetadataKey.toDTO(), + new UnresolvedMosaicIdDto(this.targetMosaicId.id.toDTO()), + this.valueSizeDelta, + this.value, + ); + return transactionBuilder.serialize(); + } +} diff --git a/src/model/transaction/NamespaceMetaDataTransaction.ts b/src/model/transaction/NamespaceMetaDataTransaction.ts new file mode 100644 index 0000000000..49d4236d94 --- /dev/null +++ b/src/model/transaction/NamespaceMetaDataTransaction.ts @@ -0,0 +1,208 @@ +/* + * 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 { SignSchema } from '../../core/crypto/SignSchema'; +import { Convert } from '../../core/format'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedNamespaceMetadataTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; +import { NamespaceMetadataTransactionBuilder } from '../../infrastructure/catbuffer/NamespaceMetadataTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { PublicAccount } from '../account/PublicAccount'; +import { NetworkType } from '../blockchain/NetworkType'; +import { NamespaceId } from '../namespace/NamespaceId'; +import { UInt64 } from '../UInt64'; +import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; +import { Transaction } from './Transaction'; +import { TransactionInfo } from './TransactionInfo'; +import { TransactionType } from './TransactionType'; +import { TransactionVersion } from './TransactionVersion'; + +/** + * Announce an namespace metadata transaction to associate a key-value state to an account. + */ +export class NamespaceMetadataTransaction extends Transaction { + /** + * Create a mosaic meta data transaction object + * @param deadline - transaction deadline + * @param targetPublicKey - Public key of the target account. + * @param scopedMetadataKey - Metadata key scoped to source, target and type. + * @param targetNamespaceId - Target namespace identifier. + * @param valueSizeDelta - Change in value size in bytes. + * @param value - Difference between the previous value and new value. + * You can calculate value as xor(previous-value, new-value). + * If there is no previous value, use directly the new value. + * @param maxFee - (Optional) Max fee defined by the sender + * @returns {NamespaceMetadataTransaction} + */ + public static create(deadline: Deadline, + targetPublicKey: string, + scopedMetadataKey: UInt64, + targetNamespaceId: NamespaceId, + valueSizeDelta: number, + value: Uint8Array, + networkType: NetworkType, + maxFee: UInt64 = new UInt64([0, 0])): NamespaceMetadataTransaction { + return new NamespaceMetadataTransaction(networkType, + TransactionVersion.NAMESPACE_METADATA_TRANSACTION, + deadline, + maxFee, + targetPublicKey, + scopedMetadataKey, + targetNamespaceId, + valueSizeDelta, + value); + } + + /** + * @param networkType + * @param version + * @param deadline + * @param maxFee + * @param targetPublicKey + * @param scopedMetadataKey + * @param targetNamespaceId + * @param valueSizeDelta + * @param value + * @param signature + * @param signer + * @param transactionInfo + */ + constructor(networkType: NetworkType, + version: number, + deadline: Deadline, + maxFee: UInt64, + /** + * Public key of the target account. + */ + public readonly targetPublicKey: string, + /** + * Metadata key scoped to source, target and type. + */ + public readonly scopedMetadataKey: UInt64, + /** + * Target namespace identifier. + */ + public readonly targetNamespaceId: NamespaceId, + /** + * Change in value size in bytes. + */ + public readonly valueSizeDelta: number, + /** + * Difference between the previous value and new value. + */ + public readonly value: Uint8Array, + signature?: string, + signer?: PublicAccount, + transactionInfo?: TransactionInfo) { + super(TransactionType.NAMESPACE_METADATA_TRANSACTION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); + if (value.length > 1024) { + throw new Error('The maximum value size is 1024'); + } + } + + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedNamespaceMetadataTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + NamespaceMetadataTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = NamespaceMetadataTransaction.create( + isEmbedded ? Deadline.create() : + Deadline.createFromDTO((builder as NamespaceMetadataTransactionBuilder).getDeadline().timestamp), + Convert.uint8ToHex(builder.getTargetPublicKey().key), + new UInt64(builder.getScopedMetadataKey()), + new NamespaceId(builder.getTargetNamespaceId().namespaceId), + builder.getValueSizeDelta(), + builder.getValue(), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as NamespaceMetadataTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + + /** + * @override Transaction.size() + * @description get the byte size of a AccountLinkTransaction + * @returns {number} + * @memberof AccountLinkTransaction + */ + public get size(): number { + const byteSize = super.size; + + // set static byte size fields + const targetPublicKey = 32; + const byteScopedMetadataKey = 8; + const byteTargetNamespaceId = 8; + const byteValueSizeDelta = 2; + + return byteSize + targetPublicKey + byteScopedMetadataKey + + byteTargetNamespaceId + byteValueSizeDelta + this.value.length; + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new NamespaceMetadataTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.NAMESPACE_METADATA_TRANSACTION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + this.scopedMetadataKey.toDTO(), + new NamespaceIdDto(this.targetNamespaceId.id.toDTO()), + this.valueSizeDelta, + this.value, + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const transactionBuilder = new EmbeddedNamespaceMetadataTransactionBuilder( + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), + this.versionToDTO(), + TransactionType.NAMESPACE_METADATA_TRANSACTION.valueOf(), + new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + this.scopedMetadataKey.toDTO(), + new NamespaceIdDto(this.targetNamespaceId.id.toDTO()), + this.valueSizeDelta, + this.value, + ); + return transactionBuilder.serialize(); + } +} diff --git a/src/model/transaction/TransactionType.ts b/src/model/transaction/TransactionType.ts index 9d571f0855..24fc2d6b84 100644 --- a/src/model/transaction/TransactionType.ts +++ b/src/model/transaction/TransactionType.ts @@ -127,4 +127,22 @@ export enum TransactionType { * @type {number} */ MOSAIC_GLOBAL_RESTRICTION = 0x4151, + + /** + * Account metadata transaction + * @type {number} + */ + ACCOUNT_METADATA_TRANSACTION = 0x4144, + + /** + * Mosaic metadata transaction + * @type {number} + */ + MOSAIC_METADATA_TRANSACTION = 0x4244, + + /** + * Namespace metadata transaction + * @type {number} + */ + NAMESPACE_METADATA_TRANSACTION = 0x4344, } diff --git a/src/model/transaction/TransactionVersion.ts b/src/model/transaction/TransactionVersion.ts index 71087ac326..5a09c39a20 100644 --- a/src/model/transaction/TransactionVersion.ts +++ b/src/model/transaction/TransactionVersion.ts @@ -135,4 +135,22 @@ export class TransactionVersion { * @type {number} */ public static readonly LINK_ACCOUNT = 0x01; + + /** + * Account metadata transaction version + * @type {number} + */ + public static readonly ACCOUNT_METADATA_TRANSACTION = 0x01; + + /** + * Mosaic metadata transaction version + * @type {number} + */ + public static readonly MOSAIC_METADATA_TRANSACTION = 0x01; + + /** + * Namespace metadata transaction version + * @type {number} + */ + public static readonly NAMESPACE_METADATA_TRANSACTION = 0x01; } diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index 7f80ee3375..713b2b5bbd 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -37,6 +37,7 @@ import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { NamespaceType } from '../../../src/model/namespace/NamespaceType'; import { AccountAddressRestrictionTransaction } from '../../../src/model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../../src/model/transaction/AccountLinkTransaction'; +import { AccountMetadataTransaction } from '../../../src/model/transaction/AccountMetadataTransaction'; import { AccountMosaicRestrictionTransaction } from '../../../src/model/transaction/AccountMosaicRestrictionTransaction'; import { AccountRestrictionModification } from '../../../src/model/transaction/AccountRestrictionModification'; import { AccountRestrictionTransaction } from '../../../src/model/transaction/AccountRestrictionTransaction'; @@ -52,9 +53,11 @@ import { MosaicAddressRestrictionTransaction } from '../../../src/model/transact import { MosaicAliasTransaction } from '../../../src/model/transaction/MosaicAliasTransaction'; import { MosaicDefinitionTransaction } from '../../../src/model/transaction/MosaicDefinitionTransaction'; import { MosaicGlobalRestrictionTransaction } from '../../../src/model/transaction/MosaicGlobalRestrictionTransaction'; +import { MosaicMetadataTransaction } from '../../../src/model/transaction/MosaicMetadataTransaction'; import { MosaicSupplyChangeTransaction } from '../../../src/model/transaction/MosaicSupplyChangeTransaction'; import { MultisigCosignatoryModification } from '../../../src/model/transaction/MultisigCosignatoryModification'; import { MultisigCosignatoryModificationType } from '../../../src/model/transaction/MultisigCosignatoryModificationType'; +import { NamespaceMetadataTransaction } from '../../../src/model/transaction/NamespaceMetaDataTransaction'; import { PlainMessage } from '../../../src/model/transaction/PlainMessage'; import { RegisterNamespaceTransaction } from '../../../src/model/transaction/RegisterNamespaceTransaction'; import { SecretLockTransaction } from '../../../src/model/transaction/SecretLockTransaction'; @@ -586,6 +589,73 @@ describe('TransactionMapping - createFromPayload', () => { expect(transaction.previousRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(0).toHex()); expect(transaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(0).toHex()); }); + + it('should create AddressMetadataTransaction', () => { + const accountMetadataTransaction = AccountMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const signedTx = accountMetadataTransaction.signWith(account, generationHash); + + const transaction = TransactionMapping.createFromPayload(signedTx.payload) as AccountMetadataTransaction; + + expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_METADATA_TRANSACTION); + expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); + expect(transaction.valueSizeDelta).to.be.equal(1); + expect(convert.uint8ToHex(transaction.value)).to.be.equal(convert.uint8ToHex(new Uint8Array(10))); + }); + + it('should create MosaicMetadataTransaction', () => { + const mosaicMetadataTransaction = MosaicMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new MosaicId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const signedTx = mosaicMetadataTransaction.signWith(account, generationHash); + + const transaction = TransactionMapping.createFromPayload(signedTx.payload) as MosaicMetadataTransaction; + + expect(transaction.type).to.be.equal(TransactionType.MOSAIC_METADATA_TRANSACTION); + expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); + expect(transaction.valueSizeDelta).to.be.equal(1); + expect(transaction.targetMosaicId.toHex()).to.be.equal(new MosaicId([2262289484, 3405110546]).toHex()); + expect(convert.uint8ToHex(transaction.value)).to.be.equal(convert.uint8ToHex(new Uint8Array(10))); + }); + + it('should create NamespaceMetadataTransaction', () => { + const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new NamespaceId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const signedTx = namespaceMetadataTransaction.signWith(account, generationHash); + + const transaction = TransactionMapping.createFromPayload(signedTx.payload) as NamespaceMetadataTransaction; + + expect(transaction.type).to.be.equal(TransactionType.NAMESPACE_METADATA_TRANSACTION); + expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); + expect(transaction.valueSizeDelta).to.be.equal(1); + expect(transaction.targetNamespaceId.toHex()).to.be.equal(new NamespaceId([2262289484, 3405110546]).toHex()); + expect(convert.uint8ToHex(transaction.value)).to.be.equal(convert.uint8ToHex(new Uint8Array(10))); + }); }); describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => { @@ -1007,4 +1077,68 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => expect(transaction.previousRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(0).toHex()); expect(transaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(0).toHex()); }); + + it('should create AddressMetadataTransaction', () => { + const accountMetadataTransaction = AccountMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const transaction = + TransactionMapping.createFromDTO(accountMetadataTransaction.toJSON()) as AccountMetadataTransaction; + + expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_METADATA_TRANSACTION); + expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); + expect(transaction.valueSizeDelta).to.be.equal(1); + expect(convert.uint8ToHex(transaction.value)).to.be.equal(convert.uint8ToHex(new Uint8Array(10))); + }); + + it('should create MosaicMetadataTransaction', () => { + const mosaicMetadataTransaction = MosaicMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new MosaicId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const transaction = + TransactionMapping.createFromDTO(mosaicMetadataTransaction.toJSON()) as MosaicMetadataTransaction; + + expect(transaction.type).to.be.equal(TransactionType.MOSAIC_METADATA_TRANSACTION); + expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); + expect(transaction.valueSizeDelta).to.be.equal(1); + expect(transaction.targetMosaicId.toHex()).to.be.equal(new MosaicId([2262289484, 3405110546]).toHex()); + expect(convert.uint8ToHex(transaction.value)).to.be.equal(convert.uint8ToHex(new Uint8Array(10))); + }); + + it('should create NamespaceMetadataTransaction', () => { + const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new NamespaceId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const transaction = + TransactionMapping.createFromDTO(namespaceMetadataTransaction.toJSON()) as NamespaceMetadataTransaction; + + expect(transaction.type).to.be.equal(TransactionType.NAMESPACE_METADATA_TRANSACTION); + expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); + expect(transaction.valueSizeDelta).to.be.equal(1); + expect(transaction.targetNamespaceId.toHex()).to.be.equal(new NamespaceId([2262289484, 3405110546]).toHex()); + expect(convert.uint8ToHex(transaction.value)).to.be.equal(convert.uint8ToHex(new Uint8Array(10))); + }); }); diff --git a/test/model/transaction/AccountMetadataTransaction.spec.ts b/test/model/transaction/AccountMetadataTransaction.spec.ts new file mode 100644 index 0000000000..bb534d5c51 --- /dev/null +++ b/test/model/transaction/AccountMetadataTransaction.spec.ts @@ -0,0 +1,105 @@ +/* + * 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 { expect } from 'chai'; +import { Account } from '../../../src/model/account/Account'; +import { NetworkType } from '../../../src/model/blockchain/NetworkType'; +import { AccountMetadataTransaction } from '../../../src/model/transaction/AccountMetadataTransaction'; +import { Deadline } from '../../../src/model/transaction/Deadline'; +import { UInt64 } from '../../../src/model/UInt64'; +import { TestingAccount } from '../../conf/conf.spec'; + +describe('AccountMetadataTransaction', () => { + let account: Account; + const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; + before(() => { + account = TestingAccount; + }); + + it('should default maxFee field be set to 0', () => { + const accountMetadataTransaction = AccountMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + expect(accountMetadataTransaction.maxFee.higher).to.be.equal(0); + expect(accountMetadataTransaction.maxFee.lower).to.be.equal(0); + }); + + it('should filled maxFee override transaction maxFee', () => { + const accountMetadataTransaction = AccountMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + new UInt64([1, 0]), + ); + + expect(accountMetadataTransaction.maxFee.higher).to.be.equal(0); + expect(accountMetadataTransaction.maxFee.lower).to.be.equal(1); + }); + + it('should create and sign an AccountMetadataTransaction object', () => { + const accountMetadataTransaction = AccountMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const signedTransaction = accountMetadataTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFEE80300000000000001000A0000000000000000000000'); + }); + + it('should throw error if value size is bigger than 1024', () => { + expect(() => { + AccountMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + 1, + new Uint8Array(1025), + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'The maximum value size is 1024'); + }); + + describe('size', () => { + it('should return 153 for AccountMetadataTransaction byte size', () => { + const accountMetadataTransaction = AccountMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + expect(accountMetadataTransaction.size).to.be.equal(172); + }); + }); +}); diff --git a/test/model/transaction/MosaicMetadataTransaction.spec.ts b/test/model/transaction/MosaicMetadataTransaction.spec.ts new file mode 100644 index 0000000000..09832cdbdc --- /dev/null +++ b/test/model/transaction/MosaicMetadataTransaction.spec.ts @@ -0,0 +1,112 @@ +/* + * 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 { expect } from 'chai'; +import { Account } from '../../../src/model/account/Account'; +import { NetworkType } from '../../../src/model/blockchain/NetworkType'; +import { MosaicId } from '../../../src/model/mosaic/MosaicId'; +import { Deadline } from '../../../src/model/transaction/Deadline'; +import { MosaicMetadataTransaction } from '../../../src/model/transaction/MosaicMetadataTransaction'; +import { UInt64 } from '../../../src/model/UInt64'; +import { TestingAccount } from '../../conf/conf.spec'; + +describe('MosaicMetadataTransaction', () => { + let account: Account; + const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; + before(() => { + account = TestingAccount; + }); + + it('should default maxFee field be set to 0', () => { + const mosaicMetadataTransaction = MosaicMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new MosaicId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + expect(mosaicMetadataTransaction.maxFee.higher).to.be.equal(0); + expect(mosaicMetadataTransaction.maxFee.lower).to.be.equal(0); + }); + + it('should filled maxFee override transaction maxFee', () => { + const mosaicMetadataTransaction = MosaicMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new MosaicId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + new UInt64([1, 0]), + ); + + expect(mosaicMetadataTransaction.maxFee.higher).to.be.equal(0); + expect(mosaicMetadataTransaction.maxFee.lower).to.be.equal(1); + }); + + it('should create and sign an MosaicMetadataTransaction object', () => { + const mosaicMetadataTransaction = MosaicMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new MosaicId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const signedTransaction = mosaicMetadataTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFEE80' + + '30000000000004CCCD78612DDF5CA01000A0000000000000000000000'); + }); + + it('should throw error if value size is bigger than 1024', () => { + expect(() => { + MosaicMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new MosaicId([2262289484, 3405110546]), + 1, + new Uint8Array(1025), + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'The maximum value size is 1024'); + }); + + describe('size', () => { + it('should return 153 for MosaicMetadataTransaction byte size', () => { + const mosaicMetadataTransaction = MosaicMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new MosaicId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + expect(mosaicMetadataTransaction.size).to.be.equal(180); + }); + }); +}); diff --git a/test/model/transaction/NamespaceMetadata.spec.ts b/test/model/transaction/NamespaceMetadata.spec.ts new file mode 100644 index 0000000000..2c5a4b64b9 --- /dev/null +++ b/test/model/transaction/NamespaceMetadata.spec.ts @@ -0,0 +1,112 @@ +/* + * 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 { expect } from 'chai'; +import { Account } from '../../../src/model/account/Account'; +import { NetworkType } from '../../../src/model/blockchain/NetworkType'; +import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; +import { Deadline } from '../../../src/model/transaction/Deadline'; +import { NamespaceMetadataTransaction } from '../../../src/model/transaction/NamespaceMetadataTransaction'; +import { UInt64 } from '../../../src/model/UInt64'; +import { TestingAccount } from '../../conf/conf.spec'; + +describe('NamespaceMetadataTransaction', () => { + let account: Account; + const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; + before(() => { + account = TestingAccount; + }); + + it('should default maxFee field be set to 0', () => { + const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new NamespaceId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + expect(namespaceMetadataTransaction.maxFee.higher).to.be.equal(0); + expect(namespaceMetadataTransaction.maxFee.lower).to.be.equal(0); + }); + + it('should filled maxFee override transaction maxFee', () => { + const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new NamespaceId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + new UInt64([1, 0]), + ); + + expect(namespaceMetadataTransaction.maxFee.higher).to.be.equal(0); + expect(namespaceMetadataTransaction.maxFee.lower).to.be.equal(1); + }); + + it('should create and sign an NamespaceMetadataTransaction object', () => { + const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new NamespaceId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const signedTransaction = namespaceMetadataTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFEE80' + + '30000000000004CCCD78612DDF5CA01000A0000000000000000000000'); + }); + + it('should throw error if value size is bigger than 1024', () => { + expect(() => { + NamespaceMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new NamespaceId([2262289484, 3405110546]), + 1, + new Uint8Array(1025), + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'The maximum value size is 1024'); + }); + + describe('size', () => { + it('should return 153 for NamespaceMetadataTransaction byte size', () => { + const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new NamespaceId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + expect(namespaceMetadataTransaction.size).to.be.equal(180); + }); + }); +}); From 7a880a6f9d20a5d0f6224ad0d4cb5b689c58ee75 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 20 Aug 2019 21:45:37 +0100 Subject: [PATCH 55/98] renamed namespaceMetadataTransaction unit test file name --- ...spaceMetadata.spec.ts => NamespaceMetadataTransaction.spec.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/model/transaction/{NamespaceMetadata.spec.ts => NamespaceMetadataTransaction.spec.ts} (100%) diff --git a/test/model/transaction/NamespaceMetadata.spec.ts b/test/model/transaction/NamespaceMetadataTransaction.spec.ts similarity index 100% rename from test/model/transaction/NamespaceMetadata.spec.ts rename to test/model/transaction/NamespaceMetadataTransaction.spec.ts From 4d7b0194f42cd44908ea7d4dd828212ffd6d89b2 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 20 Aug 2019 21:50:24 +0100 Subject: [PATCH 56/98] Added missing exports --- src/model/model.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/model/model.ts b/src/model/model.ts index 06d3767f14..1c18ef6a17 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -130,6 +130,9 @@ export * from './transaction/TransactionStatus'; export * from './transaction/TransactionStatusError'; export * from './transaction/TransactionType'; export * from './transaction/TransferTransaction'; +export * from './transaction/AccountMetadataTransaction'; +export * from './transaction/MosaicMetadataTransaction'; +export * from './transaction/NamespaceMetadataTransaction'; // Wallet export * from './wallet/EncryptedPrivateKey'; From 5b7f44c8f3aaa56c13fbab5002090fe2a168fc9b Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 20 Aug 2019 21:51:23 +0100 Subject: [PATCH 57/98] Added missing mosaic restriction exports --- src/model/model.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/model/model.ts b/src/model/model.ts index 1c18ef6a17..edccb533eb 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -133,6 +133,8 @@ export * from './transaction/TransferTransaction'; export * from './transaction/AccountMetadataTransaction'; export * from './transaction/MosaicMetadataTransaction'; export * from './transaction/NamespaceMetadataTransaction'; +export * from './transaction/MosaicGlobalRestrictionTransaction'; +export * from './transaction/MosaicAddressRestrictionTransaction'; // Wallet export * from './wallet/EncryptedPrivateKey'; From 0d31e3e007862c049baabe5a6e37308eee963406 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 20 Aug 2019 22:00:19 +0100 Subject: [PATCH 58/98] Renamed NamespaceMetaDataTransaction.ts --- e2e/infrastructure/TransactionHttp.spec.ts | 8 ++++---- .../transaction/CreateTransactionFromDTO.ts | 2 +- .../transaction/CreateTransactionFromPayload.ts | 2 +- .../transaction/SerializeTransactionToJSON.ts | 2 +- test/core/utils/TransactionMapping.spec.ts | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 6b9e78d610..bb396f5746 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -18,7 +18,7 @@ import * as CryptoJS from 'crypto-js'; import {ChronoUnit} from 'js-joda'; import {keccak_256, sha3_256} from 'js-sha3'; import {Crypto} from '../../src/core/crypto'; -import { Convert as convert, Convert } from '../../src/core/format'; +import { Convert, Convert as convert } from '../../src/core/format'; import { TransactionMapping } from '../../src/core/utils/TransactionMapping'; import {AccountHttp} from '../../src/infrastructure/AccountHttp'; import { NamespaceHttp } from '../../src/infrastructure/infrastructure'; @@ -39,6 +39,7 @@ import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AccountAddressRestrictionTransaction } from '../../src/model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../src/model/transaction/AccountLinkTransaction'; +import { AccountMetadataTransaction } from '../../src/model/transaction/AccountMetadataTransaction'; import { AccountMosaicRestrictionTransaction } from '../../src/model/transaction/AccountMosaicRestrictionTransaction'; import { AccountOperationRestrictionTransaction } from '../../src/model/transaction/AccountOperationRestrictionTransaction'; import { AccountRestrictionModification } from '../../src/model/transaction/AccountRestrictionModification'; @@ -56,7 +57,9 @@ import { MosaicAddressRestrictionTransaction } from '../../src/model/transaction import { MosaicAliasTransaction } from '../../src/model/transaction/MosaicAliasTransaction'; import {MosaicDefinitionTransaction} from '../../src/model/transaction/MosaicDefinitionTransaction'; import { MosaicGlobalRestrictionTransaction } from '../../src/model/transaction/MosaicGlobalRestrictionTransaction'; +import { MosaicMetadataTransaction } from '../../src/model/transaction/MosaicMetadataTransaction'; import {MosaicSupplyChangeTransaction} from '../../src/model/transaction/MosaicSupplyChangeTransaction'; +import { NamespaceMetadataTransaction } from '../../src/model/transaction/NamespaceMetadataTransaction'; import { PlainMessage } from '../../src/model/transaction/PlainMessage'; import {RegisterNamespaceTransaction} from '../../src/model/transaction/RegisterNamespaceTransaction'; import {SecretLockTransaction} from '../../src/model/transaction/SecretLockTransaction'; @@ -66,9 +69,6 @@ import {Transaction} from '../../src/model/transaction/Transaction'; import {TransactionType} from '../../src/model/transaction/TransactionType'; import {TransferTransaction} from '../../src/model/transaction/TransferTransaction'; import {UInt64} from '../../src/model/UInt64'; -import { AccountMetadataTransaction } from '../../src/model/transaction/AccountMetadataTransaction'; -import { MosaicMetadataTransaction } from '../../src/model/transaction/MosaicMetadataTransaction'; -import { NamespaceMetadataTransaction } from '../../src/model/transaction/NamespaceMetaDataTransaction'; describe('TransactionHttp', () => { let transactionHash; let transactionId; diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index d97e24bd4a..27d698a4bb 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -46,7 +46,7 @@ import { MosaicGlobalRestrictionTransaction } from '../../model/transaction/Mosa import { MosaicMetadataTransaction } from '../../model/transaction/MosaicMetadataTransaction'; import {MosaicSupplyChangeTransaction} from '../../model/transaction/MosaicSupplyChangeTransaction'; import {MultisigCosignatoryModification} from '../../model/transaction/MultisigCosignatoryModification'; -import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetaDataTransaction'; +import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetadataTransaction'; import {EmptyMessage, PlainMessage} from '../../model/transaction/PlainMessage'; import {RegisterNamespaceTransaction} from '../../model/transaction/RegisterNamespaceTransaction'; import {SecretLockTransaction} from '../../model/transaction/SecretLockTransaction'; diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index 87a5455da5..20b0410151 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -32,7 +32,7 @@ import { MosaicDefinitionTransaction } from '../../model/transaction/MosaicDefin import { MosaicGlobalRestrictionTransaction } from '../../model/transaction/MosaicGlobalRestrictionTransaction'; import { MosaicMetadataTransaction } from '../../model/transaction/MosaicMetadataTransaction'; import { MosaicSupplyChangeTransaction } from '../../model/transaction/MosaicSupplyChangeTransaction'; -import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetaDataTransaction'; +import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetadataTransaction'; import { RegisterNamespaceTransaction } from '../../model/transaction/RegisterNamespaceTransaction'; import { SecretLockTransaction } from '../../model/transaction/SecretLockTransaction'; import { SecretProofTransaction } from '../../model/transaction/SecretProofTransaction'; diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index ee68778a74..48fa73fee7 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -30,7 +30,7 @@ import { MosaicDefinitionTransaction } from '../../model/transaction/MosaicDefin import { MosaicGlobalRestrictionTransaction } from '../../model/transaction/MosaicGlobalRestrictionTransaction'; import { MosaicMetadataTransaction } from '../../model/transaction/MosaicMetadataTransaction'; import { MosaicSupplyChangeTransaction } from '../../model/transaction/MosaicSupplyChangeTransaction'; -import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetaDataTransaction'; +import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetadataTransaction'; import { RegisterNamespaceTransaction } from '../../model/transaction/RegisterNamespaceTransaction'; import { SecretLockTransaction } from '../../model/transaction/SecretLockTransaction'; import { SecretProofTransaction } from '../../model/transaction/SecretProofTransaction'; diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index 713b2b5bbd..d4c46a692b 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -57,7 +57,7 @@ import { MosaicMetadataTransaction } from '../../../src/model/transaction/Mosaic import { MosaicSupplyChangeTransaction } from '../../../src/model/transaction/MosaicSupplyChangeTransaction'; import { MultisigCosignatoryModification } from '../../../src/model/transaction/MultisigCosignatoryModification'; import { MultisigCosignatoryModificationType } from '../../../src/model/transaction/MultisigCosignatoryModificationType'; -import { NamespaceMetadataTransaction } from '../../../src/model/transaction/NamespaceMetaDataTransaction'; +import { NamespaceMetadataTransaction } from '../../../src/model/transaction/NamespaceMetadataTransaction'; import { PlainMessage } from '../../../src/model/transaction/PlainMessage'; import { RegisterNamespaceTransaction } from '../../../src/model/transaction/RegisterNamespaceTransaction'; import { SecretLockTransaction } from '../../../src/model/transaction/SecretLockTransaction'; From b682fc06068a08462b726a4b603c7b674bcf2fdb Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 20 Aug 2019 22:02:58 +0100 Subject: [PATCH 59/98] Rename NamespaceMetadata --- ...paceMetaDataTransaction.ts => NamespaceMetadataTransaction.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/model/transaction/{NamespaceMetaDataTransaction.ts => NamespaceMetadataTransaction.ts} (100%) diff --git a/src/model/transaction/NamespaceMetaDataTransaction.ts b/src/model/transaction/NamespaceMetadataTransaction.ts similarity index 100% rename from src/model/transaction/NamespaceMetaDataTransaction.ts rename to src/model/transaction/NamespaceMetadataTransaction.ts From dea2155988a6fb31e80057fa6d4d80a2ec57571b Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 21 Aug 2019 12:00:38 +0100 Subject: [PATCH 60/98] Added missing mosaicRestrictionType export --- src/model/model.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/model/model.ts b/src/model/model.ts index edccb533eb..5efac4c845 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -56,6 +56,7 @@ export * from './mosaic/NetworkCurrencyMosaic'; export * from './mosaic/NetworkHarvestMosaic'; export * from './mosaic/MosaicNames'; export * from './mosaic/MosaicPropertyType'; +export * from './mosaic/MosaicRestrictionType'; // Namespace export * from '../service/Namespace'; From 0925bd924eab2f29a5cf5b08618088f344755cb4 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 21:43:04 +0100 Subject: [PATCH 61/98] Added ts catbuffer codes (without aggregateTx) Appended new signwithCatbuffer method in Transaction (temp) Applied catbuffer builders on standalone transaction (builder) Updated unit tests --- e2e/infrastructure/TransactionHttp.spec.ts | 12 +- src/infrastructure/QueryParams.ts | 1 - .../AccountRestrictionsAddressTransaction.ts | 2 +- ...ccountRestrictionsEntityTypeTransaction.ts | 2 +- .../AccountRestrictionsMosaicTransaction.ts | 2 +- ...ntAddressRestrictionModificationBuilder.ts | 91 ++++++++ ...ddressRestrictionTransactionBodyBuilder.ts | 114 ++++++++++ ...untAddressRestrictionTransactionBuilder.ts | 116 +++++++++++ .../catbuffer/AccountLinkActionDto.ts | 29 +++ .../AccountLinkTransactionBodyBuilder.ts | 102 +++++++++ .../AccountLinkTransactionBuilder.ts | 113 ++++++++++ .../AccountMetadataTransactionBodyBuilder.ts | 147 +++++++++++++ .../AccountMetadataTransactionBuilder.ts | 139 +++++++++++++ ...untMosaicRestrictionModificationBuilder.ts | 91 ++++++++ ...MosaicRestrictionTransactionBodyBuilder.ts | 114 ++++++++++ ...ountMosaicRestrictionTransactionBuilder.ts | 116 +++++++++++ ...OperationRestrictionModificationBuilder.ts | 91 ++++++++ ...rationRestrictionTransactionBodyBuilder.ts | 114 ++++++++++ ...tOperationRestrictionTransactionBuilder.ts | 116 +++++++++++ ...AccountRestrictionModificationActionDto.ts | 29 +++ .../AccountRestrictionModificationBuilder.ts | 83 ++++++++ .../catbuffer/AccountRestrictionTypeDto.ts | 35 ++++ .../AddressAliasTransactionBodyBuilder.ts | 121 +++++++++++ .../AddressAliasTransactionBuilder.ts | 125 +++++++++++ src/infrastructure/catbuffer/AddressDto.ts | 79 +++++++ .../catbuffer/AliasActionDto.ts | 29 +++ src/infrastructure/catbuffer/AmountDto.ts | 80 ++++++++ .../catbuffer/BlockDurationDto.ts | 80 ++++++++ .../CosignatoryModificationActionDto.ts | 29 +++ .../CosignatoryModificationBuilder.ts | 102 +++++++++ ...untAddressRestrictionTransactionBuilder.ts | 110 ++++++++++ .../EmbeddedAccountLinkTransactionBuilder.ts | 107 ++++++++++ ...beddedAccountMetadataTransactionBuilder.ts | 133 ++++++++++++ ...ountMosaicRestrictionTransactionBuilder.ts | 110 ++++++++++ ...tOperationRestrictionTransactionBuilder.ts | 110 ++++++++++ .../EmbeddedAddressAliasTransactionBuilder.ts | 119 +++++++++++ .../EmbeddedHashLockTransactionBuilder.ts | 119 +++++++++++ ...aicAddressRestrictionTransactionBuilder.ts | 140 +++++++++++++ .../EmbeddedMosaicAliasTransactionBuilder.ts | 119 +++++++++++ ...eddedMosaicDefinitionTransactionBuilder.ts | 141 +++++++++++++ ...saicGlobalRestrictionTransactionBuilder.ts | 160 +++++++++++++++ ...mbeddedMosaicMetadataTransactionBuilder.ts | 144 +++++++++++++ ...dedMosaicSupplyChangeTransactionBuilder.ts | 120 +++++++++++ ...igAccountModificationTransactionBuilder.ts | 119 +++++++++++ ...ddedNamespaceMetadataTransactionBuilder.ts | 145 +++++++++++++ ...NamespaceRegistrationTransactionBuilder.ts | 143 +++++++++++++ .../EmbeddedSecretLockTransactionBuilder.ts | 142 +++++++++++++ .../EmbeddedSecretProofTransactionBuilder.ts | 129 ++++++++++++ .../catbuffer/EmbeddedTransactionBuilder.ts | 127 ++++++++++++ .../EmbeddedTransferTransactionBuilder.ts | 118 +++++++++++ src/infrastructure/catbuffer/EntityTypeDto.ts | 133 ++++++++++++ .../catbuffer/GeneratorUtils.ts | 141 +++++++++++++ src/infrastructure/catbuffer/Hash256Dto.ts | 79 +++++++ src/infrastructure/catbuffer/Hash512Dto.ts | 79 +++++++ .../HashLockTransactionBodyBuilder.ts | 121 +++++++++++ .../catbuffer/HashLockTransactionBuilder.ts | 125 +++++++++++ src/infrastructure/catbuffer/KeyDto.ts | 79 +++++++ .../catbuffer/LockHashAlgorithmDto.ts | 33 +++ ...ddressRestrictionTransactionBodyBuilder.ts | 158 ++++++++++++++ ...aicAddressRestrictionTransactionBuilder.ts | 146 +++++++++++++ .../MosaicAliasTransactionBodyBuilder.ts | 121 +++++++++++ .../MosaicAliasTransactionBuilder.ts | 125 +++++++++++ src/infrastructure/catbuffer/MosaicBuilder.ts | 102 +++++++++ .../MosaicDefinitionTransactionBodyBuilder.ts | 158 ++++++++++++++ .../MosaicDefinitionTransactionBuilder.ts | 147 +++++++++++++ .../catbuffer/MosaicFlagsDto.ts | 33 +++ ...GlobalRestrictionTransactionBodyBuilder.ts | 194 ++++++++++++++++++ ...saicGlobalRestrictionTransactionBuilder.ts | 166 +++++++++++++++ src/infrastructure/catbuffer/MosaicIdDto.ts | 80 ++++++++ .../MosaicMetadataTransactionBodyBuilder.ts | 168 +++++++++++++++ .../MosaicMetadataTransactionBuilder.ts | 150 ++++++++++++++ .../catbuffer/MosaicNonceDto.ts | 80 ++++++++ .../catbuffer/MosaicRestrictionTypeDto.ts | 39 ++++ .../catbuffer/MosaicSupplyChangeActionDto.ts | 29 +++ ...osaicSupplyChangeTransactionBodyBuilder.ts | 121 +++++++++++ .../MosaicSupplyChangeTransactionBuilder.ts | 125 +++++++++++ ...countModificationTransactionBodyBuilder.ts | 131 ++++++++++++ ...igAccountModificationTransactionBuilder.ts | 125 +++++++++++ .../catbuffer/NamespaceIdDto.ts | 80 ++++++++ ...NamespaceMetadataTransactionBodyBuilder.ts | 168 +++++++++++++++ .../NamespaceMetadataTransactionBuilder.ts | 151 ++++++++++++++ ...spaceRegistrationTransactionBodyBuilder.ts | 188 +++++++++++++++++ ...NamespaceRegistrationTransactionBuilder.ts | 149 ++++++++++++++ .../catbuffer/NamespaceRegistrationTypeDto.ts | 29 +++ .../SecretLockTransactionBodyBuilder.ts | 160 +++++++++++++++ .../catbuffer/SecretLockTransactionBuilder.ts | 148 +++++++++++++ .../SecretProofTransactionBodyBuilder.ts | 144 +++++++++++++ .../SecretProofTransactionBuilder.ts | 135 ++++++++++++ src/infrastructure/catbuffer/SignatureDto.ts | 79 +++++++ src/infrastructure/catbuffer/TimestampDto.ts | 80 ++++++++ .../catbuffer/TransactionBuilder.ts | 185 +++++++++++++++++ .../TransferTransactionBodyBuilder.ts | 135 ++++++++++++ .../catbuffer/TransferTransactionBuilder.ts | 124 +++++++++++ .../catbuffer/UnresolvedAddressDto.ts | 79 +++++++ .../catbuffer/UnresolvedMosaicBuilder.ts | 102 +++++++++ .../catbuffer/UnresolvedMosaicIdDto.ts | 80 ++++++++ .../transaction/CreateTransactionFromDTO.ts | 18 +- .../CreateTransactionFromPayload.ts | 24 +-- .../transaction/SerializeTransactionToJSON.ts | 24 +-- src/model/model.ts | 6 +- src/model/mosaic/MosaicFlag.ts | 25 +++ ...> AccountAddressRestrictionTransaction.ts} | 50 ++++- .../transaction/AccountLinkTransaction.ts | 27 +++ ...=> AccountMosaicRestrictionTransaction.ts} | 49 ++++- ...AccountOperationRestrictionTransaction.ts} | 46 ++++- .../AccountRestrictionTransaction.ts | 16 +- .../transaction/AddressAliasTransaction.ts | 30 +++ src/model/transaction/AggregateTransaction.ts | 10 +- src/model/transaction/LockFundsTransaction.ts | 7 + .../ModifyMultisigAccountTransaction.ts | 35 +++- .../MosaicAddressRestrictionTransaction.ts | 7 + .../transaction/MosaicAliasTransaction.ts | 29 +++ .../MosaicDefinitionTransaction.ts | 68 ++++++ .../MosaicGlobalRestrictionTransaction.ts | 7 + .../MosaicSupplyChangeTransaction.ts | 27 +++ .../RegisterNamespaceTransaction.ts | 7 + .../transaction/SecretLockTransaction.ts | 46 ++++- .../transaction/SecretProofTransaction.ts | 50 ++++- src/model/transaction/Transaction.ts | 62 +++++- src/model/transaction/TransactionType.ts | 42 ++-- src/model/transaction/TransactionVersion.ts | 4 +- src/model/transaction/TransferTransaction.ts | 61 +++++- test/core/utils/TransactionMapping.spec.ts | 10 +- .../AccountLinkTransaction.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 12 +- .../AddressAliasTransaction.spec.ts | 2 +- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- .../MosaicAliasTransaction.spec.ts | 4 +- .../MosaicDefinitionTransaction.spec.ts | 4 +- .../transaction/SecretLockTransaction.spec.ts | 31 ++- .../SecretProofTransaction.spec.ts | 22 +- test/model/transaction/Transaction.spec.ts | 4 + .../transaction/TransferTransaction.spec.ts | 28 ++- 133 files changed, 11033 insertions(+), 128 deletions(-) create mode 100644 src/infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountLinkActionDto.ts create mode 100644 src/infrastructure/catbuffer/AccountLinkTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountLinkTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMetadataTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountRestrictionModificationActionDto.ts create mode 100644 src/infrastructure/catbuffer/AccountRestrictionModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/AccountRestrictionTypeDto.ts create mode 100644 src/infrastructure/catbuffer/AddressAliasTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/AddressAliasTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AddressDto.ts create mode 100644 src/infrastructure/catbuffer/AliasActionDto.ts create mode 100644 src/infrastructure/catbuffer/AmountDto.ts create mode 100644 src/infrastructure/catbuffer/BlockDurationDto.ts create mode 100644 src/infrastructure/catbuffer/CosignatoryModificationActionDto.ts create mode 100644 src/infrastructure/catbuffer/CosignatoryModificationBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EmbeddedTransferTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/EntityTypeDto.ts create mode 100644 src/infrastructure/catbuffer/GeneratorUtils.ts create mode 100644 src/infrastructure/catbuffer/Hash256Dto.ts create mode 100644 src/infrastructure/catbuffer/Hash512Dto.ts create mode 100644 src/infrastructure/catbuffer/HashLockTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/HashLockTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/KeyDto.ts create mode 100644 src/infrastructure/catbuffer/LockHashAlgorithmDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicAliasTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicAliasTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicDefinitionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicDefinitionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicFlagsDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicIdDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicMetadataTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicNonceDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicRestrictionTypeDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicSupplyChangeActionDto.ts create mode 100644 src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/MultisigAccountModificationTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceIdDto.ts create mode 100644 src/infrastructure/catbuffer/NamespaceMetadataTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceMetadataTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceRegistrationTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/NamespaceRegistrationTypeDto.ts create mode 100644 src/infrastructure/catbuffer/SecretLockTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/SecretLockTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/SecretProofTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/SecretProofTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/SignatureDto.ts create mode 100644 src/infrastructure/catbuffer/TimestampDto.ts create mode 100644 src/infrastructure/catbuffer/TransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/TransferTransactionBodyBuilder.ts create mode 100644 src/infrastructure/catbuffer/TransferTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/UnresolvedAddressDto.ts create mode 100644 src/infrastructure/catbuffer/UnresolvedMosaicBuilder.ts create mode 100644 src/infrastructure/catbuffer/UnresolvedMosaicIdDto.ts create mode 100644 src/model/mosaic/MosaicFlag.ts rename src/model/transaction/{AccountAddressRestrictionModificationTransaction.ts => AccountAddressRestrictionTransaction.ts} (64%) rename src/model/transaction/{AccountMosaicRestrictionModificationTransaction.ts => AccountMosaicRestrictionTransaction.ts} (65%) rename src/model/transaction/{AccountOperationRestrictionModificationTransaction.ts => AccountOperationRestrictionTransaction.ts} (67%) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 5e22d114e3..bf85a04ac5 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -37,10 +37,10 @@ import {MosaicSupplyType} from '../../src/model/mosaic/MosaicSupplyType'; import {NetworkCurrencyMosaic} from '../../src/model/mosaic/NetworkCurrencyMosaic'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; -import { AccountAddressRestrictionModificationTransaction } from '../../src/model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from '../../src/model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../src/model/transaction/AccountLinkTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from '../../src/model/transaction/AccountMosaicRestrictionModificationTransaction'; -import { AccountOperationRestrictionModificationTransaction } from '../../src/model/transaction/AccountOperationRestrictionModificationTransaction'; +import { AccountMosaicRestrictionTransaction } from '../../src/model/transaction/AccountMosaicRestrictionTransaction'; +import { AccountOperationRestrictionTransaction } from '../../src/model/transaction/AccountOperationRestrictionTransaction'; import { AccountRestrictionModification } from '../../src/model/transaction/AccountRestrictionModification'; import { AccountRestrictionTransaction } from '../../src/model/transaction/AccountRestrictionTransaction'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; @@ -410,7 +410,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = addressModification.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionModificationTransaction) => { + listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionTransaction) => { expect(transaction.modifications, 'Modifications').not.to.be.undefined; expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; @@ -561,7 +561,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = addressModification.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AccountMosaicRestrictionModificationTransaction) => { + listener.confirmed(account.address).subscribe((transaction: AccountMosaicRestrictionTransaction) => { expect(transaction.modifications, 'Modifications').not.to.be.undefined; expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; @@ -636,7 +636,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = addressModification.signWith(account3, generationHash); - listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionModificationTransaction) => { + listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionTransaction) => { expect(transaction.modifications, 'Modifications').not.to.be.undefined; expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; diff --git a/src/infrastructure/QueryParams.ts b/src/infrastructure/QueryParams.ts index b1644cf2b3..ee41206d80 100644 --- a/src/infrastructure/QueryParams.ts +++ b/src/infrastructure/QueryParams.ts @@ -22,7 +22,6 @@ export enum Order { DESC = '-id', } - /** * The query params structure describes pagination params for requests. * diff --git a/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts b/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts index 452e4c30b7..bd355c6b94 100644 --- a/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts +++ b/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts @@ -45,7 +45,7 @@ export class Builder { modifications: any; constructor() { this.maxFee = [0, 0]; - this.type = TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS; + this.type = TransactionType.ACCOUNT_RESTRICTION_ADDRESS; } addFee(maxFee) { diff --git a/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts b/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts index edfed292ba..6973e8ccc4 100644 --- a/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts +++ b/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts @@ -45,7 +45,7 @@ export class Builder { modifications: any; constructor() { this.maxFee = [0, 0]; - this.type = TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION; + this.type = TransactionType.ACCOUNT_RESTRICTION_OPERATION; } addFee(maxFee) { diff --git a/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts b/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts index ec97bcc02e..da9338deb4 100644 --- a/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts +++ b/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts @@ -45,7 +45,7 @@ export class Builder { modifications: any; constructor() { this.maxFee = [0, 0]; - this.type = TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC; + this.type = TransactionType.ACCOUNT_RESTRICTION_MOSAIC; } addFee(maxFee) { diff --git a/src/infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder.ts b/src/infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder.ts new file mode 100644 index 0000000000..b8c508eb76 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder.ts @@ -0,0 +1,91 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountRestrictionModificationActionDto } from './AccountRestrictionModificationActionDto'; +import { AccountRestrictionModificationBuilder } from './AccountRestrictionModificationBuilder'; +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; + +/** Account address restriction modification. */ +export class AccountAddressRestrictionModificationBuilder extends AccountRestrictionModificationBuilder { + /** Address restriction value. */ + value: UnresolvedAddressDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + * @param value Address restriction value. + */ + public constructor(modificationAction: AccountRestrictionModificationActionDto, value: UnresolvedAddressDto) { + super(modificationAction); + this.value = value; + } + + /** + * Creates an instance of AccountAddressRestrictionModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountAddressRestrictionModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountAddressRestrictionModificationBuilder { + const byteArray = Array.from(payload); + const superObject = AccountRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const value = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, value.getSize()); + return new AccountAddressRestrictionModificationBuilder(superObject.modificationAction, value); + } + + /** + * Gets address restriction value. + * + * @return Address restriction value. + */ + public getValue(): UnresolvedAddressDto { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.value.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const valueBytes = this.value.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..fcc36e1509 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,114 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountAddressRestrictionModificationBuilder } from './AccountAddressRestrictionModificationBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for an account address restriction transaction. */ +export class AccountAddressRestrictionTransactionBodyBuilder { + /** Account restriction type. */ + restrictionType: AccountRestrictionTypeDto; + /** Account restriction modifications. */ + modifications: AccountAddressRestrictionModificationBuilder[]; + + /** + * Constructor. + * + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(restrictionType: AccountRestrictionTypeDto, modifications: AccountAddressRestrictionModificationBuilder[]) { + this.restrictionType = restrictionType; + this.modifications = modifications; + } + + /** + * Creates an instance of AccountAddressRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountAddressRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountAddressRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const restrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modificationsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modifications: AccountAddressRestrictionModificationBuilder[] = []; + for (let i = 0; i < modificationsCount; i++) { + const item = AccountAddressRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + modifications.push(item); + byteArray.splice(0, item.getSize()); + } + return new AccountAddressRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.restrictionType; + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountAddressRestrictionModificationBuilder[] { + return this.modifications; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // restrictionType + size += 1; // modificationsCount + this.modifications.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const restrictionTypeBytes = GeneratorUtils.uintToBuffer(this.restrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionTypeBytes); + const modificationsCountBytes = GeneratorUtils.uintToBuffer(this.modifications.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsCountBytes); + this.modifications.forEach((item) => { + const modificationsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..a20f98b7c6 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder.ts @@ -0,0 +1,116 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountAddressRestrictionModificationBuilder } from './AccountAddressRestrictionModificationBuilder'; +import { AccountAddressRestrictionTransactionBodyBuilder } from './AccountAddressRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account address restriction transaction. */ +export class AccountAddressRestrictionTransactionBuilder extends TransactionBuilder { + /** Account address restriction transaction body. */ + accountAddressRestrictionTransactionBody: AccountAddressRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountAddressRestrictionModificationBuilder[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.accountAddressRestrictionTransactionBody = new AccountAddressRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of AccountAddressRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountAddressRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountAddressRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountAddressRestrictionTransactionBody = AccountAddressRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountAddressRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountAddressRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountAddressRestrictionTransactionBody.restrictionType, accountAddressRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountAddressRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountAddressRestrictionModificationBuilder[] { + return this.accountAddressRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountAddressRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountAddressRestrictionTransactionBodyBytes = this.accountAddressRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountAddressRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountLinkActionDto.ts b/src/infrastructure/catbuffer/AccountLinkActionDto.ts new file mode 100644 index 0000000000..196ab88465 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountLinkActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of account link actions. */ +export enum AccountLinkActionDto { + /** Unlink account. */ + UNLINK = 0, + /** Link account. */ + LINK = 1, +} diff --git a/src/infrastructure/catbuffer/AccountLinkTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountLinkTransactionBodyBuilder.ts new file mode 100644 index 0000000000..bddb0b8579 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountLinkTransactionBodyBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountLinkActionDto } from './AccountLinkActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an account link transaction. */ +export class AccountLinkTransactionBodyBuilder { + /** Remote account public key. */ + remoteAccountPublicKey: KeyDto; + /** Account link action. */ + linkAction: AccountLinkActionDto; + + /** + * Constructor. + * + * @param remoteAccountPublicKey Remote account public key. + * @param linkAction Account link action. + */ + public constructor(remoteAccountPublicKey: KeyDto, linkAction: AccountLinkActionDto) { + this.remoteAccountPublicKey = remoteAccountPublicKey; + this.linkAction = linkAction; + } + + /** + * Creates an instance of AccountLinkTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountLinkTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountLinkTransactionBodyBuilder { + const byteArray = Array.from(payload); + const remoteAccountPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, remoteAccountPublicKey.getSize()); + const linkAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + return new AccountLinkTransactionBodyBuilder(remoteAccountPublicKey, linkAction); + } + + /** + * Gets remote account public key. + * + * @return Remote account public key. + */ + public getRemoteAccountPublicKey(): KeyDto { + return this.remoteAccountPublicKey; + } + + /** + * Gets account link action. + * + * @return Account link action. + */ + public getLinkAction(): AccountLinkActionDto { + return this.linkAction; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.remoteAccountPublicKey.getSize(); + size += 1; // linkAction + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const remoteAccountPublicKeyBytes = this.remoteAccountPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, remoteAccountPublicKeyBytes); + const linkActionBytes = GeneratorUtils.uintToBuffer(this.linkAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, linkActionBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountLinkTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountLinkTransactionBuilder.ts new file mode 100644 index 0000000000..13aecd9155 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountLinkTransactionBuilder.ts @@ -0,0 +1,113 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountLinkActionDto } from './AccountLinkActionDto'; +import { AccountLinkTransactionBodyBuilder } from './AccountLinkTransactionBodyBuilder'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account link transaction. */ +export class AccountLinkTransactionBuilder extends TransactionBuilder { + /** Account link transaction body. */ + accountLinkTransactionBody: AccountLinkTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param remoteAccountPublicKey Remote account public key. + * @param linkAction Account link action. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, remoteAccountPublicKey: KeyDto, linkAction: AccountLinkActionDto) { + super(signature, signer, version, type, fee, deadline); + this.accountLinkTransactionBody = new AccountLinkTransactionBodyBuilder(remoteAccountPublicKey, linkAction); + } + + /** + * Creates an instance of AccountLinkTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountLinkTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountLinkTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const accountLinkTransactionBody = AccountLinkTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountLinkTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountLinkTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountLinkTransactionBody.remoteAccountPublicKey, accountLinkTransactionBody.linkAction); + } + + /** + * Gets remote account public key. + * + * @return Remote account public key. + */ + public getRemoteAccountPublicKey(): KeyDto { + return this.accountLinkTransactionBody.getRemoteAccountPublicKey(); + } + + /** + * Gets account link action. + * + * @return Account link action. + */ + public getLinkAction(): AccountLinkActionDto { + return this.accountLinkTransactionBody.getLinkAction(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountLinkTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountLinkTransactionBodyBytes = this.accountLinkTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountLinkTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMetadataTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountMetadataTransactionBodyBuilder.ts new file mode 100644 index 0000000000..32353f22c9 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMetadataTransactionBodyBuilder.ts @@ -0,0 +1,147 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an account metadata transaction. */ +export class AccountMetadataTransactionBodyBuilder { + /** Metadata target public key. */ + targetPublicKey: KeyDto; + /** Metadata key scoped to source, target and type. */ + scopedMetadataKey: number[]; + /** Change in value size in bytes. */ + valueSizeDelta: number; + /** Difference between existing value and new value \note when there is no existing value, new value is same this value \note when there is an existing value, new value is calculated as xor(previous-value, value). */ + value: Uint8Array; + + /** + * Constructor. + * + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public constructor(targetPublicKey: KeyDto, scopedMetadataKey: number[], valueSizeDelta: number, value: Uint8Array) { + this.targetPublicKey = targetPublicKey; + this.scopedMetadataKey = scopedMetadataKey; + this.valueSizeDelta = valueSizeDelta; + this.value = value; + } + + /** + * Creates an instance of AccountMetadataTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMetadataTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMetadataTransactionBodyBuilder { + const byteArray = Array.from(payload); + const targetPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetPublicKey.getSize()); + const scopedMetadataKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const valueSizeDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const valueSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const value = GeneratorUtils.getBytes(Uint8Array.from(byteArray), valueSize); + byteArray.splice(0, valueSize); + return new AccountMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, valueSizeDelta, value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.targetPublicKey; + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.scopedMetadataKey; + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.valueSizeDelta; + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.targetPublicKey.getSize(); + size += 8; // scopedMetadataKey + size += 2; // valueSizeDelta + size += 2; // valueSize + size += this.value.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const targetPublicKeyBytes = this.targetPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetPublicKeyBytes); + const scopedMetadataKeyBytes = GeneratorUtils.uint64ToBuffer(this.getScopedMetadataKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, scopedMetadataKeyBytes); + const valueSizeDeltaBytes = GeneratorUtils.uintToBuffer(this.getValueSizeDelta(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeDeltaBytes); + const valueSizeBytes = GeneratorUtils.uintToBuffer(this.value.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.value); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..84daaea40a --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMetadataTransactionBuilder.ts @@ -0,0 +1,139 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMetadataTransactionBodyBuilder } from './AccountMetadataTransactionBodyBuilder'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account metadata transaction. */ +export class AccountMetadataTransactionBuilder extends TransactionBuilder { + /** Account metadata transaction body. */ + accountMetadataTransactionBody: AccountMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], valueSizeDelta: number, value: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.accountMetadataTransactionBody = new AccountMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, valueSizeDelta, value); + } + + /** + * Creates an instance of AccountMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const accountMetadataTransactionBody = AccountMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountMetadataTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountMetadataTransactionBody.targetPublicKey, accountMetadataTransactionBody.scopedMetadataKey, accountMetadataTransactionBody.valueSizeDelta, accountMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.accountMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.accountMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.accountMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.accountMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountMetadataTransactionBodyBytes = this.accountMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder.ts b/src/infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder.ts new file mode 100644 index 0000000000..29abdc38c8 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder.ts @@ -0,0 +1,91 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountRestrictionModificationActionDto } from './AccountRestrictionModificationActionDto'; +import { AccountRestrictionModificationBuilder } from './AccountRestrictionModificationBuilder'; +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Account mosaic restriction modification. */ +export class AccountMosaicRestrictionModificationBuilder extends AccountRestrictionModificationBuilder { + /** Mosaic identifier restriction value. */ + value: UnresolvedMosaicIdDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + * @param value Mosaic identifier restriction value. + */ + public constructor(modificationAction: AccountRestrictionModificationActionDto, value: UnresolvedMosaicIdDto) { + super(modificationAction); + this.value = value; + } + + /** + * Creates an instance of AccountMosaicRestrictionModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMosaicRestrictionModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMosaicRestrictionModificationBuilder { + const byteArray = Array.from(payload); + const superObject = AccountRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const value = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, value.getSize()); + return new AccountMosaicRestrictionModificationBuilder(superObject.modificationAction, value); + } + + /** + * Gets mosaic identifier restriction value. + * + * @return Mosaic identifier restriction value. + */ + public getValue(): UnresolvedMosaicIdDto { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.value.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const valueBytes = this.value.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..c094bdc1c2 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,114 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMosaicRestrictionModificationBuilder } from './AccountMosaicRestrictionModificationBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for an account mosaic restriction transaction. */ +export class AccountMosaicRestrictionTransactionBodyBuilder { + /** Account restriction type. */ + restrictionType: AccountRestrictionTypeDto; + /** Account restriction modifications. */ + modifications: AccountMosaicRestrictionModificationBuilder[]; + + /** + * Constructor. + * + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(restrictionType: AccountRestrictionTypeDto, modifications: AccountMosaicRestrictionModificationBuilder[]) { + this.restrictionType = restrictionType; + this.modifications = modifications; + } + + /** + * Creates an instance of AccountMosaicRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMosaicRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMosaicRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const restrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modificationsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modifications: AccountMosaicRestrictionModificationBuilder[] = []; + for (let i = 0; i < modificationsCount; i++) { + const item = AccountMosaicRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + modifications.push(item); + byteArray.splice(0, item.getSize()); + } + return new AccountMosaicRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.restrictionType; + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountMosaicRestrictionModificationBuilder[] { + return this.modifications; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // restrictionType + size += 1; // modificationsCount + this.modifications.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const restrictionTypeBytes = GeneratorUtils.uintToBuffer(this.restrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionTypeBytes); + const modificationsCountBytes = GeneratorUtils.uintToBuffer(this.modifications.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsCountBytes); + this.modifications.forEach((item) => { + const modificationsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..8b2f79a57e --- /dev/null +++ b/src/infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder.ts @@ -0,0 +1,116 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMosaicRestrictionModificationBuilder } from './AccountMosaicRestrictionModificationBuilder'; +import { AccountMosaicRestrictionTransactionBodyBuilder } from './AccountMosaicRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account mosaic restriction transaction. */ +export class AccountMosaicRestrictionTransactionBuilder extends TransactionBuilder { + /** Account mosaic restriction transaction body. */ + accountMosaicRestrictionTransactionBody: AccountMosaicRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountMosaicRestrictionModificationBuilder[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.accountMosaicRestrictionTransactionBody = new AccountMosaicRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of AccountMosaicRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountMosaicRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountMosaicRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountMosaicRestrictionTransactionBody = AccountMosaicRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountMosaicRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountMosaicRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountMosaicRestrictionTransactionBody.restrictionType, accountMosaicRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountMosaicRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountMosaicRestrictionModificationBuilder[] { + return this.accountMosaicRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountMosaicRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountMosaicRestrictionTransactionBodyBytes = this.accountMosaicRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountMosaicRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder.ts b/src/infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder.ts new file mode 100644 index 0000000000..669bfc4dce --- /dev/null +++ b/src/infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder.ts @@ -0,0 +1,91 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountRestrictionModificationActionDto } from './AccountRestrictionModificationActionDto'; +import { AccountRestrictionModificationBuilder } from './AccountRestrictionModificationBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Account operation restriction modification. */ +export class AccountOperationRestrictionModificationBuilder extends AccountRestrictionModificationBuilder { + /** Transaction type restriction value. */ + value: EntityTypeDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + * @param value Transaction type restriction value. + */ + public constructor(modificationAction: AccountRestrictionModificationActionDto, value: EntityTypeDto) { + super(modificationAction); + this.value = value; + } + + /** + * Creates an instance of AccountOperationRestrictionModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountOperationRestrictionModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountOperationRestrictionModificationBuilder { + const byteArray = Array.from(payload); + const superObject = AccountRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const value = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + return new AccountOperationRestrictionModificationBuilder(superObject.modificationAction, value); + } + + /** + * Gets transaction type restriction value. + * + * @return Transaction type restriction value. + */ + public getValue(): EntityTypeDto { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += 2; // value + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const valueBytes = GeneratorUtils.uintToBuffer(this.value, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..dd505b0b5f --- /dev/null +++ b/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,114 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountOperationRestrictionModificationBuilder } from './AccountOperationRestrictionModificationBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for an account operation restriction transaction. */ +export class AccountOperationRestrictionTransactionBodyBuilder { + /** Account restriction type. */ + restrictionType: AccountRestrictionTypeDto; + /** Account restriction modifications. */ + modifications: AccountOperationRestrictionModificationBuilder[]; + + /** + * Constructor. + * + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(restrictionType: AccountRestrictionTypeDto, modifications: AccountOperationRestrictionModificationBuilder[]) { + this.restrictionType = restrictionType; + this.modifications = modifications; + } + + /** + * Creates an instance of AccountOperationRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountOperationRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountOperationRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const restrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modificationsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modifications: AccountOperationRestrictionModificationBuilder[] = []; + for (let i = 0; i < modificationsCount; i++) { + const item = AccountOperationRestrictionModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + modifications.push(item); + byteArray.splice(0, item.getSize()); + } + return new AccountOperationRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.restrictionType; + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountOperationRestrictionModificationBuilder[] { + return this.modifications; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // restrictionType + size += 1; // modificationsCount + this.modifications.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const restrictionTypeBytes = GeneratorUtils.uintToBuffer(this.restrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionTypeBytes); + const modificationsCountBytes = GeneratorUtils.uintToBuffer(this.modifications.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsCountBytes); + this.modifications.forEach((item) => { + const modificationsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..2f5795b732 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder.ts @@ -0,0 +1,116 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountOperationRestrictionModificationBuilder } from './AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBodyBuilder } from './AccountOperationRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded account operation restriction transaction. */ +export class AccountOperationRestrictionTransactionBuilder extends TransactionBuilder { + /** Account operation restriction transaction body. */ + accountOperationRestrictionTransactionBody: AccountOperationRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountOperationRestrictionModificationBuilder[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.accountOperationRestrictionTransactionBody = new AccountOperationRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of AccountOperationRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountOperationRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountOperationRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountOperationRestrictionTransactionBody = AccountOperationRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountOperationRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AccountOperationRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, accountOperationRestrictionTransactionBody.restrictionType, accountOperationRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountOperationRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountOperationRestrictionModificationBuilder[] { + return this.accountOperationRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountOperationRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountOperationRestrictionTransactionBodyBytes = this.accountOperationRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountOperationRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountRestrictionModificationActionDto.ts b/src/infrastructure/catbuffer/AccountRestrictionModificationActionDto.ts new file mode 100644 index 0000000000..84da076601 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountRestrictionModificationActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of account restriction modification actions. */ +export enum AccountRestrictionModificationActionDto { + /** Remove account restriction value. */ + DEL = 0, + /** Add account restriction value. */ + ADD = 1, +} diff --git a/src/infrastructure/catbuffer/AccountRestrictionModificationBuilder.ts b/src/infrastructure/catbuffer/AccountRestrictionModificationBuilder.ts new file mode 100644 index 0000000000..286901d4c9 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountRestrictionModificationBuilder.ts @@ -0,0 +1,83 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountRestrictionModificationActionDto } from './AccountRestrictionModificationActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Account restriction basic modification. */ +export class AccountRestrictionModificationBuilder { + /** Modification action. */ + modificationAction: AccountRestrictionModificationActionDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + */ + public constructor(modificationAction: AccountRestrictionModificationActionDto) { + this.modificationAction = modificationAction; + } + + /** + * Creates an instance of AccountRestrictionModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AccountRestrictionModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AccountRestrictionModificationBuilder { + const byteArray = Array.from(payload); + const modificationAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + return new AccountRestrictionModificationBuilder(modificationAction); + } + + /** + * Gets modification action. + * + * @return Modification action. + */ + public getModificationAction(): AccountRestrictionModificationActionDto { + return this.modificationAction; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // modificationAction + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const modificationActionBytes = GeneratorUtils.uintToBuffer(this.modificationAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationActionBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AccountRestrictionTypeDto.ts b/src/infrastructure/catbuffer/AccountRestrictionTypeDto.ts new file mode 100644 index 0000000000..2d9cc2d061 --- /dev/null +++ b/src/infrastructure/catbuffer/AccountRestrictionTypeDto.ts @@ -0,0 +1,35 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of account restriction types. */ +export enum AccountRestrictionTypeDto { + /** Restriction type is an address. */ + ADDRESS = 1, + /** Restriction type is a mosaic identifier. */ + MOSAIC_ID = 2, + /** Restriction type is a transaction type. */ + TRANSACTION_TYPE = 4, + /** Restriction is interpreted as outgoing. */ + OUTGOING = 64, + /** Restriction is interpreted as blocking operation. */ + BLOCK = 128, +} diff --git a/src/infrastructure/catbuffer/AddressAliasTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AddressAliasTransactionBodyBuilder.ts new file mode 100644 index 0000000000..0cdb182cc0 --- /dev/null +++ b/src/infrastructure/catbuffer/AddressAliasTransactionBodyBuilder.ts @@ -0,0 +1,121 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AddressDto } from './AddressDto'; +import { AliasActionDto } from './AliasActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for an address alias transaction. */ +export class AddressAliasTransactionBodyBuilder { + /** Alias action. */ + aliasAction: AliasActionDto; + /** Identifier of the namespace that will become an alias. */ + namespaceId: NamespaceIdDto; + /** Aliased address. */ + address: AddressDto; + + /** + * Constructor. + * + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param address Aliased address. + */ + public constructor(aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, address: AddressDto) { + this.aliasAction = aliasAction; + this.namespaceId = namespaceId; + this.address = address; + } + + /** + * Creates an instance of AddressAliasTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AddressAliasTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AddressAliasTransactionBodyBuilder { + const byteArray = Array.from(payload); + const aliasAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const namespaceId = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceId.getSize()); + const address = AddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, address.getSize()); + return new AddressAliasTransactionBodyBuilder(aliasAction, namespaceId, address); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.aliasAction; + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.namespaceId; + } + + /** + * Gets aliased address. + * + * @return Aliased address. + */ + public getAddress(): AddressDto { + return this.address; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // aliasAction + size += this.namespaceId.getSize(); + size += this.address.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const aliasActionBytes = GeneratorUtils.uintToBuffer(this.aliasAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, aliasActionBytes); + const namespaceIdBytes = this.namespaceId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceIdBytes); + const addressBytes = this.address.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, addressBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AddressAliasTransactionBuilder.ts b/src/infrastructure/catbuffer/AddressAliasTransactionBuilder.ts new file mode 100644 index 0000000000..a1b64702cc --- /dev/null +++ b/src/infrastructure/catbuffer/AddressAliasTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; +import { AddressDto } from './AddressDto'; +import { AliasActionDto } from './AliasActionDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded address alias transaction. */ +export class AddressAliasTransactionBuilder extends TransactionBuilder { + /** Address alias transaction body. */ + addressAliasTransactionBody: AddressAliasTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param address Aliased address. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, address: AddressDto) { + super(signature, signer, version, type, fee, deadline); + this.addressAliasTransactionBody = new AddressAliasTransactionBodyBuilder(aliasAction, namespaceId, address); + } + + /** + * Creates an instance of AddressAliasTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AddressAliasTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AddressAliasTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const addressAliasTransactionBody = AddressAliasTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, addressAliasTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AddressAliasTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, addressAliasTransactionBody.aliasAction, addressAliasTransactionBody.namespaceId, addressAliasTransactionBody.address); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.addressAliasTransactionBody.getAliasAction(); + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.addressAliasTransactionBody.getNamespaceId(); + } + + /** + * Gets aliased address. + * + * @return Aliased address. + */ + public getAddress(): AddressDto { + return this.addressAliasTransactionBody.getAddress(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.addressAliasTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const addressAliasTransactionBodyBytes = this.addressAliasTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, addressAliasTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AddressDto.ts b/src/infrastructure/catbuffer/AddressDto.ts new file mode 100644 index 0000000000..16214f53dc --- /dev/null +++ b/src/infrastructure/catbuffer/AddressDto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Address. */ +export class AddressDto { + /** Address. */ + address: Uint8Array; + + /** + * Constructor. + * + * @param address Address. + */ + constructor(address: Uint8Array) { + this.address = address; + } + + /** + * Creates an instance of AddressDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AddressDto. + */ + public static loadFromBinary(payload: Uint8Array): AddressDto { + const byteArray = Array.from(payload); + const address = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 25); + byteArray.splice(0, 25); + return new AddressDto(address); + } + + /** + * Gets Address. + * + * @return Address. + */ + public getAddress(): Uint8Array { + return this.address; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 25; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.address); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AliasActionDto.ts b/src/infrastructure/catbuffer/AliasActionDto.ts new file mode 100644 index 0000000000..58cd769ca8 --- /dev/null +++ b/src/infrastructure/catbuffer/AliasActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of alias actions. */ +export enum AliasActionDto { + /** Unlink alias. */ + UNLINK = 0, + /** Link alias. */ + LINK = 1, +} diff --git a/src/infrastructure/catbuffer/AmountDto.ts b/src/infrastructure/catbuffer/AmountDto.ts new file mode 100644 index 0000000000..b1e3c31731 --- /dev/null +++ b/src/infrastructure/catbuffer/AmountDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Amount. */ +export class AmountDto { + /** Amount. */ + amount: number[]; + + /** + * Constructor. + * + * @param amount Amount. + */ + constructor(amount: number[]) { + this.amount = amount; + } + + /** + * Creates an instance of AmountDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AmountDto. + */ + public static loadFromBinary(payload: Uint8Array): AmountDto { + const byteArray = Array.from(payload); + const amount = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new AmountDto(amount); + } + + /** + * Gets Amount. + * + * @return Amount. + */ + public getAmount(): number[] { + return this.amount; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const amountBytes = GeneratorUtils.uint64ToBuffer(this.getAmount()); + newArray = GeneratorUtils.concatTypedArrays(newArray, amountBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/BlockDurationDto.ts b/src/infrastructure/catbuffer/BlockDurationDto.ts new file mode 100644 index 0000000000..dfc232ebdc --- /dev/null +++ b/src/infrastructure/catbuffer/BlockDurationDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Block duration. */ +export class BlockDurationDto { + /** Block duration. */ + blockDuration: number[]; + + /** + * Constructor. + * + * @param blockDuration Block duration. + */ + constructor(blockDuration: number[]) { + this.blockDuration = blockDuration; + } + + /** + * Creates an instance of BlockDurationDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of BlockDurationDto. + */ + public static loadFromBinary(payload: Uint8Array): BlockDurationDto { + const byteArray = Array.from(payload); + const blockDuration = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new BlockDurationDto(blockDuration); + } + + /** + * Gets Block duration. + * + * @return Block duration. + */ + public getBlockDuration(): number[] { + return this.blockDuration; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const blockDurationBytes = GeneratorUtils.uint64ToBuffer(this.getBlockDuration()); + newArray = GeneratorUtils.concatTypedArrays(newArray, blockDurationBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/CosignatoryModificationActionDto.ts b/src/infrastructure/catbuffer/CosignatoryModificationActionDto.ts new file mode 100644 index 0000000000..c428422d9a --- /dev/null +++ b/src/infrastructure/catbuffer/CosignatoryModificationActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of cosignatory modification actions. */ +export enum CosignatoryModificationActionDto { + /** Remove cosignatory. */ + DEL = 0, + /** Add cosignatory. */ + ADD = 1, +} diff --git a/src/infrastructure/catbuffer/CosignatoryModificationBuilder.ts b/src/infrastructure/catbuffer/CosignatoryModificationBuilder.ts new file mode 100644 index 0000000000..8413b779db --- /dev/null +++ b/src/infrastructure/catbuffer/CosignatoryModificationBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { CosignatoryModificationActionDto } from './CosignatoryModificationActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for a cosignatory modification. */ +export class CosignatoryModificationBuilder { + /** Modification action. */ + modificationAction: CosignatoryModificationActionDto; + /** Cosignatory account public key. */ + cosignatoryPublicKey: KeyDto; + + /** + * Constructor. + * + * @param modificationAction Modification action. + * @param cosignatoryPublicKey Cosignatory account public key. + */ + public constructor(modificationAction: CosignatoryModificationActionDto, cosignatoryPublicKey: KeyDto) { + this.modificationAction = modificationAction; + this.cosignatoryPublicKey = cosignatoryPublicKey; + } + + /** + * Creates an instance of CosignatoryModificationBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of CosignatoryModificationBuilder. + */ + public static loadFromBinary(payload: Uint8Array): CosignatoryModificationBuilder { + const byteArray = Array.from(payload); + const modificationAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const cosignatoryPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, cosignatoryPublicKey.getSize()); + return new CosignatoryModificationBuilder(modificationAction, cosignatoryPublicKey); + } + + /** + * Gets modification action. + * + * @return Modification action. + */ + public getModificationAction(): CosignatoryModificationActionDto { + return this.modificationAction; + } + + /** + * Gets cosignatory account public key. + * + * @return Cosignatory account public key. + */ + public getCosignatoryPublicKey(): KeyDto { + return this.cosignatoryPublicKey; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // modificationAction + size += this.cosignatoryPublicKey.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const modificationActionBytes = GeneratorUtils.uintToBuffer(this.modificationAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationActionBytes); + const cosignatoryPublicKeyBytes = this.cosignatoryPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, cosignatoryPublicKeyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..af18bf390d --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder.ts @@ -0,0 +1,110 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountAddressRestrictionModificationBuilder } from './AccountAddressRestrictionModificationBuilder'; +import { AccountAddressRestrictionTransactionBodyBuilder } from './AccountAddressRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account address restriction transaction. */ +export class EmbeddedAccountAddressRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account address restriction transaction body. */ + accountAddressRestrictionTransactionBody: AccountAddressRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountAddressRestrictionModificationBuilder[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.accountAddressRestrictionTransactionBody = new AccountAddressRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of EmbeddedAccountAddressRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountAddressRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountAddressRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountAddressRestrictionTransactionBody = AccountAddressRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountAddressRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountAddressRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountAddressRestrictionTransactionBody.restrictionType, accountAddressRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountAddressRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountAddressRestrictionModificationBuilder[] { + return this.accountAddressRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountAddressRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountAddressRestrictionTransactionBodyBytes = this.accountAddressRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountAddressRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder.ts new file mode 100644 index 0000000000..c2219f36bb --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder.ts @@ -0,0 +1,107 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountLinkActionDto } from './AccountLinkActionDto'; +import { AccountLinkTransactionBodyBuilder } from './AccountLinkTransactionBodyBuilder'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account link transaction. */ +export class EmbeddedAccountLinkTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account link transaction body. */ + accountLinkTransactionBody: AccountLinkTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param remoteAccountPublicKey Remote account public key. + * @param linkAction Account link action. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, remoteAccountPublicKey: KeyDto, linkAction: AccountLinkActionDto) { + super(signer, version, type); + this.accountLinkTransactionBody = new AccountLinkTransactionBodyBuilder(remoteAccountPublicKey, linkAction); + } + + /** + * Creates an instance of EmbeddedAccountLinkTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountLinkTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountLinkTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const accountLinkTransactionBody = AccountLinkTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountLinkTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountLinkTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountLinkTransactionBody.remoteAccountPublicKey, accountLinkTransactionBody.linkAction); + } + + /** + * Gets remote account public key. + * + * @return Remote account public key. + */ + public getRemoteAccountPublicKey(): KeyDto { + return this.accountLinkTransactionBody.getRemoteAccountPublicKey(); + } + + /** + * Gets account link action. + * + * @return Account link action. + */ + public getLinkAction(): AccountLinkActionDto { + return this.accountLinkTransactionBody.getLinkAction(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountLinkTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountLinkTransactionBodyBytes = this.accountLinkTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountLinkTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..ec9f33ca7f --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder.ts @@ -0,0 +1,133 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMetadataTransactionBodyBuilder } from './AccountMetadataTransactionBodyBuilder'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account metadata transaction. */ +export class EmbeddedAccountMetadataTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account metadata transaction body. */ + accountMetadataTransactionBody: AccountMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], valueSizeDelta: number, value: Uint8Array) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.accountMetadataTransactionBody = new AccountMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, valueSizeDelta, value); + } + + /** + * Creates an instance of EmbeddedAccountMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const accountMetadataTransactionBody = AccountMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountMetadataTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountMetadataTransactionBody.targetPublicKey, accountMetadataTransactionBody.scopedMetadataKey, accountMetadataTransactionBody.valueSizeDelta, accountMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.accountMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.accountMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.accountMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.accountMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountMetadataTransactionBodyBytes = this.accountMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..d97d085545 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder.ts @@ -0,0 +1,110 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountMosaicRestrictionModificationBuilder } from './AccountMosaicRestrictionModificationBuilder'; +import { AccountMosaicRestrictionTransactionBodyBuilder } from './AccountMosaicRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account mosaic restriction transaction. */ +export class EmbeddedAccountMosaicRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account mosaic restriction transaction body. */ + accountMosaicRestrictionTransactionBody: AccountMosaicRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountMosaicRestrictionModificationBuilder[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.accountMosaicRestrictionTransactionBody = new AccountMosaicRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of EmbeddedAccountMosaicRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountMosaicRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountMosaicRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountMosaicRestrictionTransactionBody = AccountMosaicRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountMosaicRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountMosaicRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountMosaicRestrictionTransactionBody.restrictionType, accountMosaicRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountMosaicRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountMosaicRestrictionModificationBuilder[] { + return this.accountMosaicRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountMosaicRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountMosaicRestrictionTransactionBodyBytes = this.accountMosaicRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountMosaicRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..c4de2fb15c --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder.ts @@ -0,0 +1,110 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AccountOperationRestrictionModificationBuilder } from './AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBodyBuilder } from './AccountOperationRestrictionTransactionBodyBuilder'; +import { AccountRestrictionTypeDto } from './AccountRestrictionTypeDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded account operation restriction transaction. */ +export class EmbeddedAccountOperationRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Account operation restriction transaction body. */ + accountOperationRestrictionTransactionBody: AccountOperationRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param restrictionType Account restriction type. + * @param modifications Account restriction modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, restrictionType: AccountRestrictionTypeDto, modifications: AccountOperationRestrictionModificationBuilder[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.accountOperationRestrictionTransactionBody = new AccountOperationRestrictionTransactionBodyBuilder(restrictionType, modifications); + } + + /** + * Creates an instance of EmbeddedAccountOperationRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAccountOperationRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAccountOperationRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const accountOperationRestrictionTransactionBody = AccountOperationRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, accountOperationRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAccountOperationRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, accountOperationRestrictionTransactionBody.restrictionType, accountOperationRestrictionTransactionBody.modifications); + } + + /** + * Gets account restriction type. + * + * @return Account restriction type. + */ + public getRestrictionType(): AccountRestrictionTypeDto { + return this.accountOperationRestrictionTransactionBody.getRestrictionType(); + } + + /** + * Gets account restriction modifications. + * + * @return Account restriction modifications. + */ + public getModifications(): AccountOperationRestrictionModificationBuilder[] { + return this.accountOperationRestrictionTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.accountOperationRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const accountOperationRestrictionTransactionBodyBytes = this.accountOperationRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, accountOperationRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder.ts new file mode 100644 index 0000000000..7532500571 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder.ts @@ -0,0 +1,119 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; +import { AddressDto } from './AddressDto'; +import { AliasActionDto } from './AliasActionDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for an embedded address alias transaction. */ +export class EmbeddedAddressAliasTransactionBuilder extends EmbeddedTransactionBuilder { + /** Address alias transaction body. */ + addressAliasTransactionBody: AddressAliasTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param address Aliased address. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, address: AddressDto) { + super(signer, version, type); + this.addressAliasTransactionBody = new AddressAliasTransactionBodyBuilder(aliasAction, namespaceId, address); + } + + /** + * Creates an instance of EmbeddedAddressAliasTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedAddressAliasTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedAddressAliasTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const addressAliasTransactionBody = AddressAliasTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, addressAliasTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedAddressAliasTransactionBuilder(superObject.signer, superObject.version, superObject.type, addressAliasTransactionBody.aliasAction, addressAliasTransactionBody.namespaceId, addressAliasTransactionBody.address); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.addressAliasTransactionBody.getAliasAction(); + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.addressAliasTransactionBody.getNamespaceId(); + } + + /** + * Gets aliased address. + * + * @return Aliased address. + */ + public getAddress(): AddressDto { + return this.addressAliasTransactionBody.getAddress(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.addressAliasTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const addressAliasTransactionBodyBytes = this.addressAliasTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, addressAliasTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder.ts new file mode 100644 index 0000000000..e91a7e98b4 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder.ts @@ -0,0 +1,119 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { HashLockTransactionBodyBuilder } from './HashLockTransactionBodyBuilder'; +import { KeyDto } from './KeyDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for an embedded hash lock transaction. */ +export class EmbeddedHashLockTransactionBuilder extends EmbeddedTransactionBuilder { + /** Hash lock transaction body. */ + hashLockTransactionBody: HashLockTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaic Lock mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hash Lock hash. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hash: Hash256Dto) { + super(signer, version, type); + this.hashLockTransactionBody = new HashLockTransactionBodyBuilder(mosaic, duration, hash); + } + + /** + * Creates an instance of EmbeddedHashLockTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedHashLockTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedHashLockTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const hashLockTransactionBody = HashLockTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, hashLockTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedHashLockTransactionBuilder(superObject.signer, superObject.version, superObject.type, hashLockTransactionBody.mosaic, hashLockTransactionBody.duration, hashLockTransactionBody.hash); + } + + /** + * Gets lock mosaic. + * + * @return Lock mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.hashLockTransactionBody.getMosaic(); + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.hashLockTransactionBody.getDuration(); + } + + /** + * Gets lock hash. + * + * @return Lock hash. + */ + public getHash(): Hash256Dto { + return this.hashLockTransactionBody.getHash(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.hashLockTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const hashLockTransactionBodyBytes = this.hashLockTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashLockTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..ead5de2075 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder.ts @@ -0,0 +1,140 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicAddressRestrictionTransactionBodyBuilder } from './MosaicAddressRestrictionTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an embedded mosaic address restriction transaction. */ +export class EmbeddedMosaicAddressRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic address restriction transaction body. */ + mosaicAddressRestrictionTransactionBody: MosaicAddressRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaicId Identifier of the mosaic to which the restriction applies. + * @param restrictionKey Restriction key. + * @param targetAddress Address being restricted. + * @param previousRestrictionValue Previous restriction value. + * @param newRestrictionValue New restriction value. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], targetAddress: UnresolvedAddressDto, previousRestrictionValue: number[], newRestrictionValue: number[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.mosaicAddressRestrictionTransactionBody = new MosaicAddressRestrictionTransactionBodyBuilder(mosaicId, restrictionKey, targetAddress, previousRestrictionValue, newRestrictionValue); + } + + /** + * Creates an instance of EmbeddedMosaicAddressRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicAddressRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicAddressRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicAddressRestrictionTransactionBody = MosaicAddressRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicAddressRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicAddressRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicAddressRestrictionTransactionBody.mosaicId, mosaicAddressRestrictionTransactionBody.restrictionKey, mosaicAddressRestrictionTransactionBody.targetAddress, mosaicAddressRestrictionTransactionBody.previousRestrictionValue, mosaicAddressRestrictionTransactionBody.newRestrictionValue); + } + + /** + * Gets identifier of the mosaic to which the restriction applies. + * + * @return Identifier of the mosaic to which the restriction applies. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicAddressRestrictionTransactionBody.getMosaicId(); + } + + /** + * Gets restriction key. + * + * @return Restriction key. + */ + public getRestrictionKey(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getRestrictionKey(); + } + + /** + * Gets address being restricted. + * + * @return Address being restricted. + */ + public getTargetAddress(): UnresolvedAddressDto { + return this.mosaicAddressRestrictionTransactionBody.getTargetAddress(); + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getPreviousRestrictionValue(); + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getNewRestrictionValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicAddressRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicAddressRestrictionTransactionBodyBytes = this.mosaicAddressRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicAddressRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder.ts new file mode 100644 index 0000000000..635b59964f --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder.ts @@ -0,0 +1,119 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AliasActionDto } from './AliasActionDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicAliasTransactionBodyBuilder } from './MosaicAliasTransactionBodyBuilder'; +import { MosaicIdDto } from './MosaicIdDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for an embedded mosaic alias transaction. */ +export class EmbeddedMosaicAliasTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic alias transaction body. */ + mosaicAliasTransactionBody: MosaicAliasTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param mosaicId Aliased mosaic identifier. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, mosaicId: MosaicIdDto) { + super(signer, version, type); + this.mosaicAliasTransactionBody = new MosaicAliasTransactionBodyBuilder(aliasAction, namespaceId, mosaicId); + } + + /** + * Creates an instance of EmbeddedMosaicAliasTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicAliasTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicAliasTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const mosaicAliasTransactionBody = MosaicAliasTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicAliasTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicAliasTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicAliasTransactionBody.aliasAction, mosaicAliasTransactionBody.namespaceId, mosaicAliasTransactionBody.mosaicId); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.mosaicAliasTransactionBody.getAliasAction(); + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.mosaicAliasTransactionBody.getNamespaceId(); + } + + /** + * Gets aliased mosaic identifier. + * + * @return Aliased mosaic identifier. + */ + public getMosaicId(): MosaicIdDto { + return this.mosaicAliasTransactionBody.getMosaicId(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicAliasTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicAliasTransactionBodyBytes = this.mosaicAliasTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicAliasTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder.ts new file mode 100644 index 0000000000..ad46a89813 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder.ts @@ -0,0 +1,141 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicDefinitionTransactionBodyBuilder } from './MosaicDefinitionTransactionBodyBuilder'; +import { MosaicIdDto } from './MosaicIdDto'; +import { MosaicNonceDto } from './MosaicNonceDto'; + +/** Binary layout for an embedded mosaic definition transaction. */ +export class EmbeddedMosaicDefinitionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic definition transaction body. */ + mosaicDefinitionTransactionBody: MosaicDefinitionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param nonce Mosaic nonce. + * @param id Mosaic identifier. + * @param flags Mosaic flags. + * @param divisibility Mosaic divisibility. + * @param duration Mosaic duration. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, nonce: MosaicNonceDto, id: MosaicIdDto, flags: number, divisibility: number, duration: BlockDurationDto) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.mosaicDefinitionTransactionBody = new MosaicDefinitionTransactionBodyBuilder(nonce, id, flags, divisibility, duration); + } + + /** + * Creates an instance of EmbeddedMosaicDefinitionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicDefinitionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicDefinitionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicDefinitionTransactionBody = MosaicDefinitionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicDefinitionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicDefinitionTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicDefinitionTransactionBody.nonce, mosaicDefinitionTransactionBody.id, mosaicDefinitionTransactionBody.flags, mosaicDefinitionTransactionBody.divisibility, mosaicDefinitionTransactionBody.duration); + } + + /** + * Gets mosaic nonce. + * + * @return Mosaic nonce. + */ + public getNonce(): MosaicNonceDto { + return this.mosaicDefinitionTransactionBody.getNonce(); + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getId(): MosaicIdDto { + return this.mosaicDefinitionTransactionBody.getId(); + } + + /** + * Gets mosaic flags. + * + * @return Mosaic flags. + */ + public getFlags(): number { + return this.mosaicDefinitionTransactionBody.getFlags(); + } + + /** + * Gets mosaic divisibility. + * + * @return Mosaic divisibility. + */ + public getDivisibility(): number { + return this.mosaicDefinitionTransactionBody.getDivisibility(); + } + + /** + * Gets mosaic duration. + * + * @return Mosaic duration. + */ + public getDuration(): BlockDurationDto { + return this.mosaicDefinitionTransactionBody.getDuration(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicDefinitionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicDefinitionTransactionBodyBytes = this.mosaicDefinitionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicDefinitionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..224df49b31 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder.ts @@ -0,0 +1,160 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicGlobalRestrictionTransactionBodyBuilder } from './MosaicGlobalRestrictionTransactionBodyBuilder'; +import { MosaicRestrictionTypeDto } from './MosaicRestrictionTypeDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an embedded mosaic global restriction transaction. */ +export class EmbeddedMosaicGlobalRestrictionTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic global restriction transaction body. */ + mosaicGlobalRestrictionTransactionBody: MosaicGlobalRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaicId Identifier of the mosaic being restricted. + * @param referenceMosaicId Identifier of the mosaic providing the restriction key. + * @param restrictionKey Restriction key relative to the reference mosaic identifier. + * @param previousRestrictionValue Previous restriction value. + * @param previousRestrictionType Previous restriction type. + * @param newRestrictionValue New restriction value. + * @param newRestrictionType New restriction type. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaicId: UnresolvedMosaicIdDto, referenceMosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], previousRestrictionValue: number[], previousRestrictionType: MosaicRestrictionTypeDto, newRestrictionValue: number[], newRestrictionType: MosaicRestrictionTypeDto) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.mosaicGlobalRestrictionTransactionBody = new MosaicGlobalRestrictionTransactionBodyBuilder(mosaicId, referenceMosaicId, restrictionKey, previousRestrictionValue, previousRestrictionType, newRestrictionValue, newRestrictionType); + } + + /** + * Creates an instance of EmbeddedMosaicGlobalRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicGlobalRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicGlobalRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicGlobalRestrictionTransactionBody = MosaicGlobalRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicGlobalRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicGlobalRestrictionTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicGlobalRestrictionTransactionBody.mosaicId, mosaicGlobalRestrictionTransactionBody.referenceMosaicId, mosaicGlobalRestrictionTransactionBody.restrictionKey, mosaicGlobalRestrictionTransactionBody.previousRestrictionValue, mosaicGlobalRestrictionTransactionBody.previousRestrictionType, mosaicGlobalRestrictionTransactionBody.newRestrictionValue, mosaicGlobalRestrictionTransactionBody.newRestrictionType); + } + + /** + * Gets identifier of the mosaic being restricted. + * + * @return Identifier of the mosaic being restricted. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicGlobalRestrictionTransactionBody.getMosaicId(); + } + + /** + * Gets identifier of the mosaic providing the restriction key. + * + * @return Identifier of the mosaic providing the restriction key. + */ + public getReferenceMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicGlobalRestrictionTransactionBody.getReferenceMosaicId(); + } + + /** + * Gets restriction key relative to the reference mosaic identifier. + * + * @return Restriction key relative to the reference mosaic identifier. + */ + public getRestrictionKey(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getRestrictionKey(); + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getPreviousRestrictionValue(); + } + + /** + * Gets previous restriction type. + * + * @return Previous restriction type. + */ + public getPreviousRestrictionType(): MosaicRestrictionTypeDto { + return this.mosaicGlobalRestrictionTransactionBody.getPreviousRestrictionType(); + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getNewRestrictionValue(); + } + + /** + * Gets new restriction type. + * + * @return New restriction type. + */ + public getNewRestrictionType(): MosaicRestrictionTypeDto { + return this.mosaicGlobalRestrictionTransactionBody.getNewRestrictionType(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicGlobalRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicGlobalRestrictionTransactionBodyBytes = this.mosaicGlobalRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicGlobalRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..378bec0bf3 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder.ts @@ -0,0 +1,144 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicMetadataTransactionBodyBuilder } from './MosaicMetadataTransactionBodyBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an embedded mosaic metadata transaction. */ +export class EmbeddedMosaicMetadataTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic metadata transaction body. */ + mosaicMetadataTransactionBody: MosaicMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetMosaicId Target mosaic identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], targetMosaicId: UnresolvedMosaicIdDto, valueSizeDelta: number, value: Uint8Array) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.mosaicMetadataTransactionBody = new MosaicMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetMosaicId, valueSizeDelta, value); + } + + /** + * Creates an instance of EmbeddedMosaicMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const mosaicMetadataTransactionBody = MosaicMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicMetadataTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicMetadataTransactionBody.targetPublicKey, mosaicMetadataTransactionBody.scopedMetadataKey, mosaicMetadataTransactionBody.targetMosaicId, mosaicMetadataTransactionBody.valueSizeDelta, mosaicMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.mosaicMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.mosaicMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets target mosaic identifier. + * + * @return Target mosaic identifier. + */ + public getTargetMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicMetadataTransactionBody.getTargetMosaicId(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.mosaicMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.mosaicMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicMetadataTransactionBodyBytes = this.mosaicMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder.ts new file mode 100644 index 0000000000..6f66b59522 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder.ts @@ -0,0 +1,120 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicSupplyChangeActionDto } from './MosaicSupplyChangeActionDto'; +import { MosaicSupplyChangeTransactionBodyBuilder } from './MosaicSupplyChangeTransactionBodyBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an embedded mosaic supply change transaction. */ +export class EmbeddedMosaicSupplyChangeTransactionBuilder extends EmbeddedTransactionBuilder { + /** Mosaic supply change transaction body. */ + mosaicSupplyChangeTransactionBody: MosaicSupplyChangeTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaicId Affected mosaic identifier. + * @param action Supply change action. + * @param delta Change amount. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaicId: UnresolvedMosaicIdDto, action: MosaicSupplyChangeActionDto, delta: AmountDto) { + super(signer, version, type); + this.mosaicSupplyChangeTransactionBody = new MosaicSupplyChangeTransactionBodyBuilder(mosaicId, action, delta); + } + + /** + * Creates an instance of EmbeddedMosaicSupplyChangeTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMosaicSupplyChangeTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMosaicSupplyChangeTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicSupplyChangeTransactionBody = MosaicSupplyChangeTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicSupplyChangeTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMosaicSupplyChangeTransactionBuilder(superObject.signer, superObject.version, superObject.type, mosaicSupplyChangeTransactionBody.mosaicId, mosaicSupplyChangeTransactionBody.action, mosaicSupplyChangeTransactionBody.delta); + } + + /** + * Gets affected mosaic identifier. + * + * @return Affected mosaic identifier. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicSupplyChangeTransactionBody.getMosaicId(); + } + + /** + * Gets supply change action. + * + * @return Supply change action. + */ + public getAction(): MosaicSupplyChangeActionDto { + return this.mosaicSupplyChangeTransactionBody.getAction(); + } + + /** + * Gets change amount. + * + * @return Change amount. + */ + public getDelta(): AmountDto { + return this.mosaicSupplyChangeTransactionBody.getDelta(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicSupplyChangeTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicSupplyChangeTransactionBodyBytes = this.mosaicSupplyChangeTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicSupplyChangeTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder.ts new file mode 100644 index 0000000000..b2de331994 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder.ts @@ -0,0 +1,119 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { CosignatoryModificationBuilder } from './CosignatoryModificationBuilder'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MultisigAccountModificationTransactionBodyBuilder } from './MultisigAccountModificationTransactionBodyBuilder'; + +/** Binary layout for an embedded multisig account modification transaction. */ +export class EmbeddedMultisigAccountModificationTransactionBuilder extends EmbeddedTransactionBuilder { + /** Multisig account modification transaction body. */ + multisigAccountModificationTransactionBody: MultisigAccountModificationTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param minRemovalDelta Relative change of the minimal number of cosignatories required when removing an account. + * @param minApprovalDelta Relative change of the minimal number of cosignatories required when approving a transaction. + * @param modifications Attached cosignatory modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, minRemovalDelta: number, minApprovalDelta: number, modifications: CosignatoryModificationBuilder[]) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.multisigAccountModificationTransactionBody = new MultisigAccountModificationTransactionBodyBuilder(minRemovalDelta, minApprovalDelta, modifications); + } + + /** + * Creates an instance of EmbeddedMultisigAccountModificationTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedMultisigAccountModificationTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedMultisigAccountModificationTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const multisigAccountModificationTransactionBody = MultisigAccountModificationTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, multisigAccountModificationTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedMultisigAccountModificationTransactionBuilder(superObject.signer, superObject.version, superObject.type, multisigAccountModificationTransactionBody.minRemovalDelta, multisigAccountModificationTransactionBody.minApprovalDelta, multisigAccountModificationTransactionBody.modifications); + } + + /** + * Gets relative change of the minimal number of cosignatories required when removing an account. + * + * @return Relative change of the minimal number of cosignatories required when removing an account. + */ + public getMinRemovalDelta(): number { + return this.multisigAccountModificationTransactionBody.getMinRemovalDelta(); + } + + /** + * Gets relative change of the minimal number of cosignatories required when approving a transaction. + * + * @return Relative change of the minimal number of cosignatories required when approving a transaction. + */ + public getMinApprovalDelta(): number { + return this.multisigAccountModificationTransactionBody.getMinApprovalDelta(); + } + + /** + * Gets attached cosignatory modifications. + * + * @return Attached cosignatory modifications. + */ + public getModifications(): CosignatoryModificationBuilder[] { + return this.multisigAccountModificationTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.multisigAccountModificationTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const multisigAccountModificationTransactionBodyBytes = this.multisigAccountModificationTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, multisigAccountModificationTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..1d4bbe606c --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder.ts @@ -0,0 +1,145 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceMetadataTransactionBodyBuilder } from './NamespaceMetadataTransactionBodyBuilder'; + +/** Binary layout for an embedded namespace metadata transaction. */ +export class EmbeddedNamespaceMetadataTransactionBuilder extends EmbeddedTransactionBuilder { + /** Namespace metadata transaction body. */ + namespaceMetadataTransactionBody: NamespaceMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetNamespaceId Target namespace identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], targetNamespaceId: NamespaceIdDto, valueSizeDelta: number, value: Uint8Array) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.namespaceMetadataTransactionBody = new NamespaceMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetNamespaceId, valueSizeDelta, value); + } + + /** + * Creates an instance of EmbeddedNamespaceMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedNamespaceMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedNamespaceMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const namespaceMetadataTransactionBody = NamespaceMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedNamespaceMetadataTransactionBuilder(superObject.signer, superObject.version, superObject.type, namespaceMetadataTransactionBody.targetPublicKey, namespaceMetadataTransactionBody.scopedMetadataKey, namespaceMetadataTransactionBody.targetNamespaceId, namespaceMetadataTransactionBody.valueSizeDelta, namespaceMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.namespaceMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.namespaceMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets target namespace identifier. + * + * @return Target namespace identifier. + */ + public getTargetNamespaceId(): NamespaceIdDto { + return this.namespaceMetadataTransactionBody.getTargetNamespaceId(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.namespaceMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.namespaceMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.namespaceMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const namespaceMetadataTransactionBodyBytes = this.namespaceMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder.ts new file mode 100644 index 0000000000..29d51b3fb1 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder.ts @@ -0,0 +1,143 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceRegistrationTransactionBodyBuilder } from './NamespaceRegistrationTransactionBodyBuilder'; +import { NamespaceRegistrationTypeDto } from './NamespaceRegistrationTypeDto'; + +/** Binary layout for an embedded namespace registration transaction. */ +export class EmbeddedNamespaceRegistrationTransactionBuilder extends EmbeddedTransactionBuilder { + /** Namespace registration transaction body. */ + namespaceRegistrationTransactionBody: NamespaceRegistrationTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param duration Namespace duration. + * @param parentId Parent namespace identifier. + * @param id Namespace identifier. + * @param name Namespace name. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, id: NamespaceIdDto, name: Uint8Array, duration?: BlockDurationDto, parentId?: NamespaceIdDto) { + super(signer, version, type); + if ((duration && parentId) || (!duration && !parentId)) { + throw new Error('Invalid conditional parameters'); + } + // tslint:disable-next-line: max-line-length + this.namespaceRegistrationTransactionBody = new NamespaceRegistrationTransactionBodyBuilder(id, name, duration, parentId); + } + + /** + * Creates an instance of EmbeddedNamespaceRegistrationTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedNamespaceRegistrationTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedNamespaceRegistrationTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const namespaceRegistrationTransactionBody = NamespaceRegistrationTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceRegistrationTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedNamespaceRegistrationTransactionBuilder(superObject.signer, superObject.version, superObject.type, namespaceRegistrationTransactionBody.id, namespaceRegistrationTransactionBody.name, namespaceRegistrationTransactionBody.duration, namespaceRegistrationTransactionBody.parentId); + } + + /** + * Gets namespace registration type. + * + * @return Namespace registration type. + */ + public getRegistrationType(): NamespaceRegistrationTypeDto { + return this.namespaceRegistrationTransactionBody.getRegistrationType(); + } + + /** + * Gets namespace duration. + * + * @return Namespace duration. + */ + public getDuration(): BlockDurationDto | undefined { + return this.namespaceRegistrationTransactionBody.getDuration(); + } + + /** + * Gets parent namespace identifier. + * + * @return Parent namespace identifier. + */ + public getParentId(): NamespaceIdDto | undefined { + return this.namespaceRegistrationTransactionBody.getParentId(); + } + + /** + * Gets namespace identifier. + * + * @return Namespace identifier. + */ + public getId(): NamespaceIdDto { + return this.namespaceRegistrationTransactionBody.getId(); + } + + /** + * Gets namespace name. + * + * @return Namespace name. + */ + public getName(): Uint8Array { + return this.namespaceRegistrationTransactionBody.getName(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.namespaceRegistrationTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const namespaceRegistrationTransactionBodyBytes = this.namespaceRegistrationTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceRegistrationTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder.ts new file mode 100644 index 0000000000..e8f4c80213 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder.ts @@ -0,0 +1,142 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { KeyDto } from './KeyDto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { SecretLockTransactionBodyBuilder } from './SecretLockTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for an embedded secret lock transaction. */ +export class EmbeddedSecretLockTransactionBuilder extends EmbeddedTransactionBuilder { + /** Secret lock transaction body. */ + secretLockTransactionBody: SecretLockTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param mosaic Locked mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Locked mosaic recipient. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto) { + super(signer, version, type); + // tslint:disable-next-line: max-line-length + this.secretLockTransactionBody = new SecretLockTransactionBodyBuilder(mosaic, duration, hashAlgorithm, secret, recipient); + } + + /** + * Creates an instance of EmbeddedSecretLockTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedSecretLockTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedSecretLockTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const secretLockTransactionBody = SecretLockTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secretLockTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedSecretLockTransactionBuilder(superObject.signer, superObject.version, superObject.type, secretLockTransactionBody.mosaic, secretLockTransactionBody.duration, secretLockTransactionBody.hashAlgorithm, secretLockTransactionBody.secret, secretLockTransactionBody.recipient); + } + + /** + * Gets locked mosaic. + * + * @return Locked mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.secretLockTransactionBody.getMosaic(); + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.secretLockTransactionBody.getDuration(); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.secretLockTransactionBody.getHashAlgorithm(); + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secretLockTransactionBody.getSecret(); + } + + /** + * Gets locked mosaic recipient. + * + * @return Locked mosaic recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.secretLockTransactionBody.getRecipient(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.secretLockTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const secretLockTransactionBodyBytes = this.secretLockTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretLockTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder.ts new file mode 100644 index 0000000000..58d0df9188 --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder.ts @@ -0,0 +1,129 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { KeyDto } from './KeyDto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { SecretProofTransactionBodyBuilder } from './SecretProofTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; + +/** Binary layout for an embedded secret proof transaction. */ +export class EmbeddedSecretProofTransactionBuilder extends EmbeddedTransactionBuilder { + /** Secret proof transaction body. */ + secretProofTransactionBody: SecretProofTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Recipient. + * @param proof Proof data. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto, proof: Uint8Array) { + super(signer, version, type); + this.secretProofTransactionBody = new SecretProofTransactionBodyBuilder(hashAlgorithm, secret, recipient, proof); + } + + /** + * Creates an instance of EmbeddedSecretProofTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedSecretProofTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedSecretProofTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const secretProofTransactionBody = SecretProofTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secretProofTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedSecretProofTransactionBuilder(superObject.signer, superObject.version, superObject.type, secretProofTransactionBody.hashAlgorithm, secretProofTransactionBody.secret, secretProofTransactionBody.recipient, secretProofTransactionBody.proof); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.secretProofTransactionBody.getHashAlgorithm(); + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secretProofTransactionBody.getSecret(); + } + + /** + * Gets recipient. + * + * @return Recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.secretProofTransactionBody.getRecipient(); + } + + /** + * Gets proof data. + * + * @return Proof data. + */ + public getProof(): Uint8Array { + return this.secretProofTransactionBody.getProof(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.secretProofTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const secretProofTransactionBodyBytes = this.secretProofTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretProofTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedTransactionBuilder.ts new file mode 100644 index 0000000000..836a8cda5d --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedTransactionBuilder.ts @@ -0,0 +1,127 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; + +/** Binary layout for an embedded transaction. */ +export class EmbeddedTransactionBuilder { + /** Entity size. */ + size = 0; + /** Entity signer's public key. */ + signer: KeyDto; + /** Entity version. */ + version: number; + /** Entity type. */ + type: EntityTypeDto; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + */ + public constructor(signer: KeyDto, version: number, type: EntityTypeDto) { + this.signer = signer; + this.version = version; + this.type = type; + } + + /** + * Creates an instance of EmbeddedTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedTransactionBuilder { + const byteArray = Array.from(payload); + const size = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signer.getSize()); + const version = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const type = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + return new EmbeddedTransactionBuilder(signer, version, type); + } + + /** + * Gets entity signer's public key. + * + * @return Entity signer's public key. + */ + public getSigner(): KeyDto { + return this.signer; + } + + /** + * Gets entity version. + * + * @return Entity version. + */ + public getVersion(): number { + return this.version; + } + + /** + * Gets entity type. + * + * @return Entity type. + */ + public getType(): EntityTypeDto { + return this.type; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 4; // size + size += this.signer.getSize(); + size += 2; // version + size += 2; // type + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const sizeBytes = GeneratorUtils.uintToBuffer(this.getSize(), 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, sizeBytes); + const signerBytes = this.signer.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); + const versionBytes = GeneratorUtils.uintToBuffer(this.getVersion(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, versionBytes); + const typeBytes = GeneratorUtils.uintToBuffer(this.type, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, typeBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EmbeddedTransferTransactionBuilder.ts b/src/infrastructure/catbuffer/EmbeddedTransferTransactionBuilder.ts new file mode 100644 index 0000000000..f4402345ef --- /dev/null +++ b/src/infrastructure/catbuffer/EmbeddedTransferTransactionBuilder.ts @@ -0,0 +1,118 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { EmbeddedTransactionBuilder } from './EmbeddedTransactionBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { TransferTransactionBodyBuilder } from './TransferTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for an embedded transfer transaction. */ +export class EmbeddedTransferTransactionBuilder extends EmbeddedTransactionBuilder { + /** Transfer transaction body. */ + transferTransactionBody: TransferTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param recipient Transaction recipient. + * @param message Transaction message. + * @param mosaics Attached mosaics. + */ + // tslint:disable-next-line: max-line-length + public constructor(signer: KeyDto, version: number, type: EntityTypeDto, recipient: UnresolvedAddressDto, message: Uint8Array, mosaics: UnresolvedMosaicBuilder[]) { + super(signer, version, type); + this.transferTransactionBody = new TransferTransactionBodyBuilder(recipient, message, mosaics); + } + + /** + * Creates an instance of EmbeddedTransferTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of EmbeddedTransferTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): EmbeddedTransferTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = EmbeddedTransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const transferTransactionBody = TransferTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, transferTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new EmbeddedTransferTransactionBuilder(superObject.signer, superObject.version, superObject.type, transferTransactionBody.recipient, transferTransactionBody.message, transferTransactionBody.mosaics); + } + + /** + * Gets transaction recipient. + * + * @return Transaction recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.transferTransactionBody.getRecipient(); + } + + /** + * Gets transaction message. + * + * @return Transaction message. + */ + public getMessage(): Uint8Array { + return this.transferTransactionBody.getMessage(); + } + + /** + * Gets attached mosaics. + * + * @return Attached mosaics. + */ + public getMosaics(): UnresolvedMosaicBuilder[] { + return this.transferTransactionBody.getMosaics(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.transferTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const transferTransactionBodyBytes = this.transferTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, transferTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/EntityTypeDto.ts b/src/infrastructure/catbuffer/EntityTypeDto.ts new file mode 100644 index 0000000000..52e1c55a94 --- /dev/null +++ b/src/infrastructure/catbuffer/EntityTypeDto.ts @@ -0,0 +1,133 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of entity types. */ +export enum EntityTypeDto { + /** Reserved entity type. */ + RESERVED = 0, + /** + * Transfer Transaction transaction type. + * @type {number} + */ + TRANSFER = 0x4154, + + /** + * Register namespace transaction type. + * @type {number} + */ + REGISTER_NAMESPACE = 0x414E, + + /** + * Address alias transaction type + * @type {number} + */ + ADDRESS_ALIAS = 0x424E, + + /** + * Mosaic alias transaction type + * @type {number} + */ + MOSAIC_ALIAS = 0x434E, + + /** + * Mosaic definition transaction type. + * @type {number} + */ + MOSAIC_DEFINITION = 0x414D, + + /** + * Mosaic supply change transaction. + * @type {number} + */ + MOSAIC_SUPPLY_CHANGE = 0x424D, + + /** + * Modify multisig account transaction type. + * @type {number} + */ + MODIFY_MULTISIG_ACCOUNT = 0x4155, + + /** + * Aggregate complete transaction type. + * @type {number} + */ + AGGREGATE_COMPLETE = 0x4141, + + /** + * Aggregate bonded transaction type + */ + AGGREGATE_BONDED = 0x4241, + + /** + * Lock transaction type + * @type {number} + */ + LOCK = 0x4148, + + /** + * Secret Lock Transaction type + * @type {number} + */ + SECRET_LOCK = 0x4152, + + /** + * Secret Proof transaction type + * @type {number} + */ + SECRET_PROOF = 0x4252, + + /** + * Account restriction address transaction type + * @type {number} + */ + ACCOUNT_RESTRICTION_ADDRESS = 0x4150, + + /** + * Account restriction mosaic transaction type + * @type {number} + */ + ACCOUNT_RESTRICTION_MOSAIC = 0x4250, + + /** + * Account restriction operation transaction type + * @type {number} + */ + ACCOUNT_RESTRICTION_OPERATION = 0x4350, + + /** + * Link account transaction type + * @type {number} + */ + LINK_ACCOUNT = 0x414C, + + /** + * Mosaic address restriction type + * @type {number} + */ + MOSAIC_ADDRESS_RESTRICTION = 0x4251, + + /** + * Mosaic global restriction type + * @type {number} + */ + MOSAIC_GLOBAL_RESTRICTION = 0x4151, +} diff --git a/src/infrastructure/catbuffer/GeneratorUtils.ts b/src/infrastructure/catbuffer/GeneratorUtils.ts new file mode 100644 index 0000000000..437c32d117 --- /dev/null +++ b/src/infrastructure/catbuffer/GeneratorUtils.ts @@ -0,0 +1,141 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +/** + * Generator utility class. + */ +export class GeneratorUtils { + + /** + * Converts a (64bit) uint8 array into a number array. + * @param {Uint8Array} input A uint8 array. + * @returns {number[]} The uint64 representation of the input. + */ + public static bufferToUint64 (input: Uint8Array): number[] { + if (8 !== input.length) { + throw Error(`byte array has unexpected size '${input.length}'`); + } + input = input.reverse(); + return [GeneratorUtils.readUint32At(input, 0), GeneratorUtils.readUint32At(input, 4)]; + } + + /** + * Read buffer into 32bits integer at given index. + * @param {Uint8Array} bytes A uint8 array. + * @param {number} index Index. + * @returns {number} 32bits integer. + */ + public static readUint32At(bytes: Uint8Array, index: number): number { + return (bytes[index] + (bytes[index + 1] << 8) + (bytes[index + 2] << 16) + (bytes[index + 3] << 24)) >>> 0; + } + + /** + * Write uint to buffer + * @param {number} uintValue A uint8 array. + * @param {number} bufferSize Buffer size. + * @returns {Uint8Array} + */ + public static uintToBuffer (uintValue: number, bufferSize: number): Uint8Array { + const buffer = new ArrayBuffer(bufferSize); + const dataView = new DataView(buffer); + if (1 === bufferSize) + dataView.setUint8(0, uintValue); + + else if (2 === bufferSize) + dataView.setUint16(0, uintValue, true); + + else if (4 === bufferSize) + dataView.setUint32(0, uintValue, true); + + else + throw new Error('Unexpected bufferSize'); + + return new Uint8Array(buffer); + } + + /** + * Write uint to buffer + * @param {Uint8Array} buffer A uint8 array. + * @returns {number} + */ + public static bufferToUint(buffer: Uint8Array): number { + const dataView = new DataView(buffer.buffer); + if (1 === buffer.byteLength) + return dataView.getUint8(0); + + else if (2 === buffer.byteLength) + return dataView.getUint16(0, true); + + else if (4 === buffer.byteLength) + return dataView.getUint32(0, true); + + throw new Error('Unexpected buffer size'); + }; + + /** + * Write Uint64 to buffer + * @param {number} uintValue Uint64 (number[]). + * @returns {Uint8Array} + */ + public static uint64ToBuffer(uintValue: number[]): Uint8Array { + const uint32Array = new Uint32Array(uintValue); + return new Uint8Array(uint32Array.buffer); + } + + /** + * Concatenate two arrays + * @param {Uint8Array} array1 A Uint8Array. + * @param {Uint8Array} array2 A Uint8Array. + * @returns {Uint8Array} + */ + public static concatTypedArrays(array1: Uint8Array, array2: Uint8Array): Uint8Array { + const newArray = new Uint8Array(array1.length + array2.length); + newArray.set(array1); + newArray.set(array2, array1.length); + return newArray; + } + + /** Converts an unsigned byte to a signed byte with the same binary representation. + * @param {number} input An unsigned byte. + * @returns {number} A signed byte with the same binary representation as the input. + * + */ + public static uint8ToInt8 = (input: number): number => { + if (0xFF < input) { + throw Error(`input '${input}' is out of range`); + } + return input << 24 >> 24; + } + + /** Get bytes by given sub array size. + * @param {Uint8Array} binary Binary bytes array. + * @param {number} size Subarray size. + * @returns {Uint8Array} + * + */ + public static getBytes(binary: Uint8Array, size: number): Uint8Array { + if (size > binary.length) + throw new RangeError(); + + const bytes = binary.slice(0, size); + return bytes; + } +} diff --git a/src/infrastructure/catbuffer/Hash256Dto.ts b/src/infrastructure/catbuffer/Hash256Dto.ts new file mode 100644 index 0000000000..0f09dfda19 --- /dev/null +++ b/src/infrastructure/catbuffer/Hash256Dto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Hash256. */ +export class Hash256Dto { + /** Hash256. */ + hash256: Uint8Array; + + /** + * Constructor. + * + * @param hash256 Hash256. + */ + constructor(hash256: Uint8Array) { + this.hash256 = hash256; + } + + /** + * Creates an instance of Hash256Dto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of Hash256Dto. + */ + public static loadFromBinary(payload: Uint8Array): Hash256Dto { + const byteArray = Array.from(payload); + const hash256 = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 32); + byteArray.splice(0, 32); + return new Hash256Dto(hash256); + } + + /** + * Gets Hash256. + * + * @return Hash256. + */ + public getHash256(): Uint8Array { + return this.hash256; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 32; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.hash256); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/Hash512Dto.ts b/src/infrastructure/catbuffer/Hash512Dto.ts new file mode 100644 index 0000000000..1455eb7623 --- /dev/null +++ b/src/infrastructure/catbuffer/Hash512Dto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Hash512. */ +export class Hash512Dto { + /** Hash512. */ + hash512: Uint8Array; + + /** + * Constructor. + * + * @param hash512 Hash512. + */ + constructor(hash512: Uint8Array) { + this.hash512 = hash512; + } + + /** + * Creates an instance of Hash512Dto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of Hash512Dto. + */ + public static loadFromBinary(payload: Uint8Array): Hash512Dto { + const byteArray = Array.from(payload); + const hash512 = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 64); + byteArray.splice(0, 64); + return new Hash512Dto(hash512); + } + + /** + * Gets Hash512. + * + * @return Hash512. + */ + public getHash512(): Uint8Array { + return this.hash512; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 64; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.hash512); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/HashLockTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/HashLockTransactionBodyBuilder.ts new file mode 100644 index 0000000000..26d8158335 --- /dev/null +++ b/src/infrastructure/catbuffer/HashLockTransactionBodyBuilder.ts @@ -0,0 +1,121 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a hash lock transaction. */ +export class HashLockTransactionBodyBuilder { + /** Lock mosaic. */ + mosaic: UnresolvedMosaicBuilder; + /** Number of blocks for which a lock should be valid. */ + duration: BlockDurationDto; + /** Lock hash. */ + hash: Hash256Dto; + + /** + * Constructor. + * + * @param mosaic Lock mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hash Lock hash. + */ + public constructor(mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hash: Hash256Dto) { + this.mosaic = mosaic; + this.duration = duration; + this.hash = hash; + } + + /** + * Creates an instance of HashLockTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of HashLockTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): HashLockTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaic = UnresolvedMosaicBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaic.getSize()); + const duration = BlockDurationDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, duration.getSize()); + const hash = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, hash.getSize()); + return new HashLockTransactionBodyBuilder(mosaic, duration, hash); + } + + /** + * Gets lock mosaic. + * + * @return Lock mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.mosaic; + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.duration; + } + + /** + * Gets lock hash. + * + * @return Lock hash. + */ + public getHash(): Hash256Dto { + return this.hash; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaic.getSize(); + size += this.duration.getSize(); + size += this.hash.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicBytes = this.mosaic.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicBytes); + const durationBytes = this.duration.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, durationBytes); + const hashBytes = this.hash.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/HashLockTransactionBuilder.ts b/src/infrastructure/catbuffer/HashLockTransactionBuilder.ts new file mode 100644 index 0000000000..b6c5b9643f --- /dev/null +++ b/src/infrastructure/catbuffer/HashLockTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { BlockDurationDto } from './BlockDurationDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { HashLockTransactionBodyBuilder } from './HashLockTransactionBodyBuilder'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a non-embedded hash lock transaction. */ +export class HashLockTransactionBuilder extends TransactionBuilder { + /** Hash lock transaction body. */ + hashLockTransactionBody: HashLockTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaic Lock mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hash Lock hash. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hash: Hash256Dto) { + super(signature, signer, version, type, fee, deadline); + this.hashLockTransactionBody = new HashLockTransactionBodyBuilder(mosaic, duration, hash); + } + + /** + * Creates an instance of HashLockTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of HashLockTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): HashLockTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const hashLockTransactionBody = HashLockTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, hashLockTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new HashLockTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, hashLockTransactionBody.mosaic, hashLockTransactionBody.duration, hashLockTransactionBody.hash); + } + + /** + * Gets lock mosaic. + * + * @return Lock mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.hashLockTransactionBody.getMosaic(); + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.hashLockTransactionBody.getDuration(); + } + + /** + * Gets lock hash. + * + * @return Lock hash. + */ + public getHash(): Hash256Dto { + return this.hashLockTransactionBody.getHash(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.hashLockTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const hashLockTransactionBodyBytes = this.hashLockTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashLockTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/KeyDto.ts b/src/infrastructure/catbuffer/KeyDto.ts new file mode 100644 index 0000000000..ea1fb55242 --- /dev/null +++ b/src/infrastructure/catbuffer/KeyDto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Key. */ +export class KeyDto { + /** Key. */ + key: Uint8Array; + + /** + * Constructor. + * + * @param key Key. + */ + constructor(key: Uint8Array) { + this.key = key; + } + + /** + * Creates an instance of KeyDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of KeyDto. + */ + public static loadFromBinary(payload: Uint8Array): KeyDto { + const byteArray = Array.from(payload); + const key = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 32); + byteArray.splice(0, 32); + return new KeyDto(key); + } + + /** + * Gets Key. + * + * @return Key. + */ + public getKey(): Uint8Array { + return this.key; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 32; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.key); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/LockHashAlgorithmDto.ts b/src/infrastructure/catbuffer/LockHashAlgorithmDto.ts new file mode 100644 index 0000000000..46ed416098 --- /dev/null +++ b/src/infrastructure/catbuffer/LockHashAlgorithmDto.ts @@ -0,0 +1,33 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of lock hash algorithms. */ +export enum LockHashAlgorithmDto { + /** Input is hashed using sha-3 256. */ + SHA3_256 = 0, + /** Input is hashed using keccak 256. */ + KECCAK_256 = 1, + /** Input is hashed twice: first with sha-256 and then with ripemd-160 (bitcoin's OP_HASH160). */ + HASH_160 = 2, + /** Input is hashed twice with sha-256 (bitcoin's OP_HASH256). */ + HASH_256 = 3, +} diff --git a/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..2572bae2f0 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,158 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a mosaic address restriction transaction. */ +export class MosaicAddressRestrictionTransactionBodyBuilder { + /** Identifier of the mosaic to which the restriction applies. */ + mosaicId: UnresolvedMosaicIdDto; + /** Restriction key. */ + restrictionKey: number[]; + /** Address being restricted. */ + targetAddress: UnresolvedAddressDto; + /** Previous restriction value. */ + previousRestrictionValue: number[]; + /** New restriction value. */ + newRestrictionValue: number[]; + + /** + * Constructor. + * + * @param mosaicId Identifier of the mosaic to which the restriction applies. + * @param restrictionKey Restriction key. + * @param targetAddress Address being restricted. + * @param previousRestrictionValue Previous restriction value. + * @param newRestrictionValue New restriction value. + */ + // tslint:disable-next-line: max-line-length + public constructor(mosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], targetAddress: UnresolvedAddressDto, previousRestrictionValue: number[], newRestrictionValue: number[]) { + this.mosaicId = mosaicId; + this.restrictionKey = restrictionKey; + this.targetAddress = targetAddress; + this.previousRestrictionValue = previousRestrictionValue; + this.newRestrictionValue = newRestrictionValue; + } + + /** + * Creates an instance of MosaicAddressRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicAddressRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicAddressRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const restrictionKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const targetAddress = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetAddress.getSize()); + const previousRestrictionValue = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const newRestrictionValue = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + // tslint:disable-next-line: max-line-length + return new MosaicAddressRestrictionTransactionBodyBuilder(mosaicId, restrictionKey, targetAddress, previousRestrictionValue, newRestrictionValue); + } + + /** + * Gets identifier of the mosaic to which the restriction applies. + * + * @return Identifier of the mosaic to which the restriction applies. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicId; + } + + /** + * Gets restriction key. + * + * @return Restriction key. + */ + public getRestrictionKey(): number[] { + return this.restrictionKey; + } + + /** + * Gets address being restricted. + * + * @return Address being restricted. + */ + public getTargetAddress(): UnresolvedAddressDto { + return this.targetAddress; + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.previousRestrictionValue; + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.newRestrictionValue; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += 8; // restrictionKey + size += this.targetAddress.getSize(); + size += 8; // previousRestrictionValue + size += 8; // newRestrictionValue + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const restrictionKeyBytes = GeneratorUtils.uint64ToBuffer(this.getRestrictionKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionKeyBytes); + const targetAddressBytes = this.targetAddress.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetAddressBytes); + const previousRestrictionValueBytes = GeneratorUtils.uint64ToBuffer(this.getPreviousRestrictionValue()); + newArray = GeneratorUtils.concatTypedArrays(newArray, previousRestrictionValueBytes); + const newRestrictionValueBytes = GeneratorUtils.uint64ToBuffer(this.getNewRestrictionValue()); + newArray = GeneratorUtils.concatTypedArrays(newArray, newRestrictionValueBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..ba0d6b5d7e --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder.ts @@ -0,0 +1,146 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicAddressRestrictionTransactionBodyBuilder } from './MosaicAddressRestrictionTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a non-embedded mosaic address restriction transaction. */ +export class MosaicAddressRestrictionTransactionBuilder extends TransactionBuilder { + /** Mosaic address restriction transaction body. */ + mosaicAddressRestrictionTransactionBody: MosaicAddressRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaicId Identifier of the mosaic to which the restriction applies. + * @param restrictionKey Restriction key. + * @param targetAddress Address being restricted. + * @param previousRestrictionValue Previous restriction value. + * @param newRestrictionValue New restriction value. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], targetAddress: UnresolvedAddressDto, previousRestrictionValue: number[], newRestrictionValue: number[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.mosaicAddressRestrictionTransactionBody = new MosaicAddressRestrictionTransactionBodyBuilder(mosaicId, restrictionKey, targetAddress, previousRestrictionValue, newRestrictionValue); + } + + /** + * Creates an instance of MosaicAddressRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicAddressRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicAddressRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicAddressRestrictionTransactionBody = MosaicAddressRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicAddressRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicAddressRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicAddressRestrictionTransactionBody.mosaicId, mosaicAddressRestrictionTransactionBody.restrictionKey, mosaicAddressRestrictionTransactionBody.targetAddress, mosaicAddressRestrictionTransactionBody.previousRestrictionValue, mosaicAddressRestrictionTransactionBody.newRestrictionValue); + } + + /** + * Gets identifier of the mosaic to which the restriction applies. + * + * @return Identifier of the mosaic to which the restriction applies. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicAddressRestrictionTransactionBody.getMosaicId(); + } + + /** + * Gets restriction key. + * + * @return Restriction key. + */ + public getRestrictionKey(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getRestrictionKey(); + } + + /** + * Gets address being restricted. + * + * @return Address being restricted. + */ + public getTargetAddress(): UnresolvedAddressDto { + return this.mosaicAddressRestrictionTransactionBody.getTargetAddress(); + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getPreviousRestrictionValue(); + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.mosaicAddressRestrictionTransactionBody.getNewRestrictionValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicAddressRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicAddressRestrictionTransactionBodyBytes = this.mosaicAddressRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicAddressRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicAliasTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicAliasTransactionBodyBuilder.ts new file mode 100644 index 0000000000..6c411a6ecb --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicAliasTransactionBodyBuilder.ts @@ -0,0 +1,121 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AliasActionDto } from './AliasActionDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicIdDto } from './MosaicIdDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for an mosaic alias transaction. */ +export class MosaicAliasTransactionBodyBuilder { + /** Alias action. */ + aliasAction: AliasActionDto; + /** Identifier of the namespace that will become an alias. */ + namespaceId: NamespaceIdDto; + /** Aliased mosaic identifier. */ + mosaicId: MosaicIdDto; + + /** + * Constructor. + * + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param mosaicId Aliased mosaic identifier. + */ + public constructor(aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, mosaicId: MosaicIdDto) { + this.aliasAction = aliasAction; + this.namespaceId = namespaceId; + this.mosaicId = mosaicId; + } + + /** + * Creates an instance of MosaicAliasTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicAliasTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicAliasTransactionBodyBuilder { + const byteArray = Array.from(payload); + const aliasAction = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const namespaceId = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceId.getSize()); + const mosaicId = MosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + return new MosaicAliasTransactionBodyBuilder(aliasAction, namespaceId, mosaicId); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.aliasAction; + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.namespaceId; + } + + /** + * Gets aliased mosaic identifier. + * + * @return Aliased mosaic identifier. + */ + public getMosaicId(): MosaicIdDto { + return this.mosaicId; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // aliasAction + size += this.namespaceId.getSize(); + size += this.mosaicId.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const aliasActionBytes = GeneratorUtils.uintToBuffer(this.aliasAction, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, aliasActionBytes); + const namespaceIdBytes = this.namespaceId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceIdBytes); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicAliasTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicAliasTransactionBuilder.ts new file mode 100644 index 0000000000..d126fef24c --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicAliasTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AliasActionDto } from './AliasActionDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicAliasTransactionBodyBuilder } from './MosaicAliasTransactionBodyBuilder'; +import { MosaicIdDto } from './MosaicIdDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded mosaic alias transaction. */ +export class MosaicAliasTransactionBuilder extends TransactionBuilder { + /** Mosaic alias transaction body. */ + mosaicAliasTransactionBody: MosaicAliasTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param aliasAction Alias action. + * @param namespaceId Identifier of the namespace that will become an alias. + * @param mosaicId Aliased mosaic identifier. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, aliasAction: AliasActionDto, namespaceId: NamespaceIdDto, mosaicId: MosaicIdDto) { + super(signature, signer, version, type, fee, deadline); + this.mosaicAliasTransactionBody = new MosaicAliasTransactionBodyBuilder(aliasAction, namespaceId, mosaicId); + } + + /** + * Creates an instance of MosaicAliasTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicAliasTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicAliasTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const mosaicAliasTransactionBody = MosaicAliasTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicAliasTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicAliasTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicAliasTransactionBody.aliasAction, mosaicAliasTransactionBody.namespaceId, mosaicAliasTransactionBody.mosaicId); + } + + /** + * Gets alias action. + * + * @return Alias action. + */ + public getAliasAction(): AliasActionDto { + return this.mosaicAliasTransactionBody.getAliasAction(); + } + + /** + * Gets identifier of the namespace that will become an alias. + * + * @return Identifier of the namespace that will become an alias. + */ + public getNamespaceId(): NamespaceIdDto { + return this.mosaicAliasTransactionBody.getNamespaceId(); + } + + /** + * Gets aliased mosaic identifier. + * + * @return Aliased mosaic identifier. + */ + public getMosaicId(): MosaicIdDto { + return this.mosaicAliasTransactionBody.getMosaicId(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicAliasTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicAliasTransactionBodyBytes = this.mosaicAliasTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicAliasTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicBuilder.ts b/src/infrastructure/catbuffer/MosaicBuilder.ts new file mode 100644 index 0000000000..dc2ac60e87 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicIdDto } from './MosaicIdDto'; + +/** Binary layout for a mosaic. */ +export class MosaicBuilder { + /** Mosaic identifier. */ + mosaicId: MosaicIdDto; + /** Mosaic amount. */ + amount: AmountDto; + + /** + * Constructor. + * + * @param mosaicId Mosaic identifier. + * @param amount Mosaic amount. + */ + public constructor(mosaicId: MosaicIdDto, amount: AmountDto) { + this.mosaicId = mosaicId; + this.amount = amount; + } + + /** + * Creates an instance of MosaicBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicBuilder { + const byteArray = Array.from(payload); + const mosaicId = MosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const amount = AmountDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, amount.getSize()); + return new MosaicBuilder(mosaicId, amount); + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getMosaicId(): MosaicIdDto { + return this.mosaicId; + } + + /** + * Gets mosaic amount. + * + * @return Mosaic amount. + */ + public getAmount(): AmountDto { + return this.amount; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += this.amount.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const amountBytes = this.amount.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, amountBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicDefinitionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicDefinitionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..b82254e5f7 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicDefinitionTransactionBodyBuilder.ts @@ -0,0 +1,158 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicIdDto } from './MosaicIdDto'; +import { MosaicNonceDto } from './MosaicNonceDto'; + +/** Binary layout for a mosaic definition transaction. */ +export class MosaicDefinitionTransactionBodyBuilder { + /** Mosaic nonce. */ + nonce: MosaicNonceDto; + /** Mosaic identifier. */ + id: MosaicIdDto; + /** Mosaic flags. */ + flags: number; + /** Mosaic divisibility. */ + divisibility: number; + /** Mosaic duration. */ + duration: BlockDurationDto; + + /** + * Constructor. + * + * @param nonce Mosaic nonce. + * @param id Mosaic identifier. + * @param flags Mosaic flags. + * @param divisibility Mosaic divisibility. + * @param duration Mosaic duration. + */ + // tslint:disable-next-line: max-line-length + public constructor(nonce: MosaicNonceDto, id: MosaicIdDto, flags: number, divisibility: number, duration: BlockDurationDto) { + this.nonce = nonce; + this.id = id; + this.flags = flags; + this.divisibility = divisibility; + this.duration = duration; + } + + /** + * Creates an instance of MosaicDefinitionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicDefinitionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicDefinitionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const nonce = MosaicNonceDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, nonce.getSize()); + const id = MosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, id.getSize()); + const flags = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const divisibility = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const duration = BlockDurationDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, duration.getSize()); + return new MosaicDefinitionTransactionBodyBuilder(nonce, id, flags, divisibility, duration); + } + + /** + * Gets mosaic nonce. + * + * @return Mosaic nonce. + */ + public getNonce(): MosaicNonceDto { + return this.nonce; + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getId(): MosaicIdDto { + return this.id; + } + + /** + * Gets mosaic flags. + * + * @return Mosaic flags. + */ + public getFlags(): number { + return this.flags; + } + + /** + * Gets mosaic divisibility. + * + * @return Mosaic divisibility. + */ + public getDivisibility(): number { + return this.divisibility; + } + + /** + * Gets mosaic duration. + * + * @return Mosaic duration. + */ + public getDuration(): BlockDurationDto { + return this.duration; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.nonce.getSize(); + size += this.id.getSize(); + size += 1; // flags + size += 1; // divisibility + size += this.duration.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const nonceBytes = this.nonce.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, nonceBytes); + const idBytes = this.id.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, idBytes); + const flagsBytes = GeneratorUtils.uintToBuffer(this.getFlags(), 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, flagsBytes); + const divisibilityBytes = GeneratorUtils.uintToBuffer(this.getDivisibility(), 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, divisibilityBytes); + const durationBytes = this.duration.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, durationBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicDefinitionTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicDefinitionTransactionBuilder.ts new file mode 100644 index 0000000000..a32b33b5d9 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicDefinitionTransactionBuilder.ts @@ -0,0 +1,147 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { BlockDurationDto } from './BlockDurationDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicDefinitionTransactionBodyBuilder } from './MosaicDefinitionTransactionBodyBuilder'; +import { MosaicIdDto } from './MosaicIdDto'; +import { MosaicNonceDto } from './MosaicNonceDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded mosaic definition transaction. */ +export class MosaicDefinitionTransactionBuilder extends TransactionBuilder { + /** Mosaic definition transaction body. */ + mosaicDefinitionTransactionBody: MosaicDefinitionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param nonce Mosaic nonce. + * @param id Mosaic identifier. + * @param flags Mosaic flags. + * @param divisibility Mosaic divisibility. + * @param duration Mosaic duration. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, nonce: MosaicNonceDto, id: MosaicIdDto, flags: number, divisibility: number, duration: BlockDurationDto) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.mosaicDefinitionTransactionBody = new MosaicDefinitionTransactionBodyBuilder(nonce, id, flags, divisibility, duration); + } + + /** + * Creates an instance of MosaicDefinitionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicDefinitionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicDefinitionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicDefinitionTransactionBody = MosaicDefinitionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicDefinitionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicDefinitionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicDefinitionTransactionBody.nonce, mosaicDefinitionTransactionBody.id, mosaicDefinitionTransactionBody.flags, mosaicDefinitionTransactionBody.divisibility, mosaicDefinitionTransactionBody.duration); + } + + /** + * Gets mosaic nonce. + * + * @return Mosaic nonce. + */ + public getNonce(): MosaicNonceDto { + return this.mosaicDefinitionTransactionBody.getNonce(); + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getId(): MosaicIdDto { + return this.mosaicDefinitionTransactionBody.getId(); + } + + /** + * Gets mosaic flags. + * + * @return Mosaic flags. + */ + public getFlags(): number { + return this.mosaicDefinitionTransactionBody.getFlags(); + } + + /** + * Gets mosaic divisibility. + * + * @return Mosaic divisibility. + */ + public getDivisibility(): number { + return this.mosaicDefinitionTransactionBody.getDivisibility(); + } + + /** + * Gets mosaic duration. + * + * @return Mosaic duration. + */ + public getDuration(): BlockDurationDto { + return this.mosaicDefinitionTransactionBody.getDuration(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicDefinitionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicDefinitionTransactionBodyBytes = this.mosaicDefinitionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicDefinitionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicFlagsDto.ts b/src/infrastructure/catbuffer/MosaicFlagsDto.ts new file mode 100644 index 0000000000..11a740ab03 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicFlagsDto.ts @@ -0,0 +1,33 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of mosaic property flags. */ +export enum MosaicFlagsDto { + /** No flags present. */ + NONE = 0, + /** Mosaic supports supply changes even when mosaic owner owns partial supply. */ + SUPPLY_MUTABLE = 1, + /** Mosaic supports transfers between arbitrary accounts \note when not set, mosaic can only be transferred to and from mosaic owner. */ + TRANSFERABLE = 2, + /** Mosaic supports custom restrictions configured by mosaic owner. */ + RESTRICTABLE = 4, +} diff --git a/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBodyBuilder.ts new file mode 100644 index 0000000000..09f3fd4e5e --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBodyBuilder.ts @@ -0,0 +1,194 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicRestrictionTypeDto } from './MosaicRestrictionTypeDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a mosaic global restriction transaction. */ +export class MosaicGlobalRestrictionTransactionBodyBuilder { + /** Identifier of the mosaic being restricted. */ + mosaicId: UnresolvedMosaicIdDto; + /** Identifier of the mosaic providing the restriction key. */ + referenceMosaicId: UnresolvedMosaicIdDto; + /** Restriction key relative to the reference mosaic identifier. */ + restrictionKey: number[]; + /** Previous restriction value. */ + previousRestrictionValue: number[]; + /** Previous restriction type. */ + previousRestrictionType: MosaicRestrictionTypeDto; + /** New restriction value. */ + newRestrictionValue: number[]; + /** New restriction type. */ + newRestrictionType: MosaicRestrictionTypeDto; + + /** + * Constructor. + * + * @param mosaicId Identifier of the mosaic being restricted. + * @param referenceMosaicId Identifier of the mosaic providing the restriction key. + * @param restrictionKey Restriction key relative to the reference mosaic identifier. + * @param previousRestrictionValue Previous restriction value. + * @param previousRestrictionType Previous restriction type. + * @param newRestrictionValue New restriction value. + * @param newRestrictionType New restriction type. + */ + // tslint:disable-next-line: max-line-length + public constructor(mosaicId: UnresolvedMosaicIdDto, referenceMosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], previousRestrictionValue: number[], previousRestrictionType: MosaicRestrictionTypeDto, newRestrictionValue: number[], newRestrictionType: MosaicRestrictionTypeDto) { + this.mosaicId = mosaicId; + this.referenceMosaicId = referenceMosaicId; + this.restrictionKey = restrictionKey; + this.previousRestrictionValue = previousRestrictionValue; + this.previousRestrictionType = previousRestrictionType; + this.newRestrictionValue = newRestrictionValue; + this.newRestrictionType = newRestrictionType; + } + + /** + * Creates an instance of MosaicGlobalRestrictionTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicGlobalRestrictionTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicGlobalRestrictionTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const referenceMosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, referenceMosaicId.getSize()); + const restrictionKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const previousRestrictionValue = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const previousRestrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const newRestrictionValue = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const newRestrictionType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + // tslint:disable-next-line: max-line-length + return new MosaicGlobalRestrictionTransactionBodyBuilder(mosaicId, referenceMosaicId, restrictionKey, previousRestrictionValue, previousRestrictionType, newRestrictionValue, newRestrictionType); + } + + /** + * Gets identifier of the mosaic being restricted. + * + * @return Identifier of the mosaic being restricted. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicId; + } + + /** + * Gets identifier of the mosaic providing the restriction key. + * + * @return Identifier of the mosaic providing the restriction key. + */ + public getReferenceMosaicId(): UnresolvedMosaicIdDto { + return this.referenceMosaicId; + } + + /** + * Gets restriction key relative to the reference mosaic identifier. + * + * @return Restriction key relative to the reference mosaic identifier. + */ + public getRestrictionKey(): number[] { + return this.restrictionKey; + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.previousRestrictionValue; + } + + /** + * Gets previous restriction type. + * + * @return Previous restriction type. + */ + public getPreviousRestrictionType(): MosaicRestrictionTypeDto { + return this.previousRestrictionType; + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.newRestrictionValue; + } + + /** + * Gets new restriction type. + * + * @return New restriction type. + */ + public getNewRestrictionType(): MosaicRestrictionTypeDto { + return this.newRestrictionType; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += this.referenceMosaicId.getSize(); + size += 8; // restrictionKey + size += 8; // previousRestrictionValue + size += 1; // previousRestrictionType + size += 8; // newRestrictionValue + size += 1; // newRestrictionType + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const referenceMosaicIdBytes = this.referenceMosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, referenceMosaicIdBytes); + const restrictionKeyBytes = GeneratorUtils.uint64ToBuffer(this.getRestrictionKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, restrictionKeyBytes); + const previousRestrictionValueBytes = GeneratorUtils.uint64ToBuffer(this.getPreviousRestrictionValue()); + newArray = GeneratorUtils.concatTypedArrays(newArray, previousRestrictionValueBytes); + const previousRestrictionTypeBytes = GeneratorUtils.uintToBuffer(this.previousRestrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, previousRestrictionTypeBytes); + const newRestrictionValueBytes = GeneratorUtils.uint64ToBuffer(this.getNewRestrictionValue()); + newArray = GeneratorUtils.concatTypedArrays(newArray, newRestrictionValueBytes); + const newRestrictionTypeBytes = GeneratorUtils.uintToBuffer(this.newRestrictionType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, newRestrictionTypeBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder.ts new file mode 100644 index 0000000000..e84414e6e2 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder.ts @@ -0,0 +1,166 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicGlobalRestrictionTransactionBodyBuilder } from './MosaicGlobalRestrictionTransactionBodyBuilder'; +import { MosaicRestrictionTypeDto } from './MosaicRestrictionTypeDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a non-embedded mosaic global restriction transaction. */ +export class MosaicGlobalRestrictionTransactionBuilder extends TransactionBuilder { + /** Mosaic global restriction transaction body. */ + mosaicGlobalRestrictionTransactionBody: MosaicGlobalRestrictionTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaicId Identifier of the mosaic being restricted. + * @param referenceMosaicId Identifier of the mosaic providing the restriction key. + * @param restrictionKey Restriction key relative to the reference mosaic identifier. + * @param previousRestrictionValue Previous restriction value. + * @param previousRestrictionType Previous restriction type. + * @param newRestrictionValue New restriction value. + * @param newRestrictionType New restriction type. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaicId: UnresolvedMosaicIdDto, referenceMosaicId: UnresolvedMosaicIdDto, restrictionKey: number[], previousRestrictionValue: number[], previousRestrictionType: MosaicRestrictionTypeDto, newRestrictionValue: number[], newRestrictionType: MosaicRestrictionTypeDto) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.mosaicGlobalRestrictionTransactionBody = new MosaicGlobalRestrictionTransactionBodyBuilder(mosaicId, referenceMosaicId, restrictionKey, previousRestrictionValue, previousRestrictionType, newRestrictionValue, newRestrictionType); + } + + /** + * Creates an instance of MosaicGlobalRestrictionTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicGlobalRestrictionTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicGlobalRestrictionTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicGlobalRestrictionTransactionBody = MosaicGlobalRestrictionTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicGlobalRestrictionTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicGlobalRestrictionTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicGlobalRestrictionTransactionBody.mosaicId, mosaicGlobalRestrictionTransactionBody.referenceMosaicId, mosaicGlobalRestrictionTransactionBody.restrictionKey, mosaicGlobalRestrictionTransactionBody.previousRestrictionValue, mosaicGlobalRestrictionTransactionBody.previousRestrictionType, mosaicGlobalRestrictionTransactionBody.newRestrictionValue, mosaicGlobalRestrictionTransactionBody.newRestrictionType); + } + + /** + * Gets identifier of the mosaic being restricted. + * + * @return Identifier of the mosaic being restricted. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicGlobalRestrictionTransactionBody.getMosaicId(); + } + + /** + * Gets identifier of the mosaic providing the restriction key. + * + * @return Identifier of the mosaic providing the restriction key. + */ + public getReferenceMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicGlobalRestrictionTransactionBody.getReferenceMosaicId(); + } + + /** + * Gets restriction key relative to the reference mosaic identifier. + * + * @return Restriction key relative to the reference mosaic identifier. + */ + public getRestrictionKey(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getRestrictionKey(); + } + + /** + * Gets previous restriction value. + * + * @return Previous restriction value. + */ + public getPreviousRestrictionValue(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getPreviousRestrictionValue(); + } + + /** + * Gets previous restriction type. + * + * @return Previous restriction type. + */ + public getPreviousRestrictionType(): MosaicRestrictionTypeDto { + return this.mosaicGlobalRestrictionTransactionBody.getPreviousRestrictionType(); + } + + /** + * Gets new restriction value. + * + * @return New restriction value. + */ + public getNewRestrictionValue(): number[] { + return this.mosaicGlobalRestrictionTransactionBody.getNewRestrictionValue(); + } + + /** + * Gets new restriction type. + * + * @return New restriction type. + */ + public getNewRestrictionType(): MosaicRestrictionTypeDto { + return this.mosaicGlobalRestrictionTransactionBody.getNewRestrictionType(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicGlobalRestrictionTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicGlobalRestrictionTransactionBodyBytes = this.mosaicGlobalRestrictionTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicGlobalRestrictionTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicIdDto.ts b/src/infrastructure/catbuffer/MosaicIdDto.ts new file mode 100644 index 0000000000..dd88e70b01 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicIdDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Mosaic id. */ +export class MosaicIdDto { + /** Mosaic id. */ + mosaicId: number[]; + + /** + * Constructor. + * + * @param mosaicId Mosaic id. + */ + constructor(mosaicId: number[]) { + this.mosaicId = mosaicId; + } + + /** + * Creates an instance of MosaicIdDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicIdDto. + */ + public static loadFromBinary(payload: Uint8Array): MosaicIdDto { + const byteArray = Array.from(payload); + const mosaicId = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new MosaicIdDto(mosaicId); + } + + /** + * Gets Mosaic id. + * + * @return Mosaic id. + */ + public getMosaicId(): number[] { + return this.mosaicId; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = GeneratorUtils.uint64ToBuffer(this.getMosaicId()); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicMetadataTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicMetadataTransactionBodyBuilder.ts new file mode 100644 index 0000000000..a4ee75bcbc --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicMetadataTransactionBodyBuilder.ts @@ -0,0 +1,168 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a mosaic metadata transaction. */ +export class MosaicMetadataTransactionBodyBuilder { + /** Metadata target public key. */ + targetPublicKey: KeyDto; + /** Metadata key scoped to source, target and type. */ + scopedMetadataKey: number[]; + /** Target mosaic identifier. */ + targetMosaicId: UnresolvedMosaicIdDto; + /** Change in value size in bytes. */ + valueSizeDelta: number; + /** Difference between existing value and new value \note when there is no existing value, new value is same this value \note when there is an existing value, new value is calculated as xor(previous-value, value). */ + value: Uint8Array; + + /** + * Constructor. + * + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetMosaicId Target mosaic identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(targetPublicKey: KeyDto, scopedMetadataKey: number[], targetMosaicId: UnresolvedMosaicIdDto, valueSizeDelta: number, value: Uint8Array) { + this.targetPublicKey = targetPublicKey; + this.scopedMetadataKey = scopedMetadataKey; + this.targetMosaicId = targetMosaicId; + this.valueSizeDelta = valueSizeDelta; + this.value = value; + } + + /** + * Creates an instance of MosaicMetadataTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicMetadataTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicMetadataTransactionBodyBuilder { + const byteArray = Array.from(payload); + const targetPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetPublicKey.getSize()); + const scopedMetadataKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const targetMosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetMosaicId.getSize()); + const valueSizeDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const valueSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const value = GeneratorUtils.getBytes(Uint8Array.from(byteArray), valueSize); + byteArray.splice(0, valueSize); + // tslint:disable-next-line: max-line-length + return new MosaicMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetMosaicId, valueSizeDelta, value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.targetPublicKey; + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.scopedMetadataKey; + } + + /** + * Gets target mosaic identifier. + * + * @return Target mosaic identifier. + */ + public getTargetMosaicId(): UnresolvedMosaicIdDto { + return this.targetMosaicId; + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.valueSizeDelta; + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.targetPublicKey.getSize(); + size += 8; // scopedMetadataKey + size += this.targetMosaicId.getSize(); + size += 2; // valueSizeDelta + size += 2; // valueSize + size += this.value.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const targetPublicKeyBytes = this.targetPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetPublicKeyBytes); + const scopedMetadataKeyBytes = GeneratorUtils.uint64ToBuffer(this.getScopedMetadataKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, scopedMetadataKeyBytes); + const targetMosaicIdBytes = this.targetMosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetMosaicIdBytes); + const valueSizeDeltaBytes = GeneratorUtils.uintToBuffer(this.getValueSizeDelta(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeDeltaBytes); + const valueSizeBytes = GeneratorUtils.uintToBuffer(this.value.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.value); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..1a5866a030 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicMetadataTransactionBuilder.ts @@ -0,0 +1,150 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicMetadataTransactionBodyBuilder } from './MosaicMetadataTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a non-embedded mosaic metadata transaction. */ +export class MosaicMetadataTransactionBuilder extends TransactionBuilder { + /** Mosaic metadata transaction body. */ + mosaicMetadataTransactionBody: MosaicMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetMosaicId Target mosaic identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], targetMosaicId: UnresolvedMosaicIdDto, valueSizeDelta: number, value: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.mosaicMetadataTransactionBody = new MosaicMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetMosaicId, valueSizeDelta, value); + } + + /** + * Creates an instance of MosaicMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const mosaicMetadataTransactionBody = MosaicMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicMetadataTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicMetadataTransactionBody.targetPublicKey, mosaicMetadataTransactionBody.scopedMetadataKey, mosaicMetadataTransactionBody.targetMosaicId, mosaicMetadataTransactionBody.valueSizeDelta, mosaicMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.mosaicMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.mosaicMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets target mosaic identifier. + * + * @return Target mosaic identifier. + */ + public getTargetMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicMetadataTransactionBody.getTargetMosaicId(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.mosaicMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.mosaicMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicMetadataTransactionBodyBytes = this.mosaicMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicNonceDto.ts b/src/infrastructure/catbuffer/MosaicNonceDto.ts new file mode 100644 index 0000000000..82db3703e0 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicNonceDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Mosaic nonce. */ +export class MosaicNonceDto { + /** Mosaic nonce. */ + mosaicNonce: number; + + /** + * Constructor. + * + * @param mosaicNonce Mosaic nonce. + */ + constructor(mosaicNonce: number) { + this.mosaicNonce = mosaicNonce; + } + + /** + * Creates an instance of MosaicNonceDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicNonceDto. + */ + public static loadFromBinary(payload: Uint8Array): MosaicNonceDto { + const byteArray = Array.from(payload); + const mosaicNonce = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + return new MosaicNonceDto(mosaicNonce); + } + + /** + * Gets Mosaic nonce. + * + * @return Mosaic nonce. + */ + public getMosaicNonce(): number { + return this.mosaicNonce; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 4; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicNonceBytes = GeneratorUtils.uintToBuffer(this.getMosaicNonce(), 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicNonceBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicRestrictionTypeDto.ts b/src/infrastructure/catbuffer/MosaicRestrictionTypeDto.ts new file mode 100644 index 0000000000..78b5f8d179 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicRestrictionTypeDto.ts @@ -0,0 +1,39 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of mosaic restriction types. */ +export enum MosaicRestrictionTypeDto { + /** Uninitialized value indicating no restriction. */ + NONE = 0, + /** Allow if equal. */ + EQ = 1, + /** Allow if not equal. */ + NE = 2, + /** Allow if less than. */ + LT = 3, + /** Allow if less than or equal. */ + LE = 4, + /** Allow if greater than. */ + GT = 5, + /** Allow if greater than or equal. */ + GE = 6, +} diff --git a/src/infrastructure/catbuffer/MosaicSupplyChangeActionDto.ts b/src/infrastructure/catbuffer/MosaicSupplyChangeActionDto.ts new file mode 100644 index 0000000000..eafa2d5b4e --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicSupplyChangeActionDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of mosaic supply change actions. */ +export enum MosaicSupplyChangeActionDto { + /** Decreases the supply. */ + DECREASE = 0, + /** Increases the supply. */ + INCREASE = 1, +} diff --git a/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBodyBuilder.ts new file mode 100644 index 0000000000..6e9a680728 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBodyBuilder.ts @@ -0,0 +1,121 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { MosaicSupplyChangeActionDto } from './MosaicSupplyChangeActionDto'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a mosaic supply change transaction. */ +export class MosaicSupplyChangeTransactionBodyBuilder { + /** Affected mosaic identifier. */ + mosaicId: UnresolvedMosaicIdDto; + /** Supply change action. */ + action: MosaicSupplyChangeActionDto; + /** Change amount. */ + delta: AmountDto; + + /** + * Constructor. + * + * @param mosaicId Affected mosaic identifier. + * @param action Supply change action. + * @param delta Change amount. + */ + public constructor(mosaicId: UnresolvedMosaicIdDto, action: MosaicSupplyChangeActionDto, delta: AmountDto) { + this.mosaicId = mosaicId; + this.action = action; + this.delta = delta; + } + + /** + * Creates an instance of MosaicSupplyChangeTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicSupplyChangeTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicSupplyChangeTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const action = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const delta = AmountDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, delta.getSize()); + return new MosaicSupplyChangeTransactionBodyBuilder(mosaicId, action, delta); + } + + /** + * Gets affected mosaic identifier. + * + * @return Affected mosaic identifier. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicId; + } + + /** + * Gets supply change action. + * + * @return Supply change action. + */ + public getAction(): MosaicSupplyChangeActionDto { + return this.action; + } + + /** + * Gets change amount. + * + * @return Change amount. + */ + public getDelta(): AmountDto { + return this.delta; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += 1; // action + size += this.delta.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const actionBytes = GeneratorUtils.uintToBuffer(this.action, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, actionBytes); + const deltaBytes = this.delta.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, deltaBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder.ts b/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder.ts new file mode 100644 index 0000000000..ae1c675729 --- /dev/null +++ b/src/infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MosaicSupplyChangeActionDto } from './MosaicSupplyChangeActionDto'; +import { MosaicSupplyChangeTransactionBodyBuilder } from './MosaicSupplyChangeTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for a non-embedded mosaic supply change transaction. */ +export class MosaicSupplyChangeTransactionBuilder extends TransactionBuilder { + /** Mosaic supply change transaction body. */ + mosaicSupplyChangeTransactionBody: MosaicSupplyChangeTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaicId Affected mosaic identifier. + * @param action Supply change action. + * @param delta Change amount. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaicId: UnresolvedMosaicIdDto, action: MosaicSupplyChangeActionDto, delta: AmountDto) { + super(signature, signer, version, type, fee, deadline); + this.mosaicSupplyChangeTransactionBody = new MosaicSupplyChangeTransactionBodyBuilder(mosaicId, action, delta); + } + + /** + * Creates an instance of MosaicSupplyChangeTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MosaicSupplyChangeTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MosaicSupplyChangeTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const mosaicSupplyChangeTransactionBody = MosaicSupplyChangeTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicSupplyChangeTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MosaicSupplyChangeTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, mosaicSupplyChangeTransactionBody.mosaicId, mosaicSupplyChangeTransactionBody.action, mosaicSupplyChangeTransactionBody.delta); + } + + /** + * Gets affected mosaic identifier. + * + * @return Affected mosaic identifier. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicSupplyChangeTransactionBody.getMosaicId(); + } + + /** + * Gets supply change action. + * + * @return Supply change action. + */ + public getAction(): MosaicSupplyChangeActionDto { + return this.mosaicSupplyChangeTransactionBody.getAction(); + } + + /** + * Gets change amount. + * + * @return Change amount. + */ + public getDelta(): AmountDto { + return this.mosaicSupplyChangeTransactionBody.getDelta(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.mosaicSupplyChangeTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const mosaicSupplyChangeTransactionBodyBytes = this.mosaicSupplyChangeTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicSupplyChangeTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBodyBuilder.ts new file mode 100644 index 0000000000..9f646f89cb --- /dev/null +++ b/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBodyBuilder.ts @@ -0,0 +1,131 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { CosignatoryModificationBuilder } from './CosignatoryModificationBuilder'; +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for a multisig account modification transaction. */ +export class MultisigAccountModificationTransactionBodyBuilder { + /** Relative change of the minimal number of cosignatories required when removing an account. */ + minRemovalDelta: number; + /** Relative change of the minimal number of cosignatories required when approving a transaction. */ + minApprovalDelta: number; + /** Attached cosignatory modifications. */ + modifications: CosignatoryModificationBuilder[]; + + /** + * Constructor. + * + * @param minRemovalDelta Relative change of the minimal number of cosignatories required when removing an account. + * @param minApprovalDelta Relative change of the minimal number of cosignatories required when approving a transaction. + * @param modifications Attached cosignatory modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(minRemovalDelta: number, minApprovalDelta: number, modifications: CosignatoryModificationBuilder[]) { + this.minRemovalDelta = minRemovalDelta; + this.minApprovalDelta = minApprovalDelta; + this.modifications = modifications; + } + + /** + * Creates an instance of MultisigAccountModificationTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MultisigAccountModificationTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MultisigAccountModificationTransactionBodyBuilder { + const byteArray = Array.from(payload); + const minRemovalDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const minApprovalDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modificationsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const modifications: CosignatoryModificationBuilder[] = []; + for (let i = 0; i < modificationsCount; i++) { + const item = CosignatoryModificationBuilder.loadFromBinary(Uint8Array.from(byteArray)); + modifications.push(item); + byteArray.splice(0, item.getSize()); + } + return new MultisigAccountModificationTransactionBodyBuilder(minRemovalDelta, minApprovalDelta, modifications); + } + + /** + * Gets relative change of the minimal number of cosignatories required when removing an account. + * + * @return Relative change of the minimal number of cosignatories required when removing an account. + */ + public getMinRemovalDelta(): number { + return this.minRemovalDelta; + } + + /** + * Gets relative change of the minimal number of cosignatories required when approving a transaction. + * + * @return Relative change of the minimal number of cosignatories required when approving a transaction. + */ + public getMinApprovalDelta(): number { + return this.minApprovalDelta; + } + + /** + * Gets attached cosignatory modifications. + * + * @return Attached cosignatory modifications. + */ + public getModifications(): CosignatoryModificationBuilder[] { + return this.modifications; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // minRemovalDelta + size += 1; // minApprovalDelta + size += 1; // modificationsCount + this.modifications.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const minRemovalDeltaBytes = GeneratorUtils.uintToBuffer(this.getMinRemovalDelta(), 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, minRemovalDeltaBytes); + const minApprovalDeltaBytes = GeneratorUtils.uintToBuffer(this.getMinApprovalDelta(), 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, minApprovalDeltaBytes); + const modificationsCountBytes = GeneratorUtils.uintToBuffer(this.modifications.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsCountBytes); + this.modifications.forEach((item) => { + const modificationsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, modificationsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder.ts b/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder.ts new file mode 100644 index 0000000000..4405bdc6ca --- /dev/null +++ b/src/infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder.ts @@ -0,0 +1,125 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { CosignatoryModificationBuilder } from './CosignatoryModificationBuilder'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { MultisigAccountModificationTransactionBodyBuilder } from './MultisigAccountModificationTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded multisig account modification transaction. */ +export class MultisigAccountModificationTransactionBuilder extends TransactionBuilder { + /** Multisig account modification transaction body. */ + multisigAccountModificationTransactionBody: MultisigAccountModificationTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param minRemovalDelta Relative change of the minimal number of cosignatories required when removing an account. + * @param minApprovalDelta Relative change of the minimal number of cosignatories required when approving a transaction. + * @param modifications Attached cosignatory modifications. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, minRemovalDelta: number, minApprovalDelta: number, modifications: CosignatoryModificationBuilder[]) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.multisigAccountModificationTransactionBody = new MultisigAccountModificationTransactionBodyBuilder(minRemovalDelta, minApprovalDelta, modifications); + } + + /** + * Creates an instance of MultisigAccountModificationTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of MultisigAccountModificationTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): MultisigAccountModificationTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const multisigAccountModificationTransactionBody = MultisigAccountModificationTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, multisigAccountModificationTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new MultisigAccountModificationTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, multisigAccountModificationTransactionBody.minRemovalDelta, multisigAccountModificationTransactionBody.minApprovalDelta, multisigAccountModificationTransactionBody.modifications); + } + + /** + * Gets relative change of the minimal number of cosignatories required when removing an account. + * + * @return Relative change of the minimal number of cosignatories required when removing an account. + */ + public getMinRemovalDelta(): number { + return this.multisigAccountModificationTransactionBody.getMinRemovalDelta(); + } + + /** + * Gets relative change of the minimal number of cosignatories required when approving a transaction. + * + * @return Relative change of the minimal number of cosignatories required when approving a transaction. + */ + public getMinApprovalDelta(): number { + return this.multisigAccountModificationTransactionBody.getMinApprovalDelta(); + } + + /** + * Gets attached cosignatory modifications. + * + * @return Attached cosignatory modifications. + */ + public getModifications(): CosignatoryModificationBuilder[] { + return this.multisigAccountModificationTransactionBody.getModifications(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.multisigAccountModificationTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const multisigAccountModificationTransactionBodyBytes = this.multisigAccountModificationTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, multisigAccountModificationTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceIdDto.ts b/src/infrastructure/catbuffer/NamespaceIdDto.ts new file mode 100644 index 0000000000..498f63dbe3 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceIdDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Namespace id. */ +export class NamespaceIdDto { + /** Namespace id. */ + namespaceId: number[]; + + /** + * Constructor. + * + * @param namespaceId Namespace id. + */ + constructor(namespaceId: number[]) { + this.namespaceId = namespaceId; + } + + /** + * Creates an instance of NamespaceIdDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceIdDto. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceIdDto { + const byteArray = Array.from(payload); + const namespaceId = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new NamespaceIdDto(namespaceId); + } + + /** + * Gets Namespace id. + * + * @return Namespace id. + */ + public getNamespaceId(): number[] { + return this.namespaceId; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const namespaceIdBytes = GeneratorUtils.uint64ToBuffer(this.getNamespaceId()); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceIdBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceMetadataTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/NamespaceMetadataTransactionBodyBuilder.ts new file mode 100644 index 0000000000..f460ab3c25 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceMetadataTransactionBodyBuilder.ts @@ -0,0 +1,168 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; + +/** Binary layout for a namespace metadata transaction. */ +export class NamespaceMetadataTransactionBodyBuilder { + /** Metadata target public key. */ + targetPublicKey: KeyDto; + /** Metadata key scoped to source, target and type. */ + scopedMetadataKey: number[]; + /** Target namespace identifier. */ + targetNamespaceId: NamespaceIdDto; + /** Change in value size in bytes. */ + valueSizeDelta: number; + /** Difference between existing value and new value \note when there is no existing value, new value is same this value \note when there is an existing value, new value is calculated as xor(previous-value, value). */ + value: Uint8Array; + + /** + * Constructor. + * + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetNamespaceId Target namespace identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(targetPublicKey: KeyDto, scopedMetadataKey: number[], targetNamespaceId: NamespaceIdDto, valueSizeDelta: number, value: Uint8Array) { + this.targetPublicKey = targetPublicKey; + this.scopedMetadataKey = scopedMetadataKey; + this.targetNamespaceId = targetNamespaceId; + this.valueSizeDelta = valueSizeDelta; + this.value = value; + } + + /** + * Creates an instance of NamespaceMetadataTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceMetadataTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceMetadataTransactionBodyBuilder { + const byteArray = Array.from(payload); + const targetPublicKey = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetPublicKey.getSize()); + const scopedMetadataKey = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + const targetNamespaceId = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, targetNamespaceId.getSize()); + const valueSizeDelta = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const valueSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const value = GeneratorUtils.getBytes(Uint8Array.from(byteArray), valueSize); + byteArray.splice(0, valueSize); + // tslint:disable-next-line: max-line-length + return new NamespaceMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetNamespaceId, valueSizeDelta, value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.targetPublicKey; + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.scopedMetadataKey; + } + + /** + * Gets target namespace identifier. + * + * @return Target namespace identifier. + */ + public getTargetNamespaceId(): NamespaceIdDto { + return this.targetNamespaceId; + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.valueSizeDelta; + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.value; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.targetPublicKey.getSize(); + size += 8; // scopedMetadataKey + size += this.targetNamespaceId.getSize(); + size += 2; // valueSizeDelta + size += 2; // valueSize + size += this.value.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const targetPublicKeyBytes = this.targetPublicKey.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetPublicKeyBytes); + const scopedMetadataKeyBytes = GeneratorUtils.uint64ToBuffer(this.getScopedMetadataKey()); + newArray = GeneratorUtils.concatTypedArrays(newArray, scopedMetadataKeyBytes); + const targetNamespaceIdBytes = this.targetNamespaceId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, targetNamespaceIdBytes); + const valueSizeDeltaBytes = GeneratorUtils.uintToBuffer(this.getValueSizeDelta(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeDeltaBytes); + const valueSizeBytes = GeneratorUtils.uintToBuffer(this.value.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, valueSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.value); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceMetadataTransactionBuilder.ts b/src/infrastructure/catbuffer/NamespaceMetadataTransactionBuilder.ts new file mode 100644 index 0000000000..6b4b2e4885 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceMetadataTransactionBuilder.ts @@ -0,0 +1,151 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceMetadataTransactionBodyBuilder } from './NamespaceMetadataTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded namespace metadata transaction. */ +export class NamespaceMetadataTransactionBuilder extends TransactionBuilder { + /** Namespace metadata transaction body. */ + namespaceMetadataTransactionBody: NamespaceMetadataTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param targetPublicKey Metadata target public key. + * @param scopedMetadataKey Metadata key scoped to source, target and type. + * @param targetNamespaceId Target namespace identifier. + * @param valueSizeDelta Change in value size in bytes. + * @param value Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, targetPublicKey: KeyDto, scopedMetadataKey: number[], targetNamespaceId: NamespaceIdDto, valueSizeDelta: number, value: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.namespaceMetadataTransactionBody = new NamespaceMetadataTransactionBodyBuilder(targetPublicKey, scopedMetadataKey, targetNamespaceId, valueSizeDelta, value); + } + + /** + * Creates an instance of NamespaceMetadataTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceMetadataTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceMetadataTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const namespaceMetadataTransactionBody = NamespaceMetadataTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceMetadataTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new NamespaceMetadataTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, namespaceMetadataTransactionBody.targetPublicKey, namespaceMetadataTransactionBody.scopedMetadataKey, namespaceMetadataTransactionBody.targetNamespaceId, namespaceMetadataTransactionBody.valueSizeDelta, namespaceMetadataTransactionBody.value); + } + + /** + * Gets metadata target public key. + * + * @return Metadata target public key. + */ + public getTargetPublicKey(): KeyDto { + return this.namespaceMetadataTransactionBody.getTargetPublicKey(); + } + + /** + * Gets metadata key scoped to source, target and type. + * + * @return Metadata key scoped to source, target and type. + */ + public getScopedMetadataKey(): number[] { + return this.namespaceMetadataTransactionBody.getScopedMetadataKey(); + } + + /** + * Gets target namespace identifier. + * + * @return Target namespace identifier. + */ + public getTargetNamespaceId(): NamespaceIdDto { + return this.namespaceMetadataTransactionBody.getTargetNamespaceId(); + } + + /** + * Gets change in value size in bytes. + * + * @return Change in value size in bytes. + */ + public getValueSizeDelta(): number { + return this.namespaceMetadataTransactionBody.getValueSizeDelta(); + } + + /** + * Gets difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + * + * @return Difference between existing value and new value. + * @note when there is no existing value, new value is same this value. + * @note when there is an existing value, new value is calculated as xor(previous-value, value). + */ + public getValue(): Uint8Array { + return this.namespaceMetadataTransactionBody.getValue(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.namespaceMetadataTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const namespaceMetadataTransactionBodyBytes = this.namespaceMetadataTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceMetadataTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBodyBuilder.ts new file mode 100644 index 0000000000..465636812f --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBodyBuilder.ts @@ -0,0 +1,188 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceRegistrationTypeDto } from './NamespaceRegistrationTypeDto'; + +/** Binary layout for a namespace registration transaction. */ +export class NamespaceRegistrationTransactionBodyBuilder { + /** Namespace registration type. */ + registrationType: NamespaceRegistrationTypeDto; + /** Namespace duration. */ + duration?: BlockDurationDto; + /** Parent namespace identifier. */ + parentId?: NamespaceIdDto; + /** Namespace identifier. */ + id: NamespaceIdDto; + /** Namespace name. */ + name: Uint8Array; + + /** + * Constructor. + * + * @param duration Namespace duration. + * @param parentId Parent namespace identifier. + * @param id Namespace identifier. + * @param name Namespace name. + */ + public constructor(id: NamespaceIdDto, name: Uint8Array, duration?: BlockDurationDto, parentId?: NamespaceIdDto) { + if ((duration && parentId) || (!duration && !parentId)) { + throw new Error('Invalid conditional parameters'); + } + this.duration = duration; + this.parentId = parentId; + this.id = id; + this.name = name; + if (duration) { + this.registrationType = NamespaceRegistrationTypeDto.ROOT; + } + if (parentId) { + this.registrationType = NamespaceRegistrationTypeDto.CHILD; + } + } + + /** + * Creates an instance of NamespaceRegistrationTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceRegistrationTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceRegistrationTransactionBodyBuilder { + const byteArray = Array.from(payload); + const registrationType = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + let duration; + if (registrationType === NamespaceRegistrationTypeDto.ROOT) { + duration = BlockDurationDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, duration.getSize()); + } + let parentId; + if (registrationType === NamespaceRegistrationTypeDto.CHILD) { + parentId = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, parentId.getSize()); + } + const id = NamespaceIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, id.getSize()); + const nameSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const name = GeneratorUtils.getBytes(Uint8Array.from(byteArray), nameSize); + byteArray.splice(0, nameSize); + return new NamespaceRegistrationTransactionBodyBuilder(id, name, duration, parentId); + } + + /** + * Gets namespace registration type. + * + * @return Namespace registration type. + */ + public getRegistrationType(): NamespaceRegistrationTypeDto { + return this.registrationType; + } + + /** + * Gets namespace duration. + * + * @return Namespace duration. + */ + public getDuration(): BlockDurationDto | undefined { + if (this.registrationType !== NamespaceRegistrationTypeDto.ROOT) { + throw new Error('registrationType is not set to ROOT.'); + } + return this.duration; + } + + /** + * Gets parent namespace identifier. + * + * @return Parent namespace identifier. + */ + public getParentId(): NamespaceIdDto | undefined { + if (this.registrationType !== NamespaceRegistrationTypeDto.CHILD) { + throw new Error('registrationType is not set to CHILD.'); + } + return this.parentId; + } + + /** + * Gets namespace identifier. + * + * @return Namespace identifier. + */ + public getId(): NamespaceIdDto { + return this.id; + } + + /** + * Gets namespace name. + * + * @return Namespace name. + */ + public getName(): Uint8Array { + return this.name; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // registrationType + if (this.registrationType === NamespaceRegistrationTypeDto.ROOT) { + size += this.duration!.getSize(); + } + if (this.registrationType === NamespaceRegistrationTypeDto.CHILD) { + size += this.parentId!.getSize(); + } + size += this.id.getSize(); + size += 1; // nameSize + size += this.name.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const registrationTypeBytes = GeneratorUtils.uintToBuffer(this.registrationType, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, registrationTypeBytes); + if (this.registrationType === NamespaceRegistrationTypeDto.ROOT) { + const durationBytes = this.duration!.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, durationBytes); + } + if (this.registrationType === NamespaceRegistrationTypeDto.CHILD) { + const parentIdBytes = this.parentId!.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, parentIdBytes); + } + const idBytes = this.id.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, idBytes); + const nameSizeBytes = GeneratorUtils.uintToBuffer(this.name.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, nameSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.name); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder.ts b/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder.ts new file mode 100644 index 0000000000..a9e96db248 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder.ts @@ -0,0 +1,149 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { BlockDurationDto } from './BlockDurationDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { NamespaceRegistrationTransactionBodyBuilder } from './NamespaceRegistrationTransactionBodyBuilder'; +import { NamespaceRegistrationTypeDto } from './NamespaceRegistrationTypeDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for a non-embedded namespace registration transaction. */ +export class NamespaceRegistrationTransactionBuilder extends TransactionBuilder { + /** Namespace registration transaction body. */ + namespaceRegistrationTransactionBody: NamespaceRegistrationTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param duration Namespace duration. + * @param parentId Parent namespace identifier. + * @param id Namespace identifier. + * @param name Namespace name. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, id: NamespaceIdDto, name: Uint8Array, duration?: BlockDurationDto, parentId?: NamespaceIdDto) { + super(signature, signer, version, type, fee, deadline); + if ((duration && parentId) || (!duration && !parentId)) { + throw new Error('Invalid conditional parameters'); + } + // tslint:disable-next-line: max-line-length + this.namespaceRegistrationTransactionBody = new NamespaceRegistrationTransactionBodyBuilder(id, name, duration, parentId); + } + + /** + * Creates an instance of NamespaceRegistrationTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of NamespaceRegistrationTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): NamespaceRegistrationTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + // tslint:disable-next-line: max-line-length + const namespaceRegistrationTransactionBody = NamespaceRegistrationTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, namespaceRegistrationTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new NamespaceRegistrationTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, namespaceRegistrationTransactionBody.id, namespaceRegistrationTransactionBody.name, namespaceRegistrationTransactionBody.duration, namespaceRegistrationTransactionBody.parentId); + } + + /** + * Gets namespace registration type. + * + * @return Namespace registration type. + */ + public getRegistrationType(): NamespaceRegistrationTypeDto { + return this.namespaceRegistrationTransactionBody.getRegistrationType(); + } + + /** + * Gets namespace duration. + * + * @return Namespace duration. + */ + public getDuration(): BlockDurationDto | undefined { + return this.namespaceRegistrationTransactionBody.getDuration(); + } + + /** + * Gets parent namespace identifier. + * + * @return Parent namespace identifier. + */ + public getParentId(): NamespaceIdDto | undefined { + return this.namespaceRegistrationTransactionBody.getParentId(); + } + + /** + * Gets namespace identifier. + * + * @return Namespace identifier. + */ + public getId(): NamespaceIdDto { + return this.namespaceRegistrationTransactionBody.getId(); + } + + /** + * Gets namespace name. + * + * @return Namespace name. + */ + public getName(): Uint8Array { + return this.namespaceRegistrationTransactionBody.getName(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.namespaceRegistrationTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const namespaceRegistrationTransactionBodyBytes = this.namespaceRegistrationTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, namespaceRegistrationTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/NamespaceRegistrationTypeDto.ts b/src/infrastructure/catbuffer/NamespaceRegistrationTypeDto.ts new file mode 100644 index 0000000000..349db68025 --- /dev/null +++ b/src/infrastructure/catbuffer/NamespaceRegistrationTypeDto.ts @@ -0,0 +1,29 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + + +/** Enumeration of namespace registration types. */ +export enum NamespaceRegistrationTypeDto { + /** Root namespace. */ + ROOT = 0, + /** Child namespace. */ + CHILD = 1, +} diff --git a/src/infrastructure/catbuffer/SecretLockTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/SecretLockTransactionBodyBuilder.ts new file mode 100644 index 0000000000..a38da76d77 --- /dev/null +++ b/src/infrastructure/catbuffer/SecretLockTransactionBodyBuilder.ts @@ -0,0 +1,160 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { BlockDurationDto } from './BlockDurationDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a secret lock transaction. */ +export class SecretLockTransactionBodyBuilder { + /** Locked mosaic. */ + mosaic: UnresolvedMosaicBuilder; + /** Number of blocks for which a lock should be valid. */ + duration: BlockDurationDto; + /** Hash algorithm. */ + hashAlgorithm: LockHashAlgorithmDto; + /** Secret. */ + secret: Hash256Dto; + /** Locked mosaic recipient. */ + recipient: UnresolvedAddressDto; + + /** + * Constructor. + * + * @param mosaic Locked mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Locked mosaic recipient. + */ + // tslint:disable-next-line: max-line-length + public constructor(mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto) { + this.mosaic = mosaic; + this.duration = duration; + this.hashAlgorithm = hashAlgorithm; + this.secret = secret; + this.recipient = recipient; + } + + /** + * Creates an instance of SecretLockTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SecretLockTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): SecretLockTransactionBodyBuilder { + const byteArray = Array.from(payload); + const mosaic = UnresolvedMosaicBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaic.getSize()); + const duration = BlockDurationDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, duration.getSize()); + const hashAlgorithm = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const secret = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secret.getSize()); + const recipient = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, recipient.getSize()); + return new SecretLockTransactionBodyBuilder(mosaic, duration, hashAlgorithm, secret, recipient); + } + + /** + * Gets locked mosaic. + * + * @return Locked mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.mosaic; + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.duration; + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.hashAlgorithm; + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secret; + } + + /** + * Gets locked mosaic recipient. + * + * @return Locked mosaic recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.recipient; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaic.getSize(); + size += this.duration.getSize(); + size += 1; // hashAlgorithm + size += this.secret.getSize(); + size += this.recipient.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicBytes = this.mosaic.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicBytes); + const durationBytes = this.duration.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, durationBytes); + const hashAlgorithmBytes = GeneratorUtils.uintToBuffer(this.hashAlgorithm, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashAlgorithmBytes); + const secretBytes = this.secret.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretBytes); + const recipientBytes = this.recipient.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, recipientBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/SecretLockTransactionBuilder.ts b/src/infrastructure/catbuffer/SecretLockTransactionBuilder.ts new file mode 100644 index 0000000000..3f99ae1dd0 --- /dev/null +++ b/src/infrastructure/catbuffer/SecretLockTransactionBuilder.ts @@ -0,0 +1,148 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { BlockDurationDto } from './BlockDurationDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { KeyDto } from './KeyDto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { SecretLockTransactionBodyBuilder } from './SecretLockTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a non-embedded secret lock transaction. */ +export class SecretLockTransactionBuilder extends TransactionBuilder { + /** Secret lock transaction body. */ + secretLockTransactionBody: SecretLockTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param mosaic Locked mosaic. + * @param duration Number of blocks for which a lock should be valid. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Locked mosaic recipient. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, mosaic: UnresolvedMosaicBuilder, duration: BlockDurationDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto) { + super(signature, signer, version, type, fee, deadline); + // tslint:disable-next-line: max-line-length + this.secretLockTransactionBody = new SecretLockTransactionBodyBuilder(mosaic, duration, hashAlgorithm, secret, recipient); + } + + /** + * Creates an instance of SecretLockTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SecretLockTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): SecretLockTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const secretLockTransactionBody = SecretLockTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secretLockTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new SecretLockTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, secretLockTransactionBody.mosaic, secretLockTransactionBody.duration, secretLockTransactionBody.hashAlgorithm, secretLockTransactionBody.secret, secretLockTransactionBody.recipient); + } + + /** + * Gets locked mosaic. + * + * @return Locked mosaic. + */ + public getMosaic(): UnresolvedMosaicBuilder { + return this.secretLockTransactionBody.getMosaic(); + } + + /** + * Gets number of blocks for which a lock should be valid. + * + * @return Number of blocks for which a lock should be valid. + */ + public getDuration(): BlockDurationDto { + return this.secretLockTransactionBody.getDuration(); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.secretLockTransactionBody.getHashAlgorithm(); + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secretLockTransactionBody.getSecret(); + } + + /** + * Gets locked mosaic recipient. + * + * @return Locked mosaic recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.secretLockTransactionBody.getRecipient(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.secretLockTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const secretLockTransactionBodyBytes = this.secretLockTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretLockTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/SecretProofTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/SecretProofTransactionBodyBuilder.ts new file mode 100644 index 0000000000..ba7a2a1fa2 --- /dev/null +++ b/src/infrastructure/catbuffer/SecretProofTransactionBodyBuilder.ts @@ -0,0 +1,144 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; + +/** Binary layout for a secret proof transaction. */ +export class SecretProofTransactionBodyBuilder { + /** Hash algorithm. */ + hashAlgorithm: LockHashAlgorithmDto; + /** Secret. */ + secret: Hash256Dto; + /** Recipient. */ + recipient: UnresolvedAddressDto; + /** Proof data. */ + proof: Uint8Array; + + /** + * Constructor. + * + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Recipient. + * @param proof Proof data. + */ + // tslint:disable-next-line: max-line-length + public constructor(hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto, proof: Uint8Array) { + this.hashAlgorithm = hashAlgorithm; + this.secret = secret; + this.recipient = recipient; + this.proof = proof; + } + + /** + * Creates an instance of SecretProofTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SecretProofTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): SecretProofTransactionBodyBuilder { + const byteArray = Array.from(payload); + const hashAlgorithm = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const secret = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secret.getSize()); + const recipient = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, recipient.getSize()); + const proofSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const proof = GeneratorUtils.getBytes(Uint8Array.from(byteArray), proofSize); + byteArray.splice(0, proofSize); + return new SecretProofTransactionBodyBuilder(hashAlgorithm, secret, recipient, proof); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.hashAlgorithm; + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secret; + } + + /** + * Gets recipient. + * + * @return Recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.recipient; + } + + /** + * Gets proof data. + * + * @return Proof data. + */ + public getProof(): Uint8Array { + return this.proof; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 1; // hashAlgorithm + size += this.secret.getSize(); + size += this.recipient.getSize(); + size += 2; // proofSize + size += this.proof.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const hashAlgorithmBytes = GeneratorUtils.uintToBuffer(this.hashAlgorithm, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, hashAlgorithmBytes); + const secretBytes = this.secret.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretBytes); + const recipientBytes = this.recipient.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, recipientBytes); + const proofSizeBytes = GeneratorUtils.uintToBuffer(this.proof.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, proofSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.proof); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/SecretProofTransactionBuilder.ts b/src/infrastructure/catbuffer/SecretProofTransactionBuilder.ts new file mode 100644 index 0000000000..445a74e418 --- /dev/null +++ b/src/infrastructure/catbuffer/SecretProofTransactionBuilder.ts @@ -0,0 +1,135 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; +import { KeyDto } from './KeyDto'; +import { LockHashAlgorithmDto } from './LockHashAlgorithmDto'; +import { SecretProofTransactionBodyBuilder } from './SecretProofTransactionBodyBuilder'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; + +/** Binary layout for a non-embedded secret proof transaction. */ +export class SecretProofTransactionBuilder extends TransactionBuilder { + /** Secret proof transaction body. */ + secretProofTransactionBody: SecretProofTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param hashAlgorithm Hash algorithm. + * @param secret Secret. + * @param recipient Recipient. + * @param proof Proof data. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, hashAlgorithm: LockHashAlgorithmDto, secret: Hash256Dto, recipient: UnresolvedAddressDto, proof: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + this.secretProofTransactionBody = new SecretProofTransactionBodyBuilder(hashAlgorithm, secret, recipient, proof); + } + + /** + * Creates an instance of SecretProofTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SecretProofTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): SecretProofTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const secretProofTransactionBody = SecretProofTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, secretProofTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new SecretProofTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, secretProofTransactionBody.hashAlgorithm, secretProofTransactionBody.secret, secretProofTransactionBody.recipient, secretProofTransactionBody.proof); + } + + /** + * Gets hash algorithm. + * + * @return Hash algorithm. + */ + public getHashAlgorithm(): LockHashAlgorithmDto { + return this.secretProofTransactionBody.getHashAlgorithm(); + } + + /** + * Gets secret. + * + * @return Secret. + */ + public getSecret(): Hash256Dto { + return this.secretProofTransactionBody.getSecret(); + } + + /** + * Gets recipient. + * + * @return Recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.secretProofTransactionBody.getRecipient(); + } + + /** + * Gets proof data. + * + * @return Proof data. + */ + public getProof(): Uint8Array { + return this.secretProofTransactionBody.getProof(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.secretProofTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const secretProofTransactionBodyBytes = this.secretProofTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, secretProofTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/SignatureDto.ts b/src/infrastructure/catbuffer/SignatureDto.ts new file mode 100644 index 0000000000..307efb2b50 --- /dev/null +++ b/src/infrastructure/catbuffer/SignatureDto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Signature. */ +export class SignatureDto { + /** Signature. */ + signature: Uint8Array; + + /** + * Constructor. + * + * @param signature Signature. + */ + constructor(signature: Uint8Array) { + this.signature = signature; + } + + /** + * Creates an instance of SignatureDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of SignatureDto. + */ + public static loadFromBinary(payload: Uint8Array): SignatureDto { + const byteArray = Array.from(payload); + const signature = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 64); + byteArray.splice(0, 64); + return new SignatureDto(signature); + } + + /** + * Gets Signature. + * + * @return Signature. + */ + public getSignature(): Uint8Array { + return this.signature; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 64; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.signature); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/TimestampDto.ts b/src/infrastructure/catbuffer/TimestampDto.ts new file mode 100644 index 0000000000..af3de24b9e --- /dev/null +++ b/src/infrastructure/catbuffer/TimestampDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Timestamp. */ +export class TimestampDto { + /** Timestamp. */ + timestamp: number[]; + + /** + * Constructor. + * + * @param timestamp Timestamp. + */ + constructor(timestamp: number[]) { + this.timestamp = timestamp; + } + + /** + * Creates an instance of TimestampDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of TimestampDto. + */ + public static loadFromBinary(payload: Uint8Array): TimestampDto { + const byteArray = Array.from(payload); + const timestamp = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new TimestampDto(timestamp); + } + + /** + * Gets Timestamp. + * + * @return Timestamp. + */ + public getTimestamp(): number[] { + return this.timestamp; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const timestampBytes = GeneratorUtils.uint64ToBuffer(this.getTimestamp()); + newArray = GeneratorUtils.concatTypedArrays(newArray, timestampBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/TransactionBuilder.ts b/src/infrastructure/catbuffer/TransactionBuilder.ts new file mode 100644 index 0000000000..e50a3024be --- /dev/null +++ b/src/infrastructure/catbuffer/TransactionBuilder.ts @@ -0,0 +1,185 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; + +/** Binary layout for a transaction. */ +export class TransactionBuilder { + /** Entity size. */ + size = 0; + /** Entity signature. */ + signature: SignatureDto; + /** Entity signer's public key. */ + signer: KeyDto; + /** Entity version. */ + version: number; + /** Entity type. */ + type: EntityTypeDto; + /** Transaction fee. */ + fee: AmountDto; + /** Transaction deadline. */ + deadline: TimestampDto; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto) { + this.signature = signature; + this.signer = signer; + this.version = version; + this.type = type; + this.fee = fee; + this.deadline = deadline; + } + + /** + * Creates an instance of TransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of TransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): TransactionBuilder { + const byteArray = Array.from(payload); + const size = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + const signature = SignatureDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signature.getSize()); + const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signer.getSize()); + const version = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const type = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const fee = AmountDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, fee.getSize()); + const deadline = TimestampDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, deadline.getSize()); + return new TransactionBuilder(signature, signer, version, type, fee, deadline); + } + + /** + * Gets entity signature. + * + * @return Entity signature. + */ + public getSignature(): SignatureDto { + return this.signature; + } + + /** + * Gets entity signer's public key. + * + * @return Entity signer's public key. + */ + public getSigner(): KeyDto { + return this.signer; + } + + /** + * Gets entity version. + * + * @return Entity version. + */ + public getVersion(): number { + return this.version; + } + + /** + * Gets entity type. + * + * @return Entity type. + */ + public getType(): EntityTypeDto { + return this.type; + } + + /** + * Gets transaction fee.. + * + * @return Transaction fee. + */ + public getFee(): AmountDto { + return this.fee; + } + + /** + * Gets transaction deadline. + * + * @return Transaction deadline. + */ + public getDeadline(): TimestampDto { + return this.deadline; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 4; // size + size += this.signature.getSize(); + size += this.signer.getSize(); + size += 2; // version + size += 2; // type + size += this.fee.getSize(); + size += this.deadline.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const sizeBytes = GeneratorUtils.uintToBuffer(this.getSize(), 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, sizeBytes); + const signatureBytes = this.signature.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signatureBytes); + const signerBytes = this.signer.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); + const versionBytes = GeneratorUtils.uintToBuffer(this.getVersion(), 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, versionBytes); + const typeBytes = GeneratorUtils.uintToBuffer(this.type, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, typeBytes); + const feeBytes = this.fee.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, feeBytes); + const deadlineBytes = this.deadline.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, deadlineBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/TransferTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/TransferTransactionBodyBuilder.ts new file mode 100644 index 0000000000..e0ee7daed1 --- /dev/null +++ b/src/infrastructure/catbuffer/TransferTransactionBodyBuilder.ts @@ -0,0 +1,135 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a transfer transaction. */ +export class TransferTransactionBodyBuilder { + /** Transaction recipient. */ + recipient: UnresolvedAddressDto; + /** Transaction message. */ + message: Uint8Array; + /** Attached mosaics. */ + mosaics: UnresolvedMosaicBuilder[]; + + /** + * Constructor. + * + * @param recipient Transaction recipient. + * @param message Transaction message. + * @param mosaics Attached mosaics. + */ + public constructor(recipient: UnresolvedAddressDto, message: Uint8Array, mosaics: UnresolvedMosaicBuilder[]) { + this.recipient = recipient; + this.message = message; + this.mosaics = mosaics; + } + + /** + * Creates an instance of TransferTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of TransferTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): TransferTransactionBodyBuilder { + const byteArray = Array.from(payload); + const recipient = UnresolvedAddressDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, recipient.getSize()); + const messageSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 2)); + byteArray.splice(0, 2); + const mosaicsCount = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 1)); + byteArray.splice(0, 1); + const message = GeneratorUtils.getBytes(Uint8Array.from(byteArray), messageSize); + byteArray.splice(0, messageSize); + const mosaics: UnresolvedMosaicBuilder[] = []; + for (let i = 0; i < mosaicsCount; i++) { + const item = UnresolvedMosaicBuilder.loadFromBinary(Uint8Array.from(byteArray)); + mosaics.push(item); + byteArray.splice(0, item.getSize()); + } + return new TransferTransactionBodyBuilder(recipient, message, mosaics); + } + + /** + * Gets transaction recipient. + * + * @return Transaction recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.recipient; + } + + /** + * Gets transaction message. + * + * @return Transaction message. + */ + public getMessage(): Uint8Array { + return this.message; + } + + /** + * Gets attached mosaics. + * + * @return Attached mosaics. + */ + public getMosaics(): UnresolvedMosaicBuilder[] { + return this.mosaics; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.recipient.getSize(); + size += 2; // messageSize + size += 1; // mosaicsCount + size += this.message.length; + this.mosaics.forEach((o) => size += o.getSize()); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const recipientBytes = this.recipient.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, recipientBytes); + const messageSizeBytes = GeneratorUtils.uintToBuffer(this.message.length, 2); + newArray = GeneratorUtils.concatTypedArrays(newArray, messageSizeBytes); + const mosaicsCountBytes = GeneratorUtils.uintToBuffer(this.mosaics.length, 1); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicsCountBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.message); + this.mosaics.forEach((item) => { + const mosaicsBytes = item.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicsBytes); + }); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/TransferTransactionBuilder.ts b/src/infrastructure/catbuffer/TransferTransactionBuilder.ts new file mode 100644 index 0000000000..722d79409a --- /dev/null +++ b/src/infrastructure/catbuffer/TransferTransactionBuilder.ts @@ -0,0 +1,124 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; +import { TransferTransactionBodyBuilder } from './TransferTransactionBodyBuilder'; +import { UnresolvedAddressDto } from './UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from './UnresolvedMosaicBuilder'; + +/** Binary layout for a non-embedded transfer transaction. */ +export class TransferTransactionBuilder extends TransactionBuilder { + /** Transfer transaction body. */ + transferTransactionBody: TransferTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param recipient Transaction recipient. + * @param message Transaction message. + * @param mosaics Attached mosaics. + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, recipient: UnresolvedAddressDto, message: Uint8Array, mosaics: UnresolvedMosaicBuilder[]) { + super(signature, signer, version, type, fee, deadline); + this.transferTransactionBody = new TransferTransactionBodyBuilder(recipient, message, mosaics); + } + + /** + * Creates an instance of TransferTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of TransferTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): TransferTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const transferTransactionBody = TransferTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, transferTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new TransferTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, transferTransactionBody.recipient, transferTransactionBody.message, transferTransactionBody.mosaics); + } + + /** + * Gets transaction recipient. + * + * @return Transaction recipient. + */ + public getRecipient(): UnresolvedAddressDto { + return this.transferTransactionBody.getRecipient(); + } + + /** + * Gets transaction message. + * + * @return Transaction message. + */ + public getMessage(): Uint8Array { + return this.transferTransactionBody.getMessage(); + } + + /** + * Gets attached mosaics. + * + * @return Attached mosaics. + */ + public getMosaics(): UnresolvedMosaicBuilder[] { + return this.transferTransactionBody.getMosaics(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.transferTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const transferTransactionBodyBytes = this.transferTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, transferTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/UnresolvedAddressDto.ts b/src/infrastructure/catbuffer/UnresolvedAddressDto.ts new file mode 100644 index 0000000000..2a0748d76d --- /dev/null +++ b/src/infrastructure/catbuffer/UnresolvedAddressDto.ts @@ -0,0 +1,79 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Unresolved address. */ +export class UnresolvedAddressDto { + /** Unresolved address. */ + unresolvedAddress: Uint8Array; + + /** + * Constructor. + * + * @param unresolvedAddress Unresolved address. + */ + constructor(unresolvedAddress: Uint8Array) { + this.unresolvedAddress = unresolvedAddress; + } + + /** + * Creates an instance of UnresolvedAddressDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of UnresolvedAddressDto. + */ + public static loadFromBinary(payload: Uint8Array): UnresolvedAddressDto { + const byteArray = Array.from(payload); + const unresolvedAddress = GeneratorUtils.getBytes(Uint8Array.from(byteArray), 25); + byteArray.splice(0, 25); + return new UnresolvedAddressDto(unresolvedAddress); + } + + /** + * Gets Unresolved address. + * + * @return Unresolved address. + */ + public getUnresolvedAddress(): Uint8Array { + return this.unresolvedAddress; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 25; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.unresolvedAddress); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/UnresolvedMosaicBuilder.ts b/src/infrastructure/catbuffer/UnresolvedMosaicBuilder.ts new file mode 100644 index 0000000000..5091228ad9 --- /dev/null +++ b/src/infrastructure/catbuffer/UnresolvedMosaicBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AmountDto } from './AmountDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { UnresolvedMosaicIdDto } from './UnresolvedMosaicIdDto'; + +/** Binary layout for an unresolved mosaic. */ +export class UnresolvedMosaicBuilder { + /** Mosaic identifier. */ + mosaicId: UnresolvedMosaicIdDto; + /** Mosaic amount. */ + amount: AmountDto; + + /** + * Constructor. + * + * @param mosaicId Mosaic identifier. + * @param amount Mosaic amount. + */ + public constructor(mosaicId: UnresolvedMosaicIdDto, amount: AmountDto) { + this.mosaicId = mosaicId; + this.amount = amount; + } + + /** + * Creates an instance of UnresolvedMosaicBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of UnresolvedMosaicBuilder. + */ + public static loadFromBinary(payload: Uint8Array): UnresolvedMosaicBuilder { + const byteArray = Array.from(payload); + const mosaicId = UnresolvedMosaicIdDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, mosaicId.getSize()); + const amount = AmountDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, amount.getSize()); + return new UnresolvedMosaicBuilder(mosaicId, amount); + } + + /** + * Gets mosaic identifier. + * + * @return Mosaic identifier. + */ + public getMosaicId(): UnresolvedMosaicIdDto { + return this.mosaicId; + } + + /** + * Gets mosaic amount. + * + * @return Mosaic amount. + */ + public getAmount(): AmountDto { + return this.amount; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.mosaicId.getSize(); + size += this.amount.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const mosaicIdBytes = this.mosaicId.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, mosaicIdBytes); + const amountBytes = this.amount.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, amountBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/UnresolvedMosaicIdDto.ts b/src/infrastructure/catbuffer/UnresolvedMosaicIdDto.ts new file mode 100644 index 0000000000..8b49a58aea --- /dev/null +++ b/src/infrastructure/catbuffer/UnresolvedMosaicIdDto.ts @@ -0,0 +1,80 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Unresolved mosaic id. */ +export class UnresolvedMosaicIdDto { + /** Unresolved mosaic id. */ + unresolvedMosaicId: number[]; + + /** + * Constructor. + * + * @param unresolvedMosaicId Unresolved mosaic id. + */ + constructor(unresolvedMosaicId: number[]) { + this.unresolvedMosaicId = unresolvedMosaicId; + } + + /** + * Creates an instance of UnresolvedMosaicIdDto from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of UnresolvedMosaicIdDto. + */ + public static loadFromBinary(payload: Uint8Array): UnresolvedMosaicIdDto { + const byteArray = Array.from(payload); + const unresolvedMosaicId = GeneratorUtils.bufferToUint64(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 8)); + byteArray.splice(0, 8); + return new UnresolvedMosaicIdDto(unresolvedMosaicId); + } + + /** + * Gets Unresolved mosaic id. + * + * @return Unresolved mosaic id. + */ + public getUnresolvedMosaicId(): number[] { + return this.unresolvedMosaicId; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + return 8; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const unresolvedMosaicIdBytes = GeneratorUtils.uint64ToBuffer(this.getUnresolvedMosaicId()); + newArray = GeneratorUtils.concatTypedArrays(newArray, unresolvedMosaicIdBytes); + return newArray; + } +} diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index 2205ed1d37..e6a1e3d7ae 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -24,10 +24,10 @@ import {MosaicId} from '../../model/mosaic/MosaicId'; import {MosaicProperties} from '../../model/mosaic/MosaicProperties'; import { MosaicPropertyType } from '../../model/mosaic/MosaicPropertyType'; import {NamespaceId} from '../../model/namespace/NamespaceId'; -import {AccountAddressRestrictionModificationTransaction} from '../../model/transaction/AccountAddressRestrictionModificationTransaction'; +import {AccountAddressRestrictionTransaction} from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; -import {AccountMosaicRestrictionModificationTransaction} from '../../model/transaction/AccountMosaicRestrictionModificationTransaction'; -import {AccountOperationRestrictionModificationTransaction} from '../../model/transaction/AccountOperationRestrictionModificationTransaction'; +import {AccountMosaicRestrictionTransaction} from '../../model/transaction/AccountMosaicRestrictionTransaction'; +import {AccountOperationRestrictionTransaction} from '../../model/transaction/AccountOperationRestrictionTransaction'; import {AccountRestrictionModification} from '../../model/transaction/AccountRestrictionModification'; import {AddressAliasTransaction} from '../../model/transaction/AddressAliasTransaction'; import {AggregateTransaction} from '../../model/transaction/AggregateTransaction'; @@ -280,8 +280,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr extractNetworkType(transactionDTO.version)) : undefined, transactionInfo, ); - } else if (transactionDTO.type === TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS) { - return new AccountAddressRestrictionModificationTransaction( + } else if (transactionDTO.type === TransactionType.ACCOUNT_RESTRICTION_ADDRESS) { + return new AccountAddressRestrictionTransaction( extractNetworkType(transactionDTO.version), extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), @@ -296,8 +296,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr extractNetworkType(transactionDTO.version)) : undefined, transactionInfo, ); - } else if (transactionDTO.type === TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION) { - return new AccountOperationRestrictionModificationTransaction( + } else if (transactionDTO.type === TransactionType.ACCOUNT_RESTRICTION_OPERATION) { + return new AccountOperationRestrictionTransaction( extractNetworkType(transactionDTO.version), extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), @@ -312,8 +312,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr extractNetworkType(transactionDTO.version)) : undefined, transactionInfo, ); - } else if (transactionDTO.type === TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC) { - return new AccountMosaicRestrictionModificationTransaction( + } else if (transactionDTO.type === TransactionType.ACCOUNT_RESTRICTION_MOSAIC) { + return new AccountMosaicRestrictionTransaction( extractNetworkType(transactionDTO.version), extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index afe17f162a..b1198243fd 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -25,10 +25,10 @@ import { MosaicNonce } from '../../model/mosaic/MosaicNonce'; import { MosaicProperties } from '../../model/mosaic/MosaicProperties'; import { NamespaceId } from '../../model/namespace/NamespaceId'; import { NamespaceType } from '../../model/namespace/NamespaceType'; -import { AccountAddressRestrictionModificationTransaction } from '../../model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from '../../model/transaction/AccountMosaicRestrictionModificationTransaction'; -import { AccountOperationRestrictionModificationTransaction } from '../../model/transaction/AccountOperationRestrictionModificationTransaction'; +import { AccountMosaicRestrictionTransaction } from '../../model/transaction/AccountMosaicRestrictionTransaction'; +import { AccountOperationRestrictionTransaction } from '../../model/transaction/AccountOperationRestrictionTransaction'; import { AccountRestrictionModification } from '../../model/transaction/AccountRestrictionModification'; import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction'; import { AggregateTransaction } from '../../model/transaction/AggregateTransaction'; @@ -100,9 +100,9 @@ export const CreateTransactionFromPayload = (transactionBinary: string): Transac */ const CreateTransaction = (type: number, transactionData: string, networkType: NetworkType, deadline: number[]): Transaction => { switch (type) { - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS: - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION: - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC: + case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: + case TransactionType.ACCOUNT_RESTRICTION_OPERATION: + case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: const propertyTypeLength = 2; const modificationCountOffset = propertyTypeLength; @@ -114,8 +114,8 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N const modificationArray = modifications.match(/.{1,52}/g); switch (type) { - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS: - const t = AccountAddressRestrictionModificationTransaction.create( + case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: + const t = AccountAddressRestrictionTransaction.create( Deadline.createFromDTO(deadline), parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( @@ -125,8 +125,8 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N networkType, ); return t; - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC: - return AccountMosaicRestrictionModificationTransaction.create( + case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: + return AccountMosaicRestrictionTransaction.create( Deadline.createFromDTO(deadline), parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( @@ -135,8 +135,8 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N )) : [], networkType, ); - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION: - return AccountOperationRestrictionModificationTransaction.create( + case TransactionType.ACCOUNT_RESTRICTION_OPERATION: + return AccountOperationRestrictionTransaction.create( Deadline.createFromDTO(deadline), parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index 4802bbd278..4ba47f1e4c 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -14,10 +14,10 @@ * limitations under the License. */ -import { AccountAddressRestrictionModificationTransaction } from '../../model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from '../../model/transaction/AccountMosaicRestrictionModificationTransaction'; -import { AccountOperationRestrictionModificationTransaction } from '../../model/transaction/AccountOperationRestrictionModificationTransaction'; +import { AccountMosaicRestrictionTransaction } from '../../model/transaction/AccountMosaicRestrictionTransaction'; +import { AccountOperationRestrictionTransaction } from '../../model/transaction/AccountOperationRestrictionTransaction'; import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction'; import { AggregateTransaction } from '../../model/transaction/AggregateTransaction'; import { LockFundsTransaction } from '../../model/transaction/LockFundsTransaction'; @@ -70,26 +70,26 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { duration: (transaction as LockFundsTransaction).duration.toDTO(), hash: (transaction as LockFundsTransaction).hash, }; - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS: + case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: return { - restrictionType: (transaction as AccountAddressRestrictionModificationTransaction).restrictionType, - modifications: (transaction as AccountAddressRestrictionModificationTransaction). + restrictionType: (transaction as AccountAddressRestrictionTransaction).restrictionType, + modifications: (transaction as AccountAddressRestrictionTransaction). modifications.map((modification) => { return modification.toDTO(); }), }; - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION: + case TransactionType.ACCOUNT_RESTRICTION_OPERATION: return { - restrictionType: (transaction as AccountOperationRestrictionModificationTransaction).restrictionType, - modifications: (transaction as AccountOperationRestrictionModificationTransaction). + restrictionType: (transaction as AccountOperationRestrictionTransaction).restrictionType, + modifications: (transaction as AccountOperationRestrictionTransaction). modifications.map((modification) => { return modification.toDTO(); }), }; - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC: + case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: return { - restrictionType: (transaction as AccountMosaicRestrictionModificationTransaction).restrictionType, - modifications: (transaction as AccountMosaicRestrictionModificationTransaction).modifications.map((modification) => { + restrictionType: (transaction as AccountMosaicRestrictionTransaction).restrictionType, + modifications: (transaction as AccountMosaicRestrictionTransaction).modifications.map((modification) => { return modification.toDTO(); }), }; diff --git a/src/model/model.ts b/src/model/model.ts index 2c0c7a755b..f9ecae784e 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -92,9 +92,9 @@ export * from './receipt/Statement'; // Transaction export * from './transaction/AccountLinkTransaction'; export * from './transaction/AccountRestrictionTransaction'; -export * from './transaction/AccountAddressRestrictionModificationTransaction'; -export * from './transaction/AccountOperationRestrictionModificationTransaction'; -export * from './transaction/AccountMosaicRestrictionModificationTransaction'; +export * from './transaction/AccountAddressRestrictionTransaction'; +export * from './transaction/AccountMosaicRestrictionTransaction'; +export * from './transaction/AccountMosaicRestrictionTransaction'; export * from './transaction/AccountRestrictionModification'; export * from './transaction/AddressAliasTransaction'; export * from './transaction/AggregateTransaction'; diff --git a/src/model/mosaic/MosaicFlag.ts b/src/model/mosaic/MosaicFlag.ts new file mode 100644 index 0000000000..dcf6a8b500 --- /dev/null +++ b/src/model/mosaic/MosaicFlag.ts @@ -0,0 +1,25 @@ +/* + * Copyright 2018 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. + */ +export enum MosaicFlags { + /** No flags present. */ + NONE = 0, + /** Mosaic supports supply changes even when mosaic owner owns partial supply. */ + SUPPLY_MUTABLE = 1, + /** Mosaic supports transfers between arbitrary accounts \note when not set, mosaic can only be transferred to and from mosaic owner. */ + TRANSFERABLE = 2, + /** Mosaic supports custom restrictions configured by mosaic owner. */ + RESTRICTABLE = 4, +} diff --git a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts similarity index 64% rename from src/model/transaction/AccountAddressRestrictionModificationTransaction.ts rename to src/model/transaction/AccountAddressRestrictionTransaction.ts index 822bc9d284..f894211d01 100644 --- a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -14,8 +14,17 @@ * limitations under the License. */ +import { RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; +import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -27,7 +36,7 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -export class AccountAddressRestrictionModificationTransaction extends Transaction { +export class AccountAddressRestrictionTransaction extends Transaction { /** * Create a modify account address restriction transaction object @@ -36,15 +45,15 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio * @param modifications - The array of modifications. * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountAddressRestrictionModificationTransaction} + * @returns {AccountAddressRestrictionTransaction} */ public static create(deadline: Deadline, restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, - maxFee: UInt64 = new UInt64([0, 0])): AccountAddressRestrictionModificationTransaction { - return new AccountAddressRestrictionModificationTransaction(networkType, - TransactionVersion.MODIFY_ACCOUNT_RESTRICTION_ADDRESS, + maxFee: UInt64 = new UInt64([0, 0])): AccountAddressRestrictionTransaction { + return new AccountAddressRestrictionTransaction(networkType, + TransactionVersion.ACCOUNT_RESTRICTION_ADDRESS, deadline, maxFee, restrictionType, @@ -71,15 +80,15 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio signature?: string, signer?: PublicAccount, transactionInfo?: TransactionInfo) { - super(TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS, + super(TransactionType.ACCOUNT_RESTRICTION_ADDRESS, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } /** * @override Transaction.size() - * @description get the byte size of a AccountAddressRestrictionModificationTransaction + * @description get the byte size of a AccountAddressRestrictionTransaction * @returns {number} - * @memberof AccountAddressRestrictionModificationTransaction + * @memberof AccountAddressRestrictionTransaction */ public get size(): number { const byteSize = super.size; @@ -110,4 +119,29 @@ export class AccountAddressRestrictionModificationTransaction extends Transactio .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountAddressRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountAddressRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedAddressDto(RawAddress.stringToAddress(modification.value)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index 78915b03a3..41e00509b0 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -14,8 +14,15 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountLinkTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/AccountLinkTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; @@ -111,4 +118,24 @@ export class AccountLinkTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountLinkTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.LINK_ACCOUNT.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new KeyDto(Convert.hexToUint8(this.remoteAccountKey)), + this.linkAction.valueOf(), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts similarity index 65% rename from src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts rename to src/model/transaction/AccountMosaicRestrictionTransaction.ts index 9de6449f61..edca3a7f89 100644 --- a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -17,6 +17,14 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountRestrictionType } from '../account/AccountRestrictionType'; +import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; +import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; @@ -27,7 +35,7 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -export class AccountMosaicRestrictionModificationTransaction extends Transaction { +export class AccountMosaicRestrictionTransaction extends Transaction { /** * Create a modify account mosaic restriction transaction object @@ -36,15 +44,15 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction * @param modifications - The array of modifications. * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountAddressRestrictionModificationTransaction} + * @returns {AccountAddressRestrictionTransaction} */ public static create(deadline: Deadline, restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, - maxFee: UInt64 = new UInt64([0, 0])): AccountMosaicRestrictionModificationTransaction { - return new AccountMosaicRestrictionModificationTransaction(networkType, - TransactionVersion.MODIFY_ACCOUNT_RESTRICTION_MOSAIC, + maxFee: UInt64 = new UInt64([0, 0])): AccountMosaicRestrictionTransaction { + return new AccountMosaicRestrictionTransaction(networkType, + TransactionVersion.ACCOUNT_RESTRICTION_MOSAIC, deadline, maxFee, restrictionType, @@ -71,15 +79,15 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction signature?: string, signer?: PublicAccount, transactionInfo?: TransactionInfo) { - super(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC, + super(TransactionType.ACCOUNT_RESTRICTION_MOSAIC, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } /** * @override Transaction.size() - * @description get the byte size of a AccountMosaicRestrictionModificationTransaction + * @description get the byte size of a AccountMosaicRestrictionTransaction * @returns {number} - * @memberof AccountMosaicRestrictionModificationTransaction + * @memberof AccountMosaicRestrictionTransaction */ public get size(): number { const byteSize = super.size; @@ -110,4 +118,29 @@ export class AccountMosaicRestrictionModificationTransaction extends Transaction .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountMosaicRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_MOSAIC.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountMosaicRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedMosaicIdDto(modification.value), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts similarity index 67% rename from src/model/transaction/AccountOperationRestrictionModificationTransaction.ts rename to src/model/transaction/AccountOperationRestrictionTransaction.ts index 45788393e3..b0b1e8ccdd 100644 --- a/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -26,8 +26,15 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; -export class AccountOperationRestrictionModificationTransaction extends Transaction { +export class AccountOperationRestrictionTransaction extends Transaction { /** * Create a modify account operation restriction type transaction object @@ -36,14 +43,14 @@ export class AccountOperationRestrictionModificationTransaction extends Transact * @param modifications - The array of modifications. * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountOperationRestrictionModificationTransaction} + * @returns {AccountOperationRestrictionTransaction} */ public static create(deadline: Deadline, restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, - maxFee: UInt64 = new UInt64([0, 0])): AccountOperationRestrictionModificationTransaction { - return new AccountOperationRestrictionModificationTransaction(networkType, + maxFee: UInt64 = new UInt64([0, 0])): AccountOperationRestrictionTransaction { + return new AccountOperationRestrictionTransaction(networkType, TransactionVersion.MODIFY_ACCOUNT_RESTRICTION_ENTITY_TYPE, deadline, maxFee, @@ -71,15 +78,15 @@ export class AccountOperationRestrictionModificationTransaction extends Transact signature?: string, signer?: PublicAccount, transactionInfo?: TransactionInfo) { - super(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION, + super(TransactionType.ACCOUNT_RESTRICTION_OPERATION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } /** * @override Transaction.size() - * @description get the byte size of a AccountOperationRestrictionModificationTransaction + * @description get the byte size of a AccountOperationRestrictionTransaction * @returns {number} - * @memberof AccountOperationRestrictionModificationTransaction + * @memberof AccountOperationRestrictionTransaction */ public get size(): number { const byteSize = super.size; @@ -110,4 +117,29 @@ export class AccountOperationRestrictionModificationTransaction extends Transact .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountOperationRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_OPERATION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountOperationRestrictionModificationBuilder( + modification.modificationType.valueOf(), + modification.value.valueOf(), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountRestrictionTransaction.ts b/src/model/transaction/AccountRestrictionTransaction.ts index 1ebbbf7849..33ee6cd715 100644 --- a/src/model/transaction/AccountRestrictionTransaction.ts +++ b/src/model/transaction/AccountRestrictionTransaction.ts @@ -17,9 +17,9 @@ import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; -import { AccountAddressRestrictionModificationTransaction } from './AccountAddressRestrictionModificationTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from './AccountMosaicRestrictionModificationTransaction'; -import { AccountOperationRestrictionModificationTransaction } from './AccountOperationRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from './AccountAddressRestrictionTransaction'; +import { AccountMosaicRestrictionTransaction } from './AccountMosaicRestrictionTransaction'; +import { AccountOperationRestrictionTransaction } from './AccountOperationRestrictionTransaction'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; import { TransactionType } from './TransactionType'; @@ -32,7 +32,7 @@ export class AccountRestrictionTransaction { * @param modification - array of address modifications * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountAddressRestrictionModificationTransaction} + * @returns {AccountAddressRestrictionTransaction} */ public static createAddressRestrictionModificationTransaction( deadline: Deadline, @@ -47,7 +47,7 @@ export class AccountRestrictionTransaction { AccountRestrictionType.BlockIncomingAddress].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } - return AccountAddressRestrictionModificationTransaction.create( + return AccountAddressRestrictionTransaction.create( deadline, restrictionType, modifications, @@ -63,7 +63,7 @@ export class AccountRestrictionTransaction { * @param modification - array of mosaic modifications * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountMosaicRestrictionModificationTransaction} + * @returns {AccountMosaicRestrictionTransaction} */ public static createMosaicRestrictionModificationTransaction( deadline: Deadline, @@ -75,7 +75,7 @@ export class AccountRestrictionTransaction { if (![AccountRestrictionType.AllowMosaic,AccountRestrictionType.BlockMosaic].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } - return AccountMosaicRestrictionModificationTransaction.create( + return AccountMosaicRestrictionTransaction.create( deadline, restrictionType, modifications, @@ -106,7 +106,7 @@ export class AccountRestrictionTransaction { AccountRestrictionType.BlockOutgoingTransactionType].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } - return AccountOperationRestrictionModificationTransaction.create( + return AccountOperationRestrictionTransaction.create( deadline, restrictionType, modifications, diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index c52a9efbed..b1b449dc69 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -16,6 +16,14 @@ import { Builder } from '../../infrastructure/builders/AddressAliasTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; +import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; +import { AddressDto } from '../../infrastructure/catbuffer/AddressDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -27,6 +35,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { RawAddress } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -126,4 +135,25 @@ export class AddressAliasTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AddressAliasTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ADDRESS_ALIAS.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new AddressDto(RawAddress.stringToAddress(this.address.plain())), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 26ace13e3b..5c5fbcadca 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -214,4 +214,12 @@ export class AggregateTransaction extends Transaction { return byteSize + byteTransactionsSize + byteTransactions; } -} \ No newline at end of file + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } +} diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index 4036654043..9ad23c1a60 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -137,4 +137,11 @@ export class LockFundsTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index e8afe30251..dbc22505a7 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -14,8 +14,15 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MultisigModificationTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { CosignatoryModificationBuilder } from '../../infrastructure/catbuffer/CosignatoryModificationBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; @@ -112,7 +119,7 @@ export class ModifyMultisigAccountTransaction extends Transaction { // each modification contains : // - 1 byte for modificationType // - 32 bytes for cosignatoryPublicKey - const byteModifications = 33 * this.modifications.length + const byteModifications = 33 * this.modifications.length; return byteSize + byteRemovalDelta + byteApprovalDelta + byteNumModifications + byteModifications; } @@ -132,4 +139,30 @@ export class ModifyMultisigAccountTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MultisigAccountModificationTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MODIFY_MULTISIG_ACCOUNT.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.minRemovalDelta, + this.minApprovalDelta, + this.modifications.map((modification) => { + return new CosignatoryModificationBuilder( + modification.type.valueOf(), + new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index 8c03b28ab6..3bc49806c6 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -150,4 +150,11 @@ export class MosaicAddressRestrictionTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index 8220ccea1e..2ae1588994 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -16,6 +16,14 @@ import { Builder } from '../../infrastructure/builders/MosaicAliasTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/MosaicAliasTransactionBuilder'; +import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; +import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { MosaicId } from '../mosaic/MosaicId'; @@ -122,4 +130,25 @@ export class MosaicAliasTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicAliasTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_ALIAS.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index b82844ab41..7a41faddf9 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -27,6 +27,19 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; +import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; +import { MosaicFlagsDto } from '../../infrastructure/catbuffer/MosaicFlagsDto'; +import { MosaicFlags } from '../mosaic/MosaicFlag'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { Convert } from '../../core/format'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; /** * Before a mosaic can be created or transferred, a corresponding definition of the mosaic has to be created and published to the network. @@ -115,6 +128,37 @@ export class MosaicDefinitionTransaction extends Transaction { return byteSize + byteNonce + byteMosaicId + byteNumProps + byteFlags + byteDivisibility + byteDurationSize + byteDuration; } + /** + * @description get the calculated mosaic flag value + * @returns {number} + * @memberof MosaicDefinitionTransaction + */ + public getMosaicFlagValue(): number { + let flag = MosaicFlags.NONE; + if (this.mosaicProperties.supplyMutable === true) { + flag += MosaicFlags.SUPPLY_MUTABLE; + } + + if (this.mosaicProperties.transferable === true) { + flag += MosaicFlags.TRANSFERABLE; + } + + if (this.mosaicProperties.restrictable === true) { + flag += MosaicFlags.RESTRICTABLE; + } + + return flag.valueOf(); + } + + /** + * @description Get mosaic nonce int value + * @returns {number} + * @memberof MosaicDefinitionTransaction + */ + public getMosaicNonceIntValue(): number { + return GeneratorUtils.readUint32At(this.nonce.toDTO(), 0); + } + /** * @internal * @returns {VerifiableTransaction} @@ -144,4 +188,28 @@ export class MosaicDefinitionTransaction extends Transaction { return mosaicDefinitionTransaction.build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicDefinitionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_DEFINITION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new MosaicNonceDto(this.getMosaicNonceIntValue()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + this.getMosaicFlagValue(), + this.mosaicProperties.divisibility, + new BlockDurationDto(this.mosaicProperties.duration ? + this.mosaicProperties.duration.toDTO() : []), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index 7530eba330..7cbb7a55d5 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -173,4 +173,11 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index 39b33d8318..b53fbd92d3 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -16,6 +16,12 @@ import { Builder } from '../../infrastructure/builders/MosaicSupplyChangeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { MosaicId } from '../mosaic/MosaicId'; @@ -125,4 +131,25 @@ export class MosaicSupplyChangeTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicSupplyChangeTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_SUPPLY_CHANGE.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + this.direction.valueOf(), + new AmountDto(this.delta.toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index da05639507..f1f29cd6a2 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -182,4 +182,11 @@ export class RegisterNamespaceTransaction extends Transaction { return registerNamespacetransaction.build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index 6862dc7a3b..9e02785071 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -13,9 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Convert as convert } from '../../core/format'; +import { Convert as convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/SecretLockTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SecretLockTransactionBuilder } from '../../infrastructure/catbuffer/SecretLockTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from '../../infrastructure/catbuffer/UnresolvedMosaicBuilder'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -134,6 +145,15 @@ export class SecretLockTransaction extends Transaction { return byteSize + byteMosaicId + byteAmount + byteDuration + byteAlgorithm + byteRecipient + byteSecret; } + /** + * @description Get secret bytes + * @returns {Uint8Array} + * @memberof SecretLockTransaction + */ + public getSecretByte(): Uint8Array { + return convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); + } + /** * @internal * @returns {VerifiableTransaction} @@ -153,4 +173,28 @@ export class SecretLockTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new SecretLockTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_LOCK.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), + new AmountDto(this.mosaic.amount.toDTO())), + new BlockDurationDto(this.duration.toDTO()), + this.hashType.valueOf(), + new Hash256Dto(this.getSecretByte()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipient.plain())), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index cf41678857..588638fcc6 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -14,9 +14,17 @@ * limitations under the License. */ -import { Convert as convert } from '../../core/format'; +import { Convert, Convert as convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/SecretProofTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SecretProofTransactionBuilder } from '../../infrastructure/catbuffer/SecretProofTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -113,6 +121,24 @@ export class SecretProofTransaction extends Transaction { return byteSize + byteAlgorithm + byteSecret + byteRecipient + byteProofSize + byteProof; } + /** + * @description Get secret bytes + * @returns {Uint8Array} + * @memberof SecretLockTransaction + */ + public getSecretByte(): Uint8Array { + return convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); + } + + /** + * @description Get proof bytes + * @returns {Uint8Array} + * @memberof SecretLockTransaction + */ + public getProofByte(): Uint8Array { + return convert.hexToUint8(this.proof); + } + /** * @internal * @returns {VerifiableTransaction} @@ -130,4 +156,26 @@ export class SecretProofTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new SecretProofTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_PROOF.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + this.hashType.valueOf(), + new Hash256Dto(this.getSecretByte()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipient.plain())), + this.getProofByte(), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index 63fb543965..0bc6786fb3 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -import { SignSchema } from '../../core/crypto'; +import { KeyPair, SHA3Hasher, SignSchema } from '../../core/crypto'; +import { Convert } from '../../core/format'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { SerializeTransactionToJSON } from '../../infrastructure/transaction/SerializeTransactionToJSON'; import { Account } from '../account/Account'; @@ -79,6 +80,16 @@ export abstract class Transaction { public readonly transactionInfo?: TransactionInfo | AggregateTransactionInfo) { } + /** + * @internal + */ + protected abstract buildTransaction(): VerifiableTransaction; + + /** + * @internal + */ + protected abstract generateBytes(): Uint8Array; + /** * @internal * Serialize and sign transaction creating a new SignedTransaction @@ -100,8 +111,55 @@ export abstract class Transaction { /** * @internal + * Serialize and sign transaction creating a new SignedTransaction + * @param account - The account to sign the transaction + * @param generationHash - Network generation hash hex + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {SignedTransaction} */ - protected abstract buildTransaction(): VerifiableTransaction; + public signWithCatbuffer(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { + const generationHashBytes = Array.from(Convert.hexToUint8(generationHash)); + const byteBuffer = Array.from(this.generateBytes()); + const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); + const keyPairEncoded = KeyPair.createKeyPairFromPrivateKeyString(account.privateKey, signSchema); + const signature = Array.from(KeyPair.sign(account, new Uint8Array(signingBytes), signSchema)); + const signedTransactionBuffer = byteBuffer + .splice(0, 4) + .concat(signature) + .concat(Array.from(keyPairEncoded.publicKey)) + .concat(byteBuffer + .splice(64 + 32, byteBuffer.length)); + const payload = Convert.uint8ToHex(signedTransactionBuffer); + return new SignedTransaction( + payload, + this.createTransactionHash(payload, generationHashBytes), + account.publicKey, + this.type, + this.networkType); + } + + /** + * Generate transaction hash hex + * @param {string} transactionPayload HexString Payload + * @param {Array} generationHashBuffer Network generation hash byte + * @returns {string} Returns Transaction Payload hash + */ + public createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { + const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); + const signingBytes = byteBuffer + .slice(4, 36) + .concat(byteBuffer + .slice(4 + 64, 4 + 64 + 32)) + .concat(generationHashBuffer) + .concat(byteBuffer + .splice(4 + 64 + 32, byteBuffer.length)); + + const hash = new Uint8Array(32); + + SHA3Hasher.func(hash, signingBytes, 32); + + return Convert.uint8ToHex(hash); + } /** * @internal diff --git a/src/model/transaction/TransactionType.ts b/src/model/transaction/TransactionType.ts index 7b2b000adf..9d571f0855 100644 --- a/src/model/transaction/TransactionType.ts +++ b/src/model/transaction/TransactionType.ts @@ -15,114 +15,116 @@ */ /** - * Static class containing transaction type constants. + * Enum containing transaction type constants. */ -export class TransactionType { +export enum TransactionType { + /** Reserved entity type. */ + RESERVED = 0, /** * Transfer Transaction transaction type. * @type {number} */ - public static readonly TRANSFER = 0x4154; + TRANSFER = 0x4154, /** * Register namespace transaction type. * @type {number} */ - public static readonly REGISTER_NAMESPACE = 0x414E; + REGISTER_NAMESPACE = 0x414E, /** * Address alias transaction type * @type {number} */ - public static readonly ADDRESS_ALIAS = 0x424E; + ADDRESS_ALIAS = 0x424E, /** * Mosaic alias transaction type * @type {number} */ - public static readonly MOSAIC_ALIAS = 0x434E; + MOSAIC_ALIAS = 0x434E, /** * Mosaic definition transaction type. * @type {number} */ - public static readonly MOSAIC_DEFINITION = 0x414D; + MOSAIC_DEFINITION = 0x414D, /** * Mosaic supply change transaction. * @type {number} */ - public static readonly MOSAIC_SUPPLY_CHANGE = 0x424D; + MOSAIC_SUPPLY_CHANGE = 0x424D, /** * Modify multisig account transaction type. * @type {number} */ - public static readonly MODIFY_MULTISIG_ACCOUNT = 0x4155; + MODIFY_MULTISIG_ACCOUNT = 0x4155, /** * Aggregate complete transaction type. * @type {number} */ - public static readonly AGGREGATE_COMPLETE = 0x4141; + AGGREGATE_COMPLETE = 0x4141, /** * Aggregate bonded transaction type */ - public static readonly AGGREGATE_BONDED = 0x4241; + AGGREGATE_BONDED = 0x4241, /** * Lock transaction type * @type {number} */ - public static readonly LOCK = 0x4148; + LOCK = 0x4148, /** * Secret Lock Transaction type * @type {number} */ - public static readonly SECRET_LOCK = 0x4152; + SECRET_LOCK = 0x4152, /** * Secret Proof transaction type * @type {number} */ - public static readonly SECRET_PROOF = 0x4252; + SECRET_PROOF = 0x4252, /** * Account restriction address transaction type * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_ADDRESS = 0x4150; + ACCOUNT_RESTRICTION_ADDRESS = 0x4150, /** * Account restriction mosaic transaction type * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_MOSAIC = 0x4250; + ACCOUNT_RESTRICTION_MOSAIC = 0x4250, /** * Account restriction operation transaction type * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_OPERATION = 0x4350; + ACCOUNT_RESTRICTION_OPERATION = 0x4350, /** * Link account transaction type * @type {number} */ - public static readonly LINK_ACCOUNT = 0x414C; + LINK_ACCOUNT = 0x414C, /** * Mosaic address restriction type * @type {number} */ - public static readonly MOSAIC_ADDRESS_RESTRICTION = 0x4251; + MOSAIC_ADDRESS_RESTRICTION = 0x4251, /** * Mosaic global restriction type * @type {number} */ - public static readonly MOSAIC_GLOBAL_RESTRICTION = 0x4151; + MOSAIC_GLOBAL_RESTRICTION = 0x4151, } diff --git a/src/model/transaction/TransactionVersion.ts b/src/model/transaction/TransactionVersion.ts index 953c35e096..71087ac326 100644 --- a/src/model/transaction/TransactionVersion.ts +++ b/src/model/transaction/TransactionVersion.ts @@ -116,13 +116,13 @@ export class TransactionVersion { * Account Restriction address transaction version * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_ADDRESS = 0x01; + public static readonly ACCOUNT_RESTRICTION_ADDRESS = 0x01; /** * Account Restriction mosaic transaction version * @type {number} */ - public static readonly MODIFY_ACCOUNT_RESTRICTION_MOSAIC = 0x01; + public static readonly ACCOUNT_RESTRICTION_MOSAIC = 0x01; /** * Account Restriction operation transaction version diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 880374187d..31dea94577 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -14,9 +14,20 @@ * limitations under the License. */ -import { Convert as convert } from '../../core/format'; +import { Convert, Convert as convert } from '../../core/format'; +import { RawAddress } from '../../core/format/RawAddress'; import { Builder } from '../../infrastructure/builders/TransferTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { TransferTransactionBuilder } from '../../infrastructure/catbuffer/TransferTransactionBuilder'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; +import { UnresolvedMosaicBuilder } from '../../infrastructure/catbuffer/UnresolvedMosaicBuilder'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -109,6 +120,30 @@ export class TransferTransaction extends Transaction { return (this.recipient as Address).plain(); } + /** + * Return sorted mosaic arrays + * @internal + * @returns {Mosaic[]} + */ + public sortMosaics(): Mosaic[] { + const sortedMosaics = this.mosaics.sort((a, b) => { + if (Number(a.id[1]) > b.id[1]) { return 1; } else if (a.id[1] < b.id[1]) { return -1; } + return 0; + }); + return sortedMosaics; + } + + /** + * Return message buffer + * @internal + * @returns {Uint8Array} + */ + public getMessageBuffer(): Uint8Array { + const payloadBuffer = Convert.hexToUint8(Convert.utf8ToHex(this.message.payload)); + const typeBuffer = GeneratorUtils.uintToBuffer(this.message.type, 1); + return GeneratorUtils.concatTypedArrays(typeBuffer, payloadBuffer); + } + /** * @override Transaction.size() * @description get the byte size of a TransferTransaction @@ -146,4 +181,28 @@ export class TransferTransaction extends Transaction { .build(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new TransferTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.TRANSFER.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), + this.getMessageBuffer(), + this.sortMosaics().map((mosaic) => { + return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), + new AmountDto(mosaic.amount.toDTO())); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index 29d45b2c40..ebcfcf0734 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -37,7 +37,7 @@ import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { NamespaceType } from '../../../src/model/namespace/NamespaceType'; import { AccountAddressRestrictionModificationTransaction } from'../../../src/model/transaction/AccountAddressRestrictionModificationTransaction'; import { AccountLinkTransaction } from '../../../src/model/transaction/AccountLinkTransaction'; -import { AccountMosaicRestrictionModificationTransaction } from '../../../src/model/transaction/AccountMosaicRestrictionModificationTransaction'; +import { AccountMosaicRestrictionTransaction } from '../../../src/model/transaction/AccountMosaicRestrictionTransaction'; import { AccountRestrictionModification } from '../../../src/model/transaction/AccountRestrictionModification'; import { AccountRestrictionTransaction } from '../../../src/model/transaction/AccountRestrictionTransaction'; import { AddressAliasTransaction } from '../../../src/model/transaction/AddressAliasTransaction'; @@ -87,7 +87,7 @@ describe('TransactionMapping - createFromPayload', () => { const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); const transaction = TransactionMapping - .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; + .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionTransaction; expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); @@ -672,7 +672,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const transaction = - TransactionMapping.createFromDTO(addressRestrictionTransaction.toJSON()) as AccountAddressRestrictionModificationTransaction; + TransactionMapping.createFromDTO(addressRestrictionTransaction.toJSON()) as AccountAddressRestrictionTransaction; expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); @@ -693,7 +693,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const transaction = - TransactionMapping.createFromDTO(mosaicRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; + TransactionMapping.createFromDTO(mosaicRestrictionTransaction.toJSON()) as AccountMosaicRestrictionTransaction; expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC); expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowMosaic); @@ -714,7 +714,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const transaction = - TransactionMapping.createFromDTO(operationRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction; + TransactionMapping.createFromDTO(operationRestrictionTransaction.toJSON()) as AccountMosaicRestrictionTransaction; expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType); diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index 68c65c8eae..0d5b8c8b25 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountLinkTransaction', () => { expect(accountLinkTransaction.linkAction).to.be.equal(0); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); - const signedTransaction = accountLinkTransaction.signWith(account, generationHash); + const signedTransaction = accountLinkTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index eeb10081ff..753a431d02 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountRestrictionTransaction', () => { }); describe('size', () => { - it('should return 148 for AccountAddressRestrictionModificationTransaction transaction byte size with 1 modification', () => { + it('should return 148 for AccountAddressRestrictionTransaction transaction byte size with 1 modification', () => { const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); const addressRestrictionFilter = AccountRestrictionModification.createForAddress( RestrictionModificationType.Add, @@ -82,7 +82,7 @@ describe('AccountRestrictionTransaction', () => { expect(addressRestrictionTransaction.size).to.be.equal(148); }); - it('should return 131 for AccountMosaicRestrictionModificationTransaction transaction byte size with 1 modification', () => { + it('should return 131 for AccountMosaicRestrictionTransaction transaction byte size with 1 modification', () => { const mosaicId = new MosaicId([2262289484, 3405110546]); const mosaicRestrictionFilter = AccountRestrictionModification.createForMosaic( RestrictionModificationType.Add, @@ -97,7 +97,7 @@ describe('AccountRestrictionTransaction', () => { expect(mosaicRestrictionTransaction.size).to.be.equal(131); }); - it('should return 125 for AccountOperationRestrictionModificationTransaction transaction byte size with 1 modification', () => { + it('should return 125 for AccountOperationRestrictionTransaction transaction byte size with 1 modification', () => { const operation = TransactionType.ADDRESS_ALIAS; const operationRestrictionFilter = AccountRestrictionModification.createForOperation( RestrictionModificationType.Add, @@ -162,7 +162,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = addressRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -213,7 +213,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -266,7 +266,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = operationRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index 3111de06cb..2721b583d9 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('AddressAliasTransaction', () => { expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = addressAliasTransaction.signWith(account, generationHash); + const signedTransaction = addressAliasTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index f6065c02b3..c1c549a0b6 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -110,7 +110,7 @@ describe('ModifyMultisigAccountTransaction', () => { expect(modifyMultisigAccountTransaction.modifications[1].cosignatoryPublicAccount.publicKey) .to.be.equal('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); - const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); + const signedTransaction = modifyMultisigAccountTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index 0cf1077609..a9314a0c54 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -56,7 +56,7 @@ describe('MosaicAliasTransaction', () => { namespaceId, mosaicId, NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(mosaicAliasTransaction.maxFee.higher).to.be.equal(0); @@ -80,7 +80,7 @@ describe('MosaicAliasTransaction', () => { expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); expect(mosaicAliasTransaction.mosaicId.id.higher).to.be.equal(3405110546); - const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); + const signedTransaction = mosaicAliasTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index 5c15bafa89..688506516b 100644 --- a/test/model/transaction/MosaicDefinitionTransaction.spec.ts +++ b/test/model/transaction/MosaicDefinitionTransaction.spec.ts @@ -93,12 +93,12 @@ describe('MosaicDefinitionTransaction', () => { expect(mosaicDefinitionTransaction.mosaicProperties.transferable).to.be.equal(true); expect(mosaicDefinitionTransaction.mosaicProperties.restrictable).to.be.equal(true); - const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicDefinitionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('E6DE84B8010000000000000001070302E803000000000000'); + )).to.be.equal('E6DE84B801000000000000000703E803000000000000'); }); diff --git a/test/model/transaction/SecretLockTransaction.spec.ts b/test/model/transaction/SecretLockTransaction.spec.ts index 26bbd11ede..9f240dda47 100644 --- a/test/model/transaction/SecretLockTransaction.spec.ts +++ b/test/model/transaction/SecretLockTransaction.spec.ts @@ -18,6 +18,7 @@ import {expect} from 'chai'; import * as CryptoJS from 'crypto-js'; import {keccak_256, sha3_256} from 'js-sha3'; import {Convert as convert} from '../../../src/core/format'; +import { Account } from '../../../src/model/account/Account'; import {Address} from '../../../src/model/account/Address'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; @@ -25,9 +26,14 @@ import {Deadline} from '../../../src/model/transaction/Deadline'; import {HashType} from '../../../src/model/transaction/HashType'; import {SecretLockTransaction} from '../../../src/model/transaction/SecretLockTransaction'; import {UInt64} from '../../../src/model/UInt64'; +import { TestingAccount } from '../../conf/conf.spec'; describe('SecretLockTransaction', () => { - + let account: Account; + const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; + before(() => { + account = TestingAccount; + }); it('should default maxFee field be set to 0', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; const recipient = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); @@ -56,7 +62,7 @@ describe('SecretLockTransaction', () => { sha3_256.create().update(convert.hexToUint8(proof)).hex(), recipient, NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(secretLockTransaction.maxFee.higher).to.be.equal(0); @@ -83,6 +89,27 @@ describe('SecretLockTransaction', () => { expect(secretLockTransaction.recipient).to.be.equal(recipient); }); + it('should be created and sign SecretLock Transaction', () => { + const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; + const recipient = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const secretLockTransaction = SecretLockTransaction.create( + Deadline.create(), + NetworkCurrencyMosaic.createAbsolute(10), + UInt64.fromUint(100), + HashType.Op_Sha3_256, + sha3_256.create().update(convert.hexToUint8(proof)).hex(), + recipient, + NetworkType.MIJIN_TEST, + ); + const signedTx = secretLockTransaction.signWithCatbuffer(account, generationHash); + expect(signedTx.payload.substring( + 240, + signedTx.payload.length, + )).to.be.equal( + '44B262C46CEABB850A000000000000006400000000000000009B3155B37159DA50AA52D5967C509B41' + + '0F5A36A3B1E31ECB5AC76675D79B4A5E90C2337113E6D8F15B56E0821149299F340C01706FC1CAD6CB'); + }); + it('should throw exception when the input is not related to HashTyp: Op_Sha3_256', () => { expect(() => { const recipient = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); diff --git a/test/model/transaction/SecretProofTransaction.spec.ts b/test/model/transaction/SecretProofTransaction.spec.ts index 6ee0b3aaab..8712f1ca9e 100644 --- a/test/model/transaction/SecretProofTransaction.spec.ts +++ b/test/model/transaction/SecretProofTransaction.spec.ts @@ -27,7 +27,7 @@ import { TestingAccount } from '../../conf/conf.spec'; describe('SecretProofTransaction', () => { let account: Account; - + const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; before(() => { account = TestingAccount; }); @@ -191,4 +191,24 @@ describe('SecretProofTransaction', () => { expect(secretProofTransaction.size).to.be.equal(212); }); }); + + it('should create and sign SecretProof Transaction', () => { + const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; + const secretProofTransaction = SecretProofTransaction.create( + Deadline.create(), + HashType.Op_Sha3_256, + sha3_256.create().update(convert.hexToUint8(proof)).hex(), + account.address, + proof, + NetworkType.MIJIN_TEST, + ); + + const signedTx = secretProofTransaction.signWithCatbuffer(account, generationHash); + expect(signedTx.payload.substring( + 240, + signedTx.payload.length, + )).to.be.equal( + '009B3155B37159DA50AA52D5967C509B410F5A36A3B1E31ECB5AC76675D79B4A5E90A75B6B63D31BDA938' + + '08727940F24699AECDDF17C568508BA2000B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'); + }); }); diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index c378c39c32..8e8b4cc9d4 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -238,4 +238,8 @@ class FakeTransaction extends Transaction { protected buildTransaction(): VerifiableTransaction { throw new Error('Method not implemented.'); } + + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/test/model/transaction/TransferTransaction.spec.ts b/test/model/transaction/TransferTransaction.spec.ts index 31e063be36..63d8bb880c 100644 --- a/test/model/transaction/TransferTransaction.spec.ts +++ b/test/model/transaction/TransferTransaction.spec.ts @@ -53,7 +53,7 @@ describe('TransferTransaction', () => { [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(transferTransaction.maxFee.higher).to.be.equal(0); @@ -193,4 +193,30 @@ describe('TransferTransaction', () => { expect(transaction.size).to.be.equal(158); }); }); + + it('should create TransferTransaction and sign using catbuffer', () => { + const transferTransaction = TransferTransaction.create( + Deadline.create(), + Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + [ + NetworkCurrencyMosaic.createRelative(100), + ], + PlainMessage.create('test-message'), + NetworkType.MIJIN_TEST, + ); + + expect(transferTransaction.message.payload).to.be.equal('test-message'); + expect(transferTransaction.mosaics.length).to.be.equal(1); + expect(transferTransaction.recipient).to.be.instanceof(Address); + expect((transferTransaction.recipient as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + + const signedTransaction = transferTransaction.signWithCatbuffer(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal( + '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000100746573742D6D657373616765' + + '44B262C46CEABB8500E1F50500000000'); + }); }); From da25ce775b95b00d7c4e9d6bc111ec7eb196a70b Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 22:38:29 +0100 Subject: [PATCH 62/98] Manually added aggregate transaction builder --- .../catbuffer/AggregateTransactionBuilder.ts | 136 ++++++++++++++++++ .../catbuffer/CosignatureBuilder.ts | 102 +++++++++++++ .../catbuffer/DetachedCosignatureBuilder.ts | 97 +++++++++++++ 3 files changed, 335 insertions(+) create mode 100644 src/infrastructure/catbuffer/AggregateTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/CosignatureBuilder.ts create mode 100644 src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts diff --git a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts new file mode 100644 index 0000000000..64b11c499f --- /dev/null +++ b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts @@ -0,0 +1,136 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; +import { AddressDto } from './AddressDto'; +import { AliasActionDto } from './AliasActionDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** binary layout for an aggregate transaction. */ +export class AggregateTransactionBuilder extends TransactionBuilder { + /** embedded transactions. */ + transactions: Uint8Array; + /** cosignatures. */ + cosignatures: Uint8Array; + + /** + * Constructor. + * + * @param signature entity signature. + * @param signer entity signer's public key. + * @param version entity version. + * @param type entity type. + * @param fee transaction fee. + * @param deadline transaction deadline. + * @param transactions embedded transactions. + * @param cosignatures cosignatures. + */ + public constructor( + signature: SignatureDto, + signer: KeyDto, + version: number, + type: EntityTypeDto, + fee: AmountDto, + deadline: TimestampDto, + transactions: Uint8Array, + cosignatures: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + this.transactions = transactions; + this.cosignatures = cosignatures; + } + + /** + * loadFromBinary - Create an instance of AggregateTransactionBuilder from a stream. + * + * @param Uint8Array Byte to use to serialize the object. + * @return An instance of AggregateTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AggregateTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const payloadSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + const transactions = GeneratorUtils.getBytes(Uint8Array.from(byteArray), payloadSize); + byteArray.splice(0, transactions.length); + const cosignatures = Uint8Array.from(byteArray); + // tslint:disable-next-line: max-line-length + return new AggregateTransactionBuilder(superObject.signature, superObject.signer, superObject.version, + superObject.type, superObject.fee, superObject.deadline, + transactions, cosignatures); + } + + /** + * Get embedded transactions. + * + * @return embedded transactions. + */ + public getTransactions(): Uint8Array { + return this.transactions; + } + + /** + * Get cosignatures. + * + * @return cosignatures. + */ + public getCosignatures(): Uint8Array { + return this.cosignatures; + } + + /** + * Get the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += 4; // payloadSize + size += this.transactions.length; + size += this.cosignatures.length; + return size; + } + + /** + * Serialize the object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const payloadSizeBytes = GeneratorUtils.uintToBuffer(this.transactions.length, 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes); + const transactionBytes = this.transactions; + newArray = GeneratorUtils.concatTypedArrays(newArray, transactionBytes); + const cosignaturesBytes = this.transactions; + newArray = GeneratorUtils.concatTypedArrays(newArray, cosignaturesBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/CosignatureBuilder.ts b/src/infrastructure/catbuffer/CosignatureBuilder.ts new file mode 100644 index 0000000000..5e0ba7a43c --- /dev/null +++ b/src/infrastructure/catbuffer/CosignatureBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; + +/** a cosignature. */ +export class CosignatureBuilder { + /** cosigner public key. */ + signer: KeyDto; + /** cosigner signature. */ + signature: SignatureDto; + + /** + * Constructor. + * + * @param signer cosigner public key. + * @param signature cosigner signature. + */ + public constructor(signer: KeyDto, signature: SignatureDto) { + this.signer = signer; + this.signature = signature; + } + + /** + * loadFromBinary - Create an instance of CosignatureBuilder from a stream. + * + * @param payload Byte to use to serialize the object. + * @return An instance of CosignatureBuilder. + */ + public static loadFromBinary(payload: Uint8Array): CosignatureBuilder { + const byteArray = Array.from(payload); + const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signer.getSize()); + const signature = SignatureDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signature.getSize()); + return new CosignatureBuilder(signer, signature); + } + + /** + * Get cosigner public key. + * + * @return cosigner public key. + */ + public getSigner(): KeyDto { + return this.signer; + } + + /** + * Get cosigner signature. + * + * @return cosigner signature. + */ + public getSignature(): SignatureDto { + return this.signature; + } + + /** + * Get the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += this.signer.getSize(); + size += this.signature.getSize(); + return size; + } + + /** + * Serialize the object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const signerBytes = this.signer.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); + const signatureBytes = this.signature.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signatureBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts b/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts new file mode 100644 index 0000000000..58a3152ed0 --- /dev/null +++ b/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts @@ -0,0 +1,97 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { CosignatureBuilder } from './CosignatureBuilder'; +import { Hash256Dto } from './Hash256Dto'; + +/** a detached cosignature. */ +export class DetachedCosignatureBuilder extends CosignatureBuilder { + /** hash of the corresponding parent. */ + parentHash: Hash256Dto; + + /** + * Constructor. + * + * @param signer cosigner public key. + * @param signature cosigner signature. + * @param parentHash hash of the corresponding parent. + */ + public constructor(signer: KeyDto, signature: SignatureDto, parentHash: Hash256Dto) { + super(signer, signature); + this.parentHash = parentHash; + } + + /** + * loadFromBinary - Create an instance of DetachedCosignatureBuilder from a stream. + * + * @param payload Byte to use to serialize the object. + * @return An instance of DetachedCosignatureBuilder. + */ + public static loadFromBinary(payload: Uint8Array): DetachedCosignatureBuilder { + const byteArray = Array.from(payload); + const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signer.getSize()); + const signature = SignatureDto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, signature.getSize()); + const parentHash = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, parentHash.getSize()); + return new DetachedCosignatureBuilder(signer, signature, parentHash); + } + + /** + * Get hash of the corresponding parent. + * + * @return hash of the corresponding parent. + */ + public getParentHash(): Hash256Dto { + return this.parentHash; + } + + /** + * Get the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = super.getSize(); + size += this.parentHash.getSize(); + return size; + } + + /** + * Serialize the object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const signerBytes = this.signer.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); + const signatureBytes = this.signature.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, signatureBytes); + const parentHashBytes = this.parentHash.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, parentHashBytes); + return newArray; + } +} From 6728a5d090202159ca42bd189b04218e6b1aaffe Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 23:43:48 +0100 Subject: [PATCH 63/98] Added embedded transaction builders --- .../AccountAddressRestrictionTransaction.ts | 23 ++++++ .../transaction/AccountLinkTransaction.ts | 18 +++++ .../AccountMosaicRestrictionTransaction.ts | 23 ++++++ .../AccountOperationRestrictionTransaction.ts | 36 +++++++-- .../transaction/AddressAliasTransaction.ts | 21 +++++- src/model/transaction/AggregateTransaction.ts | 8 ++ src/model/transaction/LockFundsTransaction.ts | 47 +++++++++++- .../ModifyMultisigAccountTransaction.ts | 24 ++++++ .../MosaicAddressRestrictionTransaction.ts | 47 +++++++++++- .../transaction/MosaicAliasTransaction.ts | 19 +++++ .../MosaicDefinitionTransaction.ts | 45 ++++++++---- .../MosaicGlobalRestrictionTransaction.ts | 49 ++++++++++++- .../MosaicSupplyChangeTransaction.ts | 19 +++++ .../RegisterNamespaceTransaction.ts | 73 ++++++++++++++++++- .../transaction/SecretLockTransaction.ts | 22 ++++++ .../transaction/SecretProofTransaction.ts | 20 +++++ src/model/transaction/Transaction.ts | 5 ++ src/model/transaction/TransferTransaction.ts | 21 ++++++ .../transaction/LockFundsTransaction.spec.ts | 30 +++++++- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- ...osaicAddressRestrictionTransaction.spec.ts | 2 +- ...MosaicGlobalRestrictionTransaction.spec.ts | 2 +- .../RegisterNamespaceTransaction.spec.ts | 4 +- test/model/transaction/Transaction.spec.ts | 4 + 24 files changed, 531 insertions(+), 33 deletions(-) diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index f894211d01..ec44d13a4b 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -20,6 +20,7 @@ import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTra import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -144,4 +145,26 @@ export class AccountAddressRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountAddressRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountAddressRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedAddressDto(RawAddress.stringToAddress(modification.value)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index 41e00509b0..0d8c60c32b 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -19,6 +19,7 @@ import { Builder } from '../../infrastructure/builders/AccountLinkTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/AccountLinkTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -138,4 +139,21 @@ export class AccountLinkTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountLinkTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.LINK_ACCOUNT.valueOf(), + new KeyDto(Convert.hexToUint8(this.remoteAccountKey)), + this.linkAction.valueOf(), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index edca3a7f89..98a6321b00 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -20,6 +20,7 @@ import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -143,4 +144,26 @@ export class AccountMosaicRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountMosaicRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_MOSAIC.valueOf(), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountMosaicRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedMosaicIdDto(modification.value), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index b0b1e8ccdd..704cabe56b 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -16,6 +16,13 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -26,13 +33,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; -import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; -import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; -import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; -import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; export class AccountOperationRestrictionTransaction extends Transaction { @@ -142,4 +142,26 @@ export class AccountOperationRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountOperationRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_OPERATION.valueOf(), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountOperationRestrictionModificationBuilder( + modification.modificationType.valueOf(), + modification.value.valueOf(), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index b1b449dc69..8be88d2be4 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -14,11 +14,13 @@ * limitations under the License. */ +import { RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AddressAliasTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; import { AddressDto } from '../../infrastructure/catbuffer/AddressDto'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; @@ -35,7 +37,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { RawAddress } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -156,4 +157,22 @@ export class AddressAliasTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAddressAliasTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ADDRESS_ALIAS.valueOf(), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new AddressDto(RawAddress.stringToAddress(this.address.plain())), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 5c5fbcadca..483c588592 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -222,4 +222,12 @@ export class AggregateTransaction extends Transaction { protected generateBytes(): Uint8Array { throw new Error('Not implemented'); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index 9ad23c1a60..52027d141d 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -14,8 +14,19 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/HashLockTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EmbeddedHashLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder'; +import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; +import { HashLockTransactionBuilder } from '../../infrastructure/catbuffer/HashLockTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicBuilder } from '../../infrastructure/catbuffer/UnresolvedMosaicBuilder'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { Mosaic } from '../mosaic/Mosaic'; @@ -142,6 +153,40 @@ export class LockFundsTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new HashLockTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.LOCK.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), + new AmountDto(this.mosaic.amount.toDTO())), + new BlockDurationDto(this.duration.toDTO()), + new Hash256Dto(Convert.hexToUint8(this.hash)), + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedHashLockTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.LOCK.valueOf(), + new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), + new AmountDto(this.mosaic.amount.toDTO())), + new BlockDurationDto(this.duration.toDTO()), + new Hash256Dto(Convert.hexToUint8(this.hash)), + ); + return transactionBuilder.serialize(); } } diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index dbc22505a7..f33e7af077 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -32,6 +32,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; /** * Modify multisig account transactions are part of the NEM's multisig account system. @@ -165,4 +166,27 @@ export class ModifyMultisigAccountTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMultisigAccountModificationTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MODIFY_MULTISIG_ACCOUNT.valueOf(), + this.minRemovalDelta, + this.minApprovalDelta, + this.modifications.map((modification) => { + return new CosignatoryModificationBuilder( + modification.type.valueOf(), + new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index 3bc49806c6..b1c62e0167 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -14,8 +14,17 @@ * limitations under the License. */ +import { RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicAddressRestrictionTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -155,6 +164,42 @@ export class MosaicAddressRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicAddressRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_ADDRESS_RESTRICTION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + this.restrictionKey.toDTO(), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.targetAddress.plain())), + this.previousRestrictionValue.toDTO(), + this.newRestrictionValue.toDTO(), + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicAddressRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_ADDRESS_RESTRICTION.valueOf(), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + this.restrictionKey.toDTO(), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.targetAddress.plain())), + this.previousRestrictionValue.toDTO(), + this.newRestrictionValue.toDTO(), + ); + return transactionBuilder.serialize(); } } diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index 2ae1588994..6e2e600ff8 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -17,6 +17,7 @@ import { Builder } from '../../infrastructure/builders/MosaicAliasTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { MosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/MosaicAliasTransactionBuilder'; @@ -151,4 +152,22 @@ export class MosaicAliasTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicAliasTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_ALIAS.valueOf(), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 7a41faddf9..8ac6e76eb0 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -16,8 +16,19 @@ import { Builder } from '../../infrastructure/builders/MosaicCreationTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EmbeddedMosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; +import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; +import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; +import { MosaicFlags } from '../mosaic/MosaicFlag'; import { MosaicId } from '../mosaic/MosaicId'; import { MosaicNonce } from '../mosaic/MosaicNonce'; import { MosaicProperties } from '../mosaic/MosaicProperties'; @@ -27,19 +38,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; -import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; -import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; -import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; -import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; -import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; -import { MosaicFlagsDto } from '../../infrastructure/catbuffer/MosaicFlagsDto'; -import { MosaicFlags } from '../mosaic/MosaicFlag'; -import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; -import { Convert } from '../../core/format'; -import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; /** * Before a mosaic can be created or transferred, a corresponding definition of the mosaic has to be created and published to the network. @@ -212,4 +210,25 @@ export class MosaicDefinitionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicDefinitionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_DEFINITION.valueOf(), + new MosaicNonceDto(this.getMosaicNonceIntValue()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + this.getMosaicFlagValue(), + this.mosaicProperties.divisibility, + new BlockDurationDto(this.mosaicProperties.duration ? + this.mosaicProperties.duration.toDTO() : []), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index 7cbb7a55d5..b2d421dca3 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -16,6 +16,13 @@ import { Builder } from '../../infrastructure/builders/MosaicGlobalRestrictionTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicGlobalRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicGlobalRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicGlobalRestrictionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -178,6 +185,46 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicGlobalRestrictionTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_GLOBAL_RESTRICTION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + new UnresolvedMosaicIdDto(this.referenceMosaicId.id.toDTO()), + this.restrictionKey.toDTO(), + this.previousRestrictionValue.toDTO(), + this.previousRestrictionType.valueOf(), + this.newRestrictionValue.toDTO(), + this.newRestrictionType.valueOf(), + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicGlobalRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_GLOBAL_RESTRICTION.valueOf(), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + new UnresolvedMosaicIdDto(this.referenceMosaicId.id.toDTO()), + this.restrictionKey.toDTO(), + this.previousRestrictionValue.toDTO(), + this.previousRestrictionType.valueOf(), + this.newRestrictionValue.toDTO(), + this.newRestrictionType.valueOf(), + ); + return transactionBuilder.serialize(); } } diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index b53fbd92d3..cc58bda02e 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -17,6 +17,7 @@ import { Builder } from '../../infrastructure/builders/MosaicSupplyChangeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { MosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/MosaicSupplyChangeTransactionBuilder'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -152,4 +153,22 @@ export class MosaicSupplyChangeTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicSupplyChangeTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_SUPPLY_CHANGE.valueOf(), + new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), + this.direction.valueOf(), + new AmountDto(this.delta.toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index f1f29cd6a2..627397bc69 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -14,9 +14,17 @@ * limitations under the License. */ -import { Convert as convert } from '../../core/format'; +import { Convert, Convert as convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/NamespaceCreationTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EmbeddedNamespaceRegistrationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; +import { NamespaceRegistrationTransactionBuilder } from '../../infrastructure/catbuffer/NamespaceRegistrationTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import {NamespaceMosaicIdGenerator} from '../../infrastructure/transaction/NamespaceMosaicIdGenerator'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -187,6 +195,67 @@ export class RegisterNamespaceTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + let transactionBuilder: NamespaceRegistrationTransactionBuilder; + if (this.namespaceType === NamespaceType.RootNamespace) { + transactionBuilder = new NamespaceRegistrationTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.REGISTER_NAMESPACE.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), + new BlockDurationDto(this.duration!.toDTO()), + undefined, + ); + } else { + transactionBuilder = new NamespaceRegistrationTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.REGISTER_NAMESPACE.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), + undefined, + new NamespaceIdDto(this.parentId!.id.toDTO()), + ); + } + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + let transactionBuilder: EmbeddedNamespaceRegistrationTransactionBuilder; + if (this.namespaceType === NamespaceType.RootNamespace) { + transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_LOCK.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), + new BlockDurationDto(this.duration!.toDTO()), + undefined, + ); + } else { + transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_LOCK.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), + undefined, + new NamespaceIdDto(this.parentId!.id.toDTO()), + ); + } + return transactionBuilder.serialize(); } } diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index 9e02785071..9c0efaab1e 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -18,6 +18,7 @@ import { Builder } from '../../infrastructure/builders/SecretLockTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { EmbeddedSecretLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -197,4 +198,25 @@ export class SecretLockTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedSecretLockTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_LOCK.valueOf(), + new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), + new AmountDto(this.mosaic.amount.toDTO())), + new BlockDurationDto(this.duration.toDTO()), + this.hashType.valueOf(), + new Hash256Dto(this.getSecretByte()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipient.plain())), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index 588638fcc6..acc1c53d7b 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -18,6 +18,7 @@ import { Convert, Convert as convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/SecretProofTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedSecretProofTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -178,4 +179,23 @@ export class SecretProofTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedSecretProofTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.SECRET_PROOF.valueOf(), + this.hashType.valueOf(), + new Hash256Dto(this.getSecretByte()), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipient.plain())), + this.getProofByte(), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index 0bc6786fb3..ceea1ab24c 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -90,6 +90,11 @@ export abstract class Transaction { */ protected abstract generateBytes(): Uint8Array; + /** + * @internal + */ + protected abstract generateEmbeddedBytes(): Uint8Array; + /** * @internal * Serialize and sign transaction creating a new SignedTransaction diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 31dea94577..08b6b29cc2 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -19,6 +19,7 @@ import { RawAddress } from '../../core/format/RawAddress'; import { Builder } from '../../infrastructure/builders/TransferTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedTransferTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedTransferTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -205,4 +206,24 @@ export class TransferTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const transactionBuilder = new EmbeddedTransferTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.TRANSFER.valueOf(), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), + this.getMessageBuffer(), + this.sortMosaics().map((mosaic) => { + return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), + new AmountDto(mosaic.amount.toDTO())); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/test/model/transaction/LockFundsTransaction.spec.ts b/test/model/transaction/LockFundsTransaction.spec.ts index ebd56dc4e0..df3583f1d7 100644 --- a/test/model/transaction/LockFundsTransaction.spec.ts +++ b/test/model/transaction/LockFundsTransaction.spec.ts @@ -15,6 +15,7 @@ */ import {deepEqual} from 'assert'; import {expect} from 'chai'; +import {Account} from '../../../src/model/account/Account'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; import {AggregateTransaction} from '../../../src/model/transaction/AggregateTransaction'; @@ -24,8 +25,11 @@ import {UInt64} from '../../../src/model/UInt64'; import {TestingAccount} from '../../conf/conf.spec'; describe('LockFundsTransaction', () => { - const account = TestingAccount; + let account: Account; const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; + before(() => { + account = TestingAccount; + }); it('should default maxFee field be set to 0', () => { const aggregateTransaction = AggregateTransaction.createBonded( Deadline.create(), @@ -58,7 +62,7 @@ describe('LockFundsTransaction', () => { UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(lockFundsTransaction.maxFee.higher).to.be.equal(0); @@ -100,6 +104,28 @@ describe('LockFundsTransaction', () => { }).to.throw(Error); }); + it('should create and sign LockFundsTransaction', () => { + const aggregateTransaction = AggregateTransaction.createBonded( + Deadline.create(), + [], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = account.sign(aggregateTransaction, generationHash); + const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), + NetworkCurrencyMosaic.createRelative(10), + UInt64.fromUint(10), + signedTransaction, + NetworkType.MIJIN_TEST, + ); + const signedTx = lockFundsTransaction.signWithCatbuffer(account, generationHash); + + expect(signedTx.payload.substring( + 136, + signedTransaction.payload.length - 32, + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE0190484100000000'); + }); + describe('size', () => { it('should return 176 for LockFundsTransaction transaction byte size', () => { const aggregateTransaction = AggregateTransaction.createBonded( diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index c1c549a0b6..f6232022da 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -70,7 +70,7 @@ describe('ModifyMultisigAccountTransaction', () => { NetworkType.MIJIN_TEST), )], NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(modifyMultisigAccountTransaction.maxFee.higher).to.be.equal(0); diff --git a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts index 947904ce56..02aad2fc65 100644 --- a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts @@ -47,7 +47,7 @@ describe('MosaicAddressRestrictionTransaction', () => { expect(mosaicAddressRestrictionTransaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(8).toHex()); expect(mosaicAddressRestrictionTransaction.targetAddress.plain()).to.be.equal(account.address.plain()); - const signedTransaction = mosaicAddressRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicAddressRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts index 39c409bd22..9e436d2fea 100644 --- a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts @@ -54,7 +54,7 @@ describe('MosaicGlobalRestrictionTransaction', () => { expect(mosaicGlobalRestrictionTransaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.EQ); expect(mosaicGlobalRestrictionTransaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); - const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicGlobalRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/RegisterNamespaceTransaction.spec.ts b/test/model/transaction/RegisterNamespaceTransaction.spec.ts index dcd12d95f7..db497c73b9 100644 --- a/test/model/transaction/RegisterNamespaceTransaction.spec.ts +++ b/test/model/transaction/RegisterNamespaceTransaction.spec.ts @@ -66,7 +66,7 @@ describe('RegisterNamespaceTransaction', () => { expect(registerNamespaceTransaction.duration!.lower).to.be.equal(1000); expect(registerNamespaceTransaction.duration!.higher).to.be.equal(0); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -83,7 +83,7 @@ describe('RegisterNamespaceTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index 8e8b4cc9d4..6f53048623 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -242,4 +242,8 @@ class FakeTransaction extends Transaction { protected generateBytes(): Uint8Array { throw new Error('Not implemented'); } + + protected generateEmbeddedBytes(): Uint8Array { + throw new Error('Not implemented'); + } } From 634d0baf21158cbe1efed9eb50da8d7f4ba293bb Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 08:26:17 +0100 Subject: [PATCH 64/98] Applied catbuffer on aggregate transaction --- .../catbuffer/AggregateTransactionBuilder.ts | 6 +-- .../AccountAddressRestrictionTransaction.ts | 6 +-- .../transaction/AccountLinkTransaction.ts | 4 +- .../AccountMosaicRestrictionTransaction.ts | 6 +-- .../AccountOperationRestrictionTransaction.ts | 5 +- .../transaction/AddressAliasTransaction.ts | 6 +-- src/model/transaction/AggregateTransaction.ts | 47 +++++++++++++++++-- src/model/transaction/LockFundsTransaction.ts | 4 +- .../ModifyMultisigAccountTransaction.ts | 4 +- .../MosaicAddressRestrictionTransaction.ts | 6 +-- .../transaction/MosaicAliasTransaction.ts | 5 +- .../MosaicDefinitionTransaction.ts | 5 +- .../MosaicGlobalRestrictionTransaction.ts | 5 +- .../MosaicSupplyChangeTransaction.ts | 5 +- .../RegisterNamespaceTransaction.ts | 5 +- .../transaction/SecretLockTransaction.ts | 4 +- .../transaction/SecretProofTransaction.ts | 4 +- src/model/transaction/Transaction.ts | 9 ++++ src/model/transaction/TransferTransaction.ts | 3 +- .../transaction/AggregateTransaction.spec.ts | 2 +- 20 files changed, 81 insertions(+), 60 deletions(-) diff --git a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts index 64b11c499f..20462d8514 100644 --- a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts +++ b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts @@ -19,14 +19,10 @@ *** along with Catapult. If not, see . **/ -import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; -import { AddressDto } from './AddressDto'; -import { AliasActionDto } from './AliasActionDto'; import { AmountDto } from './AmountDto'; import { EntityTypeDto } from './EntityTypeDto'; import { GeneratorUtils } from './GeneratorUtils'; import { KeyDto } from './KeyDto'; -import { NamespaceIdDto } from './NamespaceIdDto'; import { SignatureDto } from './SignatureDto'; import { TimestampDto } from './TimestampDto'; import { TransactionBuilder } from './TransactionBuilder'; @@ -129,7 +125,7 @@ export class AggregateTransactionBuilder extends TransactionBuilder { newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes); const transactionBytes = this.transactions; newArray = GeneratorUtils.concatTypedArrays(newArray, transactionBytes); - const cosignaturesBytes = this.transactions; + const cosignaturesBytes = this.cosignatures; newArray = GeneratorUtils.concatTypedArrays(newArray, cosignaturesBytes); return newArray; } diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index ec44d13a4b..b70120db8a 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RawAddress } from '../../core/format'; +import { Convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; @@ -151,10 +151,8 @@ export class AccountAddressRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountAddressRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), this.restrictionType.valueOf(), diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index 0d8c60c32b..bd0a0303db 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -145,10 +145,8 @@ export class AccountLinkTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountLinkTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.LINK_ACCOUNT.valueOf(), new KeyDto(Convert.hexToUint8(this.remoteAccountKey)), diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index 98a6321b00..97b35651b4 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountRestrictionType } from '../account/AccountRestrictionType'; @@ -21,7 +22,6 @@ import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructur import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; @@ -150,10 +150,8 @@ export class AccountMosaicRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountMosaicRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ACCOUNT_RESTRICTION_MOSAIC.valueOf(), this.restrictionType.valueOf(), diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index 704cabe56b..5ecda29c0b 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; @@ -148,10 +149,8 @@ export class AccountOperationRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountOperationRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ACCOUNT_RESTRICTION_OPERATION.valueOf(), this.restrictionType.valueOf(), diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 8be88d2be4..98a416a6d3 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RawAddress } from '../../core/format'; +import { Convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AddressAliasTransaction'; import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; @@ -163,10 +163,8 @@ export class AddressAliasTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAddressAliasTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ADDRESS_ALIAS.valueOf(), this.actionType.valueOf(), diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 483c588592..6b1d36e4be 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -15,8 +15,16 @@ */ import { SignSchema } from '../../core/crypto'; -import { Builder } from '../../infrastructure/builders/AggregateTransaction'; +import { Convert } from '../../core/format'; import { AggregateTransaction as AggregatedTransactionCore} from '../../infrastructure/builders/AggregateTransaction'; +import { Builder } from '../../infrastructure/builders/AggregateTransaction'; +import { AggregateTransactionBuilder } from '../../infrastructure/catbuffer/AggregateTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { CosignatureBuilder } from '../../infrastructure/catbuffer/CosignatureBuilder'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { Account } from '../account/Account'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -220,7 +228,40 @@ export class AggregateTransaction extends Transaction { * @returns {Uint8Array} */ protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + let transactions = Uint8Array.from([]); + this.innerTransactions.forEach((transaction) => { + const transactionByte = transaction.toAggregateTransactionBytes(); + transactions = GeneratorUtils.concatTypedArrays(transactions, transactionByte); + }); + + const cosignatures = Uint8Array.from([]); + this.cosignatures.forEach((cosignature) => { + const signerBytes = Convert.hexToUint8(cosignature.signer.publicKey); + const signatureBytes = Convert.hexToUint8(cosignature.signature); + const cosignatureBytes = new CosignatureBuilder( + new KeyDto(signerBytes), + new SignatureDto(signatureBytes), + ).serialize(); + transactions = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); + }); + + console.log('cosignatures', Convert.uint8ToHex(cosignatures)); + console.log('transactions', Convert.uint8ToHex(transactions)); + + const transactionBuilder = new AggregateTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + this.type.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + transactions, + cosignatures, + ); + return transactionBuilder.serialize(); } /** @@ -228,6 +269,6 @@ export class AggregateTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - throw new Error('Not implemented'); + throw new Error('Method not implemented'); } } diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index 52027d141d..e34bb40489 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -176,10 +176,8 @@ export class LockFundsTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedHashLockTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.LOCK.valueOf(), new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index f33e7af077..fa1e35dfef 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -172,10 +172,8 @@ export class ModifyMultisigAccountTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMultisigAccountModificationTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MODIFY_MULTISIG_ACCOUNT.valueOf(), this.minRemovalDelta, diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index b1c62e0167..819d69c43c 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RawAddress } from '../../core/format'; +import { Convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicAddressRestrictionTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -188,10 +188,8 @@ export class MosaicAddressRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicAddressRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_ADDRESS_RESTRICTION.valueOf(), new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index 6e2e600ff8..f822b73505 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicAliasTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -158,10 +159,8 @@ export class MosaicAliasTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicAliasTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_ALIAS.valueOf(), this.actionType.valueOf(), diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 8ac6e76eb0..c0adbd1e8b 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicCreationTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -216,10 +217,8 @@ export class MosaicDefinitionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicDefinitionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_DEFINITION.valueOf(), new MosaicNonceDto(this.getMosaicNonceIntValue()), diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index b2d421dca3..7b4f757efc 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/MosaicGlobalRestrictionTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -211,10 +212,8 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicGlobalRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_GLOBAL_RESTRICTION.valueOf(), new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index cc58bda02e..be4f3a89a3 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -33,6 +33,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { Convert } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -159,10 +160,8 @@ export class MosaicSupplyChangeTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicSupplyChangeTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_SUPPLY_CHANGE.valueOf(), new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()), diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index 627397bc69..0cdcae2aa6 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -233,11 +233,10 @@ export class RegisterNamespaceTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); let transactionBuilder: EmbeddedNamespaceRegistrationTransactionBuilder; if (this.namespaceType === NamespaceType.RootNamespace) { transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.SECRET_LOCK.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), @@ -247,7 +246,7 @@ export class RegisterNamespaceTransaction extends Transaction { ); } else { transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.SECRET_LOCK.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index 9c0efaab1e..e65187384d 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -204,10 +204,8 @@ export class SecretLockTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedSecretLockTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.SECRET_LOCK.valueOf(), new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index acc1c53d7b..41df6b207b 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -185,10 +185,8 @@ export class SecretProofTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedSecretProofTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.SECRET_PROOF.valueOf(), this.hashType.valueOf(), diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index ceea1ab24c..ca2fbbce44 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -186,6 +186,15 @@ export abstract class Transaction { return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {signer}); } + /** + * Takes a transaction and formats bytes to be included in an aggregate transaction. + * + * @return transaction with signer serialized to be part of an aggregate transaction + */ + public toAggregateTransactionBytes() { + return this.generateEmbeddedBytes(); + } + /** * Transaction pending to be included in a block * @returns {boolean} diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 08b6b29cc2..6714fd7904 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -212,9 +212,8 @@ export class TransferTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); const transactionBuilder = new EmbeddedTransferTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.TRANSFER.valueOf(), new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 5cf09cf275..5f527cd9b1 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -106,7 +106,7 @@ describe('AggregateTransaction', () => { NetworkType.MIJIN_TEST, []); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); + const signedTransaction = aggregateTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); From 806182b77c77f9006f082d0765925d515f9abb23 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 11:46:27 +0100 Subject: [PATCH 65/98] Removed old flatbuffer staffs --- e2e/conf/network.conf | 64 +- .../buffers/AccountLinkTransactionBuffer.ts | 425 ---------- ...untRestrictionsAddressTransactionBuffer.ts | 557 ------------- ...RestrictionsEntityTypeTransactionBuffer.ts | 520 ------------ ...ountRestrictionsMosaicTransactionBuffer.ts | 557 ------------- .../buffers/AddressAliasTransactionBuffer.ts | 479 ----------- .../buffers/AggregateTransactionBuffer.ts | 425 ---------- .../buffers/HashLockTransactionBuffer.ts | 571 ------------- ...saicAddressRestrictionTransactionBuffer.ts | 625 -------------- .../buffers/MosaicAliasTransactionBuffer.ts | 479 ----------- .../MosaicCreationTransactionBuffer.ts | 582 ------------- ...osaicGlobalRestrictionTransactionBuffer.ts | 657 --------------- .../MosaicSupplyChangeTransactionBuffer.ts | 479 ----------- .../MultisigModificationTransactionBuffer.ts | 571 ------------- .../NamespaceCreationTransactionBuffer.ts | 512 ------------ .../buffers/SecretLockTransactionBuffer.ts | 641 -------------- .../buffers/SecretProofTransactionBuffer.ts | 549 ------------ .../buffers/TransferTransactionBuffer.ts | 785 ------------------ .../builders/AccountLinkTransaction.ts | 110 --- .../AccountRestrictionsAddressTransaction.ts | 128 --- ...ccountRestrictionsEntityTypeTransaction.ts | 126 --- .../AccountRestrictionsMosaicTransaction.ts | 127 --- .../builders/AddressAliasTransaction.ts | 122 --- .../builders/AggregateTransaction.ts | 151 ---- .../builders/CosignatureTransaction.ts | 27 - src/infrastructure/builders/Deadline.ts | 22 - .../builders/HashLockTransaction.ts | 127 --- .../MosaicAddressRestrictionTransaction.ts | 146 ---- .../builders/MosaicAliasTransaction.ts | 122 --- .../builders/MosaicCreationTransaction.ts | 164 ---- .../MosaicGlobalRestrictionTransaction.ts | 159 ---- .../builders/MosaicSupplyChangeTransaction.ts | 120 --- .../MultisigModificationTransaction.ts | 134 --- .../builders/NamespaceCreationTransaction.ts | 142 ---- .../builders/SecretLockTransaction.ts | 142 ---- .../builders/SecretProofTransaction.ts | 127 --- .../builders/TransferTransaction.ts | 152 ---- .../builders/VerifiableTransaction.ts | 128 --- .../builders/VerificableTransactionBuilder.ts | 65 -- .../schemas/AccountLinkTransactionSchema.ts | 44 - ...onsAddressModificationTransactionSchema.ts | 48 -- ...EntityTypeModificationTransactionSchema.ts | 48 -- ...ionsMosaicModificationTransactionSchema.ts | 48 -- .../schemas/AddressAliasTransactionSchema.ts | 44 - .../schemas/AggregateTransactionSchema.ts | 44 - .../schemas/HashLockTransactionSchema.ts | 45 - ...saicAddressRestrictionTransactionSchema.ts | 46 - .../schemas/MosaicAliasTransactionSchema.ts | 44 - .../MosaicCreationTransactionSchema.ts | 63 -- ...osaicGlobalRestrictionTransactionSchema.ts | 49 -- .../MosaicSupplyChangeTransactionSchema.ts | 44 - .../MultisigModificationTransactionSchema.ts | 49 -- .../NamespaceCreationTransactionSchema.ts | 47 -- src/infrastructure/schemas/Schema.ts | 374 --------- .../schemas/SecretLockTransactionSchema.ts | 48 -- .../schemas/SecretProofTransactionSchema.ts | 47 -- .../schemas/TransferTransactionSchema.ts | 55 -- .../CreateTransactionFromPayload.ts | 14 +- src/model/namespace/AliasAction.ts | 6 +- .../AccountAddressRestrictionTransaction.ts | 17 - .../transaction/AccountLinkTransaction.ts | 16 - .../AccountMosaicRestrictionTransaction.ts | 17 - .../AccountOperationRestrictionTransaction.ts | 16 - .../transaction/AddressAliasTransaction.ts | 17 - src/model/transaction/AggregateTransaction.ts | 67 +- .../transaction/CosignatureTransaction.ts | 39 +- src/model/transaction/LockFundsTransaction.ts | 19 - .../ModifyMultisigAccountTransaction.ts | 19 +- .../MosaicAddressRestrictionTransaction.ts | 19 - .../transaction/MosaicAliasTransaction.ts | 17 - .../MosaicDefinitionTransaction.ts | 35 +- .../MosaicGlobalRestrictionTransaction.ts | 21 - .../MosaicSupplyChangeTransaction.ts | 19 +- .../RegisterNamespaceTransaction.ts | 28 +- .../transaction/SecretLockTransaction.ts | 21 - .../transaction/SecretProofTransaction.ts | 19 - src/model/transaction/Transaction.ts | 88 +- src/model/transaction/TransferTransaction.ts | 35 +- .../AccountLinkTransaction.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 6 +- .../AddressAliasTransaction.spec.ts | 4 +- .../transaction/AggregateTransaction.spec.ts | 8 +- .../transaction/LockFundsTransaction.spec.ts | 2 +- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- ...osaicAddressRestrictionTransaction.spec.ts | 2 +- .../MosaicAliasTransaction.spec.ts | 4 +- .../MosaicDefinitionTransaction.spec.ts | 8 +- ...MosaicGlobalRestrictionTransaction.spec.ts | 2 +- .../RegisterNamespaceTransaction.spec.ts | 4 +- .../transaction/SecretLockTransaction.spec.ts | 2 +- .../SecretProofTransaction.spec.ts | 2 +- test/model/transaction/Transaction.spec.ts | 5 - .../transaction/TransferTransaction.spec.ts | 2 +- 93 files changed, 180 insertions(+), 13630 deletions(-) delete mode 100644 src/infrastructure/buffers/AccountLinkTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AccountRestrictionsAddressTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AccountRestrictionsEntityTypeTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AccountRestrictionsMosaicTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AddressAliasTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/AggregateTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/HashLockTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicAddressRestrictionTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicAliasTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicCreationTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicGlobalRestrictionTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MosaicSupplyChangeTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/MultisigModificationTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/NamespaceCreationTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/SecretLockTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/SecretProofTransactionBuffer.ts delete mode 100644 src/infrastructure/buffers/TransferTransactionBuffer.ts delete mode 100644 src/infrastructure/builders/AccountLinkTransaction.ts delete mode 100644 src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts delete mode 100644 src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts delete mode 100644 src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts delete mode 100644 src/infrastructure/builders/AddressAliasTransaction.ts delete mode 100644 src/infrastructure/builders/AggregateTransaction.ts delete mode 100644 src/infrastructure/builders/CosignatureTransaction.ts delete mode 100644 src/infrastructure/builders/Deadline.ts delete mode 100644 src/infrastructure/builders/HashLockTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicAddressRestrictionTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicAliasTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicCreationTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicGlobalRestrictionTransaction.ts delete mode 100644 src/infrastructure/builders/MosaicSupplyChangeTransaction.ts delete mode 100644 src/infrastructure/builders/MultisigModificationTransaction.ts delete mode 100644 src/infrastructure/builders/NamespaceCreationTransaction.ts delete mode 100644 src/infrastructure/builders/SecretLockTransaction.ts delete mode 100644 src/infrastructure/builders/SecretProofTransaction.ts delete mode 100644 src/infrastructure/builders/TransferTransaction.ts delete mode 100644 src/infrastructure/builders/VerifiableTransaction.ts delete mode 100644 src/infrastructure/builders/VerificableTransactionBuilder.ts delete mode 100644 src/infrastructure/schemas/AccountLinkTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AccountRestrictionsAddressModificationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AccountRestrictionsEntityTypeModificationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AccountRestrictionsMosaicModificationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AddressAliasTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/AggregateTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/HashLockTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicAddressRestrictionTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicAliasTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicCreationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicGlobalRestrictionTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MosaicSupplyChangeTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/MultisigModificationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/NamespaceCreationTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/Schema.ts delete mode 100644 src/infrastructure/schemas/SecretLockTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/SecretProofTransactionSchema.ts delete mode 100644 src/infrastructure/schemas/TransferTransactionSchema.ts diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index 95fa85d3c7..79f895aecf 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -1,54 +1,54 @@ { - "apiUrl": "http://localhost:3000", + "apiUrl": "http://c2.nem.ninja:3000", "generationHash": "57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6", "testAccount": { - "privateKey": "D242FB34C2C4DD36E995B9C865F93940065E326661BA5A4A247331D211FE3A3D", - "address": "SBMYYFIM6VGG45KWGSZLSXFHP74WVT7MOF6UYBHT", - "publicKey": "2FC3872A792933617D70E02AFF8FBDE152821A0DF0CA5FB04CB56FC3D21C8863" + "privateKey": "E1C8521608F4896CA26A0C2DE739310EA4B06861D126CF4D6922064678A1969B", + "address": "SAKT3CKHCYIG5BBOPTSY2WXSVPBSLIA67AEOX4ND", + "publicKey": "9F784BF20318AE3CA6246C0EC2207FE095FFF7A84B6787E7E3C2CE4C3B92A2EA" }, "multisigAccount": { - "privateKey": "6EBE2AB0584C816771B494B36B40EC6CE1A0024C37DC6056D89D570A21A70262", - "address": "SCJAK5N6ICIE3JGHV5SVDSSNM5RUZZVDWQJ5G76N", - "publicKey": "224556169645EFAB772BFE1B5665490334428017E5D86FB3C9DFC4070B2F16A6" + "privateKey": "A9CEAA617D0B7D9DEBE9F96BD63CCF68A49950BB315CB9A4169FC6AAA1EC9E28", + "address": "SDWY3PYN4ZZO4S4EBEY2UPSSZUPGZH2G2LQMUSEU", + "publicKey": "8A613468924B8771779C7E4C889205A9BE6CAE0B9435B4BCC8E79A8DD8571608" }, "cosignatoryAccount": { - "privateKey": "44C0044B36AEF44C7743C407CEE4B6FD801BF6B0652AB7799B0991FFD3A81E71", - "address": "SCPL4YCGZYCML5WUSCIVN5MQF5YZAAF4GMZJIEL4", - "publicKey": "76C1622C7FB58986E500228E8FFB30C606CAAFC1CD78E770E82C73DAB7BD7C9F" + "privateKey": "8CBAA7491B7DC1070BECBC4F60AE55F4A272DA1DAD1D502DB016E142993817BA", + "address": "SB7Q5A3KEKFEWBPBTC6RFKU6Q2L4V7DM4ZNE4A7A", + "publicKey": "61B8EB2C02F3D3731A8EF6FE4CCD6BC84615BABA09CA3E891C0D2542096E6AD3" }, "cosignatory2Account": { - "privateKey": "F7B3A64652BAE6DB00D8B7C45F9D1C9BE0DB9E02002111A0B547AE1E220B7DDC", - "address": "SBISV4QCGJ7SSOLG64DBNPWU6J7SSY64R22D2L3Q", - "publicKey": "B5C2611E32E16482B0B9811ABF906A1DE84184DED1D343790482F517C02FB01C" + "privateKey": "60380027EBE63A5D60F6156F5637685172331705160783FF2F9D93C1E5A8622B", + "address": "SCM47E3JVPHOFWLSMNX3RKQQQIB3JUBR7MTX4M4P", + "publicKey": "3D9996683A0FA460D13288B846DF68A9B6C0C1F14EC2E43907DF8D84DC87B9C2" }, "cosignatory3Account": { - "privateKey": "A7D6ED74CDDECBF621DDC63558433DB604FA800D138810B3DF9B4EC880D0705F", - "address": "SD2UY5LHIAAZDVKRHBOYSS4MTLHVTJVUTQPEGV2U", - "publicKey": "3A33DA75E00F643C49C57E8BD3282149911B06FF107C37F7AEDFED5532166BDA" + "privateKey": "E39CE241F730CD190658AFDB5F3896628F92D7BC35D88435D148BED88C6CC844", + "address": "SDEVG5MU4MEGJ72NSBC7PKMK7JCJKN7QB3DOVARJ", + "publicKey": "422697046582D8B8063931B7327D0C06FA454B416F6A5C000922EC5BA546F4B2" }, "cosignatory4Account": { - "privateKey": "D2A12301F5595869EFD5374B3372F0ED7EC26BF73A71D310950CC018D3FA0B03", - "address": "SD7PYMM2BTT4SGSITZ2MBQBK4SXIQQQV4ZOP46VF", - "publicKey": "FDE589878756C2287056EC8D7B2829D9C1FA6D389EBDC808034813FE7810AAB0" + "privateKey": "0EA7E63C96FC580AD5EE85ED3C77A96B421F7C8BF75A83AB889313114C9082F2", + "address": "SCBNKMD23J7BO3Q42SEGP4LXGVJYSDPUESSEWGWZ", + "publicKey": "3A225A2C7C7D95279E74D420728D2DA2A176DE036B67909074AEF5F2DCFAF31C" }, "testAccount2": { - "privateKey": "E5DCCEBDB01A8B03A7DB7BA5888E2E33FD4617B5F6FED48C4C09C0780F422713", - "address": "SBSBLBT7CIOQG6XUI7TRDMHV4TKS5O7QM3MWQYHL", - "publicKey": "5F14CD455A1C0B08073C657EFA09365921736C1ADAF0F0685848678AE966EE09" + "privateKey": "A084418D937627BCDA19B277D8610C845124149FA18AABE96A17D56A2EA7FB8B", + "address": "SBF5HY3T7SXIBCSK4V4WNS4LS4QUMESMVNBCD2AQ", + "publicKey": "1C4B44400FDC933860B1949A5AEA756F19A36D73C4634699E49C3E7275EFA54F" }, "testAccount3": { - "privateKey": "CA95470BEFF4487D692D501E5C41F86FAE9CE6DD15B7B64E150E42A18BDE9CF8", - "address": "SBCFDASM35I6JSLUPQMSX2WGJG55WOCNB53NNVPH", - "publicKey": "E97077A656D9E7F5679880D4950BBF2B3638B7ACE17C82CCB7881DE9BAF396C6" + "privateKey": "8C9E72C5D8964A19174B478B65BD4B7F2AFD8F92C05AE45B15A9EDF222EC8CA8", + "address": "SDY65GIMMOF7GZGGART66QGS6ELWDTQT55JJOF42", + "publicKey": "B8320002C5CF64D855F073F2387FB18F13E7A04FA57FC3743694B04579104F98" }, "testAccountNoBalance": { - "privateKey": "A0591F79F588758280DFB4823A47FCEEC6A551344F794FFDE3760A9D7E1DE348", - "address": "SC5NTT5APX2FAUS4VQUII3UTMAD7GHRFTLDQOEDW", - "publicKey": "6D652E480E5B2997A19D0C7485724693D79A63FCD591A948B40240BD196BA7D6" + "privateKey": "CE4E6B1113EF8999ED79A027A4F3255C367BC2E40417E27E614FB7C12E42BDFA", + "address": "SDNMDW5TXIORKRXQ7F3QORRW4KUAK4ALQ7JWX2KJ", + "publicKey": "92658FE642AEAF1B766D0F4FE4E263C3A0E069735836383D31A70E2B7801358B" }, "harvestingAccount": { - "privateKey": "0B9802C011DA2D61BCD203F4DC76C012898EE38BA54A7E030B86630A8FD43CA6", - "address": "SAALWHKCWH72J53M3M4LB6UYFGLQMAOXJACWJX2U", - "publicKey": "092CAAFEBCB51C64A7CE423050964492407B264CA306D063DBA927A2304C4DD8" + "privateKey": "9999630E4AE5CA5675A703F3268084EB9A9B477A8C519D66465D5D21830E691A", + "address": "SC2PGQO5WV4QZRAQHJDNQ2Q5IFWA2D3VLFEFFZHC", + "publicKey": "74771A0B0B920D787F4F8242926C348007B23062910DE99C7E56AA79D4D7B90A" } -} \ No newline at end of file +} diff --git a/src/infrastructure/buffers/AccountLinkTransactionBuffer.ts b/src/infrastructure/buffers/AccountLinkTransactionBuffer.ts deleted file mode 100644 index 30dde827ce..0000000000 --- a/src/infrastructure/buffers/AccountLinkTransactionBuffer.ts +++ /dev/null @@ -1,425 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.AccountLinkTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AccountLinkTransactionBuffer} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AccountLinkTransactionBuffer=} obj - * @returns {Catapult.Buffers.AccountLinkTransactionBuffer} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.getRootAsAccountLinkTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AccountLinkTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signerLength = function() { - let offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.signerArray = function() { - let offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.version = function() { - let offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.type = function() { - let offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.fee = function(index) { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.feeLength = function() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.feeArray = function() { - const offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.deadline = function(index) { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.deadlineLength = function() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.deadlineArray = function() { - const offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.remoteAccountKey = function(index) { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.remoteAccountKeyLength = function() { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.remoteAccountKeyArray = function() { - const offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.prototype.linkAction = function() { - const offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startAccountLinkTransactionBuffer = function(builder) { - builder.startObject(12); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} remoteAccountKey - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addRemoteAccountKey = function(builder, remoteAccountKeyOffset) { - builder.addFieldOffset(7, remoteAccountKeyOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.createRemoteAccountKeyVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (let i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountLinkTransactionBuffer.startRemoteAccountKeyVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} linkAction - */ -Catapult.Buffers.AccountLinkTransactionBuffer.addLinkAction = function(builder, linkAction) { - builder.addFieldInt8(8, linkAction, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountLinkTransactionBuffer.endAccountLinkTransactionBuffer = function(builder) { - const offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AccountLinkTransactionBuffer.finishAccountLinkTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AccountRestrictionsAddressTransactionBuffer.ts b/src/infrastructure/buffers/AccountRestrictionsAddressTransactionBuffer.ts deleted file mode 100644 index 7f71878ffc..0000000000 --- a/src/infrastructure/buffers/AccountRestrictionsAddressTransactionBuffer.ts +++ /dev/null @@ -1,557 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.RestrictionAddressModificationBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.RestrictionAddressModificationBuffer} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.RestrictionAddressModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionAddressModificationBuffer} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.getRootAsRestrictionAddressModificationBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.RestrictionAddressModificationBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.modificationType = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.value = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.valueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.prototype.valueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.startRestrictionAddressModificationBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.addModificationType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} valueOffset - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.addValue = function(builder, valueOffset) { - builder.addFieldOffset(1, valueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.createValueVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.startValueVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionAddressModificationBuffer.endRestrictionAddressModificationBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer=} obj - * @returns {Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.getRootAsAccountRestrictionsAddressTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.restrictionType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.modificationCount = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.RestrictionAddressModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionAddressModificationBuffer} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.modifications = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? (obj || new Catapult.Buffers.RestrictionAddressModificationBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.prototype.modificationsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startAccountRestrictionsAddressTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} restrictionType - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addRestrictionType = function(builder, restrictionType) { - builder.addFieldInt8(7, restrictionType, 0); -}; - - -/** - * @param {flatbuffers.Builder} builder - * @param {number} modificationCount - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addModificationCount = function(builder, modificationCount) { - builder.addFieldInt8(8, modificationCount, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} modificationsOffset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.addModifications = function(builder, modificationsOffset) { - builder.addFieldOffset(9, modificationsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.createModificationsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.startModificationsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.endAccountRestrictionsAddressTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AccountRestrictionsAddressTransactionBuffer.finishAccountRestrictionsAddressTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AccountRestrictionsEntityTypeTransactionBuffer.ts b/src/infrastructure/buffers/AccountRestrictionsEntityTypeTransactionBuffer.ts deleted file mode 100644 index b842f8d776..0000000000 --- a/src/infrastructure/buffers/AccountRestrictionsEntityTypeTransactionBuffer.ts +++ /dev/null @@ -1,520 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.RestrictionEntityTypeModificationBuffer} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.RestrictionEntityTypeModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionEntityTypeModificationBuffer} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.getRootAsRestrictionEntityTypeModificationBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.RestrictionEntityTypeModificationBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.prototype.modificationType = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.prototype.value = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.startRestrictionEntityTypeModificationBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.addModificationType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} valueOffset - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.addValue = function(builder, valueOffset) { - builder.addFieldInt16(1, valueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionEntityTypeModificationBuffer.endRestrictionEntityTypeModificationBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer=} obj - * @returns {Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.getRootAsAccountRestrictionsEntityTypeTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.restrictionType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.modificationCount = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.RestrictionEntityTypeModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionEntityTypeModificationBuffer} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.modifications = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? (obj || new Catapult.Buffers.RestrictionEntityTypeModificationBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.prototype.modificationsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startAccountRestrictionsEntityTypeTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} restrictionType - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addRestrictionType = function(builder, restrictionType) { - builder.addFieldInt8(7, restrictionType, 0); -}; - - -/** - * @param {flatbuffers.Builder} builder - * @param {number} modificationCount - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addModificationCount = function(builder, modificationCount) { - builder.addFieldInt8(8, modificationCount, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} modificationsOffset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.addModifications = function(builder, modificationsOffset) { - builder.addFieldOffset(9, modificationsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.createModificationsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.startModificationsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.endAccountRestrictionsEntityTypeTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AccountRestrictionsEntityTypeTransactionBuffer.finishAccountRestrictionsEntityTypeTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AccountRestrictionsMosaicTransactionBuffer.ts b/src/infrastructure/buffers/AccountRestrictionsMosaicTransactionBuffer.ts deleted file mode 100644 index 2fde91933f..0000000000 --- a/src/infrastructure/buffers/AccountRestrictionsMosaicTransactionBuffer.ts +++ /dev/null @@ -1,557 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.RestrictionMosaicModificationBuffer} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.RestrictionMosaicModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionMosaicModificationBuffer} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.getRootAsRestrictionMosaicModificationBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.RestrictionMosaicModificationBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.modificationType = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.value = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.valueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.prototype.valueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.startRestrictionMosaicModificationBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.addModificationType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} valueOffset - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.addValue = function(builder, valueOffset) { - builder.addFieldOffset(1, valueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.createValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.startValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.RestrictionMosaicModificationBuffer.endRestrictionMosaicModificationBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer=} obj - * @returns {Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.getRootAsAccountRestrictionsMosaicTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.restrictionType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.modificationCount = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.RestrictionMosaicModificationBuffer=} obj - * @returns {Catapult.Buffers.RestrictionMosaicModificationBuffer} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.modifications = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? (obj || new Catapult.Buffers.RestrictionMosaicModificationBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.prototype.modificationsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startAccountRestrictionsMosaicTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} restrictionType - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addRestrictionType = function(builder, restrictionType) { - builder.addFieldInt8(7, restrictionType, 0); -}; - - -/** - * @param {flatbuffers.Builder} builder - * @param {number} modificationCount - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addModificationCount = function(builder, modificationCount) { - builder.addFieldInt8(8, modificationCount, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} modificationsOffset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.addModifications = function(builder, modificationsOffset) { - builder.addFieldOffset(9, modificationsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.createModificationsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.startModificationsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.endAccountRestrictionsMosaicTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AccountRestrictionsMosaicTransactionBuffer.finishAccountRestrictionsMosaicTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AddressAliasTransactionBuffer.ts b/src/infrastructure/buffers/AddressAliasTransactionBuffer.ts deleted file mode 100644 index 00aa5f0a78..0000000000 --- a/src/infrastructure/buffers/AddressAliasTransactionBuffer.ts +++ /dev/null @@ -1,479 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.AddressAliasTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AddressAliasTransactionBuffer} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AddressAliasTransactionBuffer=} obj - * @returns {Catapult.Buffers.AddressAliasTransactionBuffer} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.getRootAsAddressAliasTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AddressAliasTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.aliasAction = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.namespaceId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.namespaceIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.namespaceIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.address = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.addressLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.prototype.addressArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startAddressAliasTransactionBuffer = function(builder) { - builder.startObject(10); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} aliasAction - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addAliasAction = function(builder, aliasAction) { - builder.addFieldInt8(7, aliasAction, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deltaOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addNamespaceId = function(builder, namespaceIdOffset) { - builder.addFieldOffset(8, namespaceIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createNamespaceIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startNamespaceIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.addAddress = function(builder, addressOffset) { - builder.addFieldOffset(9, addressOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.createAddressVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AddressAliasTransactionBuffer.startAddressVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AddressAliasTransactionBuffer.endAddressAliasTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AddressAliasTransactionBuffer.finishAddressAliasTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/AggregateTransactionBuffer.ts b/src/infrastructure/buffers/AggregateTransactionBuffer.ts deleted file mode 100644 index e2f9f68e83..0000000000 --- a/src/infrastructure/buffers/AggregateTransactionBuffer.ts +++ /dev/null @@ -1,425 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.AggregateTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.AggregateTransactionBuffer} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.AggregateTransactionBuffer=} obj - * @returns {Catapult.Buffers.AggregateTransactionBuffer} - */ -Catapult.Buffers.AggregateTransactionBuffer.getRootAsAggregateTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.AggregateTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.transactionsSize = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.transactions = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.transactionsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.AggregateTransactionBuffer.prototype.transactionsArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.AggregateTransactionBuffer.startAggregateTransactionBuffer = function(builder) { - builder.startObject(9); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.AggregateTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.AggregateTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.AggregateTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} transactionsSize - */ -Catapult.Buffers.AggregateTransactionBuffer.addTransactionsSize = function(builder, transactionsSize) { - builder.addFieldInt32(7, transactionsSize, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} transactionsOffset - */ -Catapult.Buffers.AggregateTransactionBuffer.addTransactions = function(builder, transactionsOffset) { - builder.addFieldOffset(8, transactionsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.createTransactionsVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.AggregateTransactionBuffer.startTransactionsVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.AggregateTransactionBuffer.endAggregateTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.AggregateTransactionBuffer.finishAggregateTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/HashLockTransactionBuffer.ts b/src/infrastructure/buffers/HashLockTransactionBuffer.ts deleted file mode 100644 index ed4f0d4d8d..0000000000 --- a/src/infrastructure/buffers/HashLockTransactionBuffer.ts +++ /dev/null @@ -1,571 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.HashLockTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.HashLockTransactionBuffer} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.HashLockTransactionBuffer=} obj - * @returns {Catapult.Buffers.HashLockTransactionBuffer} - */ -Catapult.Buffers.HashLockTransactionBuffer.getRootAsHashLockTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.HashLockTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicAmount = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicAmountLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.mosaicAmountArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.duration = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.durationLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.durationArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.hash = function(index) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.hashLength = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.HashLockTransactionBuffer.prototype.hashArray = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.HashLockTransactionBuffer.startHashLockTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.HashLockTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.HashLockTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.HashLockTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicAmountOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addMosaicAmount = function(builder, mosaicAmountOffset) { - builder.addFieldOffset(8, mosaicAmountOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createMosaicAmountVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startMosaicAmountVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} durationOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addDuration = function(builder, durationOffset) { - builder.addFieldOffset(9, durationOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createDurationVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startDurationVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} hashOffset - */ -Catapult.Buffers.HashLockTransactionBuffer.addHash = function(builder, hashOffset) { - builder.addFieldOffset(10, hashOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.createHashVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.HashLockTransactionBuffer.startHashVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.HashLockTransactionBuffer.endHashLockTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.HashLockTransactionBuffer.finishHashLockTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicAddressRestrictionTransactionBuffer.ts b/src/infrastructure/buffers/MosaicAddressRestrictionTransactionBuffer.ts deleted file mode 100644 index a306031841..0000000000 --- a/src/infrastructure/buffers/MosaicAddressRestrictionTransactionBuffer.ts +++ /dev/null @@ -1,625 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.getRootAsMosaicAddressRestrictionTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.restrictionKey = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.restrictionKeyLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.restrictionKeyArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.targetAddress = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.targetAddressLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.targetAddressArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.previousRestrictionValue = function(index) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.previousRestrictionValueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.previousRestrictionValueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.newRestrictionValue = function(index) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.newRestrictionValueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.prototype.newRestrictionValueValueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startMosaicAddressRestrictionTransactionBuffer = function(builder) { - builder.startObject(14); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} restrictionKeyOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addRestrictionKey = function(builder, restrictionKeyOffset) { - builder.addFieldOffset(8, restrictionKeyOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createRestrictionKeyVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startRestrictionKeyVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} targetAddressOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addTargetAddress = function(builder, targetAddressOffset) { - builder.addFieldOffset(9, targetAddressOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createTargetAddressVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startTargetAddressVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} previousRestrictionValueOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addPreviousRestrictionValue = function(builder, previousRestrictionValueOffset) { - builder.addFieldOffset(10, previousRestrictionValueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createPreviousRestrictionValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startPreviousRestrictionValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} newRestrictionValueOffset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.addNewRestrictionValue = function(builder, newRestrictionValueOffset) { - builder.addFieldOffset(11, newRestrictionValueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.createNewRestrictionValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.startNewRestrictionValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.endMosaicAddressRestrictionTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicAddressRestrictionTransactionBuffer.finishMosaicAddressRestrictionTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicAliasTransactionBuffer.ts b/src/infrastructure/buffers/MosaicAliasTransactionBuffer.ts deleted file mode 100644 index 3632f14354..0000000000 --- a/src/infrastructure/buffers/MosaicAliasTransactionBuffer.ts +++ /dev/null @@ -1,479 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicAliasTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicAliasTransactionBuffer} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicAliasTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicAliasTransactionBuffer} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.getRootAsMosaicAliasTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicAliasTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.aliasAction = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.namespaceId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.namespaceIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.namespaceIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startMosaicAliasTransactionBuffer = function(builder) { - builder.startObject(10); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} aliasAction - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addAliasAction = function(builder, aliasAction) { - builder.addFieldInt8(7, aliasAction, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deltaOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addNamespaceId = function(builder, namespaceIdOffset) { - builder.addFieldOffset(8, namespaceIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createNamespaceIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startNamespaceIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(9, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.endMosaicAliasTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicAliasTransactionBuffer.finishMosaicAliasTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicCreationTransactionBuffer.ts b/src/infrastructure/buffers/MosaicCreationTransactionBuffer.ts deleted file mode 100644 index eef8821885..0000000000 --- a/src/infrastructure/buffers/MosaicCreationTransactionBuffer.ts +++ /dev/null @@ -1,582 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicCreationTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicCreationTransactionBuffer} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicCreationTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicCreationTransactionBuffer} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.getRootAsMosaicCreationTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicCreationTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.nonce = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.nonceLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.nonceArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.numOptionalProperties = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.flags = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.divisibility = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.indicateDuration = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.duration = function(index) { - var offset = this.bb.__offset(this.bb_pos, 30); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.durationLength = function() { - var offset = this.bb.__offset(this.bb_pos, 30); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.prototype.durationArray = function() { - var offset = this.bb.__offset(this.bb_pos, 30); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startMosaicCreationTransactionBuffer = function(builder) { - builder.startObject(14); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} nonce - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addNonce = function(builder, nonceOffset) { - - builder.addFieldOffset(7, nonceOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createNonceVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startNonceVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(8, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numOptionalProperties - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addNumOptionalProperties = function(builder, numOptionalProperties) { - builder.addFieldInt8(9, numOptionalProperties, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} flags - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addFlags = function(builder, flags) { - builder.addFieldInt8(10, flags, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} divisibility - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addDivisibility = function(builder, divisibility) { - builder.addFieldInt8(11, divisibility, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} indicateDuration - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addIndicateDuration = function(builder, indicateDuration) { - builder.addFieldInt8(12, indicateDuration, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} durationOffset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.addDuration = function(builder, durationOffset) { - builder.addFieldOffset(13, durationOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.createDurationVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.startDurationVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.endMosaicCreationTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicCreationTransactionBuffer.finishMosaicCreationTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicGlobalRestrictionTransactionBuffer.ts b/src/infrastructure/buffers/MosaicGlobalRestrictionTransactionBuffer.ts deleted file mode 100644 index 794dfd3add..0000000000 --- a/src/infrastructure/buffers/MosaicGlobalRestrictionTransactionBuffer.ts +++ /dev/null @@ -1,657 +0,0 @@ -/* - * 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.getRootAsMosaicGlobalRestrictionTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.referenceMosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.referenceMosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.referenceMosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.restrictionKey = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.restrictionKeyLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.restrictionKeyArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.previousRestrictionValue = function(index) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.previousRestrictionValueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.previousRestrictionValueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.previousRestrictionType = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.newRestrictionValue = function(index) { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.newRestrictionValueLength = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.newRestrictionValueValueArray = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.prototype.newRestrictionValue = function() { - var offset = this.bb.__offset(this.bb_pos, 30); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startMosaicGlobalRestrictionTransactionBuffer = function(builder) { - builder.startObject(14); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} referenceMosaicIdOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addReferenceMosaicId = function(builder, referenceMosaicIdOffset) { - builder.addFieldOffset(8, referenceMosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createReferenceMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startReferenceMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} restrictionKeyOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addRestrictionKey = function(builder, restrictionKeyOffset) { - builder.addFieldOffset(9, restrictionKeyOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createRestrictionKeyVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startRestrictionKeyVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} previousRestrictionValueOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addPreviousRestrictionValue = function(builder, previousRestrictionValueOffset) { - builder.addFieldOffset(10, previousRestrictionValueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createPreviousRestrictionValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startPreviousRestrictionValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} previousRestrictionType - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addPreviousRestrictionType = function(builder, previousRestrictionType) { - builder.addFieldInt16(11, previousRestrictionType, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} newRestrictionValueOffset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addNewRestrictionValue = function(builder, newRestrictionValueOffset) { - builder.addFieldOffset(12, newRestrictionValueOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.createNewRestrictionValueVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.startNewRestrictionValueVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} newRestrictionType - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.addNewRestrictionType = function(builder, newRestrictionType) { - builder.addFieldInt16(13, newRestrictionType, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.endMosaicGlobalRestrictionTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicGlobalRestrictionTransactionBuffer.finishMosaicGlobalRestrictionTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MosaicSupplyChangeTransactionBuffer.ts b/src/infrastructure/buffers/MosaicSupplyChangeTransactionBuffer.ts deleted file mode 100644 index 0297f46688..0000000000 --- a/src/infrastructure/buffers/MosaicSupplyChangeTransactionBuffer.ts +++ /dev/null @@ -1,479 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicSupplyChangeTransactionBuffer} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicSupplyChangeTransactionBuffer=} obj - * @returns {Catapult.Buffers.MosaicSupplyChangeTransactionBuffer} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.getRootAsMosaicSupplyChangeTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicSupplyChangeTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.direction = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.delta = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deltaLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.prototype.deltaArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startMosaicSupplyChangeTransactionBuffer = function(builder) { - builder.startObject(10); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} direction - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addDirection = function(builder, direction) { - builder.addFieldInt8(8, direction, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deltaOffset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.addDelta = function(builder, deltaOffset) { - builder.addFieldOffset(9, deltaOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.createDeltaVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.startDeltaVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.endMosaicSupplyChangeTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MosaicSupplyChangeTransactionBuffer.finishMosaicSupplyChangeTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/MultisigModificationTransactionBuffer.ts b/src/infrastructure/buffers/MultisigModificationTransactionBuffer.ts deleted file mode 100644 index 14376de447..0000000000 --- a/src/infrastructure/buffers/MultisigModificationTransactionBuffer.ts +++ /dev/null @@ -1,571 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.CosignatoryModificationBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.CosignatoryModificationBuffer} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.CosignatoryModificationBuffer=} obj - * @returns {Catapult.Buffers.CosignatoryModificationBuffer} - */ -Catapult.Buffers.CosignatoryModificationBuffer.getRootAsCosignatoryModificationBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.CosignatoryModificationBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.cosignatoryPublicKey = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.cosignatoryPublicKeyLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.CosignatoryModificationBuffer.prototype.cosignatoryPublicKeyArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.CosignatoryModificationBuffer.startCosignatoryModificationBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.CosignatoryModificationBuffer.addType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} cosignatoryPublicKeyOffset - */ -Catapult.Buffers.CosignatoryModificationBuffer.addCosignatoryPublicKey = function(builder, cosignatoryPublicKeyOffset) { - builder.addFieldOffset(1, cosignatoryPublicKeyOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.CosignatoryModificationBuffer.createCosignatoryPublicKeyVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.CosignatoryModificationBuffer.startCosignatoryPublicKeyVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.CosignatoryModificationBuffer.endCosignatoryModificationBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.MultisigModificationTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MultisigModificationTransactionBuffer} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MultisigModificationTransactionBuffer=} obj - * @returns {Catapult.Buffers.MultisigModificationTransactionBuffer} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.getRootAsMultisigModificationTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MultisigModificationTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.minRemovalDelta = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.minApprovalDelta = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.numModifications = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.CosignatoryModificationBuffer=} obj - * @returns {Catapult.Buffers.CosignatoryModificationBuffer} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.modifications = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? (obj || new Catapult.Buffers.CosignatoryModificationBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.prototype.modificationsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startMultisigModificationTransactionBuffer = function(builder) { - builder.startObject(11); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} minRemovalDelta - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addMinRemovalDelta = function(builder, minRemovalDelta) { - builder.addFieldInt8(7, minRemovalDelta, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} minApprovalDelta - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addMinApprovalDelta = function(builder, minApprovalDelta) { - builder.addFieldInt8(8, minApprovalDelta, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numModifications - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addNumModifications = function(builder, numModifications) { - builder.addFieldInt8(9, numModifications, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} modificationsOffset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.addModifications = function(builder, modificationsOffset) { - builder.addFieldOffset(10, modificationsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.createModificationsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.startModificationsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.endMultisigModificationTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.MultisigModificationTransactionBuffer.finishMultisigModificationTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/NamespaceCreationTransactionBuffer.ts b/src/infrastructure/buffers/NamespaceCreationTransactionBuffer.ts deleted file mode 100644 index 47e9657a44..0000000000 --- a/src/infrastructure/buffers/NamespaceCreationTransactionBuffer.ts +++ /dev/null @@ -1,512 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.NamespaceCreationTransactionBuffer} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.NamespaceCreationTransactionBuffer=} obj - * @returns {Catapult.Buffers.NamespaceCreationTransactionBuffer} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.getRootAsNamespaceCreationTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.NamespaceCreationTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceType = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.durationParentId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.durationParentIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.durationParentIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceNameSize = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Encoding=} optionalEncoding - * @returns {string|Uint8Array|null} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.prototype.namespaceName = function(optionalEncoding) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startNamespaceCreationTransactionBuffer = function(builder) { - builder.startObject(12); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} namespaceType - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addNamespaceType = function(builder, namespaceType) { - builder.addFieldInt8(7, namespaceType, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} durationParentIdOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addDurationParentId = function(builder, durationParentIdOffset) { - builder.addFieldOffset(8, durationParentIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createDurationParentIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startDurationParentIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} namespaceIdOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addNamespaceId = function(builder, namespaceIdOffset) { - builder.addFieldOffset(9, namespaceIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.createNamespaceIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.startNamespaceIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} namespaceNameSize - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addNamespaceNameSize = function(builder, namespaceNameSize) { - builder.addFieldInt8(10, namespaceNameSize, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} namespaceNameOffset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.addNamespaceName = function(builder, namespaceNameOffset) { - builder.addFieldOffset(11, namespaceNameOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.endNamespaceCreationTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.NamespaceCreationTransactionBuffer.finishNamespaceCreationTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/SecretLockTransactionBuffer.ts b/src/infrastructure/buffers/SecretLockTransactionBuffer.ts deleted file mode 100644 index 4036cdd4c2..0000000000 --- a/src/infrastructure/buffers/SecretLockTransactionBuffer.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.SecretLockTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.SecretLockTransactionBuffer} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.SecretLockTransactionBuffer=} obj - * @returns {Catapult.Buffers.SecretLockTransactionBuffer} - */ -Catapult.Buffers.SecretLockTransactionBuffer.getRootAsSecretLockTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.SecretLockTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicId = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicIdLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicIdArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicAmount = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicAmountLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.mosaicAmountArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.duration = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.durationLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.durationArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.hashAlgorithm = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.secret = function(index) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.secretLength = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.secretArray = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.recipient = function(index) { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.recipientLength = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretLockTransactionBuffer.prototype.recipientArray = function() { - var offset = this.bb.__offset(this.bb_pos, 28); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.SecretLockTransactionBuffer.startSecretLockTransactionBuffer = function(builder) { - builder.startObject(13); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.SecretLockTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.SecretLockTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.SecretLockTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicIdOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addMosaicId = function(builder, mosaicIdOffset) { - builder.addFieldOffset(7, mosaicIdOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createMosaicIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startMosaicIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicAmountOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addMosaicAmount = function(builder, mosaicAmountOffset) { - builder.addFieldOffset(8, mosaicAmountOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createMosaicAmountVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startMosaicAmountVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} durationOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addDuration = function(builder, durationOffset) { - builder.addFieldOffset(9, durationOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createDurationVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startDurationVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} hashAlgorithm - */ -Catapult.Buffers.SecretLockTransactionBuffer.addHashAlgorithm = function(builder, hashAlgorithm) { - builder.addFieldInt8(10, hashAlgorithm, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} secretOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addSecret = function(builder, secretOffset) { - builder.addFieldOffset(11, secretOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createSecretVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startSecretVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} recipientOffset - */ -Catapult.Buffers.SecretLockTransactionBuffer.addRecipient = function(builder, recipientOffset) { - builder.addFieldOffset(12, recipientOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.createRecipientVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretLockTransactionBuffer.startRecipientVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretLockTransactionBuffer.endSecretLockTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.SecretLockTransactionBuffer.finishSecretLockTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/SecretProofTransactionBuffer.ts b/src/infrastructure/buffers/SecretProofTransactionBuffer.ts deleted file mode 100644 index 570f57a886..0000000000 --- a/src/infrastructure/buffers/SecretProofTransactionBuffer.ts +++ /dev/null @@ -1,549 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.SecretProofTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.SecretProofTransactionBuffer} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.SecretProofTransactionBuffer=} obj - * @returns {Catapult.Buffers.SecretProofTransactionBuffer} - */ -Catapult.Buffers.SecretProofTransactionBuffer.getRootAsSecretProofTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.SecretProofTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.hashAlgorithm = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.secret = function(index) { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.secretLength = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.secretArray = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.recipient = function(index) { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.recipientLength = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.recipientArray = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.proofSize = function() { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.proof = function(index) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.proofLength = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.SecretProofTransactionBuffer.prototype.proofArray = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.SecretProofTransactionBuffer.startSecretProofTransactionBuffer = function(builder) { - builder.startObject(12); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.SecretProofTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.SecretProofTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.SecretProofTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} hashAlgorithm - */ -Catapult.Buffers.SecretProofTransactionBuffer.addHashAlgorithm = function(builder, hashAlgorithm) { - builder.addFieldInt8(7, hashAlgorithm, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} secretOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addSecret = function(builder, secretOffset) { - builder.addFieldOffset(8, secretOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createSecretVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startSecretVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} recipientOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addRecipient = function(builder, recipientOffset) { - builder.addFieldOffset(9, recipientOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createRecipientVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startRecipientVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} proofSize - */ -Catapult.Buffers.SecretProofTransactionBuffer.addProofSize = function(builder, proofSize) { - builder.addFieldInt16(10, proofSize, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} proofOffset - */ -Catapult.Buffers.SecretProofTransactionBuffer.addProof = function(builder, proofOffset) { - builder.addFieldOffset(11, proofOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.createProofVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.SecretProofTransactionBuffer.startProofVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.SecretProofTransactionBuffer.endSecretProofTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.SecretProofTransactionBuffer.finishSecretProofTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/buffers/TransferTransactionBuffer.ts b/src/infrastructure/buffers/TransferTransactionBuffer.ts deleted file mode 100644 index 05be19edfb..0000000000 --- a/src/infrastructure/buffers/TransferTransactionBuffer.ts +++ /dev/null @@ -1,785 +0,0 @@ -/* - * Copyright 2018 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. - */ - -// automatically generated by the FlatBuffers compiler, do not modify - -/** - * @const - * @namespace - */ -var Catapult = Catapult || {}; - -/** - * @const - * @namespace - */ -Catapult.Buffers = Catapult.Buffers || {}; - -/** - * @constructor - */ -Catapult.Buffers.MessageBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MessageBuffer} - */ -Catapult.Buffers.MessageBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MessageBuffer=} obj - * @returns {Catapult.Buffers.MessageBuffer} - */ -Catapult.Buffers.MessageBuffer.getRootAsMessageBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MessageBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MessageBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MessageBuffer.prototype.payload = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MessageBuffer.prototype.payloadLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.MessageBuffer.prototype.payloadArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MessageBuffer.startMessageBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.MessageBuffer.addType = function(builder, type) { - builder.addFieldInt8(0, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} payloadOffset - */ -Catapult.Buffers.MessageBuffer.addPayload = function(builder, payloadOffset) { - builder.addFieldOffset(1, payloadOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MessageBuffer.createPayloadVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MessageBuffer.startPayloadVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MessageBuffer.endMessageBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.MosaicBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.MosaicBuffer} - */ -Catapult.Buffers.MosaicBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.MosaicBuffer=} obj - * @returns {Catapult.Buffers.MosaicBuffer} - */ -Catapult.Buffers.MosaicBuffer.getRootAsMosaicBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.MosaicBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicBuffer.prototype.id = function(index) { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicBuffer.prototype.idLength = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicBuffer.prototype.idArray = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.MosaicBuffer.prototype.amount = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.MosaicBuffer.prototype.amountLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.MosaicBuffer.prototype.amountArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.MosaicBuffer.startMosaicBuffer = function(builder) { - builder.startObject(2); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} idOffset - */ -Catapult.Buffers.MosaicBuffer.addId = function(builder, idOffset) { - builder.addFieldOffset(0, idOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicBuffer.createIdVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicBuffer.startIdVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} amountOffset - */ -Catapult.Buffers.MosaicBuffer.addAmount = function(builder, amountOffset) { - builder.addFieldOffset(1, amountOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicBuffer.createAmountVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.MosaicBuffer.startAmountVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.MosaicBuffer.endMosaicBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @constructor - */ -Catapult.Buffers.TransferTransactionBuffer = function() { - /** - * @type {flatbuffers.ByteBuffer} - */ - this.bb = null; - - /** - * @type {number} - */ - this.bb_pos = 0; -}; - -/** - * @param {number} i - * @param {flatbuffers.ByteBuffer} bb - * @returns {Catapult.Buffers.TransferTransactionBuffer} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.__init = function(i, bb) { - this.bb_pos = i; - this.bb = bb; - return this; -}; - -/** - * @param {flatbuffers.ByteBuffer} bb - * @param {Catapult.Buffers.TransferTransactionBuffer=} obj - * @returns {Catapult.Buffers.TransferTransactionBuffer} - */ -Catapult.Buffers.TransferTransactionBuffer.getRootAsTransferTransactionBuffer = function(bb, obj) { - return (obj || new Catapult.Buffers.TransferTransactionBuffer).__init(bb.readInt32(bb.position()) + bb.position(), bb); -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.size = function() { - var offset = this.bb.__offset(this.bb_pos, 4); - return offset ? this.bb.readUint32(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signature = function(index) { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signatureLength = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signatureArray = function() { - var offset = this.bb.__offset(this.bb_pos, 6); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signer = function(index) { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signerLength = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.signerArray = function() { - var offset = this.bb.__offset(this.bb_pos, 8); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.version = function() { - var offset = this.bb.__offset(this.bb_pos, 10); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.type = function() { - var offset = this.bb.__offset(this.bb_pos, 12); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.fee = function(index) { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.feeLength = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.feeArray = function() { - var offset = this.bb.__offset(this.bb_pos, 14); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.deadline = function(index) { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.readUint32(this.bb.__vector(this.bb_pos + offset) + index * 4) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.deadlineLength = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint32Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.deadlineArray = function() { - var offset = this.bb.__offset(this.bb_pos, 16); - return offset ? new Uint32Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @param {number} index - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.recipient = function(index) { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.recipientLength = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @returns {Uint8Array} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.recipientArray = function() { - var offset = this.bb.__offset(this.bb_pos, 18); - return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.messageSize = function() { - var offset = this.bb.__offset(this.bb_pos, 20); - return offset ? this.bb.readUint16(this.bb_pos + offset) : 0; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.numMosaics = function() { - var offset = this.bb.__offset(this.bb_pos, 22); - return offset ? this.bb.readUint8(this.bb_pos + offset) : 0; -}; - -/** - * @param {Catapult.Buffers.MessageBuffer=} obj - * @returns {Catapult.Buffers.MessageBuffer|null} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.message = function(obj) { - var offset = this.bb.__offset(this.bb_pos, 24); - return offset ? (obj || new Catapult.Buffers.MessageBuffer).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null; -}; - -/** - * @param {number} index - * @param {Catapult.Buffers.MosaicBuffer=} obj - * @returns {Catapult.Buffers.MosaicBuffer} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.mosaics = function(index, obj) { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? (obj || new Catapult.Buffers.MosaicBuffer).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null; -}; - -/** - * @returns {number} - */ -Catapult.Buffers.TransferTransactionBuffer.prototype.mosaicsLength = function() { - var offset = this.bb.__offset(this.bb_pos, 26); - return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0; -}; - -/** - * @param {flatbuffers.Builder} builder - */ -Catapult.Buffers.TransferTransactionBuffer.startTransferTransactionBuffer = function(builder) { - builder.startObject(12); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} size - */ -Catapult.Buffers.TransferTransactionBuffer.addSize = function(builder, size) { - builder.addFieldInt32(0, size, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signatureOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addSignature = function(builder, signatureOffset) { - builder.addFieldOffset(1, signatureOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createSignatureVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startSignatureVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} signerOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addSigner = function(builder, signerOffset) { - builder.addFieldOffset(2, signerOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createSignerVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startSignerVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} version - */ -Catapult.Buffers.TransferTransactionBuffer.addVersion = function(builder, version) { - builder.addFieldInt16(3, version, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} type - */ -Catapult.Buffers.TransferTransactionBuffer.addType = function(builder, type) { - builder.addFieldInt16(4, type, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} feeOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addFee = function(builder, feeOffset) { - builder.addFieldOffset(5, feeOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createFeeVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startFeeVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} deadlineOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addDeadline = function(builder, deadlineOffset) { - builder.addFieldOffset(6, deadlineOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createDeadlineVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt32(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startDeadlineVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} recipientOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addRecipient = function(builder, recipientOffset) { - builder.addFieldOffset(7, recipientOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createRecipientVector = function(builder, data) { - builder.startVector(1, data.length, 1); - for (var i = data.length - 1; i >= 0; i--) { - builder.addInt8(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startRecipientVector = function(builder, numElems) { - builder.startVector(1, numElems, 1); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} messageSize - */ -Catapult.Buffers.TransferTransactionBuffer.addMessageSize = function(builder, messageSize) { - builder.addFieldInt16(8, messageSize, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numMosaics - */ -Catapult.Buffers.TransferTransactionBuffer.addNumMosaics = function(builder, numMosaics) { - builder.addFieldInt8(9, numMosaics, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} messageOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addMessage = function(builder, messageOffset) { - builder.addFieldOffset(10, messageOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} mosaicsOffset - */ -Catapult.Buffers.TransferTransactionBuffer.addMosaics = function(builder, mosaicsOffset) { - builder.addFieldOffset(11, mosaicsOffset, 0); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {Array.} data - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.createMosaicsVector = function(builder, data) { - builder.startVector(4, data.length, 4); - for (var i = data.length - 1; i >= 0; i--) { - builder.addOffset(data[i]); - } - return builder.endVector(); -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {number} numElems - */ -Catapult.Buffers.TransferTransactionBuffer.startMosaicsVector = function(builder, numElems) { - builder.startVector(4, numElems, 4); -}; - -/** - * @param {flatbuffers.Builder} builder - * @returns {flatbuffers.Offset} - */ -Catapult.Buffers.TransferTransactionBuffer.endTransferTransactionBuffer = function(builder) { - var offset = builder.endObject(); - return offset; -}; - -/** - * @param {flatbuffers.Builder} builder - * @param {flatbuffers.Offset} offset - */ -Catapult.Buffers.TransferTransactionBuffer.finishTransferTransactionBufferBuffer = function(builder, offset) { - builder.finish(offset); -}; - -// Exports for Node.js and RequireJS -export default Catapult; diff --git a/src/infrastructure/builders/AccountLinkTransaction.ts b/src/infrastructure/builders/AccountLinkTransaction.ts deleted file mode 100644 index 15cdb7738c..0000000000 --- a/src/infrastructure/builders/AccountLinkTransaction.ts +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AccountLinkTransaction - */ -import { Convert as convert } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import AccountLinkTransactionBufferPackage from '../buffers/AccountLinkTransactionBuffer'; -import AccountLinkTransactionSchema from '../schemas/AccountLinkTransactionSchema'; -import {VerifiableTransaction} from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - AccountLinkTransactionBuffer, -} = AccountLinkTransactionBufferPackage.Buffers; - -export class AccountLinkTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AccountLinkTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - remoteAccountKey: any; - linkAction: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.LINK_ACCOUNT; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRemoteAccountKey(remoteAccountKey) { - this.remoteAccountKey = convert.hexToUint8(remoteAccountKey); - return this; - } - - addLinkAction(linkAction) { - this.linkAction = linkAction; - return this; - } - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = AccountLinkTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = AccountLinkTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = AccountLinkTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = AccountLinkTransactionBuffer.createFeeVector(builder, this.maxFee); - const remoteAccountKeyVector = AccountLinkTransactionBuffer.createRemoteAccountKeyVector(builder, this.remoteAccountKey); - - AccountLinkTransactionBuffer.startAccountLinkTransactionBuffer(builder); - AccountLinkTransactionBuffer.addSize(builder, 153); - AccountLinkTransactionBuffer.addSignature(builder, signatureVector); - AccountLinkTransactionBuffer.addSigner(builder, signerVector); - AccountLinkTransactionBuffer.addVersion(builder, this.version); - AccountLinkTransactionBuffer.addType(builder, this.type); - AccountLinkTransactionBuffer.addFee(builder, feeVector); - AccountLinkTransactionBuffer.addDeadline(builder, deadlineVector); - AccountLinkTransactionBuffer.addRemoteAccountKey(builder, remoteAccountKeyVector); - AccountLinkTransactionBuffer.addLinkAction(builder, this.linkAction); - - // Calculate size - - const codedTransfer = AccountLinkTransactionBuffer.endAccountLinkTransactionBuffer(builder); - builder.finish(codedTransfer); - - const bytes = builder.asUint8Array(); - return new AccountLinkTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts b/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts deleted file mode 100644 index bd355c6b94..0000000000 --- a/src/infrastructure/builders/AccountRestrictionsAddressTransaction.ts +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AccountRestrictionsAddressTransaction - */ -import { RawAddress as address } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import AccountRestrictionsAddressTransactionBufferPackage from '../buffers/AccountRestrictionsAddressTransactionBuffer'; -import AccountRestrictionsAddressModificationTransactionSchema from '../schemas/AccountRestrictionsAddressModificationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; -const { - AccountRestrictionsAddressTransactionBuffer, - RestrictionAddressModificationBuffer, -} = AccountRestrictionsAddressTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -export default class AccountRestrictionsAddressTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AccountRestrictionsAddressModificationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - restrictionType: any; - modifications: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.ACCOUNT_RESTRICTION_ADDRESS; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionType(restrictionType) { - this.restrictionType = restrictionType; - return this; - } - - addModifications(modifications) { - this.modifications = modifications; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create modifications - const modificationsArray: any = []; - this.modifications.forEach((modification) => { - const addressModificationVector = RestrictionAddressModificationBuffer - .createValueVector(builder, address.stringToAddress(modification.value)); - RestrictionAddressModificationBuffer.startRestrictionAddressModificationBuffer(builder); - RestrictionAddressModificationBuffer.addModificationType(builder, modification.type); - RestrictionAddressModificationBuffer.addValue(builder, addressModificationVector); - modificationsArray.push(RestrictionAddressModificationBuffer.endRestrictionAddressModificationBuffer(builder)); - }); - - // Create vectors - const signatureVector = AccountRestrictionsAddressTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = AccountRestrictionsAddressTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = AccountRestrictionsAddressTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = AccountRestrictionsAddressTransactionBuffer - .createFeeVector(builder, this.maxFee); - const modificationVector = AccountRestrictionsAddressTransactionBuffer - .createModificationsVector(builder, modificationsArray); - - AccountRestrictionsAddressTransactionBuffer.startAccountRestrictionsAddressTransactionBuffer(builder); - AccountRestrictionsAddressTransactionBuffer.addSize(builder, 122 + (26 * this.modifications.length)); - AccountRestrictionsAddressTransactionBuffer.addSignature(builder, signatureVector); - AccountRestrictionsAddressTransactionBuffer.addSigner(builder, signerVector); - AccountRestrictionsAddressTransactionBuffer.addVersion(builder, this.version); - AccountRestrictionsAddressTransactionBuffer.addType(builder, this.type); - AccountRestrictionsAddressTransactionBuffer.addFee(builder, feeVector); - AccountRestrictionsAddressTransactionBuffer.addDeadline(builder, deadlineVector); - AccountRestrictionsAddressTransactionBuffer.addRestrictionType(builder, this.restrictionType); - AccountRestrictionsAddressTransactionBuffer.addModificationCount(builder, this.modifications.length); - AccountRestrictionsAddressTransactionBuffer.addModifications(builder, modificationVector); - - // Calculate size - const codedAccountRestrictionsAddress = - AccountRestrictionsAddressTransactionBuffer.endAccountRestrictionsAddressTransactionBuffer(builder); - builder.finish(codedAccountRestrictionsAddress); - - const bytes = builder.asUint8Array(); - - return new AccountRestrictionsAddressTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts b/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts deleted file mode 100644 index 6973e8ccc4..0000000000 --- a/src/infrastructure/builders/AccountRestrictionsEntityTypeTransaction.ts +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AccountRestrictionsEntityTypeTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import AccountRestrictionsEntityTypeTransactionBufferPackage from '../buffers/AccountRestrictionsEntityTypeTransactionBuffer'; -import AccountRestrictionsEntityTypeModificationTransactionSchema from '../schemas/AccountRestrictionsEntityTypeModificationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - AccountRestrictionsEntityTypeTransactionBuffer, - RestrictionEntityTypeModificationBuffer, -} = AccountRestrictionsEntityTypeTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -export default class AccountRestrictionsEntityTypeTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AccountRestrictionsEntityTypeModificationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - restrictionType: any; - modifications: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.ACCOUNT_RESTRICTION_OPERATION; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionType(restrictionType) { - this.restrictionType = restrictionType; - return this; - } - - addModifications(modifications) { - this.modifications = modifications; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create modifications - const modificationsArray: any = []; - this.modifications.forEach((modification) => { - RestrictionEntityTypeModificationBuffer.startRestrictionEntityTypeModificationBuffer(builder); - RestrictionEntityTypeModificationBuffer.addModificationType(builder, modification.type); - RestrictionEntityTypeModificationBuffer.addValue(builder, modification.value); - modificationsArray.push(RestrictionEntityTypeModificationBuffer.endRestrictionEntityTypeModificationBuffer(builder)); - }); - - // Create vectors - const signatureVector = AccountRestrictionsEntityTypeTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = AccountRestrictionsEntityTypeTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = AccountRestrictionsEntityTypeTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = AccountRestrictionsEntityTypeTransactionBuffer - .createFeeVector(builder, this.maxFee); - const modificationVector = AccountRestrictionsEntityTypeTransactionBuffer - .createModificationsVector(builder, modificationsArray); - - AccountRestrictionsEntityTypeTransactionBuffer.startAccountRestrictionsEntityTypeTransactionBuffer(builder); - AccountRestrictionsEntityTypeTransactionBuffer.addSize(builder, 122 + (3 * this.modifications.length)); - AccountRestrictionsEntityTypeTransactionBuffer.addSignature(builder, signatureVector); - AccountRestrictionsEntityTypeTransactionBuffer.addSigner(builder, signerVector); - AccountRestrictionsEntityTypeTransactionBuffer.addVersion(builder, this.version); - AccountRestrictionsEntityTypeTransactionBuffer.addType(builder, this.type); - AccountRestrictionsEntityTypeTransactionBuffer.addFee(builder, feeVector); - AccountRestrictionsEntityTypeTransactionBuffer.addDeadline(builder, deadlineVector); - AccountRestrictionsEntityTypeTransactionBuffer.addRestrictionType(builder, this.restrictionType); - AccountRestrictionsEntityTypeTransactionBuffer.addModificationCount(builder, this.modifications.length); - AccountRestrictionsEntityTypeTransactionBuffer.addModifications(builder, modificationVector); - - // Calculate size - const codedAccountRestrictionsAddress = AccountRestrictionsEntityTypeTransactionBuffer - .endAccountRestrictionsEntityTypeTransactionBuffer(builder); - builder.finish(codedAccountRestrictionsAddress); - - const bytes = builder.asUint8Array(); - - return new AccountRestrictionsEntityTypeTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts b/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts deleted file mode 100644 index da9338deb4..0000000000 --- a/src/infrastructure/builders/AccountRestrictionsMosaicTransaction.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AccountRestrictionsMosaicTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import AccountRestrictionsMosaicTransactionBufferPackage from '../buffers/AccountRestrictionsMosaicTransactionBuffer'; -import AccountRestrictionsMosaicModificationTransactionSchema from '../schemas/AccountRestrictionsMosaicModificationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - AccountRestrictionsMosaicTransactionBuffer, - RestrictionMosaicModificationBuffer, -} = AccountRestrictionsMosaicTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -export default class AccountRestrictionsMosaicTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AccountRestrictionsMosaicModificationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - restrictionType: any; - modifications: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.ACCOUNT_RESTRICTION_MOSAIC; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionType(restrictionType) { - this.restrictionType = restrictionType; - return this; - } - - addModifications(modifications) { - this.modifications = modifications; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create modifications - const modificationsArray: any = []; - this.modifications.forEach((modification) => { - const addressModificationVector = RestrictionMosaicModificationBuffer - .createValueVector(builder, modification.value); - RestrictionMosaicModificationBuffer.startRestrictionMosaicModificationBuffer(builder); - RestrictionMosaicModificationBuffer.addModificationType(builder, modification.type); - RestrictionMosaicModificationBuffer.addValue(builder, addressModificationVector); - modificationsArray.push(RestrictionMosaicModificationBuffer.endRestrictionMosaicModificationBuffer(builder)); - }); - - // Create vectors - const signatureVector = AccountRestrictionsMosaicTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = AccountRestrictionsMosaicTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = AccountRestrictionsMosaicTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = AccountRestrictionsMosaicTransactionBuffer - .createFeeVector(builder, this.maxFee); - const modificationVector = AccountRestrictionsMosaicTransactionBuffer - .createModificationsVector(builder, modificationsArray); - - AccountRestrictionsMosaicTransactionBuffer.startAccountRestrictionsMosaicTransactionBuffer(builder); - AccountRestrictionsMosaicTransactionBuffer.addSize(builder, 122 + (9 * this.modifications.length)); - AccountRestrictionsMosaicTransactionBuffer.addSignature(builder, signatureVector); - AccountRestrictionsMosaicTransactionBuffer.addSigner(builder, signerVector); - AccountRestrictionsMosaicTransactionBuffer.addVersion(builder, this.version); - AccountRestrictionsMosaicTransactionBuffer.addType(builder, this.type); - AccountRestrictionsMosaicTransactionBuffer.addFee(builder, feeVector); - AccountRestrictionsMosaicTransactionBuffer.addDeadline(builder, deadlineVector); - AccountRestrictionsMosaicTransactionBuffer.addRestrictionType(builder, this.restrictionType); - AccountRestrictionsMosaicTransactionBuffer.addModificationCount(builder, this.modifications.length); - AccountRestrictionsMosaicTransactionBuffer.addModifications(builder, modificationVector); - - // Calculate size - const codedAccountRestrictionsMosaic = AccountRestrictionsMosaicTransactionBuffer.endAccountRestrictionsMosaicTransactionBuffer(builder); - builder.finish(codedAccountRestrictionsMosaic); - - const bytes = builder.asUint8Array(); - - return new AccountRestrictionsMosaicTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/AddressAliasTransaction.ts b/src/infrastructure/builders/AddressAliasTransaction.ts deleted file mode 100644 index bbbda06fb9..0000000000 --- a/src/infrastructure/builders/AddressAliasTransaction.ts +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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 { RawAddress as addressLibrary } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import AddressAliasTransactionBufferPackage from '../buffers/AddressAliasTransactionBuffer'; -import AddressAliasTransactionSchema from '../schemas/AddressAliasTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - AddressAliasTransactionBuffer, -} = AddressAliasTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -/** - * @module transactions/AddressAliasTransaction - */ -export class AddressAliasTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AddressAliasTransactionSchema); - } -} -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - address: any; - namespaceId: any; - aliasAction: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.ADDRESS_ALIAS; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addAliasAction(aliasAction) { - this.aliasAction = aliasAction; - return this; - } - - addNamespaceId(namespaceId) { - this.namespaceId = namespaceId; - return this; - } - - addAddress(address) { - this.address = addressLibrary.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.maxFee); - 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.addAliasAction(builder, this.aliasAction); - 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); - } -} diff --git a/src/infrastructure/builders/AggregateTransaction.ts b/src/infrastructure/builders/AggregateTransaction.ts deleted file mode 100644 index 8aae5a5e28..0000000000 --- a/src/infrastructure/builders/AggregateTransaction.ts +++ /dev/null @@ -1,151 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/AggregateTransaction - */ -import { SignSchema } from '../../core/crypto'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import AggregateTransactionBufferPackage from '../buffers/AggregateTransactionBuffer'; -import AggregateTransactionSchema from '../schemas/AggregateTransactionSchema'; -import { CosignatureTransaction} from './CosignatureTransaction'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - AggregateTransactionBuffer, -} = AggregateTransactionBufferPackage.Buffers; - -export class AggregateTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, AggregateTransactionSchema); - } - - signTransactionWithCosigners(initializer, cosigners, generationHash, signSchema: SignSchema = SignSchema.SHA3) { - const signedTransaction = this.signTransaction(initializer, generationHash, signSchema); - cosigners.forEach((cosigner) => { - const signatureTransaction = new CosignatureTransaction(signedTransaction.hash); - const signatureCosignTransaction = signatureTransaction.signCosignatoriesTransaction(cosigner, signSchema); - signedTransaction.payload = signedTransaction.payload + - signatureCosignTransaction.signer + signatureCosignTransaction.signature; - }); - - // Calculate new size - const size = `00000000${(signedTransaction.payload.length / 2).toString(16)}`; - const formatedSize = size.substr(size.length - 8, size.length); - const littleEndianSize = formatedSize.substr(6, 2) + formatedSize.substr(4, 2) + - formatedSize.substr(2, 2) + formatedSize.substr(0, 2); - - signedTransaction.payload = littleEndianSize + - signedTransaction.payload.substr(8, signedTransaction.payload.length - 8); - - return signedTransaction; - } - - signTransactionGivenSignatures(initializer, cosignedSignedTransactions, generationHash, signSchema = SignSchema.SHA3) { - const signedTransaction = this.signTransaction(initializer, generationHash, signSchema); - cosignedSignedTransactions.forEach((cosignedTransaction) => { - signedTransaction.payload = signedTransaction.payload + cosignedTransaction.signer + cosignedTransaction.signature; - }); - - // Calculate new size - const size = `00000000${(signedTransaction.payload.length / 2).toString(16)}`; - const formatedSize = size.substr(size.length - 8, size.length); - const littleEndianSize = formatedSize.substr(6, 2) + formatedSize.substr(4, 2) + - formatedSize.substr(2, 2) + formatedSize.substr(0, 2); - - signedTransaction.payload = littleEndianSize + - signedTransaction.payload.substr(8, signedTransaction.payload.length - 8); - - return signedTransaction; - } -} -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - transactions: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.AGGREGATE_COMPLETE; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addTransactions(transactions) { - let tmp = []; - for (let i = 0; i < transactions.length; ++i) { - tmp = tmp.concat(transactions[i]); - } - - this.transactions = tmp; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = AggregateTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)) - .map(Number.prototype.valueOf, 0)); - const signerVector = AggregateTransactionBuffer - .createSignerVector(builder, Array(...Array(32)) - .map(Number.prototype.valueOf, 0)); - const deadlineVector = AggregateTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = AggregateTransactionBuffer.createFeeVector(builder, this.maxFee); - const modificationsVector = AggregateTransactionBuffer.createTransactionsVector(builder, this.transactions); - - AggregateTransactionBuffer.startAggregateTransactionBuffer(builder); - AggregateTransactionBuffer.addSize(builder, 120 + 4 + this.transactions.length); - AggregateTransactionBuffer.addSignature(builder, signatureVector); - AggregateTransactionBuffer.addSigner(builder, signerVector); - AggregateTransactionBuffer.addVersion(builder, this.version); - AggregateTransactionBuffer.addType(builder, this.type); - AggregateTransactionBuffer.addFee(builder, feeVector); - AggregateTransactionBuffer.addDeadline(builder, deadlineVector); - AggregateTransactionBuffer.addTransactionsSize(builder, 0 !== this.transactions.length ? this.transactions.length : 4294967296); - AggregateTransactionBuffer.addTransactions(builder, modificationsVector); - - // Calculate size - const codedAggregate = AggregateTransactionBuffer.endAggregateTransactionBuffer(builder); - builder.finish(codedAggregate); - - const bytes = builder.asUint8Array(); - return new AggregateTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/CosignatureTransaction.ts b/src/infrastructure/builders/CosignatureTransaction.ts deleted file mode 100644 index 717041f910..0000000000 --- a/src/infrastructure/builders/CosignatureTransaction.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 { Convert as convert } from '../../core/format/Convert'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -/** - * @module transactions/AggregateSignatureTransaction - * @version 1.0.0 - */ -export class CosignatureTransaction extends VerifiableTransaction { - constructor(hash) { - super(convert.hexToUint8(hash), undefined); - } -} diff --git a/src/infrastructure/builders/Deadline.ts b/src/infrastructure/builders/Deadline.ts deleted file mode 100644 index 3b37923c5a..0000000000 --- a/src/infrastructure/builders/Deadline.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 { RawUInt64 as uint64 } from '../../core/format'; - -export default function deadline(deadlineParam) { - const NetworkTime = (new Date()).getTime() - 1459468800000; - const deadlineValue = deadlineParam || 60 * 60 * 1000; - return uint64.fromUint(deadlineValue + NetworkTime); -} \ No newline at end of file diff --git a/src/infrastructure/builders/HashLockTransaction.ts b/src/infrastructure/builders/HashLockTransaction.ts deleted file mode 100644 index 538454d3ea..0000000000 --- a/src/infrastructure/builders/HashLockTransaction.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/HashLockTransaction - */ -import { Convert as convert } from '../../core/format'; -import * as HashLockTransactionBufferPackage from '../buffers/HashLockTransactionBuffer'; -import HashLockTransactionSchema from '../schemas/HashLockTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; -import { TransactionType } from '../../model/transaction/TransactionType'; - -import {flatbuffers} from 'flatbuffers'; - -const { - HashLockTransactionBuffer, -} = HashLockTransactionBufferPackage.default.Buffers; - -export default class HashLockTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, HashLockTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - mosaicAmount: any; - duration: any; - hash: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.LOCK; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - addMosaicAmount(mosaicAmount) { - this.mosaicAmount = mosaicAmount; - return this; - } - - addDuration(duration) { - this.duration = duration; - return this; - } - - addHash(hash) { - this.hash = hash; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = HashLockTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = HashLockTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = HashLockTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = HashLockTransactionBuffer.createFeeVector(builder, this.maxFee); - const mosaicIdVector = HashLockTransactionBuffer.createMosaicIdVector(builder, this.mosaicId); - const mosaicAmountVector = HashLockTransactionBuffer.createMosaicAmountVector(builder, this.mosaicAmount); - const durationVector = HashLockTransactionBuffer.createDurationVector(builder, this.duration); - const byteHash = convert.hexToUint8(this.hash); - const hashVector = HashLockTransactionBuffer.createHashVector(builder, byteHash); - - HashLockTransactionBuffer.startHashLockTransactionBuffer(builder); - HashLockTransactionBuffer.addSize(builder, 176); - HashLockTransactionBuffer.addSignature(builder, signatureVector); - HashLockTransactionBuffer.addSigner(builder, signerVector); - HashLockTransactionBuffer.addVersion(builder, this.version); - HashLockTransactionBuffer.addType(builder, this.type); - HashLockTransactionBuffer.addFee(builder, feeVector); - HashLockTransactionBuffer.addDeadline(builder, deadlineVector); - HashLockTransactionBuffer.addMosaicId(builder, mosaicIdVector); - HashLockTransactionBuffer.addMosaicAmount(builder, mosaicAmountVector); - HashLockTransactionBuffer.addDuration(builder, durationVector); - HashLockTransactionBuffer.addHash(builder, hashVector); - - const codedHashLock = HashLockTransactionBuffer.endHashLockTransactionBuffer(builder); - builder.finish(codedHashLock); - - const bytes = builder.asUint8Array(); - return new HashLockTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/MosaicAddressRestrictionTransaction.ts b/src/infrastructure/builders/MosaicAddressRestrictionTransaction.ts deleted file mode 100644 index 0b214c496b..0000000000 --- a/src/infrastructure/builders/MosaicAddressRestrictionTransaction.ts +++ /dev/null @@ -1,146 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/MosaicAddressRestrictionTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicAddressRestrictionTransactionBufferPackage from '../buffers/MosaicAddressRestrictionTransactionBuffer'; -import MosaicAddressRestrictionTransactionSchema from '../schemas/MosaicAddressRestrictionTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; -import { RawAddress } from '../../core/format'; - -const { - MosaicAddressRestrictionTransactionBuffer, -} = MosaicAddressRestrictionTransactionBufferPackage.Buffers; - -export default class MosaicAddressRestrictionTransaction extends VerifiableTransaction { - constructor(bytes, schema) { - super(bytes, schema); - } -} -// tslint:disable-next-line: max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - restrictionKey: any; - targetAddress: any; - previousRestrictionValue: any; - newRestrictionValue: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_ADDRESS_RESTRICTION; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionKey(restrictionKey) { - this.restrictionKey = restrictionKey; - return this; - } - - addTargetAddress(targetAddress) { - this.targetAddress = RawAddress.stringToAddress(targetAddress); - return this; - } - - addPreviousRestrictionValue(previousRestrictionValue) { - this.previousRestrictionValue = previousRestrictionValue; - return this; - } - - addNewRestrictionValue(newRestrictionValue) { - this.newRestrictionValue = newRestrictionValue; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicAddressRestrictionTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicAddressRestrictionTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicAddressRestrictionTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicAddressRestrictionTransactionBuffer - .createFeeVector(builder, this.maxFee); - const mosaicIdVector = MosaicAddressRestrictionTransactionBuffer - .createMosaicIdVector(builder, this.mosaicId); - const restrictionKeyVector = MosaicAddressRestrictionTransactionBuffer - .createRestrictionKeyVector(builder, this.restrictionKey); - const targetAddressVector = MosaicAddressRestrictionTransactionBuffer - .createTargetAddressVector(builder, this.targetAddress); - const previousRestrictionValueVector = MosaicAddressRestrictionTransactionBuffer - .createPreviousRestrictionValueVector(builder, this.previousRestrictionValue); - const newRestrictionValueVector = MosaicAddressRestrictionTransactionBuffer - .createNewRestrictionValueVector(builder, this.newRestrictionValue); - - MosaicAddressRestrictionTransactionBuffer.startMosaicAddressRestrictionTransactionBuffer(builder); - MosaicAddressRestrictionTransactionBuffer.addSize(builder, 169); - MosaicAddressRestrictionTransactionBuffer.addSignature(builder, signatureVector); - MosaicAddressRestrictionTransactionBuffer.addSigner(builder, signerVector); - MosaicAddressRestrictionTransactionBuffer.addVersion(builder, this.version); - MosaicAddressRestrictionTransactionBuffer.addType(builder, this.type); - MosaicAddressRestrictionTransactionBuffer.addFee(builder, feeVector); - MosaicAddressRestrictionTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicAddressRestrictionTransactionBuffer.addMosaicId(builder, mosaicIdVector); - MosaicAddressRestrictionTransactionBuffer.addRestrictionKey(builder, restrictionKeyVector); - MosaicAddressRestrictionTransactionBuffer.addTargetAddress(builder, targetAddressVector); - MosaicAddressRestrictionTransactionBuffer.addPreviousRestrictionValue(builder, previousRestrictionValueVector); - MosaicAddressRestrictionTransactionBuffer.addNewRestrictionValue(builder, newRestrictionValueVector); - - // Calculate size - - const codedMosaicAddressRestriction = - MosaicAddressRestrictionTransactionBuffer.endMosaicAddressRestrictionTransactionBuffer(builder); - builder.finish(codedMosaicAddressRestriction); - - const bytes = builder.asUint8Array(); - - const schema = MosaicAddressRestrictionTransactionSchema; - return new MosaicAddressRestrictionTransaction(bytes, schema); - } -} diff --git a/src/infrastructure/builders/MosaicAliasTransaction.ts b/src/infrastructure/builders/MosaicAliasTransaction.ts deleted file mode 100644 index 7d3abcb45d..0000000000 --- a/src/infrastructure/builders/MosaicAliasTransaction.ts +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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 { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicAliasTransactionBufferPackage from '../buffers/MosaicAliasTransactionBuffer'; -import MosaicAliasTransactionSchema from '../schemas/MosaicAliasTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - MosaicAliasTransactionBuffer, -} = MosaicAliasTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -/** - * @module transactions/MosaicAliasTransaction - */ -export default class MosaicAliasTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, MosaicAliasTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - aliasAction: any; - namespaceId: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_ALIAS; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addAliasAction(aliasAction) { - this.aliasAction = aliasAction; - return this; - } - - addNamespaceId(namespaceId) { - this.namespaceId = namespaceId; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicAliasTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicAliasTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicAliasTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicAliasTransactionBuffer - .createFeeVector(builder, this.maxFee); - const namespaceIdVector = MosaicAliasTransactionBuffer - .createNamespaceIdVector(builder, this.namespaceId); - const mosaicIdVector = MosaicAliasTransactionBuffer - .createMosaicIdVector(builder, this.mosaicId); - - MosaicAliasTransactionBuffer.startMosaicAliasTransactionBuffer(builder); - MosaicAliasTransactionBuffer.addSize(builder, 137); - MosaicAliasTransactionBuffer.addSignature(builder, signatureVector); - MosaicAliasTransactionBuffer.addSigner(builder, signerVector); - MosaicAliasTransactionBuffer.addVersion(builder, this.version); - MosaicAliasTransactionBuffer.addType(builder, this.type); - MosaicAliasTransactionBuffer.addFee(builder, feeVector); - MosaicAliasTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicAliasTransactionBuffer.addAliasAction(builder, this.aliasAction); - MosaicAliasTransactionBuffer.addNamespaceId(builder, namespaceIdVector); - MosaicAliasTransactionBuffer.addMosaicId(builder, mosaicIdVector); - - // Calculate size - const codedMosaicChangeSupply = MosaicAliasTransactionBuffer.endMosaicAliasTransactionBuffer(builder); - builder.finish(codedMosaicChangeSupply); - - const bytes = builder.asUint8Array(); - - return new MosaicAliasTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/MosaicCreationTransaction.ts b/src/infrastructure/builders/MosaicCreationTransaction.ts deleted file mode 100644 index d74ba21660..0000000000 --- a/src/infrastructure/builders/MosaicCreationTransaction.ts +++ /dev/null @@ -1,164 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/MosaicCreationTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicCreationTransactionBufferPackage from '../buffers/MosaicCreationTransactionBuffer'; -import { - schema as MosaicCreationTransactionSchema, - schemaNoDuration as MosaicCreationTransactionSchemaNoDuration, -} from '../schemas/MosaicCreationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - MosaicCreationTransactionBuffer, -} = MosaicCreationTransactionBufferPackage.Buffers; - -export default class MosaicCreationTransaction extends VerifiableTransaction { - constructor(bytes, schema) { - super(bytes, schema); - } -} -// tslint:disable-next-line: max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - flags: any; - nonce: any; - divisibility: any; - duration: any; - constructor() { - this.flags = 0; - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_DEFINITION; - this.nonce = 0; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addNonce(nonce) { - this.nonce = nonce; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addDuration(duration) { - this.duration = duration; - return this; - } - - addDivisibility(divisibility) { - this.divisibility = divisibility; - return this; - } - - addSupplyMutable() { - this.flags += 1; - return this; - } - - addTransferability() { - this.flags += 2; - return this; - } - - addRestrictable() { - this.flags += 4; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicCreationTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicCreationTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicCreationTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicCreationTransactionBuffer - .createFeeVector(builder, this.maxFee); - const nonceVector = MosaicCreationTransactionBuffer - .createNonceVector(builder, this.nonce); - const mosaicIdVector = MosaicCreationTransactionBuffer - .createMosaicIdVector(builder, this.mosaicId); - - const durationVector = MosaicCreationTransactionBuffer - .createDurationVector(builder, this.duration); - - const durationProvided = 0 < this.duration.length; - - MosaicCreationTransactionBuffer.startMosaicCreationTransactionBuffer(builder); - MosaicCreationTransactionBuffer.addSize(builder, durationProvided ? 144 : 135); - MosaicCreationTransactionBuffer.addSignature(builder, signatureVector); - MosaicCreationTransactionBuffer.addSigner(builder, signerVector); - MosaicCreationTransactionBuffer.addVersion(builder, this.version); - MosaicCreationTransactionBuffer.addType(builder, this.type); - MosaicCreationTransactionBuffer.addFee(builder, feeVector); - MosaicCreationTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicCreationTransactionBuffer.addNonce(builder, nonceVector); - MosaicCreationTransactionBuffer.addMosaicId(builder, mosaicIdVector); - MosaicCreationTransactionBuffer.addNumOptionalProperties(builder, durationProvided ? 1 : 0); - MosaicCreationTransactionBuffer.addFlags(builder, this.flags); - - MosaicCreationTransactionBuffer.addDivisibility(builder, this.divisibility); - - if (durationProvided) { - MosaicCreationTransactionBuffer.addIndicateDuration(builder, 2); - MosaicCreationTransactionBuffer.addDuration(builder, durationVector); - } - - // Calculate size - - const codedMosaicCreation = MosaicCreationTransactionBuffer.endMosaicCreationTransactionBuffer(builder); - builder.finish(codedMosaicCreation); - - const bytes = builder.asUint8Array(); - - const schema = durationProvided ? MosaicCreationTransactionSchema : MosaicCreationTransactionSchemaNoDuration; - return new MosaicCreationTransaction(bytes, schema); - } -} diff --git a/src/infrastructure/builders/MosaicGlobalRestrictionTransaction.ts b/src/infrastructure/builders/MosaicGlobalRestrictionTransaction.ts deleted file mode 100644 index 608cc0f2c0..0000000000 --- a/src/infrastructure/builders/MosaicGlobalRestrictionTransaction.ts +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/MosaicGlobalRestrictionTransaction - */ -import { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicGlobalRestrictionTransactionBufferPackage from '../buffers/MosaicGlobalRestrictionTransactionBuffer'; -import MosaicGlobalRestrictionTransactionSchema from '../schemas/MosaicGlobalRestrictionTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - MosaicGlobalRestrictionTransactionBuffer, -} = MosaicGlobalRestrictionTransactionBufferPackage.Buffers; - -export default class MosaicGlobalRestrictionTransaction extends VerifiableTransaction { - constructor(bytes, schema) { - super(bytes, schema); - } -} -// tslint:disable-next-line: max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - referenceMosaicId: any; - restrictionKey: any; - previousRestrictionValue: any; - previousRestrictionType: any; - newRestrictionValue: any; - newRestrictionType: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_GLOBAL_RESTRICTION; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRestrictionKey(restrictionKey) { - this.restrictionKey = restrictionKey; - return this; - } - - addPreviousRestrictionValue(previousRestrictionValue) { - this.previousRestrictionValue = previousRestrictionValue; - return this; - } - - addPreviousRestrictionType(previousRestrictionType) { - this.previousRestrictionType = previousRestrictionType; - return this; - } - - addNewRestrictionValue(newRestrictionValue) { - this.newRestrictionValue = newRestrictionValue; - return this; - } - - addNewRestrictionType(newRestrictionType) { - this.newRestrictionType = newRestrictionType; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - addReferenceMosaicId(referenceMosaicId) { - this.referenceMosaicId = referenceMosaicId; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicGlobalRestrictionTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicGlobalRestrictionTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicGlobalRestrictionTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicGlobalRestrictionTransactionBuffer - .createFeeVector(builder, this.maxFee); - const mosaicIdVector = MosaicGlobalRestrictionTransactionBuffer - .createMosaicIdVector(builder, this.mosaicId); - const referenceMosaicIdVector = MosaicGlobalRestrictionTransactionBuffer - .createReferenceMosaicIdVector(builder, this.referenceMosaicId); - const restrictionKeyVector = MosaicGlobalRestrictionTransactionBuffer - .createRestrictionKeyVector(builder, this.restrictionKey); - const previousRestrictionValueVector = MosaicGlobalRestrictionTransactionBuffer - .createPreviousRestrictionValueVector(builder, this.previousRestrictionValue); - const newRestrictionValueVector = MosaicGlobalRestrictionTransactionBuffer - .createNewRestrictionValueVector(builder, this.newRestrictionValue); - - MosaicGlobalRestrictionTransactionBuffer.startMosaicGlobalRestrictionTransactionBuffer(builder); - MosaicGlobalRestrictionTransactionBuffer.addSize(builder, 162); - MosaicGlobalRestrictionTransactionBuffer.addSignature(builder, signatureVector); - MosaicGlobalRestrictionTransactionBuffer.addSigner(builder, signerVector); - MosaicGlobalRestrictionTransactionBuffer.addVersion(builder, this.version); - MosaicGlobalRestrictionTransactionBuffer.addType(builder, this.type); - MosaicGlobalRestrictionTransactionBuffer.addFee(builder, feeVector); - MosaicGlobalRestrictionTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicGlobalRestrictionTransactionBuffer.addMosaicId(builder, mosaicIdVector); - MosaicGlobalRestrictionTransactionBuffer.addReferenceMosaicId(builder, referenceMosaicIdVector); - MosaicGlobalRestrictionTransactionBuffer.addRestrictionKey(builder, restrictionKeyVector); - MosaicGlobalRestrictionTransactionBuffer.addPreviousRestrictionValue(builder, previousRestrictionValueVector); - MosaicGlobalRestrictionTransactionBuffer.addPreviousRestrictionType(builder, this.previousRestrictionType); - MosaicGlobalRestrictionTransactionBuffer.addNewRestrictionValue(builder, newRestrictionValueVector); - MosaicGlobalRestrictionTransactionBuffer.addNewRestrictionType(builder, this.newRestrictionType); - - // Calculate size - - const codedMosaicGlobalRestriction = - MosaicGlobalRestrictionTransactionBuffer.endMosaicGlobalRestrictionTransactionBuffer(builder); - builder.finish(codedMosaicGlobalRestriction); - - const bytes = builder.asUint8Array(); - - const schema = MosaicGlobalRestrictionTransactionSchema; - return new MosaicGlobalRestrictionTransaction(bytes, schema); - } -} diff --git a/src/infrastructure/builders/MosaicSupplyChangeTransaction.ts b/src/infrastructure/builders/MosaicSupplyChangeTransaction.ts deleted file mode 100644 index cfff8db53c..0000000000 --- a/src/infrastructure/builders/MosaicSupplyChangeTransaction.ts +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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 { TransactionType } from '../../model/transaction/TransactionType'; -import MosaicSupplyChangeTransactionBufferPackage from '../buffers/MosaicSupplyChangeTransactionBuffer'; -import MosaicSupplyChangeTransactionSchema from '../schemas/MosaicSupplyChangeTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - MosaicSupplyChangeTransactionBuffer, -} = MosaicSupplyChangeTransactionBufferPackage.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -/** - * @module transactions/MosaicSupplyChangeTransaction - */ -export default class MosaicSupplyChangeTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, MosaicSupplyChangeTransactionSchema); - } -} -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - direction: any; - delta: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MOSAIC_SUPPLY_CHANGE; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - addDirection(direction) { - this.direction = direction; - return this; - } - - addDelta(delta) { - this.delta = delta; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = MosaicSupplyChangeTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MosaicSupplyChangeTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MosaicSupplyChangeTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MosaicSupplyChangeTransactionBuffer - .createFeeVector(builder, this.maxFee); - const mosaicIdVector = MosaicSupplyChangeTransactionBuffer - .createFeeVector(builder, this.mosaicId); - const deltaVector = MosaicSupplyChangeTransactionBuffer - .createFeeVector(builder, this.delta); - - MosaicSupplyChangeTransactionBuffer.startMosaicSupplyChangeTransactionBuffer(builder); - MosaicSupplyChangeTransactionBuffer.addSize(builder, 137); - MosaicSupplyChangeTransactionBuffer.addSignature(builder, signatureVector); - MosaicSupplyChangeTransactionBuffer.addSigner(builder, signerVector); - MosaicSupplyChangeTransactionBuffer.addVersion(builder, this.version); - MosaicSupplyChangeTransactionBuffer.addType(builder, this.type); - MosaicSupplyChangeTransactionBuffer.addFee(builder, feeVector); - MosaicSupplyChangeTransactionBuffer.addDeadline(builder, deadlineVector); - MosaicSupplyChangeTransactionBuffer.addMosaicId(builder, mosaicIdVector); - MosaicSupplyChangeTransactionBuffer.addDirection(builder, this.direction); - MosaicSupplyChangeTransactionBuffer.addDelta(builder, deltaVector); - - // Calculate size - const codedMosaicChangeSupply = MosaicSupplyChangeTransactionBuffer.endMosaicSupplyChangeTransactionBuffer(builder); - builder.finish(codedMosaicChangeSupply); - - const bytes = builder.asUint8Array(); - return new MosaicSupplyChangeTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/MultisigModificationTransaction.ts b/src/infrastructure/builders/MultisigModificationTransaction.ts deleted file mode 100644 index a11dbfdeb5..0000000000 --- a/src/infrastructure/builders/MultisigModificationTransaction.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* - * 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 { Convert as convert } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import MultisigModificationTransactionBufferPackage from '../buffers/MultisigModificationTransactionBuffer'; -import MultisigModificationTransactionSchema from '../schemas/MultisigModificationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - MultisigModificationTransactionBuffer, - CosignatoryModificationBuffer, -} = MultisigModificationTransactionBufferPackage.Buffers; - -/** - * @module transactions/MultisigModificationTransaction - */ -export default class MultisigModificationTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, MultisigModificationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - minRemovalDelta: any; - minApprovalDelta: any; - modifications: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.MODIFY_MULTISIG_ACCOUNT; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addMinRemovalDelta(minRemovalDelta) { - this.minRemovalDelta = minRemovalDelta; - return this; - } - - addMinApprovalDelta(minApprovalDelta) { - this.minApprovalDelta = minApprovalDelta; - return this; - } - - addModifications(modifications) { - this.modifications = modifications; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create modifications - const modificationsArray: any = []; - this.modifications.forEach((modification) => { - const cosignatoryPublicKeyVector = CosignatoryModificationBuffer - .createCosignatoryPublicKeyVector(builder, convert.hexToUint8(modification.cosignatoryPublicKey)); - CosignatoryModificationBuffer.startCosignatoryModificationBuffer(builder); - CosignatoryModificationBuffer.addType(builder, modification.type); - CosignatoryModificationBuffer.addCosignatoryPublicKey(builder, cosignatoryPublicKeyVector); - modificationsArray.push(CosignatoryModificationBuffer.endCosignatoryModificationBuffer(builder)); - }); - - // Create vectors - const signatureVector = MultisigModificationTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = MultisigModificationTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = MultisigModificationTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = MultisigModificationTransactionBuffer - .createFeeVector(builder, this.maxFee); - const modificationsVector = MultisigModificationTransactionBuffer - .createModificationsVector(builder, modificationsArray); - - MultisigModificationTransactionBuffer.startMultisigModificationTransactionBuffer(builder); - MultisigModificationTransactionBuffer.addSize(builder, 123 + (33 * this.modifications.length)); - MultisigModificationTransactionBuffer.addSignature(builder, signatureVector); - MultisigModificationTransactionBuffer.addSigner(builder, signerVector); - MultisigModificationTransactionBuffer.addVersion(builder, this.version); - MultisigModificationTransactionBuffer.addType(builder, this.type); - MultisigModificationTransactionBuffer.addFee(builder, feeVector); - MultisigModificationTransactionBuffer.addDeadline(builder, deadlineVector); - MultisigModificationTransactionBuffer.addMinRemovalDelta(builder, this.minRemovalDelta); - MultisigModificationTransactionBuffer.addMinApprovalDelta(builder, this.minApprovalDelta); - MultisigModificationTransactionBuffer.addNumModifications(builder, this.modifications.length); - MultisigModificationTransactionBuffer.addModifications(builder, modificationsVector); - - // Calculate size - const codedMultisigAggregate = MultisigModificationTransactionBuffer - .endMultisigModificationTransactionBuffer(builder); - builder.finish(codedMultisigAggregate); - - const bytes = builder.asUint8Array(); - return new MultisigModificationTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/NamespaceCreationTransaction.ts b/src/infrastructure/builders/NamespaceCreationTransaction.ts deleted file mode 100644 index 0cf2ba5d67..0000000000 --- a/src/infrastructure/builders/NamespaceCreationTransaction.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/NamespaceCreationTransaction - */ -import { Convert as convert } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import * as NamespaceCreationTransactionBufferPackage from '../buffers/NamespaceCreationTransactionBuffer'; -import NamespaceCreationTransactionSchema from '../schemas/NamespaceCreationTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -const { - NamespaceCreationTransactionBuffer, -} = NamespaceCreationTransactionBufferPackage.default.Buffers; - -import {flatbuffers} from 'flatbuffers'; - -export default class NamespaceCreationTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, NamespaceCreationTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - namespaceType: any; - duration: any; - parentId: any; - namespaceId: any; - namespaceName: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.REGISTER_NAMESPACE; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addNamespaceType(namespaceType) { - this.namespaceType = namespaceType; - return this; - } - - addDuration(duration) { - this.duration = duration; - return this; - } - - addParentId(parentId) { - this.parentId = parentId; - return this; - } - - addNamespaceId(namespaceId) { - this.namespaceId = namespaceId; - return this; - } - - addNamespaceName(namespaceName) { - this.namespaceName = namespaceName; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - const namespaceNameLength = convert.utf8ToHex(this.namespaceName).length / 2; - - // create vectors - const signatureVector = NamespaceCreationTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = NamespaceCreationTransactionBuffer - .createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = NamespaceCreationTransactionBuffer - .createDeadlineVector(builder, this.deadline); - const feeVector = NamespaceCreationTransactionBuffer - .createFeeVector(builder, this.maxFee); - const parentIdVector = 1 === this.namespaceType ? this.parentId : this.duration; - const durationParentIdVector = NamespaceCreationTransactionBuffer - .createDurationParentIdVector(builder, parentIdVector); - const namespaceIdVector = NamespaceCreationTransactionBuffer - .createNamespaceIdVector(builder, this.namespaceId); - - const name = builder.createString(this.namespaceName); - - NamespaceCreationTransactionBuffer.startNamespaceCreationTransactionBuffer(builder); - NamespaceCreationTransactionBuffer.addSize(builder, 138 + namespaceNameLength); - NamespaceCreationTransactionBuffer.addSignature(builder, signatureVector); - NamespaceCreationTransactionBuffer.addSigner(builder, signerVector); - NamespaceCreationTransactionBuffer.addVersion(builder, this.version); - NamespaceCreationTransactionBuffer.addType(builder, this.type); - NamespaceCreationTransactionBuffer.addFee(builder, feeVector); - NamespaceCreationTransactionBuffer.addDeadline(builder, deadlineVector); - NamespaceCreationTransactionBuffer.addNamespaceType(builder, this.namespaceType); - NamespaceCreationTransactionBuffer.addDurationParentId(builder, durationParentIdVector); - NamespaceCreationTransactionBuffer.addNamespaceId(builder, namespaceIdVector); - NamespaceCreationTransactionBuffer.addNamespaceNameSize(builder, namespaceNameLength); - NamespaceCreationTransactionBuffer.addNamespaceName(builder, name); - - // Calculate size - const codedNamespace = NamespaceCreationTransactionBuffer.endNamespaceCreationTransactionBuffer(builder); - builder.finish(codedNamespace); - - const bytes = builder.asUint8Array(); - return new NamespaceCreationTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/SecretLockTransaction.ts b/src/infrastructure/builders/SecretLockTransaction.ts deleted file mode 100644 index 5e66e40c9b..0000000000 --- a/src/infrastructure/builders/SecretLockTransaction.ts +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/SecretLockTransaction - */ -import { Convert as convert, RawAddress as address } from '../../core/format'; -import * as SecretLockTransactionBufferPackage from '../../infrastructure/buffers/SecretLockTransactionBuffer'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; -import SecretLockTransactionSchema from '../../infrastructure/schemas/SecretLockTransactionSchema'; -import { TransactionType } from '../../model/transaction/TransactionType'; - -import {flatbuffers} from 'flatbuffers'; - -const { - SecretLockTransactionBuffer, -} = SecretLockTransactionBufferPackage.default.Buffers; - -export default class SecretLockTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, SecretLockTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - mosaicId: any; - mosaicAmount: any; - duration: any; - hashAlgorithm: any; - secret: any; - recipient: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.SECRET_LOCK; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addMosaicId(mosaicId) { - this.mosaicId = mosaicId; - return this; - } - - addMosaicAmount(mosaicAmount) { - this.mosaicAmount = mosaicAmount; - return this; - } - - addDuration(duration) { - this.duration = duration; - return this; - } - - addHashAlgorithm(hashAlgorithm) { - this.hashAlgorithm = hashAlgorithm; - return this; - } - - addSecret(secret) { - this.secret = secret; - return this; - } - - addRecipient(recipient) { - this.recipient = address.stringToAddress(recipient); - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = SecretLockTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = SecretLockTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = SecretLockTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = SecretLockTransactionBuffer.createFeeVector(builder, this.maxFee); - const mosaicIdVector = SecretLockTransactionBuffer.createMosaicIdVector(builder, this.mosaicId); - const mosaicAmountVector = SecretLockTransactionBuffer.createMosaicAmountVector(builder, this.mosaicAmount); - const durationVector = SecretLockTransactionBuffer.createDurationVector(builder, this.duration); - const byteSecret = convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); - const secretVector = SecretLockTransactionBuffer.createSecretVector(builder, byteSecret); - const recipientVector = SecretLockTransactionBuffer.createRecipientVector(builder, this.recipient); - - SecretLockTransactionBuffer.startSecretLockTransactionBuffer(builder); - SecretLockTransactionBuffer.addSize(builder, 202); - SecretLockTransactionBuffer.addSignature(builder, signatureVector); - SecretLockTransactionBuffer.addSigner(builder, signerVector); - SecretLockTransactionBuffer.addVersion(builder, this.version); - SecretLockTransactionBuffer.addType(builder, this.type); - SecretLockTransactionBuffer.addFee(builder, feeVector); - SecretLockTransactionBuffer.addDeadline(builder, deadlineVector); - SecretLockTransactionBuffer.addMosaicId(builder, mosaicIdVector); - SecretLockTransactionBuffer.addMosaicAmount(builder, mosaicAmountVector); - SecretLockTransactionBuffer.addDuration(builder, durationVector); - SecretLockTransactionBuffer.addHashAlgorithm(builder, this.hashAlgorithm); - SecretLockTransactionBuffer.addSecret(builder, secretVector); - SecretLockTransactionBuffer.addRecipient(builder, recipientVector); - - const codedSecretLock = SecretLockTransactionBuffer.endSecretLockTransactionBuffer(builder); - builder.finish(codedSecretLock); - - const bytes = builder.asUint8Array(); - return new SecretLockTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/SecretProofTransaction.ts b/src/infrastructure/builders/SecretProofTransaction.ts deleted file mode 100644 index 619e037173..0000000000 --- a/src/infrastructure/builders/SecretProofTransaction.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/SecretProofTransaction - */ -import { Convert as convert, RawAddress as address } from '../../core/format'; -import { TransactionType } from '../../model/transaction/TransactionType'; -import * as SecretProofTransactionBufferPackage from '../buffers/SecretProofTransactionBuffer'; -import SecretProofTransactionSchema from '../schemas/SecretProofTransactionSchema'; -import { VerifiableTransaction } from './VerifiableTransaction'; - -import {flatbuffers} from 'flatbuffers'; - -const { - SecretProofTransactionBuffer, -} = SecretProofTransactionBufferPackage.default.Buffers; - -export default class SecretProofTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, SecretProofTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - hashAlgorithm: any; - secret: any; - recipient: any; - proof: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.SECRET_PROOF; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addHashAlgorithm(hashAlgorithm) { - this.hashAlgorithm = hashAlgorithm; - return this; - } - - addSecret(secret) { - this.secret = secret; - return this; - } - addRecipient(recipient) { - this.recipient = address.stringToAddress(recipient); - return this; - } - - addProof(proof) { - this.proof = proof; - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - - // Create vectors - const signatureVector = SecretProofTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = SecretProofTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = SecretProofTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = SecretProofTransactionBuffer.createFeeVector(builder, this.maxFee); - const byteSecret = convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); - const secretVector = SecretProofTransactionBuffer.createSecretVector(builder, byteSecret); - const recipientVector = SecretProofTransactionBuffer.createRecipientVector(builder, this.recipient); - const byteProof = convert.hexToUint8(this.proof); - const proofVector = SecretProofTransactionBuffer.createProofVector(builder, byteProof); - - SecretProofTransactionBuffer.startSecretProofTransactionBuffer(builder); - SecretProofTransactionBuffer.addSize(builder, 180 + byteProof.length); - SecretProofTransactionBuffer.addSignature(builder, signatureVector); - SecretProofTransactionBuffer.addSigner(builder, signerVector); - SecretProofTransactionBuffer.addVersion(builder, this.version); - SecretProofTransactionBuffer.addType(builder, this.type); - SecretProofTransactionBuffer.addFee(builder, feeVector); - SecretProofTransactionBuffer.addDeadline(builder, deadlineVector); - SecretProofTransactionBuffer.addHashAlgorithm(builder, this.hashAlgorithm); - SecretProofTransactionBuffer.addSecret(builder, secretVector); - SecretProofTransactionBuffer.addRecipient(builder, recipientVector); - SecretProofTransactionBuffer.addProofSize(builder, byteProof.length); - SecretProofTransactionBuffer.addProof(builder, proofVector); - - const codedSecretProof = SecretProofTransactionBuffer.endSecretProofTransactionBuffer(builder); - builder.finish(codedSecretProof); - - const bytes = builder.asUint8Array(); - return new SecretProofTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/TransferTransaction.ts b/src/infrastructure/builders/TransferTransaction.ts deleted file mode 100644 index 0153d44a91..0000000000 --- a/src/infrastructure/builders/TransferTransaction.ts +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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. - */ - -/** - * @module transactions/TransferTransaction - */ -import { Convert as convert, RawAddress as address} from '../../core/format'; -import * as TransferTransactionBufferPackage from '../../infrastructure/buffers/TransferTransactionBuffer'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; -import TransferTransactionSchema from '../../infrastructure/schemas/TransferTransactionSchema'; -import { TransactionType } from '../../model/transaction/TransactionType'; - -import {flatbuffers} from 'flatbuffers'; - -const { - TransferTransactionBuffer, - MessageBuffer, - MosaicBuffer, -} = TransferTransactionBufferPackage.default.Buffers; - -export default class TransferTransaction extends VerifiableTransaction { - constructor(bytes) { - super(bytes, TransferTransactionSchema); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Builder { - maxFee: any; - version: any; - type: any; - deadline: any; - recipient: any; - message: any; - mosaics: any; - constructor() { - this.maxFee = [0, 0]; - this.type = TransactionType.TRANSFER; - } - - addFee(maxFee) { - this.maxFee = maxFee; - return this; - } - - addVersion(version) { - this.version = version; - return this; - } - - addType(type) { - this.type = type; - return this; - } - - addDeadline(deadline) { - this.deadline = deadline; - return this; - } - - addRecipient(recipient) { - if (/^[0-9a-fA-F]{16}$/.test(recipient)) { - // received hexadecimal notation of namespaceId (alias) - this.recipient = address.aliasToRecipient(convert.hexToUint8(recipient)); - } else { - // received recipient address - this.recipient = address.stringToAddress(recipient); - } - return this; - } - - addMessage(message) { - this.message = message; - return this; - } - - addMosaics(mosaics) { - this.mosaics = mosaics.sort((a, b) => { - if (Number(a.id[1]) > b.id[1]) { return 1; } else if (a.id[1] < b.id[1]) { return -1; } - return 0; - }); - return this; - } - - build() { - const builder = new flatbuffers.Builder(1); - // Constants - - // Create message - const bytePayload = convert.hexToUint8(convert.utf8ToHex(this.message.payload)); - const payload = MessageBuffer.createPayloadVector(builder, bytePayload); - MessageBuffer.startMessageBuffer(builder); - MessageBuffer.addType(builder, this.message.type); - MessageBuffer.addPayload(builder, payload); - const message = MessageBuffer.endMessageBuffer(builder); - - // Create mosaics - const mosaics: any = []; - this.mosaics.forEach(mosaic => { - const id = MosaicBuffer.createIdVector(builder, mosaic.id); - const amount = MosaicBuffer.createAmountVector(builder, mosaic.amount); - MosaicBuffer.startMosaicBuffer(builder); - MosaicBuffer.addId(builder, id); - MosaicBuffer.addAmount(builder, amount); - mosaics.push(MosaicBuffer.endMosaicBuffer(builder)); - }); - - // Create vectors - const signatureVector = TransferTransactionBuffer - .createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); - const signerVector = TransferTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); - const deadlineVector = TransferTransactionBuffer.createDeadlineVector(builder, this.deadline); - const feeVector = TransferTransactionBuffer.createFeeVector(builder, this.maxFee); - const recipientVector = TransferTransactionBuffer.createRecipientVector(builder, this.recipient); - const mosaicsVector = TransferTransactionBuffer.createMosaicsVector(builder, mosaics); - - TransferTransactionBuffer.startTransferTransactionBuffer(builder); - TransferTransactionBuffer.addSize(builder, 149 + (16 * this.mosaics.length) + bytePayload.length); - TransferTransactionBuffer.addSignature(builder, signatureVector); - TransferTransactionBuffer.addSigner(builder, signerVector); - TransferTransactionBuffer.addVersion(builder, this.version); - TransferTransactionBuffer.addType(builder, this.type); - TransferTransactionBuffer.addFee(builder, feeVector); - TransferTransactionBuffer.addDeadline(builder, deadlineVector); - TransferTransactionBuffer.addRecipient(builder, recipientVector); - TransferTransactionBuffer.addNumMosaics(builder, this.mosaics.length); - TransferTransactionBuffer.addMessageSize(builder, bytePayload.length + 1); - TransferTransactionBuffer.addMessage(builder, message); - TransferTransactionBuffer.addMosaics(builder, mosaicsVector); - - // Calculate size - - const codedTransfer = TransferTransactionBuffer.endTransferTransactionBuffer(builder); - builder.finish(codedTransfer); - - const bytes = builder.asUint8Array(); - return new TransferTransaction(bytes); - } -} diff --git a/src/infrastructure/builders/VerifiableTransaction.ts b/src/infrastructure/builders/VerifiableTransaction.ts deleted file mode 100644 index d83b079d59..0000000000 --- a/src/infrastructure/builders/VerifiableTransaction.ts +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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 { KeyPair, SignSchema } from '../../core/crypto'; -import { SHA3Hasher as sha3Hasher } from '../../core/crypto/SHA3Hasher'; -import { Convert as convert } from '../../core/format'; - -/** - * VerifiableTransaction - * @module transactions/VerifiableTransaction - * @version 1.0.0 - */ -export class VerifiableTransaction { - bytes: any; - schema: any; - /** - * @constructor - * @param {Uint8Array} bytes Uint8Array after flatbuffers.build.asUint8Array() - * @param {module:schema/Schema} schema Schema definition corresponding to flatbuffer Schema - */ - constructor(bytes, schema) { - this.bytes = bytes; - this.schema = schema; - } - - /** - * @param {string} transactionPayload HexString Payload - * @param {string} generationHash Network generation hash byte - * @returns {*|string} Returns Transaction Payload hash - */ - static createTransactionHash(transactionPayload, generationHash) { - const byteBuffer = Array.from(convert.hexToUint8(transactionPayload)); - const signingBytes = byteBuffer - .slice(4, 36) - .concat(byteBuffer - .slice(4 + 64, 4 + 64 + 32)) - .concat(generationHash) - .concat(byteBuffer - .splice(4 + 64 + 32, byteBuffer.length)); - - const hash = new Uint8Array(32); - - sha3Hasher.func(hash, signingBytes, 32); - - return convert.uint8ToHex(hash); - } - - /** - * @param {KeyPair } keyPair KeyPair instance - * @param {string} generationHash Network generation hash hex - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {module:model/TransactionPayload} - Signed Transaction Payload - */ - signTransaction(keyPair, generationHash, signSchema: SignSchema = SignSchema.SHA3) { - const generationHashBytes = Array.from(convert.hexToUint8(generationHash)); - const byteBuffer = this.serialize(); - const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); - const keyPairEncoded = KeyPair.createKeyPairFromPrivateKeyString(keyPair.privateKey, signSchema); - const signature = Array.from(KeyPair.sign(keyPair, new Uint8Array(signingBytes), signSchema)); - const signedTransactionBuffer = byteBuffer - .splice(0, 4) - .concat(signature) - .concat(Array.from(keyPairEncoded.publicKey)) - .concat(byteBuffer - .splice(64 + 32, byteBuffer.length)); - const payload = convert.uint8ToHex(signedTransactionBuffer); - return { - payload, - hash: VerifiableTransaction.createTransactionHash(payload, generationHashBytes), - }; - } - - serialize() { - return this.schema.serialize(Array.from(this.bytes)); - } - - /** - * @returns {string} - Serialized Transaction Payload - */ - serializeUnsignedTransaction() { - return convert.uint8ToHex(this.serialize()); - } - - /** - * @param {KeyPair} keyPair KeyPair instance - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {module:model/TransactionPayload} Returns TransactionPayload instance - */ - signCosignatoriesTransaction(keyPair, signSchema: SignSchema = SignSchema.SHA3) { - const signature = KeyPair.sign(keyPair, new Uint8Array(this.bytes), signSchema); - return { - parentHash: convert.uint8ToHex(this.bytes), - signature: convert.uint8ToHex(signature), - signer: keyPair.publicKey, - }; - } - - /** - * Converts the transaction into AggregateTransaction compatible - * @param {string} [_signer] Signer public key - * @returns {Array.<*>} AggregateTransaction bytes - */ - toAggregateTransaction(_signer) { - const signer = convert.hexToUint8(_signer); - let resultBytes = this.schema.serialize(Array.from(this.bytes)); - resultBytes.splice(0, 4 + 64 + 32); - resultBytes = Array.from(signer).concat(resultBytes); - resultBytes.splice(32 + 2 + 2, 16); - return Array.from((new Uint8Array([ - (resultBytes.length + 4 & 0x000000ff), - (resultBytes.length + 4 & 0x0000ff00) >> 8, - (resultBytes.length + 4 & 0x00ff0000) >> 16, - (resultBytes.length + 4 & 0xff000000) >> 24, - ]))).concat(resultBytes); - } -} diff --git a/src/infrastructure/builders/VerificableTransactionBuilder.ts b/src/infrastructure/builders/VerificableTransactionBuilder.ts deleted file mode 100644 index a63c9cb9ab..0000000000 --- a/src/infrastructure/builders/VerificableTransactionBuilder.ts +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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'; - -const { - flatbuffers -} = require('flatbuffers'); - -/** - * @module transactions/VerifiableTransactionBuilder - */ - -/** - * @callback LambdaBuilder - * @param {flatbuffers.Builder} builder - * @return {void} - */ - -export default class VerifiableTransactionBuilder { - bytes: any; - schema: any - /** - * @param {LambdaBuilder} lambda Callback - * @returns {VerifiableTransactionBuilder} Returns self instance - */ - addTransaction(lambda) { - const builder = new flatbuffers.Builder(1); - - lambda(builder); - - this.bytes = builder.asUint8Array(); - return this; - } - - /** - * @param {module:schema/Schema} schema Schema corresponding with flatbuffers Schema used on addTransaction - * @returns {VerifiableTransactionBuilder} Returns self instance - */ - addSchema(schema) { - this.schema = schema; - return this; - } - - /** - * @returns {VerifiableTransaction} Returns VerifiableTransaction instance - */ - build() { - return new VerifiableTransaction(this.bytes, this.schema); - } -} diff --git a/src/infrastructure/schemas/AccountLinkTransactionSchema.ts b/src/infrastructure/schemas/AccountLinkTransactionSchema.ts deleted file mode 100644 index 5a0e3be1ba..0000000000 --- a/src/infrastructure/schemas/AccountLinkTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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/AccountLinkTransaction - */ - -/** - * Account Link schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('remoteAccountKey'), - ubyte('linkAction') -]); -export default schema; diff --git a/src/infrastructure/schemas/AccountRestrictionsAddressModificationTransactionSchema.ts b/src/infrastructure/schemas/AccountRestrictionsAddressModificationTransactionSchema.ts deleted file mode 100644 index f08fd0cda3..0000000000 --- a/src/infrastructure/schemas/AccountRestrictionsAddressModificationTransactionSchema.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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, - ushort, - tableArray, - uint -} from './Schema'; - -/** - * @module schema/AccountRestrictionsAddressModificationTransactionSchema - */ - -/** - * Account restriction address 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('restrictionType'), - ubyte('modificationCount'), - tableArray('modifications', [ - ubyte('modificationType'), - array('value', TypeSize.BYTE) - ]) -]); diff --git a/src/infrastructure/schemas/AccountRestrictionsEntityTypeModificationTransactionSchema.ts b/src/infrastructure/schemas/AccountRestrictionsEntityTypeModificationTransactionSchema.ts deleted file mode 100644 index 6d9090a5c0..0000000000 --- a/src/infrastructure/schemas/AccountRestrictionsEntityTypeModificationTransactionSchema.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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, - ushort, - tableArray, - uint -} from './Schema'; - -/** - * @module schema/AccountRestrictionsEntityTypeModificationTransactionSchema - */ - -/** - * Account restrictions address 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('restrictionType'), - ubyte('modificationCount'), - tableArray('modifications', [ - ubyte('modificationType'), - ushort('value') - ]) -]); diff --git a/src/infrastructure/schemas/AccountRestrictionsMosaicModificationTransactionSchema.ts b/src/infrastructure/schemas/AccountRestrictionsMosaicModificationTransactionSchema.ts deleted file mode 100644 index 557c38898e..0000000000 --- a/src/infrastructure/schemas/AccountRestrictionsMosaicModificationTransactionSchema.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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, - ushort, - tableArray, - uint -} from './Schema'; - -/** - * @module schema/AccountRestrictionsMosaicModificationTransactionSchema - */ - -/** - * Account restrictions address 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('restrictionType'), - ubyte('modificationCount'), - tableArray('modifications', [ - ubyte('modificationType'), - array('value', TypeSize.INT) - ]) -]); diff --git a/src/infrastructure/schemas/AddressAliasTransactionSchema.ts b/src/infrastructure/schemas/AddressAliasTransactionSchema.ts deleted file mode 100644 index ef01e3eadd..0000000000 --- a/src/infrastructure/schemas/AddressAliasTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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('aliasAction'), - array('namespaceId', TypeSize.INT), - array('address', TypeSize.BYTE) -]); diff --git a/src/infrastructure/schemas/AggregateTransactionSchema.ts b/src/infrastructure/schemas/AggregateTransactionSchema.ts deleted file mode 100644 index f27bc0e142..0000000000 --- a/src/infrastructure/schemas/AggregateTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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, - uint, - ushort -} from './Schema'; - -/** - * @module schema/AggregateTransactionSchema - */ - -/** - * Aggregate transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - uint('transactionsSize'), - array('transactions') -]); - -export default schema; diff --git a/src/infrastructure/schemas/HashLockTransactionSchema.ts b/src/infrastructure/schemas/HashLockTransactionSchema.ts deleted file mode 100644 index 2efbf4ffaa..0000000000 --- a/src/infrastructure/schemas/HashLockTransactionSchema.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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, - uint, - ushort -} from './Schema'; - -/** - * @module schema/HashLockTransactionSchema - */ - -/** - * Hash lock transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('mosaicId', TypeSize.INT), - array('mosaicAmount', TypeSize.INT), - array('duration', TypeSize.INT), - array('hash') -]); -export default schema; diff --git a/src/infrastructure/schemas/MosaicAddressRestrictionTransactionSchema.ts b/src/infrastructure/schemas/MosaicAddressRestrictionTransactionSchema.ts deleted file mode 100644 index 18123110e1..0000000000 --- a/src/infrastructure/schemas/MosaicAddressRestrictionTransactionSchema.ts +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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/MosaicAddressRestrictionTransactionSchema - */ - -/** - * Account Link 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), - array('mosaicId', TypeSize.INT), - array('restrictionKey', TypeSize.INT), - array('targetAddress', TypeSize.BYTE), - array('previousRestrictionValue', TypeSize.INT), - array('newRestrictionValue', TypeSize.INT), -]); diff --git a/src/infrastructure/schemas/MosaicAliasTransactionSchema.ts b/src/infrastructure/schemas/MosaicAliasTransactionSchema.ts deleted file mode 100644 index 37b827b192..0000000000 --- a/src/infrastructure/schemas/MosaicAliasTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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('aliasAction'), - array('namespaceId', TypeSize.INT), - array('mosaicId', TypeSize.INT) -]); diff --git a/src/infrastructure/schemas/MosaicCreationTransactionSchema.ts b/src/infrastructure/schemas/MosaicCreationTransactionSchema.ts deleted file mode 100644 index e9d947652a..0000000000 --- a/src/infrastructure/schemas/MosaicCreationTransactionSchema.ts +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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/MosaicCreationTransactionSchema - */ - -/** - * Mosaic definition creation transaction schema - * @const {module:schema/Schema} - */ -export const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('nonce', TypeSize.BYTE), - array('mosaicId', TypeSize.INT), - ubyte('numOptionalProperties'), - ubyte('flags'), - ubyte('divisibility'), - ubyte('indicateDuration'), - array('duration', TypeSize.INT) -]); - -export const schemaNoDuration = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('nonce', TypeSize.BYTE), - array('mosaicId', TypeSize.INT), - ubyte('numOptionalProperties'), - ubyte('flags'), - ubyte('divisibility') -]); diff --git a/src/infrastructure/schemas/MosaicGlobalRestrictionTransactionSchema.ts b/src/infrastructure/schemas/MosaicGlobalRestrictionTransactionSchema.ts deleted file mode 100644 index d5be82b1ec..0000000000 --- a/src/infrastructure/schemas/MosaicGlobalRestrictionTransactionSchema.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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/MosaicGlobalRestrictionTransactionSchema - */ - -/** - * Account Link 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), - array('mosaicId', TypeSize.INT), - array('referenceMosaicId', TypeSize.INT), - array('restrictionKey', TypeSize.INT), - array('previousRestrictionValue', TypeSize.INT), - ubyte('previousRestrictionType'), - array('newRestrictionValue', TypeSize.INT), - ubyte('newRestrictionType'), - -]); diff --git a/src/infrastructure/schemas/MosaicSupplyChangeTransactionSchema.ts b/src/infrastructure/schemas/MosaicSupplyChangeTransactionSchema.ts deleted file mode 100644 index 19df7503b8..0000000000 --- a/src/infrastructure/schemas/MosaicSupplyChangeTransactionSchema.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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/MosaicSupplyChangeTransactionSchema - */ - -/** - * Mosaic supply change 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), - array('mosaicId', TypeSize.INT), - ubyte('direction'), - array('delta', TypeSize.INT) -]); diff --git a/src/infrastructure/schemas/MultisigModificationTransactionSchema.ts b/src/infrastructure/schemas/MultisigModificationTransactionSchema.ts deleted file mode 100644 index 91beb8efc6..0000000000 --- a/src/infrastructure/schemas/MultisigModificationTransactionSchema.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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, - tableArray, - TypeSize, - ubyte, - uint, - ushort -} from './Schema'; - -/** - * @module schema/MultigAggregateModificationTransactionSchema - */ - -/** - * Multisig aggregate modification 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('minRemovalDelta'), - ubyte('minApprovalDelta'), - ubyte('numModifications'), - tableArray('modifications', [ - ubyte('type'), - array('cosignatoryPublicKey') - ]) -]); diff --git a/src/infrastructure/schemas/NamespaceCreationTransactionSchema.ts b/src/infrastructure/schemas/NamespaceCreationTransactionSchema.ts deleted file mode 100644 index 7694dddc5e..0000000000 --- a/src/infrastructure/schemas/NamespaceCreationTransactionSchema.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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, - string, - TypeSize, - ubyte, - uint, - ushort -} from './Schema'; - -/** - * @module schema/NamespaceCreationTransactionSchema - */ - -/** - * Provision namespace 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('namespaceType'), - array('durationParentId', TypeSize.INT), - array('namespaceId', TypeSize.INT), - ubyte('namespaceNameSize'), - string('name') -]); diff --git a/src/infrastructure/schemas/Schema.ts b/src/infrastructure/schemas/Schema.ts deleted file mode 100644 index 212378e39e..0000000000 --- a/src/infrastructure/schemas/Schema.ts +++ /dev/null @@ -1,374 +0,0 @@ -/* - * 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. - */ - -/* eslint-disable no-use-before-define */ - -/** - * In bytes - * @type {{BYTE: number, SHORT: number, INT: number}} - */ -export const TypeSize = { - BYTE: 1, - SHORT: 2, - INT: 4, -}; - -/** - * @param {string} name Attribute name - * @returns {ScalarAttribute} return ScalarAttribute Instance - */ -export const ubyte = (name) => { - return new ScalarAttribute(name, TypeSize.BYTE); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const byte = (name) => { - return new ScalarAttribute(name, TypeSize.BYTE); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const ushort = (name) => { - return new ScalarAttribute(name, TypeSize.SHORT); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const short = (name) => { - return new ScalarAttribute(name, TypeSize.SHORT); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const uint = (name) => { - return new ScalarAttribute(name, TypeSize.INT); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ScalarAttribute} ScalarAttribute Instance - */ -export const int = (name) => { - return new ScalarAttribute(name, TypeSize.INT); -}; - -/** - * - * @param {string} name Attribute Name - * @param {number} typeSize Attribute Byte Size - * @returns {ArrayAttribute} ArrayAttribute Instance - */ -export const array = (name, typeSize = TypeSize.BYTE) => { - return new ArrayAttribute(name, typeSize); -}; - -/** - * - * @param {string} name Attribute Name - * @returns {ArrayAttribute} ArrayAttribute Instance - */ -export const string = (name) => { - return array(name); -}; - -/** - * - * @param {string} name Attribute Name - * @param {module:schema/Schema} schema Table Specific Schema definition - * @returns {TableAttribute} TableAttribute Instance - */ -export const table = (name, schema) => { - return new TableAttribute(name, schema); -}; - -/** - * - * @param {string} name Attribute Name - * @param {module:schema/Schema} schema Schema Definition - * @returns {TableArrayAttribute} TableAttribute Instance - */ -export const tableArray = (name, schema) => { - return new TableArrayAttribute(name, schema); -}; - -/* eslint-disable */ -const readInt32 = (offset, bytes) => { - return bytes[offset] | bytes[offset + 1] << 8 | bytes[offset + 2] << 16 | bytes[offset + 3] << 24; -}; - -const readInt16 = (offset, bytes) => { - return bytes[offset] | bytes[offset + 1] << 8; -}; - -const __offset = (val0, fieldPos, bytes) => { - const vtable = val0 - readInt32(val0, bytes); - return fieldPos < readInt16(vtable, bytes) ? readInt16(vtable + fieldPos, bytes) : 0; -}; - -const __vector_length = (offset, bytes) => { - return readInt32(offset + readInt32(offset, bytes), bytes); -}; - -const __indirect = (offset, bytes) => { - return offset + readInt32(offset, bytes); -}; - -const __vector = (offset, bytes) => { - return offset + readInt32(offset, bytes) + 4; -}; - -const findVector = (val0, fieldPos, bytes, size) => { - const offset = __offset(val0, fieldPos, bytes); - const offsetLong = offset + val0; - const vecStart = __vector(offsetLong, bytes); - const vecLength = __vector_length(offsetLong, bytes) * (size ? size : 1); - return offset ? bytes.slice(vecStart, vecStart + vecLength) : 0; -}; - -const findParam = (val0, fieldPos, bytes, numBytes) => { - const offset = __offset(val0, fieldPos, bytes); - return offset ? bytes.slice(offset + val0, offset + val0 + numBytes) : 0; -}; - -const findObjectStartPosition = (val0, fieldPos, bytes) => { - const offset = __offset(val0, fieldPos, bytes); - return __indirect(offset + val0, bytes); -}; - -const findArrayLength = (val0, fieldPos, bytes) => { - const offset = __offset(val0, fieldPos, bytes); - return offset ? __vector_length(val0 + offset, bytes) : 0; -}; - -const findObjectArrayElementStartPosition = (val0, fieldPos, bytes, index) => { - const offset = __offset(val0, fieldPos, bytes); - const vector = __vector(val0 + offset, bytes); - return __indirect(vector + index * 4, bytes); -}; - -/** - * Schema - * @module schema/Schema - */ -export class Schema { - schemaDefinition; - /** - * @constructor - * @param {Array.} schemaDefinition Schema Definition - */ - constructor(schemaDefinition) { - this.schemaDefinition = schemaDefinition; - } - - /** - * - * @param {Uint8Array} bytes flatbuffers bytes - * @returns {Uint8Array} catapult buffer - */ - serialize(bytes) { - let i = 0; - let resultBytes = []; - while (i < this.schemaDefinition.length) { - resultBytes = resultBytes.concat(this.schemaDefinition[i].serialize(bytes, 4 + (i * 2))); - i++; - } - return resultBytes; - } - - /** - * @param {Uint8Array} bytes flatbuffer bytes - * @returns {Array} Array with field name + payload - */ - debugSerialize(bytes) { - let i = 0; - let result: any = []; - while (i < this.schemaDefinition.length) { - result = result.concat({ - name: this.schemaDefinition[i].name, - bytes: this.schemaDefinition[i].debugSerialize(bytes, 4 + i * 2), - }); - i++; - } - return result; - } -} - -// tslint:disable-next-line:max-classes-per-file -export class Attribute { - name: any; - /** - * @constructor - * @param {string} name schema attribute name - */ - constructor(name) { - this.name = name; - } - - /** - * - * @param {Uint8Array} buffer flatbuffer bytes - * @param {number} position attribute possition in flatbuffer bytes - * @param {number} val0 position in case that it is an inner object - */ - serialize(buffer, position, val0 = undefined) { - throw new Error('Unimplemented method'); - } - - /** - * @suppress warnings - * @param {Uint8Array} buffer buffer flatbuffer bytes - * @param {number} position attribute possition in flatbuffer bytes - * @param {number} val0 position in case that it is an inner object - */ - debugSerialize(buffer, position, val0 = undefined) { - throw new Error('Unimplemented method'); - } -} - -// tslint:disable-next-line:max-classes-per-file -export class ScalarAttribute extends Attribute { - typeSize: any; - name: any; - /** - * @constructor - * @param {string} name schema attribute name - * @param {number} typeSize - */ - constructor(name, typeSize) { - super(name); - this.typeSize = typeSize; - } - - serialize(buffer, position, val0 = undefined) { - return findParam(val0 ? val0 : buffer[0], position, buffer, this.typeSize); - } - - debugSerialize(buffer, position, val0 = undefined) { - return { - name: this.name, - bytes: this.serialize(buffer, position, val0), - }; - } -} - -// tslint:disable-next-line:max-classes-per-file -export class ArrayAttribute extends Attribute { - typeSize: any; - name: any; - /** - * @constructor - * @param name - {string} - * @param typeSize - {TypeSize} - */ - constructor(name, typeSize) { - super(name); - this.typeSize = typeSize; - } - - serialize(buffer, position, val0 = undefined) { - return findVector(val0 ? val0 : buffer[0], position, buffer, this.typeSize); - } - - debugSerialize(buffer, position, val0 = undefined) { - return { - name: this.name, - bytes: this.serialize(buffer, position, val0), - }; - } -} - -// tslint:disable-next-line:max-classes-per-file -export class TableAttribute extends Attribute { - schema: any; - name: any; - /** - * - * @param {string} name - * @param {module:schema/Schema} schema - */ - constructor(name, schema) { - super(name); - this.schema = schema; - } - - serialize(bytes, position, val0 = undefined) { - let result = []; - const messageStartPosition = findObjectStartPosition(val0 ? val0 : bytes[0], position, bytes); - let i = 0; - while (i < this.schema.length) { - result = result.concat(this.schema[i].serialize(bytes, 4 + i * 2, messageStartPosition)); - i++; - } - return result; - } - - debugSerialize(buffer, position, val0 = undefined) { - return { - name: this.name, - bytes: this.serialize(buffer, position, val0), - }; - } -} - -// tslint:disable-next-line:max-classes-per-file -export class TableArrayAttribute extends Attribute { - schema: any; - name: any; - /** - * @constructor - * @param {string} name - * @param {module:schema/Schema} schema - */ - constructor(name, schema) { - super(name); - this.schema = schema; - } - - serialize(bytes, position, val0 = undefined) { - let result = []; - const arrayLength = findArrayLength(val0 ? val0 : bytes[0], position, bytes); - let i = 0; - while (i < arrayLength) { - const startArrayPosition = findObjectArrayElementStartPosition(val0 ? val0 : bytes[0], position, bytes, i); - for (let j = 0; j < this.schema.length; ++j) { - result = result.concat(this.schema[j].serialize(bytes, 4 + j * 2, startArrayPosition)); - } - i++; - } - return result; - } - - debugSerialize(buffer, position, val0 = undefined) { - return { - name: this.name, - bytes: this.serialize(buffer, position, val0), - }; - } -} diff --git a/src/infrastructure/schemas/SecretLockTransactionSchema.ts b/src/infrastructure/schemas/SecretLockTransactionSchema.ts deleted file mode 100644 index 046f02c178..0000000000 --- a/src/infrastructure/schemas/SecretLockTransactionSchema.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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/SecretLockTransactionSchema - */ - -/** - * Secret lock transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('mosaicId', TypeSize.INT), - array('mosaicAmount', TypeSize.INT), - array('duration', TypeSize.INT), - ubyte('hashAlgorithm'), - array('secret'), - array('recipient') -]); -export default schema; diff --git a/src/infrastructure/schemas/SecretProofTransactionSchema.ts b/src/infrastructure/schemas/SecretProofTransactionSchema.ts deleted file mode 100644 index db03f6eaf4..0000000000 --- a/src/infrastructure/schemas/SecretProofTransactionSchema.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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/SecretProofTransactionSchema - */ - -/** - * Secret proof transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - ubyte('hashAlgorithm'), - array('secret'), - array('recipient'), - ushort('proofSize'), - array('proof') -]); -export default schema; diff --git a/src/infrastructure/schemas/TransferTransactionSchema.ts b/src/infrastructure/schemas/TransferTransactionSchema.ts deleted file mode 100644 index eb8efdfd4e..0000000000 --- a/src/infrastructure/schemas/TransferTransactionSchema.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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, - table, - tableArray, - TypeSize, - ubyte, - uint, - ushort -} from './Schema'; - -/** - * @module schema/TransferTransactionSchema - */ - -/** - * Transfer transaction schema - * @const {module:schema/Schema} - */ -const schema = new Schema([ - uint('size'), - array('signature'), - array('signer'), - ushort('version'), - ushort('type'), - array('fee', TypeSize.INT), - array('deadline', TypeSize.INT), - array('recipient'), - ushort('messageSize'), - ubyte('numMosaics'), - table('message', [ - ubyte('type'), - array('payload') - ]), - tableArray('mosaics', [ - array('id', TypeSize.INT), - array('amount', TypeSize.INT) - ]) -]); -export default schema; diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index b1198243fd..6491749d4c 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -190,27 +190,21 @@ const CreateTransaction = (type: number, transactionData: string, networkType: N case TransactionType.MOSAIC_DEFINITION: const mosaicDefMosaicNonceLength = 8; const mosaicDefMosaicIdLength = 16; - const mosaicDefPropsNumLength = 2; const mosaicDefPropsFlagsLength = 2; const mosaicDefDivisibilityLength = 2; - const mosaicDefDurationIndLength = 2; const mosaicDefDurationLength = 16; const mosaicIdOffset = mosaicDefMosaicNonceLength; - const propsOffset = mosaicIdOffset + mosaicDefMosaicIdLength; - const flagsOffset = propsOffset + mosaicDefPropsNumLength; + const flagsOffset = mosaicIdOffset + mosaicDefMosaicIdLength; const divisibilityOffset = flagsOffset + mosaicDefPropsFlagsLength; - const durationIndOffset = divisibilityOffset + mosaicDefDivisibilityLength; - const durationOffset = durationIndOffset + mosaicDefDurationIndLength; + const durationOffset = divisibilityOffset + mosaicDefDivisibilityLength; // read bytes const mosaicNonce = transactionData.substring(0, mosaicDefMosaicNonceLength); - const mosaicId = transactionData.substring(mosaicIdOffset, propsOffset); - const props = transactionData.substring(propsOffset, flagsOffset); + const mosaicId = transactionData.substring(mosaicIdOffset, flagsOffset); const flags = parseInt(convert.uint8ToHex(convert.hexToUint8( transactionData.substring(flagsOffset, divisibilityOffset)).reverse()), 16); - const divisibility = transactionData.substring(divisibilityOffset, durationIndOffset); - const durationInd = transactionData.substring(durationIndOffset, durationOffset); + const divisibility = transactionData.substring(divisibilityOffset, durationOffset); const duration = transactionData.substring(durationOffset); const regexArray = mosaicNonce.match(/.{1,2}/g); diff --git a/src/model/namespace/AliasAction.ts b/src/model/namespace/AliasAction.ts index ae709efd97..27669a1d91 100644 --- a/src/model/namespace/AliasAction.ts +++ b/src/model/namespace/AliasAction.ts @@ -19,7 +19,7 @@ * 0: Link an alias. * 1: Unlink an alias. */ -export enum AliasAction { - Link = 0, - Unlink = 1, +export enum AliasActionType { + Link = 1, + Unlink = 0, } diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index b70120db8a..d5e0f4d8a9 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -15,13 +15,10 @@ */ import { Convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; @@ -106,20 +103,6 @@ export class AccountAddressRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRestrictionType(this.restrictionType) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index bd0a0303db..58584444b2 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountLinkTransaction'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/AccountLinkTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder'; @@ -105,20 +103,6 @@ export class AccountLinkTransaction extends Transaction { return byteSize + bytePublicKey + byteLinkAction; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRemoteAccountKey(this.remoteAccountKey) - .addLinkAction(this.linkAction) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index 97b35651b4..3a5b19946c 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -15,9 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; -import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -105,20 +102,6 @@ export class AccountMosaicRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRestrictionType(this.restrictionType) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index 5ecda29c0b..df82913d22 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -104,20 +102,6 @@ export class AccountOperationRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRestrictionType(this.restrictionType) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 98a416a6d3..1ad4e6b61f 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AddressAliasTransaction'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; import { AddressDto } from '../../infrastructure/catbuffer/AddressDto'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -121,21 +119,6 @@ export class AddressAliasTransaction extends Transaction { return byteSize + byteActionType + byteNamespaceId + byteAddress; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addAliasAction(this.aliasAction) - .addNamespaceId(this.namespaceId.id.toDTO()) - .addAddress(this.address.plain()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 6b1d36e4be..01039aa405 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -14,10 +14,8 @@ * limitations under the License. */ -import { SignSchema } from '../../core/crypto'; +import { KeyPair, SignSchema } from '../../core/crypto'; import { Convert } from '../../core/format'; -import { AggregateTransaction as AggregatedTransactionCore} from '../../infrastructure/builders/AggregateTransaction'; -import { Builder } from '../../infrastructure/builders/AggregateTransaction'; import { AggregateTransactionBuilder } from '../../infrastructure/catbuffer/AggregateTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { CosignatureBuilder } from '../../infrastructure/catbuffer/CosignatureBuilder'; @@ -31,6 +29,7 @@ import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AggregateTransactionCosignature } from './AggregateTransactionCosignature'; import { CosignatureSignedTransaction } from './CosignatureSignedTransaction'; +import { CosignatureTransaction } from './CosignatureTransaction'; import { Deadline } from './Deadline'; import { InnerTransaction } from './InnerTransaction'; import { SignedTransaction } from './SignedTransaction'; @@ -134,21 +133,6 @@ export class AggregateTransaction extends Transaction { return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {innerTransactions}); } - /** - * @internal - * @returns {AggregateTransaction} - */ - public buildTransaction(): AggregatedTransactionCore { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addType(this.type) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addTransactions(this.innerTransactions.map((transaction) => { - return transaction.aggregateTransaction(); - })).build(); - } - /** * @internal * Sign transaction with cosignatories creating a new SignedTransaction @@ -161,11 +145,23 @@ export class AggregateTransaction extends Transaction { public signTransactionWithCosignatories(initiatorAccount: Account, cosignatories: Account[], generationHash: string, - signSchema: SignSchema = SignSchema.SHA3) { - const aggregateTransaction = this.buildTransaction(); - const signedTransactionRaw = aggregateTransaction - .signTransactionWithCosigners(initiatorAccount, cosignatories, generationHash, signSchema); - return new SignedTransaction(signedTransactionRaw.payload, signedTransactionRaw.hash, initiatorAccount.publicKey, + signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { + const signedTransaction = this.signWith(initiatorAccount, generationHash, signSchema); + const transactionHashBytes = Convert.hexToUint8(signedTransaction.hash); + let signedPayload = signedTransaction.payload; + cosignatories.forEach((cosigner) => { + const signature = KeyPair.sign(cosigner, transactionHashBytes, signSchema); + signedPayload += cosigner.publicKey + Convert.uint8ToHex(signature); + }); + + // Calculate new size + const size = `00000000${(signedPayload.length / 2).toString(16)}`; + const formatedSize = size.substr(size.length - 8, size.length); + const littleEndianSize = formatedSize.substr(6, 2) + formatedSize.substr(4, 2) + + formatedSize.substr(2, 2) + formatedSize.substr(0, 2); + + signedPayload = littleEndianSize + signedPayload.substr(8, signedPayload.length - 8); + return new SignedTransaction(signedPayload, signedTransaction.hash, initiatorAccount.publicKey, this.type, this.networkType); } @@ -182,13 +178,21 @@ export class AggregateTransaction extends Transaction { public signTransactionGivenSignatures(initiatorAccount: Account, cosignatureSignedTransactions: CosignatureSignedTransaction[], generationHash: string, - signSchema: SignSchema= SignSchema.SHA3) { - const aggregateTransaction = this.buildTransaction(); - const signedTransactionRaw = aggregateTransaction.signTransactionGivenSignatures(initiatorAccount, - cosignatureSignedTransactions, - generationHash, - signSchema); - return new SignedTransaction(signedTransactionRaw.payload, signedTransactionRaw.hash, initiatorAccount.publicKey, + signSchema: SignSchema= SignSchema.SHA3): SignedTransaction { + const signedTransaction = this.signWith(initiatorAccount, generationHash, signSchema); + let signedPayload = signedTransaction.payload; + cosignatureSignedTransactions.forEach((cosignedTransaction) => { + signedPayload += cosignedTransaction.signer + cosignedTransaction.signature; + }); + + // Calculate new size + const size = `00000000${(signedPayload.length / 2).toString(16)}`; + const formatedSize = size.substr(size.length - 8, size.length); + const littleEndianSize = formatedSize.substr(6, 2) + formatedSize.substr(4, 2) + + formatedSize.substr(2, 2) + formatedSize.substr(0, 2); + + signedPayload = littleEndianSize + signedPayload.substr(8, signedPayload.length - 8); + return new SignedTransaction(signedPayload, signedTransaction.hash, initiatorAccount.publicKey, this.type, this.networkType); } @@ -248,9 +252,6 @@ export class AggregateTransaction extends Transaction { transactions = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); }); - console.log('cosignatures', Convert.uint8ToHex(cosignatures)); - console.log('transactions', Convert.uint8ToHex(transactions)); - const transactionBuilder = new AggregateTransactionBuilder( new SignatureDto(signatureBuffer), new KeyDto(signerBuffer), diff --git a/src/model/transaction/CosignatureTransaction.ts b/src/model/transaction/CosignatureTransaction.ts index d1b6ddc5b5..62e4a248ed 100644 --- a/src/model/transaction/CosignatureTransaction.ts +++ b/src/model/transaction/CosignatureTransaction.ts @@ -14,13 +14,12 @@ * limitations under the License. */ -import { SignSchema } from '../../core/crypto'; +import { KeyPair, SignSchema } from '../../core/crypto'; import { Convert } from '../../core/format/Convert'; -import {CosignatureTransaction as CosignaturetransactionLibrary} from '../../infrastructure/builders/CosignatureTransaction'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import {Account} from '../account/Account'; import {AggregateTransaction} from './AggregateTransaction'; import {CosignatureSignedTransaction} from './CosignatureSignedTransaction'; +import { Transaction } from './Transaction'; /** * Cosignature transaction is used to sign an aggregate transactions with missing cosignatures. @@ -41,9 +40,9 @@ export class CosignatureTransaction { * @param transactionToCosign - Transaction to cosign. * @returns {CosignatureTransaction} */ - public static create(transactionToCosign: AggregateTransaction) { + public static create(transactionToCosign: AggregateTransaction): CosignatureTransaction { if (transactionToCosign.isUnannounced()) { - throw new Error('transaction to cosign should be announced first'); + throw new Error('Transaction to cosign should be announced first'); } return new CosignatureTransaction(transactionToCosign); } @@ -64,12 +63,14 @@ export class CosignatureTransaction { /** * For aggregated complete transaction, cosignatories are gathered off chain announced. */ - const transactionHash = VerifiableTransaction.createTransactionHash(payload, Array.from(Convert.hexToUint8(generationHash))); - const aggregateSignatureTransaction = new CosignaturetransactionLibrary(transactionHash); - const signedTransactionRaw = aggregateSignatureTransaction.signCosignatoriesTransaction(account, signSchema); - return new CosignatureSignedTransaction(signedTransactionRaw.parentHash, - signedTransactionRaw.signature, - signedTransactionRaw.signer); + const transactionHash = Transaction.createTransactionHash(payload, Array.from(Convert.hexToUint8(generationHash))); + const hashBytes = Convert.hexToUint8(transactionHash); + const signature = KeyPair.sign(account, new Uint8Array(hashBytes), signSchema); + return new CosignatureSignedTransaction( + Convert.uint8ToHex(hashBytes), + Convert.uint8ToHex(signature), + account.publicKey, + ); } /** @@ -80,10 +81,16 @@ export class CosignatureTransaction { * @returns {CosignatureSignedTransaction} */ public signWith(account: Account, signSchema: SignSchema = SignSchema.SHA3): CosignatureSignedTransaction { - const aggregateSignatureTransaction = new CosignaturetransactionLibrary(this.transactionToCosign.transactionInfo!.hash); - const signedTransactionRaw = aggregateSignatureTransaction.signCosignatoriesTransaction(account, signSchema); - return new CosignatureSignedTransaction(signedTransactionRaw.parentHash, - signedTransactionRaw.signature, - signedTransactionRaw.signer); + if (!this.transactionToCosign.transactionInfo!.hash) { + throw new Error('Transaction to cosign should be announced first'); + } + const hash = this.transactionToCosign.transactionInfo!.hash; + const hashBytes = Convert.hexToUint8(hash ? hash : ''); + const signature = KeyPair.sign(account, new Uint8Array(hashBytes), signSchema); + return new CosignatureSignedTransaction( + hash ? hash : '', + Convert.uint8ToHex(signature), + account.publicKey, + ); } } diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index e34bb40489..b36810cf05 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/HashLockTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedHashLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder'; @@ -131,23 +129,6 @@ export class LockFundsTransaction extends Transaction { return byteSize + byteMosaicId + byteAmount + byteDuration + byteHash; } - /** - * @internal - * @return {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addType(this.type) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaic.id.id.toDTO()) - .addMosaicAmount(this.mosaic.amount.toDTO()) - .addDuration(this.duration.toDTO()) - .addHash(this.hash) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index fa1e35dfef..6fb31645ba 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -15,10 +15,9 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MultisigModificationTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { CosignatoryModificationBuilder } from '../../infrastructure/catbuffer/CosignatoryModificationBuilder'; +import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { MultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/MultisigAccountModificationTransactionBuilder'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -32,7 +31,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; /** * Modify multisig account transactions are part of the NEM's multisig account system. @@ -125,21 +123,6 @@ export class ModifyMultisigAccountTransaction extends Transaction { return byteSize + byteRemovalDelta + byteApprovalDelta + byteNumModifications + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMinApprovalDelta(this.minApprovalDelta) - .addMinRemovalDelta(this.minRemovalDelta) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index 819d69c43c..f366fc0aed 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MosaicAddressRestrictionTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -142,23 +140,6 @@ export class MosaicAddressRestrictionTransaction extends Transaction { byteTargetAddress + bytePreviousRestrictionValue + byteNewRestrictionValue; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaicId.id.toDTO()) - .addRestrictionKey(this.restrictionKey.toDTO()) - .addTargetAddress(this.targetAddress.plain()) - .addPreviousRestrictionValue(this.previousRestrictionValue.toDTO()) - .addNewRestrictionValue(this.newRestrictionValue.toDTO()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index f822b73505..acffa89de0 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MosaicAliasTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; @@ -117,21 +115,6 @@ export class MosaicAliasTransaction extends Transaction { return byteSize + byteType + byteNamespaceId + byteMosaicId; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addAliasAction(this.aliasAction) - .addNamespaceId(this.namespaceId.id.toDTO()) - .addMosaicId(this.mosaicId.id.toDTO()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index c0adbd1e8b..9ebbf03fe6 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MosaicCreationTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedMosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicDefinitionTransactionBuilder'; @@ -158,35 +156,6 @@ export class MosaicDefinitionTransaction extends Transaction { return GeneratorUtils.readUint32At(this.nonce.toDTO(), 0); } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - let mosaicDefinitionTransaction = new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addDivisibility(this.mosaicProperties.divisibility) - .addDuration(this.mosaicProperties.duration ? this.mosaicProperties.duration.toDTO() : []) - .addNonce(this.nonce.toDTO()) - .addMosaicId(this.mosaicId.id.toDTO()); - - if (this.mosaicProperties.supplyMutable === true) { - mosaicDefinitionTransaction = mosaicDefinitionTransaction.addSupplyMutable(); - } - - if (this.mosaicProperties.transferable === true) { - mosaicDefinitionTransaction = mosaicDefinitionTransaction.addTransferability(); - } - - if (this.mosaicProperties.restrictable === true) { - mosaicDefinitionTransaction = mosaicDefinitionTransaction.addRestrictable(); - } - - return mosaicDefinitionTransaction.build(); - } - /** * @internal * @returns {Uint8Array} @@ -207,7 +176,7 @@ export class MosaicDefinitionTransaction extends Transaction { this.getMosaicFlagValue(), this.mosaicProperties.divisibility, new BlockDurationDto(this.mosaicProperties.duration ? - this.mosaicProperties.duration.toDTO() : []), + this.mosaicProperties.duration.toDTO() : UInt64.fromUint(0).toDTO()), ); return transactionBuilder.serialize(); } @@ -226,7 +195,7 @@ export class MosaicDefinitionTransaction extends Transaction { this.getMosaicFlagValue(), this.mosaicProperties.divisibility, new BlockDurationDto(this.mosaicProperties.duration ? - this.mosaicProperties.duration.toDTO() : []), + this.mosaicProperties.duration.toDTO() : UInt64.fromUint(0).toDTO()), ); return transactionBuilder.serialize(); } diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index 7b4f757efc..9081fa5dbc 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/MosaicGlobalRestrictionTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicGlobalRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -162,25 +160,6 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { bytePreviousRestrictionType; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaicId.id.toDTO()) - .addReferenceMosaicId(this.referenceMosaicId.id.toDTO()) - .addRestrictionKey(this.restrictionKey.toDTO()) - .addPreviousRestrictionValue(this.previousRestrictionValue.toDTO()) - .addPreviousRestrictionType(this.previousRestrictionType) - .addNewRestrictionValue(this.newRestrictionValue.toDTO()) - .addNewRestrictionType(this.newRestrictionType) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index be4f3a89a3..03f0137241 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -14,8 +14,7 @@ * limitations under the License. */ -import { Builder } from '../../infrastructure/builders/MosaicSupplyChangeTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; @@ -33,7 +32,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { Convert } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -118,21 +116,6 @@ export class MosaicSupplyChangeTransaction extends Transaction { return byteSize + byteMosaicId + byteDirection + byteDelta; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaicId.id.toDTO()) - .addDirection(this.direction) - .addDelta(this.delta.toDTO()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index 0cdcae2aa6..3089126e25 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert, Convert as convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/NamespaceCreationTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedNamespaceRegistrationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedNamespaceRegistrationTransactionBuilder'; @@ -168,28 +166,6 @@ export class RegisterNamespaceTransaction extends Transaction { return byteSize + byteType + byteDurationParentId + byteNamespaceId + byteNameSize + byteName; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - let registerNamespacetransaction = new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addNamespaceType(this.namespaceType) - .addNamespaceId(this.namespaceId.id.toDTO()) - .addNamespaceName(this.namespaceName); - - if (this.namespaceType === NamespaceType.RootNamespace) { - registerNamespacetransaction = registerNamespacetransaction.addDuration(this.duration!.toDTO()); - } else { - registerNamespacetransaction = registerNamespacetransaction.addParentId(this.parentId!.id.toDTO()); - } - - return registerNamespacetransaction.build(); - } - /** * @internal * @returns {Uint8Array} @@ -238,7 +214,7 @@ export class RegisterNamespaceTransaction extends Transaction { transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), - TransactionType.SECRET_LOCK.valueOf(), + TransactionType.REGISTER_NAMESPACE.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), new BlockDurationDto(this.duration!.toDTO()), @@ -248,7 +224,7 @@ export class RegisterNamespaceTransaction extends Transaction { transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), - TransactionType.SECRET_LOCK.valueOf(), + TransactionType.REGISTER_NAMESPACE.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), Convert.hexToUint8(Convert.utf8ToHex(this.namespaceName)), undefined, diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index e65187384d..5efbe3c3fe 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -14,8 +14,6 @@ * limitations under the License. */ import { Convert as convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/SecretLockTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedSecretLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder'; @@ -155,25 +153,6 @@ export class SecretLockTransaction extends Transaction { return convert.hexToUint8(64 > this.secret.length ? this.secret + '0'.repeat(64 - this.secret.length) : this.secret); } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addType(this.type) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addMosaicId(this.mosaic.id.id.toDTO()) - .addMosaicAmount(this.mosaic.amount.toDTO()) - .addDuration(this.duration.toDTO()) - .addHashAlgorithm(this.hashType) - .addSecret(this.secret) - .addRecipient(this.recipient.plain()) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index 41df6b207b..cbca7576b2 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert, Convert as convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/SecretProofTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedSecretProofTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; @@ -140,23 +138,6 @@ export class SecretProofTransaction extends Transaction { return convert.hexToUint8(this.proof); } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addType(this.type) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addHashAlgorithm(this.hashType) - .addSecret(this.secret) - .addRecipient(this.recipient.plain()) - .addProof(this.proof) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index ca2fbbce44..29d3ae1b3d 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -16,7 +16,6 @@ import { KeyPair, SHA3Hasher, SignSchema } from '../../core/crypto'; import { Convert } from '../../core/format'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; import { SerializeTransactionToJSON } from '../../infrastructure/transaction/SerializeTransactionToJSON'; import { Account } from '../account/Account'; import { PublicAccount } from '../account/PublicAccount'; @@ -81,9 +80,27 @@ export abstract class Transaction { } /** - * @internal + * Generate transaction hash hex + * @param {string} transactionPayload HexString Payload + * @param {Array} generationHashBuffer Network generation hash byte + * @returns {string} Returns Transaction Payload hash */ - protected abstract buildTransaction(): VerifiableTransaction; + public static createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { + const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); + const signingBytes = byteBuffer + .slice(4, 36) + .concat(byteBuffer + .slice(4 + 64, 4 + 64 + 32)) + .concat(generationHashBuffer) + .concat(byteBuffer + .splice(4 + 64 + 32, byteBuffer.length)); + + const hash = new Uint8Array(32); + + SHA3Hasher.func(hash, signingBytes, 32); + + return Convert.uint8ToHex(hash); + } /** * @internal @@ -104,25 +121,6 @@ export abstract class Transaction { * @returns {SignedTransaction} */ public signWith(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { - const transaction = this.buildTransaction(); - const signedTransactionRaw = transaction.signTransaction(account, generationHash, signSchema); - return new SignedTransaction( - signedTransactionRaw.payload, - signedTransactionRaw.hash, - account.publicKey, - this.type, - this.networkType); - } - - /** - * @internal - * Serialize and sign transaction creating a new SignedTransaction - * @param account - The account to sign the transaction - * @param generationHash - Network generation hash hex - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {SignedTransaction} - */ - public signWithCatbuffer(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { const generationHashBytes = Array.from(Convert.hexToUint8(generationHash)); const byteBuffer = Array.from(this.generateBytes()); const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); @@ -137,41 +135,28 @@ export abstract class Transaction { const payload = Convert.uint8ToHex(signedTransactionBuffer); return new SignedTransaction( payload, - this.createTransactionHash(payload, generationHashBytes), + Transaction.createTransactionHash(payload, generationHashBytes), account.publicKey, this.type, this.networkType); } /** - * Generate transaction hash hex - * @param {string} transactionPayload HexString Payload - * @param {Array} generationHashBuffer Network generation hash byte - * @returns {string} Returns Transaction Payload hash - */ - public createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { - const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); - const signingBytes = byteBuffer - .slice(4, 36) - .concat(byteBuffer - .slice(4 + 64, 4 + 64 + 32)) - .concat(generationHashBuffer) - .concat(byteBuffer - .splice(4 + 64 + 32, byteBuffer.length)); - - const hash = new Uint8Array(32); - - SHA3Hasher.func(hash, signingBytes, 32); - - return Convert.uint8ToHex(hash); - } - - /** - * @internal - * @returns {Array} + * Converts the transaction into AggregateTransaction compatible + * @returns {Array.<*>} AggregateTransaction bytes */ public aggregateTransaction(): number[] { - return this.buildTransaction().toAggregateTransaction(this.signer!.publicKey); + const signer = Convert.hexToUint8(this.signer!.publicKey); + let resultBytes = Array.from(this.generateBytes()); + resultBytes.splice(0, 4 + 64 + 32); + resultBytes = Array.from(signer).concat(resultBytes); + resultBytes.splice(32 + 2 + 2, 16); + return Array.from((new Uint8Array([ + (resultBytes.length + 4 & 0x000000ff), + (resultBytes.length + 4 & 0x0000ff00) >> 8, + (resultBytes.length + 4 & 0x00ff0000) >> 16, + (resultBytes.length + 4 & 0xff000000) >> 24, + ]))).concat(resultBytes); } /** @@ -278,9 +263,8 @@ export abstract class Transaction { * @returns {string} * @memberof Transaction */ - public serialize() { - const transaction = this.buildTransaction(); - return transaction.serializeUnsignedTransaction(); + public serialize(): string { + return Convert.uint8ToHex(this.generateBytes()); } /** diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 6714fd7904..c78253b040 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -16,8 +16,6 @@ import { Convert, Convert as convert } from '../../core/format'; import { RawAddress } from '../../core/format/RawAddress'; -import { Builder } from '../../infrastructure/builders/TransferTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedTransferTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedTransferTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; @@ -145,6 +143,22 @@ export class TransferTransaction extends Transaction { return GeneratorUtils.concatTypedArrays(typeBuffer, payloadBuffer); } + /** + * Return unresolved address bytes of the recipient + * @internal + * @returns {string} + */ + public getRecipientBytes(): Uint8Array { + const recipient = this.recipientToString(); + if (/^[0-9a-fA-F]{16}$/.test(recipient)) { + // received hexadecimal notation of namespaceId (alias) + return RawAddress.aliasToRecipient(convert.hexToUint8(recipient)); + } else { + // received recipient address + return RawAddress.stringToAddress(recipient); + } + } + /** * @override Transaction.size() * @description get the byte size of a TransferTransaction @@ -167,21 +181,6 @@ export class TransferTransaction extends Transaction { return byteSize + byteRecipient + byteNumMosaics + bytePayload + byteMosaics; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRecipient(this.recipientToString()) - .addMosaics(this.mosaics.map((mosaic) => mosaic.toDTO())) - .addMessage(this.message) - .build(); - } - /** * @internal * @returns {Uint8Array} @@ -197,7 +196,7 @@ export class TransferTransaction extends Transaction { TransactionType.TRANSFER.valueOf(), new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), - new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), + new UnresolvedAddressDto(this.getRecipientBytes()), this.getMessageBuffer(), this.sortMosaics().map((mosaic) => { return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index 0d5b8c8b25..68c65c8eae 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountLinkTransaction', () => { expect(accountLinkTransaction.linkAction).to.be.equal(0); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); - const signedTransaction = accountLinkTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = accountLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 753a431d02..df7a5bbb03 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -162,7 +162,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = addressRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -213,7 +213,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = mosaicRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -266,7 +266,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = operationRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index 2721b583d9..59b1ce1144 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -80,12 +80,12 @@ describe('AddressAliasTransaction', () => { expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = addressAliasTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = addressAliasTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('002AD8FC018D9A49E19050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + )).to.be.equal('012AD8FC018D9A49E19050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); }); diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 5f527cd9b1..178a980e4e 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -106,7 +106,7 @@ describe('AggregateTransaction', () => { NetworkType.MIJIN_TEST, []); - const signedTransaction = aggregateTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); @@ -166,12 +166,12 @@ describe('AggregateTransaction', () => { const signedTransaction = aggregateTransaction.signWith(account, generationHash); - expect(signedTransaction.payload.substring(0, 8)).to.be.equal('BC000000'); - expect(signedTransaction.payload.substring(240, 256)).to.be.equal('4000000040000000'); + expect(signedTransaction.payload.substring(0, 8)).to.be.equal('BA000000'); + expect(signedTransaction.payload.substring(240, 256)).to.be.equal('3E0000003E000000'); expect(signedTransaction.payload.substring( 320, signedTransaction.payload.length, - )).to.be.equal('01904D41E6DE84B8010000000000000001070302E803000000000000'); + )).to.be.equal('01904D41E6DE84B801000000000000000703E803000000000000'); }); it('should createComplete an AggregateTransaction object with MosaicSupplyChangeTransaction', () => { diff --git a/test/model/transaction/LockFundsTransaction.spec.ts b/test/model/transaction/LockFundsTransaction.spec.ts index df3583f1d7..779e6166d7 100644 --- a/test/model/transaction/LockFundsTransaction.spec.ts +++ b/test/model/transaction/LockFundsTransaction.spec.ts @@ -118,7 +118,7 @@ describe('LockFundsTransaction', () => { signedTransaction, NetworkType.MIJIN_TEST, ); - const signedTx = lockFundsTransaction.signWithCatbuffer(account, generationHash); + const signedTx = lockFundsTransaction.signWith(account, generationHash); expect(signedTx.payload.substring( 136, diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index f6232022da..041a685b6b 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -110,7 +110,7 @@ describe('ModifyMultisigAccountTransaction', () => { expect(modifyMultisigAccountTransaction.modifications[1].cosignatoryPublicAccount.publicKey) .to.be.equal('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); - const signedTransaction = modifyMultisigAccountTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts index 02aad2fc65..947904ce56 100644 --- a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts @@ -47,7 +47,7 @@ describe('MosaicAddressRestrictionTransaction', () => { expect(mosaicAddressRestrictionTransaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(8).toHex()); expect(mosaicAddressRestrictionTransaction.targetAddress.plain()).to.be.equal(account.address.plain()); - const signedTransaction = mosaicAddressRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicAddressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index a9314a0c54..34184eff95 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -80,12 +80,12 @@ describe('MosaicAliasTransaction', () => { expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); expect(mosaicAliasTransaction.mosaicId.id.higher).to.be.equal(3405110546); - const signedTransaction = mosaicAliasTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('002AD8FC018D9A49E14CCCD78612DDF5CA'); + )).to.be.equal('012AD8FC018D9A49E14CCCD78612DDF5CA'); }); diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index 688506516b..f444278cbe 100644 --- a/test/model/transaction/MosaicDefinitionTransaction.spec.ts +++ b/test/model/transaction/MosaicDefinitionTransaction.spec.ts @@ -64,7 +64,7 @@ describe('MosaicDefinitionTransaction', () => { duration: UInt64.fromUint(1000), }), NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(mosaicDefinitionTransaction.maxFee.higher).to.be.equal(0); @@ -93,7 +93,7 @@ describe('MosaicDefinitionTransaction', () => { expect(mosaicDefinitionTransaction.mosaicProperties.transferable).to.be.equal(true); expect(mosaicDefinitionTransaction.mosaicProperties.restrictable).to.be.equal(true); - const signedTransaction = mosaicDefinitionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -129,7 +129,7 @@ describe('MosaicDefinitionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('E6DE84B8010000000000000001000302E803000000000000'); + )).to.be.equal('E6DE84B801000000000000000003E803000000000000'); }); @@ -175,7 +175,7 @@ describe('MosaicDefinitionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('E6DE84B80100000000000000000003'); + )).to.be.equal('E6DE84B8010000000000000000030000000000000000'); }); }); diff --git a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts index 9e436d2fea..39c409bd22 100644 --- a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts @@ -54,7 +54,7 @@ describe('MosaicGlobalRestrictionTransaction', () => { expect(mosaicGlobalRestrictionTransaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.EQ); expect(mosaicGlobalRestrictionTransaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); - const signedTransaction = mosaicGlobalRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/RegisterNamespaceTransaction.spec.ts b/test/model/transaction/RegisterNamespaceTransaction.spec.ts index db497c73b9..dcd12d95f7 100644 --- a/test/model/transaction/RegisterNamespaceTransaction.spec.ts +++ b/test/model/transaction/RegisterNamespaceTransaction.spec.ts @@ -66,7 +66,7 @@ describe('RegisterNamespaceTransaction', () => { expect(registerNamespaceTransaction.duration!.lower).to.be.equal(1000); expect(registerNamespaceTransaction.duration!.higher).to.be.equal(0); - const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -83,7 +83,7 @@ describe('RegisterNamespaceTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/SecretLockTransaction.spec.ts b/test/model/transaction/SecretLockTransaction.spec.ts index 9f240dda47..9b5a00780d 100644 --- a/test/model/transaction/SecretLockTransaction.spec.ts +++ b/test/model/transaction/SecretLockTransaction.spec.ts @@ -101,7 +101,7 @@ describe('SecretLockTransaction', () => { recipient, NetworkType.MIJIN_TEST, ); - const signedTx = secretLockTransaction.signWithCatbuffer(account, generationHash); + const signedTx = secretLockTransaction.signWith(account, generationHash); expect(signedTx.payload.substring( 240, signedTx.payload.length, diff --git a/test/model/transaction/SecretProofTransaction.spec.ts b/test/model/transaction/SecretProofTransaction.spec.ts index 8712f1ca9e..951b1ab8f0 100644 --- a/test/model/transaction/SecretProofTransaction.spec.ts +++ b/test/model/transaction/SecretProofTransaction.spec.ts @@ -203,7 +203,7 @@ describe('SecretProofTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTx = secretProofTransaction.signWithCatbuffer(account, generationHash); + const signedTx = secretProofTransaction.signWith(account, generationHash); expect(signedTx.payload.substring( 240, signedTx.payload.length, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index 6f53048623..d0baad099a 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -15,7 +15,6 @@ */ import { expect } from 'chai'; -import { VerifiableTransaction } from '../../../src/infrastructure/builders/VerifiableTransaction'; import { Account } from '../../../src/model/account/Account'; import { Address } from '../../../src/model/account/Address'; import { NetworkType } from '../../../src/model/blockchain/NetworkType'; @@ -235,10 +234,6 @@ class FakeTransaction extends Transaction { throw new Error('Method not implemented.'); } - protected buildTransaction(): VerifiableTransaction { - throw new Error('Method not implemented.'); - } - protected generateBytes(): Uint8Array { throw new Error('Not implemented'); } diff --git a/test/model/transaction/TransferTransaction.spec.ts b/test/model/transaction/TransferTransaction.spec.ts index 63d8bb880c..969bf81a1b 100644 --- a/test/model/transaction/TransferTransaction.spec.ts +++ b/test/model/transaction/TransferTransaction.spec.ts @@ -210,7 +210,7 @@ describe('TransferTransaction', () => { expect(transferTransaction.recipient).to.be.instanceof(Address); expect((transferTransaction.recipient as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = transferTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = transferTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, From b73893ea0fc2c5dd565a2fd9e4abc74d3ec8eed5 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 12:15:35 +0100 Subject: [PATCH 66/98] updated action types value --- src/model/account/RestrictionModificationType.ts | 4 ++-- src/model/mosaic/MosaicSupplyType.ts | 4 ++-- src/model/namespace/AliasAction.ts | 4 ++-- src/model/transaction/LinkAction.ts | 4 ++-- src/model/transaction/MultisigCosignatoryModificationType.ts | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/model/account/RestrictionModificationType.ts b/src/model/account/RestrictionModificationType.ts index b4aabd8151..a9aa625500 100644 --- a/src/model/account/RestrictionModificationType.ts +++ b/src/model/account/RestrictionModificationType.ts @@ -18,6 +18,6 @@ * Account restriction modification type */ export enum RestrictionModificationType { - Add = 0x00, - Remove = 0x01, + Add = 0x01, + Remove = 0x00, } diff --git a/src/model/mosaic/MosaicSupplyType.ts b/src/model/mosaic/MosaicSupplyType.ts index c5cf2655fa..0f28e995b0 100644 --- a/src/model/mosaic/MosaicSupplyType.ts +++ b/src/model/mosaic/MosaicSupplyType.ts @@ -20,6 +20,6 @@ * 1: Decrease in supply. */ export enum MosaicSupplyType { - Decrease = 0, - Increase = 1, + Decrease = 0x00, + Increase = 0x01, } diff --git a/src/model/namespace/AliasAction.ts b/src/model/namespace/AliasAction.ts index 27669a1d91..b107b0d65d 100644 --- a/src/model/namespace/AliasAction.ts +++ b/src/model/namespace/AliasAction.ts @@ -20,6 +20,6 @@ * 1: Unlink an alias. */ export enum AliasActionType { - Link = 1, - Unlink = 0, + Link = 0x01, + Unlink = 0x00, } diff --git a/src/model/transaction/LinkAction.ts b/src/model/transaction/LinkAction.ts index 678e1bb87d..212a0a9c80 100644 --- a/src/model/transaction/LinkAction.ts +++ b/src/model/transaction/LinkAction.ts @@ -15,6 +15,6 @@ */ export enum LinkAction { - Link = 0, - Unlink = 1, + Link = 0x01, + Unlink = 0x00, } diff --git a/src/model/transaction/MultisigCosignatoryModificationType.ts b/src/model/transaction/MultisigCosignatoryModificationType.ts index 7aa92781f7..2edfa42d01 100644 --- a/src/model/transaction/MultisigCosignatoryModificationType.ts +++ b/src/model/transaction/MultisigCosignatoryModificationType.ts @@ -20,6 +20,6 @@ * 1: Remove cosignatory. */ export enum MultisigCosignatoryModificationType { - Add = 0, - Remove = 1, + Add = 0x01, + Remove = 0x00, } From bfb1cb1c12bf90e9c2891b105fe2fc2ee1e513fe Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 12:16:52 +0100 Subject: [PATCH 67/98] restored network config for e2e --- e2e/conf/network.conf | 66 +++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index 79f895aecf..150443d82d 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -1,54 +1,54 @@ { - "apiUrl": "http://c2.nem.ninja:3000", - "generationHash": "57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6", + "apiUrl": "http://localhost:3000", + "generationHash": "5E34C898234E17E8553359D4DEAA123742C323F4C42758C511E6CC805934853E", "testAccount": { - "privateKey": "E1C8521608F4896CA26A0C2DE739310EA4B06861D126CF4D6922064678A1969B", - "address": "SAKT3CKHCYIG5BBOPTSY2WXSVPBSLIA67AEOX4ND", - "publicKey": "9F784BF20318AE3CA6246C0EC2207FE095FFF7A84B6787E7E3C2CE4C3B92A2EA" + "privateKey": "C422CC3C9257A1568036E1726E64EB5923C8363A13D4344F9E66CD89C8789BC7", + "address": "SAMA2UEQNAQ45DWYDNJVLPWKQJDAHFZIVLWACIGN", + "publicKey": "8A78C9E9B0E59D0F74C0D47AB29FBD523C706293A3FA9CD9FE0EEB2C10EA924A" }, "multisigAccount": { - "privateKey": "A9CEAA617D0B7D9DEBE9F96BD63CCF68A49950BB315CB9A4169FC6AAA1EC9E28", - "address": "SDWY3PYN4ZZO4S4EBEY2UPSSZUPGZH2G2LQMUSEU", - "publicKey": "8A613468924B8771779C7E4C889205A9BE6CAE0B9435B4BCC8E79A8DD8571608" + "privateKey": "F6815438AE34F95F2CF364B4679D16F3602CA2107073C0709738BAB457B09A45", + "publicKey": "FAF3F9FD3E32EB43273E5351BAE705D0179D37CBDCC4DD78A0C73232DD3EF32C", + "address": "SDC4BXKIIDBQA2CY6RPRFO3WLC5OZHLKLJJ3NFEH" }, "cosignatoryAccount": { - "privateKey": "8CBAA7491B7DC1070BECBC4F60AE55F4A272DA1DAD1D502DB016E142993817BA", - "address": "SB7Q5A3KEKFEWBPBTC6RFKU6Q2L4V7DM4ZNE4A7A", - "publicKey": "61B8EB2C02F3D3731A8EF6FE4CCD6BC84615BABA09CA3E891C0D2542096E6AD3" + "privateKey": "F48EA053D7D2B47DC518FDD69B338D34C819D9AC51E8754378F2D86FC29783C7", + "publicKey": "D9FB51DDFA64CC56D7AEBB32976DA8A3A72C8C7D02838AA1041046FA0883EBC6", + "address": "SCHNSELDJ7JN5MPHBOKHNBR2QRST4GOGEMS4XZNE" }, "cosignatory2Account": { - "privateKey": "60380027EBE63A5D60F6156F5637685172331705160783FF2F9D93C1E5A8622B", - "address": "SCM47E3JVPHOFWLSMNX3RKQQQIB3JUBR7MTX4M4P", - "publicKey": "3D9996683A0FA460D13288B846DF68A9B6C0C1F14EC2E43907DF8D84DC87B9C2" + "privateKey": "E697E9E0D849ACD3BD9379E80C4E953B23375112C28D983AF94160AD269BE327", + "publicKey": "2B4598150E66B26D991FA56FAF691C539FD1A92EBEA99E2AF91808B9C7C4316F", + "address": "SAWZITCY4TCOFBSSINFO4DQZTRBSB5W5OBSQE237" }, "cosignatory3Account": { - "privateKey": "E39CE241F730CD190658AFDB5F3896628F92D7BC35D88435D148BED88C6CC844", - "address": "SDEVG5MU4MEGJ72NSBC7PKMK7JCJKN7QB3DOVARJ", - "publicKey": "422697046582D8B8063931B7327D0C06FA454B416F6A5C000922EC5BA546F4B2" + "privateKey": "3F42F4308B3EA912A9FE482D6DD04CCFD8D37E4397BF9655AA2EF36894491CAB", + "publicKey": "26A339827614E7AEE9DB427323AA3A49A48456AA5656D9A2E1B50FF93DE90756", + "address": "SCGYYXGL3TLZBOA5TUCCQYIM6NSYSLVCBVHGYKKW" }, "cosignatory4Account": { - "privateKey": "0EA7E63C96FC580AD5EE85ED3C77A96B421F7C8BF75A83AB889313114C9082F2", - "address": "SCBNKMD23J7BO3Q42SEGP4LXGVJYSDPUESSEWGWZ", - "publicKey": "3A225A2C7C7D95279E74D420728D2DA2A176DE036B67909074AEF5F2DCFAF31C" + "privateKey": "53D6A6659A200DAF4930AD4C8A3B5B28ECAAA1F643E990C0A41C0B8EC9B3D05A", + "publicKey": "F721863CC533C3DF4429A957F822B986C81E62A91726A3E3BD0B861FA42F757D", + "address": "SD3JPQ2KXMQKLVOHJV7GTOYV73CL72ZSEOW7RIWE" }, "testAccount2": { - "privateKey": "A084418D937627BCDA19B277D8610C845124149FA18AABE96A17D56A2EA7FB8B", - "address": "SBF5HY3T7SXIBCSK4V4WNS4LS4QUMESMVNBCD2AQ", - "publicKey": "1C4B44400FDC933860B1949A5AEA756F19A36D73C4634699E49C3E7275EFA54F" + "privateKey": "F0AB1010EFEE19EE5373719881DF5123C13E643C519655F7E97347BFF77175BF", + "publicKey": "9DBF67474D6E1F8B131B4EB1F5BA0595AFFAE1123607BC1048F342193D7E669F", + "address": "SDBC4JE7GTJAKN2XJCQWWRJMYA35AFOYQBATXOUA" }, "testAccount3": { - "privateKey": "8C9E72C5D8964A19174B478B65BD4B7F2AFD8F92C05AE45B15A9EDF222EC8CA8", - "address": "SDY65GIMMOF7GZGGART66QGS6ELWDTQT55JJOF42", - "publicKey": "B8320002C5CF64D855F073F2387FB18F13E7A04FA57FC3743694B04579104F98" + "privateKey": "61C3C8F24E3708CFE17A64B66EBD29D747326DBF7962EBEE9340439725C04F11", + "publicKey": "399C1D18FDE3293DCF7BF522626266663C83453BDF7D38C9E96AFC795C07E0A2", + "address": "SC7PPZRJMEMQ7S32PURJTTNHOATDYQ4NPRFOAOUO" }, "testAccountNoBalance": { - "privateKey": "CE4E6B1113EF8999ED79A027A4F3255C367BC2E40417E27E614FB7C12E42BDFA", - "address": "SDNMDW5TXIORKRXQ7F3QORRW4KUAK4ALQ7JWX2KJ", - "publicKey": "92658FE642AEAF1B766D0F4FE4E263C3A0E069735836383D31A70E2B7801358B" + "privateKey": "6530E5ED4B6D32CB9AF2EE09D2889DC781C569B83C137854EDC7773B057074A1", + "publicKey": "559019D82C4CACAAE616A024544251D58BB4464CD36407224475A577F9649E78", + "address": "SCQP4B6BDNH5MZHTLL2ZNXIPYSLD5BU4NDXBZXNK" }, "harvestingAccount": { - "privateKey": "9999630E4AE5CA5675A703F3268084EB9A9B477A8C519D66465D5D21830E691A", - "address": "SC2PGQO5WV4QZRAQHJDNQ2Q5IFWA2D3VLFEFFZHC", - "publicKey": "74771A0B0B920D787F4F8242926C348007B23062910DE99C7E56AA79D4D7B90A" + "privateKey": "AF39DCC819388A2CE9DC0922730D7579588571A63F349A0FB1BC44807C926E53", + "publicKey": "FAEDB16763F22870B75BF934EA5F2792BDF109EC0C504718DDCBD92DF13C2628", + "address": "SCNPFCWFV2FYQVMU5HMJJTMADRZ3LRXVA76F56N2" } -} +} \ No newline at end of file From 917b19de17495302d9f4910fc1e874c264ae1ee6 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 12:22:36 +0100 Subject: [PATCH 68/98] Fixed unit tests after swapping action type value --- test/core/utils/TransactionMapping.spec.ts | 2 +- test/model/transaction/AccountLinkTransaction.spec.ts | 10 +++++----- .../transaction/AccountRestrictionTransaction.spec.ts | 6 +++--- test/model/transaction/AggregateTransaction.spec.ts | 4 ++-- .../ModifyMultisigAccountTransaction.spec.ts | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index ebcfcf0734..e0e66628a0 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -499,7 +499,7 @@ describe('TransactionMapping - createFromPayload', () => { const signedTransaction = accountLinkTransaction.signWith(account, generationHash); const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AccountLinkTransaction; - expect(transaction.linkAction).to.be.equal(0); + expect(transaction.linkAction).to.be.equal(1); expect(transaction.remoteAccountKey).to.be.equal(account.publicKey); }); diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index 68c65c8eae..ec2fe1630d 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -48,7 +48,7 @@ describe('AccountLinkTransaction', () => { account.publicKey, LinkAction.Link, NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(accountLinkTransaction.maxFee.higher).to.be.equal(0); @@ -63,7 +63,7 @@ describe('AccountLinkTransaction', () => { NetworkType.MIJIN_TEST, ); - expect(accountLinkTransaction.linkAction).to.be.equal(0); + expect(accountLinkTransaction.linkAction).to.be.equal(1); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); const signedTransaction = accountLinkTransaction.signWith(account, generationHash); @@ -71,7 +71,7 @@ describe('AccountLinkTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE00'); + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE01'); }); it('should create an AccountLinkTransaction object with unlink action', () => { @@ -82,7 +82,7 @@ describe('AccountLinkTransaction', () => { NetworkType.MIJIN_TEST, ); - expect(accountLinkTransaction.linkAction).to.be.equal(1); + expect(accountLinkTransaction.linkAction).to.be.equal(0); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); const signedTransaction = accountLinkTransaction.signWith(account, generationHash); @@ -90,7 +90,7 @@ describe('AccountLinkTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE01'); + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE00'); }); describe('size', () => { diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index df7a5bbb03..7fd1087647 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -167,7 +167,7 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('0101009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + )).to.be.equal('0101019050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); }); @@ -218,7 +218,7 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('0201004CCCD78612DDF5CA'); + )).to.be.equal('0201014CCCD78612DDF5CA'); }); @@ -271,7 +271,7 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('0401004E42'); + )).to.be.equal('0401014E42'); }); diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 178a980e4e..8bf2bfb730 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -232,8 +232,8 @@ describe('AggregateTransaction', () => { expect(signedTransaction.payload.substring( 320, signedTransaction.payload.length, - )).to.be.equal('0190554101020200B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC240' + - '0B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); + )).to.be.equal('0190554101020201B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC2401B1B5581FC81A69' + + '70DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); }); it('should createComplete an AggregateTransaction object with different cosignatories', () => { diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index 041a685b6b..00afd72d47 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -115,8 +115,8 @@ describe('ModifyMultisigAccountTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('01020200B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC' + - '6EC2400B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); + )).to.be.equal('01020201B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC2401B1' + + 'B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); }); From 3467578c0c3904ef48fcec27dd1fd88d66847cc5 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 21:43:04 +0100 Subject: [PATCH 69/98] Added ts catbuffer codes (without aggregateTx) Appended new signwithCatbuffer method in Transaction (temp) Applied catbuffer builders on standalone transaction (builder) Updated unit tests --- e2e/infrastructure/TransactionHttp.spec.ts | 4 +- .../AccountAddressRestrictionTransaction.ts | 46 +++++++-------- .../AccountOperationRestrictionTransaction.ts | 7 +++ .../transaction/AddressAliasTransaction.ts | 1 + .../MosaicDefinitionTransaction.ts | 13 +++++ src/model/transaction/Transaction.ts | 56 ++++++++++++++++++- src/model/transaction/TransferTransaction.ts | 1 - .../AccountLinkTransaction.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 6 +- .../AddressAliasTransaction.spec.ts | 2 +- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- .../MosaicAliasTransaction.spec.ts | 2 +- .../MosaicDefinitionTransaction.spec.ts | 2 +- test/model/transaction/Transaction.spec.ts | 4 ++ 14 files changed, 110 insertions(+), 38 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index bf85a04ac5..ee0f981589 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -486,7 +486,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = addressModification.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionModificationTransaction) => { + listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionTransaction) => { expect(transaction.modifications, 'Modifications').not.to.be.undefined; expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; @@ -712,7 +712,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = addressModification.signWith(account3, generationHash); - listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionModificationTransaction) => { + listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionTransaction) => { expect(transaction.modifications, 'Modifications').not.to.be.undefined; expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined; expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined; diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index d5e0f4d8a9..243b4ff560 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -14,17 +14,19 @@ * limitations under the License. */ -import { Convert, RawAddress } from '../../core/format'; +import { RawAddress } from '../../core/format'; +import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; +import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; -import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { PublicAccount } from '../account/PublicAccount'; +import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; @@ -46,7 +48,7 @@ export class AccountAddressRestrictionTransaction extends Transaction { * @returns {AccountAddressRestrictionTransaction} */ public static create(deadline: Deadline, - restrictionType: AccountRestrictionType, + restrictionType: RestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountAddressRestrictionTransaction { @@ -73,7 +75,7 @@ export class AccountAddressRestrictionTransaction extends Transaction { version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: AccountRestrictionType, + public readonly restrictionType: RestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, @@ -103,6 +105,20 @@ export class AccountAddressRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } + /** + * @internal + * @returns {VerifiableTransaction} + */ + protected buildTransaction(): VerifiableTransaction { + return new Builder() + .addDeadline(this.deadline.toDTO()) + .addFee(this.maxFee.toDTO()) + .addVersion(this.versionToDTO()) + .addRestrictionType(this.restrictionType) + .addModifications(this.modifications.map((modification) => modification.toDTO())) + .build(); + } + /** * @internal * @returns {Uint8Array} @@ -128,24 +144,4 @@ export class AccountAddressRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } - - /** - * @internal - * @returns {Uint8Array} - */ - protected generateEmbeddedBytes(): Uint8Array { - const transactionBuilder = new EmbeddedAccountAddressRestrictionTransactionBuilder( - new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), - this.versionToDTO(), - TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), - this.restrictionType.valueOf(), - this.modifications.map((modification) => { - return new AccountAddressRestrictionModificationBuilder( - modification.modificationType.valueOf(), - new UnresolvedAddressDto(RawAddress.stringToAddress(modification.value)), - ); - }), - ); - return transactionBuilder.serialize(); - } } diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index df82913d22..5824846b29 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -32,6 +32,13 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; export class AccountOperationRestrictionTransaction extends Transaction { diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 1ad4e6b61f..df00bd57bb 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -35,6 +35,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { RawAddress } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 9ebbf03fe6..e798b92770 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -37,6 +37,19 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; +import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; +import { MosaicFlagsDto } from '../../infrastructure/catbuffer/MosaicFlagsDto'; +import { MosaicFlags } from '../mosaic/MosaicFlag'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { Convert } from '../../core/format'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; /** * Before a mosaic can be created or transferred, a corresponding definition of the mosaic has to be created and published to the network. diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index 29d3ae1b3d..a713dc581a 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -142,8 +142,60 @@ export abstract class Transaction { } /** - * Converts the transaction into AggregateTransaction compatible - * @returns {Array.<*>} AggregateTransaction bytes + * @internal + * Serialize and sign transaction creating a new SignedTransaction + * @param account - The account to sign the transaction + * @param generationHash - Network generation hash hex + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {SignedTransaction} + */ + public signWithCatbuffer(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { + const generationHashBytes = Array.from(Convert.hexToUint8(generationHash)); + const byteBuffer = Array.from(this.generateBytes()); + const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); + const keyPairEncoded = KeyPair.createKeyPairFromPrivateKeyString(account.privateKey, signSchema); + const signature = Array.from(KeyPair.sign(account, new Uint8Array(signingBytes), signSchema)); + const signedTransactionBuffer = byteBuffer + .splice(0, 4) + .concat(signature) + .concat(Array.from(keyPairEncoded.publicKey)) + .concat(byteBuffer + .splice(64 + 32, byteBuffer.length)); + const payload = Convert.uint8ToHex(signedTransactionBuffer); + return new SignedTransaction( + payload, + this.createTransactionHash(payload, generationHashBytes), + account.publicKey, + this.type, + this.networkType); + } + + /** + * Generate transaction hash hex + * @param {string} transactionPayload HexString Payload + * @param {Array} generationHashBuffer Network generation hash byte + * @returns {string} Returns Transaction Payload hash + */ + public createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { + const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); + const signingBytes = byteBuffer + .slice(4, 36) + .concat(byteBuffer + .slice(4 + 64, 4 + 64 + 32)) + .concat(generationHashBuffer) + .concat(byteBuffer + .splice(4 + 64 + 32, byteBuffer.length)); + + const hash = new Uint8Array(32); + + SHA3Hasher.func(hash, signingBytes, 32); + + return Convert.uint8ToHex(hash); + } + + /** + * @internal + * @returns {Array} */ public aggregateTransaction(): number[] { const signer = Convert.hexToUint8(this.signer!.publicKey); diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index c78253b040..38a2d02c0b 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -18,7 +18,6 @@ import { Convert, Convert as convert } from '../../core/format'; import { RawAddress } from '../../core/format/RawAddress'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedTransferTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedTransferTransactionBuilder'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index ec2fe1630d..a6e52cc69c 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountLinkTransaction', () => { expect(accountLinkTransaction.linkAction).to.be.equal(1); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); - const signedTransaction = accountLinkTransaction.signWith(account, generationHash); + const signedTransaction = accountLinkTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 7fd1087647..e65f359a9c 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -162,7 +162,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = addressRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -213,7 +213,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -266,7 +266,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = operationRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index 59b1ce1144..1229abc20b 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('AddressAliasTransaction', () => { expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = addressAliasTransaction.signWith(account, generationHash); + const signedTransaction = addressAliasTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index 00afd72d47..4943e33e1f 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -110,7 +110,7 @@ describe('ModifyMultisigAccountTransaction', () => { expect(modifyMultisigAccountTransaction.modifications[1].cosignatoryPublicAccount.publicKey) .to.be.equal('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); - const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); + const signedTransaction = modifyMultisigAccountTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index 34184eff95..e2b8fffd90 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('MosaicAliasTransaction', () => { expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); expect(mosaicAliasTransaction.mosaicId.id.higher).to.be.equal(3405110546); - const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); + const signedTransaction = mosaicAliasTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index f444278cbe..52481c3ee8 100644 --- a/test/model/transaction/MosaicDefinitionTransaction.spec.ts +++ b/test/model/transaction/MosaicDefinitionTransaction.spec.ts @@ -93,7 +93,7 @@ describe('MosaicDefinitionTransaction', () => { expect(mosaicDefinitionTransaction.mosaicProperties.transferable).to.be.equal(true); expect(mosaicDefinitionTransaction.mosaicProperties.restrictable).to.be.equal(true); - const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicDefinitionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index d0baad099a..7488e3ca3d 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -241,4 +241,8 @@ class FakeTransaction extends Transaction { protected generateEmbeddedBytes(): Uint8Array { throw new Error('Not implemented'); } + + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } From 970b7c251be930836418df613b601add416676a0 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 23:43:48 +0100 Subject: [PATCH 70/98] Added embedded transaction builders --- .../AccountAddressRestrictionTransaction.ts | 23 +++++++++++++ .../AccountOperationRestrictionTransaction.ts | 7 ---- .../transaction/AddressAliasTransaction.ts | 1 - src/model/transaction/AggregateTransaction.ts | 8 +++++ .../ModifyMultisigAccountTransaction.ts | 1 + .../MosaicDefinitionTransaction.ts | 34 ++++++++++++------- src/model/transaction/TransferTransaction.ts | 20 +++++++++++ ...osaicAddressRestrictionTransaction.spec.ts | 2 +- ...MosaicGlobalRestrictionTransaction.spec.ts | 2 +- .../RegisterNamespaceTransaction.spec.ts | 4 +-- test/model/transaction/Transaction.spec.ts | 4 +++ 11 files changed, 81 insertions(+), 25 deletions(-) diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index 243b4ff560..de89c65970 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -20,6 +20,7 @@ import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTra import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -144,4 +145,26 @@ export class AccountAddressRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountAddressRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountAddressRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedAddressDto(RawAddress.stringToAddress(modification.value)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index 5824846b29..df82913d22 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -32,13 +32,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; -import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; -import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; -import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; -import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; export class AccountOperationRestrictionTransaction extends Transaction { diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index df00bd57bb..1ad4e6b61f 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -35,7 +35,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { RawAddress } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 01039aa405..fa3da79a06 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -272,4 +272,12 @@ export class AggregateTransaction extends Transaction { protected generateEmbeddedBytes(): Uint8Array { throw new Error('Method not implemented'); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index 6fb31645ba..c4e78b7f8e 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -31,6 +31,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; /** * Modify multisig account transactions are part of the NEM's multisig account system. diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index e798b92770..80b500c37c 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -37,19 +37,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; -import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; -import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; -import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; -import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; -import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; -import { MosaicFlagsDto } from '../../infrastructure/catbuffer/MosaicFlagsDto'; -import { MosaicFlags } from '../mosaic/MosaicFlag'; -import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; -import { Convert } from '../../core/format'; -import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; /** * Before a mosaic can be created or transferred, a corresponding definition of the mosaic has to be created and published to the network. @@ -212,4 +199,25 @@ export class MosaicDefinitionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicDefinitionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_DEFINITION.valueOf(), + new MosaicNonceDto(this.getMosaicNonceIntValue()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + this.getMosaicFlagValue(), + this.mosaicProperties.divisibility, + new BlockDurationDto(this.mosaicProperties.duration ? + this.mosaicProperties.duration.toDTO() : []), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 38a2d02c0b..7f567814d7 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -223,4 +223,24 @@ export class TransferTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const transactionBuilder = new EmbeddedTransferTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.TRANSFER.valueOf(), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), + this.getMessageBuffer(), + this.sortMosaics().map((mosaic) => { + return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), + new AmountDto(mosaic.amount.toDTO())); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts index 947904ce56..02aad2fc65 100644 --- a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts @@ -47,7 +47,7 @@ describe('MosaicAddressRestrictionTransaction', () => { expect(mosaicAddressRestrictionTransaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(8).toHex()); expect(mosaicAddressRestrictionTransaction.targetAddress.plain()).to.be.equal(account.address.plain()); - const signedTransaction = mosaicAddressRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicAddressRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts index 39c409bd22..9e436d2fea 100644 --- a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts @@ -54,7 +54,7 @@ describe('MosaicGlobalRestrictionTransaction', () => { expect(mosaicGlobalRestrictionTransaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.EQ); expect(mosaicGlobalRestrictionTransaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); - const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicGlobalRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/RegisterNamespaceTransaction.spec.ts b/test/model/transaction/RegisterNamespaceTransaction.spec.ts index dcd12d95f7..db497c73b9 100644 --- a/test/model/transaction/RegisterNamespaceTransaction.spec.ts +++ b/test/model/transaction/RegisterNamespaceTransaction.spec.ts @@ -66,7 +66,7 @@ describe('RegisterNamespaceTransaction', () => { expect(registerNamespaceTransaction.duration!.lower).to.be.equal(1000); expect(registerNamespaceTransaction.duration!.higher).to.be.equal(0); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -83,7 +83,7 @@ describe('RegisterNamespaceTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index 7488e3ca3d..cec65bb6e0 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -245,4 +245,8 @@ class FakeTransaction extends Transaction { protected generateBytes(): Uint8Array { throw new Error('Not implemented'); } + + protected generateEmbeddedBytes(): Uint8Array { + throw new Error('Not implemented'); + } } From 6e987f2104557d3b6655dc72820f0a3b3f03f00f Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 08:26:17 +0100 Subject: [PATCH 71/98] Applied catbuffer on aggregate transaction --- .../transaction/AccountAddressRestrictionTransaction.ts | 6 ++---- src/model/transaction/AggregateTransaction.ts | 8 -------- src/model/transaction/MosaicDefinitionTransaction.ts | 4 +--- src/model/transaction/MosaicSupplyChangeTransaction.ts | 1 + src/model/transaction/TransferTransaction.ts | 3 +-- test/model/transaction/AggregateTransaction.spec.ts | 2 +- 6 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index de89c65970..fd4200205c 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RawAddress } from '../../core/format'; +import { Convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; @@ -151,10 +151,8 @@ export class AccountAddressRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountAddressRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), this.restrictionType.valueOf(), diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index fa3da79a06..01039aa405 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -272,12 +272,4 @@ export class AggregateTransaction extends Transaction { protected generateEmbeddedBytes(): Uint8Array { throw new Error('Method not implemented'); } - - /** - * @internal - * @returns {Uint8Array} - */ - protected generateEmbeddedBytes(): Uint8Array { - throw new Error('Not implemented'); - } } diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 80b500c37c..03715779ea 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -205,10 +205,8 @@ export class MosaicDefinitionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicDefinitionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_DEFINITION.valueOf(), new MosaicNonceDto(this.getMosaicNonceIntValue()), diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index 03f0137241..09af28af07 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -32,6 +32,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { Convert } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 7f567814d7..875dcd9119 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -229,9 +229,8 @@ export class TransferTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); const transactionBuilder = new EmbeddedTransferTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.TRANSFER.valueOf(), new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 8bf2bfb730..2a3c153973 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -106,7 +106,7 @@ describe('AggregateTransaction', () => { NetworkType.MIJIN_TEST, []); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); + const signedTransaction = aggregateTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); From 17d92f96b1544c2c410b750cc5d99c4f3e83431d Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 11:46:27 +0100 Subject: [PATCH 72/98] Removed old flatbuffer staffs --- e2e/conf/network.conf | 2 +- .../AccountAddressRestrictionTransaction.ts | 17 ------ src/model/transaction/AggregateTransaction.ts | 11 ---- .../ModifyMultisigAccountTransaction.ts | 1 - .../MosaicDefinitionTransaction.ts | 19 ------- .../MosaicSupplyChangeTransaction.ts | 1 - src/model/transaction/Transaction.ts | 56 +------------------ src/model/transaction/TransferTransaction.ts | 19 ------- .../AccountLinkTransaction.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 6 +- .../AddressAliasTransaction.spec.ts | 2 +- .../transaction/AggregateTransaction.spec.ts | 2 +- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- ...osaicAddressRestrictionTransaction.spec.ts | 2 +- .../MosaicAliasTransaction.spec.ts | 2 +- .../MosaicDefinitionTransaction.spec.ts | 2 +- ...MosaicGlobalRestrictionTransaction.spec.ts | 2 +- .../RegisterNamespaceTransaction.spec.ts | 4 +- test/model/transaction/Transaction.spec.ts | 8 --- 19 files changed, 16 insertions(+), 144 deletions(-) diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index 150443d82d..a19e2213f0 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -51,4 +51,4 @@ "publicKey": "FAEDB16763F22870B75BF934EA5F2792BDF109EC0C504718DDCBD92DF13C2628", "address": "SCNPFCWFV2FYQVMU5HMJJTMADRZ3LRXVA76F56N2" } -} \ No newline at end of file +} diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index fd4200205c..150cd213b6 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -15,13 +15,10 @@ */ import { Convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; @@ -106,20 +103,6 @@ export class AccountAddressRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRestrictionType(this.restrictionType) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 01039aa405..608559f663 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -122,17 +122,6 @@ export class AggregateTransaction extends Transaction { ); } - /** - * @description add inner transactions to current list - * @param {InnerTransaction[]} transaction - * @returns {AggregateTransaction} - * @memberof AggregateTransaction - */ - public addTransactions(transactions: InnerTransaction[]): AggregateTransaction { - const innerTransactions = this.innerTransactions.concat(transactions); - return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {innerTransactions}); - } - /** * @internal * Sign transaction with cosignatories creating a new SignedTransaction diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index c4e78b7f8e..6fb31645ba 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -31,7 +31,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; /** * Modify multisig account transactions are part of the NEM's multisig account system. diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 03715779ea..9ebbf03fe6 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -199,23 +199,4 @@ export class MosaicDefinitionTransaction extends Transaction { ); return transactionBuilder.serialize(); } - - /** - * @internal - * @returns {Uint8Array} - */ - protected generateEmbeddedBytes(): Uint8Array { - const transactionBuilder = new EmbeddedMosaicDefinitionTransactionBuilder( - new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), - this.versionToDTO(), - TransactionType.MOSAIC_DEFINITION.valueOf(), - new MosaicNonceDto(this.getMosaicNonceIntValue()), - new MosaicIdDto(this.mosaicId.id.toDTO()), - this.getMosaicFlagValue(), - this.mosaicProperties.divisibility, - new BlockDurationDto(this.mosaicProperties.duration ? - this.mosaicProperties.duration.toDTO() : []), - ); - return transactionBuilder.serialize(); - } } diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index 09af28af07..03f0137241 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -32,7 +32,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { Convert } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index a713dc581a..29d3ae1b3d 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -142,60 +142,8 @@ export abstract class Transaction { } /** - * @internal - * Serialize and sign transaction creating a new SignedTransaction - * @param account - The account to sign the transaction - * @param generationHash - Network generation hash hex - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {SignedTransaction} - */ - public signWithCatbuffer(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { - const generationHashBytes = Array.from(Convert.hexToUint8(generationHash)); - const byteBuffer = Array.from(this.generateBytes()); - const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); - const keyPairEncoded = KeyPair.createKeyPairFromPrivateKeyString(account.privateKey, signSchema); - const signature = Array.from(KeyPair.sign(account, new Uint8Array(signingBytes), signSchema)); - const signedTransactionBuffer = byteBuffer - .splice(0, 4) - .concat(signature) - .concat(Array.from(keyPairEncoded.publicKey)) - .concat(byteBuffer - .splice(64 + 32, byteBuffer.length)); - const payload = Convert.uint8ToHex(signedTransactionBuffer); - return new SignedTransaction( - payload, - this.createTransactionHash(payload, generationHashBytes), - account.publicKey, - this.type, - this.networkType); - } - - /** - * Generate transaction hash hex - * @param {string} transactionPayload HexString Payload - * @param {Array} generationHashBuffer Network generation hash byte - * @returns {string} Returns Transaction Payload hash - */ - public createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { - const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); - const signingBytes = byteBuffer - .slice(4, 36) - .concat(byteBuffer - .slice(4 + 64, 4 + 64 + 32)) - .concat(generationHashBuffer) - .concat(byteBuffer - .splice(4 + 64 + 32, byteBuffer.length)); - - const hash = new Uint8Array(32); - - SHA3Hasher.func(hash, signingBytes, 32); - - return Convert.uint8ToHex(hash); - } - - /** - * @internal - * @returns {Array} + * Converts the transaction into AggregateTransaction compatible + * @returns {Array.<*>} AggregateTransaction bytes */ public aggregateTransaction(): number[] { const signer = Convert.hexToUint8(this.signer!.publicKey); diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 875dcd9119..38a2d02c0b 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -223,23 +223,4 @@ export class TransferTransaction extends Transaction { ); return transactionBuilder.serialize(); } - - /** - * @internal - * @returns {Uint8Array} - */ - protected generateEmbeddedBytes(): Uint8Array { - const transactionBuilder = new EmbeddedTransferTransactionBuilder( - new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), - this.versionToDTO(), - TransactionType.TRANSFER.valueOf(), - new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), - this.getMessageBuffer(), - this.sortMosaics().map((mosaic) => { - return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), - new AmountDto(mosaic.amount.toDTO())); - }), - ); - return transactionBuilder.serialize(); - } } diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index a6e52cc69c..ec2fe1630d 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountLinkTransaction', () => { expect(accountLinkTransaction.linkAction).to.be.equal(1); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); - const signedTransaction = accountLinkTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = accountLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index e65f359a9c..7fd1087647 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -162,7 +162,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = addressRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -213,7 +213,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = mosaicRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -266,7 +266,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = operationRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index 1229abc20b..59b1ce1144 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('AddressAliasTransaction', () => { expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = addressAliasTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = addressAliasTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 2a3c153973..8bf2bfb730 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -106,7 +106,7 @@ describe('AggregateTransaction', () => { NetworkType.MIJIN_TEST, []); - const signedTransaction = aggregateTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index 4943e33e1f..00afd72d47 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -110,7 +110,7 @@ describe('ModifyMultisigAccountTransaction', () => { expect(modifyMultisigAccountTransaction.modifications[1].cosignatoryPublicAccount.publicKey) .to.be.equal('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); - const signedTransaction = modifyMultisigAccountTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts index 02aad2fc65..947904ce56 100644 --- a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts @@ -47,7 +47,7 @@ describe('MosaicAddressRestrictionTransaction', () => { expect(mosaicAddressRestrictionTransaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(8).toHex()); expect(mosaicAddressRestrictionTransaction.targetAddress.plain()).to.be.equal(account.address.plain()); - const signedTransaction = mosaicAddressRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicAddressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index e2b8fffd90..34184eff95 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('MosaicAliasTransaction', () => { expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); expect(mosaicAliasTransaction.mosaicId.id.higher).to.be.equal(3405110546); - const signedTransaction = mosaicAliasTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index 52481c3ee8..f444278cbe 100644 --- a/test/model/transaction/MosaicDefinitionTransaction.spec.ts +++ b/test/model/transaction/MosaicDefinitionTransaction.spec.ts @@ -93,7 +93,7 @@ describe('MosaicDefinitionTransaction', () => { expect(mosaicDefinitionTransaction.mosaicProperties.transferable).to.be.equal(true); expect(mosaicDefinitionTransaction.mosaicProperties.restrictable).to.be.equal(true); - const signedTransaction = mosaicDefinitionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts index 9e436d2fea..39c409bd22 100644 --- a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts @@ -54,7 +54,7 @@ describe('MosaicGlobalRestrictionTransaction', () => { expect(mosaicGlobalRestrictionTransaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.EQ); expect(mosaicGlobalRestrictionTransaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); - const signedTransaction = mosaicGlobalRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/RegisterNamespaceTransaction.spec.ts b/test/model/transaction/RegisterNamespaceTransaction.spec.ts index db497c73b9..dcd12d95f7 100644 --- a/test/model/transaction/RegisterNamespaceTransaction.spec.ts +++ b/test/model/transaction/RegisterNamespaceTransaction.spec.ts @@ -66,7 +66,7 @@ describe('RegisterNamespaceTransaction', () => { expect(registerNamespaceTransaction.duration!.lower).to.be.equal(1000); expect(registerNamespaceTransaction.duration!.higher).to.be.equal(0); - const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -83,7 +83,7 @@ describe('RegisterNamespaceTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index cec65bb6e0..d0baad099a 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -241,12 +241,4 @@ class FakeTransaction extends Transaction { protected generateEmbeddedBytes(): Uint8Array { throw new Error('Not implemented'); } - - protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); - } - - protected generateEmbeddedBytes(): Uint8Array { - throw new Error('Not implemented'); - } } From 7e7f79981ce2cc2b3fbf0f433372a65756edf188 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 12:16:52 +0100 Subject: [PATCH 73/98] restored network config for e2e --- e2e/conf/network.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index a19e2213f0..150443d82d 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -51,4 +51,4 @@ "publicKey": "FAEDB16763F22870B75BF934EA5F2792BDF109EC0C504718DDCBD92DF13C2628", "address": "SCNPFCWFV2FYQVMU5HMJJTMADRZ3LRXVA76F56N2" } -} +} \ No newline at end of file From 89de0efcf61d55e87a7b83b5b60b1203232ed1ae Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 14 Aug 2019 12:02:30 +0100 Subject: [PATCH 74/98] Fixed merged conflic issues --- src/model/namespace/AliasAction.ts | 2 +- src/model/transaction/AddressAliasTransaction.ts | 4 ++-- src/model/transaction/ModifyMultisigAccountTransaction.ts | 4 ++-- src/model/transaction/MosaicAliasTransaction.ts | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/model/namespace/AliasAction.ts b/src/model/namespace/AliasAction.ts index b107b0d65d..7d81578751 100644 --- a/src/model/namespace/AliasAction.ts +++ b/src/model/namespace/AliasAction.ts @@ -19,7 +19,7 @@ * 0: Link an alias. * 1: Unlink an alias. */ -export enum AliasActionType { +export enum AliasAction { Link = 0x01, Unlink = 0x00, } diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 1ad4e6b61f..1faaeaa7dc 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -134,7 +134,7 @@ export class AddressAliasTransaction extends Transaction { TransactionType.ADDRESS_ALIAS.valueOf(), new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), - this.actionType.valueOf(), + this.aliasAction.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), new AddressDto(RawAddress.stringToAddress(this.address.plain())), ); @@ -150,7 +150,7 @@ export class AddressAliasTransaction extends Transaction { new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ADDRESS_ALIAS.valueOf(), - this.actionType.valueOf(), + this.aliasAction.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), new AddressDto(RawAddress.stringToAddress(this.address.plain())), ); diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index 6fb31645ba..835b117f13 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -142,7 +142,7 @@ export class ModifyMultisigAccountTransaction extends Transaction { this.minApprovalDelta, this.modifications.map((modification) => { return new CosignatoryModificationBuilder( - modification.type.valueOf(), + modification.modificiationType.valueOf(), new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)), ); }), @@ -163,7 +163,7 @@ export class ModifyMultisigAccountTransaction extends Transaction { this.minApprovalDelta, this.modifications.map((modification) => { return new CosignatoryModificationBuilder( - modification.type.valueOf(), + modification.modificiationType.valueOf(), new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)), ); }), diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index acffa89de0..447d5530ad 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -130,7 +130,7 @@ export class MosaicAliasTransaction extends Transaction { TransactionType.MOSAIC_ALIAS.valueOf(), new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), - this.actionType.valueOf(), + this.aliasAction.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), new MosaicIdDto(this.mosaicId.id.toDTO()), ); @@ -146,7 +146,7 @@ export class MosaicAliasTransaction extends Transaction { new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_ALIAS.valueOf(), - this.actionType.valueOf(), + this.aliasAction.valueOf(), new NamespaceIdDto(this.namespaceId.id.toDTO()), new MosaicIdDto(this.mosaicId.id.toDTO()), ); From aa2be1b98cbb8718b9bc738f0438f0f7ae64bebf Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 15 Aug 2019 12:12:33 +0100 Subject: [PATCH 75/98] Refactored TransactionMapping - createTransactionFromPayload now use catbuffer --- src/core/format/Convert.ts | 18 + src/core/utils/TransactionMapping.ts | 14 +- .../catbuffer/GeneratorUtils.ts | 172 +++--- .../CreateTransactionFromPayload.ts | 498 ++---------------- .../AccountAddressRestrictionTransaction.ts | 35 +- .../transaction/AccountLinkTransaction.ts | 26 + .../AccountMosaicRestrictionTransaction.ts | 33 ++ .../AccountOperationRestrictionTransaction.ts | 32 ++ .../transaction/AddressAliasTransaction.ts | 29 +- src/model/transaction/AggregateTransaction.ts | 60 ++- src/model/transaction/LockFundsTransaction.ts | 32 ++ .../ModifyMultisigAccountTransaction.ts | 36 ++ .../MosaicAddressRestrictionTransaction.ts | 30 ++ .../transaction/MosaicAliasTransaction.ts | 27 + .../MosaicDefinitionTransaction.ts | 34 ++ .../MosaicGlobalRestrictionTransaction.ts | 32 ++ .../MosaicSupplyChangeTransaction.ts | 28 + .../RegisterNamespaceTransaction.ts | 36 ++ .../transaction/SecretLockTransaction.ts | 36 +- .../transaction/SecretProofTransaction.ts | 29 + src/model/transaction/TransferTransaction.ts | 40 ++ 21 files changed, 714 insertions(+), 563 deletions(-) diff --git a/src/core/format/Convert.ts b/src/core/format/Convert.ts index f45b7b9eac..7d9939d084 100644 --- a/src/core/format/Convert.ts +++ b/src/core/format/Convert.ts @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { decode } from 'utf8'; import * as utilities from './Utilities'; export class Convert { @@ -172,4 +173,21 @@ export class Convert { } return result; } + + /** + * @internal decode hex to uft8 string + * @param hex - Hex input + * @returns {string} + */ + public static decodeHex = (hex: string): string => { + let str = ''; + for (let i = 0; i < hex.length; i += 2) { + str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); + } + try { + return decode(str); + } catch (e) { + return str; + } + } } diff --git a/src/core/utils/TransactionMapping.ts b/src/core/utils/TransactionMapping.ts index 7c13ae044f..7c4c36a0e4 100644 --- a/src/core/utils/TransactionMapping.ts +++ b/src/core/utils/TransactionMapping.ts @@ -16,7 +16,9 @@ import { CreateTransactionFromDTO } from '../../infrastructure/transaction/CreateTransactionFromDTO'; import { CreateTransactionFromPayload } from '../../infrastructure/transaction/CreateTransactionFromPayload'; +import { InnerTransaction } from '../../model/transaction/InnerTransaction'; import { Transaction } from '../../model/transaction/Transaction'; +import { SignSchema } from '../crypto/SignSchema'; export class TransactionMapping { @@ -31,10 +33,14 @@ export class TransactionMapping { /** * Create transaction class from payload binary. - * @param {string} dataBytes The transaction json object. - * @returns {module: model/transaction/transaction} The transaction class. + * @param {string} payload The transaction binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} The transaction class. */ - public static createFromPayload(dataBytes: string): Transaction { - return CreateTransactionFromPayload(dataBytes); + public static createFromPayload(payload: string, + isEmbedded = false, + signSchema = SignSchema.SHA3): Transaction | InnerTransaction { + return CreateTransactionFromPayload(payload, isEmbedded, signSchema); } } diff --git a/src/infrastructure/catbuffer/GeneratorUtils.ts b/src/infrastructure/catbuffer/GeneratorUtils.ts index 437c32d117..7e95285569 100644 --- a/src/infrastructure/catbuffer/GeneratorUtils.ts +++ b/src/infrastructure/catbuffer/GeneratorUtils.ts @@ -1,119 +1,117 @@ // tslint:disable: jsdoc-format /** -*** Copyright (c) 2016-present, -*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. -*** -*** This file is part of Catapult. -*** -*** Catapult is free software: you can redistribute it and/or modify -*** it under the terms of the GNU Lesser General Public License as published by -*** the Free Software Foundation, either version 3 of the License, or -*** (at your option) any later version. -*** -*** Catapult is distributed in the hope that it will be useful, -*** but WITHOUT ANY WARRANTY; without even the implied warranty of -*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -*** GNU Lesser General Public License for more details. -*** -*** You should have received a copy of the GNU Lesser General Public License -*** along with Catapult. If not, see . -**/ + *** Copyright (c) 2016-present, + *** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. + *** + *** This file is part of Catapult. + *** + *** Catapult is free software: you can redistribute it and/or modify + *** it under the terms of the GNU Lesser General Public License as published by + *** the Free Software Foundation, either version 3 of the License, or + *** (at your option) any later version. + *** + *** Catapult is distributed in the hope that it will be useful, + *** but WITHOUT ANY WARRANTY; without even the implied warranty of + *** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *** GNU Lesser General Public License for more details. + *** + *** You should have received a copy of the GNU Lesser General Public License + *** along with Catapult. If not, see . + **/ /** * Generator utility class. */ export class GeneratorUtils { - /** + /** * Converts a (64bit) uint8 array into a number array. * @param {Uint8Array} input A uint8 array. * @returns {number[]} The uint64 representation of the input. */ - public static bufferToUint64 (input: Uint8Array): number[] { + public static bufferToUint64(input: Uint8Array): number[] { if (8 !== input.length) { throw Error(`byte array has unexpected size '${input.length}'`); - } - input = input.reverse(); - return [GeneratorUtils.readUint32At(input, 0), GeneratorUtils.readUint32At(input, 4)]; - } - - /** + } + input = input.reverse(); + const view = new DataView(input.buffer); + return [view.getUint32(4), view.getUint32(0)]; + } + + /** * Read buffer into 32bits integer at given index. * @param {Uint8Array} bytes A uint8 array. - * @param {number} index Index. + * @param {number} index Index. * @returns {number} 32bits integer. */ - public static readUint32At(bytes: Uint8Array, index: number): number { - return (bytes[index] + (bytes[index + 1] << 8) + (bytes[index + 2] << 16) + (bytes[index + 3] << 24)) >>> 0; - } + public static readUint32At(bytes: Uint8Array, index: number): number { + return (bytes[index] + (bytes[index + 1] << 8) + (bytes[index + 2] << 16) + (bytes[index + 3] << 24)) >>> 0; + } - /** + /** * Write uint to buffer * @param {number} uintValue A uint8 array. - * @param {number} bufferSize Buffer size. + * @param {number} bufferSize Buffer size. * @returns {Uint8Array} */ - public static uintToBuffer (uintValue: number, bufferSize: number): Uint8Array { - const buffer = new ArrayBuffer(bufferSize); - const dataView = new DataView(buffer); - if (1 === bufferSize) - dataView.setUint8(0, uintValue); - - else if (2 === bufferSize) - dataView.setUint16(0, uintValue, true); - - else if (4 === bufferSize) - dataView.setUint32(0, uintValue, true); - - else - throw new Error('Unexpected bufferSize'); - - return new Uint8Array(buffer); - } + public static uintToBuffer(uintValue: number, bufferSize: number): Uint8Array { + const buffer = new ArrayBuffer(bufferSize); + const dataView = new DataView(buffer); + if (1 === bufferSize) { + dataView.setUint8(0, uintValue); + } else if (2 === bufferSize) { + dataView.setUint16(0, uintValue, true); + } else if (4 === bufferSize) { + dataView.setUint32(0, uintValue, true); + } else { + throw new Error('Unexpected bufferSize'); + } + + return new Uint8Array(buffer); + } - /** + /** * Write uint to buffer * @param {Uint8Array} buffer A uint8 array. * @returns {number} */ - public static bufferToUint(buffer: Uint8Array): number { - const dataView = new DataView(buffer.buffer); - if (1 === buffer.byteLength) - return dataView.getUint8(0); - - else if (2 === buffer.byteLength) - return dataView.getUint16(0, true); - - else if (4 === buffer.byteLength) - return dataView.getUint32(0, true); - - throw new Error('Unexpected buffer size'); - }; + public static bufferToUint(buffer: Uint8Array): number { + const dataView = new DataView(buffer.buffer); + if (1 === buffer.byteLength) { + return dataView.getUint8(0); + } else if (2 === buffer.byteLength) { + return dataView.getUint16(0, true); + } else if (4 === buffer.byteLength) { + return dataView.getUint32(0, true); + } - /** + throw new Error('Unexpected buffer size'); + } + + /** * Write Uint64 to buffer * @param {number} uintValue Uint64 (number[]). * @returns {Uint8Array} */ - public static uint64ToBuffer(uintValue: number[]): Uint8Array { - const uint32Array = new Uint32Array(uintValue); - return new Uint8Array(uint32Array.buffer); - } + public static uint64ToBuffer(uintValue: number[]): Uint8Array { + const uint32Array = new Uint32Array(uintValue); + return new Uint8Array(uint32Array.buffer); + } - /** + /** * Concatenate two arrays * @param {Uint8Array} array1 A Uint8Array. - * @param {Uint8Array} array2 A Uint8Array. + * @param {Uint8Array} array2 A Uint8Array. * @returns {Uint8Array} */ - public static concatTypedArrays(array1: Uint8Array, array2: Uint8Array): Uint8Array { - const newArray = new Uint8Array(array1.length + array2.length); - newArray.set(array1); - newArray.set(array2, array1.length); - return newArray; - } + public static concatTypedArrays(array1: Uint8Array, array2: Uint8Array): Uint8Array { + const newArray = new Uint8Array(array1.length + array2.length); + newArray.set(array1); + newArray.set(array2, array1.length); + return newArray; + } - /** Converts an unsigned byte to a signed byte with the same binary representation. + /** Converts an unsigned byte to a signed byte with the same binary representation. * @param {number} input An unsigned byte. * @returns {number} A signed byte with the same binary representation as the input. * @@ -125,17 +123,17 @@ export class GeneratorUtils { return input << 24 >> 24; } - /** Get bytes by given sub array size. - * @param {Uint8Array} binary Binary bytes array. + /** Get bytes by given sub array size. + * @param {Uint8Array} binary Binary bytes array. * @param {number} size Subarray size. - * @returns {Uint8Array} + * @returns {Uint8Array} * */ - public static getBytes(binary: Uint8Array, size: number): Uint8Array { - if (size > binary.length) - throw new RangeError(); - - const bytes = binary.slice(0, size); - return bytes; - } + public static getBytes(binary: Uint8Array, size: number): Uint8Array { + if (size > binary.length) { + throw new RangeError(); + } + const bytes = binary.slice(0, size); + return bytes; + } } diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index 6491749d4c..3f79ea2d5e 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -14,524 +14,88 @@ * limitations under the License. */ -import {decode} from 'utf8'; +import { SignSchema } from '../../core/crypto'; import { Convert as convert } from '../../core/format'; -import { Address } from '../../model/account/Address'; -import { PublicAccount } from '../../model/account/PublicAccount'; -import { NetworkType } from '../../model/blockchain/NetworkType'; -import { Mosaic } from '../../model/mosaic/Mosaic'; -import { MosaicId } from '../../model/mosaic/MosaicId'; -import { MosaicNonce } from '../../model/mosaic/MosaicNonce'; -import { MosaicProperties } from '../../model/mosaic/MosaicProperties'; -import { NamespaceId } from '../../model/namespace/NamespaceId'; -import { NamespaceType } from '../../model/namespace/NamespaceType'; +import { InnerTransaction } from '../../model/model'; import { AccountAddressRestrictionTransaction } from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; import { AccountMosaicRestrictionTransaction } from '../../model/transaction/AccountMosaicRestrictionTransaction'; import { AccountOperationRestrictionTransaction } from '../../model/transaction/AccountOperationRestrictionTransaction'; -import { AccountRestrictionModification } from '../../model/transaction/AccountRestrictionModification'; import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction'; import { AggregateTransaction } from '../../model/transaction/AggregateTransaction'; -import { AggregateTransactionCosignature } from '../../model/transaction/AggregateTransactionCosignature'; -import { Deadline } from '../../model/transaction/Deadline'; -import { EncryptedMessage } from '../../model/transaction/EncryptedMessage'; -import { HashType } from '../../model/transaction/HashType'; import { LockFundsTransaction } from '../../model/transaction/LockFundsTransaction'; -import { Message } from '../../model/transaction/Message'; -import { MessageType } from '../../model/transaction/MessageType'; import { ModifyMultisigAccountTransaction } from '../../model/transaction/ModifyMultisigAccountTransaction'; import { MosaicAddressRestrictionTransaction } from '../../model/transaction/MosaicAddressRestrictionTransaction'; import { MosaicAliasTransaction } from '../../model/transaction/MosaicAliasTransaction'; import { MosaicDefinitionTransaction } from '../../model/transaction/MosaicDefinitionTransaction'; import { MosaicGlobalRestrictionTransaction } from '../../model/transaction/MosaicGlobalRestrictionTransaction'; import { MosaicSupplyChangeTransaction } from '../../model/transaction/MosaicSupplyChangeTransaction'; -import { MultisigCosignatoryModification } from '../../model/transaction/MultisigCosignatoryModification'; -import { PlainMessage } from '../../model/transaction/PlainMessage'; import { RegisterNamespaceTransaction } from '../../model/transaction/RegisterNamespaceTransaction'; import { SecretLockTransaction } from '../../model/transaction/SecretLockTransaction'; import { SecretProofTransaction } from '../../model/transaction/SecretProofTransaction'; -import { SignedTransaction } from '../../model/transaction/SignedTransaction'; import { Transaction } from '../../model/transaction/Transaction'; import { TransactionType } from '../../model/transaction/TransactionType'; import { TransferTransaction } from '../../model/transaction/TransferTransaction'; -import { UInt64 } from '../../model/UInt64'; +import { EmbeddedTransactionBuilder } from '../catbuffer/EmbeddedTransactionBuilder'; +import { TransactionBuilder } from '../catbuffer/TransactionBuilder'; /** * @internal - * @param transactionBinary - The transaction binary data - * @returns {Transaction} + * @param payload - The transaction binary data + * @param isEmbedded - Is the transaction an embedded inner transaction + * @param signSchema - The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} * @constructor */ -export const CreateTransactionFromPayload = (transactionBinary: string): Transaction => { - // Transaction byte size data - const sizeLength = 8; - const signatureLength = 128; - const publicKeyLength = 64; - const versionLength = 4; - const typeLength = 4; - const feeLength = 16; - const deadlineLength = 16; - - // Transaction byte data positions - const signatureOffset = sizeLength; - const publicKeyOffset = signatureOffset + signatureLength; - const versionOffset = publicKeyOffset + publicKeyLength; - const typeOffset = versionOffset + versionLength; - const feeOffset = typeOffset + typeLength; - const deadlineOffset = feeOffset + feeLength; - const transactionOffset = deadlineOffset + deadlineLength; - - // Transaction byte data - const networkType = extractNetwork(transactionBinary.substring(versionOffset, typeOffset)); - const type = extractTransactionTypeFromHex(transactionBinary.substring(typeOffset, feeOffset)); - const deadline = UInt64.fromHex(reverse(transactionBinary.substring(deadlineOffset, transactionOffset))).toDTO(); - const transactionData = transactionBinary.substring(transactionOffset); - - return CreateTransaction(type, transactionData, networkType, deadline); -}; - -/** - * @internal - * @param type - Transaction type - * @param transactionData - Details per specific transaction type - * @param networkType - Network type - * @param deadline - Deadline - * @returns {Transaction} - */ -const CreateTransaction = (type: number, transactionData: string, networkType: NetworkType, deadline: number[]): Transaction => { +export const CreateTransactionFromPayload = (payload: string, + isEmbedded = false, + signSchema = SignSchema.SHA3): Transaction | InnerTransaction => { + const transactionBuilder = isEmbedded ? EmbeddedTransactionBuilder.loadFromBinary(convert.hexToUint8(payload)) : + TransactionBuilder.loadFromBinary(convert.hexToUint8(payload)); + const type = transactionBuilder.getType().valueOf(); switch (type) { case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: case TransactionType.ACCOUNT_RESTRICTION_OPERATION: case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: - const propertyTypeLength = 2; - - const modificationCountOffset = propertyTypeLength; - const modificationArrayOffset = modificationCountOffset + propertyTypeLength; - - // read bytes - const propertyType = transactionData.substring(0, propertyTypeLength); - const modifications = transactionData.substring(modificationArrayOffset, transactionData.length); - const modificationArray = modifications.match(/.{1,52}/g); - switch (type) { case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: - const t = AccountAddressRestrictionTransaction.create( - Deadline.createFromDTO(deadline), - parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), - modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( - parseInt(convert.uint8ToHex(convert.hexToUint8(modification.substring(0, 2)).reverse()), 16), - Address.createFromEncoded(modification.substring(2, modification.length)).plain(), - )) : [], - networkType, - ); - return t; + return AccountAddressRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: - return AccountMosaicRestrictionTransaction.create( - Deadline.createFromDTO(deadline), - parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), - modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( - parseInt(convert.uint8ToHex(convert.hexToUint8(modification.substring(0, 2)).reverse()), 16), - UInt64.fromHex(reverse(modification.substring(2, modification.length))).toDTO(), - )) : [], - networkType, - ); + return AccountMosaicRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.ACCOUNT_RESTRICTION_OPERATION: - return AccountOperationRestrictionTransaction.create( - Deadline.createFromDTO(deadline), - parseInt(convert.uint8ToHex(convert.hexToUint8(propertyType).reverse()), 16), - modificationArray ? modificationArray.map((modification) => new AccountRestrictionModification( - parseInt(convert.uint8ToHex(convert.hexToUint8(modification.substring(0, 2)).reverse()), 16), - parseInt(convert.uint8ToHex(convert.hexToUint8( - modification.substring(2, modification.length)).reverse()), 16), - )) : [], - networkType, - ); + return AccountOperationRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); } throw new Error ('Account restriction transaction type not recognised.'); case TransactionType.LINK_ACCOUNT: - // read bytes - const remoteAccountKey = transactionData.substring(0, 64); - const linkAction = transactionData.substring(64, 66); - - return AccountLinkTransaction.create( - Deadline.createFromDTO(deadline), - remoteAccountKey, - parseInt(convert.uint8ToHex(convert.hexToUint8(linkAction).reverse()), 16), - networkType, - ); + return AccountLinkTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.ADDRESS_ALIAS: - // read bytes - const addressAliasAction = transactionData.substring(0, 2); - const addressAliasNamespaceId = transactionData.substring(2, 18); - const addressAliasAddress = transactionData.substring(18); - - return AddressAliasTransaction.create( - Deadline.createFromDTO(deadline), - parseInt(convert.uint8ToHex(convert.hexToUint8(addressAliasAction).reverse()), 16), - new NamespaceId(UInt64.fromHex(reverse(addressAliasNamespaceId)).toDTO()), - Address.createFromEncoded(addressAliasAddress), - networkType, - ); + return AddressAliasTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MOSAIC_ALIAS: - const mosaicAliasActionLength = 2; - - // read bytes - const mosaicAliasAction = transactionData.substring(0, mosaicAliasActionLength); - const mosaicAliasNamespaceId = transactionData.substring(mosaicAliasActionLength, 18); - const mosaicAliasMosaicId = transactionData.substring(18); - - return MosaicAliasTransaction.create( - Deadline.createFromDTO(deadline), - parseInt(convert.uint8ToHex(convert.hexToUint8(mosaicAliasAction).reverse()), 16), - new NamespaceId(UInt64.fromHex(reverse(mosaicAliasNamespaceId)).toDTO()), - new MosaicId(UInt64.fromHex(reverse(mosaicAliasMosaicId)).toDTO()), - networkType, - ); + return MosaicAliasTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MOSAIC_DEFINITION: - const mosaicDefMosaicNonceLength = 8; - const mosaicDefMosaicIdLength = 16; - const mosaicDefPropsFlagsLength = 2; - const mosaicDefDivisibilityLength = 2; - const mosaicDefDurationLength = 16; - - const mosaicIdOffset = mosaicDefMosaicNonceLength; - const flagsOffset = mosaicIdOffset + mosaicDefMosaicIdLength; - const divisibilityOffset = flagsOffset + mosaicDefPropsFlagsLength; - const durationOffset = divisibilityOffset + mosaicDefDivisibilityLength; - - // read bytes - const mosaicNonce = transactionData.substring(0, mosaicDefMosaicNonceLength); - const mosaicId = transactionData.substring(mosaicIdOffset, flagsOffset); - const flags = parseInt(convert.uint8ToHex(convert.hexToUint8( - transactionData.substring(flagsOffset, divisibilityOffset)).reverse()), 16); - const divisibility = transactionData.substring(divisibilityOffset, durationOffset); - const duration = transactionData.substring(durationOffset); - - const regexArray = mosaicNonce.match(/.{1,2}/g); - - const nonceArray = regexArray ? regexArray.map((n) => { - return parseInt(convert.uint8ToHex(convert.hexToUint8(n).reverse()), 16); - }) : []; - - return MosaicDefinitionTransaction.create( - Deadline.createFromDTO(deadline), - new MosaicNonce(new Uint8Array(nonceArray)), - new MosaicId(UInt64.fromHex(reverse(mosaicId)).toDTO()), - MosaicProperties.create({ - supplyMutable: (flags & 1) === 1, - transferable: (flags & 2) === 2, - divisibility: parseInt(convert.uint8ToHex(convert.hexToUint8(divisibility).reverse()), 16), - restrictable: (flags & 4) === 4, - duration: duration ? UInt64.fromHex(reverse(duration)) : undefined, - }), - networkType, - ); + return MosaicDefinitionTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MOSAIC_SUPPLY_CHANGE: - // read bytes - const mosaicSupMosaicId = transactionData.substring(0, 16); - const mosaicSupDirection = transactionData.substring(16, 18); - const delta = transactionData.substring(18, 34); - - return MosaicSupplyChangeTransaction.create( - Deadline.createFromDTO(deadline), - new MosaicId(UInt64.fromHex(reverse(mosaicSupMosaicId)).toDTO()), - parseInt(convert.uint8ToHex(convert.hexToUint8(mosaicSupDirection).reverse()), 16), - UInt64.fromHex(reverse(delta)), - networkType, - ); + return MosaicSupplyChangeTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.REGISTER_NAMESPACE: - // read bytes - const namespaceType = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(0, 2)).reverse()), 16); - const nameSpaceDurationParentId = transactionData.substring(2, 18); - const nameSpaceId = transactionData.substring(18, 34); - const nameSize = transactionData.substring(34, 36); - const nameSpaceName = transactionData.substring(36); - - return namespaceType === NamespaceType.RootNamespace ? - RegisterNamespaceTransaction.createRootNamespace( - Deadline.createFromDTO(deadline), - decodeHex(nameSpaceName), - UInt64.fromHex(reverse(nameSpaceDurationParentId)), - networkType, - ) : RegisterNamespaceTransaction.createSubNamespace( - Deadline.createFromDTO(deadline), - decodeHex(nameSpaceName), - new NamespaceId(UInt64.fromHex(reverse(nameSpaceDurationParentId)).toDTO()), - networkType, - ); + return RegisterNamespaceTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.TRANSFER: - // read bytes - const transferRecipient = transactionData.substring(0, 50); - const transferMessageSize = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(50, 54)).reverse()), 16); - - const transferMessageAndMosaicSubString = transactionData.substring(56); - const transferMessageType = parseInt(convert.uint8ToHex(convert.hexToUint8( - transferMessageAndMosaicSubString.substring(0, 2)).reverse()), 16); - const transferMessage = transferMessageAndMosaicSubString.substring(2, (transferMessageSize - 1) * 2 + 2); - const transferMosaic = transferMessageAndMosaicSubString.substring(transferMessageSize * 2); - const transferMosaicArray = transferMosaic.match(/.{1,32}/g); - - return TransferTransaction.create( - Deadline.createFromDTO(deadline), - Address.createFromEncoded(transferRecipient), - transferMosaicArray ? transferMosaicArray.map((mosaic) => new Mosaic( - new MosaicId(UInt64.fromHex(reverse(mosaic.substring(0, 16))).toDTO()), - UInt64.fromHex(reverse(mosaic.substring(16))), - )) : [], - extractMessage(transferMessageType, transferMessage), - networkType, - ); + return TransferTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.SECRET_LOCK: - // read bytes - const secretLockMosaic = transactionData.substring(0, 32); - const secretLockDuration = transactionData.substring(32, 48); - const secretLockHashAlgorithm = parseInt(convert.uint8ToHex(convert.hexToUint8( - transactionData.substring(48, 50)).reverse()), 16); - const secretLockSecret = transactionData.substring(50, transactionData.length - 50); - const secretLockRecipient = transactionData.substring(transactionData.length - 50); - - return SecretLockTransaction.create( - Deadline.createFromDTO(deadline), - new Mosaic( - new MosaicId(UInt64.fromHex(reverse(secretLockMosaic.substring(0, 16))).toDTO()), - UInt64.fromHex(reverse(secretLockMosaic.substring(16))), - ), - UInt64.fromHex(reverse(secretLockDuration)), - secretLockHashAlgorithm, - secretLockSecret, - Address.createFromEncoded(secretLockRecipient), - networkType, - ); + return SecretLockTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.SECRET_PROOF: - // read bytes - const secretProofHashAlgorithm = parseInt(convert.uint8ToHex(convert.hexToUint8( - transactionData.substring(0, 2)).reverse()), 16); - - const secretProofSecretLength = 64; - const secretProofSecret = transactionData.substring(2, 66); - const secretProofRecipient = transactionData.substring(66, 116); - const secretProofSize = transactionData.substring(116, 120); - const secretProofProof = transactionData.substring(120); - - return SecretProofTransaction.create( - Deadline.createFromDTO(deadline), - secretProofHashAlgorithm, - secretProofSecret, - Address.createFromEncoded(secretProofRecipient), - secretProofProof, - networkType, - ); + return SecretProofTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MODIFY_MULTISIG_ACCOUNT: - // read bytes - const minRemovalDelta = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(0, 2)).reverse()), 16); - const minApprovalDelta = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(2, 4)).reverse()), 16); - const modificationsCount = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(4, 6)).reverse()), 16); - - const multiSigModificationSubString = transactionData.substring(6); - const multiSigModificationArray = multiSigModificationSubString.match(/.{1,66}/g); - - return ModifyMultisigAccountTransaction.create( - Deadline.createFromDTO(deadline), - minApprovalDelta, - minRemovalDelta, - multiSigModificationArray ? multiSigModificationArray.map((modification) => new MultisigCosignatoryModification( - parseInt(convert.uint8ToHex(convert.hexToUint8(modification.substring(0, 2)).reverse()), 16), - PublicAccount.createFromPublicKey(modification.substring(2), networkType), - )) : [], - networkType, - ); + return ModifyMultisigAccountTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.LOCK: - // read bytes - const hashLockMosaic = transactionData.substring(0, 32); - const hashLockDuration = transactionData.substring(32, 48); - const hashLockHash = transactionData.substring(48); - - return LockFundsTransaction.create( - Deadline.createFromDTO(deadline), - new Mosaic( - new MosaicId(UInt64.fromHex(reverse(hashLockMosaic.substring(0, 16))).toDTO()), - UInt64.fromHex(reverse(hashLockMosaic.substring(16))), - ), - UInt64.fromHex(reverse(hashLockDuration)), - new SignedTransaction('', hashLockHash, '', TransactionType.AGGREGATE_BONDED, networkType), - networkType, - ); + return LockFundsTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MOSAIC_GLOBAL_RESTRICTION: - // read bytes - const globalRestrictionMosaicId = transactionData.substring(0, 16); - const globalRestrictionReferenceMosaicId = transactionData.substring(16, 32); - const globalRestrictionRestrictionKey = transactionData.substring(32, 48); - const globalRestrictionPrevValue = transactionData.substring(48, 64); - const globalRestrictionPrevType = transactionData.substring(64, 66); - const globalRestrictionNewValue = transactionData.substring(66, 82); - const globalRestrictionNewType = transactionData.substring(82, 84); - - return MosaicGlobalRestrictionTransaction.create( - Deadline.createFromDTO(deadline), - new MosaicId(UInt64.fromHex(reverse(globalRestrictionMosaicId)).toDTO()), - new MosaicId(UInt64.fromHex(reverse(globalRestrictionReferenceMosaicId)).toDTO()), - UInt64.fromHex(reverse(globalRestrictionRestrictionKey)), - UInt64.fromHex(reverse(globalRestrictionPrevValue)), - parseInt(convert.uint8ToHex(convert.hexToUint8(globalRestrictionPrevType).reverse()), 16), - UInt64.fromHex(reverse(globalRestrictionNewValue)), - parseInt(convert.uint8ToHex(convert.hexToUint8(globalRestrictionNewType).reverse()), 16), - networkType, - ); + return MosaicGlobalRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MOSAIC_ADDRESS_RESTRICTION: - // read bytes - const addressRestrictionMosaicId = transactionData.substring(0, 16); - const addressRestrictionRestrictionKey = transactionData.substring(16, 32); - const addressRestrictionTargetAddress = transactionData.substring(32, 82); - const addressRestrictionPrevValue = transactionData.substring(82, 98); - const addressRestrictionNewValue = transactionData.substring(98, 114); - - return MosaicAddressRestrictionTransaction.create( - Deadline.createFromDTO(deadline), - new MosaicId(UInt64.fromHex(reverse(addressRestrictionMosaicId)).toDTO()), - UInt64.fromHex(reverse(addressRestrictionRestrictionKey)), - Address.createFromEncoded(addressRestrictionTargetAddress), - UInt64.fromHex(reverse(addressRestrictionPrevValue)), - UInt64.fromHex(reverse(addressRestrictionNewValue)), - networkType, - ); + return MosaicAddressRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.AGGREGATE_COMPLETE: - // read bytes - const payloadSize = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(0, 8)).reverse()), 16) * 2; - const cosignatures = transactionData.substring(payloadSize + 8); - - const innerTransactionArray = parseInnerTransactionFromBinary(transactionData.substring(8, payloadSize + 8)); - const consignatureArray = cosignatures.match(/.{1,192}/g); - - return AggregateTransaction.createComplete( - Deadline.createFromDTO(deadline), - innerTransactionArray.map((innerTransaction) => { - const transaction = CreateTransaction( - extractTransactionTypeFromHex(innerTransaction.substring(68, 72)), - innerTransaction.substring(72), - networkType, - deadline, - ); - return transaction.toAggregate(PublicAccount.createFromPublicKey(innerTransaction.substring(0, 64), networkType)); - }), - networkType, - consignatureArray ? consignatureArray.map((cosignature) => new AggregateTransactionCosignature( - cosignature.substring(64, 192), - PublicAccount.createFromPublicKey(cosignature.substring(0, 64), networkType), - )) : [], - ); case TransactionType.AGGREGATE_BONDED: - const bondedPayloadSize = parseInt(convert.uint8ToHex(convert.hexToUint8(transactionData.substring(0, 8)).reverse()), 16) * 2; - const bondedCosignatures = transactionData.substring(bondedPayloadSize + 8); - - const bondedInnerTransactionArray = parseInnerTransactionFromBinary(transactionData.substring(8, bondedPayloadSize + 8)); - const bondedConsignatureArray = bondedCosignatures.match(/.{1,192}/g); - - return AggregateTransaction.createBonded( - Deadline.createFromDTO(deadline), - bondedInnerTransactionArray.map((innerTransaction) => { - const transaction = CreateTransaction( - extractTransactionTypeFromHex(innerTransaction.substring(68, 72)), - innerTransaction.substring(72), - networkType, - deadline, - ); - return transaction.toAggregate(PublicAccount.createFromPublicKey(innerTransaction.substring(0, 64), networkType)); - }), - networkType, - bondedConsignatureArray ? bondedConsignatureArray.map((cosignature) => new AggregateTransactionCosignature( - cosignature.substring(64, 192), - PublicAccount.createFromPublicKey(cosignature.substring(0, 64), networkType), - )) : [], - ); + return AggregateTransaction.createFromPayload(payload, signSchema); default: throw new Error ('Transaction type not implemented yet.'); } }; - -/** - * @internal - * @param hexValue - Transaction type in hex - * @returns {number} - */ -const extractTransactionTypeFromHex = (hexValue: string): number => { - return parseInt(convert.uint8ToHex(convert.hexToUint8(hexValue).reverse()), 16); -}; - -/** - * @internal - * @param versionHex - Transaction version in hex - * @returns {NetworkType} - */ -const extractNetwork = (versionHex: string): NetworkType => { - const networkType = convert.hexToUint8(versionHex)[1]; - if (networkType === NetworkType.MAIN_NET) { - return NetworkType.MAIN_NET; - } else if (networkType === NetworkType.TEST_NET) { - return NetworkType.TEST_NET; - } else if (networkType === NetworkType.MIJIN) { - return NetworkType.MIJIN; - } else if (networkType === NetworkType.MIJIN_TEST) { - return NetworkType.MIJIN_TEST; - } - throw new Error('Unimplemented network type'); -}; - -/** - * @internal - * @param hex - * @returns {string} - */ -const reverse = (hex: string): string => { - return convert.uint8ToHex(convert.hexToUint8(hex).reverse()); -}; - -/** - * @internal - * @param innerTransactionBinary - Inner transaction binary data - * @returns {Array} - */ -const parseInnerTransactionFromBinary = (innerTransactionBinary: string): string[] => { - const embeddedTransaction: string[] = []; - let innerBinary = innerTransactionBinary; - - while (innerBinary.length) { - const payloadSize = parseInt(convert.uint8ToHex(convert.hexToUint8(innerBinary.substring(0, 8)).reverse()), 16) * 2; - const innerTransaction = innerBinary.substring(8, payloadSize); - embeddedTransaction.push(innerTransaction); - innerBinary = innerBinary.substring(payloadSize); - } - return embeddedTransaction; -}; - -/** - * @internal - * @param hex - Hex input - * @returns {string} - */ -const decodeHex = (hex: string): string => { - let str = ''; - for (let i = 0; i < hex.length; i += 2) { - str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); - } - try { - return decode(str); - } catch (e) { - return str; - } -}; - -/** - * @internal - * @param messageType - Message Type - * @param payload - Message Payload - * @returns {Message} - */ -const extractMessage = (messageType: MessageType, payload: string): Message => { - if (messageType === MessageType.PlainMessage) { - return PlainMessage.createFromPayload(payload); - } else if (messageType === MessageType.EncryptedMessage) { - return EncryptedMessage.createFromPayload(payload); - } else { - throw new Error('Invalid message type'); - } -}; diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index 150cd213b6..417dafba7b 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -14,21 +14,24 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, RawAddress } from '../../core/format'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; +import { EmbeddedAccountAddressRestrictionTransactionBuilder }from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; +import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -82,6 +85,36 @@ export class AccountAddressRestrictionTransaction extends Transaction { networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAccountAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AccountAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AccountAddressRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as AccountAddressRestrictionTransactionBuilder).getDeadline().timestamp), + builder.getRestrictionType().valueOf(), + builder.getModifications().map((modification) => { + return AccountRestrictionModification.createForAddress( + modification.modificationAction.valueOf(), + Address.createFromEncoded(Convert.uint8ToHex(modification.value.unresolvedAddress)), + ); + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountAddressRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AccountAddressRestrictionTransaction diff --git a/src/model/transaction/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index 58584444b2..f1cb351b7a 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/AccountLinkTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -26,6 +27,7 @@ import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { LinkAction } from './LinkAction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; @@ -87,6 +89,30 @@ export class AccountLinkTransaction extends Transaction { super(TransactionType.LINK_ACCOUNT, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAccountLinkTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AccountLinkTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AccountLinkTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as AccountLinkTransactionBuilder).getDeadline().timestamp), + Convert.uint8ToHex(builder.getRemoteAccountPublicKey().key), + builder.getLinkAction().valueOf(), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountLinkTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AccountLinkTransaction diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index 3a5b19946c..496fe2b64f 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; @@ -25,9 +26,11 @@ import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; +import { MosaicId } from '../mosaic/MosaicId'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -81,6 +84,36 @@ export class AccountMosaicRestrictionTransaction extends Transaction { networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAccountMosaicRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AccountMosaicRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AccountMosaicRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as AccountMosaicRestrictionTransactionBuilder).getDeadline().timestamp), + builder.getRestrictionType().valueOf(), + builder.getModifications().map((modification) => { + return AccountRestrictionModification.createForMosaic( + modification.modificationAction.valueOf(), + new MosaicId(modification.value.unresolvedMosaicId), + ); + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountMosaicRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AccountMosaicRestrictionTransaction diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index df82913d22..f60abe0115 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; @@ -28,6 +29,7 @@ import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -81,6 +83,36 @@ export class AccountOperationRestrictionTransaction extends Transaction { networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAccountOperationRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AccountOperationRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AccountOperationRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as AccountOperationRestrictionTransactionBuilder).getDeadline().timestamp), + builder.getRestrictionType().valueOf(), + builder.getModifications().map((modification) => { + return AccountRestrictionModification.createForOperation( + modification.modificationAction.valueOf(), + modification.value.valueOf(), + ); + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountOperationRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AccountOperationRestrictionTransaction diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 1faaeaa7dc..3975b926dc 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -14,12 +14,12 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, RawAddress } from '../../core/format'; import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder'; import { AddressDto } from '../../infrastructure/catbuffer/AddressDto'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -31,6 +31,7 @@ import { AliasAction } from '../namespace/AliasAction'; import { NamespaceId } from '../namespace/NamespaceId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -102,6 +103,32 @@ export class AddressAliasTransaction extends Transaction { super(TransactionType.ADDRESS_ALIAS, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAddressAliasTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AddressAliasTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AddressAliasTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as AddressAliasTransactionBuilder).getDeadline().timestamp), + builder.getAliasAction().valueOf(), + new NamespaceId(builder.getNamespaceId().namespaceId), + Address.createFromEncoded( + Convert.uint8ToHex(builder.getAddress().address)), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AddressAliasTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AddressAliasTransaction diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 608559f663..76eac2be1a 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -23,6 +23,7 @@ import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { CreateTransactionFromPayload } from '../../infrastructure/transaction/CreateTransactionFromPayload'; import { Account } from '../account/Account'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; @@ -122,6 +123,61 @@ export class AggregateTransaction extends Transaction { ); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {AggregateTransaction} + */ + public static createFromPayload(payload: string, signSchema: SignSchema = SignSchema.SHA3): AggregateTransaction { + const builder = AggregateTransactionBuilder + .loadFromBinary(Convert.hexToUint8(payload)); + const type = builder.getType().valueOf(); + const innerTransactionHex = Convert.uint8ToHex(builder.getTransactions()); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const consignaturesHex = Convert.uint8ToHex(builder.getCosignatures()); + + /** + * Get inner transactions array + */ + const embeddedTransactionArray: string[] = []; + let innerBinary = innerTransactionHex; + while (innerBinary.length) { + const payloadSize = parseInt(Convert.uint8ToHex(Convert.hexToUint8(innerBinary.substring(0, 8)).reverse()), 16) * 2; + const innerTransaction = innerBinary.substring(0, payloadSize); + embeddedTransactionArray.push(innerTransaction); + innerBinary = innerBinary.substring(payloadSize); + } + + /** + * Get cosignatures + */ + const consignatureArray = consignaturesHex.match(/.{1,192}/g); + const consignatures = consignatureArray ? consignatureArray.map((cosignature) => + new AggregateTransactionCosignature( + cosignature.substring(64, 192), + PublicAccount.createFromPublicKey(cosignature.substring(0, 64), networkType, signSchema), + )) : []; + + return type === TransactionType.AGGREGATE_COMPLETE ? + AggregateTransaction.createComplete( + Deadline.createFromDTO(builder.deadline.timestamp), + embeddedTransactionArray.map((transactionRaw) => { + return CreateTransactionFromPayload(transactionRaw, true, signSchema) as InnerTransaction; + }), + networkType, + consignatures, + new UInt64(builder.fee.amount), + ) : AggregateTransaction.createBonded( + Deadline.createFromDTO(builder.deadline.timestamp), + embeddedTransactionArray.map((transactionRaw) => { + return CreateTransactionFromPayload(transactionRaw, true, signSchema) as InnerTransaction; + }), + networkType, + consignatures, + new UInt64(builder.fee.amount), + ); + } /** * @internal * Sign transaction with cosignatories creating a new SignedTransaction @@ -230,7 +286,7 @@ export class AggregateTransaction extends Transaction { transactions = GeneratorUtils.concatTypedArrays(transactions, transactionByte); }); - const cosignatures = Uint8Array.from([]); + let cosignatures = Uint8Array.from([]); this.cosignatures.forEach((cosignature) => { const signerBytes = Convert.hexToUint8(cosignature.signer.publicKey); const signatureBytes = Convert.hexToUint8(cosignature.signature); @@ -238,7 +294,7 @@ export class AggregateTransaction extends Transaction { new KeyDto(signerBytes), new SignatureDto(signatureBytes), ).serialize(); - transactions = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); + cosignatures = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); }); const transactionBuilder = new AggregateTransactionBuilder( diff --git a/src/model/transaction/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index b36810cf05..96088b7ec0 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; @@ -28,8 +29,10 @@ import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/Unresolved import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { Mosaic } from '../mosaic/Mosaic'; +import { MosaicId } from '../mosaic/MosaicId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { SignedTransaction } from './SignedTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; @@ -111,6 +114,35 @@ export class LockFundsTransaction extends Transaction { } } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedHashLockTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + HashLockTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = LockFundsTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as HashLockTransactionBuilder).getDeadline().timestamp), + new Mosaic( + new MosaicId(builder.getMosaic().mosaicId.unresolvedMosaicId), + new UInt64(builder.getMosaic().amount.amount), + ), + new UInt64(builder.getDuration().blockDuration), + new SignedTransaction('', Convert.uint8ToHex(builder.getHash().hash256), '', + TransactionType.AGGREGATE_BONDED, networkType), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as HashLockTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a LockFundsTransaction diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index 835b117f13..23dce96d81 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { CosignatoryModificationBuilder } from '../../infrastructure/catbuffer/CosignatoryModificationBuilder'; @@ -26,6 +27,7 @@ import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { MultisigCosignatoryModification } from './MultisigCosignatoryModification'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; @@ -101,6 +103,40 @@ export class ModifyMultisigAccountTransaction extends Transaction { super(TransactionType.MODIFY_MULTISIG_ACCOUNT, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMultisigAccountModificationTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MultisigAccountModificationTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = ModifyMultisigAccountTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as MultisigAccountModificationTransactionBuilder).getDeadline().timestamp), + builder.getMinApprovalDelta(), + builder.getMinRemovalDelta(), + builder.getModifications().map((modification) => { + return new MultisigCosignatoryModification( + modification.modificationAction.valueOf(), + PublicAccount.createFromPublicKey( + Convert.uint8ToHex(modification.cosignatoryPublicKey.key), + networkType, + ), + ); + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MultisigAccountModificationTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a ModifyMultisigAccountTransaction diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index f366fc0aed..3f1877838a 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, RawAddress } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder'; @@ -29,6 +30,7 @@ import { NetworkType } from '../blockchain/NetworkType'; import { MosaicId } from '../mosaic/MosaicId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -119,6 +121,34 @@ export class MosaicAddressRestrictionTransaction extends Transaction { super(TransactionType.MOSAIC_ADDRESS_RESTRICTION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMosaicAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MosaicAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = MosaicAddressRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as MosaicAddressRestrictionTransactionBuilder).getDeadline().timestamp), + new MosaicId(builder.getMosaicId().unresolvedMosaicId), + new UInt64(builder.getRestrictionKey()), + Address.createFromEncoded(Convert.uint8ToHex(builder.getTargetAddress().unresolvedAddress)), + new UInt64(builder.getPreviousRestrictionValue()), + new UInt64(builder.getNewRestrictionValue()), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MosaicAddressRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a MosaicDefinitionTransaction diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index 447d5530ad..6d7cae3183 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAliasTransactionBuilder'; @@ -31,6 +32,7 @@ import { AliasAction } from '../namespace/AliasAction'; import { NamespaceId } from '../namespace/NamespaceId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -98,6 +100,31 @@ export class MosaicAliasTransaction extends Transaction { super(TransactionType.MOSAIC_ALIAS, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMosaicAliasTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MosaicAliasTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = MosaicAliasTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as MosaicAliasTransactionBuilder).getDeadline().timestamp), + builder.getAliasAction().valueOf(), + new NamespaceId(builder.getNamespaceId().namespaceId), + new MosaicId(builder.getMosaicId().mosaicId), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MosaicAliasTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a MosaicAliasTransaction diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 9ebbf03fe6..1616044875 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; @@ -33,6 +34,7 @@ import { MosaicNonce } from '../mosaic/MosaicNonce'; import { MosaicProperties } from '../mosaic/MosaicProperties'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -104,6 +106,38 @@ export class MosaicDefinitionTransaction extends Transaction { super(TransactionType.MOSAIC_DEFINITION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMosaicDefinitionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MosaicDefinitionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = MosaicDefinitionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as MosaicDefinitionTransactionBuilder).getDeadline().timestamp), + new MosaicNonce(builder.getNonce().serialize()), + new MosaicId(builder.getId().mosaicId), + MosaicProperties.create({ + supplyMutable: (builder.getFlags() & 1) === 1, + transferable: (builder.getFlags() & 2) === 2, + divisibility: builder.getDivisibility(), + restrictable: (builder.getFlags() & 4) === 4, + duration: new UInt64(builder.getDuration().blockDuration), + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MosaicDefinitionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a MosaicDefinitionTransaction diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index 9081fa5dbc..c7e36df0d2 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicGlobalRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicGlobalRestrictionTransactionBuilder'; @@ -29,6 +30,7 @@ import { MosaicId } from '../mosaic/MosaicId'; import { MosaicRestrictionType } from '../mosaic/MosaicRestrictionType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -136,6 +138,36 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { super(TransactionType.MOSAIC_GLOBAL_RESTRICTION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMosaicGlobalRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MosaicGlobalRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = MosaicGlobalRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as MosaicGlobalRestrictionTransactionBuilder).getDeadline().timestamp), + new MosaicId(builder.getMosaicId().unresolvedMosaicId), + new MosaicId(builder.getReferenceMosaicId().unresolvedMosaicId), + new UInt64(builder.getRestrictionKey()), + new UInt64(builder.getPreviousRestrictionValue()), + builder.getPreviousRestrictionType().valueOf(), + new UInt64(builder.getNewRestrictionValue()), + builder.getNewRestrictionType().valueOf(), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MosaicGlobalRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a MosaicDefinitionTransaction diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index 03f0137241..1ee6fc22d7 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedMosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder'; @@ -28,6 +29,7 @@ import { MosaicId } from '../mosaic/MosaicId'; import { MosaicSupplyType } from '../mosaic/MosaicSupplyType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -99,6 +101,32 @@ export class MosaicSupplyChangeTransaction extends Transaction { super(TransactionType.MOSAIC_SUPPLY_CHANGE, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMosaicSupplyChangeTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MosaicSupplyChangeTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = MosaicSupplyChangeTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as MosaicSupplyChangeTransactionBuilder).getDeadline().timestamp), + new MosaicId(builder.getMosaicId().unresolvedMosaicId), + builder.getAction().valueOf(), + new UInt64(builder.getDelta().amount), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MosaicSupplyChangeTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a MosaicSupplyChangeTransaction diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index 3089126e25..6c63a6c4e5 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, Convert as convert } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; @@ -30,6 +31,7 @@ import { NamespaceId } from '../namespace/NamespaceId'; import { NamespaceType } from '../namespace/NamespaceType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -145,6 +147,40 @@ export class RegisterNamespaceTransaction extends Transaction { super(TransactionType.REGISTER_NAMESPACE, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedNamespaceRegistrationTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + NamespaceRegistrationTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const namespaceType = builder.getRegistrationType().valueOf(); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = namespaceType === NamespaceType.RootNamespace ? + RegisterNamespaceTransaction.createRootNamespace( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as NamespaceRegistrationTransactionBuilder).getDeadline().timestamp), + Convert.decodeHex(Convert.uint8ToHex(builder.getName())), + new UInt64(builder.getDuration()!.blockDuration), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as NamespaceRegistrationTransactionBuilder).fee.amount), + ) : RegisterNamespaceTransaction.createSubNamespace( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as NamespaceRegistrationTransactionBuilder).getDeadline().timestamp), + Convert.decodeHex(Convert.uint8ToHex(builder.getName())), + new NamespaceId(builder.getParentId()!.namespaceId), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as NamespaceRegistrationTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a RegisterNamespaceTransaction diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index 5efbe3c3fe..6dd679613e 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -13,7 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Convert as convert, RawAddress } from '../../core/format'; +import { SignSchema } from '../../core/crypto/SignSchema'; +import { Convert, Convert as convert, RawAddress } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; import { EmbeddedSecretLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretLockTransactionBuilder'; @@ -30,9 +31,11 @@ import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { Mosaic } from '../mosaic/Mosaic'; +import { MosaicId } from '../mosaic/MosaicId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; import { HashType, HashTypeLengthValidator } from './HashType'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -122,6 +125,37 @@ export class SecretLockTransaction extends Transaction { } } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedSecretLockTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + SecretLockTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = SecretLockTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as SecretLockTransactionBuilder).getDeadline().timestamp), + new Mosaic( + new MosaicId(builder.getMosaic().mosaicId.unresolvedMosaicId), + new UInt64(builder.getMosaic().amount.amount), + ), + new UInt64(builder.getDuration().blockDuration), + builder.getHashAlgorithm().valueOf(), + Convert.uint8ToHex(builder.getSecret().hash256), + Address.createFromEncoded(Convert.uint8ToHex(builder.getRecipient().unresolvedAddress)), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as SecretLockTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a SecretLockTransaction diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index cbca7576b2..0752efa2f1 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, Convert as convert, RawAddress } from '../../core/format'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedSecretProofTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder'; @@ -30,6 +31,7 @@ import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; import { HashType, HashTypeLengthValidator } from './HashType'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -99,6 +101,33 @@ export class SecretProofTransaction extends Transaction { } } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedSecretProofTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + SecretProofTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = SecretProofTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as SecretProofTransactionBuilder).getDeadline().timestamp), + builder.getHashAlgorithm().valueOf(), + Convert.uint8ToHex(builder.getSecret().hash256), + Address.createFromEncoded(Convert.uint8ToHex(builder.getRecipient().unresolvedAddress)), + Convert.uint8ToHex(builder.getProof()), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as SecretProofTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a SecretProofTransaction diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 38a2d02c0b..eb2daab1de 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, Convert as convert } from '../../core/format'; import { RawAddress } from '../../core/format/RawAddress'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -30,10 +31,15 @@ import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../blockchain/NetworkType'; import { Mosaic } from '../mosaic/Mosaic'; +import { MosaicId } from '../mosaic/MosaicId'; import { NamespaceId } from '../namespace/NamespaceId'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { EncryptedMessage } from './EncryptedMessage'; +import { InnerTransaction } from './InnerTransaction'; import { Message } from './Message'; +import { MessageType } from './MessageType'; +import { PlainMessage } from './PlainMessage'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -102,6 +108,40 @@ export class TransferTransaction extends Transaction { super(TransactionType.TRANSFER, networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedTransferTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + TransferTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const messageType = builder.getMessage()[0]; + const messageHex = Convert.uint8ToHex(builder.getMessage()).substring(2); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = TransferTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as TransferTransactionBuilder).getDeadline().timestamp), + Address.createFromEncoded(Convert.uint8ToHex(builder.getRecipient().unresolvedAddress)), + builder.getMosaics().map((mosaic) => { + return new Mosaic( + new MosaicId(mosaic.mosaicId.unresolvedMosaicId), + new UInt64(mosaic.amount.amount)); + }), + messageType === MessageType.PlainMessage ? + PlainMessage.createFromPayload(messageHex) : + EncryptedMessage.createFromPayload(messageHex), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as TransferTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * Return the string notation for the set recipient * @internal From 1382a73feb0e7faf77dfe22eef6917ded6f14d64 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 19 Aug 2019 10:43:56 +0100 Subject: [PATCH 76/98] Applied generated aggregate transaction from catbuffer-generator --- .../AggregateBondedTransactionBuilder.ts | 112 +++++++++++++++ .../AggregateCompleteTransactionBuilder.ts | 112 +++++++++++++++ .../AggregateTransactionBodyBuilder.ts | 102 ++++++++++++++ .../catbuffer/AggregateTransactionBuilder.ts | 132 ------------------ .../catbuffer/CosignatureBuilder.ts | 30 ++-- .../catbuffer/DetachedCosignatureBuilder.ts | 46 +++--- src/infrastructure/catbuffer/EntityTypeDto.ts | 106 +++++--------- .../catbuffer/GeneratorUtils.ts | 55 ++++---- src/model/transaction/AggregateTransaction.ts | 36 +++-- 9 files changed, 449 insertions(+), 282 deletions(-) create mode 100644 src/infrastructure/catbuffer/AggregateBondedTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AggregateCompleteTransactionBuilder.ts create mode 100644 src/infrastructure/catbuffer/AggregateTransactionBodyBuilder.ts delete mode 100644 src/infrastructure/catbuffer/AggregateTransactionBuilder.ts diff --git a/src/infrastructure/catbuffer/AggregateBondedTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateBondedTransactionBuilder.ts new file mode 100644 index 0000000000..af3e1e2ed0 --- /dev/null +++ b/src/infrastructure/catbuffer/AggregateBondedTransactionBuilder.ts @@ -0,0 +1,112 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AggregateTransactionBodyBuilder } from './AggregateTransactionBodyBuilder'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for an aggregate bonded transaction. */ +export class AggregateBondedTransactionBuilder extends TransactionBuilder { + /** Aggregate transaction body. */ + aggregateTransactionBody: AggregateTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param transactions Sub-transaction data (transactions are variable sized and payload size is in bytes). + * @param cosignatures Cosignatures data (fills remaining body space after transactions). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, transactions: Uint8Array, cosignatures: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + this.aggregateTransactionBody = new AggregateTransactionBodyBuilder(transactions, cosignatures); + } + + /** + * Creates an instance of AggregateBondedTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AggregateBondedTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AggregateBondedTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const aggregateTransactionBody = AggregateTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, aggregateTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AggregateBondedTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, aggregateTransactionBody.transactions, aggregateTransactionBody.cosignatures); + } + + /** + * Gets sub-transaction data (transactions are variable sized and payload size is in bytes). + * + * @return Sub-transaction data (transactions are variable sized and payload size is in bytes). + */ + public getTransactions(): Uint8Array { + return this.aggregateTransactionBody.getTransactions(); + } + + /** + * Gets cosignatures data (fills remaining body space after transactions). + * + * @return Cosignatures data (fills remaining body space after transactions). + */ + public getCosignatures(): Uint8Array { + return this.aggregateTransactionBody.getCosignatures(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.aggregateTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const aggregateTransactionBodyBytes = this.aggregateTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, aggregateTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AggregateCompleteTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateCompleteTransactionBuilder.ts new file mode 100644 index 0000000000..a68fd86f07 --- /dev/null +++ b/src/infrastructure/catbuffer/AggregateCompleteTransactionBuilder.ts @@ -0,0 +1,112 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AggregateTransactionBodyBuilder } from './AggregateTransactionBodyBuilder'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** Binary layout for an aggregate complete transaction. */ +export class AggregateCompleteTransactionBuilder extends TransactionBuilder { + /** Aggregate transaction body. */ + aggregateTransactionBody: AggregateTransactionBodyBuilder; + + /** + * Constructor. + * + * @param signature Entity signature. + * @param signer Entity signer's public key. + * @param version Entity version. + * @param type Entity type. + * @param fee Transaction fee. + * @param deadline Transaction deadline. + * @param transactions Sub-transaction data (transactions are variable sized and payload size is in bytes). + * @param cosignatures Cosignatures data (fills remaining body space after transactions). + */ + // tslint:disable-next-line: max-line-length + public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, transactions: Uint8Array, cosignatures: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + this.aggregateTransactionBody = new AggregateTransactionBodyBuilder(transactions, cosignatures); + } + + /** + * Creates an instance of AggregateCompleteTransactionBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AggregateCompleteTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AggregateCompleteTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const aggregateTransactionBody = AggregateTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, aggregateTransactionBody.getSize()); + // tslint:disable-next-line: max-line-length + return new AggregateCompleteTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, aggregateTransactionBody.transactions, aggregateTransactionBody.cosignatures); + } + + /** + * Gets sub-transaction data (transactions are variable sized and payload size is in bytes). + * + * @return Sub-transaction data (transactions are variable sized and payload size is in bytes). + */ + public getTransactions(): Uint8Array { + return this.aggregateTransactionBody.getTransactions(); + } + + /** + * Gets cosignatures data (fills remaining body space after transactions). + * + * @return Cosignatures data (fills remaining body space after transactions). + */ + public getCosignatures(): Uint8Array { + return this.aggregateTransactionBody.getCosignatures(); + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.aggregateTransactionBody.getSize(); + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const aggregateTransactionBodyBytes = this.aggregateTransactionBody.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, aggregateTransactionBodyBytes); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AggregateTransactionBodyBuilder.ts b/src/infrastructure/catbuffer/AggregateTransactionBodyBuilder.ts new file mode 100644 index 0000000000..4d84e86f79 --- /dev/null +++ b/src/infrastructure/catbuffer/AggregateTransactionBodyBuilder.ts @@ -0,0 +1,102 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { GeneratorUtils } from './GeneratorUtils'; + +/** Binary layout for an aggregate transaction. */ +export class AggregateTransactionBodyBuilder { + /** Sub-transaction data (transactions are variable sized and payload size is in bytes). */ + transactions: Uint8Array; + /** Cosignatures data (fills remaining body space after transactions). */ + cosignatures: Uint8Array; + + /** + * Constructor. + * + * @param transactions Sub-transaction data (transactions are variable sized and payload size is in bytes). + * @param cosignatures Cosignatures data (fills remaining body space after transactions). + */ + public constructor(transactions: Uint8Array, cosignatures: Uint8Array) { + this.transactions = transactions; + this.cosignatures = cosignatures; + } + + /** + * Creates an instance of AggregateTransactionBodyBuilder from binary payload. + * + * @param payload Byte payload to use to serialize the object. + * @return Instance of AggregateTransactionBodyBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AggregateTransactionBodyBuilder { + const byteArray = Array.from(payload); + const payloadSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + const transactions = GeneratorUtils.getBytes(Uint8Array.from(byteArray), payloadSize); + byteArray.splice(0, payloadSize); + const cosignatures = Uint8Array.from(byteArray); + return new AggregateTransactionBodyBuilder(transactions, cosignatures); + } + + /** + * Gets sub-transaction data (transactions are variable sized and payload size is in bytes). + * + * @return Sub-transaction data (transactions are variable sized and payload size is in bytes). + */ + public getTransactions(): Uint8Array { + return this.transactions; + } + + /** + * Gets cosignatures data (fills remaining body space after transactions). + * + * @return Cosignatures data (fills remaining body space after transactions). + */ + public getCosignatures(): Uint8Array { + return this.cosignatures; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size = 0; + size += 4; // payloadSize + size += this.transactions.length; + size += this.cosignatures.length; + return size; + } + + /** + * Serializes an object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const payloadSizeBytes = GeneratorUtils.uintToBuffer(this.transactions.length, 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.transactions); + newArray = GeneratorUtils.concatTypedArrays(newArray, this.cosignatures); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts deleted file mode 100644 index 20462d8514..0000000000 --- a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts +++ /dev/null @@ -1,132 +0,0 @@ -// tslint:disable: jsdoc-format -/** -*** Copyright (c) 2016-present, -*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. -*** -*** This file is part of Catapult. -*** -*** Catapult is free software: you can redistribute it and/or modify -*** it under the terms of the GNU Lesser General Public License as published by -*** the Free Software Foundation, either version 3 of the License, or -*** (at your option) any later version. -*** -*** Catapult is distributed in the hope that it will be useful, -*** but WITHOUT ANY WARRANTY; without even the implied warranty of -*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -*** GNU Lesser General Public License for more details. -*** -*** You should have received a copy of the GNU Lesser General Public License -*** along with Catapult. If not, see . -**/ - -import { AmountDto } from './AmountDto'; -import { EntityTypeDto } from './EntityTypeDto'; -import { GeneratorUtils } from './GeneratorUtils'; -import { KeyDto } from './KeyDto'; -import { SignatureDto } from './SignatureDto'; -import { TimestampDto } from './TimestampDto'; -import { TransactionBuilder } from './TransactionBuilder'; - -/** binary layout for an aggregate transaction. */ -export class AggregateTransactionBuilder extends TransactionBuilder { - /** embedded transactions. */ - transactions: Uint8Array; - /** cosignatures. */ - cosignatures: Uint8Array; - - /** - * Constructor. - * - * @param signature entity signature. - * @param signer entity signer's public key. - * @param version entity version. - * @param type entity type. - * @param fee transaction fee. - * @param deadline transaction deadline. - * @param transactions embedded transactions. - * @param cosignatures cosignatures. - */ - public constructor( - signature: SignatureDto, - signer: KeyDto, - version: number, - type: EntityTypeDto, - fee: AmountDto, - deadline: TimestampDto, - transactions: Uint8Array, - cosignatures: Uint8Array) { - super(signature, signer, version, type, fee, deadline); - this.transactions = transactions; - this.cosignatures = cosignatures; - } - - /** - * loadFromBinary - Create an instance of AggregateTransactionBuilder from a stream. - * - * @param Uint8Array Byte to use to serialize the object. - * @return An instance of AggregateTransactionBuilder. - */ - public static loadFromBinary(payload: Uint8Array): AggregateTransactionBuilder { - const byteArray = Array.from(payload); - const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); - byteArray.splice(0, superObject.getSize()); - const payloadSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); - byteArray.splice(0, 4); - const transactions = GeneratorUtils.getBytes(Uint8Array.from(byteArray), payloadSize); - byteArray.splice(0, transactions.length); - const cosignatures = Uint8Array.from(byteArray); - // tslint:disable-next-line: max-line-length - return new AggregateTransactionBuilder(superObject.signature, superObject.signer, superObject.version, - superObject.type, superObject.fee, superObject.deadline, - transactions, cosignatures); - } - - /** - * Get embedded transactions. - * - * @return embedded transactions. - */ - public getTransactions(): Uint8Array { - return this.transactions; - } - - /** - * Get cosignatures. - * - * @return cosignatures. - */ - public getCosignatures(): Uint8Array { - return this.cosignatures; - } - - /** - * Get the size of the object. - * - * @return Size in bytes. - */ - public getSize(): number { - let size: number = super.getSize(); - size += 4; // payloadSize - size += this.transactions.length; - size += this.cosignatures.length; - return size; - } - - /** - * Serialize the object to bytes. - * - * @return Serialized bytes. - */ - public serialize(): Uint8Array { - let newArray = Uint8Array.from([]); - const superBytes = super.serialize(); - newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); - const payloadSizeBytes = GeneratorUtils.uintToBuffer(this.transactions.length, 4); - newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes); - const transactionBytes = this.transactions; - newArray = GeneratorUtils.concatTypedArrays(newArray, transactionBytes); - const cosignaturesBytes = this.cosignatures; - newArray = GeneratorUtils.concatTypedArrays(newArray, cosignaturesBytes); - return newArray; - } -} diff --git a/src/infrastructure/catbuffer/CosignatureBuilder.ts b/src/infrastructure/catbuffer/CosignatureBuilder.ts index 5e0ba7a43c..447524c2f6 100644 --- a/src/infrastructure/catbuffer/CosignatureBuilder.ts +++ b/src/infrastructure/catbuffer/CosignatureBuilder.ts @@ -23,29 +23,29 @@ import { GeneratorUtils } from './GeneratorUtils'; import { KeyDto } from './KeyDto'; import { SignatureDto } from './SignatureDto'; -/** a cosignature. */ +/** Cosignature attached to an aggregate transaction. */ export class CosignatureBuilder { - /** cosigner public key. */ + /** Cosigner public key. */ signer: KeyDto; - /** cosigner signature. */ + /** Cosigner signature. */ signature: SignatureDto; /** * Constructor. * - * @param signer cosigner public key. - * @param signature cosigner signature. + * @param signer Cosigner public key. + * @param signature Cosigner signature. */ - public constructor(signer: KeyDto, signature: SignatureDto) { + public constructor(signer: KeyDto, signature: SignatureDto) { this.signer = signer; this.signature = signature; } /** - * loadFromBinary - Create an instance of CosignatureBuilder from a stream. + * Creates an instance of CosignatureBuilder from binary payload. * - * @param payload Byte to use to serialize the object. - * @return An instance of CosignatureBuilder. + * @param payload Byte payload to use to serialize the object. + * @return Instance of CosignatureBuilder. */ public static loadFromBinary(payload: Uint8Array): CosignatureBuilder { const byteArray = Array.from(payload); @@ -57,25 +57,25 @@ export class CosignatureBuilder { } /** - * Get cosigner public key. + * Gets cosigner public key. * - * @return cosigner public key. + * @return Cosigner public key. */ public getSigner(): KeyDto { return this.signer; } /** - * Get cosigner signature. + * Gets cosigner signature. * - * @return cosigner signature. + * @return Cosigner signature. */ public getSignature(): SignatureDto { return this.signature; } /** - * Get the size of the object. + * Gets the size of the object. * * @return Size in bytes. */ @@ -87,7 +87,7 @@ export class CosignatureBuilder { } /** - * Serialize the object to bytes. + * Serializes an object to bytes. * * @return Serialized bytes. */ diff --git a/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts b/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts index 58a3152ed0..f10107ee30 100644 --- a/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts +++ b/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts @@ -19,77 +19,73 @@ *** along with Catapult. If not, see . **/ +import { CosignatureBuilder } from './CosignatureBuilder'; import { GeneratorUtils } from './GeneratorUtils'; +import { Hash256Dto } from './Hash256Dto'; import { KeyDto } from './KeyDto'; import { SignatureDto } from './SignatureDto'; -import { CosignatureBuilder } from './CosignatureBuilder'; -import { Hash256Dto } from './Hash256Dto'; -/** a detached cosignature. */ +/** Cosignature detached from an aggregate transaction. */ export class DetachedCosignatureBuilder extends CosignatureBuilder { - /** hash of the corresponding parent. */ + /** Hash of the aggregate transaction that is signed by this cosignature. */ parentHash: Hash256Dto; /** * Constructor. * - * @param signer cosigner public key. - * @param signature cosigner signature. - * @param parentHash hash of the corresponding parent. + * @param signer Cosigner public key. + * @param signature Cosigner signature. + * @param parentHash Hash of the aggregate transaction that is signed by this cosignature. */ - public constructor(signer: KeyDto, signature: SignatureDto, parentHash: Hash256Dto) { + public constructor(signer: KeyDto, signature: SignatureDto, parentHash: Hash256Dto) { super(signer, signature); this.parentHash = parentHash; } /** - * loadFromBinary - Create an instance of DetachedCosignatureBuilder from a stream. + * Creates an instance of DetachedCosignatureBuilder from binary payload. * - * @param payload Byte to use to serialize the object. - * @return An instance of DetachedCosignatureBuilder. + * @param payload Byte payload to use to serialize the object. + * @return Instance of DetachedCosignatureBuilder. */ public static loadFromBinary(payload: Uint8Array): DetachedCosignatureBuilder { const byteArray = Array.from(payload); - const signer = KeyDto.loadFromBinary(Uint8Array.from(byteArray)); - byteArray.splice(0, signer.getSize()); - const signature = SignatureDto.loadFromBinary(Uint8Array.from(byteArray)); - byteArray.splice(0, signature.getSize()); + const superObject = CosignatureBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); const parentHash = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); byteArray.splice(0, parentHash.getSize()); - return new DetachedCosignatureBuilder(signer, signature, parentHash); + return new DetachedCosignatureBuilder(superObject.signer, superObject.signature, parentHash); } /** - * Get hash of the corresponding parent. + * Gets hash of the aggregate transaction that is signed by this cosignature. * - * @return hash of the corresponding parent. + * @return Hash of the aggregate transaction that is signed by this cosignature. */ public getParentHash(): Hash256Dto { return this.parentHash; } /** - * Get the size of the object. + * Gets the size of the object. * * @return Size in bytes. */ public getSize(): number { - let size = super.getSize(); + let size: number = super.getSize(); size += this.parentHash.getSize(); return size; } /** - * Serialize the object to bytes. + * Serializes an object to bytes. * * @return Serialized bytes. */ public serialize(): Uint8Array { let newArray = Uint8Array.from([]); - const signerBytes = this.signer.serialize(); - newArray = GeneratorUtils.concatTypedArrays(newArray, signerBytes); - const signatureBytes = this.signature.serialize(); - newArray = GeneratorUtils.concatTypedArrays(newArray, signatureBytes); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); const parentHashBytes = this.parentHash.serialize(); newArray = GeneratorUtils.concatTypedArrays(newArray, parentHashBytes); return newArray; diff --git a/src/infrastructure/catbuffer/EntityTypeDto.ts b/src/infrastructure/catbuffer/EntityTypeDto.ts index 52e1c55a94..921a115ce9 100644 --- a/src/infrastructure/catbuffer/EntityTypeDto.ts +++ b/src/infrastructure/catbuffer/EntityTypeDto.ts @@ -25,109 +25,67 @@ export enum EntityTypeDto { /** Reserved entity type. */ RESERVED = 0, /** - * Transfer Transaction transaction type. - * @type {number} + * Account address restriction transaction. */ - TRANSFER = 0x4154, - + ACCOUNT_ADDRESS_RESTRICTION_TRANSACTION = 0x4150, /** - * Register namespace transaction type. - * @type {number} + * Account mosaic restriction transaction. */ - REGISTER_NAMESPACE = 0x414E, - + ACCOUNT_MOSAIC_RESTRICTION_TRANSACTION = 0x4250, /** - * Address alias transaction type - * @type {number} + * Account operation restriction transaction. */ - ADDRESS_ALIAS = 0x424E, - + ACCOUNT_OPERATION_RESTRICTION_TRANSACTION = 0x4350, /** - * Mosaic alias transaction type - * @type {number} + * Account link transaction. */ - MOSAIC_ALIAS = 0x434E, - + ACCOUNT_LINK_TRANSACTION = 0x414C, /** - * Mosaic definition transaction type. - * @type {number} + * Address alias transaction. */ - MOSAIC_DEFINITION = 0x414D, - + ADDRESS_ALIAS_TRANSACTION = 0x424E, /** - * Mosaic supply change transaction. - * @type {number} + * Aggregate bonded transaction. */ - MOSAIC_SUPPLY_CHANGE = 0x424D, - + AGGREGATE_BONDED_TRANSACTION = 0x4241, /** - * Modify multisig account transaction type. - * @type {number} + * Aggregate complete transaction. */ - MODIFY_MULTISIG_ACCOUNT = 0x4155, - + AGGREGATE_COMPLETE_TRANSACTION = 0x4141, /** - * Aggregate complete transaction type. - * @type {number} + * Hash lock transaction. */ - AGGREGATE_COMPLETE = 0x4141, - + HASH_LOCK_TRANSACTION = 0x4148, /** - * Aggregate bonded transaction type + * Modify multisig account transaction. */ - AGGREGATE_BONDED = 0x4241, - + MODIFY_MULTISIG_ACCOUNT_TRANSACTION = 0x4155, /** - * Lock transaction type - * @type {number} + * Mosaic definition transaction. */ - LOCK = 0x4148, - + MOSAIC_DEFINITION_TRANSACTION = 0x414D, /** - * Secret Lock Transaction type - * @type {number} - */ - SECRET_LOCK = 0x4152, - - /** - * Secret Proof transaction type - * @type {number} + * Mosaic supply change transaction. */ - SECRET_PROOF = 0x4252, - + MOSAIC_SUPPLY_CHANGE_TRANSACTION = 0x424D, /** - * Account restriction address transaction type - * @type {number} + * Mosaic alias transaction. */ - ACCOUNT_RESTRICTION_ADDRESS = 0x4150, - + MOSAIC_ALIAS_TRANSACTION = 0x434E, /** - * Account restriction mosaic transaction type - * @type {number} + * Register namespace transaction. */ - ACCOUNT_RESTRICTION_MOSAIC = 0x4250, - + REGISTER_NAMESPACE_TRANSACTION = 0x414E, /** - * Account restriction operation transaction type - * @type {number} + * Secret lock transaction. */ - ACCOUNT_RESTRICTION_OPERATION = 0x4350, - + SECRET_LOCK_TRANSACTION = 0x4152, /** - * Link account transaction type - * @type {number} + * Secret Proof transaction. */ - LINK_ACCOUNT = 0x414C, - - /** - * Mosaic address restriction type - * @type {number} - */ - MOSAIC_ADDRESS_RESTRICTION = 0x4251, - + SECRET_PROOF_TRANSACTION = 0x4252, /** - * Mosaic global restriction type - * @type {number} + * Transfer transaction. */ - MOSAIC_GLOBAL_RESTRICTION = 0x4151, + TRANSFER_TRANSACTION = 0x4154, } diff --git a/src/infrastructure/catbuffer/GeneratorUtils.ts b/src/infrastructure/catbuffer/GeneratorUtils.ts index 7e95285569..f1f8ecb3d3 100644 --- a/src/infrastructure/catbuffer/GeneratorUtils.ts +++ b/src/infrastructure/catbuffer/GeneratorUtils.ts @@ -25,7 +25,8 @@ export class GeneratorUtils { /** - * Converts a (64bit) uint8 array into a number array. + * Convert a UInt8Array input into an array of 2 numbers. + * Numbers in the returned array are cast to UInt32. * @param {Uint8Array} input A uint8 array. * @returns {number[]} The uint64 representation of the input. */ @@ -39,7 +40,7 @@ export class GeneratorUtils { } /** - * Read buffer into 32bits integer at given index. + * Read 4 bytes as a uint32 value from buffer bytes starting at given index. * @param {Uint8Array} bytes A uint8 array. * @param {number} index Index. * @returns {number} 32bits integer. @@ -49,7 +50,7 @@ export class GeneratorUtils { } /** - * Write uint to buffer + * Convert uint value into buffer * @param {number} uintValue A uint8 array. * @param {number} bufferSize Buffer size. * @returns {Uint8Array} @@ -57,39 +58,45 @@ export class GeneratorUtils { public static uintToBuffer(uintValue: number, bufferSize: number): Uint8Array { const buffer = new ArrayBuffer(bufferSize); const dataView = new DataView(buffer); - if (1 === bufferSize) { - dataView.setUint8(0, uintValue); - } else if (2 === bufferSize) { - dataView.setUint16(0, uintValue, true); - } else if (4 === bufferSize) { - dataView.setUint32(0, uintValue, true); - } else { - throw new Error('Unexpected bufferSize'); + try { + if (1 === bufferSize) { + dataView.setUint8(0, uintValue); + } else if (2 === bufferSize) { + dataView.setUint16(0, uintValue, true); + } else if (4 === bufferSize) { + dataView.setUint32(0, uintValue, true); + } else { + throw new Error('Unexpected bufferSize'); + } + return new Uint8Array(buffer); + } catch (e) { + throw new Error(`Converting uint value ${uintValue} into buffer with error: ${e}`); } - - return new Uint8Array(buffer); } /** - * Write uint to buffer + * Convert uint8 array buffer into number * @param {Uint8Array} buffer A uint8 array. * @returns {number} */ public static bufferToUint(buffer: Uint8Array): number { const dataView = new DataView(buffer.buffer); - if (1 === buffer.byteLength) { - return dataView.getUint8(0); - } else if (2 === buffer.byteLength) { - return dataView.getUint16(0, true); - } else if (4 === buffer.byteLength) { - return dataView.getUint32(0, true); - } - - throw new Error('Unexpected buffer size'); + try { + if (1 === buffer.byteLength) { + return dataView.getUint8(0); + } else if (2 === buffer.byteLength) { + return dataView.getUint16(0, true); + } else if (4 === buffer.byteLength) { + return dataView.getUint32(0, true); + } + throw new Error('Unexpected buffer size'); + } catch (e) { + throw new Error(`Converting buffer into number with error: ${e}`); + } } /** - * Write Uint64 to buffer + * Convert unit64 into buffer * @param {number} uintValue Uint64 (number[]). * @returns {Uint8Array} */ diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 76eac2be1a..ccc5579a04 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -16,7 +16,8 @@ import { KeyPair, SignSchema } from '../../core/crypto'; import { Convert } from '../../core/format'; -import { AggregateTransactionBuilder } from '../../infrastructure/catbuffer/AggregateTransactionBuilder'; +import { AggregateBondedTransactionBuilder } from '../../infrastructure/catbuffer/AggregateBondedTransactionBuilder'; +import { AggregateCompleteTransactionBuilder } from '../../infrastructure/catbuffer/AggregateCompleteTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { CosignatureBuilder } from '../../infrastructure/catbuffer/CosignatureBuilder'; import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; @@ -130,7 +131,7 @@ export class AggregateTransaction extends Transaction { * @returns {AggregateTransaction} */ public static createFromPayload(payload: string, signSchema: SignSchema = SignSchema.SHA3): AggregateTransaction { - const builder = AggregateTransactionBuilder + const builder = AggregateCompleteTransactionBuilder .loadFromBinary(Convert.hexToUint8(payload)); const type = builder.getType().valueOf(); const innerTransactionHex = Convert.uint8ToHex(builder.getTransactions()); @@ -297,16 +298,27 @@ export class AggregateTransaction extends Transaction { cosignatures = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); }); - const transactionBuilder = new AggregateTransactionBuilder( - new SignatureDto(signatureBuffer), - new KeyDto(signerBuffer), - this.versionToDTO(), - this.type.valueOf(), - new AmountDto(this.maxFee.toDTO()), - new TimestampDto(this.deadline.toDTO()), - transactions, - cosignatures, - ); + const transactionBuilder = this.type === TransactionType.AGGREGATE_COMPLETE ? + new AggregateCompleteTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + this.type.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + transactions, + cosignatures, + ) : + new AggregateBondedTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + this.type.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + transactions, + cosignatures, + ); return transactionBuilder.serialize(); } From 2194c8a86cabc69660bef5829b87417b4153b1af Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 19 Aug 2019 20:58:08 +0100 Subject: [PATCH 77/98] Fixed aggregate transaction creatFromPayload - Catbuffer use separate builder class for Complete and Bonded - Added unit tests --- src/model/transaction/AggregateTransaction.ts | 11 +++++--- test/core/utils/TransactionMapping.spec.ts | 2 ++ .../transaction/AggregateTransaction.spec.ts | 27 +++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index ccc5579a04..591fa6182e 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -131,9 +131,14 @@ export class AggregateTransaction extends Transaction { * @returns {AggregateTransaction} */ public static createFromPayload(payload: string, signSchema: SignSchema = SignSchema.SHA3): AggregateTransaction { - const builder = AggregateCompleteTransactionBuilder - .loadFromBinary(Convert.hexToUint8(payload)); - const type = builder.getType().valueOf(); + /** + * Get transaction type from the payload hex + * As buffer uses separate builder class for Complete and bonded + */ + const type = parseInt(Convert.uint8ToHex(Convert.hexToUint8(payload.substring(204, 208)).reverse()), 16); + const builder = type === TransactionType.AGGREGATE_COMPLETE ? + AggregateCompleteTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AggregateBondedTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); const innerTransactionHex = Convert.uint8ToHex(builder.getTransactions()); const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; const consignaturesHex = Convert.uint8ToHex(builder.getCosignatures()); diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index e0e66628a0..3ba2e99fb7 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -440,6 +440,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AggregateTransaction; + expect(transaction.type).to.be.equal(TransactionType.AGGREGATE_COMPLETE); expect(transaction.innerTransactions[0].type).to.be.equal(TransactionType.TRANSFER); }); @@ -462,6 +463,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AggregateTransaction; + expect(transaction.type).to.be.equal(TransactionType.AGGREGATE_BONDED); expect(transaction.innerTransactions[0].type).to.be.equal(TransactionType.TRANSFER); }); diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 8bf2bfb730..4e8c4227e6 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -265,6 +265,33 @@ describe('AggregateTransaction', () => { }); + it('should createBonded an AggregateTransaction object with TransferTransaction', () => { + const transferTransaction = TransferTransaction.create( + Deadline.create(), + Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + [], + PlainMessage.create('test-message'), + NetworkType.MIJIN_TEST, + ); + + const aggregateTransaction = AggregateTransaction.createBonded( + Deadline.create(2, ChronoUnit.MINUTES), + [transferTransaction.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); + expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); + expect(signedTransaction.payload.substring(204, 208)).to.be.equal('4142'); + expect(signedTransaction.payload.substring( + 320, + signedTransaction.payload.length, + )).to.be.equal('019054419050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000000746573742D6D657373616765'); + }); + it('should validate if accounts have signed an aggregate transaction', () => { const aggregateTransactionDTO = { meta: { From 51fc076e296380c609147a360e692affbde8ed5c Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 21:43:04 +0100 Subject: [PATCH 78/98] Added ts catbuffer codes (without aggregateTx) Appended new signwithCatbuffer method in Transaction (temp) Applied catbuffer builders on standalone transaction (builder) Updated unit tests --- .../AccountAddressRestrictionTransaction.ts | 73 ++++----------- .../AccountMosaicRestrictionTransaction.ts | 77 +++++----------- .../AccountOperationRestrictionTransaction.ts | 89 ++++++------------- .../transaction/AddressAliasTransaction.ts | 1 + .../MosaicDefinitionTransaction.ts | 13 +++ .../AccountLinkTransaction.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 6 +- .../AddressAliasTransaction.spec.ts | 2 +- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- .../MosaicAliasTransaction.spec.ts | 2 +- .../MosaicDefinitionTransaction.spec.ts | 2 +- test/model/transaction/Transaction.spec.ts | 4 + 12 files changed, 90 insertions(+), 183 deletions(-) diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index 417dafba7b..243b4ff560 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -14,24 +14,23 @@ * limitations under the License. */ -import { SignSchema } from '../../core/crypto/SignSchema'; -import { Convert, RawAddress } from '../../core/format'; +import { RawAddress } from '../../core/format'; +import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; +import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { EmbeddedAccountAddressRestrictionTransactionBuilder }from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; -import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; -import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -85,36 +84,6 @@ export class AccountAddressRestrictionTransaction extends Transaction { networkType, version, deadline, maxFee, signature, signer, transactionInfo); } - /** - * Create a transaction object from payload - * @param {string} payload Binary payload - * @param {Boolean} isEmbedded Is embedded transaction (Default: false) - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {Transaction | InnerTransaction} - */ - public static createFromPayload(payload: string, - isEmbedded: boolean = false, - signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { - const builder = isEmbedded ? EmbeddedAccountAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : - AccountAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); - const signer = Convert.uint8ToHex(builder.getSigner().key); - const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; - const transaction = AccountAddressRestrictionTransaction.create( - isEmbedded ? Deadline.create() : Deadline.createFromDTO( - (builder as AccountAddressRestrictionTransactionBuilder).getDeadline().timestamp), - builder.getRestrictionType().valueOf(), - builder.getModifications().map((modification) => { - return AccountRestrictionModification.createForAddress( - modification.modificationAction.valueOf(), - Address.createFromEncoded(Convert.uint8ToHex(modification.value.unresolvedAddress)), - ); - }), - networkType, - isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountAddressRestrictionTransactionBuilder).fee.amount), - ); - return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; - } - /** * @override Transaction.size() * @description get the byte size of a AccountAddressRestrictionTransaction @@ -136,6 +105,20 @@ export class AccountAddressRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } + /** + * @internal + * @returns {VerifiableTransaction} + */ + protected buildTransaction(): VerifiableTransaction { + return new Builder() + .addDeadline(this.deadline.toDTO()) + .addFee(this.maxFee.toDTO()) + .addVersion(this.versionToDTO()) + .addRestrictionType(this.restrictionType) + .addModifications(this.modifications.map((modification) => modification.toDTO())) + .build(); + } + /** * @internal * @returns {Uint8Array} @@ -161,24 +144,4 @@ export class AccountAddressRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } - - /** - * @internal - * @returns {Uint8Array} - */ - protected generateEmbeddedBytes(): Uint8Array { - const transactionBuilder = new EmbeddedAccountAddressRestrictionTransactionBuilder( - new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), - this.versionToDTO(), - TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), - this.restrictionType.valueOf(), - this.modifications.map((modification) => { - return new AccountAddressRestrictionModificationBuilder( - modification.modificationType.valueOf(), - new UnresolvedAddressDto(RawAddress.stringToAddress(modification.value)), - ); - }), - ); - return transactionBuilder.serialize(); - } } diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index 496fe2b64f..cfac1c3ea1 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -14,23 +14,22 @@ * limitations under the License. */ -import { SignSchema } from '../../core/crypto/SignSchema'; -import { Convert } from '../../core/format'; +import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; +import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { EmbeddedAccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; import { PublicAccount } from '../account/PublicAccount'; +import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; -import { MosaicId } from '../mosaic/MosaicId'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; -import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -48,7 +47,7 @@ export class AccountMosaicRestrictionTransaction extends Transaction { * @returns {AccountAddressRestrictionTransaction} */ public static create(deadline: Deadline, - restrictionType: AccountRestrictionType, + restrictionType: RestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountMosaicRestrictionTransaction { @@ -75,7 +74,7 @@ export class AccountMosaicRestrictionTransaction extends Transaction { version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: AccountRestrictionType, + public readonly restrictionType: RestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, @@ -84,36 +83,6 @@ export class AccountMosaicRestrictionTransaction extends Transaction { networkType, version, deadline, maxFee, signature, signer, transactionInfo); } - /** - * Create a transaction object from payload - * @param {string} payload Binary payload - * @param {Boolean} isEmbedded Is embedded transaction (Default: false) - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {Transaction | InnerTransaction} - */ - public static createFromPayload(payload: string, - isEmbedded: boolean = false, - signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { - const builder = isEmbedded ? EmbeddedAccountMosaicRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : - AccountMosaicRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); - const signer = Convert.uint8ToHex(builder.getSigner().key); - const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; - const transaction = AccountMosaicRestrictionTransaction.create( - isEmbedded ? Deadline.create() : Deadline.createFromDTO( - (builder as AccountMosaicRestrictionTransactionBuilder).getDeadline().timestamp), - builder.getRestrictionType().valueOf(), - builder.getModifications().map((modification) => { - return AccountRestrictionModification.createForMosaic( - modification.modificationAction.valueOf(), - new MosaicId(modification.value.unresolvedMosaicId), - ); - }), - networkType, - isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountMosaicRestrictionTransactionBuilder).fee.amount), - ); - return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; - } - /** * @override Transaction.size() * @description get the byte size of a AccountMosaicRestrictionTransaction @@ -135,6 +104,20 @@ export class AccountMosaicRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } + /** + * @internal + * @returns {VerifiableTransaction} + */ + protected buildTransaction(): VerifiableTransaction { + return new Builder() + .addDeadline(this.deadline.toDTO()) + .addFee(this.maxFee.toDTO()) + .addVersion(this.versionToDTO()) + .addRestrictionType(this.restrictionType) + .addModifications(this.modifications.map((modification) => modification.toDTO())) + .build(); + } + /** * @internal * @returns {Uint8Array} @@ -160,24 +143,4 @@ export class AccountMosaicRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } - - /** - * @internal - * @returns {Uint8Array} - */ - protected generateEmbeddedBytes(): Uint8Array { - const transactionBuilder = new EmbeddedAccountMosaicRestrictionTransactionBuilder( - new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), - this.versionToDTO(), - TransactionType.ACCOUNT_RESTRICTION_MOSAIC.valueOf(), - this.restrictionType.valueOf(), - this.modifications.map((modification) => { - return new AccountMosaicRestrictionModificationBuilder( - modification.modificationType.valueOf(), - new UnresolvedMosaicIdDto(modification.value), - ); - }), - ); - return transactionBuilder.serialize(); - } } diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index f60abe0115..4ed72af488 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -14,26 +14,25 @@ * limitations under the License. */ -import { SignSchema } from '../../core/crypto/SignSchema'; -import { Convert } from '../../core/format'; -import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; -import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; -import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { EmbeddedAccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder'; -import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; -import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; -import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; -import { AccountRestrictionType } from '../account/AccountRestrictionType'; +import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; +import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { PublicAccount } from '../account/PublicAccount'; +import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; -import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; export class AccountOperationRestrictionTransaction extends Transaction { @@ -47,7 +46,7 @@ export class AccountOperationRestrictionTransaction extends Transaction { * @returns {AccountOperationRestrictionTransaction} */ public static create(deadline: Deadline, - restrictionType: AccountRestrictionType, + restrictionType: RestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountOperationRestrictionTransaction { @@ -74,7 +73,7 @@ export class AccountOperationRestrictionTransaction extends Transaction { version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: AccountRestrictionType, + public readonly restrictionType: RestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, @@ -83,36 +82,6 @@ export class AccountOperationRestrictionTransaction extends Transaction { networkType, version, deadline, maxFee, signature, signer, transactionInfo); } - /** - * Create a transaction object from payload - * @param {string} payload Binary payload - * @param {Boolean} isEmbedded Is embedded transaction (Default: false) - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {Transaction | InnerTransaction} - */ - public static createFromPayload(payload: string, - isEmbedded: boolean = false, - signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { - const builder = isEmbedded ? EmbeddedAccountOperationRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : - AccountOperationRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); - const signer = Convert.uint8ToHex(builder.getSigner().key); - const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; - const transaction = AccountOperationRestrictionTransaction.create( - isEmbedded ? Deadline.create() : Deadline.createFromDTO( - (builder as AccountOperationRestrictionTransactionBuilder).getDeadline().timestamp), - builder.getRestrictionType().valueOf(), - builder.getModifications().map((modification) => { - return AccountRestrictionModification.createForOperation( - modification.modificationAction.valueOf(), - modification.value.valueOf(), - ); - }), - networkType, - isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountOperationRestrictionTransactionBuilder).fee.amount), - ); - return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; - } - /** * @override Transaction.size() * @description get the byte size of a AccountOperationRestrictionTransaction @@ -134,6 +103,20 @@ export class AccountOperationRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } + /** + * @internal + * @returns {VerifiableTransaction} + */ + protected buildTransaction(): VerifiableTransaction { + return new Builder() + .addDeadline(this.deadline.toDTO()) + .addFee(this.maxFee.toDTO()) + .addVersion(this.versionToDTO()) + .addRestrictionType(this.restrictionType) + .addModifications(this.modifications.map((modification) => modification.toDTO())) + .build(); + } + /** * @internal * @returns {Uint8Array} @@ -159,24 +142,4 @@ export class AccountOperationRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } - - /** - * @internal - * @returns {Uint8Array} - */ - protected generateEmbeddedBytes(): Uint8Array { - const transactionBuilder = new EmbeddedAccountOperationRestrictionTransactionBuilder( - new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), - this.versionToDTO(), - TransactionType.ACCOUNT_RESTRICTION_OPERATION.valueOf(), - this.restrictionType.valueOf(), - this.modifications.map((modification) => { - return new AccountOperationRestrictionModificationBuilder( - modification.modificationType.valueOf(), - modification.value.valueOf(), - ); - }), - ); - return transactionBuilder.serialize(); - } } diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 3975b926dc..55d57062f6 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -36,6 +36,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { RawAddress } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 1616044875..c85be5cf92 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -39,6 +39,19 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; +import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; +import { MosaicFlagsDto } from '../../infrastructure/catbuffer/MosaicFlagsDto'; +import { MosaicFlags } from '../mosaic/MosaicFlag'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { Convert } from '../../core/format'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; /** * Before a mosaic can be created or transferred, a corresponding definition of the mosaic has to be created and published to the network. diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index ec2fe1630d..a6e52cc69c 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountLinkTransaction', () => { expect(accountLinkTransaction.linkAction).to.be.equal(1); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); - const signedTransaction = accountLinkTransaction.signWith(account, generationHash); + const signedTransaction = accountLinkTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 7fd1087647..e65f359a9c 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -162,7 +162,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = addressRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -213,7 +213,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -266,7 +266,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = operationRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index 59b1ce1144..1229abc20b 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('AddressAliasTransaction', () => { expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = addressAliasTransaction.signWith(account, generationHash); + const signedTransaction = addressAliasTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index 00afd72d47..4943e33e1f 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -110,7 +110,7 @@ describe('ModifyMultisigAccountTransaction', () => { expect(modifyMultisigAccountTransaction.modifications[1].cosignatoryPublicAccount.publicKey) .to.be.equal('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); - const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); + const signedTransaction = modifyMultisigAccountTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index 34184eff95..e2b8fffd90 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('MosaicAliasTransaction', () => { expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); expect(mosaicAliasTransaction.mosaicId.id.higher).to.be.equal(3405110546); - const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); + const signedTransaction = mosaicAliasTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index f444278cbe..52481c3ee8 100644 --- a/test/model/transaction/MosaicDefinitionTransaction.spec.ts +++ b/test/model/transaction/MosaicDefinitionTransaction.spec.ts @@ -93,7 +93,7 @@ describe('MosaicDefinitionTransaction', () => { expect(mosaicDefinitionTransaction.mosaicProperties.transferable).to.be.equal(true); expect(mosaicDefinitionTransaction.mosaicProperties.restrictable).to.be.equal(true); - const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicDefinitionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index d0baad099a..7488e3ca3d 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -241,4 +241,8 @@ class FakeTransaction extends Transaction { protected generateEmbeddedBytes(): Uint8Array { throw new Error('Not implemented'); } + + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } From 7f19820a9e0bc45cfbfb54c22b68174f63bd95d0 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 22:38:29 +0100 Subject: [PATCH 79/98] Manually added aggregate transaction builder --- .../catbuffer/AggregateTransactionBuilder.ts | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 src/infrastructure/catbuffer/AggregateTransactionBuilder.ts diff --git a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts new file mode 100644 index 0000000000..64b11c499f --- /dev/null +++ b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts @@ -0,0 +1,136 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** along with Catapult. If not, see . +**/ + +import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; +import { AddressDto } from './AddressDto'; +import { AliasActionDto } from './AliasActionDto'; +import { AmountDto } from './AmountDto'; +import { EntityTypeDto } from './EntityTypeDto'; +import { GeneratorUtils } from './GeneratorUtils'; +import { KeyDto } from './KeyDto'; +import { NamespaceIdDto } from './NamespaceIdDto'; +import { SignatureDto } from './SignatureDto'; +import { TimestampDto } from './TimestampDto'; +import { TransactionBuilder } from './TransactionBuilder'; + +/** binary layout for an aggregate transaction. */ +export class AggregateTransactionBuilder extends TransactionBuilder { + /** embedded transactions. */ + transactions: Uint8Array; + /** cosignatures. */ + cosignatures: Uint8Array; + + /** + * Constructor. + * + * @param signature entity signature. + * @param signer entity signer's public key. + * @param version entity version. + * @param type entity type. + * @param fee transaction fee. + * @param deadline transaction deadline. + * @param transactions embedded transactions. + * @param cosignatures cosignatures. + */ + public constructor( + signature: SignatureDto, + signer: KeyDto, + version: number, + type: EntityTypeDto, + fee: AmountDto, + deadline: TimestampDto, + transactions: Uint8Array, + cosignatures: Uint8Array) { + super(signature, signer, version, type, fee, deadline); + this.transactions = transactions; + this.cosignatures = cosignatures; + } + + /** + * loadFromBinary - Create an instance of AggregateTransactionBuilder from a stream. + * + * @param Uint8Array Byte to use to serialize the object. + * @return An instance of AggregateTransactionBuilder. + */ + public static loadFromBinary(payload: Uint8Array): AggregateTransactionBuilder { + const byteArray = Array.from(payload); + const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); + byteArray.splice(0, superObject.getSize()); + const payloadSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); + byteArray.splice(0, 4); + const transactions = GeneratorUtils.getBytes(Uint8Array.from(byteArray), payloadSize); + byteArray.splice(0, transactions.length); + const cosignatures = Uint8Array.from(byteArray); + // tslint:disable-next-line: max-line-length + return new AggregateTransactionBuilder(superObject.signature, superObject.signer, superObject.version, + superObject.type, superObject.fee, superObject.deadline, + transactions, cosignatures); + } + + /** + * Get embedded transactions. + * + * @return embedded transactions. + */ + public getTransactions(): Uint8Array { + return this.transactions; + } + + /** + * Get cosignatures. + * + * @return cosignatures. + */ + public getCosignatures(): Uint8Array { + return this.cosignatures; + } + + /** + * Get the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += 4; // payloadSize + size += this.transactions.length; + size += this.cosignatures.length; + return size; + } + + /** + * Serialize the object to bytes. + * + * @return Serialized bytes. + */ + public serialize(): Uint8Array { + let newArray = Uint8Array.from([]); + const superBytes = super.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); + const payloadSizeBytes = GeneratorUtils.uintToBuffer(this.transactions.length, 4); + newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes); + const transactionBytes = this.transactions; + newArray = GeneratorUtils.concatTypedArrays(newArray, transactionBytes); + const cosignaturesBytes = this.transactions; + newArray = GeneratorUtils.concatTypedArrays(newArray, cosignaturesBytes); + return newArray; + } +} From 99fd613d45e5d2cca55ffaed48a8654ff5ba1192 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 23:43:48 +0100 Subject: [PATCH 80/98] Added embedded transaction builders --- .../AccountAddressRestrictionTransaction.ts | 23 ++++++++++++ .../AccountMosaicRestrictionTransaction.ts | 23 ++++++++++++ .../AccountOperationRestrictionTransaction.ts | 36 +++++++++++++++---- .../transaction/AddressAliasTransaction.ts | 19 +++++++++- src/model/transaction/AggregateTransaction.ts | 8 +++++ .../ModifyMultisigAccountTransaction.ts | 24 +++++++++++++ .../transaction/MosaicAliasTransaction.ts | 18 ++++++++++ .../MosaicDefinitionTransaction.ts | 34 +++++++++++------- src/model/transaction/TransferTransaction.ts | 20 +++++++++++ ...osaicAddressRestrictionTransaction.spec.ts | 2 +- ...MosaicGlobalRestrictionTransaction.spec.ts | 2 +- .../RegisterNamespaceTransaction.spec.ts | 4 +-- test/model/transaction/Transaction.spec.ts | 4 +++ 13 files changed, 192 insertions(+), 25 deletions(-) diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index 243b4ff560..de89c65970 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -20,6 +20,7 @@ import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTra import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -144,4 +145,26 @@ export class AccountAddressRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountAddressRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountAddressRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedAddressDto(RawAddress.stringToAddress(modification.value)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index cfac1c3ea1..f8275cf7eb 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -19,6 +19,7 @@ import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTra import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder'; import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; @@ -143,4 +144,26 @@ export class AccountMosaicRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountMosaicRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_MOSAIC.valueOf(), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountMosaicRestrictionModificationBuilder( + modification.modificationType.valueOf(), + new UnresolvedMosaicIdDto(modification.value), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index 4ed72af488..ac24764f6c 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -16,6 +16,13 @@ import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; @@ -26,13 +33,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; -import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; -import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; -import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; -import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; export class AccountOperationRestrictionTransaction extends Transaction { @@ -142,4 +142,26 @@ export class AccountOperationRestrictionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAccountOperationRestrictionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_RESTRICTION_OPERATION.valueOf(), + this.restrictionType.valueOf(), + this.modifications.map((modification) => { + return new AccountOperationRestrictionModificationBuilder( + modification.modificationType.valueOf(), + modification.value.valueOf(), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 55d57062f6..c438b72a2b 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -36,7 +36,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { RawAddress } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -184,4 +183,22 @@ export class AddressAliasTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedAddressAliasTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ADDRESS_ALIAS.valueOf(), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new AddressDto(RawAddress.stringToAddress(this.address.plain())), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 591fa6182e..287a9c1ee3 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -334,4 +334,12 @@ export class AggregateTransaction extends Transaction { protected generateEmbeddedBytes(): Uint8Array { throw new Error('Method not implemented'); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + throw new Error('Not implemented'); + } } diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index 23dce96d81..456d93305f 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -33,6 +33,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; /** * Modify multisig account transactions are part of the NEM's multisig account system. @@ -206,4 +207,27 @@ export class ModifyMultisigAccountTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMultisigAccountModificationTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MODIFY_MULTISIG_ACCOUNT.valueOf(), + this.minRemovalDelta, + this.minApprovalDelta, + this.modifications.map((modification) => { + return new CosignatoryModificationBuilder( + modification.type.valueOf(), + new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)), + ); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index 6d7cae3183..fc7b26dba0 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -179,4 +179,22 @@ export class MosaicAliasTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicAliasTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_ALIAS.valueOf(), + this.actionType.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index c85be5cf92..14c84bc4d9 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -39,19 +39,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; -import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; -import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; -import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; -import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; -import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; -import { MosaicFlagsDto } from '../../infrastructure/catbuffer/MosaicFlagsDto'; -import { MosaicFlags } from '../mosaic/MosaicFlag'; -import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; -import { Convert } from '../../core/format'; -import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; /** * Before a mosaic can be created or transferred, a corresponding definition of the mosaic has to be created and published to the network. @@ -246,4 +233,25 @@ export class MosaicDefinitionTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + + const transactionBuilder = new EmbeddedMosaicDefinitionTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_DEFINITION.valueOf(), + new MosaicNonceDto(this.getMosaicNonceIntValue()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + this.getMosaicFlagValue(), + this.mosaicProperties.divisibility, + new BlockDurationDto(this.mosaicProperties.duration ? + this.mosaicProperties.duration.toDTO() : []), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index eb2daab1de..f9c425f544 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -263,4 +263,24 @@ export class TransferTransaction extends Transaction { ); return transactionBuilder.serialize(); } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const transactionBuilder = new EmbeddedTransferTransactionBuilder( + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.TRANSFER.valueOf(), + new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), + this.getMessageBuffer(), + this.sortMosaics().map((mosaic) => { + return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), + new AmountDto(mosaic.amount.toDTO())); + }), + ); + return transactionBuilder.serialize(); + } } diff --git a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts index 947904ce56..02aad2fc65 100644 --- a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts @@ -47,7 +47,7 @@ describe('MosaicAddressRestrictionTransaction', () => { expect(mosaicAddressRestrictionTransaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(8).toHex()); expect(mosaicAddressRestrictionTransaction.targetAddress.plain()).to.be.equal(account.address.plain()); - const signedTransaction = mosaicAddressRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicAddressRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts index 39c409bd22..9e436d2fea 100644 --- a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts @@ -54,7 +54,7 @@ describe('MosaicGlobalRestrictionTransaction', () => { expect(mosaicGlobalRestrictionTransaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.EQ); expect(mosaicGlobalRestrictionTransaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); - const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicGlobalRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/RegisterNamespaceTransaction.spec.ts b/test/model/transaction/RegisterNamespaceTransaction.spec.ts index dcd12d95f7..db497c73b9 100644 --- a/test/model/transaction/RegisterNamespaceTransaction.spec.ts +++ b/test/model/transaction/RegisterNamespaceTransaction.spec.ts @@ -66,7 +66,7 @@ describe('RegisterNamespaceTransaction', () => { expect(registerNamespaceTransaction.duration!.lower).to.be.equal(1000); expect(registerNamespaceTransaction.duration!.higher).to.be.equal(0); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -83,7 +83,7 @@ describe('RegisterNamespaceTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index 7488e3ca3d..cec65bb6e0 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -245,4 +245,8 @@ class FakeTransaction extends Transaction { protected generateBytes(): Uint8Array { throw new Error('Not implemented'); } + + protected generateEmbeddedBytes(): Uint8Array { + throw new Error('Not implemented'); + } } From 0749efe3c4fbd5f9cc4fbfb767fb59be17a70fa5 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 08:26:17 +0100 Subject: [PATCH 81/98] Applied catbuffer on aggregate transaction --- src/infrastructure/catbuffer/AggregateTransactionBuilder.ts | 6 +----- .../transaction/AccountAddressRestrictionTransaction.ts | 6 ++---- .../transaction/AccountMosaicRestrictionTransaction.ts | 6 ++---- .../transaction/AccountOperationRestrictionTransaction.ts | 5 ++--- src/model/transaction/AddressAliasTransaction.ts | 4 +--- src/model/transaction/AggregateTransaction.ts | 2 +- src/model/transaction/ModifyMultisigAccountTransaction.ts | 4 +--- src/model/transaction/MosaicAliasTransaction.ts | 4 +--- src/model/transaction/MosaicDefinitionTransaction.ts | 4 +--- src/model/transaction/MosaicSupplyChangeTransaction.ts | 1 + src/model/transaction/TransferTransaction.ts | 3 +-- test/model/transaction/AggregateTransaction.spec.ts | 2 +- 12 files changed, 15 insertions(+), 32 deletions(-) diff --git a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts index 64b11c499f..20462d8514 100644 --- a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts +++ b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts @@ -19,14 +19,10 @@ *** along with Catapult. If not, see . **/ -import { AddressAliasTransactionBodyBuilder } from './AddressAliasTransactionBodyBuilder'; -import { AddressDto } from './AddressDto'; -import { AliasActionDto } from './AliasActionDto'; import { AmountDto } from './AmountDto'; import { EntityTypeDto } from './EntityTypeDto'; import { GeneratorUtils } from './GeneratorUtils'; import { KeyDto } from './KeyDto'; -import { NamespaceIdDto } from './NamespaceIdDto'; import { SignatureDto } from './SignatureDto'; import { TimestampDto } from './TimestampDto'; import { TransactionBuilder } from './TransactionBuilder'; @@ -129,7 +125,7 @@ export class AggregateTransactionBuilder extends TransactionBuilder { newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes); const transactionBytes = this.transactions; newArray = GeneratorUtils.concatTypedArrays(newArray, transactionBytes); - const cosignaturesBytes = this.transactions; + const cosignaturesBytes = this.cosignatures; newArray = GeneratorUtils.concatTypedArrays(newArray, cosignaturesBytes); return newArray; } diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index de89c65970..fd4200205c 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { RawAddress } from '../../core/format'; +import { Convert, RawAddress } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; @@ -151,10 +151,8 @@ export class AccountAddressRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountAddressRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(), this.restrictionType.valueOf(), diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index f8275cf7eb..efe54c41d8 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -14,13 +14,13 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; @@ -150,10 +150,8 @@ export class AccountMosaicRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountMosaicRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ACCOUNT_RESTRICTION_MOSAIC.valueOf(), this.restrictionType.valueOf(), diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index ac24764f6c..b42d33e3ab 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { Convert } from '../../core/format'; import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; @@ -148,10 +149,8 @@ export class AccountOperationRestrictionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAccountOperationRestrictionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ACCOUNT_RESTRICTION_OPERATION.valueOf(), this.restrictionType.valueOf(), diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index c438b72a2b..9b18e9db4a 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -189,10 +189,8 @@ export class AddressAliasTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedAddressAliasTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.ADDRESS_ALIAS.valueOf(), this.actionType.valueOf(), diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 287a9c1ee3..06ed339e99 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -340,6 +340,6 @@ export class AggregateTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - throw new Error('Not implemented'); + throw new Error('Method not implemented'); } } diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index 456d93305f..83e0280b06 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -213,10 +213,8 @@ export class ModifyMultisigAccountTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMultisigAccountModificationTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MODIFY_MULTISIG_ACCOUNT.valueOf(), this.minRemovalDelta, diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index fc7b26dba0..c4255e2fae 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -185,10 +185,8 @@ export class MosaicAliasTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicAliasTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_ALIAS.valueOf(), this.actionType.valueOf(), diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 14c84bc4d9..090e644c9b 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -239,10 +239,8 @@ export class MosaicDefinitionTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); - const transactionBuilder = new EmbeddedMosaicDefinitionTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.MOSAIC_DEFINITION.valueOf(), new MosaicNonceDto(this.getMosaicNonceIntValue()), diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index 1ee6fc22d7..df87f5617c 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -34,6 +34,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { Convert } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index f9c425f544..8548f706bb 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -269,9 +269,8 @@ export class TransferTransaction extends Transaction { * @returns {Uint8Array} */ protected generateEmbeddedBytes(): Uint8Array { - const signerBuffer = new Uint8Array(32); const transactionBuilder = new EmbeddedTransferTransactionBuilder( - new KeyDto(signerBuffer), + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), this.versionToDTO(), TransactionType.TRANSFER.valueOf(), new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 4e8c4227e6..7e64c38f4a 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -106,7 +106,7 @@ describe('AggregateTransaction', () => { NetworkType.MIJIN_TEST, []); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); + const signedTransaction = aggregateTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); From cba64e5bbcbfc9901eac2f9ed71c611134ba403d Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 11:46:27 +0100 Subject: [PATCH 82/98] Removed old flatbuffer staffs --- e2e/conf/network.conf | 2 +- .../AccountAddressRestrictionTransaction.ts | 17 ----------------- .../AccountMosaicRestrictionTransaction.ts | 16 ---------------- .../AccountOperationRestrictionTransaction.ts | 16 ---------------- src/model/transaction/AggregateTransaction.ts | 7 ------- .../ModifyMultisigAccountTransaction.ts | 1 - .../MosaicDefinitionTransaction.ts | 19 ------------------- .../MosaicSupplyChangeTransaction.ts | 1 - src/model/transaction/TransferTransaction.ts | 19 ------------------- .../AccountLinkTransaction.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 6 +++--- .../AddressAliasTransaction.spec.ts | 2 +- .../transaction/AggregateTransaction.spec.ts | 2 +- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- ...osaicAddressRestrictionTransaction.spec.ts | 2 +- .../MosaicAliasTransaction.spec.ts | 2 +- .../MosaicDefinitionTransaction.spec.ts | 2 +- ...MosaicGlobalRestrictionTransaction.spec.ts | 2 +- .../RegisterNamespaceTransaction.spec.ts | 4 ++-- test/model/transaction/Transaction.spec.ts | 8 -------- 20 files changed, 14 insertions(+), 118 deletions(-) diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index 150443d82d..a19e2213f0 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -51,4 +51,4 @@ "publicKey": "FAEDB16763F22870B75BF934EA5F2792BDF109EC0C504718DDCBD92DF13C2628", "address": "SCNPFCWFV2FYQVMU5HMJJTMADRZ3LRXVA76F56N2" } -} \ No newline at end of file +} diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index fd4200205c..150cd213b6 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -15,13 +15,10 @@ */ import { Convert, RawAddress } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; @@ -106,20 +103,6 @@ export class AccountAddressRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRestrictionType(this.restrictionType) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index efe54c41d8..be182d398b 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -105,20 +103,6 @@ export class AccountMosaicRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRestrictionType(this.restrictionType) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index b42d33e3ab..3ee53a4b4d 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -15,8 +15,6 @@ */ import { Convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; @@ -104,20 +102,6 @@ export class AccountOperationRestrictionTransaction extends Transaction { return byteSize + byteRestrictionType + byteModificationCount + byteModifications; } - /** - * @internal - * @returns {VerifiableTransaction} - */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRestrictionType(this.restrictionType) - .addModifications(this.modifications.map((modification) => modification.toDTO())) - .build(); - } - /** * @internal * @returns {Uint8Array} diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 06ed339e99..29d8848bbd 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -335,11 +335,4 @@ export class AggregateTransaction extends Transaction { throw new Error('Method not implemented'); } - /** - * @internal - * @returns {Uint8Array} - */ - protected generateEmbeddedBytes(): Uint8Array { - throw new Error('Method not implemented'); - } } diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index 83e0280b06..89e126a7eb 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -33,7 +33,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder'; /** * Modify multisig account transactions are part of the NEM's multisig account system. diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 090e644c9b..1616044875 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -233,23 +233,4 @@ export class MosaicDefinitionTransaction extends Transaction { ); return transactionBuilder.serialize(); } - - /** - * @internal - * @returns {Uint8Array} - */ - protected generateEmbeddedBytes(): Uint8Array { - const transactionBuilder = new EmbeddedMosaicDefinitionTransactionBuilder( - new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), - this.versionToDTO(), - TransactionType.MOSAIC_DEFINITION.valueOf(), - new MosaicNonceDto(this.getMosaicNonceIntValue()), - new MosaicIdDto(this.mosaicId.id.toDTO()), - this.getMosaicFlagValue(), - this.mosaicProperties.divisibility, - new BlockDurationDto(this.mosaicProperties.duration ? - this.mosaicProperties.duration.toDTO() : []), - ); - return transactionBuilder.serialize(); - } } diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index df87f5617c..1ee6fc22d7 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -34,7 +34,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { Convert } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 8548f706bb..eb2daab1de 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -263,23 +263,4 @@ export class TransferTransaction extends Transaction { ); return transactionBuilder.serialize(); } - - /** - * @internal - * @returns {Uint8Array} - */ - protected generateEmbeddedBytes(): Uint8Array { - const transactionBuilder = new EmbeddedTransferTransactionBuilder( - new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), - this.versionToDTO(), - TransactionType.TRANSFER.valueOf(), - new UnresolvedAddressDto(RawAddress.stringToAddress(this.recipientToString())), - this.getMessageBuffer(), - this.sortMosaics().map((mosaic) => { - return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), - new AmountDto(mosaic.amount.toDTO())); - }), - ); - return transactionBuilder.serialize(); - } } diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index a6e52cc69c..ec2fe1630d 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountLinkTransaction', () => { expect(accountLinkTransaction.linkAction).to.be.equal(1); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); - const signedTransaction = accountLinkTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = accountLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index e65f359a9c..7fd1087647 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -162,7 +162,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = addressRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -213,7 +213,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = mosaicRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -266,7 +266,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = operationRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index 1229abc20b..59b1ce1144 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('AddressAliasTransaction', () => { expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = addressAliasTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = addressAliasTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 7e64c38f4a..4e8c4227e6 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -106,7 +106,7 @@ describe('AggregateTransaction', () => { NetworkType.MIJIN_TEST, []); - const signedTransaction = aggregateTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index 4943e33e1f..00afd72d47 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -110,7 +110,7 @@ describe('ModifyMultisigAccountTransaction', () => { expect(modifyMultisigAccountTransaction.modifications[1].cosignatoryPublicAccount.publicKey) .to.be.equal('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); - const signedTransaction = modifyMultisigAccountTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts index 02aad2fc65..947904ce56 100644 --- a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts @@ -47,7 +47,7 @@ describe('MosaicAddressRestrictionTransaction', () => { expect(mosaicAddressRestrictionTransaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(8).toHex()); expect(mosaicAddressRestrictionTransaction.targetAddress.plain()).to.be.equal(account.address.plain()); - const signedTransaction = mosaicAddressRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicAddressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index e2b8fffd90..34184eff95 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('MosaicAliasTransaction', () => { expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); expect(mosaicAliasTransaction.mosaicId.id.higher).to.be.equal(3405110546); - const signedTransaction = mosaicAliasTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index 52481c3ee8..f444278cbe 100644 --- a/test/model/transaction/MosaicDefinitionTransaction.spec.ts +++ b/test/model/transaction/MosaicDefinitionTransaction.spec.ts @@ -93,7 +93,7 @@ describe('MosaicDefinitionTransaction', () => { expect(mosaicDefinitionTransaction.mosaicProperties.transferable).to.be.equal(true); expect(mosaicDefinitionTransaction.mosaicProperties.restrictable).to.be.equal(true); - const signedTransaction = mosaicDefinitionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts index 9e436d2fea..39c409bd22 100644 --- a/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicGlobalRestrictionTransaction.spec.ts @@ -54,7 +54,7 @@ describe('MosaicGlobalRestrictionTransaction', () => { expect(mosaicGlobalRestrictionTransaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.EQ); expect(mosaicGlobalRestrictionTransaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); - const signedTransaction = mosaicGlobalRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/RegisterNamespaceTransaction.spec.ts b/test/model/transaction/RegisterNamespaceTransaction.spec.ts index db497c73b9..dcd12d95f7 100644 --- a/test/model/transaction/RegisterNamespaceTransaction.spec.ts +++ b/test/model/transaction/RegisterNamespaceTransaction.spec.ts @@ -66,7 +66,7 @@ describe('RegisterNamespaceTransaction', () => { expect(registerNamespaceTransaction.duration!.lower).to.be.equal(1000); expect(registerNamespaceTransaction.duration!.higher).to.be.equal(0); - const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -83,7 +83,7 @@ describe('RegisterNamespaceTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = registerNamespaceTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index cec65bb6e0..d0baad099a 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -241,12 +241,4 @@ class FakeTransaction extends Transaction { protected generateEmbeddedBytes(): Uint8Array { throw new Error('Not implemented'); } - - protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); - } - - protected generateEmbeddedBytes(): Uint8Array { - throw new Error('Not implemented'); - } } From a70afb477c81515985c3432422160245b9dfae05 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 12:16:52 +0100 Subject: [PATCH 83/98] restored network config for e2e --- e2e/conf/network.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index a19e2213f0..150443d82d 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -51,4 +51,4 @@ "publicKey": "FAEDB16763F22870B75BF934EA5F2792BDF109EC0C504718DDCBD92DF13C2628", "address": "SCNPFCWFV2FYQVMU5HMJJTMADRZ3LRXVA76F56N2" } -} +} \ No newline at end of file From e6a9f062e6f59b17ab29a7d6333608155f1f8835 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 7 Aug 2019 21:43:04 +0100 Subject: [PATCH 84/98] Added ts catbuffer codes (without aggregateTx) Appended new signwithCatbuffer method in Transaction (temp) Applied catbuffer builders on standalone transaction (builder) Updated unit tests --- .../AccountOperationRestrictionTransaction.ts | 7 ++ .../transaction/AddressAliasTransaction.ts | 1 + .../MosaicDefinitionTransaction.ts | 13 ++++ src/model/transaction/Transaction.ts | 66 ++++++++++++++++++- .../AccountLinkTransaction.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 6 +- .../AddressAliasTransaction.spec.ts | 2 +- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- .../MosaicAliasTransaction.spec.ts | 2 +- .../MosaicDefinitionTransaction.spec.ts | 2 +- test/model/transaction/Transaction.spec.ts | 4 ++ 11 files changed, 97 insertions(+), 10 deletions(-) diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index 3ee53a4b4d..07e19502f9 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -32,6 +32,13 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; +import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; export class AccountOperationRestrictionTransaction extends Transaction { diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 9b18e9db4a..2d89adcfc2 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -36,6 +36,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { RawAddress } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index 1616044875..c85be5cf92 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -39,6 +39,19 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; +import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; +import { MosaicFlagsDto } from '../../infrastructure/catbuffer/MosaicFlagsDto'; +import { MosaicFlags } from '../mosaic/MosaicFlag'; +import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; +import { Convert } from '../../core/format'; +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; /** * Before a mosaic can be created or transferred, a corresponding definition of the mosaic has to be created and published to the network. diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index 29d3ae1b3d..61dcccce4e 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -112,6 +112,16 @@ export abstract class Transaction { */ protected abstract generateEmbeddedBytes(): Uint8Array; + /** + * @internal + */ + protected abstract buildTransaction(): VerifiableTransaction; + + /** + * @internal + */ + protected abstract generateBytes(): Uint8Array; + /** * @internal * Serialize and sign transaction creating a new SignedTransaction @@ -142,8 +152,60 @@ export abstract class Transaction { } /** - * Converts the transaction into AggregateTransaction compatible - * @returns {Array.<*>} AggregateTransaction bytes + * @internal + * Serialize and sign transaction creating a new SignedTransaction + * @param account - The account to sign the transaction + * @param generationHash - Network generation hash hex + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {SignedTransaction} + */ + public signWithCatbuffer(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { + const generationHashBytes = Array.from(Convert.hexToUint8(generationHash)); + const byteBuffer = Array.from(this.generateBytes()); + const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); + const keyPairEncoded = KeyPair.createKeyPairFromPrivateKeyString(account.privateKey, signSchema); + const signature = Array.from(KeyPair.sign(account, new Uint8Array(signingBytes), signSchema)); + const signedTransactionBuffer = byteBuffer + .splice(0, 4) + .concat(signature) + .concat(Array.from(keyPairEncoded.publicKey)) + .concat(byteBuffer + .splice(64 + 32, byteBuffer.length)); + const payload = Convert.uint8ToHex(signedTransactionBuffer); + return new SignedTransaction( + payload, + this.createTransactionHash(payload, generationHashBytes), + account.publicKey, + this.type, + this.networkType); + } + + /** + * Generate transaction hash hex + * @param {string} transactionPayload HexString Payload + * @param {Array} generationHashBuffer Network generation hash byte + * @returns {string} Returns Transaction Payload hash + */ + public createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { + const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); + const signingBytes = byteBuffer + .slice(4, 36) + .concat(byteBuffer + .slice(4 + 64, 4 + 64 + 32)) + .concat(generationHashBuffer) + .concat(byteBuffer + .splice(4 + 64 + 32, byteBuffer.length)); + + const hash = new Uint8Array(32); + + SHA3Hasher.func(hash, signingBytes, 32); + + return Convert.uint8ToHex(hash); + } + + /** + * @internal + * @returns {Array} */ public aggregateTransaction(): number[] { const signer = Convert.hexToUint8(this.signer!.publicKey); diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index ec2fe1630d..a6e52cc69c 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountLinkTransaction', () => { expect(accountLinkTransaction.linkAction).to.be.equal(1); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); - const signedTransaction = accountLinkTransaction.signWith(account, generationHash); + const signedTransaction = accountLinkTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 7fd1087647..e65f359a9c 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -162,7 +162,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = addressRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -213,7 +213,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -266,7 +266,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); + const signedTransaction = operationRestrictionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index 59b1ce1144..1229abc20b 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('AddressAliasTransaction', () => { expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = addressAliasTransaction.signWith(account, generationHash); + const signedTransaction = addressAliasTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index 00afd72d47..4943e33e1f 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -110,7 +110,7 @@ describe('ModifyMultisigAccountTransaction', () => { expect(modifyMultisigAccountTransaction.modifications[1].cosignatoryPublicAccount.publicKey) .to.be.equal('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); - const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); + const signedTransaction = modifyMultisigAccountTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index 34184eff95..e2b8fffd90 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('MosaicAliasTransaction', () => { expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); expect(mosaicAliasTransaction.mosaicId.id.higher).to.be.equal(3405110546); - const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); + const signedTransaction = mosaicAliasTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index f444278cbe..52481c3ee8 100644 --- a/test/model/transaction/MosaicDefinitionTransaction.spec.ts +++ b/test/model/transaction/MosaicDefinitionTransaction.spec.ts @@ -93,7 +93,7 @@ describe('MosaicDefinitionTransaction', () => { expect(mosaicDefinitionTransaction.mosaicProperties.transferable).to.be.equal(true); expect(mosaicDefinitionTransaction.mosaicProperties.restrictable).to.be.equal(true); - const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); + const signedTransaction = mosaicDefinitionTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index d0baad099a..7488e3ca3d 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -241,4 +241,8 @@ class FakeTransaction extends Transaction { protected generateEmbeddedBytes(): Uint8Array { throw new Error('Not implemented'); } + + protected generateBytes(): Uint8Array { + throw new Error('Not implemented'); + } } From 12fe1b10994ded5576ae1b3c3c934cd8bcf3489e Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 08:26:17 +0100 Subject: [PATCH 85/98] Applied catbuffer on aggregate transaction --- src/model/transaction/MosaicSupplyChangeTransaction.ts | 1 + test/model/transaction/AggregateTransaction.spec.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index 1ee6fc22d7..df87f5617c 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -34,6 +34,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { Convert } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 4e8c4227e6..7e64c38f4a 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -106,7 +106,7 @@ describe('AggregateTransaction', () => { NetworkType.MIJIN_TEST, []); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); + const signedTransaction = aggregateTransaction.signWithCatbuffer(account, generationHash); expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); From e61ac934ac242e5eabd6bdc121072ba184bf104d Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 11:46:27 +0100 Subject: [PATCH 86/98] Removed old flatbuffer staffs --- e2e/conf/network.conf | 2 +- .../MosaicSupplyChangeTransaction.ts | 1 - src/model/transaction/Transaction.ts | 66 +------------------ .../AccountLinkTransaction.spec.ts | 2 +- .../AccountRestrictionTransaction.spec.ts | 6 +- .../AddressAliasTransaction.spec.ts | 2 +- .../transaction/AggregateTransaction.spec.ts | 2 +- .../ModifyMultisigAccountTransaction.spec.ts | 2 +- .../MosaicAliasTransaction.spec.ts | 2 +- .../MosaicDefinitionTransaction.spec.ts | 2 +- test/model/transaction/Transaction.spec.ts | 4 -- 11 files changed, 12 insertions(+), 79 deletions(-) diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index 150443d82d..a19e2213f0 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -51,4 +51,4 @@ "publicKey": "FAEDB16763F22870B75BF934EA5F2792BDF109EC0C504718DDCBD92DF13C2628", "address": "SCNPFCWFV2FYQVMU5HMJJTMADRZ3LRXVA76F56N2" } -} \ No newline at end of file +} diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index df87f5617c..1ee6fc22d7 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -34,7 +34,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { Convert } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, diff --git a/src/model/transaction/Transaction.ts b/src/model/transaction/Transaction.ts index 61dcccce4e..29d3ae1b3d 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -112,16 +112,6 @@ export abstract class Transaction { */ protected abstract generateEmbeddedBytes(): Uint8Array; - /** - * @internal - */ - protected abstract buildTransaction(): VerifiableTransaction; - - /** - * @internal - */ - protected abstract generateBytes(): Uint8Array; - /** * @internal * Serialize and sign transaction creating a new SignedTransaction @@ -152,60 +142,8 @@ export abstract class Transaction { } /** - * @internal - * Serialize and sign transaction creating a new SignedTransaction - * @param account - The account to sign the transaction - * @param generationHash - Network generation hash hex - * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) - * @returns {SignedTransaction} - */ - public signWithCatbuffer(account: Account, generationHash: string, signSchema: SignSchema = SignSchema.SHA3): SignedTransaction { - const generationHashBytes = Array.from(Convert.hexToUint8(generationHash)); - const byteBuffer = Array.from(this.generateBytes()); - const signingBytes = generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)); - const keyPairEncoded = KeyPair.createKeyPairFromPrivateKeyString(account.privateKey, signSchema); - const signature = Array.from(KeyPair.sign(account, new Uint8Array(signingBytes), signSchema)); - const signedTransactionBuffer = byteBuffer - .splice(0, 4) - .concat(signature) - .concat(Array.from(keyPairEncoded.publicKey)) - .concat(byteBuffer - .splice(64 + 32, byteBuffer.length)); - const payload = Convert.uint8ToHex(signedTransactionBuffer); - return new SignedTransaction( - payload, - this.createTransactionHash(payload, generationHashBytes), - account.publicKey, - this.type, - this.networkType); - } - - /** - * Generate transaction hash hex - * @param {string} transactionPayload HexString Payload - * @param {Array} generationHashBuffer Network generation hash byte - * @returns {string} Returns Transaction Payload hash - */ - public createTransactionHash(transactionPayload: string, generationHashBuffer: number[]): string { - const byteBuffer = Array.from(Convert.hexToUint8(transactionPayload)); - const signingBytes = byteBuffer - .slice(4, 36) - .concat(byteBuffer - .slice(4 + 64, 4 + 64 + 32)) - .concat(generationHashBuffer) - .concat(byteBuffer - .splice(4 + 64 + 32, byteBuffer.length)); - - const hash = new Uint8Array(32); - - SHA3Hasher.func(hash, signingBytes, 32); - - return Convert.uint8ToHex(hash); - } - - /** - * @internal - * @returns {Array} + * Converts the transaction into AggregateTransaction compatible + * @returns {Array.<*>} AggregateTransaction bytes */ public aggregateTransaction(): number[] { const signer = Convert.hexToUint8(this.signer!.publicKey); diff --git a/test/model/transaction/AccountLinkTransaction.spec.ts b/test/model/transaction/AccountLinkTransaction.spec.ts index a6e52cc69c..ec2fe1630d 100644 --- a/test/model/transaction/AccountLinkTransaction.spec.ts +++ b/test/model/transaction/AccountLinkTransaction.spec.ts @@ -66,7 +66,7 @@ describe('AccountLinkTransaction', () => { expect(accountLinkTransaction.linkAction).to.be.equal(1); expect(accountLinkTransaction.remoteAccountKey).to.be.equal(account.publicKey); - const signedTransaction = accountLinkTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = accountLinkTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index e65f359a9c..7fd1087647 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -162,7 +162,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = addressRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -213,7 +213,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = mosaicRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, @@ -266,7 +266,7 @@ describe('AccountRestrictionTransaction', () => { NetworkType.MIJIN_TEST, ); - const signedTransaction = operationRestrictionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index 1229abc20b..59b1ce1144 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('AddressAliasTransaction', () => { expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); - const signedTransaction = addressAliasTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = addressAliasTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 7e64c38f4a..4e8c4227e6 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -106,7 +106,7 @@ describe('AggregateTransaction', () => { NetworkType.MIJIN_TEST, []); - const signedTransaction = aggregateTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(0, 8)).to.be.equal('CD000000'); expect(signedTransaction.payload.substring(240, 256)).to.be.equal('5100000051000000'); diff --git a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts index 4943e33e1f..00afd72d47 100644 --- a/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts +++ b/test/model/transaction/ModifyMultisigAccountTransaction.spec.ts @@ -110,7 +110,7 @@ describe('ModifyMultisigAccountTransaction', () => { expect(modifyMultisigAccountTransaction.modifications[1].cosignatoryPublicAccount.publicKey) .to.be.equal('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); - const signedTransaction = modifyMultisigAccountTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index e2b8fffd90..34184eff95 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -80,7 +80,7 @@ describe('MosaicAliasTransaction', () => { expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); expect(mosaicAliasTransaction.mosaicId.id.higher).to.be.equal(3405110546); - const signedTransaction = mosaicAliasTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index 52481c3ee8..f444278cbe 100644 --- a/test/model/transaction/MosaicDefinitionTransaction.spec.ts +++ b/test/model/transaction/MosaicDefinitionTransaction.spec.ts @@ -93,7 +93,7 @@ describe('MosaicDefinitionTransaction', () => { expect(mosaicDefinitionTransaction.mosaicProperties.transferable).to.be.equal(true); expect(mosaicDefinitionTransaction.mosaicProperties.restrictable).to.be.equal(true); - const signedTransaction = mosaicDefinitionTransaction.signWithCatbuffer(account, generationHash); + const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring( 240, diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index 7488e3ca3d..d0baad099a 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -241,8 +241,4 @@ class FakeTransaction extends Transaction { protected generateEmbeddedBytes(): Uint8Array { throw new Error('Not implemented'); } - - protected generateBytes(): Uint8Array { - throw new Error('Not implemented'); - } } From ec243e8f4eedf086c346d48f388c938f5f863581 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 8 Aug 2019 12:16:52 +0100 Subject: [PATCH 87/98] restored network config for e2e --- e2e/conf/network.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index a19e2213f0..150443d82d 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -51,4 +51,4 @@ "publicKey": "FAEDB16763F22870B75BF934EA5F2792BDF109EC0C504718DDCBD92DF13C2628", "address": "SCNPFCWFV2FYQVMU5HMJJTMADRZ3LRXVA76F56N2" } -} +} \ No newline at end of file From 8cfc9f8eedcfdde3c167d4e3e30431d7be4ca8f2 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 14 Aug 2019 12:02:30 +0100 Subject: [PATCH 88/98] Fixed merged conflic issues --- .../transaction/AddressAliasTransaction.ts | 16 -------------- .../ModifyMultisigAccountTransaction.ts | 21 ------------------- .../transaction/MosaicAliasTransaction.ts | 16 -------------- 3 files changed, 53 deletions(-) diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 2d89adcfc2..55d57062f6 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -184,20 +184,4 @@ export class AddressAliasTransaction extends Transaction { ); return transactionBuilder.serialize(); } - - /** - * @internal - * @returns {Uint8Array} - */ - protected generateEmbeddedBytes(): Uint8Array { - const transactionBuilder = new EmbeddedAddressAliasTransactionBuilder( - new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), - this.versionToDTO(), - TransactionType.ADDRESS_ALIAS.valueOf(), - this.actionType.valueOf(), - new NamespaceIdDto(this.namespaceId.id.toDTO()), - new AddressDto(RawAddress.stringToAddress(this.address.plain())), - ); - return transactionBuilder.serialize(); - } } diff --git a/src/model/transaction/ModifyMultisigAccountTransaction.ts b/src/model/transaction/ModifyMultisigAccountTransaction.ts index 89e126a7eb..23dce96d81 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -206,25 +206,4 @@ export class ModifyMultisigAccountTransaction extends Transaction { ); return transactionBuilder.serialize(); } - - /** - * @internal - * @returns {Uint8Array} - */ - protected generateEmbeddedBytes(): Uint8Array { - const transactionBuilder = new EmbeddedMultisigAccountModificationTransactionBuilder( - new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), - this.versionToDTO(), - TransactionType.MODIFY_MULTISIG_ACCOUNT.valueOf(), - this.minRemovalDelta, - this.minApprovalDelta, - this.modifications.map((modification) => { - return new CosignatoryModificationBuilder( - modification.type.valueOf(), - new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)), - ); - }), - ); - return transactionBuilder.serialize(); - } } diff --git a/src/model/transaction/MosaicAliasTransaction.ts b/src/model/transaction/MosaicAliasTransaction.ts index c4255e2fae..6d7cae3183 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -179,20 +179,4 @@ export class MosaicAliasTransaction extends Transaction { ); return transactionBuilder.serialize(); } - - /** - * @internal - * @returns {Uint8Array} - */ - protected generateEmbeddedBytes(): Uint8Array { - const transactionBuilder = new EmbeddedMosaicAliasTransactionBuilder( - new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), - this.versionToDTO(), - TransactionType.MOSAIC_ALIAS.valueOf(), - this.actionType.valueOf(), - new NamespaceIdDto(this.namespaceId.id.toDTO()), - new MosaicIdDto(this.mosaicId.id.toDTO()), - ); - return transactionBuilder.serialize(); - } } From 21964b27a2388b3b045ee7c65cf883213134dab4 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 15 Aug 2019 12:12:33 +0100 Subject: [PATCH 89/98] Refactored TransactionMapping - createTransactionFromPayload now use catbuffer --- .../AccountAddressRestrictionTransaction.ts | 35 ++++++++++++++++++- .../AccountMosaicRestrictionTransaction.ts | 33 +++++++++++++++++ .../AccountOperationRestrictionTransaction.ts | 32 +++++++++++++++++ 3 files changed, 99 insertions(+), 1 deletion(-) diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index 150cd213b6..417dafba7b 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -14,21 +14,24 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert, RawAddress } from '../../core/format'; import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder'; import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder'; import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; +import { EmbeddedAccountAddressRestrictionTransactionBuilder }from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder'; import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; +import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -82,6 +85,36 @@ export class AccountAddressRestrictionTransaction extends Transaction { networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAccountAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AccountAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AccountAddressRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as AccountAddressRestrictionTransactionBuilder).getDeadline().timestamp), + builder.getRestrictionType().valueOf(), + builder.getModifications().map((modification) => { + return AccountRestrictionModification.createForAddress( + modification.modificationAction.valueOf(), + Address.createFromEncoded(Convert.uint8ToHex(modification.value.unresolvedAddress)), + ); + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountAddressRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AccountAddressRestrictionTransaction diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index be182d398b..ba7170a2cf 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; @@ -26,9 +27,11 @@ import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/Unresolved import { PublicAccount } from '../account/PublicAccount'; import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; +import { MosaicId } from '../mosaic/MosaicId'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -82,6 +85,36 @@ export class AccountMosaicRestrictionTransaction extends Transaction { networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAccountMosaicRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AccountMosaicRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AccountMosaicRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as AccountMosaicRestrictionTransactionBuilder).getDeadline().timestamp), + builder.getRestrictionType().valueOf(), + builder.getModifications().map((modification) => { + return AccountRestrictionModification.createForMosaic( + modification.modificationAction.valueOf(), + new MosaicId(modification.value.unresolvedMosaicId), + ); + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountMosaicRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AccountMosaicRestrictionTransaction diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index 07e19502f9..c95552e89b 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { SignSchema } from '../../core/crypto/SignSchema'; import { Convert } from '../../core/format'; import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; @@ -28,6 +29,7 @@ import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -88,6 +90,36 @@ export class AccountOperationRestrictionTransaction extends Transaction { networkType, version, deadline, maxFee, signature, signer, transactionInfo); } + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAccountOperationRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AccountOperationRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AccountOperationRestrictionTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO( + (builder as AccountOperationRestrictionTransactionBuilder).getDeadline().timestamp), + builder.getRestrictionType().valueOf(), + builder.getModifications().map((modification) => { + return AccountRestrictionModification.createForOperation( + modification.modificationAction.valueOf(), + modification.value.valueOf(), + ); + }), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountOperationRestrictionTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + /** * @override Transaction.size() * @description get the byte size of a AccountOperationRestrictionTransaction From 36fe77719045f230b9f2a37c4bf9c47771beba22 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 19 Aug 2019 10:43:56 +0100 Subject: [PATCH 90/98] Applied generated aggregate transaction from catbuffer-generator --- .../catbuffer/AggregateTransactionBuilder.ts | 132 ------------------ 1 file changed, 132 deletions(-) delete mode 100644 src/infrastructure/catbuffer/AggregateTransactionBuilder.ts diff --git a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts b/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts deleted file mode 100644 index 20462d8514..0000000000 --- a/src/infrastructure/catbuffer/AggregateTransactionBuilder.ts +++ /dev/null @@ -1,132 +0,0 @@ -// tslint:disable: jsdoc-format -/** -*** Copyright (c) 2016-present, -*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. -*** -*** This file is part of Catapult. -*** -*** Catapult is free software: you can redistribute it and/or modify -*** it under the terms of the GNU Lesser General Public License as published by -*** the Free Software Foundation, either version 3 of the License, or -*** (at your option) any later version. -*** -*** Catapult is distributed in the hope that it will be useful, -*** but WITHOUT ANY WARRANTY; without even the implied warranty of -*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -*** GNU Lesser General Public License for more details. -*** -*** You should have received a copy of the GNU Lesser General Public License -*** along with Catapult. If not, see . -**/ - -import { AmountDto } from './AmountDto'; -import { EntityTypeDto } from './EntityTypeDto'; -import { GeneratorUtils } from './GeneratorUtils'; -import { KeyDto } from './KeyDto'; -import { SignatureDto } from './SignatureDto'; -import { TimestampDto } from './TimestampDto'; -import { TransactionBuilder } from './TransactionBuilder'; - -/** binary layout for an aggregate transaction. */ -export class AggregateTransactionBuilder extends TransactionBuilder { - /** embedded transactions. */ - transactions: Uint8Array; - /** cosignatures. */ - cosignatures: Uint8Array; - - /** - * Constructor. - * - * @param signature entity signature. - * @param signer entity signer's public key. - * @param version entity version. - * @param type entity type. - * @param fee transaction fee. - * @param deadline transaction deadline. - * @param transactions embedded transactions. - * @param cosignatures cosignatures. - */ - public constructor( - signature: SignatureDto, - signer: KeyDto, - version: number, - type: EntityTypeDto, - fee: AmountDto, - deadline: TimestampDto, - transactions: Uint8Array, - cosignatures: Uint8Array) { - super(signature, signer, version, type, fee, deadline); - this.transactions = transactions; - this.cosignatures = cosignatures; - } - - /** - * loadFromBinary - Create an instance of AggregateTransactionBuilder from a stream. - * - * @param Uint8Array Byte to use to serialize the object. - * @return An instance of AggregateTransactionBuilder. - */ - public static loadFromBinary(payload: Uint8Array): AggregateTransactionBuilder { - const byteArray = Array.from(payload); - const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray)); - byteArray.splice(0, superObject.getSize()); - const payloadSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4)); - byteArray.splice(0, 4); - const transactions = GeneratorUtils.getBytes(Uint8Array.from(byteArray), payloadSize); - byteArray.splice(0, transactions.length); - const cosignatures = Uint8Array.from(byteArray); - // tslint:disable-next-line: max-line-length - return new AggregateTransactionBuilder(superObject.signature, superObject.signer, superObject.version, - superObject.type, superObject.fee, superObject.deadline, - transactions, cosignatures); - } - - /** - * Get embedded transactions. - * - * @return embedded transactions. - */ - public getTransactions(): Uint8Array { - return this.transactions; - } - - /** - * Get cosignatures. - * - * @return cosignatures. - */ - public getCosignatures(): Uint8Array { - return this.cosignatures; - } - - /** - * Get the size of the object. - * - * @return Size in bytes. - */ - public getSize(): number { - let size: number = super.getSize(); - size += 4; // payloadSize - size += this.transactions.length; - size += this.cosignatures.length; - return size; - } - - /** - * Serialize the object to bytes. - * - * @return Serialized bytes. - */ - public serialize(): Uint8Array { - let newArray = Uint8Array.from([]); - const superBytes = super.serialize(); - newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); - const payloadSizeBytes = GeneratorUtils.uintToBuffer(this.transactions.length, 4); - newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes); - const transactionBytes = this.transactions; - newArray = GeneratorUtils.concatTypedArrays(newArray, transactionBytes); - const cosignaturesBytes = this.cosignatures; - newArray = GeneratorUtils.concatTypedArrays(newArray, cosignaturesBytes); - return newArray; - } -} From 1ef0033c879795d43cec8747498166c7c62fa11c Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 2 Sep 2019 13:36:38 +0100 Subject: [PATCH 91/98] Fixed merge errors --- .../AccountAddressRestrictionTransaction.ts | 6 +++--- .../AccountMosaicRestrictionTransaction.ts | 6 +++--- .../AccountOperationRestrictionTransaction.ts | 13 +++---------- .../transaction/AccountRestrictionTransaction.ts | 8 ++++---- src/model/transaction/AddressAliasTransaction.ts | 1 - src/model/transaction/AggregateTransaction.ts | 11 +++++++++++ .../transaction/MosaicDefinitionTransaction.ts | 13 ------------- test/core/utils/TransactionMapping.spec.ts | 12 ++++++------ .../SerializeTransactionToJSON.spec.ts | 6 +++--- .../AccountRestrictionTransaction.spec.ts | 8 ++++---- 10 files changed, 37 insertions(+), 47 deletions(-) diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index 417dafba7b..48299057bb 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -24,9 +24,9 @@ import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; -import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; @@ -49,7 +49,7 @@ export class AccountAddressRestrictionTransaction extends Transaction { * @returns {AccountAddressRestrictionTransaction} */ public static create(deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountAddressRestrictionTransaction { @@ -76,7 +76,7 @@ export class AccountAddressRestrictionTransaction extends Transaction { version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index ba7170a2cf..97343c5460 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -24,8 +24,8 @@ import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { PublicAccount } from '../account/PublicAccount'; -import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { MosaicId } from '../mosaic/MosaicId'; import { UInt64 } from '../UInt64'; @@ -49,7 +49,7 @@ export class AccountMosaicRestrictionTransaction extends Transaction { * @returns {AccountAddressRestrictionTransaction} */ public static create(deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountMosaicRestrictionTransaction { @@ -76,7 +76,7 @@ export class AccountMosaicRestrictionTransaction extends Transaction { version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts index c95552e89b..f60abe0115 100644 --- a/src/model/transaction/AccountOperationRestrictionTransaction.ts +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -23,8 +23,8 @@ import { EmbeddedAccountOperationRestrictionTransactionBuilder } from '../../inf import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { AccountRestrictionType } from '../account/AccountRestrictionType'; import { PublicAccount } from '../account/PublicAccount'; -import { RestrictionType } from '../account/RestrictionType'; import { NetworkType } from '../blockchain/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountRestrictionModification } from './AccountRestrictionModification'; @@ -34,13 +34,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder'; -import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder'; -import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; -import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; -import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; export class AccountOperationRestrictionTransaction extends Transaction { @@ -54,7 +47,7 @@ export class AccountOperationRestrictionTransaction extends Transaction { * @returns {AccountOperationRestrictionTransaction} */ public static create(deadline: Deadline, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0])): AccountOperationRestrictionTransaction { @@ -81,7 +74,7 @@ export class AccountOperationRestrictionTransaction extends Transaction { version: number, deadline: Deadline, maxFee: UInt64, - public readonly restrictionType: RestrictionType, + public readonly restrictionType: AccountRestrictionType, public readonly modifications: Array>, signature?: string, signer?: PublicAccount, diff --git a/src/model/transaction/AccountRestrictionTransaction.ts b/src/model/transaction/AccountRestrictionTransaction.ts index 33ee6cd715..4c294e4bc9 100644 --- a/src/model/transaction/AccountRestrictionTransaction.ts +++ b/src/model/transaction/AccountRestrictionTransaction.ts @@ -40,7 +40,7 @@ export class AccountRestrictionTransaction { modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), - ): AccountAddressRestrictionModificationTransaction { + ): AccountAddressRestrictionTransaction { if (![AccountRestrictionType.AllowIncomingAddress, AccountRestrictionType.AllowOutgoingAddress, AccountRestrictionType.BlockOutgoingAddress, @@ -71,7 +71,7 @@ export class AccountRestrictionTransaction { modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), - ): AccountMosaicRestrictionModificationTransaction { + ): AccountMosaicRestrictionTransaction { if (![AccountRestrictionType.AllowMosaic,AccountRestrictionType.BlockMosaic].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } @@ -91,7 +91,7 @@ export class AccountRestrictionTransaction { * @param modification - array of operation modifications * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender - * @returns {createOperationRestrictionModificationTransaction} + * @returns {AccountOperationRestrictionTransaction} */ public static createOperationRestrictionModificationTransaction( deadline: Deadline, @@ -99,7 +99,7 @@ export class AccountRestrictionTransaction { modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), - ): AccountOperationRestrictionModificationTransaction { + ): AccountOperationRestrictionTransaction { if (![AccountRestrictionType.AllowIncomingTransactionType, AccountRestrictionType.AllowOutgoingTransactionType, AccountRestrictionType.BlockOutgoingTransactionType, diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index 55d57062f6..3975b926dc 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -36,7 +36,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { RawAddress } from '../../core/format'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index 591fa6182e..0f473c5667 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -124,6 +124,17 @@ export class AggregateTransaction extends Transaction { ); } + /** + * @description add inner transactions to current list + * @param {InnerTransaction[]} transaction + * @returns {AggregateTransaction} + * @memberof AggregateTransaction + */ + public addTransactions(transactions: InnerTransaction[]): AggregateTransaction { + const innerTransactions = this.innerTransactions.concat(transactions); + return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {innerTransactions}); + } + /** * Create a transaction object from payload * @param {string} payload Binary payload diff --git a/src/model/transaction/MosaicDefinitionTransaction.ts b/src/model/transaction/MosaicDefinitionTransaction.ts index c85be5cf92..1616044875 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -39,19 +39,6 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; -import { MosaicDefinitionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicDefinitionTransactionBuilder'; -import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; -import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; -import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto'; -import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; -import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; -import { MosaicNonceDto } from '../../infrastructure/catbuffer/MosaicNonceDto'; -import { MosaicIdDto } from '../../infrastructure/catbuffer/MosaicIdDto'; -import { MosaicFlagsDto } from '../../infrastructure/catbuffer/MosaicFlagsDto'; -import { MosaicFlags } from '../mosaic/MosaicFlag'; -import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto'; -import { Convert } from '../../core/format'; -import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; /** * Before a mosaic can be created or transferred, a corresponding definition of the mosaic has to be created and published to the network. diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index 3ba2e99fb7..f6b7af8d20 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -25,7 +25,6 @@ import { Address } from '../../../src/model/account/Address'; import { PublicAccount } from '../../../src/model/account/PublicAccount'; import { RestrictionModificationType } from '../../../src/model/account/RestrictionModificationType'; import { NetworkType } from '../../../src/model/blockchain/NetworkType'; -import { EncryptedMessage } from '../../../src/model/model'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../../src/model/mosaic/MosaicNonce'; import { MosaicProperties } from '../../../src/model/mosaic/MosaicProperties'; @@ -35,7 +34,7 @@ import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrency import { AliasAction } from '../../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { NamespaceType } from '../../../src/model/namespace/NamespaceType'; -import { AccountAddressRestrictionModificationTransaction } from'../../../src/model/transaction/AccountAddressRestrictionModificationTransaction'; +import { AccountAddressRestrictionTransaction } from '../../../src/model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../../src/model/transaction/AccountLinkTransaction'; import { AccountMosaicRestrictionTransaction } from '../../../src/model/transaction/AccountMosaicRestrictionTransaction'; import { AccountRestrictionModification } from '../../../src/model/transaction/AccountRestrictionModification'; @@ -43,6 +42,7 @@ import { AccountRestrictionTransaction } from '../../../src/model/transaction/Ac import { AddressAliasTransaction } from '../../../src/model/transaction/AddressAliasTransaction'; import { AggregateTransaction } from '../../../src/model/transaction/AggregateTransaction'; import { Deadline } from '../../../src/model/transaction/Deadline'; +import { EncryptedMessage } from '../../../src/model/transaction/EncryptedMessage'; import { HashType } from '../../../src/model/transaction/HashType'; import { LinkAction } from '../../../src/model/transaction/LinkAction'; import { LockFundsTransaction } from '../../../src/model/transaction/LockFundsTransaction'; @@ -110,7 +110,7 @@ describe('TransactionMapping - createFromPayload', () => { const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); const transaction = TransactionMapping - .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; + .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionTransaction; expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowMosaic); expect(transaction.modifications[0].value[0]).to.be.equal(2262289484); expect(transaction.modifications[0].value[1]).to.be.equal(3405110546); @@ -133,7 +133,7 @@ describe('TransactionMapping - createFromPayload', () => { const signedTransaction = operationRestrictionTransaction.signWith(account, generationHash); const transaction = TransactionMapping - .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; + .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionTransaction; expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType); expect(transaction.modifications[0].value).to.be.equal(operation); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); @@ -697,7 +697,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => const transaction = TransactionMapping.createFromDTO(mosaicRestrictionTransaction.toJSON()) as AccountMosaicRestrictionTransaction; - expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC); + expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_MOSAIC); expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowMosaic); expect(transaction.modifications.length).to.be.equal(1); }); @@ -718,7 +718,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => const transaction = TransactionMapping.createFromDTO(operationRestrictionTransaction.toJSON()) as AccountMosaicRestrictionTransaction; - expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); + expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_OPERATION); expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType); expect(transaction.modifications.length).to.be.equal(1); }); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 1559522ba3..21822a3091 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -90,7 +90,7 @@ describe('SerializeTransactionToJSON', () => { const json = addressRestrictionTransaction.toJSON(); - expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS); + expect(json.transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_ADDRESS); expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -110,7 +110,7 @@ describe('SerializeTransactionToJSON', () => { const json = mosaicRestrictionTransaction.toJSON(); - expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC); + expect(json.transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_MOSAIC); expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowMosaic); expect(json.transaction.modifications.length).to.be.equal(1); }); @@ -130,7 +130,7 @@ describe('SerializeTransactionToJSON', () => { const json = operationRestrictionTransaction.toJSON(); - expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION); + expect(json.transaction.type).to.be.equal(TransactionType.ACCOUNT_RESTRICTION_OPERATION); expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType); expect(json.transaction.modifications.length).to.be.equal(1); }); diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 7fd1087647..cde002ae01 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -322,7 +322,7 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('4101009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + )).to.be.equal('4101019050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), @@ -336,7 +336,7 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('C101009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + )).to.be.equal('C101019050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); }); @@ -359,7 +359,7 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('4401004E42'); + )).to.be.equal('4401014E42'); operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), @@ -373,7 +373,7 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('C401004E42'); + )).to.be.equal('C401014E42'); }); }); From 70b8819651c128e3f6b271a68a20fcef6736c9d7 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 20 Aug 2019 19:59:36 +0100 Subject: [PATCH 92/98] Added metadata transactions --- e2e/infrastructure/TransactionHttp.spec.ts | 301 +++++++++++++----- src/infrastructure/catbuffer/EntityTypeDto.ts | 12 + .../transaction/CreateTransactionFromDTO.ts | 50 +++ .../CreateTransactionFromPayload.ts | 9 + .../transaction/SerializeTransactionToJSON.ts | 33 ++ .../transaction/AccountMetadataTransaction.ts | 193 +++++++++++ .../transaction/MosaicMetadataTransaction.ts | 207 ++++++++++++ .../NamespaceMetaDataTransaction.ts | 208 ++++++++++++ src/model/transaction/TransactionType.ts | 18 ++ src/model/transaction/TransactionVersion.ts | 18 ++ test/core/utils/TransactionMapping.spec.ts | 134 ++++++++ .../AccountMetadataTransaction.spec.ts | 105 ++++++ .../MosaicMetadataTransaction.spec.ts | 112 +++++++ .../transaction/NamespaceMetadata.spec.ts | 112 +++++++ 14 files changed, 1431 insertions(+), 81 deletions(-) create mode 100644 src/model/transaction/AccountMetadataTransaction.ts create mode 100644 src/model/transaction/MosaicMetadataTransaction.ts create mode 100644 src/model/transaction/NamespaceMetaDataTransaction.ts create mode 100644 test/model/transaction/AccountMetadataTransaction.spec.ts create mode 100644 test/model/transaction/MosaicMetadataTransaction.spec.ts create mode 100644 test/model/transaction/NamespaceMetadata.spec.ts diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index ee0f981589..ebb487942c 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -18,7 +18,7 @@ import * as CryptoJS from 'crypto-js'; import {ChronoUnit} from 'js-joda'; import {keccak_256, sha3_256} from 'js-sha3'; import {Crypto} from '../../src/core/crypto'; -import { Convert as convert } from '../../src/core/format'; +import { Convert as convert, Convert } from '../../src/core/format'; import { TransactionMapping } from '../../src/core/utils/TransactionMapping'; import {AccountHttp} from '../../src/infrastructure/AccountHttp'; import { NamespaceHttp } from '../../src/infrastructure/infrastructure'; @@ -66,6 +66,9 @@ import {Transaction} from '../../src/model/transaction/Transaction'; import {TransactionType} from '../../src/model/transaction/TransactionType'; import {TransferTransaction} from '../../src/model/transaction/TransferTransaction'; import {UInt64} from '../../src/model/UInt64'; +import { AccountMetadataTransaction } from '../../src/model/transaction/AccountMetadataTransaction'; +import { MosaicMetadataTransaction } from '../../src/model/transaction/MosaicMetadataTransaction'; +import { NamespaceMetadataTransaction } from '../../src/model/transaction/NamespaceMetaDataTransaction'; describe('TransactionHttp', () => { let transactionHash; let transactionId; @@ -208,6 +211,206 @@ describe('TransactionHttp', () => { }); }); + describe('AccountMetadataTransaction', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('aggregate', (done) => { + const accountMetadataTransaction = AccountMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + 10, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [accountMetadataTransaction.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + listener.confirmed(account.address).subscribe((transaction: AggregateTransaction) => { + transaction.innerTransactions.forEach((innerTx) => { + expect((innerTx as AccountMetadataTransaction).targetPublicKey, 'TargetPublicKey').not.to.be.undefined; + expect((innerTx as AccountMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; + expect((innerTx as AccountMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; + expect((innerTx as AccountMetadataTransaction).value, 'Value').not.to.be.undefined; + }); + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + + describe('MosaicMetadataTransaction', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('aggregate', (done) => { + const mosaicMetadataTransaction = MosaicMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + mosaicId, + 10, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [mosaicMetadataTransaction.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + listener.confirmed(account.address).subscribe((transaction: AggregateTransaction) => { + transaction.innerTransactions.forEach((innerTx) => { + expect((innerTx as MosaicMetadataTransaction).targetPublicKey, 'TargetPublicKey').not.to.be.undefined; + expect((innerTx as MosaicMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; + expect((innerTx as MosaicMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; + expect((innerTx as MosaicMetadataTransaction).value, 'Value').not.to.be.undefined; + expect((innerTx as MosaicMetadataTransaction).targetMosaicId, 'TargetMosaicId').not.to.be.undefined; + }); + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + + describe('RegisterNamespaceTransaction', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('standalone', (done) => { + const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); + const registerNamespaceTransaction = RegisterNamespaceTransaction.createRootNamespace( + Deadline.create(), + namespaceName, + UInt64.fromUint(1000), + NetworkType.MIJIN_TEST, + ); + namespaceId = new NamespaceId(namespaceName); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + listener.confirmed(account.address).subscribe((transaction: RegisterNamespaceTransaction) => { + expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; + expect(transaction.namespaceName, 'NamespaceName').not.to.be.undefined; + expect(transaction.namespaceType, 'NamespaceType').not.to.be.undefined; + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + + describe('RegisterNamespaceTransaction', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('aggregate', (done) => { + const registerNamespaceTransaction = RegisterNamespaceTransaction.createRootNamespace( + Deadline.create(), + 'root-test-namespace-' + Math.floor(Math.random() * 10000), + UInt64.fromUint(1000), + NetworkType.MIJIN_TEST, + ); + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [registerNamespaceTransaction.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + []); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + listener.confirmed(account.address).subscribe((transaction: Transaction) => { + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + + describe('NamespaceMetadataTransaction', () => { + let listener: Listener; + before (() => { + listener = new Listener(config.apiUrl); + return listener.open(); + }); + after(() => { + return listener.close(); + }); + it('aggregate', (done) => { + const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + namespaceId, + 10, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), + [namespaceMetadataTransaction.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + const signedTransaction = aggregateTransaction.signWith(account, generationHash); + listener.confirmed(account.address).subscribe((transaction: AggregateTransaction) => { + transaction.innerTransactions.forEach((innerTx) => { + expect((innerTx as NamespaceMetadataTransaction).targetPublicKey, 'TargetPublicKey').not.to.be.undefined; + expect((innerTx as NamespaceMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; + expect((innerTx as NamespaceMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; + expect((innerTx as NamespaceMetadataTransaction).value, 'Value').not.to.be.undefined; + expect((innerTx as NamespaceMetadataTransaction).targetNamespaceId, 'TargetNamespaceId').not.to.be.undefined; + }); + done(); + }); + listener.status(account.address).subscribe((error) => { + console.log('Error:', error); + assert(false); + done(); + }); + transactionHttp.announce(signedTransaction); + }); + }); + describe('MosaicGlobalRestrictionTransaction', () => { let listener: Listener; before (() => { @@ -830,71 +1033,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('RegisterNamespaceTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('standalone', (done) => { - const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); - const registerNamespaceTransaction = RegisterNamespaceTransaction.createRootNamespace( - Deadline.create(), - namespaceName, - UInt64.fromUint(1000), - NetworkType.MIJIN_TEST, - ); - namespaceId = new NamespaceId(namespaceName); - const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: RegisterNamespaceTransaction) => { - expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; - expect(transaction.namespaceName, 'NamespaceName').not.to.be.undefined; - expect(transaction.namespaceType, 'NamespaceType').not.to.be.undefined; - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); - }); - }); - describe('RegisterNamespaceTransaction', () => { - let listener: Listener; - before (() => { - listener = new Listener(config.apiUrl); - return listener.open(); - }); - after(() => { - return listener.close(); - }); - it('aggregate', (done) => { - const registerNamespaceTransaction = RegisterNamespaceTransaction.createRootNamespace( - Deadline.create(), - 'root-test-namespace-' + Math.floor(Math.random() * 10000), - UInt64.fromUint(1000), - NetworkType.MIJIN_TEST, - ); - const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(), - [registerNamespaceTransaction.toAggregate(account.publicAccount)], - NetworkType.MIJIN_TEST, - []); - const signedTransaction = aggregateTransaction.signWith(account, generationHash); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - done(); - }); - listener.status(account.address).subscribe((error) => { - console.log('Error:', error); - assert(false); - done(); - }); - transactionHttp.announce(signedTransaction); - }); - }); + describe('AddressAliasTransaction', () => { let listener: Listener; before (() => { @@ -1534,7 +1673,7 @@ describe('TransactionHttp', () => { account2.address, NetworkType.MIJIN_TEST, ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { + listener.confirmed(account.address).subscribe(() => { listener.confirmed(account2.address).subscribe((transaction: SecretProofTransaction) => { expect(transaction.secret, 'Secret').not.to.be.undefined; expect(transaction.recipient, 'Recipient').not.to.be.undefined; @@ -1584,8 +1723,8 @@ describe('TransactionHttp', () => { account2.address, NetworkType.MIJIN_TEST, ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - listener.confirmed(account2.address).subscribe((transaction: Transaction) => { + listener.confirmed(account.address).subscribe(() => { + listener.confirmed(account2.address).subscribe(() => { done(); }); const secretProofTransaction = SecretProofTransaction.create( @@ -1632,8 +1771,8 @@ describe('TransactionHttp', () => { account2.address, NetworkType.MIJIN_TEST, ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - listener.confirmed(account2.address).subscribe((transaction: Transaction) => { + listener.confirmed(account.address).subscribe(() => { + listener.confirmed(account2.address).subscribe(() => { done(); }); const secretProofTransaction = SecretProofTransaction.create( @@ -1676,8 +1815,8 @@ describe('TransactionHttp', () => { account2.address, NetworkType.MIJIN_TEST, ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - listener.confirmed(account2.address).subscribe((transaction: Transaction) => { + listener.confirmed(account.address).subscribe(() => { + listener.confirmed(account2.address).subscribe(() => { done(); }); const secretProofTransaction = SecretProofTransaction.create( @@ -1726,8 +1865,8 @@ describe('TransactionHttp', () => { account2.address, NetworkType.MIJIN_TEST, ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - listener.confirmed(account2.address).subscribe((transaction: Transaction) => { + listener.confirmed(account.address).subscribe(() => { + listener.confirmed(account2.address).subscribe(() => { done(); }); listener.status(account2.address).subscribe((error) => { @@ -1778,8 +1917,8 @@ describe('TransactionHttp', () => { account2.address, NetworkType.MIJIN_TEST, ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - listener.confirmed(account2.address).subscribe((transaction: Transaction) => { + listener.confirmed(account.address).subscribe(() => { + listener.confirmed(account2.address).subscribe(() => { done(); }); listener.status(account2.address).subscribe((error) => { @@ -1833,8 +1972,8 @@ describe('TransactionHttp', () => { account2.address, NetworkType.MIJIN_TEST, ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - listener.confirmed(account2.address).subscribe((transaction: Transaction) => { + listener.confirmed(account.address).subscribe(() => { + listener.confirmed(account2.address).subscribe(() => { done(); }); listener.status(account2.address).subscribe((error) => { @@ -1884,8 +2023,8 @@ describe('TransactionHttp', () => { account2.address, NetworkType.MIJIN_TEST, ); - listener.confirmed(account.address).subscribe((transaction: Transaction) => { - listener.confirmed(account2.address).subscribe((transaction: Transaction) => { + listener.confirmed(account.address).subscribe(() => { + listener.confirmed(account2.address).subscribe(() => { done(); }); listener.status(account2.address).subscribe((error) => { diff --git a/src/infrastructure/catbuffer/EntityTypeDto.ts b/src/infrastructure/catbuffer/EntityTypeDto.ts index 921a115ce9..56350b2507 100644 --- a/src/infrastructure/catbuffer/EntityTypeDto.ts +++ b/src/infrastructure/catbuffer/EntityTypeDto.ts @@ -28,6 +28,10 @@ export enum EntityTypeDto { * Account address restriction transaction. */ ACCOUNT_ADDRESS_RESTRICTION_TRANSACTION = 0x4150, + /** + * Account metadata transaction + */ + ACCOUNT_METADATA_TRANSACTION = 0x4144, /** * Account mosaic restriction transaction. */ @@ -64,6 +68,10 @@ export enum EntityTypeDto { * Mosaic definition transaction. */ MOSAIC_DEFINITION_TRANSACTION = 0x414D, + /** + * Mosaic metadata transaction. + */ + MOSAIC_METADATA_TRANSACTION = 0x4244, /** * Mosaic supply change transaction. */ @@ -72,6 +80,10 @@ export enum EntityTypeDto { * Mosaic alias transaction. */ MOSAIC_ALIAS_TRANSACTION = 0x434E, + /** + * Namespace metadata transaction. + */ + NAMESPACE_METADATA_TRANSACTION = 0x4344, /** * Register namespace transaction. */ diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index e6a1e3d7ae..d97e24bd4a 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -26,6 +26,7 @@ import { MosaicPropertyType } from '../../model/mosaic/MosaicPropertyType'; import {NamespaceId} from '../../model/namespace/NamespaceId'; import {AccountAddressRestrictionTransaction} from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; +import { AccountMetadataTransaction } from '../../model/transaction/AccountMetadataTransaction'; import {AccountMosaicRestrictionTransaction} from '../../model/transaction/AccountMosaicRestrictionTransaction'; import {AccountOperationRestrictionTransaction} from '../../model/transaction/AccountOperationRestrictionTransaction'; import {AccountRestrictionModification} from '../../model/transaction/AccountRestrictionModification'; @@ -42,8 +43,10 @@ import { MosaicAddressRestrictionTransaction } from '../../model/transaction/Mos import {MosaicAliasTransaction} from '../../model/transaction/MosaicAliasTransaction'; import {MosaicDefinitionTransaction} from '../../model/transaction/MosaicDefinitionTransaction'; import { MosaicGlobalRestrictionTransaction } from '../../model/transaction/MosaicGlobalRestrictionTransaction'; +import { MosaicMetadataTransaction } from '../../model/transaction/MosaicMetadataTransaction'; import {MosaicSupplyChangeTransaction} from '../../model/transaction/MosaicSupplyChangeTransaction'; import {MultisigCosignatoryModification} from '../../model/transaction/MultisigCosignatoryModification'; +import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetaDataTransaction'; import {EmptyMessage, PlainMessage} from '../../model/transaction/PlainMessage'; import {RegisterNamespaceTransaction} from '../../model/transaction/RegisterNamespaceTransaction'; import {SecretLockTransaction} from '../../model/transaction/SecretLockTransaction'; @@ -377,6 +380,53 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr extractNetworkType(transactionDTO.version)) : undefined, transactionInfo, ); + } else if (transactionDTO.type === TransactionType.ACCOUNT_METADATA_TRANSACTION) { + return new AccountMetadataTransaction( + extractNetworkType(transactionDTO.version), + extractTransactionVersion(transactionDTO.version), + Deadline.createFromDTO(transactionDTO.deadline), + new UInt64(transactionDTO.maxFee || [0, 0]), + transactionDTO.targetPublicKey, + new UInt64(transactionDTO.scopedMetadataKey), + transactionDTO.valueSizeDelta, + convert.hexToUint8(transactionDTO.value), + transactionDTO.signature, + transactionDTO.signer ? PublicAccount.createFromPublicKey(transactionDTO.signer, + extractNetworkType(transactionDTO.version)) : undefined, + transactionInfo, + ); + } else if (transactionDTO.type === TransactionType.MOSAIC_METADATA_TRANSACTION) { + return new MosaicMetadataTransaction( + extractNetworkType(transactionDTO.version), + extractTransactionVersion(transactionDTO.version), + Deadline.createFromDTO(transactionDTO.deadline), + new UInt64(transactionDTO.maxFee || [0, 0]), + transactionDTO.targetPublicKey, + new UInt64(transactionDTO.scopedMetadataKey), + new MosaicId(transactionDTO.targetMosaicId), + transactionDTO.valueSizeDelta, + convert.hexToUint8(transactionDTO.value), + transactionDTO.signature, + transactionDTO.signer ? PublicAccount.createFromPublicKey(transactionDTO.signer, + extractNetworkType(transactionDTO.version)) : undefined, + transactionInfo, + ); + } else if (transactionDTO.type === TransactionType.NAMESPACE_METADATA_TRANSACTION) { + return new NamespaceMetadataTransaction( + extractNetworkType(transactionDTO.version), + extractTransactionVersion(transactionDTO.version), + Deadline.createFromDTO(transactionDTO.deadline), + new UInt64(transactionDTO.maxFee || [0, 0]), + transactionDTO.targetPublicKey, + new UInt64(transactionDTO.scopedMetadataKey), + new NamespaceId(transactionDTO.targetNamespaceId), + transactionDTO.valueSizeDelta, + convert.hexToUint8(transactionDTO.value), + transactionDTO.signature, + transactionDTO.signer ? PublicAccount.createFromPublicKey(transactionDTO.signer, + extractNetworkType(transactionDTO.version)) : undefined, + transactionInfo, + ); } throw new Error('Unimplemented transaction with type ' + transactionDTO.type); }; diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index 3f79ea2d5e..87a5455da5 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -19,6 +19,7 @@ import { Convert as convert } from '../../core/format'; import { InnerTransaction } from '../../model/model'; import { AccountAddressRestrictionTransaction } from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; +import { AccountMetadataTransaction } from '../../model/transaction/AccountMetadataTransaction'; import { AccountMosaicRestrictionTransaction } from '../../model/transaction/AccountMosaicRestrictionTransaction'; import { AccountOperationRestrictionTransaction } from '../../model/transaction/AccountOperationRestrictionTransaction'; import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction'; @@ -29,7 +30,9 @@ import { MosaicAddressRestrictionTransaction } from '../../model/transaction/Mos import { MosaicAliasTransaction } from '../../model/transaction/MosaicAliasTransaction'; import { MosaicDefinitionTransaction } from '../../model/transaction/MosaicDefinitionTransaction'; import { MosaicGlobalRestrictionTransaction } from '../../model/transaction/MosaicGlobalRestrictionTransaction'; +import { MosaicMetadataTransaction } from '../../model/transaction/MosaicMetadataTransaction'; import { MosaicSupplyChangeTransaction } from '../../model/transaction/MosaicSupplyChangeTransaction'; +import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetaDataTransaction'; import { RegisterNamespaceTransaction } from '../../model/transaction/RegisterNamespaceTransaction'; import { SecretLockTransaction } from '../../model/transaction/SecretLockTransaction'; import { SecretProofTransaction } from '../../model/transaction/SecretProofTransaction'; @@ -92,6 +95,12 @@ export const CreateTransactionFromPayload = (payload: string, return MosaicGlobalRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.MOSAIC_ADDRESS_RESTRICTION: return MosaicAddressRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); + case TransactionType.ACCOUNT_METADATA_TRANSACTION: + return AccountMetadataTransaction.createFromPayload(payload, isEmbedded, signSchema); + case TransactionType.MOSAIC_METADATA_TRANSACTION: + return MosaicMetadataTransaction.createFromPayload(payload, isEmbedded, signSchema); + case TransactionType.NAMESPACE_METADATA_TRANSACTION: + return NamespaceMetadataTransaction.createFromPayload(payload, isEmbedded, signSchema); case TransactionType.AGGREGATE_COMPLETE: case TransactionType.AGGREGATE_BONDED: return AggregateTransaction.createFromPayload(payload, signSchema); diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index 4ba47f1e4c..ee68778a74 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -14,8 +14,10 @@ * limitations under the License. */ +import { Convert } from '../../core/format/Convert'; import { AccountAddressRestrictionTransaction } from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../model/transaction/AccountLinkTransaction'; +import { AccountMetadataTransaction } from '../../model/transaction/AccountMetadataTransaction'; import { AccountMosaicRestrictionTransaction } from '../../model/transaction/AccountMosaicRestrictionTransaction'; import { AccountOperationRestrictionTransaction } from '../../model/transaction/AccountOperationRestrictionTransaction'; import { AddressAliasTransaction } from '../../model/transaction/AddressAliasTransaction'; @@ -26,7 +28,9 @@ import { MosaicAddressRestrictionTransaction } from '../../model/transaction/Mos import { MosaicAliasTransaction } from '../../model/transaction/MosaicAliasTransaction'; import { MosaicDefinitionTransaction } from '../../model/transaction/MosaicDefinitionTransaction'; import { MosaicGlobalRestrictionTransaction } from '../../model/transaction/MosaicGlobalRestrictionTransaction'; +import { MosaicMetadataTransaction } from '../../model/transaction/MosaicMetadataTransaction'; import { MosaicSupplyChangeTransaction } from '../../model/transaction/MosaicSupplyChangeTransaction'; +import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetaDataTransaction'; import { RegisterNamespaceTransaction } from '../../model/transaction/RegisterNamespaceTransaction'; import { SecretLockTransaction } from '../../model/transaction/SecretLockTransaction'; import { SecretProofTransaction } from '../../model/transaction/SecretProofTransaction'; @@ -178,6 +182,35 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { previousRestrictionValue: (transaction as MosaicAddressRestrictionTransaction).previousRestrictionValue.toDTO(), newRestrictionValue: (transaction as MosaicAddressRestrictionTransaction).newRestrictionValue.toDTO(), + }; + case TransactionType.ACCOUNT_METADATA_TRANSACTION: + return { + targetPublicKey: (transaction as AccountMetadataTransaction).targetPublicKey, + scopedMetadataKey: (transaction as AccountMetadataTransaction).scopedMetadataKey.toDTO(), + valueSizeDelta: (transaction as AccountMetadataTransaction).valueSizeDelta, + valueSize: (transaction as AccountMetadataTransaction).value.length, + value: Convert.uint8ToHex((transaction as AccountMetadataTransaction).value), + + }; + case TransactionType.MOSAIC_METADATA_TRANSACTION: + return { + targetPublicKey: (transaction as MosaicMetadataTransaction).targetPublicKey, + scopedMetadataKey: (transaction as MosaicMetadataTransaction).scopedMetadataKey.toDTO(), + valueSizeDelta: (transaction as MosaicMetadataTransaction).valueSizeDelta, + targetMosaicId: (transaction as MosaicMetadataTransaction).targetMosaicId.id.toDTO(), + valueSize: (transaction as MosaicMetadataTransaction).value.length, + value: Convert.uint8ToHex((transaction as MosaicMetadataTransaction).value), + + }; + case TransactionType.NAMESPACE_METADATA_TRANSACTION: + return { + targetPublicKey: (transaction as NamespaceMetadataTransaction).targetPublicKey, + scopedMetadataKey: (transaction as NamespaceMetadataTransaction).scopedMetadataKey.toDTO(), + valueSizeDelta: (transaction as NamespaceMetadataTransaction).valueSizeDelta, + targetNamespaceId: (transaction as NamespaceMetadataTransaction).targetNamespaceId.id.toDTO(), + valueSize: (transaction as NamespaceMetadataTransaction).value.length, + value: Convert.uint8ToHex((transaction as NamespaceMetadataTransaction).value), + }; default: throw new Error ('Transaction type not implemented yet.'); diff --git a/src/model/transaction/AccountMetadataTransaction.ts b/src/model/transaction/AccountMetadataTransaction.ts new file mode 100644 index 0000000000..23120e9367 --- /dev/null +++ b/src/model/transaction/AccountMetadataTransaction.ts @@ -0,0 +1,193 @@ +/* + * 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 { SignSchema } from '../../core/crypto/SignSchema'; +import { Convert } from '../../core/format'; +import { AccountMetadataTransactionBuilder } from '../../infrastructure/catbuffer/AccountMetadataTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountMetadataTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { PublicAccount } from '../account/PublicAccount'; +import { NetworkType } from '../blockchain/NetworkType'; +import { UInt64 } from '../UInt64'; +import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; +import { Transaction } from './Transaction'; +import { TransactionInfo } from './TransactionInfo'; +import { TransactionType } from './TransactionType'; +import { TransactionVersion } from './TransactionVersion'; + +/** + * Announce an account metadata transaction to associate a key-value state to an account. + */ +export class AccountMetadataTransaction extends Transaction { + /** + * Create a account meta data transaction object + * @param deadline - transaction deadline + * @param targetPublicKey - Public key of the target account. + * @param scopedMetadataKey - Metadata key scoped to source, target and type. + * @param valueSizeDelta - Change in value size in bytes. + * @param value - Difference between the previous value and new value. + * You can calculate value as xor(previous-value, new-value). + * If there is no previous value, use directly the new value. + * @param maxFee - (Optional) Max fee defined by the sender + * @returns {AccountMetadataTransaction} + */ + public static create(deadline: Deadline, + targetPublicKey: string, + scopedMetadataKey: UInt64, + valueSizeDelta: number, + value: Uint8Array, + networkType: NetworkType, + maxFee: UInt64 = new UInt64([0, 0])): AccountMetadataTransaction { + return new AccountMetadataTransaction(networkType, + TransactionVersion.ACCOUNT_METADATA_TRANSACTION, + deadline, + maxFee, + targetPublicKey, + scopedMetadataKey, + valueSizeDelta, + value); + } + + /** + * @param networkType + * @param version + * @param deadline + * @param maxFee + * @param targetPublicKey + * @param scopedMetadataKey + * @param valueSizeDelta + * @param value + * @param signature + * @param signer + * @param transactionInfo + */ + constructor(networkType: NetworkType, + version: number, + deadline: Deadline, + maxFee: UInt64, + /** + * Public key of the target account. + */ + public readonly targetPublicKey: string, + /** + * Metadata key scoped to source, target and type. + */ + public readonly scopedMetadataKey: UInt64, + /** + * Change in value size in bytes. + */ + public readonly valueSizeDelta: number, + /** + * Difference between the previous value and new value. + */ + public readonly value: Uint8Array, + signature?: string, + signer?: PublicAccount, + transactionInfo?: TransactionInfo) { + super(TransactionType.ACCOUNT_METADATA_TRANSACTION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); + if (value.length > 1024) { + throw new Error('The maximum value size is 1024'); + } + } + + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedAccountMetadataTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + AccountMetadataTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = AccountMetadataTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as AccountMetadataTransactionBuilder).getDeadline().timestamp), + Convert.uint8ToHex(builder.getTargetPublicKey().key), + new UInt64(builder.getScopedMetadataKey()), + builder.getValueSizeDelta(), + builder.getValue(), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountMetadataTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + + /** + * @override Transaction.size() + * @description get the byte size of a AccountLinkTransaction + * @returns {number} + * @memberof AccountLinkTransaction + */ + public get size(): number { + const byteSize = super.size; + + // set static byte size fields + const targetPublicKey = 32; + const byteScopedMetadataKey = 8; + const byteValueSizeDelta = 2; + + return byteSize + targetPublicKey + byteScopedMetadataKey + + byteValueSizeDelta + this.value.length; + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new AccountMetadataTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.ACCOUNT_METADATA_TRANSACTION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + this.scopedMetadataKey.toDTO(), + this.valueSizeDelta, + this.value, + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const transactionBuilder = new EmbeddedAccountMetadataTransactionBuilder( + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), + this.versionToDTO(), + TransactionType.ACCOUNT_METADATA_TRANSACTION.valueOf(), + new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + this.scopedMetadataKey.toDTO(), + this.valueSizeDelta, + this.value, + ); + return transactionBuilder.serialize(); + } +} diff --git a/src/model/transaction/MosaicMetadataTransaction.ts b/src/model/transaction/MosaicMetadataTransaction.ts new file mode 100644 index 0000000000..78798f73a9 --- /dev/null +++ b/src/model/transaction/MosaicMetadataTransaction.ts @@ -0,0 +1,207 @@ +/* + * 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 { SignSchema } from '../../core/crypto/SignSchema'; +import { Convert } from '../../core/format'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedMosaicMetadataTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { MosaicMetadataTransactionBuilder } from '../../infrastructure/catbuffer/MosaicMetadataTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto'; +import { PublicAccount } from '../account/PublicAccount'; +import { NetworkType } from '../blockchain/NetworkType'; +import { MosaicId } from '../mosaic/MosaicId'; +import { UInt64 } from '../UInt64'; +import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; +import { Transaction } from './Transaction'; +import { TransactionInfo } from './TransactionInfo'; +import { TransactionType } from './TransactionType'; +import { TransactionVersion } from './TransactionVersion'; + +/** + * Announce an mosaic metadata transaction to associate a key-value state to an account. + */ +export class MosaicMetadataTransaction extends Transaction { + /** + * Create a mosaic meta data transaction object + * @param deadline - transaction deadline + * @param targetPublicKey - Public key of the target account. + * @param scopedMetadataKey - Metadata key scoped to source, target and type. + * @param targetMosaicId - Target mosaic identifier. + * @param valueSizeDelta - Change in value size in bytes. + * @param value - Difference between the previous value and new value. + * You can calculate value as xor(previous-value, new-value). + * If there is no previous value, use directly the new value. + * @param maxFee - (Optional) Max fee defined by the sender + * @returns {MosaicMetadataTransaction} + */ + public static create(deadline: Deadline, + targetPublicKey: string, + scopedMetadataKey: UInt64, + targetMosaicId: MosaicId, + valueSizeDelta: number, + value: Uint8Array, + networkType: NetworkType, + maxFee: UInt64 = new UInt64([0, 0])): MosaicMetadataTransaction { + return new MosaicMetadataTransaction(networkType, + TransactionVersion.MOSAIC_METADATA_TRANSACTION, + deadline, + maxFee, + targetPublicKey, + scopedMetadataKey, + targetMosaicId, + valueSizeDelta, + value); + } + + /** + * @param networkType + * @param version + * @param deadline + * @param maxFee + * @param targetPublicKey + * @param scopedMetadataKey + * @param targetMosaicId + * @param valueSizeDelta + * @param value + * @param signature + * @param signer + * @param transactionInfo + */ + constructor(networkType: NetworkType, + version: number, + deadline: Deadline, + maxFee: UInt64, + /** + * Public key of the target account. + */ + public readonly targetPublicKey: string, + /** + * Metadata key scoped to source, target and type. + */ + public readonly scopedMetadataKey: UInt64, + /** + * Target mosaic identifier. + */ + public readonly targetMosaicId: MosaicId, + /** + * Change in value size in bytes. + */ + public readonly valueSizeDelta: number, + /** + * Difference between the previous value and new value. + */ + public readonly value: Uint8Array, + signature?: string, + signer?: PublicAccount, + transactionInfo?: TransactionInfo) { + super(TransactionType.MOSAIC_METADATA_TRANSACTION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); + if (value.length > 1024) { + throw new Error('The maximum value size is 1024'); + } + } + + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedMosaicMetadataTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + MosaicMetadataTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = MosaicMetadataTransaction.create( + isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as MosaicMetadataTransactionBuilder).getDeadline().timestamp), + Convert.uint8ToHex(builder.getTargetPublicKey().key), + new UInt64(builder.getScopedMetadataKey()), + new MosaicId(builder.getTargetMosaicId().unresolvedMosaicId), + builder.getValueSizeDelta(), + builder.getValue(), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MosaicMetadataTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + + /** + * @override Transaction.size() + * @description get the byte size of a AccountLinkTransaction + * @returns {number} + * @memberof AccountLinkTransaction + */ + public get size(): number { + const byteSize = super.size; + + // set static byte size fields + const targetPublicKey = 32; + const byteScopedMetadataKey = 8; + const byteTargetMosaicId = 8; + const byteValueSizeDelta = 2; + + return byteSize + targetPublicKey + byteScopedMetadataKey + + byteTargetMosaicId + byteValueSizeDelta + this.value.length; + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new MosaicMetadataTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.MOSAIC_METADATA_TRANSACTION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + this.scopedMetadataKey.toDTO(), + new UnresolvedMosaicIdDto(this.targetMosaicId.id.toDTO()), + this.valueSizeDelta, + this.value, + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const transactionBuilder = new EmbeddedMosaicMetadataTransactionBuilder( + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), + this.versionToDTO(), + TransactionType.MOSAIC_METADATA_TRANSACTION.valueOf(), + new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + this.scopedMetadataKey.toDTO(), + new UnresolvedMosaicIdDto(this.targetMosaicId.id.toDTO()), + this.valueSizeDelta, + this.value, + ); + return transactionBuilder.serialize(); + } +} diff --git a/src/model/transaction/NamespaceMetaDataTransaction.ts b/src/model/transaction/NamespaceMetaDataTransaction.ts new file mode 100644 index 0000000000..49d4236d94 --- /dev/null +++ b/src/model/transaction/NamespaceMetaDataTransaction.ts @@ -0,0 +1,208 @@ +/* + * 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 { SignSchema } from '../../core/crypto/SignSchema'; +import { Convert } from '../../core/format'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedNamespaceMetadataTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedNamespaceMetadataTransactionBuilder'; +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; +import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto'; +import { NamespaceMetadataTransactionBuilder } from '../../infrastructure/catbuffer/NamespaceMetadataTransactionBuilder'; +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; +import { PublicAccount } from '../account/PublicAccount'; +import { NetworkType } from '../blockchain/NetworkType'; +import { NamespaceId } from '../namespace/NamespaceId'; +import { UInt64 } from '../UInt64'; +import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; +import { Transaction } from './Transaction'; +import { TransactionInfo } from './TransactionInfo'; +import { TransactionType } from './TransactionType'; +import { TransactionVersion } from './TransactionVersion'; + +/** + * Announce an namespace metadata transaction to associate a key-value state to an account. + */ +export class NamespaceMetadataTransaction extends Transaction { + /** + * Create a mosaic meta data transaction object + * @param deadline - transaction deadline + * @param targetPublicKey - Public key of the target account. + * @param scopedMetadataKey - Metadata key scoped to source, target and type. + * @param targetNamespaceId - Target namespace identifier. + * @param valueSizeDelta - Change in value size in bytes. + * @param value - Difference between the previous value and new value. + * You can calculate value as xor(previous-value, new-value). + * If there is no previous value, use directly the new value. + * @param maxFee - (Optional) Max fee defined by the sender + * @returns {NamespaceMetadataTransaction} + */ + public static create(deadline: Deadline, + targetPublicKey: string, + scopedMetadataKey: UInt64, + targetNamespaceId: NamespaceId, + valueSizeDelta: number, + value: Uint8Array, + networkType: NetworkType, + maxFee: UInt64 = new UInt64([0, 0])): NamespaceMetadataTransaction { + return new NamespaceMetadataTransaction(networkType, + TransactionVersion.NAMESPACE_METADATA_TRANSACTION, + deadline, + maxFee, + targetPublicKey, + scopedMetadataKey, + targetNamespaceId, + valueSizeDelta, + value); + } + + /** + * @param networkType + * @param version + * @param deadline + * @param maxFee + * @param targetPublicKey + * @param scopedMetadataKey + * @param targetNamespaceId + * @param valueSizeDelta + * @param value + * @param signature + * @param signer + * @param transactionInfo + */ + constructor(networkType: NetworkType, + version: number, + deadline: Deadline, + maxFee: UInt64, + /** + * Public key of the target account. + */ + public readonly targetPublicKey: string, + /** + * Metadata key scoped to source, target and type. + */ + public readonly scopedMetadataKey: UInt64, + /** + * Target namespace identifier. + */ + public readonly targetNamespaceId: NamespaceId, + /** + * Change in value size in bytes. + */ + public readonly valueSizeDelta: number, + /** + * Difference between the previous value and new value. + */ + public readonly value: Uint8Array, + signature?: string, + signer?: PublicAccount, + transactionInfo?: TransactionInfo) { + super(TransactionType.NAMESPACE_METADATA_TRANSACTION, networkType, version, deadline, maxFee, signature, signer, transactionInfo); + if (value.length > 1024) { + throw new Error('The maximum value size is 1024'); + } + } + + /** + * Create a transaction object from payload + * @param {string} payload Binary payload + * @param {Boolean} isEmbedded Is embedded transaction (Default: false) + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {Transaction | InnerTransaction} + */ + public static createFromPayload(payload: string, + isEmbedded: boolean = false, + signSchema: SignSchema = SignSchema.SHA3): Transaction | InnerTransaction { + const builder = isEmbedded ? EmbeddedNamespaceMetadataTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)) : + NamespaceMetadataTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload)); + const signer = Convert.uint8ToHex(builder.getSigner().key); + const networkType = Convert.hexToUint8(builder.getVersion().toString(16))[0]; + const transaction = NamespaceMetadataTransaction.create( + isEmbedded ? Deadline.create() : + Deadline.createFromDTO((builder as NamespaceMetadataTransactionBuilder).getDeadline().timestamp), + Convert.uint8ToHex(builder.getTargetPublicKey().key), + new UInt64(builder.getScopedMetadataKey()), + new NamespaceId(builder.getTargetNamespaceId().namespaceId), + builder.getValueSizeDelta(), + builder.getValue(), + networkType, + isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as NamespaceMetadataTransactionBuilder).fee.amount), + ); + return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType, signSchema)) : transaction; + } + + /** + * @override Transaction.size() + * @description get the byte size of a AccountLinkTransaction + * @returns {number} + * @memberof AccountLinkTransaction + */ + public get size(): number { + const byteSize = super.size; + + // set static byte size fields + const targetPublicKey = 32; + const byteScopedMetadataKey = 8; + const byteTargetNamespaceId = 8; + const byteValueSizeDelta = 2; + + return byteSize + targetPublicKey + byteScopedMetadataKey + + byteTargetNamespaceId + byteValueSizeDelta + this.value.length; + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + + const transactionBuilder = new NamespaceMetadataTransactionBuilder( + new SignatureDto(signatureBuffer), + new KeyDto(signerBuffer), + this.versionToDTO(), + TransactionType.NAMESPACE_METADATA_TRANSACTION.valueOf(), + new AmountDto(this.maxFee.toDTO()), + new TimestampDto(this.deadline.toDTO()), + new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + this.scopedMetadataKey.toDTO(), + new NamespaceIdDto(this.targetNamespaceId.id.toDTO()), + this.valueSizeDelta, + this.value, + ); + return transactionBuilder.serialize(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const transactionBuilder = new EmbeddedNamespaceMetadataTransactionBuilder( + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), + this.versionToDTO(), + TransactionType.NAMESPACE_METADATA_TRANSACTION.valueOf(), + new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + this.scopedMetadataKey.toDTO(), + new NamespaceIdDto(this.targetNamespaceId.id.toDTO()), + this.valueSizeDelta, + this.value, + ); + return transactionBuilder.serialize(); + } +} diff --git a/src/model/transaction/TransactionType.ts b/src/model/transaction/TransactionType.ts index 9d571f0855..24fc2d6b84 100644 --- a/src/model/transaction/TransactionType.ts +++ b/src/model/transaction/TransactionType.ts @@ -127,4 +127,22 @@ export enum TransactionType { * @type {number} */ MOSAIC_GLOBAL_RESTRICTION = 0x4151, + + /** + * Account metadata transaction + * @type {number} + */ + ACCOUNT_METADATA_TRANSACTION = 0x4144, + + /** + * Mosaic metadata transaction + * @type {number} + */ + MOSAIC_METADATA_TRANSACTION = 0x4244, + + /** + * Namespace metadata transaction + * @type {number} + */ + NAMESPACE_METADATA_TRANSACTION = 0x4344, } diff --git a/src/model/transaction/TransactionVersion.ts b/src/model/transaction/TransactionVersion.ts index 71087ac326..5a09c39a20 100644 --- a/src/model/transaction/TransactionVersion.ts +++ b/src/model/transaction/TransactionVersion.ts @@ -135,4 +135,22 @@ export class TransactionVersion { * @type {number} */ public static readonly LINK_ACCOUNT = 0x01; + + /** + * Account metadata transaction version + * @type {number} + */ + public static readonly ACCOUNT_METADATA_TRANSACTION = 0x01; + + /** + * Mosaic metadata transaction version + * @type {number} + */ + public static readonly MOSAIC_METADATA_TRANSACTION = 0x01; + + /** + * Namespace metadata transaction version + * @type {number} + */ + public static readonly NAMESPACE_METADATA_TRANSACTION = 0x01; } diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index f6b7af8d20..1b80b8b694 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -36,6 +36,7 @@ import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { NamespaceType } from '../../../src/model/namespace/NamespaceType'; import { AccountAddressRestrictionTransaction } from '../../../src/model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../../src/model/transaction/AccountLinkTransaction'; +import { AccountMetadataTransaction } from '../../../src/model/transaction/AccountMetadataTransaction'; import { AccountMosaicRestrictionTransaction } from '../../../src/model/transaction/AccountMosaicRestrictionTransaction'; import { AccountRestrictionModification } from '../../../src/model/transaction/AccountRestrictionModification'; import { AccountRestrictionTransaction } from '../../../src/model/transaction/AccountRestrictionTransaction'; @@ -52,9 +53,11 @@ import { MosaicAddressRestrictionTransaction } from '../../../src/model/transact import { MosaicAliasTransaction } from '../../../src/model/transaction/MosaicAliasTransaction'; import { MosaicDefinitionTransaction } from '../../../src/model/transaction/MosaicDefinitionTransaction'; import { MosaicGlobalRestrictionTransaction } from '../../../src/model/transaction/MosaicGlobalRestrictionTransaction'; +import { MosaicMetadataTransaction } from '../../../src/model/transaction/MosaicMetadataTransaction'; import { MosaicSupplyChangeTransaction } from '../../../src/model/transaction/MosaicSupplyChangeTransaction'; import { MultisigCosignatoryModification } from '../../../src/model/transaction/MultisigCosignatoryModification'; import { MultisigCosignatoryModificationType } from '../../../src/model/transaction/MultisigCosignatoryModificationType'; +import { NamespaceMetadataTransaction } from '../../../src/model/transaction/NamespaceMetaDataTransaction'; import { PlainMessage } from '../../../src/model/transaction/PlainMessage'; import { RegisterNamespaceTransaction } from '../../../src/model/transaction/RegisterNamespaceTransaction'; import { SecretLockTransaction } from '../../../src/model/transaction/SecretLockTransaction'; @@ -587,6 +590,73 @@ describe('TransactionMapping - createFromPayload', () => { expect(transaction.previousRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(0).toHex()); expect(transaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(0).toHex()); }); + + it('should create AddressMetadataTransaction', () => { + const accountMetadataTransaction = AccountMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const signedTx = accountMetadataTransaction.signWith(account, generationHash); + + const transaction = TransactionMapping.createFromPayload(signedTx.payload) as AccountMetadataTransaction; + + expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_METADATA_TRANSACTION); + expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); + expect(transaction.valueSizeDelta).to.be.equal(1); + expect(convert.uint8ToHex(transaction.value)).to.be.equal(convert.uint8ToHex(new Uint8Array(10))); + }); + + it('should create MosaicMetadataTransaction', () => { + const mosaicMetadataTransaction = MosaicMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new MosaicId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const signedTx = mosaicMetadataTransaction.signWith(account, generationHash); + + const transaction = TransactionMapping.createFromPayload(signedTx.payload) as MosaicMetadataTransaction; + + expect(transaction.type).to.be.equal(TransactionType.MOSAIC_METADATA_TRANSACTION); + expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); + expect(transaction.valueSizeDelta).to.be.equal(1); + expect(transaction.targetMosaicId.toHex()).to.be.equal(new MosaicId([2262289484, 3405110546]).toHex()); + expect(convert.uint8ToHex(transaction.value)).to.be.equal(convert.uint8ToHex(new Uint8Array(10))); + }); + + it('should create NamespaceMetadataTransaction', () => { + const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new NamespaceId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const signedTx = namespaceMetadataTransaction.signWith(account, generationHash); + + const transaction = TransactionMapping.createFromPayload(signedTx.payload) as NamespaceMetadataTransaction; + + expect(transaction.type).to.be.equal(TransactionType.NAMESPACE_METADATA_TRANSACTION); + expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); + expect(transaction.valueSizeDelta).to.be.equal(1); + expect(transaction.targetNamespaceId.toHex()).to.be.equal(new NamespaceId([2262289484, 3405110546]).toHex()); + expect(convert.uint8ToHex(transaction.value)).to.be.equal(convert.uint8ToHex(new Uint8Array(10))); + }); }); describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => { @@ -1008,4 +1078,68 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => expect(transaction.previousRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(0).toHex()); expect(transaction.newRestrictionValue.toHex()).to.be.equal(UInt64.fromUint(0).toHex()); }); + + it('should create AddressMetadataTransaction', () => { + const accountMetadataTransaction = AccountMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const transaction = + TransactionMapping.createFromDTO(accountMetadataTransaction.toJSON()) as AccountMetadataTransaction; + + expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_METADATA_TRANSACTION); + expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); + expect(transaction.valueSizeDelta).to.be.equal(1); + expect(convert.uint8ToHex(transaction.value)).to.be.equal(convert.uint8ToHex(new Uint8Array(10))); + }); + + it('should create MosaicMetadataTransaction', () => { + const mosaicMetadataTransaction = MosaicMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new MosaicId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const transaction = + TransactionMapping.createFromDTO(mosaicMetadataTransaction.toJSON()) as MosaicMetadataTransaction; + + expect(transaction.type).to.be.equal(TransactionType.MOSAIC_METADATA_TRANSACTION); + expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); + expect(transaction.valueSizeDelta).to.be.equal(1); + expect(transaction.targetMosaicId.toHex()).to.be.equal(new MosaicId([2262289484, 3405110546]).toHex()); + expect(convert.uint8ToHex(transaction.value)).to.be.equal(convert.uint8ToHex(new Uint8Array(10))); + }); + + it('should create NamespaceMetadataTransaction', () => { + const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new NamespaceId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const transaction = + TransactionMapping.createFromDTO(namespaceMetadataTransaction.toJSON()) as NamespaceMetadataTransaction; + + expect(transaction.type).to.be.equal(TransactionType.NAMESPACE_METADATA_TRANSACTION); + expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); + expect(transaction.valueSizeDelta).to.be.equal(1); + expect(transaction.targetNamespaceId.toHex()).to.be.equal(new NamespaceId([2262289484, 3405110546]).toHex()); + expect(convert.uint8ToHex(transaction.value)).to.be.equal(convert.uint8ToHex(new Uint8Array(10))); + }); }); diff --git a/test/model/transaction/AccountMetadataTransaction.spec.ts b/test/model/transaction/AccountMetadataTransaction.spec.ts new file mode 100644 index 0000000000..bb534d5c51 --- /dev/null +++ b/test/model/transaction/AccountMetadataTransaction.spec.ts @@ -0,0 +1,105 @@ +/* + * 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 { expect } from 'chai'; +import { Account } from '../../../src/model/account/Account'; +import { NetworkType } from '../../../src/model/blockchain/NetworkType'; +import { AccountMetadataTransaction } from '../../../src/model/transaction/AccountMetadataTransaction'; +import { Deadline } from '../../../src/model/transaction/Deadline'; +import { UInt64 } from '../../../src/model/UInt64'; +import { TestingAccount } from '../../conf/conf.spec'; + +describe('AccountMetadataTransaction', () => { + let account: Account; + const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; + before(() => { + account = TestingAccount; + }); + + it('should default maxFee field be set to 0', () => { + const accountMetadataTransaction = AccountMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + expect(accountMetadataTransaction.maxFee.higher).to.be.equal(0); + expect(accountMetadataTransaction.maxFee.lower).to.be.equal(0); + }); + + it('should filled maxFee override transaction maxFee', () => { + const accountMetadataTransaction = AccountMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + new UInt64([1, 0]), + ); + + expect(accountMetadataTransaction.maxFee.higher).to.be.equal(0); + expect(accountMetadataTransaction.maxFee.lower).to.be.equal(1); + }); + + it('should create and sign an AccountMetadataTransaction object', () => { + const accountMetadataTransaction = AccountMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const signedTransaction = accountMetadataTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFEE80300000000000001000A0000000000000000000000'); + }); + + it('should throw error if value size is bigger than 1024', () => { + expect(() => { + AccountMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + 1, + new Uint8Array(1025), + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'The maximum value size is 1024'); + }); + + describe('size', () => { + it('should return 153 for AccountMetadataTransaction byte size', () => { + const accountMetadataTransaction = AccountMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + expect(accountMetadataTransaction.size).to.be.equal(172); + }); + }); +}); diff --git a/test/model/transaction/MosaicMetadataTransaction.spec.ts b/test/model/transaction/MosaicMetadataTransaction.spec.ts new file mode 100644 index 0000000000..09832cdbdc --- /dev/null +++ b/test/model/transaction/MosaicMetadataTransaction.spec.ts @@ -0,0 +1,112 @@ +/* + * 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 { expect } from 'chai'; +import { Account } from '../../../src/model/account/Account'; +import { NetworkType } from '../../../src/model/blockchain/NetworkType'; +import { MosaicId } from '../../../src/model/mosaic/MosaicId'; +import { Deadline } from '../../../src/model/transaction/Deadline'; +import { MosaicMetadataTransaction } from '../../../src/model/transaction/MosaicMetadataTransaction'; +import { UInt64 } from '../../../src/model/UInt64'; +import { TestingAccount } from '../../conf/conf.spec'; + +describe('MosaicMetadataTransaction', () => { + let account: Account; + const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; + before(() => { + account = TestingAccount; + }); + + it('should default maxFee field be set to 0', () => { + const mosaicMetadataTransaction = MosaicMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new MosaicId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + expect(mosaicMetadataTransaction.maxFee.higher).to.be.equal(0); + expect(mosaicMetadataTransaction.maxFee.lower).to.be.equal(0); + }); + + it('should filled maxFee override transaction maxFee', () => { + const mosaicMetadataTransaction = MosaicMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new MosaicId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + new UInt64([1, 0]), + ); + + expect(mosaicMetadataTransaction.maxFee.higher).to.be.equal(0); + expect(mosaicMetadataTransaction.maxFee.lower).to.be.equal(1); + }); + + it('should create and sign an MosaicMetadataTransaction object', () => { + const mosaicMetadataTransaction = MosaicMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new MosaicId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const signedTransaction = mosaicMetadataTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFEE80' + + '30000000000004CCCD78612DDF5CA01000A0000000000000000000000'); + }); + + it('should throw error if value size is bigger than 1024', () => { + expect(() => { + MosaicMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new MosaicId([2262289484, 3405110546]), + 1, + new Uint8Array(1025), + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'The maximum value size is 1024'); + }); + + describe('size', () => { + it('should return 153 for MosaicMetadataTransaction byte size', () => { + const mosaicMetadataTransaction = MosaicMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new MosaicId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + expect(mosaicMetadataTransaction.size).to.be.equal(180); + }); + }); +}); diff --git a/test/model/transaction/NamespaceMetadata.spec.ts b/test/model/transaction/NamespaceMetadata.spec.ts new file mode 100644 index 0000000000..2c5a4b64b9 --- /dev/null +++ b/test/model/transaction/NamespaceMetadata.spec.ts @@ -0,0 +1,112 @@ +/* + * 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 { expect } from 'chai'; +import { Account } from '../../../src/model/account/Account'; +import { NetworkType } from '../../../src/model/blockchain/NetworkType'; +import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; +import { Deadline } from '../../../src/model/transaction/Deadline'; +import { NamespaceMetadataTransaction } from '../../../src/model/transaction/NamespaceMetadataTransaction'; +import { UInt64 } from '../../../src/model/UInt64'; +import { TestingAccount } from '../../conf/conf.spec'; + +describe('NamespaceMetadataTransaction', () => { + let account: Account; + const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; + before(() => { + account = TestingAccount; + }); + + it('should default maxFee field be set to 0', () => { + const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new NamespaceId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + expect(namespaceMetadataTransaction.maxFee.higher).to.be.equal(0); + expect(namespaceMetadataTransaction.maxFee.lower).to.be.equal(0); + }); + + it('should filled maxFee override transaction maxFee', () => { + const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new NamespaceId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + new UInt64([1, 0]), + ); + + expect(namespaceMetadataTransaction.maxFee.higher).to.be.equal(0); + expect(namespaceMetadataTransaction.maxFee.lower).to.be.equal(1); + }); + + it('should create and sign an NamespaceMetadataTransaction object', () => { + const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new NamespaceId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + + const signedTransaction = namespaceMetadataTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFEE80' + + '30000000000004CCCD78612DDF5CA01000A0000000000000000000000'); + }); + + it('should throw error if value size is bigger than 1024', () => { + expect(() => { + NamespaceMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new NamespaceId([2262289484, 3405110546]), + 1, + new Uint8Array(1025), + NetworkType.MIJIN_TEST, + ); + }).to.throw(Error, 'The maximum value size is 1024'); + }); + + describe('size', () => { + it('should return 153 for NamespaceMetadataTransaction byte size', () => { + const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( + Deadline.create(), + account.publicKey, + UInt64.fromUint(1000), + new NamespaceId([2262289484, 3405110546]), + 1, + new Uint8Array(10), + NetworkType.MIJIN_TEST, + ); + expect(namespaceMetadataTransaction.size).to.be.equal(180); + }); + }); +}); From 71fd041404a67cdccf6707662ce5eae2407b374b Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 20 Aug 2019 21:45:37 +0100 Subject: [PATCH 93/98] renamed namespaceMetadataTransaction unit test file name --- ...spaceMetadata.spec.ts => NamespaceMetadataTransaction.spec.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/model/transaction/{NamespaceMetadata.spec.ts => NamespaceMetadataTransaction.spec.ts} (100%) diff --git a/test/model/transaction/NamespaceMetadata.spec.ts b/test/model/transaction/NamespaceMetadataTransaction.spec.ts similarity index 100% rename from test/model/transaction/NamespaceMetadata.spec.ts rename to test/model/transaction/NamespaceMetadataTransaction.spec.ts From 49740ed52486b3efa12782d508ba7d5cac47a7de Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 20 Aug 2019 21:50:24 +0100 Subject: [PATCH 94/98] Added missing exports --- src/model/model.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/model/model.ts b/src/model/model.ts index f9ecae784e..b1a5957300 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -130,6 +130,9 @@ export * from './transaction/TransactionStatus'; export * from './transaction/TransactionStatusError'; export * from './transaction/TransactionType'; export * from './transaction/TransferTransaction'; +export * from './transaction/AccountMetadataTransaction'; +export * from './transaction/MosaicMetadataTransaction'; +export * from './transaction/NamespaceMetadataTransaction'; // Wallet export * from './wallet/EncryptedPrivateKey'; From 45c1e1a4804288c28c05df6f2a9214f8d7976ec4 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 20 Aug 2019 21:51:23 +0100 Subject: [PATCH 95/98] Added missing mosaic restriction exports --- src/model/model.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/model/model.ts b/src/model/model.ts index b1a5957300..169a9ca507 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -133,6 +133,8 @@ export * from './transaction/TransferTransaction'; export * from './transaction/AccountMetadataTransaction'; export * from './transaction/MosaicMetadataTransaction'; export * from './transaction/NamespaceMetadataTransaction'; +export * from './transaction/MosaicGlobalRestrictionTransaction'; +export * from './transaction/MosaicAddressRestrictionTransaction'; // Wallet export * from './wallet/EncryptedPrivateKey'; From c05b448a821b7bba3bb7df4003f829fa3e692cd5 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 20 Aug 2019 22:00:19 +0100 Subject: [PATCH 96/98] Renamed NamespaceMetaDataTransaction.ts --- e2e/infrastructure/TransactionHttp.spec.ts | 8 ++++---- .../transaction/CreateTransactionFromDTO.ts | 2 +- .../transaction/CreateTransactionFromPayload.ts | 2 +- .../transaction/SerializeTransactionToJSON.ts | 2 +- test/core/utils/TransactionMapping.spec.ts | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index ebb487942c..ff7e1952eb 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -18,7 +18,7 @@ import * as CryptoJS from 'crypto-js'; import {ChronoUnit} from 'js-joda'; import {keccak_256, sha3_256} from 'js-sha3'; import {Crypto} from '../../src/core/crypto'; -import { Convert as convert, Convert } from '../../src/core/format'; +import { Convert, Convert as convert } from '../../src/core/format'; import { TransactionMapping } from '../../src/core/utils/TransactionMapping'; import {AccountHttp} from '../../src/infrastructure/AccountHttp'; import { NamespaceHttp } from '../../src/infrastructure/infrastructure'; @@ -39,6 +39,7 @@ import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AccountAddressRestrictionTransaction } from '../../src/model/transaction/AccountAddressRestrictionTransaction'; import { AccountLinkTransaction } from '../../src/model/transaction/AccountLinkTransaction'; +import { AccountMetadataTransaction } from '../../src/model/transaction/AccountMetadataTransaction'; import { AccountMosaicRestrictionTransaction } from '../../src/model/transaction/AccountMosaicRestrictionTransaction'; import { AccountOperationRestrictionTransaction } from '../../src/model/transaction/AccountOperationRestrictionTransaction'; import { AccountRestrictionModification } from '../../src/model/transaction/AccountRestrictionModification'; @@ -56,7 +57,9 @@ import { MosaicAddressRestrictionTransaction } from '../../src/model/transaction import { MosaicAliasTransaction } from '../../src/model/transaction/MosaicAliasTransaction'; import {MosaicDefinitionTransaction} from '../../src/model/transaction/MosaicDefinitionTransaction'; import { MosaicGlobalRestrictionTransaction } from '../../src/model/transaction/MosaicGlobalRestrictionTransaction'; +import { MosaicMetadataTransaction } from '../../src/model/transaction/MosaicMetadataTransaction'; import {MosaicSupplyChangeTransaction} from '../../src/model/transaction/MosaicSupplyChangeTransaction'; +import { NamespaceMetadataTransaction } from '../../src/model/transaction/NamespaceMetadataTransaction'; import { PlainMessage } from '../../src/model/transaction/PlainMessage'; import {RegisterNamespaceTransaction} from '../../src/model/transaction/RegisterNamespaceTransaction'; import {SecretLockTransaction} from '../../src/model/transaction/SecretLockTransaction'; @@ -66,9 +69,6 @@ import {Transaction} from '../../src/model/transaction/Transaction'; import {TransactionType} from '../../src/model/transaction/TransactionType'; import {TransferTransaction} from '../../src/model/transaction/TransferTransaction'; import {UInt64} from '../../src/model/UInt64'; -import { AccountMetadataTransaction } from '../../src/model/transaction/AccountMetadataTransaction'; -import { MosaicMetadataTransaction } from '../../src/model/transaction/MosaicMetadataTransaction'; -import { NamespaceMetadataTransaction } from '../../src/model/transaction/NamespaceMetaDataTransaction'; describe('TransactionHttp', () => { let transactionHash; let transactionId; diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index d97e24bd4a..27d698a4bb 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -46,7 +46,7 @@ import { MosaicGlobalRestrictionTransaction } from '../../model/transaction/Mosa import { MosaicMetadataTransaction } from '../../model/transaction/MosaicMetadataTransaction'; import {MosaicSupplyChangeTransaction} from '../../model/transaction/MosaicSupplyChangeTransaction'; import {MultisigCosignatoryModification} from '../../model/transaction/MultisigCosignatoryModification'; -import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetaDataTransaction'; +import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetadataTransaction'; import {EmptyMessage, PlainMessage} from '../../model/transaction/PlainMessage'; import {RegisterNamespaceTransaction} from '../../model/transaction/RegisterNamespaceTransaction'; import {SecretLockTransaction} from '../../model/transaction/SecretLockTransaction'; diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index 87a5455da5..20b0410151 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -32,7 +32,7 @@ import { MosaicDefinitionTransaction } from '../../model/transaction/MosaicDefin import { MosaicGlobalRestrictionTransaction } from '../../model/transaction/MosaicGlobalRestrictionTransaction'; import { MosaicMetadataTransaction } from '../../model/transaction/MosaicMetadataTransaction'; import { MosaicSupplyChangeTransaction } from '../../model/transaction/MosaicSupplyChangeTransaction'; -import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetaDataTransaction'; +import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetadataTransaction'; import { RegisterNamespaceTransaction } from '../../model/transaction/RegisterNamespaceTransaction'; import { SecretLockTransaction } from '../../model/transaction/SecretLockTransaction'; import { SecretProofTransaction } from '../../model/transaction/SecretProofTransaction'; diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index ee68778a74..48fa73fee7 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -30,7 +30,7 @@ import { MosaicDefinitionTransaction } from '../../model/transaction/MosaicDefin import { MosaicGlobalRestrictionTransaction } from '../../model/transaction/MosaicGlobalRestrictionTransaction'; import { MosaicMetadataTransaction } from '../../model/transaction/MosaicMetadataTransaction'; import { MosaicSupplyChangeTransaction } from '../../model/transaction/MosaicSupplyChangeTransaction'; -import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetaDataTransaction'; +import { NamespaceMetadataTransaction } from '../../model/transaction/NamespaceMetadataTransaction'; import { RegisterNamespaceTransaction } from '../../model/transaction/RegisterNamespaceTransaction'; import { SecretLockTransaction } from '../../model/transaction/SecretLockTransaction'; import { SecretProofTransaction } from '../../model/transaction/SecretProofTransaction'; diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index 1b80b8b694..53e7d8df9c 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -57,7 +57,7 @@ import { MosaicMetadataTransaction } from '../../../src/model/transaction/Mosaic import { MosaicSupplyChangeTransaction } from '../../../src/model/transaction/MosaicSupplyChangeTransaction'; import { MultisigCosignatoryModification } from '../../../src/model/transaction/MultisigCosignatoryModification'; import { MultisigCosignatoryModificationType } from '../../../src/model/transaction/MultisigCosignatoryModificationType'; -import { NamespaceMetadataTransaction } from '../../../src/model/transaction/NamespaceMetaDataTransaction'; +import { NamespaceMetadataTransaction } from '../../../src/model/transaction/NamespaceMetadataTransaction'; import { PlainMessage } from '../../../src/model/transaction/PlainMessage'; import { RegisterNamespaceTransaction } from '../../../src/model/transaction/RegisterNamespaceTransaction'; import { SecretLockTransaction } from '../../../src/model/transaction/SecretLockTransaction'; From b228d090798e1b5a498fbb0f943d428bc5f4a6b9 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 20 Aug 2019 22:02:58 +0100 Subject: [PATCH 97/98] Rename NamespaceMetadata --- ...paceMetaDataTransaction.ts => NamespaceMetadataTransaction.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/model/transaction/{NamespaceMetaDataTransaction.ts => NamespaceMetadataTransaction.ts} (100%) diff --git a/src/model/transaction/NamespaceMetaDataTransaction.ts b/src/model/transaction/NamespaceMetadataTransaction.ts similarity index 100% rename from src/model/transaction/NamespaceMetaDataTransaction.ts rename to src/model/transaction/NamespaceMetadataTransaction.ts From b0e743329b8e90c0727547b2c1ed77d47046effe Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 21 Aug 2019 12:00:38 +0100 Subject: [PATCH 98/98] Added missing mosaicRestrictionType export --- src/model/model.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/model/model.ts b/src/model/model.ts index 169a9ca507..c825aa96ef 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -56,6 +56,7 @@ export * from './mosaic/NetworkCurrencyMosaic'; export * from './mosaic/NetworkHarvestMosaic'; export * from './mosaic/MosaicNames'; export * from './mosaic/MosaicPropertyType'; +export * from './mosaic/MosaicRestrictionType'; // Namespace export * from '../service/Namespace';