Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/core/utils/DtoMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,15 @@ export class DtoMapping {
}
})));
}

/**
* Creates a copy of the first object adding the attributes of the second object.
* @param object the object to be cloned
* @param attributes the extra attributes to be added to the object.
* @returns a copy of the first object with the new attributes added.
*/
public static assign<T>(object: T, attributes: any): T {
return Object.assign({__proto__: Object.getPrototypeOf(object)}, object, attributes);
}

}
17 changes: 9 additions & 8 deletions src/model/transaction/AccountAddressRestrictionTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { Convert } from '../../core/format';
import { DtoMapping } from '../../core/utils/DtoMapping';
import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping';
import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder';
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
Expand Down Expand Up @@ -199,13 +200,13 @@ export class AccountAddressRestrictionTransaction extends Transaction {
*/
resolveAliases(statement: Statement, aggregateTransactionIndex: number = 0): AccountAddressRestrictionTransaction {
const transactionInfo = this.checkTransactionHeightAndIndex();
return {...Object.getPrototypeOf(this),
restrictionAdditions:
this.restrictionAdditions.map((addition) => statement.resolveAddress(addition, transactionInfo.height.toString(),
transactionInfo.index, aggregateTransactionIndex)),
restrictionDeletions:
this.restrictionDeletions.map((deletion) => statement.resolveAddress(deletion, transactionInfo.height.toString(),
transactionInfo.index, aggregateTransactionIndex)),
};
return DtoMapping.assign(this, {
restrictionAdditions:
this.restrictionAdditions.map((addition) => statement.resolveAddress(addition, transactionInfo.height.toString(),
transactionInfo.index, aggregateTransactionIndex)),
restrictionDeletions:
this.restrictionDeletions.map((deletion) => statement.resolveAddress(deletion, transactionInfo.height.toString(),
transactionInfo.index, aggregateTransactionIndex)),
});
}
}
5 changes: 3 additions & 2 deletions src/model/transaction/AccountMosaicRestrictionTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { Convert } from '../../core/format';
import { DtoMapping } from '../../core/utils/DtoMapping';
import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping';
import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder';
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
Expand Down Expand Up @@ -199,13 +200,13 @@ export class AccountMosaicRestrictionTransaction extends Transaction {
*/
resolveAliases(statement: Statement, aggregateTransactionIndex: number = 0): AccountMosaicRestrictionTransaction {
const transactionInfo = this.checkTransactionHeightAndIndex();
return {...Object.getPrototypeOf(this),
return DtoMapping.assign(this, {
restrictionAdditions:
this.restrictionAdditions.map((addition) => statement.resolveMosaicId(addition, transactionInfo.height.toString(),
transactionInfo.index, aggregateTransactionIndex)),
restrictionDeletions:
this.restrictionDeletions.map((deletion) => statement.resolveMosaicId(deletion, transactionInfo.height.toString(),
transactionInfo.index, aggregateTransactionIndex)),
};
});
}
}
9 changes: 5 additions & 4 deletions src/model/transaction/AggregateTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import {KeyPair, MerkleHashBuilder, SHA3Hasher, SignSchema} from '../../core/crypto';
import {Convert} from '../../core/format';
import { DtoMapping } from '../../core/utils/DtoMapping';
import {AggregateBondedTransactionBuilder} from '../../infrastructure/catbuffer/AggregateBondedTransactionBuilder';
import {AggregateCompleteTransactionBuilder} from '../../infrastructure/catbuffer/AggregateCompleteTransactionBuilder';
import {AmountDto} from '../../infrastructure/catbuffer/AmountDto';
Expand Down Expand Up @@ -193,7 +194,7 @@ export class AggregateTransaction extends Transaction {
*/
public addTransactions(transactions: InnerTransaction[]): AggregateTransaction {
const innerTransactions = this.innerTransactions.concat(transactions);
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {innerTransactions});
return DtoMapping.assign(this, {innerTransactions});
}

/**
Expand All @@ -204,7 +205,7 @@ export class AggregateTransaction extends Transaction {
*/
public addCosignatures(cosigs: AggregateTransactionCosignature[]): AggregateTransaction {
const cosignatures = this.cosignatures.concat(cosigs);
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {cosignatures});
return DtoMapping.assign(this, {cosignatures});
}

