diff --git a/e2e/conf/network.conf b/e2e/conf/network.conf index 95fa85d3c7..150443d82d 100644 --- a/e2e/conf/network.conf +++ b/e2e/conf/network.conf @@ -1,54 +1,54 @@ { "apiUrl": "http://localhost:3000", - "generationHash": "57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6", + "generationHash": "5E34C898234E17E8553359D4DEAA123742C323F4C42758C511E6CC805934853E", "testAccount": { - "privateKey": "D242FB34C2C4DD36E995B9C865F93940065E326661BA5A4A247331D211FE3A3D", - "address": "SBMYYFIM6VGG45KWGSZLSXFHP74WVT7MOF6UYBHT", - "publicKey": "2FC3872A792933617D70E02AFF8FBDE152821A0DF0CA5FB04CB56FC3D21C8863" + "privateKey": "C422CC3C9257A1568036E1726E64EB5923C8363A13D4344F9E66CD89C8789BC7", + "address": "SAMA2UEQNAQ45DWYDNJVLPWKQJDAHFZIVLWACIGN", + "publicKey": "8A78C9E9B0E59D0F74C0D47AB29FBD523C706293A3FA9CD9FE0EEB2C10EA924A" }, "multisigAccount": { - "privateKey": "6EBE2AB0584C816771B494B36B40EC6CE1A0024C37DC6056D89D570A21A70262", - "address": "SCJAK5N6ICIE3JGHV5SVDSSNM5RUZZVDWQJ5G76N", - "publicKey": "224556169645EFAB772BFE1B5665490334428017E5D86FB3C9DFC4070B2F16A6" + "privateKey": "F6815438AE34F95F2CF364B4679D16F3602CA2107073C0709738BAB457B09A45", + "publicKey": "FAF3F9FD3E32EB43273E5351BAE705D0179D37CBDCC4DD78A0C73232DD3EF32C", + "address": "SDC4BXKIIDBQA2CY6RPRFO3WLC5OZHLKLJJ3NFEH" }, "cosignatoryAccount": { - "privateKey": "44C0044B36AEF44C7743C407CEE4B6FD801BF6B0652AB7799B0991FFD3A81E71", - "address": "SCPL4YCGZYCML5WUSCIVN5MQF5YZAAF4GMZJIEL4", - "publicKey": "76C1622C7FB58986E500228E8FFB30C606CAAFC1CD78E770E82C73DAB7BD7C9F" + "privateKey": "F48EA053D7D2B47DC518FDD69B338D34C819D9AC51E8754378F2D86FC29783C7", + "publicKey": "D9FB51DDFA64CC56D7AEBB32976DA8A3A72C8C7D02838AA1041046FA0883EBC6", + "address": "SCHNSELDJ7JN5MPHBOKHNBR2QRST4GOGEMS4XZNE" }, "cosignatory2Account": { - "privateKey": "F7B3A64652BAE6DB00D8B7C45F9D1C9BE0DB9E02002111A0B547AE1E220B7DDC", - "address": "SBISV4QCGJ7SSOLG64DBNPWU6J7SSY64R22D2L3Q", - "publicKey": "B5C2611E32E16482B0B9811ABF906A1DE84184DED1D343790482F517C02FB01C" + "privateKey": "E697E9E0D849ACD3BD9379E80C4E953B23375112C28D983AF94160AD269BE327", + "publicKey": "2B4598150E66B26D991FA56FAF691C539FD1A92EBEA99E2AF91808B9C7C4316F", + "address": "SAWZITCY4TCOFBSSINFO4DQZTRBSB5W5OBSQE237" }, "cosignatory3Account": { - "privateKey": "A7D6ED74CDDECBF621DDC63558433DB604FA800D138810B3DF9B4EC880D0705F", - "address": "SD2UY5LHIAAZDVKRHBOYSS4MTLHVTJVUTQPEGV2U", - "publicKey": "3A33DA75E00F643C49C57E8BD3282149911B06FF107C37F7AEDFED5532166BDA" + "privateKey": "3F42F4308B3EA912A9FE482D6DD04CCFD8D37E4397BF9655AA2EF36894491CAB", + "publicKey": "26A339827614E7AEE9DB427323AA3A49A48456AA5656D9A2E1B50FF93DE90756", + "address": "SCGYYXGL3TLZBOA5TUCCQYIM6NSYSLVCBVHGYKKW" }, "cosignatory4Account": { - "privateKey": "D2A12301F5595869EFD5374B3372F0ED7EC26BF73A71D310950CC018D3FA0B03", - "address": "SD7PYMM2BTT4SGSITZ2MBQBK4SXIQQQV4ZOP46VF", - "publicKey": "FDE589878756C2287056EC8D7B2829D9C1FA6D389EBDC808034813FE7810AAB0" + "privateKey": "53D6A6659A200DAF4930AD4C8A3B5B28ECAAA1F643E990C0A41C0B8EC9B3D05A", + "publicKey": "F721863CC533C3DF4429A957F822B986C81E62A91726A3E3BD0B861FA42F757D", + "address": "SD3JPQ2KXMQKLVOHJV7GTOYV73CL72ZSEOW7RIWE" }, "testAccount2": { - "privateKey": "E5DCCEBDB01A8B03A7DB7BA5888E2E33FD4617B5F6FED48C4C09C0780F422713", - "address": "SBSBLBT7CIOQG6XUI7TRDMHV4TKS5O7QM3MWQYHL", - "publicKey": "5F14CD455A1C0B08073C657EFA09365921736C1ADAF0F0685848678AE966EE09" + "privateKey": "F0AB1010EFEE19EE5373719881DF5123C13E643C519655F7E97347BFF77175BF", + "publicKey": "9DBF67474D6E1F8B131B4EB1F5BA0595AFFAE1123607BC1048F342193D7E669F", + "address": "SDBC4JE7GTJAKN2XJCQWWRJMYA35AFOYQBATXOUA" }, "testAccount3": { - "privateKey": "CA95470BEFF4487D692D501E5C41F86FAE9CE6DD15B7B64E150E42A18BDE9CF8", - "address": "SBCFDASM35I6JSLUPQMSX2WGJG55WOCNB53NNVPH", - "publicKey": "E97077A656D9E7F5679880D4950BBF2B3638B7ACE17C82CCB7881DE9BAF396C6" + "privateKey": "61C3C8F24E3708CFE17A64B66EBD29D747326DBF7962EBEE9340439725C04F11", + "publicKey": "399C1D18FDE3293DCF7BF522626266663C83453BDF7D38C9E96AFC795C07E0A2", + "address": "SC7PPZRJMEMQ7S32PURJTTNHOATDYQ4NPRFOAOUO" }, "testAccountNoBalance": { - "privateKey": "A0591F79F588758280DFB4823A47FCEEC6A551344F794FFDE3760A9D7E1DE348", - "address": "SC5NTT5APX2FAUS4VQUII3UTMAD7GHRFTLDQOEDW", - "publicKey": "6D652E480E5B2997A19D0C7485724693D79A63FCD591A948B40240BD196BA7D6" + "privateKey": "6530E5ED4B6D32CB9AF2EE09D2889DC781C569B83C137854EDC7773B057074A1", + "publicKey": "559019D82C4CACAAE616A024544251D58BB4464CD36407224475A577F9649E78", + "address": "SCQP4B6BDNH5MZHTLL2ZNXIPYSLD5BU4NDXBZXNK" }, "harvestingAccount": { - "privateKey": "0B9802C011DA2D61BCD203F4DC76C012898EE38BA54A7E030B86630A8FD43CA6", - "address": "SAALWHKCWH72J53M3M4LB6UYFGLQMAOXJACWJX2U", - "publicKey": "092CAAFEBCB51C64A7CE423050964492407B264CA306D063DBA927A2304C4DD8" + "privateKey": "AF39DCC819388A2CE9DC0922730D7579588571A63F349A0FB1BC44807C926E53", + "publicKey": "FAEDB16763F22870B75BF934EA5F2792BDF109EC0C504718DDCBD92DF13C2628", + "address": "SCNPFCWFV2FYQVMU5HMJJTMADRZ3LRXVA76F56N2" } } \ No newline at end of file diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 89c0ba90ff..c190d8c0ae 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -19,13 +19,13 @@ 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'; +import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AccountRestrictionModification } from '../../src/model/transaction/AccountRestrictionModification'; import { AccountRestrictionTransaction } from '../../src/model/transaction/AccountRestrictionTransaction'; @@ -164,7 +164,7 @@ describe('AccountHttp', () => { it('Announce addressAliasTransaction', (done) => { const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, account.address, NetworkType.MIJIN_TEST, @@ -200,7 +200,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); @@ -293,8 +293,8 @@ describe('AccountHttp', () => { }); }); - describe('getAccountRestrictions', () => { - it('should call getAccountRestrictions successfully', (done) => { + describe('getAccountRestrictionsFromAccounts', () => { + it('should call getAccountRestrictionsFromAccounts successfully', (done) => { setTimeout(() => { accountHttp.getAccountRestrictionsFromAccounts([accountAddress]).subscribe((accountRestrictions) => { deepEqual(accountRestrictions[0]!.accountRestrictions.address, accountAddress); @@ -391,7 +391,7 @@ describe('AccountHttp', () => { it('Announce addressAliasTransaction', (done) => { const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), - AliasActionType.Unlink, + AliasAction.Unlink, namespaceId, account.address, NetworkType.MIJIN_TEST, @@ -426,7 +426,7 @@ describe('AccountHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockIncomingAddress, [addressPropertyFilter], NetworkType.MIJIN_TEST, ); diff --git a/e2e/infrastructure/MosaicHttp.spec.ts b/e2e/infrastructure/MosaicHttp.spec.ts index 8277aae662..37717636aa 100644 --- a/e2e/infrastructure/MosaicHttp.spec.ts +++ b/e2e/infrastructure/MosaicHttp.spec.ts @@ -21,7 +21,7 @@ import { NetworkType } from '../../src/model/blockchain/NetworkType'; import {MosaicId} from '../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; import { MosaicProperties } from '../../src/model/mosaic/MosaicProperties'; -import { AliasActionType } from '../../src/model/namespace/AliasActionType'; +import { AliasAction } from '../../src/model/namespace/AliasAction'; import {NamespaceId} from '../../src/model/namespace/NamespaceId'; import { Deadline } from '../../src/model/transaction/Deadline'; import { MosaicAliasTransaction } from '../../src/model/transaction/MosaicAliasTransaction'; @@ -132,7 +132,7 @@ describe('MosaicHttp', () => { it('Announce MosaicAliasTransaction', (done) => { const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, mosaicId, NetworkType.MIJIN_TEST, @@ -182,19 +182,6 @@ describe('MosaicHttp', () => { }); }); - describe('getMosaics', () => { - it('should return mosaics given array of mosaicIds', (done) => { - mosaicHttp.getMosaics([mosaicId]) - .subscribe((mosaicInfos) => { - expect(mosaicInfos[0].height.lower).not.to.be.null; - expect(mosaicInfos[0].divisibility).to.be.equal(3); - expect(mosaicInfos[0].isSupplyMutable()).to.be.equal(true); - expect(mosaicInfos[0].isTransferable()).to.be.equal(true); - done(); - }); - }); - }); - describe('getMosaicsNames', () => { it('should call getMosaicsNames successfully', (done) => { mosaicHttp.getMosaicsNames([mosaicId]).subscribe((mosaicNames) => { @@ -222,7 +209,7 @@ describe('MosaicHttp', () => { it('Announce MosaicAliasTransaction', (done) => { const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), - AliasActionType.Unlink, + AliasAction.Unlink, namespaceId, mosaicId, NetworkType.MIJIN_TEST, diff --git a/e2e/infrastructure/NamespaceHttp.spec.ts b/e2e/infrastructure/NamespaceHttp.spec.ts index afc63aa4a0..5a33e7dd46 100644 --- a/e2e/infrastructure/NamespaceHttp.spec.ts +++ b/e2e/infrastructure/NamespaceHttp.spec.ts @@ -21,7 +21,7 @@ import { TransactionHttp } from '../../src/infrastructure/TransactionHttp'; import { Account } from '../../src/model/account/Account'; import {NetworkType} from '../../src/model/blockchain/NetworkType'; import {NetworkCurrencyMosaic} from '../../src/model/mosaic/NetworkCurrencyMosaic'; -import { AliasActionType } from '../../src/model/namespace/AliasActionType'; +import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; import { Deadline } from '../../src/model/transaction/Deadline'; @@ -94,7 +94,7 @@ describe('NamespaceHttp', () => { it('standalone', (done) => { const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, account.address, NetworkType.MIJIN_TEST, diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 2f60993e0c..ee0f981589 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'; @@ -35,12 +35,12 @@ import {MosaicProperties} from '../../src/model/mosaic/MosaicProperties'; import { MosaicRestrictionType } from '../../src/model/mosaic/MosaicRestrictionType'; import {MosaicSupplyType} from '../../src/model/mosaic/MosaicSupplyType'; import {NetworkCurrencyMosaic} from '../../src/model/mosaic/NetworkCurrencyMosaic'; -import { AliasActionType } from '../../src/model/namespace/AliasActionType'; +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'; @@ -387,7 +387,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Address', () => { + describe('AccountRestrictionTransaction - Outgoing Address', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -404,13 +404,13 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + AccountRestrictionType.BlockOutgoingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); 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; @@ -425,7 +425,7 @@ describe('TransactionHttp', () => { transactionHttp.announce(signedTransaction); }); }); - describe('AccountRestrictionTransaction - Address', () => { + describe('AccountRestrictionTransaction - Outgoing Address', () => { let listener: Listener; before (() => { listener = new Listener(config.apiUrl); @@ -441,7 +441,83 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockAddress, + 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); + 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.BlockIncomingAddress, + [addressRestrictionFilter], + NetworkType.MIJIN_TEST, + ); + const signedTransaction = addressModification.signWith(account, generationHash); + + 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; + 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 - Incoming 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.BlockIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -479,13 +555,13 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockMosaic, + AccountRestrictionType.BlockMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); 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; @@ -516,7 +592,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockMosaic, + AccountRestrictionType.BlockMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -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); @@ -554,13 +630,13 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockTransaction, + AccountRestrictionType.BlockIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); 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; @@ -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); @@ -591,7 +667,7 @@ describe('TransactionHttp', () => { ); const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.BlockTransaction, + AccountRestrictionType.BlockIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -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: 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; + 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 (() => { @@ -755,7 +908,7 @@ describe('TransactionHttp', () => { it('standalone', (done) => { const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, account.address, NetworkType.MIJIN_TEST, @@ -764,7 +917,7 @@ describe('TransactionHttp', () => { listener.confirmed(account.address).subscribe((transaction: AddressAliasTransaction) => { expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; - expect(transaction.actionType, 'ActionType').not.to.be.undefined; + expect(transaction.aliasAction, 'AliasAction').not.to.be.undefined; expect(transaction.address, 'Address').not.to.be.undefined; done(); }); @@ -788,7 +941,7 @@ describe('TransactionHttp', () => { it('aggregate', (done) => { const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), - AliasActionType.Unlink, + AliasAction.Unlink, namespaceId, account.address, NetworkType.MIJIN_TEST, @@ -890,7 +1043,7 @@ describe('TransactionHttp', () => { it('standalone', (done) => { const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, mosaicId, NetworkType.MIJIN_TEST, @@ -899,7 +1052,7 @@ describe('TransactionHttp', () => { listener.confirmed(account.address).subscribe((transaction: MosaicAliasTransaction) => { expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; - expect(transaction.actionType, 'ActionType').not.to.be.undefined; + expect(transaction.aliasAction, 'AliasAction').not.to.be.undefined; expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; done(); }); @@ -959,7 +1112,7 @@ describe('TransactionHttp', () => { it('aggregate', (done) => { const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), - AliasActionType.Unlink, + AliasAction.Unlink, namespaceId, mosaicId, NetworkType.MIJIN_TEST, diff --git a/e2e/infrastructure/transaction/CreateTransactionFromDTO.spec.ts b/e2e/infrastructure/transaction/CreateTransactionFromDTO.spec.ts index 5ccda9b9bc..7f9a802332 100644 --- a/e2e/infrastructure/transaction/CreateTransactionFromDTO.spec.ts +++ b/e2e/infrastructure/transaction/CreateTransactionFromDTO.spec.ts @@ -716,7 +716,7 @@ describe('CreateTransactionFromDTO', () => { modifications: [ { cosignatoryPublicKey: '76C1622C7FB58986E500228E8FFB30C606CAAFC1CD78E770E82C73DAB7BD7C9F', - type: 0, + modificiationType: 0, }, ], signature: '553E696EB4A54E43A11D180EBA57E4B89D0048C9DD2604A9E0608120018B9E0' + @@ -783,7 +783,7 @@ describe('CreateTransactionFromDTO', () => { { cosignatoryPublicKey: '589B73FBC22063E9AE6FBAC67CB9C6EA865EF556E5' + 'FB8B7310D45F77C1250B97', - type: 0, + modificiationType: 0, }, ], signer: 'B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', diff --git a/e2e/infrastructure/transaction/ValidateTransaction.ts b/e2e/infrastructure/transaction/ValidateTransaction.ts index 3a2954acba..4d2640f915 100644 --- a/e2e/infrastructure/transaction/ValidateTransaction.ts +++ b/e2e/infrastructure/transaction/ValidateTransaction.ts @@ -124,7 +124,7 @@ const ValidateTransaction = { .to.be.equal(modifyMultisigAccountTransactionDTO.transaction.minRemovalDelta); deepEqual(modifyMultisigAccountTransaction.modifications[0], new MultisigCosignatoryModification( - modifyMultisigAccountTransactionDTO.transaction.modifications[0].type, + modifyMultisigAccountTransactionDTO.transaction.modifications[0].modificiationType, PublicAccount.createFromPublicKey(modifyMultisigAccountTransactionDTO.transaction.modifications[0].cosignatoryPublicKey, NetworkType.MIJIN_TEST), ), 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/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]); } diff --git a/src/core/utils/DtoMapping.ts b/src/core/utils/DtoMapping.ts index 9a0e2b77d1..7670b1815e 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,20 @@ 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.AllowIncomingAddress: + case AccountRestrictionType.BlockIncomingAddress: + case AccountRestrictionType.AllowOutgoingAddress: + case AccountRestrictionType.BlockOutgoingAddress: 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.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/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/Listener.ts b/src/infrastructure/Listener.ts index a4055e4329..fb631222f5 100644 --- a/src/infrastructure/Listener.ts +++ b/src/infrastructure/Listener.ts @@ -409,7 +409,7 @@ export class Listener { private accountAddedToMultiSig(transaction: Transaction, address: Address): boolean { if (transaction instanceof ModifyMultisigAccountTransaction) { transaction.modifications.map((_: MultisigCosignatoryModification) => { - if (_.type === MultisigCosignatoryModificationType.Add && _.cosignatoryPublicAccount.address.equals(address)) { + if (_.modificiationType === MultisigCosignatoryModificationType.Add && _.cosignatoryPublicAccount.address.equals(address)) { return true; } }); diff --git a/src/infrastructure/MosaicHttp.ts b/src/infrastructure/MosaicHttp.ts index 104aee210b..b86fd4b730 100644 --- a/src/infrastructure/MosaicHttp.ts +++ b/src/infrastructure/MosaicHttp.ts @@ -75,7 +75,7 @@ export class MosaicHttp extends Http implements MosaicRepository { divisibility = mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Divisibility].value; } if (mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Duration].value) { - duration = mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Divisibility].value; + duration = mosaicInfoDTO.mosaic.properties[MosaicPropertyType.Duration].value; } return new MosaicInfo( mosaicInfoDTO.meta.id, 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/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 452e4c30b7..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.MODIFY_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 edfed292ba..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.MODIFY_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 ec97bcc02e..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.MODIFY_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/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/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/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/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/CosignatureBuilder.ts b/src/infrastructure/catbuffer/CosignatureBuilder.ts new file mode 100644 index 0000000000..447524c2f6 --- /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'; + +/** Cosignature attached to an aggregate transaction. */ +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; + } + + /** + * Creates an instance of CosignatureBuilder from binary payload. + * + * @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); + 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); + } + + /** + * Gets cosigner public key. + * + * @return Cosigner public key. + */ + public getSigner(): KeyDto { + return this.signer; + } + + /** + * Gets cosigner signature. + * + * @return Cosigner signature. + */ + public getSignature(): SignatureDto { + return this.signature; + } + + /** + * Gets 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; + } + + /** + * 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); + return newArray; + } +} diff --git a/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts b/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts new file mode 100644 index 0000000000..f10107ee30 --- /dev/null +++ b/src/infrastructure/catbuffer/DetachedCosignatureBuilder.ts @@ -0,0 +1,93 @@ +// tslint:disable: jsdoc-format +/** +*** Copyright (c) 2016-present, +*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved. +*** +*** This file is part of Catapult. +*** +*** Catapult is free software: you can redistribute it and/or modify +*** it under the terms of the GNU Lesser General Public License as published by +*** the Free Software Foundation, either version 3 of the License, or +*** (at your option) any later version. +*** +*** Catapult is distributed in the hope that it will be useful, +*** but WITHOUT ANY WARRANTY; without even the implied warranty of +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +*** GNU Lesser General Public License for more details. +*** +*** You should have received a copy of the GNU Lesser General Public License +*** 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'; + +/** Cosignature detached from an aggregate transaction. */ +export class DetachedCosignatureBuilder extends CosignatureBuilder { + /** 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 aggregate transaction that is signed by this cosignature. + */ + public constructor(signer: KeyDto, signature: SignatureDto, parentHash: Hash256Dto) { + super(signer, signature); + this.parentHash = parentHash; + } + + /** + * Creates an instance of DetachedCosignatureBuilder from binary payload. + * + * @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 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(superObject.signer, superObject.signature, parentHash); + } + + /** + * Gets hash of the aggregate transaction that is signed by this cosignature. + * + * @return Hash of the aggregate transaction that is signed by this cosignature. + */ + public getParentHash(): Hash256Dto { + return this.parentHash; + } + + /** + * Gets the size of the object. + * + * @return Size in bytes. + */ + public getSize(): number { + let size: number = super.getSize(); + size += this.parentHash.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 parentHashBytes = this.parentHash.serialize(); + newArray = GeneratorUtils.concatTypedArrays(newArray, parentHashBytes); + 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..921a115ce9 --- /dev/null +++ b/src/infrastructure/catbuffer/EntityTypeDto.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 . +**/ + + +/** Enumeration of entity types. */ +export enum EntityTypeDto { + /** Reserved entity type. */ + RESERVED = 0, + /** + * Account address restriction transaction. + */ + ACCOUNT_ADDRESS_RESTRICTION_TRANSACTION = 0x4150, + /** + * Account mosaic restriction transaction. + */ + ACCOUNT_MOSAIC_RESTRICTION_TRANSACTION = 0x4250, + /** + * Account operation restriction transaction. + */ + ACCOUNT_OPERATION_RESTRICTION_TRANSACTION = 0x4350, + /** + * Account link transaction. + */ + ACCOUNT_LINK_TRANSACTION = 0x414C, + /** + * Address alias transaction. + */ + ADDRESS_ALIAS_TRANSACTION = 0x424E, + /** + * Aggregate bonded transaction. + */ + AGGREGATE_BONDED_TRANSACTION = 0x4241, + /** + * Aggregate complete transaction. + */ + AGGREGATE_COMPLETE_TRANSACTION = 0x4141, + /** + * Hash lock transaction. + */ + HASH_LOCK_TRANSACTION = 0x4148, + /** + * Modify multisig account transaction. + */ + MODIFY_MULTISIG_ACCOUNT_TRANSACTION = 0x4155, + /** + * Mosaic definition transaction. + */ + MOSAIC_DEFINITION_TRANSACTION = 0x414D, + /** + * Mosaic supply change transaction. + */ + MOSAIC_SUPPLY_CHANGE_TRANSACTION = 0x424D, + /** + * Mosaic alias transaction. + */ + MOSAIC_ALIAS_TRANSACTION = 0x434E, + /** + * Register namespace transaction. + */ + REGISTER_NAMESPACE_TRANSACTION = 0x414E, + /** + * Secret lock transaction. + */ + SECRET_LOCK_TRANSACTION = 0x4152, + /** + * Secret Proof transaction. + */ + SECRET_PROOF_TRANSACTION = 0x4252, + /** + * Transfer transaction. + */ + TRANSFER_TRANSACTION = 0x4154, +} diff --git a/src/infrastructure/catbuffer/GeneratorUtils.ts b/src/infrastructure/catbuffer/GeneratorUtils.ts new file mode 100644 index 0000000000..f1f8ecb3d3 --- /dev/null +++ b/src/infrastructure/catbuffer/GeneratorUtils.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 . + **/ + +/** + * Generator utility class. + */ +export class GeneratorUtils { + + /** + * 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. + */ + public static bufferToUint64(input: Uint8Array): number[] { + if (8 !== input.length) { + throw Error(`byte array has unexpected size '${input.length}'`); + } + input = input.reverse(); + const view = new DataView(input.buffer); + return [view.getUint32(4), view.getUint32(0)]; + } + + /** + * 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. + */ + public static readUint32At(bytes: Uint8Array, index: number): number { + return (bytes[index] + (bytes[index + 1] << 8) + (bytes[index + 2] << 16) + (bytes[index + 3] << 24)) >>> 0; + } + + /** + * Convert uint value into 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); + 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}`); + } + } + + /** + * 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); + 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}`); + } + } + + /** + * Convert unit64 into 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/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/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index 65abcd1df5..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'; @@ -195,7 +195,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr transactionDTO.minApprovalDelta, transactionDTO.minRemovalDelta, transactionDTO.modifications ? transactionDTO.modifications.map((modificationDTO) => new MultisigCosignatoryModification( - modificationDTO.type, + modificationDTO.modificiationType, PublicAccount.createFromPublicKey(modificationDTO.cosignatoryPublicKey, extractNetworkType(transactionDTO.version)), )) : [], transactionDTO.signature, @@ -258,7 +258,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), new UInt64(transactionDTO.maxFee || [0, 0]), - transactionDTO.action, + transactionDTO.aliasAction, new NamespaceId(transactionDTO.namespaceId), new MosaicId(transactionDTO.mosaicId), transactionDTO.signature, @@ -272,7 +272,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr extractTransactionVersion(transactionDTO.version), Deadline.createFromDTO(transactionDTO.deadline), new UInt64(transactionDTO.maxFee || [0, 0]), - transactionDTO.action, + transactionDTO.aliasAction, new NamespaceId(transactionDTO.namespaceId), extractRecipient(transactionDTO.address) as Address, transactionDTO.signature, @@ -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), @@ -335,7 +335,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr Deadline.createFromDTO(transactionDTO.deadline), new UInt64(transactionDTO.maxFee || [0, 0]), transactionDTO.remoteAccountKey, - transactionDTO.action, + transactionDTO.linkAction, transactionDTO.signature, transactionDTO.signer ? PublicAccount.createFromPublicKey(transactionDTO.signer, extractNetworkType(transactionDTO.version)) : undefined, diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index afe17f162a..3f79ea2d5e 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -14,530 +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 { AccountAddressRestrictionModificationTransaction } from '../../model/transaction/AccountAddressRestrictionModificationTransaction'; +import { InnerTransaction } from '../../model/model'; +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 { AccountRestrictionModification } from '../../model/transaction/AccountRestrictionModification'; +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 { 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.MODIFY_ACCOUNT_RESTRICTION_ADDRESS: - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION: - case TransactionType.MODIFY_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); - + case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: + case TransactionType.ACCOUNT_RESTRICTION_OPERATION: + case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: switch (type) { - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS: - const t = AccountAddressRestrictionModificationTransaction.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; - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC: - return AccountMosaicRestrictionModificationTransaction.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, - ); - case TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION: - return AccountOperationRestrictionModificationTransaction.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, - ); + case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: + return AccountAddressRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); + case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: + return AccountMosaicRestrictionTransaction.createFromPayload(payload, isEmbedded, signSchema); + case TransactionType.ACCOUNT_RESTRICTION_OPERATION: + 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 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 divisibilityOffset = flagsOffset + mosaicDefPropsFlagsLength; - const durationIndOffset = divisibilityOffset + mosaicDefDivisibilityLength; - const durationOffset = durationIndOffset + mosaicDefDurationIndLength; - - // read bytes - const mosaicNonce = transactionData.substring(0, mosaicDefMosaicNonceLength); - const mosaicId = transactionData.substring(mosaicIdOffset, propsOffset); - const props = transactionData.substring(propsOffset, 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 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/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index a9c5c838e0..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'; @@ -45,11 +45,11 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { case TransactionType.LINK_ACCOUNT: return { remoteAccountKey: (transaction as AccountLinkTransaction).remoteAccountKey, - action: (transaction as AccountLinkTransaction).linkAction, + linkAction: (transaction as AccountLinkTransaction).linkAction, }; case TransactionType.ADDRESS_ALIAS: return { - action: (transaction as AddressAliasTransaction).actionType, + aliasAction: (transaction as AddressAliasTransaction).aliasAction, namespaceId: (transaction as AddressAliasTransaction).namespaceId.toDTO(), address: (transaction as AddressAliasTransaction).address.toDTO(), }; @@ -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(); }), }; @@ -103,7 +103,7 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { }; case TransactionType.MOSAIC_ALIAS: return { - action: (transaction as MosaicAliasTransaction).actionType, + aliasAction: (transaction as MosaicAliasTransaction).aliasAction, namespaceId: (transaction as MosaicAliasTransaction).namespaceId.toDTO(), mosaicId: (transaction as MosaicAliasTransaction).mosaicId.toDTO(), }; 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/AccountRestrictionType.ts b/src/model/account/AccountRestrictionType.ts new file mode 100644 index 0000000000..757c1fde75 --- /dev/null +++ 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, +} 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/account/RestrictionType.ts b/src/model/account/RestrictionType.ts deleted file mode 100644 index aa7d236ed0..0000000000 --- a/src/model/account/RestrictionType.ts +++ /dev/null @@ -1,34 +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 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. - */ - -export enum RestrictionType { - AllowAddress = 0x01, - AllowMosaic = 0x02, - AllowTransaction = 0x04, - Sentinel = 0x05, - BlockAddress = (0x80 + 0x01), - BlockMosaic = (0x80 + 0x02), - BlockTransaction = (0x80 + 0x04), -} diff --git a/src/model/model.ts b/src/model/model.ts index 62bb27f331..f9ecae784e 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 @@ -67,7 +67,7 @@ export * from './namespace/NamespaceId'; export * from './namespace/NamespaceInfo'; export * from './namespace/NamespaceName'; export * from './namespace/NamespaceType'; -export * from './namespace/AliasActionType'; +export * from './namespace/AliasAction'; // Node export * from './node/NodeInfo'; @@ -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/infrastructure/builders/CosignatureTransaction.ts b/src/model/mosaic/MosaicFlag.ts similarity index 55% rename from src/infrastructure/builders/CosignatureTransaction.ts rename to src/model/mosaic/MosaicFlag.ts index 717041f910..dcf6a8b500 100644 --- a/src/infrastructure/builders/CosignatureTransaction.ts +++ b/src/model/mosaic/MosaicFlag.ts @@ -1,5 +1,5 @@ /* - * Copyright 2019 NEM + * 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. @@ -13,15 +13,13 @@ * 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); - } +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/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/AliasAction.ts similarity index 91% rename from src/model/namespace/AliasActionType.ts rename to src/model/namespace/AliasAction.ts index e44895f689..7d81578751 100644 --- a/src/model/namespace/AliasActionType.ts +++ b/src/model/namespace/AliasAction.ts @@ -19,7 +19,7 @@ * 0: Link an alias. * 1: Unlink an alias. */ -export enum AliasActionType { - Link = 0, - Unlink = 1, +export enum AliasAction { + Link = 0x01, + Unlink = 0x00, } diff --git a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts b/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts deleted file mode 100644 index 3a9d99f813..0000000000 --- a/src/model/transaction/AccountAddressRestrictionModificationTransaction.ts +++ /dev/null @@ -1,113 +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 { Builder } from '../../infrastructure/builders/AccountRestrictionsAddressTransaction'; -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 { Transaction } from './Transaction'; -import { TransactionInfo } from './TransactionInfo'; -import { TransactionType } from './TransactionType'; -import { TransactionVersion } from './TransactionVersion'; - -export class AccountAddressRestrictionModificationTransaction extends Transaction { - - /** - * Create a modify account address restriction transaction object - * @param deadline - The deadline to include the transaction. - * @param restrictionType - The account restriction type. - * @param modifications - The array of modifications. - * @param networkType - The network type. - * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountAddressRestrictionModificationTransaction} - */ - 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, - deadline, - maxFee, - restrictionType, - modifications); - } - - /** - * @param networkType - * @param version - * @param deadline - * @param maxFee - * @param restrictionType - * @param modifications - * @param signature - * @param signer - * @param transactionInfo - */ - constructor(networkType: NetworkType, - version: number, - deadline: Deadline, - maxFee: UInt64, - public readonly restrictionType: RestrictionType, - public readonly modifications: Array>, - signature?: string, - signer?: PublicAccount, - transactionInfo?: TransactionInfo) { - super(TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS, - networkType, version, deadline, maxFee, signature, signer, transactionInfo); - } - - /** - * @override Transaction.size() - * @description get the byte size of a AccountAddressRestrictionModificationTransaction - * @returns {number} - * @memberof AccountAddressRestrictionModificationTransaction - */ - public get size(): number { - const byteSize = super.size; - - // set static byte size fields - const byteRestrictionType = 1; - const byteModificationCount = 1; - - // each modification contains : - // - 1 byte for modificationType - // - 25 bytes for the modification value (address) - const byteModifications = 26 * this.modifications.length; - - 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(); - } - -} diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts new file mode 100644 index 0000000000..48299057bb --- /dev/null +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -0,0 +1,184 @@ +/* + * 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, 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 { 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 { 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'; + +export class AccountAddressRestrictionTransaction extends Transaction { + + /** + * Create a modify account address restriction transaction object + * @param deadline - The deadline to include the transaction. + * @param restrictionType - The account restriction type. + * @param modifications - The array of modifications. + * @param networkType - The network type. + * @param maxFee - (Optional) Max fee defined by the sender + * @returns {AccountAddressRestrictionTransaction} + */ + public static create(deadline: Deadline, + restrictionType: AccountRestrictionType, + modifications: Array>, + networkType: NetworkType, + maxFee: UInt64 = new UInt64([0, 0])): AccountAddressRestrictionTransaction { + return new AccountAddressRestrictionTransaction(networkType, + TransactionVersion.ACCOUNT_RESTRICTION_ADDRESS, + deadline, + maxFee, + restrictionType, + modifications); + } + + /** + * @param networkType + * @param version + * @param deadline + * @param maxFee + * @param restrictionType + * @param modifications + * @param signature + * @param signer + * @param transactionInfo + */ + constructor(networkType: NetworkType, + version: number, + deadline: Deadline, + maxFee: UInt64, + public readonly restrictionType: AccountRestrictionType, + public readonly modifications: Array>, + signature?: string, + signer?: PublicAccount, + transactionInfo?: TransactionInfo) { + super(TransactionType.ACCOUNT_RESTRICTION_ADDRESS, + 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 + * @returns {number} + * @memberof AccountAddressRestrictionTransaction + */ + public get size(): number { + const byteSize = super.size; + + // set static byte size fields + const byteRestrictionType = 1; + const byteModificationCount = 1; + + // each modification contains : + // - 1 byte for modificationType + // - 25 bytes for the modification value (address) + const byteModifications = 26 * this.modifications.length; + + return byteSize + byteRestrictionType + byteModificationCount + byteModifications; + } + + /** + * @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(); + } + + /** + * @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/AccountLinkTransaction.ts b/src/model/transaction/AccountLinkTransaction.ts index 78915b03a3..f1cb351b7a 100644 --- a/src/model/transaction/AccountLinkTransaction.ts +++ b/src/model/transaction/AccountLinkTransaction.ts @@ -14,12 +14,20 @@ * limitations under the License. */ -import { Builder } from '../../infrastructure/builders/AccountLinkTransaction'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; +import { SignSchema } from '../../core/crypto/SignSchema'; +import { Convert } from '../../core/format'; +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'; +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 { LinkAction } from './LinkAction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; @@ -81,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 @@ -99,16 +131,37 @@ export class AccountLinkTransaction extends Transaction { /** * @internal - * @returns {VerifiableTransaction} + * @returns {Uint8Array} */ - protected buildTransaction(): VerifiableTransaction { - return new Builder() - .addDeadline(this.deadline.toDTO()) - .addFee(this.maxFee.toDTO()) - .addVersion(this.versionToDTO()) - .addRemoteAccountKey(this.remoteAccountKey) - .addLinkAction(this.linkAction) - .build(); + 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(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const transactionBuilder = new EmbeddedAccountLinkTransactionBuilder( + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), + this.versionToDTO(), + TransactionType.LINK_ACCOUNT.valueOf(), + new KeyDto(Convert.hexToUint8(this.remoteAccountKey)), + this.linkAction.valueOf(), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts b/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts deleted file mode 100644 index 3a32656795..0000000000 --- a/src/model/transaction/AccountMosaicRestrictionModificationTransaction.ts +++ /dev/null @@ -1,113 +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 { Builder } from '../../infrastructure/builders/AccountRestrictionsMosaicTransaction'; -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 { Transaction } from './Transaction'; -import { TransactionInfo } from './TransactionInfo'; -import { TransactionType } from './TransactionType'; -import { TransactionVersion } from './TransactionVersion'; - -export class AccountMosaicRestrictionModificationTransaction extends Transaction { - - /** - * Create a modify account mosaic restriction transaction object - * @param deadline - The deadline to include the transaction. - * @param restrictionType - The account restriction type. - * @param modifications - The array of modifications. - * @param networkType - The network type. - * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountAddressRestrictionModificationTransaction} - */ - 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, - deadline, - maxFee, - restrictionType, - modifications); - } - - /** - * @param networkType - * @param version - * @param deadline - * @param maxFee - * @param restrictionType - * @param modifications - * @param signature - * @param signer - * @param transactionInfo - */ - constructor(networkType: NetworkType, - version: number, - deadline: Deadline, - maxFee: UInt64, - public readonly restrictionType: RestrictionType, - public readonly modifications: Array>, - signature?: string, - signer?: PublicAccount, - transactionInfo?: TransactionInfo) { - super(TransactionType.MODIFY_ACCOUNT_RESTRICTION_MOSAIC, - networkType, version, deadline, maxFee, signature, signer, transactionInfo); - } - - /** - * @override Transaction.size() - * @description get the byte size of a AccountMosaicRestrictionModificationTransaction - * @returns {number} - * @memberof AccountMosaicRestrictionModificationTransaction - */ - public get size(): number { - const byteSize = super.size; - - // set static byte size fields - const byteRestrictionType = 1; - const byteModificationCount = 1; - - // each modification contains : - // - 1 byte for modificationType - // - 8 bytes for the modification value (mosaicId) - const byteModifications = 9 * this.modifications.length; - - 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(); - } - -} diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts new file mode 100644 index 0000000000..97343c5460 --- /dev/null +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -0,0 +1,184 @@ +/* + * 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 { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder'; +import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder'; +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; +import { EmbeddedAccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder'; +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 { 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'; +import { TransactionVersion } from './TransactionVersion'; + +export class AccountMosaicRestrictionTransaction extends Transaction { + + /** + * Create a modify account mosaic restriction transaction object + * @param deadline - The deadline to include the transaction. + * @param restrictionType - The account restriction type. + * @param modifications - The array of modifications. + * @param networkType - The network type. + * @param maxFee - (Optional) Max fee defined by the sender + * @returns {AccountAddressRestrictionTransaction} + */ + public static create(deadline: Deadline, + restrictionType: AccountRestrictionType, + modifications: Array>, + networkType: NetworkType, + maxFee: UInt64 = new UInt64([0, 0])): AccountMosaicRestrictionTransaction { + return new AccountMosaicRestrictionTransaction(networkType, + TransactionVersion.ACCOUNT_RESTRICTION_MOSAIC, + deadline, + maxFee, + restrictionType, + modifications); + } + + /** + * @param networkType + * @param version + * @param deadline + * @param maxFee + * @param restrictionType + * @param modifications + * @param signature + * @param signer + * @param transactionInfo + */ + constructor(networkType: NetworkType, + version: number, + deadline: Deadline, + maxFee: UInt64, + public readonly restrictionType: AccountRestrictionType, + public readonly modifications: Array>, + signature?: string, + signer?: PublicAccount, + transactionInfo?: TransactionInfo) { + super(TransactionType.ACCOUNT_RESTRICTION_MOSAIC, + 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 + * @returns {number} + * @memberof AccountMosaicRestrictionTransaction + */ + public get size(): number { + const byteSize = super.size; + + // set static byte size fields + const byteRestrictionType = 1; + const byteModificationCount = 1; + + // each modification contains : + // - 1 byte for modificationType + // - 8 bytes for the modification value (mosaicId) + const byteModifications = 9 * this.modifications.length; + + return byteSize + byteRestrictionType + byteModificationCount + byteModifications; + } + + /** + * @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(); + } + + /** + * @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/AccountOperationRestrictionModificationTransaction.ts b/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts deleted file mode 100644 index 38160cc79d..0000000000 --- a/src/model/transaction/AccountOperationRestrictionModificationTransaction.ts +++ /dev/null @@ -1,113 +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 { 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 { Transaction } from './Transaction'; -import { TransactionInfo } from './TransactionInfo'; -import { TransactionType } from './TransactionType'; -import { TransactionVersion } from './TransactionVersion'; - -export class AccountOperationRestrictionModificationTransaction extends Transaction { - - /** - * Create a modify account operation restriction type transaction object - * @param deadline - The deadline to include the transaction. - * @param restrictionType - The account restriction type. - * @param modifications - The array of modifications. - * @param networkType - The network type. - * @param maxFee - (Optional) Max fee defined by the sender - * @returns {AccountOperationRestrictionModificationTransaction} - */ - public static create(deadline: Deadline, - restrictionType: RestrictionType, - modifications: Array>, - networkType: NetworkType, - maxFee: UInt64 = new UInt64([0, 0])): AccountOperationRestrictionModificationTransaction { - return new AccountOperationRestrictionModificationTransaction(networkType, - TransactionVersion.MODIFY_ACCOUNT_RESTRICTION_ENTITY_TYPE, - deadline, - maxFee, - restrictionType, - modifications); - } - - /** - * @param networkType - * @param version - * @param deadline - * @param maxFee - * @param restrictionType - * @param modifications - * @param signature - * @param signer - * @param transactionInfo - */ - constructor(networkType: NetworkType, - version: number, - deadline: Deadline, - maxFee: UInt64, - public readonly restrictionType: RestrictionType, - public readonly modifications: Array>, - signature?: string, - signer?: PublicAccount, - transactionInfo?: TransactionInfo) { - super(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION, - networkType, version, deadline, maxFee, signature, signer, transactionInfo); - } - - /** - * @override Transaction.size() - * @description get the byte size of a AccountOperationRestrictionModificationTransaction - * @returns {number} - * @memberof AccountOperationRestrictionModificationTransaction - */ - public get size(): number { - const byteSize = super.size; - - // set static byte size fields - const byteRestrictionType = 1; - const byteModificationCount = 1; - - // each modification contains : - // - 1 byte for modificationType - // - 2 bytes for the modification value (transaction type) - const byteModifications = 3 * this.modifications.length; - - 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(); - } - -} diff --git a/src/model/transaction/AccountOperationRestrictionTransaction.ts b/src/model/transaction/AccountOperationRestrictionTransaction.ts new file mode 100644 index 0000000000..f60abe0115 --- /dev/null +++ b/src/model/transaction/AccountOperationRestrictionTransaction.ts @@ -0,0 +1,182 @@ +/* + * 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 { 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'; +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'; + +export class AccountOperationRestrictionTransaction extends Transaction { + + /** + * Create a modify account operation restriction type transaction object + * @param deadline - The deadline to include the transaction. + * @param restrictionType - The account restriction type. + * @param modifications - The array of modifications. + * @param networkType - The network type. + * @param maxFee - (Optional) Max fee defined by the sender + * @returns {AccountOperationRestrictionTransaction} + */ + public static create(deadline: Deadline, + restrictionType: AccountRestrictionType, + modifications: Array>, + networkType: NetworkType, + maxFee: UInt64 = new UInt64([0, 0])): AccountOperationRestrictionTransaction { + return new AccountOperationRestrictionTransaction(networkType, + TransactionVersion.MODIFY_ACCOUNT_RESTRICTION_ENTITY_TYPE, + deadline, + maxFee, + restrictionType, + modifications); + } + + /** + * @param networkType + * @param version + * @param deadline + * @param maxFee + * @param restrictionType + * @param modifications + * @param signature + * @param signer + * @param transactionInfo + */ + constructor(networkType: NetworkType, + version: number, + deadline: Deadline, + maxFee: UInt64, + public readonly restrictionType: AccountRestrictionType, + public readonly modifications: Array>, + signature?: string, + signer?: PublicAccount, + transactionInfo?: TransactionInfo) { + super(TransactionType.ACCOUNT_RESTRICTION_OPERATION, + 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 + * @returns {number} + * @memberof AccountOperationRestrictionTransaction + */ + public get size(): number { + const byteSize = super.size; + + // set static byte size fields + const byteRestrictionType = 1; + const byteModificationCount = 1; + + // each modification contains : + // - 1 byte for modificationType + // - 2 bytes for the modification value (transaction type) + const byteModifications = 3 * this.modifications.length; + + return byteSize + byteRestrictionType + byteModificationCount + byteModifications; + } + + /** + * @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(); + } + + /** + * @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/AccountRestrictionTransaction.ts b/src/model/transaction/AccountRestrictionTransaction.ts index 7e0f26c313..4c294e4bc9 100644 --- a/src/model/transaction/AccountRestrictionTransaction.ts +++ b/src/model/transaction/AccountRestrictionTransaction.ts @@ -14,12 +14,12 @@ * 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'; -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,19 +32,22 @@ 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, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), - ): AccountAddressRestrictionModificationTransaction { - if (![RestrictionType.AllowAddress, RestrictionType.BlockAddress].includes(restrictionType)) { + ): AccountAddressRestrictionTransaction { + if (![AccountRestrictionType.AllowIncomingAddress, + AccountRestrictionType.AllowOutgoingAddress, + AccountRestrictionType.BlockOutgoingAddress, + AccountRestrictionType.BlockIncomingAddress].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } - return AccountAddressRestrictionModificationTransaction.create( + return AccountAddressRestrictionTransaction.create( deadline, restrictionType, modifications, @@ -60,19 +63,19 @@ 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, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), - ): AccountMosaicRestrictionModificationTransaction { - if (![RestrictionType.AllowMosaic, RestrictionType.BlockMosaic].includes(restrictionType)) { + ): AccountMosaicRestrictionTransaction { + if (![AccountRestrictionType.AllowMosaic,AccountRestrictionType.BlockMosaic].includes(restrictionType)) { throw new Error ('Restriction type is not allowed.'); } - return AccountMosaicRestrictionModificationTransaction.create( + return AccountMosaicRestrictionTransaction.create( deadline, restrictionType, modifications, @@ -88,19 +91,22 @@ 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, - restrictionType: RestrictionType, + restrictionType: AccountRestrictionType, modifications: Array>, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), - ): AccountOperationRestrictionModificationTransaction { - if (![RestrictionType.AllowTransaction, RestrictionType.BlockTransaction].includes(restrictionType)) { + ): AccountOperationRestrictionTransaction { + if (![AccountRestrictionType.AllowIncomingTransactionType, + AccountRestrictionType.AllowOutgoingTransactionType, + AccountRestrictionType.BlockOutgoingTransactionType, + 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 a0ac7d269f..3975b926dc 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -14,15 +14,24 @@ * limitations under the License. */ -import { Builder } from '../../infrastructure/builders/AddressAliasTransaction'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; +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 { 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'; -import { AliasActionType } from '../namespace/AliasActionType'; +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'; @@ -37,7 +46,7 @@ export class AddressAliasTransaction extends Transaction { /** * Create a address alias transaction object * @param deadline - The deadline to include the transaction. - * @param actionType - The alias action type. + * @param aliasAction - The alias action type. * @param namespaceId - The namespace id. * @param address - The address. * @param networkType - The network type. @@ -45,7 +54,7 @@ export class AddressAliasTransaction extends Transaction { * @returns {AddressAliasTransaction} */ public static create(deadline: Deadline, - actionType: AliasActionType, + aliasAction: AliasAction, namespaceId: NamespaceId, address: Address, networkType: NetworkType, @@ -54,7 +63,7 @@ export class AddressAliasTransaction extends Transaction { TransactionVersion.ADDRESS_ALIAS, deadline, maxFee, - actionType, + aliasAction, namespaceId, address, ); @@ -65,7 +74,7 @@ export class AddressAliasTransaction extends Transaction { * @param version * @param deadline * @param maxFee - * @param actionType + * @param aliasAction * @param namespaceId * @param address * @param signature @@ -79,7 +88,7 @@ export class AddressAliasTransaction extends Transaction { /** * The alias action type. */ - public readonly actionType: AliasActionType, + public readonly aliasAction: AliasAction, /** * The namespace id that will be an alias. */ @@ -94,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 @@ -113,17 +148,39 @@ export class AddressAliasTransaction extends Transaction { /** * @internal - * @returns {VerifiableTransaction} + * @returns {Uint8Array} */ - 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(); + 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.aliasAction.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new AddressDto(RawAddress.stringToAddress(this.address.plain())), + ); + 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.aliasAction.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..0f473c5667 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -14,15 +14,24 @@ * limitations under the License. */ -import { SignSchema } from '../../core/crypto'; -import { Builder } from '../../infrastructure/builders/AggregateTransaction'; -import { AggregateTransaction as AggregatedTransactionCore} from '../../infrastructure/builders/AggregateTransaction'; +import { KeyPair, SignSchema } from '../../core/crypto'; +import { Convert } from '../../core/format'; +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'; +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'; 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'; @@ -116,20 +125,76 @@ export class AggregateTransaction extends Transaction { } /** - * @internal + * @description add inner transactions to current list + * @param {InnerTransaction[]} transaction * @returns {AggregateTransaction} + * @memberof 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(); + 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 + * @param {SignSchema} signSchema The Sign Schema. (KECCAK_REVERSED_KEY / SHA3) + * @returns {AggregateTransaction} + */ + public static createFromPayload(payload: string, signSchema: SignSchema = SignSchema.SHA3): AggregateTransaction { + /** + * 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()); + + /** + * 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 @@ -142,11 +207,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); } @@ -163,13 +240,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); } @@ -203,4 +288,61 @@ export class AggregateTransaction extends Transaction { return byteSize + byteTransactionsSize + byteTransactions; } -} \ No newline at end of file + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateBytes(): Uint8Array { + 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); + }); + + let 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(); + cosignatures = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); + }); + + 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(); + } + + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + throw new Error('Method not implemented'); + } +} diff --git a/src/model/transaction/AliasTransaction.ts b/src/model/transaction/AliasTransaction.ts index 2333bd04be..4b023a0575 100644 --- a/src/model/transaction/AliasTransaction.ts +++ b/src/model/transaction/AliasTransaction.ts @@ -17,7 +17,7 @@ import { Address } from '../account/Address'; import { NetworkType } from '../blockchain/NetworkType'; import { MosaicId } from '../mosaic/MosaicId'; -import { AliasActionType } from '../namespace/AliasActionType'; +import { AliasAction } from '../namespace/AliasAction'; import { NamespaceId } from '../namespace/NamespaceId'; import { UInt64 } from '../UInt64'; import { AddressAliasTransaction } from './AddressAliasTransaction'; @@ -38,7 +38,7 @@ export abstract class AliasTransaction extends Transaction { * @returns {AddressAliasTransaction} */ public static createForAddress(deadline: Deadline, - aliasAction: AliasActionType, + aliasAction: AliasAction, namespaceId: NamespaceId, address: Address, networkType: NetworkType, @@ -64,7 +64,7 @@ export abstract class AliasTransaction extends Transaction { * @returns {MosaicAliasTransaction} */ public static createForMosaic(deadline: Deadline, - aliasAction: AliasActionType, + aliasAction: AliasAction, namespaceId: NamespaceId, mosaicId: MosaicId, networkType: NetworkType, 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/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/LockFundsTransaction.ts b/src/model/transaction/LockFundsTransaction.ts index 4036654043..96088b7ec0 100644 --- a/src/model/transaction/LockFundsTransaction.ts +++ b/src/model/transaction/LockFundsTransaction.ts @@ -14,13 +14,25 @@ * limitations under the License. */ -import { Builder } from '../../infrastructure/builders/HashLockTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { SignSchema } from '../../core/crypto/SignSchema'; +import { Convert } from '../../core/format'; +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'; +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'; @@ -102,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 @@ -122,19 +163,41 @@ export class LockFundsTransaction extends Transaction { /** * @internal - * @return {VerifiableTransaction} + * @returns {Uint8Array} */ - 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(); + protected generateBytes(): Uint8Array { + 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 transactionBuilder = new EmbeddedHashLockTransactionBuilder( + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), + 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 e8afe30251..23dce96d81 100644 --- a/src/model/transaction/ModifyMultisigAccountTransaction.ts +++ b/src/model/transaction/ModifyMultisigAccountTransaction.ts @@ -14,12 +14,20 @@ * limitations under the License. */ -import { Builder } from '../../infrastructure/builders/MultisigModificationTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { SignSchema } from '../../core/crypto/SignSchema'; +import { Convert } from '../../core/format'; +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'; +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 { MultisigCosignatoryModification } from './MultisigCosignatoryModification'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; @@ -95,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 @@ -112,24 +154,56 @@ 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; } /** * @internal - * @returns {VerifiableTransaction} + * @returns {Uint8Array} */ - 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(); + 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.modificiationType.valueOf(), + new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)), + ); + }), + ); + 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.modificiationType.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..3f1877838a 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -14,14 +14,23 @@ * limitations under the License. */ -import { Builder } from '../../infrastructure/builders/MosaicAddressRestrictionTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { SignSchema } from '../../core/crypto/SignSchema'; +import { Convert, RawAddress } from '../../core/format'; +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'; 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'; @@ -112,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 @@ -135,19 +172,43 @@ export class MosaicAddressRestrictionTransaction extends Transaction { /** * @internal - * @returns {VerifiableTransaction} + * @returns {Uint8Array} */ - 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(); + protected generateBytes(): Uint8Array { + 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 transactionBuilder = new EmbeddedMosaicAddressRestrictionTransactionBuilder( + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), + 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 8cc1d1914a..6d7cae3183 100644 --- a/src/model/transaction/MosaicAliasTransaction.ts +++ b/src/model/transaction/MosaicAliasTransaction.ts @@ -14,15 +14,25 @@ * limitations under the License. */ -import { Builder } from '../../infrastructure/builders/MosaicAliasTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { SignSchema } from '../../core/crypto/SignSchema'; +import { Convert } from '../../core/format'; +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'; +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'; -import { AliasActionType } from '../namespace/AliasActionType'; +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'; @@ -33,7 +43,7 @@ export class MosaicAliasTransaction extends Transaction { /** * Create a mosaic alias transaction object * @param deadline - The deadline to include the transaction. - * @param actionType - The alias action type. + * @param aliasAction - The alias action type. * @param namespaceId - The namespace id. * @param mosaicId - The mosaic id. * @param networkType - The network type. @@ -41,7 +51,7 @@ export class MosaicAliasTransaction extends Transaction { * @returns {MosaicAliasTransaction} */ public static create(deadline: Deadline, - actionType: AliasActionType, + aliasAction: AliasAction, namespaceId: NamespaceId, mosaicId: MosaicId, networkType: NetworkType, @@ -50,7 +60,7 @@ export class MosaicAliasTransaction extends Transaction { TransactionVersion.MOSAIC_ALIAS, deadline, maxFee, - actionType, + aliasAction, namespaceId, mosaicId, ); @@ -61,7 +71,7 @@ export class MosaicAliasTransaction extends Transaction { * @param version * @param deadline * @param maxFee - * @param actionType + * @param aliasAction * @param namespaceId * @param mosaicId * @param signature @@ -75,7 +85,7 @@ export class MosaicAliasTransaction extends Transaction { /** * The alias action type. */ - public readonly actionType: AliasActionType, + public readonly aliasAction: AliasAction, /** * The namespace id that will be an alias. */ @@ -90,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 @@ -109,17 +144,39 @@ export class MosaicAliasTransaction extends Transaction { /** * @internal - * @returns {VerifiableTransaction} + * @returns {Uint8Array} */ - 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(); + 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.aliasAction.valueOf(), + new NamespaceIdDto(this.namespaceId.id.toDTO()), + new MosaicIdDto(this.mosaicId.id.toDTO()), + ); + 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.aliasAction.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..1616044875 100644 --- a/src/model/transaction/MosaicDefinitionTransaction.ts +++ b/src/model/transaction/MosaicDefinitionTransaction.ts @@ -14,15 +14,27 @@ * limitations under the License. */ -import { Builder } from '../../infrastructure/builders/MosaicCreationTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { SignSchema } from '../../core/crypto/SignSchema'; +import { Convert } from '../../core/format'; +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'; import { UInt64 } from '../UInt64'; import { Deadline } from './Deadline'; +import { InnerTransaction } from './InnerTransaction'; import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; @@ -94,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 @@ -116,32 +160,77 @@ export class MosaicDefinitionTransaction extends Transaction { } /** - * @internal - * @returns {VerifiableTransaction} + * @description get the calculated mosaic flag value + * @returns {number} + * @memberof MosaicDefinitionTransaction */ - 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()); - + public getMosaicFlagValue(): number { + let flag = MosaicFlags.NONE; if (this.mosaicProperties.supplyMutable === true) { - mosaicDefinitionTransaction = mosaicDefinitionTransaction.addSupplyMutable(); + flag += MosaicFlags.SUPPLY_MUTABLE; } if (this.mosaicProperties.transferable === true) { - mosaicDefinitionTransaction = mosaicDefinitionTransaction.addTransferability(); + flag += MosaicFlags.TRANSFERABLE; } if (this.mosaicProperties.restrictable === true) { - mosaicDefinitionTransaction = mosaicDefinitionTransaction.addRestrictable(); + flag += MosaicFlags.RESTRICTABLE; } - return mosaicDefinitionTransaction.build(); + 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 {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() : UInt64.fromUint(0).toDTO()), + ); + 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() : UInt64.fromUint(0).toDTO()), + ); + return transactionBuilder.serialize(); + } } diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index 7530eba330..c7e36df0d2 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -14,8 +14,15 @@ * limitations under the License. */ -import { Builder } from '../../infrastructure/builders/MosaicGlobalRestrictionTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { SignSchema } from '../../core/crypto/SignSchema'; +import { Convert } from '../../core/format'; +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'; @@ -23,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'; @@ -130,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 @@ -156,21 +194,47 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { /** * @internal - * @returns {VerifiableTransaction} + * @returns {Uint8Array} */ - 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(); + protected generateBytes(): Uint8Array { + 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 transactionBuilder = new EmbeddedMosaicGlobalRestrictionTransactionBuilder( + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), + 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 39b33d8318..1ee6fc22d7 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -14,14 +14,22 @@ * limitations under the License. */ -import { Builder } from '../../infrastructure/builders/MosaicSupplyChangeTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +import { SignSchema } from '../../core/crypto/SignSchema'; +import { Convert } from '../../core/format'; +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'; +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 { 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'; @@ -93,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 @@ -112,17 +146,39 @@ export class MosaicSupplyChangeTransaction extends Transaction { /** * @internal - * @returns {VerifiableTransaction} + * @returns {Uint8Array} */ - 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(); + 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(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const transactionBuilder = new EmbeddedMosaicSupplyChangeTransactionBuilder( + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), + 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/MultisigCosignatoryModification.ts b/src/model/transaction/MultisigCosignatoryModification.ts index 5e1192097c..e0d45b99d5 100644 --- a/src/model/transaction/MultisigCosignatoryModification.ts +++ b/src/model/transaction/MultisigCosignatoryModification.ts @@ -27,14 +27,14 @@ export class MultisigCosignatoryModification { /** * Constructor - * @param type + * @param modificiationType * @param cosignatoryPublicAccount */ constructor( /** * Multi-signature modification type. */ - public readonly type: MultisigCosignatoryModificationType, + public readonly modificiationType: MultisigCosignatoryModificationType, /** * Cosignatory public account. */ @@ -48,7 +48,7 @@ export class MultisigCosignatoryModification { toDTO() { return { cosignatoryPublicKey: this.cosignatoryPublicAccount.publicKey, - type: this.type, + modificiationType: this.modificiationType, }; } } 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, } diff --git a/src/model/transaction/RegisterNamespaceTransaction.ts b/src/model/transaction/RegisterNamespaceTransaction.ts index da05639507..6c63a6c4e5 100644 --- a/src/model/transaction/RegisterNamespaceTransaction.ts +++ b/src/model/transaction/RegisterNamespaceTransaction.ts @@ -14,9 +14,16 @@ * limitations under the License. */ -import { Convert as convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/NamespaceCreationTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +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'; +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'; @@ -24,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'; @@ -139,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 @@ -162,24 +204,69 @@ export class RegisterNamespaceTransaction extends Transaction { /** * @internal - * @returns {VerifiableTransaction} + * @returns {Uint8Array} */ - 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); - + protected generateBytes(): Uint8Array { + const signerBuffer = new Uint8Array(32); + const signatureBuffer = new Uint8Array(64); + let transactionBuilder: NamespaceRegistrationTransactionBuilder; if (this.namespaceType === NamespaceType.RootNamespace) { - registerNamespacetransaction = registerNamespacetransaction.addDuration(this.duration!.toDTO()); + 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 { - registerNamespacetransaction = registerNamespacetransaction.addParentId(this.parentId!.id.toDTO()); + 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 registerNamespacetransaction.build(); + return transactionBuilder.serialize(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + let transactionBuilder: EmbeddedNamespaceRegistrationTransactionBuilder; + if (this.namespaceType === NamespaceType.RootNamespace) { + transactionBuilder = new EmbeddedNamespaceRegistrationTransactionBuilder( + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), + this.versionToDTO(), + TransactionType.REGISTER_NAMESPACE.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(Convert.hexToUint8(this.signer!.publicKey)), + this.versionToDTO(), + TransactionType.REGISTER_NAMESPACE.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 6862dc7a3b..6dd679613e 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -13,16 +13,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Convert as convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/SecretLockTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +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'; +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'; 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'; @@ -112,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 @@ -134,23 +178,56 @@ 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} + * @returns {Uint8Array} */ - 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(); + 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(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const transactionBuilder = new EmbeddedSecretLockTransactionBuilder( + new KeyDto(convert.hexToUint8(this.signer!.publicKey)), + 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 cf41678857..0752efa2f1 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -14,15 +14,24 @@ * limitations under the License. */ -import { Convert as convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/SecretProofTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +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'; +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'; 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'; @@ -92,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 @@ -113,21 +149,61 @@ 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} + * @returns {Uint8Array} */ - 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(); + 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(); } + /** + * @internal + * @returns {Uint8Array} + */ + protected generateEmbeddedBytes(): Uint8Array { + const transactionBuilder = new EmbeddedSecretProofTransactionBuilder( + new KeyDto(Convert.hexToUint8(this.signer!.publicKey)), + 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 63fb543965..29d3ae1b3d 100644 --- a/src/model/transaction/Transaction.ts +++ b/src/model/transaction/Transaction.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import { SignSchema } from '../../core/crypto'; -import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction'; +import { KeyPair, SHA3Hasher, SignSchema } from '../../core/crypto'; +import { Convert } from '../../core/format'; import { SerializeTransactionToJSON } from '../../infrastructure/transaction/SerializeTransactionToJSON'; import { Account } from '../account/Account'; import { PublicAccount } from '../account/PublicAccount'; @@ -79,6 +79,39 @@ export abstract class Transaction { public readonly transactionInfo?: TransactionInfo | AggregateTransactionInfo) { } + /** + * Generate transaction hash hex + * @param {string} transactionPayload HexString Payload + * @param {Array} generationHashBuffer Network generation hash byte + * @returns {string} Returns Transaction Payload hash + */ + 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 + */ + protected abstract generateBytes(): Uint8Array; + + /** + * @internal + */ + protected abstract generateEmbeddedBytes(): Uint8Array; + /** * @internal * Serialize and sign transaction creating a new SignedTransaction @@ -88,27 +121,42 @@ 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); + 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( - signedTransactionRaw.payload, - signedTransactionRaw.hash, + payload, + Transaction.createTransactionHash(payload, generationHashBytes), account.publicKey, this.type, this.networkType); } /** - * @internal - */ - protected abstract buildTransaction(): VerifiableTransaction; - - /** - * @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); } /** @@ -123,6 +171,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} @@ -206,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/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..eb2daab1de 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -14,17 +14,32 @@ * limitations under the License. */ -import { Convert as convert } from '../../core/format'; -import { Builder } from '../../infrastructure/builders/TransferTransaction'; -import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction'; +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'; +import { EmbeddedTransferTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedTransferTransactionBuilder'; +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'; 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'; @@ -93,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 @@ -109,6 +158,46 @@ 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); + } + + /** + * 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 @@ -133,17 +222,45 @@ export class TransferTransaction extends Transaction { /** * @internal - * @returns {VerifiableTransaction} + * @returns {Uint8Array} */ - 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(); + 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(this.getRecipientBytes()), + this.getMessageBuffer(), + this.sortMosaics().map((mosaic) => { + return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), + new AmountDto(mosaic.amount.toDTO())); + }), + ); + 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/src/service/AggregateTransactionService.ts b/src/service/AggregateTransactionService.ts index cd7bb44381..98775221ce 100644 --- a/src/service/AggregateTransactionService.ts +++ b/src/service/AggregateTransactionService.ts @@ -99,7 +99,7 @@ export class AggregateTransactionService { */ if (innerTransaction.type === TransactionType.MODIFY_MULTISIG_ACCOUNT) { if ((innerTransaction as ModifyMultisigAccountTransaction).modifications - .find((modification) => modification.type === MultisigCosignatoryModificationType.Remove) !== undefined) { + .find((modification) => modification.modificiationType === MultisigCosignatoryModificationType.Remove) !== undefined) { isMultisigRemoval = true; } } diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index 98fb4f5c86..f6b7af8d20 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -20,29 +20,29 @@ 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'; import { MosaicNonce } from '../../../src/model/mosaic/MosaicNonce'; import { MosaicProperties } from '../../../src/model/mosaic/MosaicProperties'; import { MosaicRestrictionType } from '../../../src/model/mosaic/MosaicRestrictionType'; import { MosaicSupplyType } from '../../../src/model/mosaic/MosaicSupplyType'; import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic'; -import { AliasActionType } from '../../../src/model/namespace/AliasActionType'; +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'; 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'; @@ -79,7 +79,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -87,9 +87,9 @@ 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.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'); }); @@ -102,7 +102,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -110,8 +110,8 @@ describe('TransactionMapping - createFromPayload', () => { const signedTransaction = mosaicRestrictionTransaction.signWith(account, generationHash); const transaction = TransactionMapping - .createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction; - expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowMosaic); + .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); 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.AllowIncomingTransactionType, [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 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); }); @@ -143,7 +144,7 @@ describe('TransactionMapping - createFromPayload', () => { const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, address, NetworkType.MIJIN_TEST, @@ -153,7 +154,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AddressAliasTransaction; - expect(transaction.actionType).to.be.equal(AliasActionType.Link); + expect(transaction.aliasAction).to.be.equal(AliasAction.Link); expect(transaction.namespaceId.id.lower).to.be.equal(33347626); expect(transaction.namespaceId.id.higher).to.be.equal(3779697293); expect(transaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); @@ -164,7 +165,7 @@ describe('TransactionMapping - createFromPayload', () => { const mosaicId = new MosaicId([2262289484, 3405110546]); const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, mosaicId, NetworkType.MIJIN_TEST, @@ -173,7 +174,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as MosaicAliasTransaction; - expect(mosaicAliasTransaction.actionType).to.be.equal(AliasActionType.Link); + expect(mosaicAliasTransaction.aliasAction).to.be.equal(AliasAction.Link); expect(mosaicAliasTransaction.namespaceId.id.lower).to.be.equal(33347626); expect(mosaicAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); @@ -414,7 +415,7 @@ describe('TransactionMapping - createFromPayload', () => { .to.be.equal(2); expect(transaction.minRemovalDelta) .to.be.equal(1); - expect(transaction.modifications[0].type) + expect(transaction.modifications[0].modificiationType) .to.be.equal(MultisigCosignatoryModificationType.Add); expect(transaction.modifications[0].cosignatoryPublicAccount.publicKey) .to.be.equal('B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24'); @@ -439,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); }); @@ -461,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); }); @@ -498,7 +501,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); }); @@ -665,16 +668,16 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); 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); + expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress); expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add); }); @@ -686,16 +689,16 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); 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(RestrictionType.AllowMosaic); + 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); }); @@ -707,16 +710,16 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); 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(RestrictionType.AllowTransaction); + 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); }); @@ -725,7 +728,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, address, NetworkType.MIJIN_TEST, @@ -735,7 +738,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(addressAliasTransaction.toJSON()) as AddressAliasTransaction; expect(transaction.type).to.be.equal(TransactionType.ADDRESS_ALIAS); - expect(transaction.actionType).to.be.equal(AliasActionType.Link); + expect(transaction.aliasAction).to.be.equal(AliasAction.Link); }); it('should create MosaicAliasTransaction', () => { @@ -743,7 +746,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => const mosaicId = new MosaicId([2262289484, 3405110546]); const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, mosaicId, NetworkType.MIJIN_TEST, @@ -752,7 +755,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => TransactionMapping.createFromDTO(mosaicAliasTransaction.toJSON()) as MosaicAliasTransaction; expect(transaction.type).to.be.equal(TransactionType.MOSAIC_ALIAS); - expect(transaction.actionType).to.be.equal(AliasActionType.Link); + expect(transaction.aliasAction).to.be.equal(AliasAction.Link); }); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 5a13ee0d28..21822a3091 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -18,17 +18,17 @@ 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'; import { MosaicProperties } from '../../src/model/mosaic/MosaicProperties'; import { MosaicSupplyType } from '../../src/model/mosaic/MosaicSupplyType'; import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; -import { AliasActionType } from '../../src/model/namespace/AliasActionType'; +import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AccountLinkTransaction } from '../../src/model/transaction/AccountLinkTransaction'; import { AccountRestrictionModification } from '../../src/model/transaction/AccountRestrictionModification'; @@ -72,7 +72,7 @@ describe('SerializeTransactionToJSON', () => { const json = accountLinkTransaction.toJSON(); expect(json.transaction.remoteAccountKey).to.be.equal(account.publicKey); - expect(json.transaction.action).to.be.equal(LinkAction.Link); + expect(json.transaction.linkAction).to.be.equal(LinkAction.Link); }); it('should create AccountRestrictionAddressTransaction', () => { @@ -83,15 +83,15 @@ describe('SerializeTransactionToJSON', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); 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.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); }); @@ -103,15 +103,15 @@ describe('SerializeTransactionToJSON', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); 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.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); }); @@ -123,15 +123,15 @@ describe('SerializeTransactionToJSON', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); 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.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); }); @@ -140,7 +140,7 @@ describe('SerializeTransactionToJSON', () => { const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, address, NetworkType.MIJIN_TEST, @@ -149,7 +149,7 @@ describe('SerializeTransactionToJSON', () => { const json = addressAliasTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.ADDRESS_ALIAS); - expect(json.transaction.action).to.be.equal(AliasActionType.Link); + expect(json.transaction.aliasAction).to.be.equal(AliasAction.Link); }); it('should create MosaicAliasTransaction', () => { @@ -157,7 +157,7 @@ describe('SerializeTransactionToJSON', () => { const mosaicId = new MosaicId([2262289484, 3405110546]); const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, mosaicId, NetworkType.MIJIN_TEST, @@ -165,7 +165,7 @@ describe('SerializeTransactionToJSON', () => { const json = mosaicAliasTransaction.toJSON(); expect(json.transaction.type).to.be.equal(TransactionType.MOSAIC_ALIAS); - expect(json.transaction.action).to.be.equal(AliasActionType.Link); + expect(json.transaction.aliasAction).to.be.equal(AliasAction.Link); }); diff --git a/test/model/account/AccountRestriction.spec.ts b/test/model/account/AccountRestriction.spec.ts index 5bc3e189b6..11defe8b1c 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.AllowIncomingAddress, values: ['906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'], }; diff --git a/test/model/account/AccountRestrictions.spec.ts b/test/model/account/AccountRestrictions.spec.ts index 1ad76d7daa..0ed43b4f0b 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.AllowIncomingAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], diff --git a/test/model/account/AccountRestrictionsInfo.spec.ts b/test/model/account/AccountRestrictionsInfo.spec.ts index 01ac4771f9..f4291f2468 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.AllowIncomingAddress, values: [{modificationType: RestrictionModificationType.Add, value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', }], 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 04ef489a07..cde002ae01 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'; @@ -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, @@ -74,7 +74,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -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, @@ -90,14 +90,14 @@ describe('AccountRestrictionTransaction', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); 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, @@ -105,7 +105,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -121,7 +121,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -138,7 +138,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -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( @@ -157,7 +157,7 @@ describe('AccountRestrictionTransaction', () => { ); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowAddress, + AccountRestrictionType.AllowIncomingAddress, [addressRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -167,7 +167,7 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('0101009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + )).to.be.equal('0101019050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); }); @@ -179,15 +179,24 @@ describe('AccountRestrictionTransaction', () => { address, ); - expect(() => { - AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( - Deadline.create(), - RestrictionType.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', () => { @@ -199,7 +208,7 @@ describe('AccountRestrictionTransaction', () => { ); const mosaicRestrictionTransaction = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowMosaic, + AccountRestrictionType.AllowMosaic, [mosaicRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -209,11 +218,11 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('0201004CCCD78612DDF5CA'); + )).to.be.equal('0201014CCCD78612DDF5CA'); }); - 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(), - RestrictionType.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', () => { @@ -241,7 +261,7 @@ describe('AccountRestrictionTransaction', () => { ); const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction( Deadline.create(), - RestrictionType.AllowTransaction, + AccountRestrictionType.AllowIncomingTransactionType, [operationRestrictionFilter], NetworkType.MIJIN_TEST, ); @@ -251,7 +271,109 @@ describe('AccountRestrictionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('0401004E42'); + )).to.be.equal('0401014E42'); + + }); + + 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('4101019050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + + 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('C101019050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + + }); + + 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('4401014E42'); + + 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('C401014E42'); }); }); diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index b05aa01f04..59b1ce1144 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -19,7 +19,7 @@ import {Account} from '../../../src/model/account/Account'; import {Address} from '../../../src/model/account/Address'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import {MosaicId} from '../../../src/model/mosaic/MosaicId'; -import {AliasActionType} from '../../../src/model/namespace/AliasActionType'; +import {AliasAction} from '../../../src/model/namespace/AliasAction'; import {NamespaceId} from '../../../src/model/namespace/NamespaceId'; import {AddressAliasTransaction} from '../../../src/model/transaction/AddressAliasTransaction'; import {Deadline} from '../../../src/model/transaction/Deadline'; @@ -38,7 +38,7 @@ describe('AddressAliasTransaction', () => { const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, address, NetworkType.MIJIN_TEST, @@ -53,7 +53,7 @@ describe('AddressAliasTransaction', () => { const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, address, NetworkType.MIJIN_TEST, @@ -69,13 +69,13 @@ describe('AddressAliasTransaction', () => { const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, address, NetworkType.MIJIN_TEST, ); - expect(addressAliasTransaction.actionType).to.be.equal(AliasActionType.Link); + expect(addressAliasTransaction.aliasAction).to.be.equal(AliasAction.Link); expect(addressAliasTransaction.namespaceId.id.lower).to.be.equal(33347626); expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); @@ -85,7 +85,7 @@ describe('AddressAliasTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('002AD8FC018D9A49E19050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + )).to.be.equal('012AD8FC018D9A49E19050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); }); @@ -95,7 +95,7 @@ describe('AddressAliasTransaction', () => { const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, address, NetworkType.MIJIN_TEST, diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index ab53059940..4e8c4227e6 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -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', () => { @@ -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', () => { @@ -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: { @@ -454,6 +481,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( diff --git a/test/model/transaction/LockFundsTransaction.spec.ts b/test/model/transaction/LockFundsTransaction.spec.ts index ebd56dc4e0..779e6166d7 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.signWith(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 503f196c8d..00afd72d47 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); @@ -101,11 +101,11 @@ describe('ModifyMultisigAccountTransaction', () => { .to.be.equal(1); expect(modifyMultisigAccountTransaction.modifications.length) .to.be.equal(2); - expect(modifyMultisigAccountTransaction.modifications[0].type) + expect(modifyMultisigAccountTransaction.modifications[0].modificiationType) .to.be.equal(MultisigCosignatoryModificationType.Add); expect(modifyMultisigAccountTransaction.modifications[0].cosignatoryPublicAccount.publicKey) .to.be.equal('B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24'); - expect(modifyMultisigAccountTransaction.modifications[1].type) + expect(modifyMultisigAccountTransaction.modifications[1].modificiationType) .to.be.equal(MultisigCosignatoryModificationType.Add); expect(modifyMultisigAccountTransaction.modifications[1].cosignatoryPublicAccount.publicKey) .to.be.equal('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); @@ -115,8 +115,8 @@ describe('ModifyMultisigAccountTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('01020200B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC' + - '6EC2400B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); + )).to.be.equal('01020201B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC2401B1' + + 'B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4'); }); diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index 82a26c9ed8..34184eff95 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -18,7 +18,7 @@ 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 {AliasActionType} from '../../../src/model/namespace/AliasActionType'; +import {AliasAction} from '../../../src/model/namespace/AliasAction'; import {NamespaceId} from '../../../src/model/namespace/NamespaceId'; import {Deadline} from '../../../src/model/transaction/Deadline'; import {MosaicAliasTransaction} from '../../../src/model/transaction/MosaicAliasTransaction'; @@ -37,7 +37,7 @@ describe('MosaicAliasTransaction', () => { const mosaicId = new MosaicId([2262289484, 3405110546]); const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, mosaicId, NetworkType.MIJIN_TEST, @@ -52,11 +52,11 @@ describe('MosaicAliasTransaction', () => { const mosaicId = new MosaicId([2262289484, 3405110546]); const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, mosaicId, NetworkType.MIJIN_TEST, - new UInt64([1, 0]) + new UInt64([1, 0]), ); expect(mosaicAliasTransaction.maxFee.higher).to.be.equal(0); @@ -68,13 +68,13 @@ describe('MosaicAliasTransaction', () => { const mosaicId = new MosaicId([2262289484, 3405110546]); const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, mosaicId, NetworkType.MIJIN_TEST, ); - expect(mosaicAliasTransaction.actionType).to.be.equal(AliasActionType.Link); + expect(mosaicAliasTransaction.aliasAction).to.be.equal(AliasAction.Link); expect(mosaicAliasTransaction.namespaceId.id.lower).to.be.equal(33347626); expect(mosaicAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); @@ -85,7 +85,7 @@ describe('MosaicAliasTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('002AD8FC018D9A49E14CCCD78612DDF5CA'); + )).to.be.equal('012AD8FC018D9A49E14CCCD78612DDF5CA'); }); @@ -95,7 +95,7 @@ describe('MosaicAliasTransaction', () => { const mosaicId = new MosaicId([2262289484, 3405110546]); const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), - AliasActionType.Link, + AliasAction.Link, namespaceId, mosaicId, NetworkType.MIJIN_TEST, diff --git a/test/model/transaction/MosaicDefinitionTransaction.spec.ts b/test/model/transaction/MosaicDefinitionTransaction.spec.ts index 5c15bafa89..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); @@ -98,7 +98,7 @@ describe('MosaicDefinitionTransaction', () => { expect(signedTransaction.payload.substring( 240, signedTransaction.payload.length, - )).to.be.equal('E6DE84B8010000000000000001070302E803000000000000'); + )).to.be.equal('E6DE84B801000000000000000703E803000000000000'); }); @@ -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/MultisigCosignatoryModification.spec.ts b/test/model/transaction/MultisigCosignatoryModification.spec.ts index 61356ec9d0..5c03c03bc3 100644 --- a/test/model/transaction/MultisigCosignatoryModification.spec.ts +++ b/test/model/transaction/MultisigCosignatoryModification.spec.ts @@ -29,7 +29,7 @@ describe('MultisigCosignatoryModification', () => { ); expect(multisigCosignatoryModification.cosignatoryPublicAccount.publicKey) .to.be.equal('C52C211CF935C61D65F26B253AA260416F018C3D21E4D184A7671F403C849BBB'); - expect(multisigCosignatoryModification.type).to.be.equal(MultisigCosignatoryModificationType.Add); + expect(multisigCosignatoryModification.modificiationType).to.be.equal(MultisigCosignatoryModificationType.Add); }); it('should create Add MultisigCosignatoryModification and get toDTO correctly', () => { @@ -39,10 +39,9 @@ describe('MultisigCosignatoryModification', () => { ).toDTO(); expect(multisigCosignatoryModification.cosignatoryPublicKey) .to.be.equal('C52C211CF935C61D65F26B253AA260416F018C3D21E4D184A7671F403C849BBB'); - expect(multisigCosignatoryModification.type).to.be.equal(MultisigCosignatoryModificationType.Add); + expect(multisigCosignatoryModification.modificiationType).to.be.equal(MultisigCosignatoryModificationType.Add); }); - it('should create Remove MultisigCosignatoryModification', () => { const multisigCosignatoryModification = new MultisigCosignatoryModification( MultisigCosignatoryModificationType.Remove, @@ -50,7 +49,7 @@ describe('MultisigCosignatoryModification', () => { ); expect(multisigCosignatoryModification.cosignatoryPublicAccount.publicKey) .to.be.equal('C52C211CF935C61D65F26B253AA260416F018C3D21E4D184A7671F403C849BBB'); - expect(multisigCosignatoryModification.type).to.be.equal(MultisigCosignatoryModificationType.Remove); + expect(multisigCosignatoryModification.modificiationType).to.be.equal(MultisigCosignatoryModificationType.Remove); }); it('should create Remove MultisigCosignatoryModification and get toDTO correctly', () => { @@ -60,6 +59,6 @@ describe('MultisigCosignatoryModification', () => { ).toDTO(); expect(multisigCosignatoryModification.cosignatoryPublicKey) .to.be.equal('C52C211CF935C61D65F26B253AA260416F018C3D21E4D184A7671F403C849BBB'); - expect(multisigCosignatoryModification.type).to.be.equal(MultisigCosignatoryModificationType.Remove); + expect(multisigCosignatoryModification.modificiationType).to.be.equal(MultisigCosignatoryModificationType.Remove); }); }); diff --git a/test/model/transaction/SecretLockTransaction.spec.ts b/test/model/transaction/SecretLockTransaction.spec.ts index 26bbd11ede..9b5a00780d 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.signWith(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..951b1ab8f0 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.signWith(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..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,7 +234,11 @@ 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'); + } + + protected generateEmbeddedBytes(): Uint8Array { + throw new Error('Not implemented'); } } diff --git a/test/model/transaction/TransferTransaction.spec.ts b/test/model/transaction/TransferTransaction.spec.ts index 31e063be36..969bf81a1b 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.signWith(account, generationHash); + + expect(signedTransaction.payload.substring( + 240, + signedTransaction.payload.length, + )).to.be.equal( + '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000100746573742D6D657373616765' + + '44B262C46CEABB8500E1F50500000000'); + }); });