From 6635297ebbbf9aae929e767044f1cd92d90fddbf Mon Sep 17 00:00:00 2001 From: Sergey Slipchenko Date: Fri, 27 Jan 2023 19:20:51 +0400 Subject: [PATCH] Fix order serialization --- src/controllers/message.ts | 19 ++++++++++++------- src/messages/utils.ts | 4 +--- test/Signature.ts | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/controllers/message.ts b/src/controllers/message.ts index bd54ca5ab..0b6badd15 100644 --- a/src/controllers/message.ts +++ b/src/controllers/message.ts @@ -1841,14 +1841,20 @@ export class MessageController extends EventEmitter { ); } - const amountAssetId = messageInput.data.data.amount.assetId ?? 'WAVES'; + const amountAssetId = + messageInput.data.data.amount.assetId === 'WAVES' + ? null + : messageInput.data.data.amount.assetId; const matcherFeeAssetId = messageInput.data.data.matcherFee.assetId === 'WAVES' ? null : messageInput.data.data.matcherFee.assetId; - const priceAssetId = messageInput.data.data.price.assetId ?? 'WAVES'; + const priceAssetId = + messageInput.data.data.price.assetId === 'WAVES' + ? null + : messageInput.data.data.price.assetId; await this.assetInfoController.updateAssets([ amountAssetId, @@ -1858,10 +1864,10 @@ export class MessageController extends EventEmitter { const assets = this.assetInfoController.getAssets(); - const amountAsset = assets[amountAssetId]; + const amountAsset = assets[amountAssetId ?? 'WAVES']; invariant(amountAsset); - const priceAsset = assets[priceAssetId]; + const priceAsset = assets[priceAssetId ?? 'WAVES']; invariant(priceAsset); const version = messageInput.data.data.version ?? 3; @@ -1884,8 +1890,7 @@ export class MessageController extends EventEmitter { messageInput.data.data.matcherFee, assets ).toCoins(), - matcherFeeAssetId: - matcherFeeAssetId === 'WAVES' ? null : matcherFeeAssetId, + matcherFeeAssetId, matcherPublicKey: messageInput.data.data.matcherPublicKey ?? (await this.networkController.getMatcherPublicKey()), @@ -1904,7 +1909,7 @@ export class MessageController extends EventEmitter { priceMode: messageInput.data.data.priceMode ?? 'fixedDecimals', proofs: messageInput.data.data.proofs ?? [], senderPublicKey: messageInput.account.publicKey, - timestamp: Date.now(), + timestamp: messageInput.data.data.timestamp ?? Date.now(), version, }; diff --git a/src/messages/utils.ts b/src/messages/utils.ts index 8e3fcd52e..6caa137f1 100644 --- a/src/messages/utils.ts +++ b/src/messages/utils.ts @@ -170,9 +170,7 @@ export function makeOrderBytes( }[order.priceMode] : undefined, proofs: order.proofs?.map(base58Decode), - senderPublicKey: order.senderPublicKey - ? base58Decode(order.senderPublicKey) - : null, + senderPublicKey: base58Decode(order.senderPublicKey), timestamp: Long.fromValue(order.timestamp), }).finish(); } diff --git a/test/Signature.ts b/test/Signature.ts index 0f2a6798a..9c8a4f1f7 100644 --- a/test/Signature.ts +++ b/test/Signature.ts @@ -2881,7 +2881,7 @@ describe('Signature', function () { orderType: INPUT.data.orderType, version: 3, assetPair: { - amountAsset: INPUT.data.amount.assetId, + amountAsset: null, priceAsset: INPUT.data.price.assetId, }, price: 0,