/**
Expand Down Expand Up @@ -407,8 +408,8 @@ export class AggregateTransaction extends Transaction {
*/
resolveAliases(statement: Statement): AggregateTransaction {
const transactionInfo = this.checkTransactionHeightAndIndex();
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this,
{innerTransactions: this.innerTransactions.map((tx) => tx.resolveAliases(statement, transactionInfo.index))
return DtoMapping.assign(this,
{innerTransactions: this.innerTransactions.map((tx) => tx.resolveAliases(statement, transactionInfo.index))
.sort((a, b) => a.transactionInfo!.index - b.transactionInfo!.index)});
}
}
5 changes: 3 additions & 2 deletions src/model/transaction/LockFundsTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { Convert } from '../../core/format';
import { DtoMapping } from '../../core/utils/DtoMapping';
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto';
import { EmbeddedHashLockTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedHashLockTransactionBuilder';
Expand Down Expand Up @@ -211,8 +212,8 @@ export class LockFundsTransaction extends Transaction {
*/
resolveAliases(statement: Statement, aggregateTransactionIndex: number = 0): LockFundsTransaction {
const transactionInfo = this.checkTransactionHeightAndIndex();
return {...Object.getPrototypeOf(this),
return DtoMapping.assign(this, {
mosaic: statement.resolveMosaic(this.mosaic, transactionInfo.height.toString(),
transactionInfo.index, aggregateTransactionIndex)};
transactionInfo.index, aggregateTransactionIndex)});
}
}
5 changes: 3 additions & 2 deletions src/model/transaction/MosaicAddressRestrictionTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { Convert } from '../../core/format';
import { DtoMapping } from '../../core/utils/DtoMapping';
import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping';
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
import {
Expand Down Expand Up @@ -243,10 +244,10 @@ export class MosaicAddressRestrictionTransaction extends Transaction {
*/
resolveAliases(statement: Statement, aggregateTransactionIndex: number = 0): MosaicAddressRestrictionTransaction {
const transactionInfo = this.checkTransactionHeightAndIndex();
return {...Object.getPrototypeOf(this),
return DtoMapping.assign(this, {
mosaicId: statement.resolveMosaicId(this.mosaicId, transactionInfo.height.toString(),
transactionInfo.index, aggregateTransactionIndex),
targetAddress: statement.resolveAddress(this.targetAddress,
transactionInfo.height.toString(), transactionInfo.index, aggregateTransactionIndex)};
transactionInfo.height.toString(), transactionInfo.index, aggregateTransactionIndex)});
}
}
5 changes: 3 additions & 2 deletions src/model/transaction/MosaicGlobalRestrictionTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { Convert } from '../../core/format';
import { DtoMapping } from '../../core/utils/DtoMapping';
import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping';
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
import {
Expand Down Expand Up @@ -253,10 +254,10 @@ export class MosaicGlobalRestrictionTransaction extends Transaction {
*/
resolveAliases(statement: Statement, aggregateTransactionIndex: number = 0): MosaicGlobalRestrictionTransaction {
const transactionInfo = this.checkTransactionHeightAndIndex();
return {...Object.getPrototypeOf(this),
return DtoMapping.assign(this, {
mosaicId: statement.resolveMosaicId(this.mosaicId, transactionInfo.height.toString(),
transactionInfo.index, aggregateTransactionIndex),
referenceMosaicId: statement.resolveMosaicId(this.referenceMosaicId, transactionInfo.height.toString(),
transactionInfo.index, aggregateTransactionIndex)};
transactionInfo.index, aggregateTransactionIndex)});
}
}
5 changes: 3 additions & 2 deletions src/model/transaction/MosaicMetadataTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { Convert } from '../../core/format';
import { DtoMapping } from '../../core/utils/DtoMapping';
import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping';
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
import { EmbeddedMosaicMetadataTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicMetadataTransactionBuilder';
Expand Down Expand Up @@ -219,8 +220,8 @@ export class MosaicMetadataTransaction extends Transaction {
*/
resolveAliases(statement: Statement, aggregateTransactionIndex: number = 0): MosaicMetadataTransaction {
const transactionInfo = this.checkTransactionHeightAndIndex();
return {...Object.getPrototypeOf(this),
return DtoMapping.assign(this, {
targetMosaicId: statement.resolveMosaicId(this.targetMosaicId, transactionInfo.height.toString(),
transactionInfo.index, aggregateTransactionIndex)};
transactionInfo.index, aggregateTransactionIndex)});
}
}
5 changes: 3 additions & 2 deletions src/model/transaction/MosaicSupplyChangeTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { Convert } from '../../core/format';
import { DtoMapping } from '../../core/utils/DtoMapping';
import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping';
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
import { EmbeddedMosaicSupplyChangeTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedMosaicSupplyChangeTransactionBuilder';
Expand Down Expand Up @@ -193,8 +194,8 @@ export class MosaicSupplyChangeTransaction extends Transaction {
*/
resolveAliases(statement: Statement, aggregateTransactionIndex: number = 0): MosaicSupplyChangeTransaction {
const transactionInfo = this.checkTransactionHeightAndIndex();
return {...Object.getPrototypeOf(this),
return DtoMapping.assign(this, {
mosaicId: statement.resolveMosaicId(this.mosaicId, transactionInfo.height.toString(),
transactionInfo.index, aggregateTransactionIndex)};
transactionInfo.index, aggregateTransactionIndex)});
}
}
5 changes: 3 additions & 2 deletions src/model/transaction/SecretLockTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
import { Convert, Convert as convert } from '../../core/format';
import { DtoMapping } from '../../core/utils/DtoMapping';
import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping';
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
import { BlockDurationDto } from '../../infrastructure/catbuffer/BlockDurationDto';
Expand Down Expand Up @@ -240,10 +241,10 @@ export class SecretLockTransaction extends Transaction {
*/
resolveAliases(statement: Statement, aggregateTransactionIndex: number = 0): SecretLockTransaction {
const transactionInfo = this.checkTransactionHeightAndIndex();
return {...Object.getPrototypeOf(this),
return DtoMapping.assign(this, {
recipientAddress: statement.resolveAddress(this.recipientAddress,
transactionInfo.height.toString(), transactionInfo.index, aggregateTransactionIndex),
mosaic: statement.resolveMosaic(this.mosaic, transactionInfo.height.toString(),
transactionInfo.index, aggregateTransactionIndex)};
transactionInfo.index, aggregateTransactionIndex)});
}
}
5 changes: 3 additions & 2 deletions src/model/transaction/SecretProofTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { Convert, Convert as convert } from '../../core/format';
import { DtoMapping } from '../../core/utils/DtoMapping';
import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping';
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
import { EmbeddedSecretProofTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedSecretProofTransactionBuilder';
Expand Down Expand Up @@ -217,8 +218,8 @@ export class SecretProofTransaction extends Transaction {
*/
resolveAliases(statement: Statement, aggregateTransactionIndex: number = 0): SecretProofTransaction {
const transactionInfo = this.checkTransactionHeightAndIndex();
return {...Object.getPrototypeOf(this),
return DtoMapping.assign(this, {
recipientAddress: statement.resolveAddress(this.recipientAddress,
transactionInfo.height.toString(), transactionInfo.index, aggregateTransactionIndex)};
transactionInfo.height.toString(), transactionInfo.index, aggregateTransactionIndex)});
}
}
7 changes: 4 additions & 3 deletions src/model/transaction/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import { KeyPair, SHA3Hasher, SignSchema } from '../../core/crypto';
import { Convert } from '../../core/format';
import { DtoMapping } from '../../core/utils/DtoMapping';
import { SerializeTransactionToJSON } from '../../infrastructure/transaction/SerializeTransactionToJSON';
import { Account } from '../account/Account';
import { PublicAccount } from '../account/PublicAccount';
Expand Down Expand Up @@ -200,7 +201,7 @@ export abstract class Transaction {
* @returns {TransferTransaction}
*/
public setMaxFee(feeMultiplier: number): Transaction {
return {...Object.getPrototypeOf(this), maxFee: UInt64.fromUint(this.size * feeMultiplier)};
return DtoMapping.assign(this, {maxFee: UInt64.fromUint(this.size * feeMultiplier)});
}

/**
Expand Down Expand Up @@ -277,7 +278,7 @@ export abstract class Transaction {
if (this.type === TransactionType.AGGREGATE_BONDED || this.type === TransactionType.AGGREGATE_COMPLETE) {
throw new Error('Inner transaction cannot be an aggregated transaction.');
}
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {signer});
return DtoMapping.assign(this, {signer});
}

/**
Expand Down Expand Up @@ -345,7 +346,7 @@ export abstract class Transaction {
*/
public reapplyGiven(deadline: Deadline = Deadline.create()): Transaction {
if (this.isUnannounced()) {
return Object.assign({__proto__: Object.getPrototypeOf(this)}, this, {deadline});
return DtoMapping.assign(this, {deadline});
}
throw new Error('an Announced transaction can\'t be modified');
}
Expand Down
9 changes: 5 additions & 4 deletions src/model/transaction/TransferTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {Transaction} from './Transaction';
import {TransactionInfo} from './TransactionInfo';
import {TransactionType} from './TransactionType';
import {TransactionVersion} from './TransactionVersion';
import { DtoMapping } from '../../core/utils/DtoMapping';

/**
* Transfer transactions contain data about transfers of mosaics and message to another account.
Expand Down Expand Up @@ -282,9 +283,9 @@ export class TransferTransaction extends Transaction {
*/
public resolveAliases(statement: Statement, aggregateTransactionIndex: number = 0): TransferTransaction {
const transactionInfo = this.checkTransactionHeightAndIndex();
return {...Object.getPrototypeOf(this), recipientAddress: statement.resolveAddress(this.recipientAddress,
transactionInfo.height.toString(), transactionInfo.index, aggregateTransactionIndex),
mosaics: this.mosaics.map((mosaic) => statement.resolveMosaic(mosaic, transactionInfo.height.toString(),
transactionInfo.index, aggregateTransactionIndex))};
return DtoMapping.assign(this, {recipientAddress: statement.resolveAddress(this.recipientAddress, transactionInfo.height.toString(),
transactionInfo.index, aggregateTransactionIndex),
mosaics: this.mosaics.map((mosaic) => statement.resolveMosaic(mosaic, transactionInfo.height.toString(),
transactionInfo.index, aggregateTransactionIndex))});
}
}
Loading