Skip to content

Commit 40c9bef

Browse files
committed
Added: maxFee factory method to be able to use feeMultiplier
Optimised: Transaction.resloveAlias with object assign Added: unit tests for Transaction.resloveAlias
1 parent 679de2f commit 40c9bef

38 files changed

+827
-163
lines changed

src/model/transaction/AccountAddressRestrictionTransaction.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,23 @@ export class AccountAddressRestrictionTransaction extends Transaction {
199199
*/
200200
resolveAliases(statement: Statement, aggregateTransactionIndex: number = 0): AccountAddressRestrictionTransaction {
201201
const transactionInfo = this.checkTransactionHeightAndIndex();
202-
return new AccountAddressRestrictionTransaction(
203-
this.networkType,
204-
this.version,
205-
this.deadline,
206-
this.maxFee,
207-
this.restrictionFlags,
208-
this.restrictionAdditions.map((addition) => statement.resolveAddress(addition, transactionInfo.height.toString(),
209-
transactionInfo.index, aggregateTransactionIndex)),
210-
this.restrictionDeletions.map((deletion) => statement.resolveAddress(deletion, transactionInfo.height.toString(),
211-
transactionInfo.index, aggregateTransactionIndex)),
212-
this.signature,
213-
this.signer,
214-
this.transactionInfo,
215-
);
202+
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this,
203+
{
204+
restrictionAdditions:
205+
this.restrictionAdditions.map((addition) => statement.resolveAddress(addition, transactionInfo.height.toString(),
206+
transactionInfo.index, aggregateTransactionIndex)),
207+
restrictionDeletions:
208+
this.restrictionDeletions.map((deletion) => statement.resolveAddress(deletion, transactionInfo.height.toString(),
209+
transactionInfo.index, aggregateTransactionIndex)),
210+
});
211+
}
212+
213+
/**
214+
* Set transaction maxFee using fee multiplier
215+
* @param feeMultiplier The fee multiplier
216+
* @returns {AccountAddressRestrictionTransaction}
217+
*/
218+
public setMaxFee(multiplier: number): AccountAddressRestrictionTransaction {
219+
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {maxFee: UInt64.fromUint(this.size * multiplier)});
216220
}
217221
}

src/model/transaction/AccountLinkTransaction.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,13 @@ export class AccountLinkTransaction extends Transaction {
171171
resolveAliases(): AccountLinkTransaction {
172172
return this;
173173
}
174+
175+
/**
176+
* Set transaction maxFee using fee multiplier
177+
* @param feeMultiplier The fee multiplier
178+
* @returns {AccountLinkTransaction}
179+
*/
180+
public setMaxFee(multiplier: number): AccountLinkTransaction {
181+
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {maxFee: UInt64.fromUint(this.size * multiplier)});
182+
}
174183
}

src/model/transaction/AccountMetadataTransaction.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,13 @@ export class AccountMetadataTransaction extends Transaction {
201201
resolveAliases(): AccountMetadataTransaction {
202202
return this;
203203
}
204+
205+
/**
206+
* Set transaction maxFee using fee multiplier
207+
* @param feeMultiplier The fee multiplier
208+
* @returns {AccountMetadataTransaction}
209+
*/
210+
public setMaxFee(multiplier: number): AccountMetadataTransaction {
211+
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {maxFee: UInt64.fromUint(this.size * multiplier)});
212+
}
204213
}

