From 8166ba9144c6dc71351b0d202719c28529294e30 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 15 Nov 2019 21:19:13 +0000 Subject: [PATCH 1/5] [#348, #319] Added getNetworkName --- src/infrastructure/NetworkHttp.ts | 23 +++++++++++++-- src/infrastructure/NetworkRepository.ts | 8 ++++++ .../transaction/SerializeTransactionToJSON.ts | 2 +- src/model/blockchain/NetworkName.ts | 28 +++++++++++++++++++ src/model/model.ts | 1 + src/model/mosaic/MosaicId.ts | 3 ++ test/core/utils/TransactionMapping.spec.ts | 1 + 7 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 src/model/blockchain/NetworkName.ts diff --git a/src/infrastructure/NetworkHttp.ts b/src/infrastructure/NetworkHttp.ts index 243f11236b..6d8bdd4f62 100644 --- a/src/infrastructure/NetworkHttp.ts +++ b/src/infrastructure/NetworkHttp.ts @@ -17,9 +17,12 @@ import { ClientResponse } from 'http'; import {from as observableFrom, Observable, throwError} from 'rxjs'; import {catchError, map} from 'rxjs/operators'; +import { NetworkName } from '../model/blockchain/NetworkName'; import {NetworkType} from '../model/blockchain/NetworkType'; import { NodeInfo } from '../model/node/NodeInfo'; +import { NetworkRoutesApi } from './api/apis'; import {Http} from './Http'; +import { NetworkTypeDTO } from './model/networkTypeDTO'; import {NetworkRepository} from './NetworkRepository'; import { NodeHttp } from './NodeHttp'; @@ -34,6 +37,7 @@ export class NetworkHttp extends Http implements NetworkRepository { * Nem2 Library account routes api */ private nodeHttp: NodeHttp; + private networkRouteApi: NetworkRoutesApi; /** * Constructor @@ -42,13 +46,14 @@ export class NetworkHttp extends Http implements NetworkRepository { constructor(url: string) { super(); this.nodeHttp = new NodeHttp(url); + this.networkRouteApi = new NetworkRoutesApi(url); } /** - * Get current network type. + * Get current network identifier. * - * @return network type enum. + * @return network identifier. */ public getNetworkType(): Observable { return observableFrom(this.nodeHttp.getNodeInfo()).pipe( @@ -58,4 +63,18 @@ export class NetworkHttp extends Http implements NetworkRepository { catchError((error) => throwError(this.errorHandling(error)))), ); } + + /** + * Get current network type name and description + * + * @return current network type name and description + */ + public getNetworkName(): Observable { + return observableFrom(this.networkRouteApi.getNetworkType()).pipe( + map((response: { response: ClientResponse; body: NetworkTypeDTO; }) => { + return new NetworkName(response.body.name, response.body.description); + }), + catchError((error) => throwError(this.errorHandling(error))), + ); + } } diff --git a/src/infrastructure/NetworkRepository.ts b/src/infrastructure/NetworkRepository.ts index 9e5b6dd5da..0dccbfca82 100644 --- a/src/infrastructure/NetworkRepository.ts +++ b/src/infrastructure/NetworkRepository.ts @@ -15,6 +15,7 @@ */ import {Observable} from 'rxjs'; +import { NetworkName } from '../model/blockchain/NetworkName'; import {NetworkType} from '../model/blockchain/NetworkType'; /** @@ -29,4 +30,11 @@ export interface NetworkRepository { * @return network type enum. */ getNetworkType(): Observable; + + /** + * Get current network type name and description + * + * @return current network type name and description + */ + getNetworkName(): Observable; } diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index 4dc5474b04..5bd5c31c3e 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -130,7 +130,7 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { case TransactionType.MOSAIC_DEFINITION: return { nonce: (transaction as MosaicDefinitionTransaction).nonce, - mosaicId: (transaction as MosaicDefinitionTransaction).mosaicId.toHex(), + id: (transaction as MosaicDefinitionTransaction).mosaicId.toHex(), flags: (transaction as MosaicDefinitionTransaction).flags.getValue(), divisibility: (transaction as MosaicDefinitionTransaction).divisibility, duration: (transaction as MosaicDefinitionTransaction).duration.toString(), diff --git a/src/model/blockchain/NetworkName.ts b/src/model/blockchain/NetworkName.ts new file mode 100644 index 0000000000..2a221813c9 --- /dev/null +++ b/src/model/blockchain/NetworkName.ts @@ -0,0 +1,28 @@ +/* + * 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. + */ + +/** + * The block merkle proof info + */ +export class NetworkName { + + /** + * @param name - Network name + * @param description - Network description + */ + constructor(public readonly name: string, public readonly description: string) { + } +} \ No newline at end of file diff --git a/src/model/model.ts b/src/model/model.ts index 1827164c23..02370bf73a 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -35,6 +35,7 @@ export * from './blockchain/BlockInfo'; export * from './blockchain/NetworkType'; export * from './blockchain/MerklePathItem'; export * from './blockchain/MerkleProofInfo'; +export * from './blockchain/NetworkName'; // Diagnostic export * from './diagnostic/ServerInfo'; diff --git a/src/model/mosaic/MosaicId.ts b/src/model/mosaic/MosaicId.ts index c16e12ef62..bb2019ddcf 100644 --- a/src/model/mosaic/MosaicId.ts +++ b/src/model/mosaic/MosaicId.ts @@ -50,6 +50,9 @@ export class MosaicId { * @param id */ constructor(id: string | number[]) { + if (id === undefined) { + throw new Error('MosaicId undefined'); + } if (id instanceof Array) { this.id = new Id(id); } else if (typeof id === 'string') { diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index ccdab1bf67..d3c9c4d9a7 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -837,6 +837,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => NetworkType.MIJIN_TEST, ); + console.log(mosaicDefinitionTransaction.toJSON()); const transaction = TransactionMapping.createFromDTO(mosaicDefinitionTransaction.toJSON()) as MosaicDefinitionTransaction; From 5f49cfc011554820d81ddc6243bd809924ced036 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 15 Nov 2019 21:21:01 +0000 Subject: [PATCH 2/5] Removed console log --- test/core/utils/TransactionMapping.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index d3c9c4d9a7..ccdab1bf67 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -837,7 +837,6 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => NetworkType.MIJIN_TEST, ); - console.log(mosaicDefinitionTransaction.toJSON()); const transaction = TransactionMapping.createFromDTO(mosaicDefinitionTransaction.toJSON()) as MosaicDefinitionTransaction; From 222be36fb5c2c476cf514b6f7e601db62da0d081 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 15 Nov 2019 21:30:37 +0000 Subject: [PATCH 3/5] fixed lint issue --- src/model/blockchain/NetworkName.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/model/blockchain/NetworkName.ts b/src/model/blockchain/NetworkName.ts index 2a221813c9..d68059ac5e 100644 --- a/src/model/blockchain/NetworkName.ts +++ b/src/model/blockchain/NetworkName.ts @@ -25,4 +25,4 @@ export class NetworkName { */ constructor(public readonly name: string, public readonly description: string) { } -} \ No newline at end of file +} From b1a8cb79ab14a4a3740695645a1034d4fa3d7547 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Sat, 16 Nov 2019 09:30:02 +0000 Subject: [PATCH 4/5] review feedback --- e2e/infrastructure/NetworkHttp.spec.ts | 11 +++++++++++ src/infrastructure/NetworkHttp.ts | 9 +++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/e2e/infrastructure/NetworkHttp.spec.ts b/e2e/infrastructure/NetworkHttp.spec.ts index 34d7a78f4d..c93481d652 100644 --- a/e2e/infrastructure/NetworkHttp.spec.ts +++ b/e2e/infrastructure/NetworkHttp.spec.ts @@ -40,4 +40,15 @@ describe('NetworkHttp', () => { }); }); }); + + describe('getNetworkName', () => { + it('should return network name and description', (done) => { + networkHttp.getNetworkName() + .subscribe((networkName) => { + expect(networkName.name.toLowerCase()).to.be.equal('mijintest'); + expect(networkName.description.toLowerCase()).to.be.equal('catapult development network'); + done(); + }); + }); + }); }); diff --git a/src/infrastructure/NetworkHttp.ts b/src/infrastructure/NetworkHttp.ts index 6d8bdd4f62..844e6613d2 100644 --- a/src/infrastructure/NetworkHttp.ts +++ b/src/infrastructure/NetworkHttp.ts @@ -57,9 +57,7 @@ export class NetworkHttp extends Http implements NetworkRepository { */ public getNetworkType(): Observable { return observableFrom(this.nodeHttp.getNodeInfo()).pipe( - map(((nodeInfo: NodeInfo) => { - return nodeInfo.networkIdentifier; - }), + map(((nodeInfo: NodeInfo) => nodeInfo.networkIdentifier), catchError((error) => throwError(this.errorHandling(error)))), ); } @@ -71,9 +69,8 @@ export class NetworkHttp extends Http implements NetworkRepository { */ public getNetworkName(): Observable { return observableFrom(this.networkRouteApi.getNetworkType()).pipe( - map((response: { response: ClientResponse; body: NetworkTypeDTO; }) => { - return new NetworkName(response.body.name, response.body.description); - }), + map((response: { response: ClientResponse; body: NetworkTypeDTO; }) => + new NetworkName(response.body.name, response.body.description)), catchError((error) => throwError(this.errorHandling(error))), ); } From b45654d9aef8ab1cecf5ddbdece87e01a90a5fe8 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Sat, 16 Nov 2019 11:29:41 +0000 Subject: [PATCH 5/5] RP feedback changes --- src/infrastructure/NetworkHttp.ts | 3 +- .../transaction/SerializeTransactionToJSON.ts | 196 ++++++++++-------- 2 files changed, 109 insertions(+), 90 deletions(-) diff --git a/src/infrastructure/NetworkHttp.ts b/src/infrastructure/NetworkHttp.ts index 844e6613d2..cc5a76e823 100644 --- a/src/infrastructure/NetworkHttp.ts +++ b/src/infrastructure/NetworkHttp.ts @@ -69,8 +69,7 @@ export class NetworkHttp extends Http implements NetworkRepository { */ public getNetworkName(): Observable { return observableFrom(this.networkRouteApi.getNetworkType()).pipe( - map((response: { response: ClientResponse; body: NetworkTypeDTO; }) => - new NetworkName(response.body.name, response.body.description)), + map((({body}) => new NetworkName(body.name, body.description))), catchError((error) => throwError(this.errorHandling(error))), ); } diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index 5bd5c31c3e..0eef5c55c6 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -47,108 +47,120 @@ import { TransferTransaction } from '../../model/transaction/TransferTransaction export const SerializeTransactionToJSON = (transaction: Transaction): any => { switch (transaction.type) { case TransactionType.LINK_ACCOUNT: + const accountLinkTx = transaction as AccountLinkTransaction; return { - remotePublicKey: (transaction as AccountLinkTransaction).remotePublicKey, - linkAction: (transaction as AccountLinkTransaction).linkAction, + remotePublicKey: accountLinkTx.remotePublicKey, + linkAction: accountLinkTx.linkAction, }; case TransactionType.ADDRESS_ALIAS: + const addressAliasTx = transaction as AddressAliasTransaction; return { - aliasAction: (transaction as AddressAliasTransaction).aliasAction, - namespaceId: (transaction as AddressAliasTransaction).namespaceId.toHex(), - address: (transaction as AddressAliasTransaction).address.toDTO(), + aliasAction: addressAliasTx.aliasAction, + namespaceId: addressAliasTx.namespaceId.toHex(), + address: addressAliasTx.address.toDTO(), }; case TransactionType.AGGREGATE_BONDED: case TransactionType.AGGREGATE_COMPLETE: + const aggregateTx = transaction as AggregateTransaction; return { - transactions: (transaction as AggregateTransaction).innerTransactions.map((innerTransaction) => { + transactions: aggregateTx.innerTransactions.map((innerTransaction) => { return innerTransaction.toJSON(); }), - cosignatures: (transaction as AggregateTransaction).cosignatures.map((cosignature) => { + cosignatures: aggregateTx.cosignatures.map((cosignature) => { return cosignature.toDTO(); }), }; case TransactionType.LOCK: + const LockFundTx = transaction as LockFundsTransaction; return { - mosaicId: (transaction as LockFundsTransaction).mosaic.id.id, - amount: (transaction as LockFundsTransaction).mosaic.amount.toString(), - duration: (transaction as LockFundsTransaction).duration.toString(), - hash: (transaction as LockFundsTransaction).hash, + mosaicId: LockFundTx.mosaic.id.id, + amount: LockFundTx.mosaic.amount.toString(), + duration: LockFundTx.duration.toString(), + hash: LockFundTx.hash, }; case TransactionType.ACCOUNT_RESTRICTION_ADDRESS: + const accountAddressRestrictionTx = transaction as AccountAddressRestrictionTransaction; return { - restrictionFlags: (transaction as AccountAddressRestrictionTransaction).restrictionFlags, - restrictionAdditionsCount: (transaction as AccountAddressRestrictionTransaction).restrictionAdditions.length, - restrictionDeletionsCount: (transaction as AccountAddressRestrictionTransaction).restrictionDeletions.length, - restrictionAdditions: (transaction as AccountAddressRestrictionTransaction).restrictionAdditions.map((addition) => { + restrictionFlags: accountAddressRestrictionTx.restrictionFlags, + restrictionAdditionsCount: accountAddressRestrictionTx.restrictionAdditions.length, + restrictionDeletionsCount: accountAddressRestrictionTx.restrictionDeletions.length, + restrictionAdditions: accountAddressRestrictionTx.restrictionAdditions.map((addition) => { return addition.toDTO(); }), - restrictionDeletions: (transaction as AccountAddressRestrictionTransaction).restrictionDeletions.map((deletion) => { + restrictionDeletions: accountAddressRestrictionTx.restrictionDeletions.map((deletion) => { return deletion.toDTO(); }), }; case TransactionType.ACCOUNT_RESTRICTION_OPERATION: + const accountOperationRestrictionTx = transaction as AccountOperationRestrictionTransaction; return { - restrictionFlags: (transaction as AccountOperationRestrictionTransaction).restrictionFlags, - restrictionAdditionsCount: (transaction as AccountAddressRestrictionTransaction).restrictionAdditions.length, - restrictionDeletionsCount: (transaction as AccountAddressRestrictionTransaction).restrictionDeletions.length, - restrictionAdditions: (transaction as AccountOperationRestrictionTransaction).restrictionAdditions.map((addition) => { + restrictionFlags: accountOperationRestrictionTx.restrictionFlags, + restrictionAdditionsCount: accountOperationRestrictionTx.restrictionAdditions.length, + restrictionDeletionsCount: accountOperationRestrictionTx.restrictionDeletions.length, + restrictionAdditions: accountOperationRestrictionTx.restrictionAdditions.map((addition) => { return addition; }), - restrictionDeletions: (transaction as AccountOperationRestrictionTransaction).restrictionDeletions.map((deletion) => { + restrictionDeletions: accountOperationRestrictionTx.restrictionDeletions.map((deletion) => { return deletion; }), }; case TransactionType.ACCOUNT_RESTRICTION_MOSAIC: + const accountMosaicRestrictionTx = transaction as AccountMosaicRestrictionTransaction; return { - restrictionFlags: (transaction as AccountMosaicRestrictionTransaction).restrictionFlags, - restrictionAdditionsCount: (transaction as AccountAddressRestrictionTransaction).restrictionAdditions.length, - restrictionDeletionsCount: (transaction as AccountAddressRestrictionTransaction).restrictionDeletions.length, - restrictionAdditions: (transaction as AccountMosaicRestrictionTransaction).restrictionAdditions.map((addition) => { + restrictionFlags: accountMosaicRestrictionTx.restrictionFlags, + restrictionAdditionsCount: accountMosaicRestrictionTx.restrictionAdditions.length, + restrictionDeletionsCount: accountMosaicRestrictionTx.restrictionDeletions.length, + restrictionAdditions: accountMosaicRestrictionTx.restrictionAdditions.map((addition) => { return addition.toHex(); }), - restrictionDeletions: (transaction as AccountMosaicRestrictionTransaction).restrictionDeletions.map((deletion) => { + restrictionDeletions: accountMosaicRestrictionTx.restrictionDeletions.map((deletion) => { return deletion.toHex(); }), }; case TransactionType.MODIFY_MULTISIG_ACCOUNT: + const multisigTx = transaction as MultisigAccountModificationTransaction; return { - minApprovalDelta: (transaction as MultisigAccountModificationTransaction).minApprovalDelta, - minRemovalDelta: (transaction as MultisigAccountModificationTransaction).minRemovalDelta, - publicKeyAdditions: (transaction as MultisigAccountModificationTransaction).publicKeyAdditions.map((addition) => { + minApprovalDelta: multisigTx.minApprovalDelta, + minRemovalDelta: multisigTx.minRemovalDelta, + publicKeyAdditions: multisigTx.publicKeyAdditions.map((addition) => { return addition.publicKey; }), - publicKeyDeletions: (transaction as MultisigAccountModificationTransaction).publicKeyDeletions.map((deletion) => { + publicKeyDeletions: multisigTx.publicKeyDeletions.map((deletion) => { return deletion.publicKey; }), }; case TransactionType.MOSAIC_ALIAS: + const mosaicAliasTx = transaction as MosaicAliasTransaction; return { - aliasAction: (transaction as MosaicAliasTransaction).aliasAction, - namespaceId: (transaction as MosaicAliasTransaction).namespaceId.toHex(), - mosaicId: (transaction as MosaicAliasTransaction).mosaicId.toHex(), + aliasAction: mosaicAliasTx.aliasAction, + namespaceId: mosaicAliasTx.namespaceId.toHex(), + mosaicId: mosaicAliasTx.mosaicId.toHex(), }; case TransactionType.MOSAIC_DEFINITION: + const mosaicDefinitionTx = transaction as MosaicDefinitionTransaction; return { - nonce: (transaction as MosaicDefinitionTransaction).nonce, - id: (transaction as MosaicDefinitionTransaction).mosaicId.toHex(), - flags: (transaction as MosaicDefinitionTransaction).flags.getValue(), - divisibility: (transaction as MosaicDefinitionTransaction).divisibility, - duration: (transaction as MosaicDefinitionTransaction).duration.toString(), + nonce: mosaicDefinitionTx.nonce, + id: mosaicDefinitionTx.mosaicId.toHex(), + flags: mosaicDefinitionTx.flags.getValue(), + divisibility: mosaicDefinitionTx.divisibility, + duration: mosaicDefinitionTx.duration.toString(), }; case TransactionType.MOSAIC_SUPPLY_CHANGE: + const mosaicSupplyTx = transaction as MosaicSupplyChangeTransaction; return { - mosaicId: (transaction as MosaicSupplyChangeTransaction).mosaicId.toHex(), - action: (transaction as MosaicSupplyChangeTransaction).action, - delta: (transaction as MosaicSupplyChangeTransaction).delta.toString(), + mosaicId: mosaicSupplyTx.mosaicId.toHex(), + action: mosaicSupplyTx.action, + delta: mosaicSupplyTx.delta.toString(), }; case TransactionType.REGISTER_NAMESPACE: - const registerNamespaceDuration = (transaction as NamespaceRegistrationTransaction).duration; - const registerNamespaceParentId = (transaction as NamespaceRegistrationTransaction).parentId; + const namespaceTx = transaction as NamespaceRegistrationTransaction; + const registerNamespaceDuration = namespaceTx.duration; + const registerNamespaceParentId = namespaceTx.parentId; const jsonObject = { - registrationType: (transaction as NamespaceRegistrationTransaction).registrationType, - namespaceName: (transaction as NamespaceRegistrationTransaction).namespaceName, - id: (transaction as NamespaceRegistrationTransaction).namespaceId.toHex(), + registrationType: namespaceTx.registrationType, + namespaceName: namespaceTx.namespaceName, + id: namespaceTx.namespaceId.toHex(), }; if (registerNamespaceDuration) { @@ -159,75 +171,83 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { } return jsonObject; case TransactionType.SECRET_LOCK: + const secretLockTx = transaction as SecretLockTransaction; return { - mosaicId: (transaction as SecretLockTransaction).mosaic.id.id.toHex(), - amount: (transaction as SecretLockTransaction).mosaic.amount.toString(), - duration: (transaction as SecretLockTransaction).duration.toString(), - hashAlgorithm: (transaction as SecretLockTransaction).hashType, - secret: (transaction as SecretLockTransaction).secret, - recipientAddress: (transaction as SecretLockTransaction).recipientAddress.toDTO(), + mosaicId: secretLockTx.mosaic.id.id.toHex(), + amount: secretLockTx.mosaic.amount.toString(), + duration: secretLockTx.duration.toString(), + hashAlgorithm: secretLockTx.hashType, + secret: secretLockTx.secret, + recipientAddress: secretLockTx.recipientAddress.toDTO(), }; case TransactionType.SECRET_PROOF: + const secretProofTx = transaction as SecretProofTransaction; return { - hashAlgorithm: (transaction as SecretProofTransaction).hashType, - secret: (transaction as SecretProofTransaction).secret, - recipientAddress: (transaction as SecretProofTransaction).recipientAddress.toDTO(), - proof: (transaction as SecretProofTransaction).proof, + hashAlgorithm: secretProofTx.hashType, + secret: secretProofTx.secret, + recipientAddress: secretProofTx.recipientAddress.toDTO(), + proof: secretProofTx.proof, }; case TransactionType.TRANSFER: + const transferTx = transaction as TransferTransaction; return { - recipientAddress: (transaction as TransferTransaction).recipientAddress.toDTO(), - mosaics: (transaction as TransferTransaction).mosaics.map((mosaic) => { + recipientAddress: transferTx.recipientAddress.toDTO(), + mosaics: transferTx.mosaics.map((mosaic) => { return mosaic.toDTO(); }), - message: (transaction as TransferTransaction).message.toDTO(), + message: transferTx.message.toDTO(), }; case TransactionType.MOSAIC_GLOBAL_RESTRICTION: + const mosaicGlobalRestrictionTx = transaction as MosaicGlobalRestrictionTransaction; return { - mosaicId: (transaction as MosaicGlobalRestrictionTransaction).mosaicId.toHex(), - referenceMosaicId: (transaction as MosaicGlobalRestrictionTransaction).referenceMosaicId.toHex(), - restrictionKey: (transaction as MosaicGlobalRestrictionTransaction).restrictionKey.toHex(), - previousRestrictionValue: (transaction as MosaicGlobalRestrictionTransaction).previousRestrictionValue.toString(), - previousRestrictionType: (transaction as MosaicGlobalRestrictionTransaction).previousRestrictionType, - newRestrictionValue: (transaction as MosaicGlobalRestrictionTransaction).newRestrictionValue.toString(), - newRestrictionType: (transaction as MosaicGlobalRestrictionTransaction).newRestrictionType, + mosaicId: mosaicGlobalRestrictionTx.mosaicId.toHex(), + referenceMosaicId: mosaicGlobalRestrictionTx.referenceMosaicId.toHex(), + restrictionKey: mosaicGlobalRestrictionTx.restrictionKey.toHex(), + previousRestrictionValue: mosaicGlobalRestrictionTx.previousRestrictionValue.toString(), + previousRestrictionType: mosaicGlobalRestrictionTx.previousRestrictionType, + newRestrictionValue: mosaicGlobalRestrictionTx.newRestrictionValue.toString(), + newRestrictionType: mosaicGlobalRestrictionTx.newRestrictionType, }; case TransactionType.MOSAIC_ADDRESS_RESTRICTION: + const mosaicAddressRestrictionTx = transaction as MosaicAddressRestrictionTransaction; return { - mosaicId: (transaction as MosaicAddressRestrictionTransaction).mosaicId.toHex(), - restrictionKey: (transaction as MosaicAddressRestrictionTransaction).restrictionKey.toHex(), - targetAddress: (transaction as MosaicAddressRestrictionTransaction).targetAddress.toDTO(), - previousRestrictionValue: (transaction as MosaicAddressRestrictionTransaction).previousRestrictionValue.toString(), - newRestrictionValue: (transaction as MosaicAddressRestrictionTransaction).newRestrictionValue.toString(), + mosaicId: mosaicAddressRestrictionTx.mosaicId.toHex(), + restrictionKey: mosaicAddressRestrictionTx.restrictionKey.toHex(), + targetAddress: mosaicAddressRestrictionTx.targetAddress.toDTO(), + previousRestrictionValue: mosaicAddressRestrictionTx.previousRestrictionValue.toString(), + newRestrictionValue: mosaicAddressRestrictionTx.newRestrictionValue.toString(), }; case TransactionType.ACCOUNT_METADATA_TRANSACTION: + const accountMetadataTx = transaction as AccountMetadataTransaction; return { - targetPublicKey: (transaction as AccountMetadataTransaction).targetPublicKey, - scopedMetadataKey: (transaction as AccountMetadataTransaction).scopedMetadataKey.toHex(), - valueSizeDelta: (transaction as AccountMetadataTransaction).valueSizeDelta, - valueSize: (transaction as AccountMetadataTransaction).value.length, - value: Convert.utf8ToHex((transaction as AccountMetadataTransaction).value), + targetPublicKey: accountMetadataTx.targetPublicKey, + scopedMetadataKey: accountMetadataTx.scopedMetadataKey.toHex(), + valueSizeDelta: accountMetadataTx.valueSizeDelta, + valueSize: accountMetadataTx.value.length, + value: Convert.utf8ToHex(accountMetadataTx.value), }; case TransactionType.MOSAIC_METADATA_TRANSACTION: + const mosaicMetadataTx = transaction as MosaicMetadataTransaction; return { - targetPublicKey: (transaction as MosaicMetadataTransaction).targetPublicKey, - scopedMetadataKey: (transaction as MosaicMetadataTransaction).scopedMetadataKey.toHex(), - valueSizeDelta: (transaction as MosaicMetadataTransaction).valueSizeDelta, - targetMosaicId: (transaction as MosaicMetadataTransaction).targetMosaicId.id.toHex(), - valueSize: (transaction as MosaicMetadataTransaction).value.length, - value: Convert.utf8ToHex((transaction as MosaicMetadataTransaction).value), + targetPublicKey: mosaicMetadataTx.targetPublicKey, + scopedMetadataKey: mosaicMetadataTx.scopedMetadataKey.toHex(), + valueSizeDelta: mosaicMetadataTx.valueSizeDelta, + targetMosaicId: mosaicMetadataTx.targetMosaicId.id.toHex(), + valueSize: mosaicMetadataTx.value.length, + value: Convert.utf8ToHex(mosaicMetadataTx.value), }; case TransactionType.NAMESPACE_METADATA_TRANSACTION: + const namespaceMetaTx = transaction as NamespaceMetadataTransaction; return { - targetPublicKey: (transaction as NamespaceMetadataTransaction).targetPublicKey, - scopedMetadataKey: (transaction as NamespaceMetadataTransaction).scopedMetadataKey.toHex(), - valueSizeDelta: (transaction as NamespaceMetadataTransaction).valueSizeDelta, - targetNamespaceId: (transaction as NamespaceMetadataTransaction).targetNamespaceId.id.toHex(), - valueSize: (transaction as NamespaceMetadataTransaction).value.length, - value: Convert.utf8ToHex((transaction as NamespaceMetadataTransaction).value), + targetPublicKey: namespaceMetaTx.targetPublicKey, + scopedMetadataKey: namespaceMetaTx.scopedMetadataKey.toHex(), + valueSizeDelta: namespaceMetaTx.valueSizeDelta, + targetNamespaceId: namespaceMetaTx.targetNamespaceId.id.toHex(), + valueSize: namespaceMetaTx.value.length, + value: Convert.utf8ToHex(namespaceMetaTx.value), }; default: