Skip to content

Commit 02e4517

Browse files
author
Greg S
committed
issue #53: implementation proposal for Transaction.size and type classes overloads
1 parent b1905fd commit 02e4517

31 files changed

+576
-7
lines changed

src/model/transaction/AccountLinkTransaction.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@ export class AccountLinkTransaction extends Transaction {
8080
super(TransactionType.LINK_ACCOUNT, networkType, version, deadline, maxFee, signature, signer, transactionInfo);
8181
}
8282

83+
/**
84+
* @override Transaction.size()
85+
* @description get the byte size of a AccountLinkTransaction
86+
* @returns {number}
87+
* @memberof AccountLinkTransaction
88+
*/
89+
public get size(): number {
90+
const byteSize = super.size;
91+
92+
// set static byte size fields
93+
const bytePublicKey = 32;
94+
const byteLinkAction = 1;
95+
96+
return byteSize + bytePublicKey + byteLinkAction;
97+
}
98+
8399
/**
84100
* @internal
85101
* @returns {VerifiableTransaction}

src/model/transaction/AccountPropertyTransaction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class AccountPropertyTransaction {
5151
propertyType,
5252
modifications,
5353
networkType,
54-
maxFee
54+
maxFee,
5555
);
5656
}
5757

@@ -79,7 +79,7 @@ export class AccountPropertyTransaction {
7979
propertyType,
8080
modifications,
8181
networkType,
82-
maxFee
82+
maxFee,
8383
);
8484
}
8585

@@ -107,7 +107,7 @@ export class AccountPropertyTransaction {
107107
propertyType,
108108
modifications,
109109
networkType,
110-
maxFee
110+
maxFee,
111111
);
112112
}
113113

src/model/transaction/AddressAliasTransaction.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,23 @@ export class AddressAliasTransaction extends Transaction {
9393
super(TransactionType.ADDRESS_ALIAS, networkType, version, deadline, maxFee, signature, signer, transactionInfo);
9494
}
9595

96+
/**
97+
* @override Transaction.size()
98+
* @description get the byte size of a AddressAliasTransaction
99+
* @returns {number}
100+
* @memberof AddressAliasTransaction
101+
*/
102+
public get size(): number {
103+
const byteSize = super.size;
104+
105+
// set static byte size fields
106+
const byteActionType = 1;
107+
const byteNamespaceId = 8;
108+
const byteAddress = 25;
109+
110+
return byteSize + byteActionType + byteNamespaceId + byteAddress;
111+
}
112+
96113
/**
97114
* @internal
98115
* @returns {VerifiableTransaction}

src/model/transaction/AggregateTransaction.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,24 @@ export class AggregateTransaction extends Transaction {
151151
|| (this.signer !== undefined && this.signer.equals(publicAccount));
152152
}
153153

154+
/**
155+
* @override Transaction.size()
156+
* @description get the byte size of a AggregateTransaction
157+
* @returns {number}
158+
* @memberof AggregateTransaction
159+
*/
160+
public get size(): number {
161+
const byteSize = super.size;
162+
163+
// set static byte size fields
164+
const byteTransactionsSize = 4;
165+
166+
// calculate each inner transaction's size
167+
let byteTransactions = 0;
168+
this.innerTransactions.map((transaction) => {
169+
byteTransactions += transaction.size;
170+
});
171+
172+
return byteSize + byteTransactionsSize + byteTransactions;
173+
}
154174
}

src/model/transaction/LockFundsTransaction.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@ export class LockFundsTransaction extends Transaction {
101101
}
102102
}
103103