src/model/transaction/AccountMosaicRestrictionTransaction.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -199,19 +199,23 @@ export class AccountMosaicRestrictionTransaction extends Transaction {
199199
*/
200200
resolveAliases(statement: Statement, aggregateTransactionIndex: number = 0): AccountMosaicRestrictionTransaction {
201201
const transactionInfo = this.checkTransactionHeightAndIndex();
202-
return new AccountMosaicRestrictionTransaction(
203-
this.networkType,
204-
this.version,
205-
this.deadline,
206-
this.maxFee,
207-
this.restrictionFlags,
208-
this.restrictionAdditions.map((addition) => statement.resolveMosaicId(addition, transactionInfo.height.toString(),
209-
transactionInfo.index, aggregateTransactionIndex)),
210-
this.restrictionDeletions.map((deletion) => statement.resolveMosaicId(deletion, transactionInfo.height.toString(),
211-
transactionInfo.index, aggregateTransactionIndex)),
212-
this.signature,
213-
this.signer,
214-
this.transactionInfo,
215-
);
202+
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this,
203+
{
204+
restrictionAdditions:
205+
this.restrictionAdditions.map((addition) => statement.resolveMosaicId(addition, transactionInfo.height.toString(),
206+
transactionInfo.index, aggregateTransactionIndex)),
207+
restrictionDeletions:
208+
this.restrictionDeletions.map((deletion) => statement.resolveMosaicId(deletion, transactionInfo.height.toString(),
209+
transactionInfo.index, aggregateTransactionIndex)),
210+
});
211+
}
212+
213+
/**
214+
* Set transaction maxFee using fee multiplier
215+
* @param feeMultiplier The fee multiplier
216+
* @returns {AccountMosaicRestrictionTransaction}
217+
*/
218+
public setMaxFee(multiplier: number): AccountMosaicRestrictionTransaction {
219+
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {maxFee: UInt64.fromUint(this.size * multiplier)});
216220
}
217221
}

src/model/transaction/AccountOperationRestrictionTransaction.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,13 @@ export class AccountOperationRestrictionTransaction extends Transaction {
182182
resolveAliases(): AccountOperationRestrictionTransaction {
183183
return this;
184184
}
185+
186+
/**
187+
* Set transaction maxFee using fee multiplier
188+
* @param feeMultiplier The fee multiplier
189+
* @returns {AccountOperationRestrictionTransaction}
190+
*/
191+
public setMaxFee(multiplier: number): AccountOperationRestrictionTransaction {
192+
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {maxFee: UInt64.fromUint(this.size * multiplier)});
193+
}
185194
}

src/model/transaction/AddressAliasTransaction.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,13 @@ export class AddressAliasTransaction extends Transaction {
194194
resolveAliases(): AddressAliasTransaction {
195195
return this;
196196
}
197+
198+
/**
199+
* Set transaction maxFee using fee multiplier
200+
* @param feeMultiplier The fee multiplier
201+
* @returns {AddressAliasTransaction}
202+
*/
203+
public setMaxFee(multiplier: number): AddressAliasTransaction {
204+
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {maxFee: UInt64.fromUint(this.size * multiplier)});
205+
}
197206
}

src/model/transaction/AggregateTransaction.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -407,18 +407,17 @@ export class AggregateTransaction extends Transaction {
407407
*/
408408
resolveAliases(statement: Statement): AggregateTransaction {
409409
const transactionInfo = this.checkTransactionHeightAndIndex();
410-
return new AggregateTransaction(
411-
this.networkType,
412-
this.type,
413-
this.version,
414-
this.deadline,
415-
this.maxFee,
416-
this.innerTransactions.map((tx) => tx.resolveAliases(statement, transactionInfo.index))
417-
.sort((a, b) => a.transactionInfo!.index - b.transactionInfo!.index),
418-
this.cosignatures,
419-
this.signature,
420-
this.signer,
421-
this.transactionInfo,
422-
);
410+
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this,
411+
{innerTransactions: this.innerTransactions.map((tx) => tx.resolveAliases(statement, transactionInfo.index))
412+
.sort((a, b) => a.transactionInfo!.index - b.transactionInfo!.index)});
413+
}
414+
415+
/**
416+
* Set transaction maxFee using fee multiplier
417+
* @param feeMultiplier The fee multiplier
418+
* @returns {AggregateTransaction}
419+
*/
420+
public setMaxFee(multiplier: number): AggregateTransaction {
421+
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {maxFee: UInt64.fromUint(this.size * multiplier)});
423422
}
424423
}

