Skip to content

Commit 416ffda

Browse files
committed
Added embedded transaction builders
1 parent 5b9b4ad commit 416ffda

24 files changed

+531
-33
lines changed

src/model/transaction/AccountAddressRestrictionTransaction.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTra
2020
import { AccountAddressRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionModificationBuilder';
2121
import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder';
2222
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
23+
import { EmbeddedAccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountAddressRestrictionTransactionBuilder';
2324
import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto';
2425
import { KeyDto } from '../../infrastructure/catbuffer/KeyDto';
2526
import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto';
@@ -144,4 +145,26 @@ export class AccountAddressRestrictionTransaction extends Transaction {
144145
);
145146
return transactionBuilder.serialize();
146147
}
148+
149+
/**
150+
* @internal
151+
* @returns {Uint8Array}
152+
*/
153+
protected generateEmbeddedBytes(): Uint8Array {
154+
const signerBuffer = new Uint8Array(32);
155+
156+
const transactionBuilder = new EmbeddedAccountAddressRestrictionTransactionBuilder(
157+
new KeyDto(signerBuffer),
158+
this.versionToDTO(),
159+
TransactionType.ACCOUNT_RESTRICTION_ADDRESS.valueOf(),
160+
this.restrictionType.valueOf(),
161+
this.modifications.map((modification) => {
162+
return new AccountAddressRestrictionModificationBuilder(
163+
modification.modificationType.valueOf(),
164+
new UnresolvedAddressDto(RawAddress.stringToAddress(modification.value)),
165+
);
166+
}),
167+
);
168+
return transactionBuilder.serialize();
169+
}
147170
}

src/model/transaction/AccountLinkTransaction.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { Builder } from '../../infrastructure/builders/AccountLinkTransaction';
1919
import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction';
2020
import { AccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/AccountLinkTransactionBuilder';
2121
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
22+
import { EmbeddedAccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder';
2223
import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto';
2324
import { KeyDto } from '../../infrastructure/catbuffer/KeyDto';
2425
import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto';
@@ -138,4 +139,21 @@ export class AccountLinkTransaction extends Transaction {
138139
);
139140
return transactionBuilder.serialize();
140141
}
142+
143+
/**
144+
* @internal
145+
* @returns {Uint8Array}
146+
*/
147+
protected generateEmbeddedBytes(): Uint8Array {
148+
const signerBuffer = new Uint8Array(32);
149+
150+
const transactionBuilder = new EmbeddedAccountLinkTransactionBuilder(
151+
new KeyDto(signerBuffer),
152+
this.versionToDTO(),
153+
TransactionType.LINK_ACCOUNT.valueOf(),
154+
new KeyDto(Convert.hexToUint8(this.remoteAccountKey)),
155+
this.linkAction.valueOf(),
156+
);
157+
return transactionBuilder.serialize();
158+
}
141159
}

src/model/transaction/AccountMosaicRestrictionTransaction.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTra
1919
import { AccountMosaicRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionModificationBuilder';
2020
import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder';
2121
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
22+
import { EmbeddedAccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountMosaicRestrictionTransactionBuilder';
2223
import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto';
2324
import { KeyDto } from '../../infrastructure/catbuffer/KeyDto';
2425
import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto';
@@ -143,4 +144,26 @@ export class AccountMosaicRestrictionTransaction extends Transaction {
143144
);
144145
return transactionBuilder.serialize();
145146
}
147+
148+
/**
149+
* @internal
150+
* @returns {Uint8Array}
151+
*/
152+
protected generateEmbeddedBytes(): Uint8Array {
153+
const signerBuffer = new Uint8Array(32);
154+
155+
const transactionBuilder = new EmbeddedAccountMosaicRestrictionTransactionBuilder(
156+
new KeyDto(signerBuffer),
157+
this.versionToDTO(),
158+
TransactionType.ACCOUNT_RESTRICTION_MOSAIC.valueOf(),
159+
this.restrictionType.valueOf(),
160+
this.modifications.map((modification) => {
161+
return new AccountMosaicRestrictionModificationBuilder(
162+
modification.modificationType.valueOf(),
163+
new UnresolvedMosaicIdDto(modification.value),
164+
);
165+
}),
166+
);
167+
return transactionBuilder.serialize();
168+
}
146169
}

