Skip to content

Commit

Permalink
Fix order serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
faergeek committed Jan 27, 2023
1 parent 8c49a10 commit 6635297
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
19 changes: 12 additions & 7 deletions src/controllers/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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()),
Expand All @@ -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,
};

Expand Down
4 changes: 1 addition & 3 deletions src/messages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion test/Signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6635297

Please sign in to comment.