src/model/transaction/LockFundsTransaction.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,18 @@ export class LockFundsTransaction extends Transaction {
212212
*/
213213
resolveAliases(statement: Statement, aggregateTransactionIndex: number = 0): LockFundsTransaction {
214214
const transactionInfo = this.checkTransactionHeightAndIndex();
215-
return new LockFundsTransaction(
216-
this.networkType,
217-
this.version,
218-
this.deadline,
219-
this.maxFee,
220-
statement.resolveMosaic(this.mosaic, transactionInfo.height.toString(),
221-
transactionInfo.index, aggregateTransactionIndex),
222-
this.duration,
223-
this.signedTransaction,
224-
this.signature,
225-
this.signer,
226-
this.transactionInfo,
227-
);
215+
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this,
216+
{
217+
mosaic: statement.resolveMosaic(this.mosaic, transactionInfo.height.toString(),
218+
transactionInfo.index, aggregateTransactionIndex)});
219+
}
220+
221+
/**
222+
* Set transaction maxFee using fee multiplier
223+
* @param feeMultiplier The fee multiplier
224+
* @returns {LockFundsTransaction}
225+
*/
226+
public setMaxFee(multiplier: number): LockFundsTransaction {
227+
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {maxFee: UInt64.fromUint(this.size * multiplier)});
228228
}
229229
}

src/model/transaction/MosaicAddressRestrictionTransaction.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -243,21 +243,20 @@ export class MosaicAddressRestrictionTransaction extends Transaction {
243243
*/
244244
resolveAliases(statement: Statement, aggregateTransactionIndex: number = 0): MosaicAddressRestrictionTransaction {
245245
const transactionInfo = this.checkTransactionHeightAndIndex();
246-
return new MosaicAddressRestrictionTransaction(
247-
this.networkType,
248-
this.version,
249-
this.deadline,
250-
this.maxFee,
251-
statement.resolveMosaicId(this.mosaicId, transactionInfo.height.toString(),
252-
transactionInfo.index, aggregateTransactionIndex),
253-
this.restrictionKey,
254-
statement.resolveAddress(this.targetAddress,
255-
transactionInfo.height.toString(), transactionInfo.index, aggregateTransactionIndex),
256-
this.previousRestrictionValue,
257-
this.newRestrictionValue,
258-
this.signature,
259-
this.signer,
260-
this.transactionInfo,
261-
);
246+
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this,
247+
{
248+
mosaicId: statement.resolveMosaicId(this.mosaicId, transactionInfo.height.toString(),
249+
transactionInfo.index, aggregateTransactionIndex),
250+
targetAddress: statement.resolveAddress(this.targetAddress,
251+
transactionInfo.height.toString(), transactionInfo.index, aggregateTransactionIndex)});
252+
}
253+
254+
/**
255+
* Set transaction maxFee using fee multiplier
256+
* @param feeMultiplier The fee multiplier
257+
* @returns {MosaicAddressRestrictionTransaction}
258+
*/
259+
public setMaxFee(multiplier: number): MosaicAddressRestrictionTransaction {
260+
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {maxFee: UInt64.fromUint(this.size * multiplier)});
262261
}
263262
}

src/model/transaction/MosaicAliasTransaction.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,13 @@ export class MosaicAliasTransaction extends Transaction {
186186
resolveAliases(): MosaicAliasTransaction {
187187
return this;
188188
}
189+
190+
/**
191+
* Set transaction maxFee using fee multiplier
192+
* @param feeMultiplier The fee multiplier
193+
* @returns {MosaicAliasTransaction}
194+
*/
195+
public setMaxFee(multiplier: number): MosaicAliasTransaction {
196+
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {maxFee: UInt64.fromUint(this.size * multiplier)});
197+
}
189198
}

0 commit comments

Comments
 (0)