104+
/**
105+
* @override Transaction.size()
106+
* @description get the byte size of a LockFundsTransaction
107+
* @returns {number}
108+
* @memberof LockFundsTransaction
109+
*/
110+
public get size(): number {
111+
const byteSize = super.size;
112+
113+
// set static byte size fields
114+
const byteMosaicId = 8;
115+
const byteAmount = 8;
116+
const byteDuration = 8;
117+
const byteHash = 32;
118+
119+
return byteSize + byteMosaicId + byteAmount + byteDuration + byteHash;
120+
}
121+
104122
/**
105123
* @internal
106124
* @return {VerifiableTransaction}

src/model/transaction/ModifyAccountPropertyAddressTransaction.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,27 @@ export class ModifyAccountPropertyAddressTransaction extends Transaction {
7474
super(TransactionType.MODIFY_ACCOUNT_PROPERTY_ADDRESS, networkType, version, deadline, maxFee, signature, signer, transactionInfo);
7575
}
7676

77+
/**
78+
* @override Transaction.size()
79+
* @description get the byte size of a ModifyAccountPropertyAddressTransaction
80+
* @returns {number}
81+
* @memberof ModifyAccountPropertyAddressTransaction
82+
*/
83+
public get size(): number {
84+
const byteSize = super.size;
85+
86+
// set static byte size fields
87+
const bytePropertyType = 1;
88+
const byteModificationCount = 1;
89+
90+
// each modification contains :
91+
// - 1 byte for modificationType
92+
// - 25 bytes for the modification value (address)
93+
const byteModifications = 26 * this.modifications.length;
94+
95+
return byteSize + bytePropertyType + byteModificationCount + byteModifications;
96+
}
97+
7798
/**
7899
* @internal
79100
* @returns {VerifiableTransaction}

src/model/transaction/ModifyAccountPropertyEntityTypeTransaction.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,27 @@ export class ModifyAccountPropertyEntityTypeTransaction extends Transaction {
7575
super(TransactionType.MODIFY_ACCOUNT_PROPERTY_ENTITY_TYPE, networkType, version, deadline, maxFee, signature, signer, transactionInfo);
7676
}
7777

78+
/**
79+
* @override Transaction.size()
80+
* @description get the byte size of a ModifyAccountPropertyEntityTypeTransaction
81+
* @returns {number}
82+
* @memberof ModifyAccountPropertyEntityTypeTransaction
83+
*/
84+
public get size(): number {
85+
const byteSize = super.size;
86+
87+
// set static byte size fields
88+
const bytePropertyType = 1;
89+
const byteModificationCount = 1;
90+
91+
// each modification contains :
92+
// - 1 byte for modificationType
93+
// - 2 bytes for the modification value (transaction type)
94+
const byteModifications = 3 * this.modifications.length;
95+
96+
return byteSize + bytePropertyType + byteModificationCount + byteModifications;
97+
}
98+
7899
/**
79100
* @internal
80101
* @returns {VerifiableTransaction}

src/model/transaction/ModifyAccountPropertyMosaicTransaction.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,27 @@ export class ModifyAccountPropertyMosaicTransaction extends Transaction {
7474
super(TransactionType.MODIFY_ACCOUNT_PROPERTY_MOSAIC, networkType, version, deadline, maxFee, signature, signer, transactionInfo);
7575
}
7676

77+
/**
78+
* @override Transaction.size()
79+
* @description get the byte size of a ModifyAccountPropertyMosaicTransaction
80+
* @returns {number}
81+
* @memberof ModifyAccountPropertyMosaicTransaction
82+
*/
83+
public get size(): number {
84+
const byteSize = super.size;
85+
86+
// set static byte size fields
87+
const bytePropertyType = 1;
88+
const byteModificationCount = 1;
89+
90+
// each modification contains :
91+
// - 1 byte for modificationType
92+
// - 8 bytes for the modification value (mosaicId)
93+
const byteModifications = 9 * this.modifications.length;
94+
95+
return byteSize + bytePropertyType + byteModificationCount + byteModifications;
96+
}
97+
7798
/**
7899
* @internal
79100
* @returns {VerifiableTransaction}

src/model/transaction/ModifyMultisigAccountTransaction.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@ export class ModifyMultisigAccountTransaction extends Transaction {
9494
super(TransactionType.MODIFY_MULTISIG_ACCOUNT, networkType, version, deadline, maxFee, signature, signer, transactionInfo);
9595
}
9696

97+
/**
98+
* @override Transaction.size()
99+
* @description get the byte size of a ModifyMultisigAccountTransaction
100+
* @returns {number}
101+
* @memberof ModifyMultisigAccountTransaction
102+
*/
103+
public get size(): number {
104+
const byteSize = super.size;
105+
106+
// set static byte size fields
107+
const byteRemovalDelta = 1;
108+
const byteApprovalDelta = 1;
109+
const byteNumModifications = 1;
110+
111+
// each modification contains :
112+
// - 1 byte for modificationType
113+
// - 32 bytes for cosignatoryPublicKey
114+
const byteModifications = 33 * this.modifications.length
115+
116+
return byteSize + byteRemovalDelta + byteApprovalDelta + byteNumModifications + byteModifications;
117+
}
118+
97119
/**
98120
* @internal
99121
* @returns {VerifiableTransaction}

src/model/transaction/MosaicAliasTransaction.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,23 @@ export class MosaicAliasTransaction extends Transaction {
9393
super(TransactionType.MOSAIC_ALIAS, networkType, version, deadline, maxFee, signature, signer, transactionInfo);
9494
}
9595

96+
/**
97+
* @override Transaction.size()
98+
* @description get the byte size of a MosaicAliasTransaction
99+
* @returns {number}
100+
* @memberof MosaicAliasTransaction
101+
*/
102+
public get size(): number {
103+
const byteSize = super.size;
104+
105+
// set static byte size fields
106+
const byteType = 1;
107+
const byteNamespaceId = 8;
108+
const byteMosaicId = 8;
109+
110+
return byteSize + byteType + byteNamespaceId + byteMosaicId;
111+
}
112+
96113
/**
97114
* @internal
98115
* @returns {VerifiableTransaction}

0 commit comments

Comments
 (0)