src/model/transaction/AccountOperationRestrictionTransaction.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616

1717
import { Builder } from '../../infrastructure/builders/AccountRestrictionsEntityTypeTransaction';
1818
import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction';
19+
import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder';
20+
import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder';
21+
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
22+
import { EmbeddedAccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountOperationRestrictionTransactionBuilder';
23+
import { KeyDto } from '../../infrastructure/catbuffer/KeyDto';
24+
import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto';
25+
import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto';
1926
import { PublicAccount } from '../account/PublicAccount';
2027
import { RestrictionType } from '../account/RestrictionType';
2128
import { NetworkType } from '../blockchain/NetworkType';
@@ -26,13 +33,6 @@ import { Transaction } from './Transaction';
2633
import { TransactionInfo } from './TransactionInfo';
2734
import { TransactionType } from './TransactionType';
2835
import { TransactionVersion } from './TransactionVersion';
29-
import { AccountOperationRestrictionModificationBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionModificationBuilder';
30-
import { AccountOperationRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountOperationRestrictionTransactionBuilder';
31-
import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto';
32-
import { KeyDto } from '../../infrastructure/catbuffer/KeyDto';
33-
import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto';
34-
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
35-
import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto';
3636

3737
export class AccountOperationRestrictionTransaction extends Transaction {
3838

@@ -142,4 +142,26 @@ export class AccountOperationRestrictionTransaction extends Transaction {
142142
);
143143
return transactionBuilder.serialize();
144144
}
145+
146+
/**
147+
* @internal
148+
* @returns {Uint8Array}
149+
*/
150+
protected generateEmbeddedBytes(): Uint8Array {
151+
const signerBuffer = new Uint8Array(32);
152+
153+
const transactionBuilder = new EmbeddedAccountOperationRestrictionTransactionBuilder(
154+
new KeyDto(signerBuffer),
155+
this.versionToDTO(),
156+
TransactionType.ACCOUNT_RESTRICTION_OPERATION.valueOf(),
157+
this.restrictionType.valueOf(),
158+
this.modifications.map((modification) => {
159+
return new AccountOperationRestrictionModificationBuilder(
160+
modification.modificationType.valueOf(),
161+
modification.value.valueOf(),
162+
);
163+
}),
164+
);
165+
return transactionBuilder.serialize();
166+
}
145167
}

src/model/transaction/AddressAliasTransaction.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { RawAddress } from '../../core/format';
1718
import { Builder } from '../../infrastructure/builders/AddressAliasTransaction';
1819
import { VerifiableTransaction } from '../../infrastructure/builders/VerifiableTransaction';
1920
import { AddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/AddressAliasTransactionBuilder';
2021
import { AddressDto } from '../../infrastructure/catbuffer/AddressDto';
2122
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
23+
import { EmbeddedAddressAliasTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAddressAliasTransactionBuilder';
2224
import { EntityTypeDto } from '../../infrastructure/catbuffer/EntityTypeDto';
2325
import { KeyDto } from '../../infrastructure/catbuffer/KeyDto';
2426
import { NamespaceIdDto } from '../../infrastructure/catbuffer/NamespaceIdDto';
@@ -35,7 +37,6 @@ import { Transaction } from './Transaction';
3537
import { TransactionInfo } from './TransactionInfo';
3638
import { TransactionType } from './TransactionType';
3739
import { TransactionVersion } from './TransactionVersion';
38-
import { RawAddress } from '../../core/format';
3940

4041
/**
4142
* In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply,
@@ -156,4 +157,22 @@ export class AddressAliasTransaction extends Transaction {
156157
);
157158
return transactionBuilder.serialize();
158159
}
160+
161+
/**
162+
* @internal
163+
* @returns {Uint8Array}
164+
*/
165+
protected generateEmbeddedBytes(): Uint8Array {
166+
const signerBuffer = new Uint8Array(32);
167+
168+
const transactionBuilder = new EmbeddedAddressAliasTransactionBuilder(
169+
new KeyDto(signerBuffer),
170+
this.versionToDTO(),
171+
TransactionType.ADDRESS_ALIAS.valueOf(),
172+
this.actionType.valueOf(),
173+
new NamespaceIdDto(this.namespaceId.id.toDTO()),
174+
new AddressDto(RawAddress.stringToAddress(this.address.plain())),
175+
);
176+
return transactionBuilder.serialize();
177+
}
159178
}

src/model/transaction/AggregateTransaction.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,12 @@ export class AggregateTransaction extends Transaction {
211211
protected generateBytes(): Uint8Array {
212212
throw new Error('Not implemented');
213213
}
214+
215+
/**
216+
* @internal
217+
* @returns {Uint8Array}
218+
*/
219+
protected generateEmbeddedBytes(): Uint8Array {
220+
throw new Error('Not implemented');
221+
}
214222
}

src/model/transaction/LockFundsTransaction.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,19 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { Convert } from '../../core/format';
1718
import { Builder } from '../../infrastructure/builders/HashLockTransaction';
1819
import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction';
20+
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
21+
import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto';
22+
import { EmbeddedHashLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder';
23+
import { Hash256Dto } from '../../infrastructure/catbuffer/Hash256Dto';
24+
import { HashLockTransactionBuilder } from '../../infrastructure/catbuffer/HashLockTransactionBuilder';
25+
import { KeyDto } from '../../infrastructure/catbuffer/KeyDto';
26+
import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto';
27+
import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto';
28+
import { UnresolvedMosaicBuilder } from '../../infrastructure/catbuffer/UnresolvedMosaicBuilder';
29+
import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto';
1930
import { PublicAccount } from '../account/PublicAccount';
2031
import { NetworkType } from '../blockchain/NetworkType';
2132
import { Mosaic } from '../mosaic/Mosaic';
@@ -142,6 +153,40 @@ export class LockFundsTransaction extends Transaction {
142153
* @returns {Uint8Array}
143154
*/
144155
protected generateBytes(): Uint8Array {
145-
throw new Error('Not implemented');
156+
const signerBuffer = new Uint8Array(32);
157+
const signatureBuffer = new Uint8Array(64);
158+
159+
const transactionBuilder = new HashLockTransactionBuilder(
160+
new SignatureDto(signatureBuffer),
161+
new KeyDto(signerBuffer),
162+
this.versionToDTO(),
163+
TransactionType.LOCK.valueOf(),
164+
new AmountDto(this.maxFee.toDTO()),
165+
new TimestampDto(this.deadline.toDTO()),
166+
new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()),
167+
new AmountDto(this.mosaic.amount.toDTO())),
168+
new BlockDurationDto(this.duration.toDTO()),
169+
new Hash256Dto(Convert.hexToUint8(this.hash)),
170+
);
171+
return transactionBuilder.serialize();
172+
}
173+
174+
/**
175+
* @internal
176+
* @returns {Uint8Array}
177+
*/
178+
protected generateEmbeddedBytes(): Uint8Array {
179+
const signerBuffer = new Uint8Array(32);
180+
181+
const transactionBuilder = new EmbeddedHashLockTransactionBuilder(
182+
new KeyDto(signerBuffer),
183+
this.versionToDTO(),
184+
TransactionType.LOCK.valueOf(),
185+
new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()),
186+
new AmountDto(this.mosaic.amount.toDTO())),
187+
new BlockDurationDto(this.duration.toDTO()),
188+
new Hash256Dto(Convert.hexToUint8(this.hash)),
189+
);
190+
return transactionBuilder.serialize();
146191
}
147192
}

src/model/transaction/ModifyMultisigAccountTransaction.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { Transaction } from './Transaction';
3232
import { TransactionInfo } from './TransactionInfo';
3333
import { TransactionType } from './TransactionType';
3434
import { TransactionVersion } from './TransactionVersion';
35+
import { EmbeddedMultisigAccountModificationTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMultisigAccountModificationTransactionBuilder';
3536

3637
/**
3738
* Modify multisig account transactions are part of the NEM's multisig account system.
@@ -165,4 +166,27 @@ export class ModifyMultisigAccountTransaction extends Transaction {
165166
);
166167
return transactionBuilder.serialize();
167168
}
169+
170+
/**
171+
* @internal
172+
* @returns {Uint8Array}
173+
*/
174+
protected generateEmbeddedBytes(): Uint8Array {
175+
const signerBuffer = new Uint8Array(32);
176+
177+
const transactionBuilder = new EmbeddedMultisigAccountModificationTransactionBuilder(
178+
new KeyDto(signerBuffer),
179+
this.versionToDTO(),
180+
TransactionType.MODIFY_MULTISIG_ACCOUNT.valueOf(),
181+
this.minRemovalDelta,
182+
this.minApprovalDelta,
183+
this.modifications.map((modification) => {
184+
return new CosignatoryModificationBuilder(
185+
modification.type.valueOf(),
186+
new KeyDto(Convert.hexToUint8(modification.cosignatoryPublicAccount.publicKey)),
187+
);
188+
}),
189+
);
190+
return transactionBuilder.serialize();
191+
}
168192
}

