From 36ba065e59bee07cd6a7f658af573e369b313d0e Mon Sep 17 00:00:00 2001 From: Anthony Law Yong Chuan Date: Fri, 14 Feb 2020 00:58:35 +0800 Subject: [PATCH 1/2] fix #446 --- src/infrastructure/BlockHttp.ts | 4 +- src/infrastructure/Listener.ts | 7 +--- .../transaction/CreateTransactionFromDTO.ts | 41 ------------------- 3 files changed, 4 insertions(+), 48 deletions(-) diff --git a/src/infrastructure/BlockHttp.ts b/src/infrastructure/BlockHttp.ts index c30b03939c..eb3a5d94a4 100644 --- a/src/infrastructure/BlockHttp.ts +++ b/src/infrastructure/BlockHttp.ts @@ -26,7 +26,7 @@ import { UInt64 } from '../model/UInt64'; import { BlockRepository } from './BlockRepository'; import { Http } from './Http'; import { QueryParams } from './QueryParams'; -import { CreateTransactionFromDTO, extractBeneficiary } from './transaction/CreateTransactionFromDTO'; +import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO'; /** * Blockchain http repository. @@ -122,7 +122,7 @@ export class BlockHttp extends Http implements BlockRepository { dto.block.transactionsHash, dto.block.receiptsHash, dto.block.stateHash, - extractBeneficiary(dto, networkType), + dto.block.beneficiaryPublicKey ? PublicAccount.createFromPublicKey(dto.block.beneficiaryPublicKey, networkType) : undefined, ); } diff --git a/src/infrastructure/Listener.ts b/src/infrastructure/Listener.ts index 01867ff680..2fdd47d284 100644 --- a/src/infrastructure/Listener.ts +++ b/src/infrastructure/Listener.ts @@ -32,10 +32,7 @@ import { TransactionStatusError } from '../model/transaction/TransactionStatusEr import { TransferTransaction } from '../model/transaction/TransferTransaction'; import { UInt64 } from '../model/UInt64'; import { IListener } from './IListener'; -import { - CreateTransactionFromDTO, - extractBeneficiary, -} from './transaction/CreateTransactionFromDTO'; +import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO'; enum ListenerChannelName { block = 'block', @@ -157,7 +154,7 @@ export class Listener implements IListener { message.block.blockTransactionsHash, message.block.blockReceiptsHash, message.block.stateHash, - extractBeneficiary(message, message.block.network), // passing `message` as `blockDTO` + message.block.beneficiaryPublicKey, ), }); } else if (message.code) { diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index e1961f383f..4342c7fa2c 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -481,44 +481,3 @@ const extractMessage = (message: any): PlainMessage | EncryptedMessage => { } return msgObj; }; - -/** - * Extract beneficiary public key from DTO. - * - * @todo Upgrade of catapult-rest WITH catapult-service-bootstrap versioning. - * - * With `cow` upgrade (nemtech/catapult-server@0.3.0.2), `catapult-rest` block DTO - * was updated and latest catapult-service-bootstrap uses the wrong block DTO. - * This will be fixed with next catapult-server upgrade to `dragon`. - * - * :warning It is currently not possible to read the block's beneficiary public key - * except when working with a local instance of `catapult-rest`. - * - * @param beneficiary {string | undefined} The beneficiary public key if set - * @return {Mosaic[]} - */ -export const extractBeneficiary = ( - blockDTO: any, - networkType: NetworkType, -): PublicAccount | undefined => { - - let dtoPublicAccount: PublicAccount | undefined; - let dtoFieldValue: string | undefined; - if (blockDTO.beneficiaryPublicKey) { - dtoFieldValue = blockDTO.beneficiaryPublicKey; - } else if (blockDTO.beneficiary) { - dtoFieldValue = blockDTO.beneficiary; - } - - if (! dtoFieldValue) { - return undefined; - } - - try { - // @FIX with latest catapult-service-bootstrap version, catapult-rest still returns - // a `string` formatted copy of the public *when it is set at all*. - dtoPublicAccount = PublicAccount.createFromPublicKey(dtoFieldValue, networkType); - } catch (e) { dtoPublicAccount =  undefined; } - - return dtoPublicAccount; -}; From b349454e4e810755c576bc1477dd76641575e112 Mon Sep 17 00:00:00 2001 From: Anthony Law Yong Chuan Date: Sat, 15 Feb 2020 23:05:30 +0800 Subject: [PATCH 2/2] added assert in e2e --- e2e/infrastructure/BlockHttp.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/infrastructure/BlockHttp.spec.ts b/e2e/infrastructure/BlockHttp.spec.ts index a39b95530e..0d12e7a93b 100644 --- a/e2e/infrastructure/BlockHttp.spec.ts +++ b/e2e/infrastructure/BlockHttp.spec.ts @@ -95,7 +95,7 @@ describe('BlockHttp', () => { expect(blockInfo.height.higher).to.be.equal(0); expect(blockInfo.timestamp.lower).to.be.equal(0); expect(blockInfo.timestamp.higher).to.be.equal(0); - + expect(blockInfo.beneficiaryPublicKey).not.to.be.undefined; }); });