Skip to content

Commit

Permalink
fix dftx TokenMint (#183)
Browse files Browse the repository at this point in the history
* bug fix on dftx TokenMint
  • Loading branch information
canonbrother authored May 4, 2021
1 parent 3fb5abc commit 9619db1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import { OP_CODES, toBuffer, toOPCodes } from '../../../../src/script'

it('should bi-directional buffer-object-buffer', () => {
const fixtures = [
'6a0e446654784d016050da6001000000',
'6a0e446654784d035fc05c7302000000',
'6a0e446654784d03a45ce23902000000',
'6a0e446654784d06ede2e73001040000'
'6a12446654784d010200000000ca9a3b00000000',
'6a12446654784d010200000000ea56fa00000000'
]

fixtures.forEach(hex => {
Expand All @@ -22,11 +20,15 @@ it('should bi-directional buffer-object-buffer', () => {
})
})

const header = '6a0e446654784d' // OP_RETURN, PUSH_DATA(44665478, 4d)
const data = '016050da6001000000'
const header = '6a12446654784d' // OP_RETURN, PUSH_DATA(44665478, 4d)
const data = '01010000006050da6001000000'
const tokenMint: TokenMint = {
tokenId: 1,
amount: new BigNumber('59.19887456')
balances: [
{
token: 1,
amount: new BigNumber('59.19887456')
}
]
}

it('should craft dftx with OP_CODES._()', () => {
Expand Down
8 changes: 3 additions & 5 deletions packages/jellyfish-transaction/src/script/defi/dftx_token.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BigNumber from 'bignumber.js'
import { BufferComposer, ComposableBuffer } from '../../buffer/buffer_composer'
import { TokenBalance, CTokenBalance } from './dftx_balance'

// Disabling no-return-assign makes the code cleaner with the setter and getter */
/* eslint-disable no-return-assign */
Expand All @@ -8,8 +8,7 @@ import { BufferComposer, ComposableBuffer } from '../../buffer/buffer_composer'
* TokenMint DeFi Transaction
*/
export interface TokenMint {
tokenId: number // -------------------| VarUInt{1-9 bytes}
amount: BigNumber // -----------------| 8 bytes
balances: TokenBalance[] // ----------| c = VarUInt{1-9 bytes}, + c x TokenBalance
}

/**
Expand All @@ -22,8 +21,7 @@ export class CTokenMint extends ComposableBuffer<TokenMint> {

composers (tm: TokenMint): BufferComposer[] {
return [
ComposableBuffer.varUInt(() => tm.tokenId, v => tm.tokenId = v),
ComposableBuffer.satoshiAsBigNumber(() => tm.amount, v => tm.amount = v)
ComposableBuffer.varUIntArray(() => tm.balances, v => tm.balances = v, v => new CTokenBalance(v))
]
}
}

0 comments on commit 9619db1

Please sign in to comment.