src/model/transaction/MosaicAddressRestrictionTransaction.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,17 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { RawAddress } from '../../core/format';
1718
import { Builder } from '../../infrastructure/builders/MosaicAddressRestrictionTransaction';
1819
import {VerifiableTransaction} from '../../infrastructure/builders/VerifiableTransaction';
20+
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
21+
import { EmbeddedMosaicAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicAddressRestrictionTransactionBuilder';
22+
import { KeyDto } from '../../infrastructure/catbuffer/KeyDto';
23+
import { MosaicAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/MosaicAddressRestrictionTransactionBuilder';
24+
import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto';
25+
import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto';
26+
import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto';
27+
import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto';
1928
import { Address } from '../account/Address';
2029
import { PublicAccount } from '../account/PublicAccount';
2130
import { NetworkType } from '../blockchain/NetworkType';
@@ -155,6 +164,42 @@ export class MosaicAddressRestrictionTransaction extends Transaction {
155164
* @returns {Uint8Array}
156165
*/
157166
protected generateBytes(): Uint8Array {
158-
throw new Error('Not implemented');
167+
const signerBuffer = new Uint8Array(32);
168+
const signatureBuffer = new Uint8Array(64);
169+
170+
const transactionBuilder = new MosaicAddressRestrictionTransactionBuilder(
171+
new SignatureDto(signatureBuffer),
172+
new KeyDto(signerBuffer),
173+
this.versionToDTO(),
174+
TransactionType.MOSAIC_ADDRESS_RESTRICTION.valueOf(),
175+
new AmountDto(this.maxFee.toDTO()),
176+
new TimestampDto(this.deadline.toDTO()),
177+
new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()),
178+
this.restrictionKey.toDTO(),
179+
new UnresolvedAddressDto(RawAddress.stringToAddress(this.targetAddress.plain())),
180+
this.previousRestrictionValue.toDTO(),
181+
this.newRestrictionValue.toDTO(),
182+
);
183+
return transactionBuilder.serialize();
184+
}
185+
186+
/**
187+
* @internal
188+
* @returns {Uint8Array}
189+
*/
190+
protected generateEmbeddedBytes(): Uint8Array {
191+
const signerBuffer = new Uint8Array(32);
192+
193+
const transactionBuilder = new EmbeddedMosaicAddressRestrictionTransactionBuilder(
194+
new KeyDto(signerBuffer),
195+
this.versionToDTO(),
196+
TransactionType.MOSAIC_ADDRESS_RESTRICTION.valueOf(),
197+
new UnresolvedMosaicIdDto(this.mosaicId.id.toDTO()),
198+
this.restrictionKey.toDTO(),
199+
new UnresolvedAddressDto(RawAddress.stringToAddress(this.targetAddress.plain())),
200+
this.previousRestrictionValue.toDTO(),
201+
this.newRestrictionValue.toDTO(),
202+
);
203+
return transactionBuilder.serialize();
159204
}
160205
}

0 commit comments

Comments
 (0)