From ac72093318ed764fc3b002df65751747cb5cb4ab Mon Sep 17 00:00:00 2001 From: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> Date: Wed, 28 Apr 2021 15:42:31 +0800 Subject: [PATCH] fixed CPoolSwap not to use bigint to parse (#169) --- .../jellyfish-transaction/src/script/defi/dftx_pool.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/jellyfish-transaction/src/script/defi/dftx_pool.ts b/packages/jellyfish-transaction/src/script/defi/dftx_pool.ts index 5ac16affe1..a37188b57d 100644 --- a/packages/jellyfish-transaction/src/script/defi/dftx_pool.ts +++ b/packages/jellyfish-transaction/src/script/defi/dftx_pool.ts @@ -3,6 +3,7 @@ import { BufferComposer, ComposableBuffer } from '../../buffer/buffer_composer' import { Script } from '../../tx' import { CScript } from '../../tx_composer' import { SmartBuffer } from 'smart-buffer' +import { readBigNumberUInt64, writeBigNumberUInt64 } from '../../buffer/buffer_bignumber' // Disabling no-return-assign makes the code cleaner with the setter and getter */ /* eslint-disable no-return-assign */ @@ -39,14 +40,14 @@ export class CPoolSwap extends ComposableBuffer { ComposableBuffer.varUInt(() => ps.toTokenId, v => ps.toTokenId = v), { fromBuffer (buffer: SmartBuffer) { - const integer = new BigNumber(buffer.readBigUInt64LE().toString()) - const fraction = new BigNumber(buffer.readBigUInt64LE().toString()) + const integer = readBigNumberUInt64(buffer) + const fraction = readBigNumberUInt64(buffer) ps.maxPrice = { integer, fraction } }, toBuffer (buffer: SmartBuffer) { const { integer, fraction } = ps.maxPrice - buffer.writeBigUInt64LE(BigInt(integer.toString(10))) - buffer.writeBigUInt64LE(BigInt(fraction.toString(10))) + writeBigNumberUInt64(integer, buffer) + writeBigNumberUInt64(fraction, buffer) } } ]