Skip to content

Commit

Permalink
fix req: use hexBEBufferLE and update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed May 27, 2021
1 parent a25e91c commit 03f3713
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ it('should bi-directional buffer-object-buffer', () => {
// https://github.com/DeFiCh/ain/blob/c7b13959cc84c6d6210927b0e2377432c0dcadeb/src/masternodes/rpc_tokens.cpp#L278
'6a26446654784effe50b27cd4325e9a87401e833a9caccf256e0b4ea37b6c4fb038bedc1cb247100'

// Note(canonbrother): isDAT is not updated after modified
// BUG(canonbrother): isDAT is not updated after modified
// Issue is submitted: https://github.com/DeFiCh/ain/issues/440
]

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

const header = '6a37446654784e' // OP_RETURN, PUSH_DATA(44665478, 4e)
const header = '6a26446654784e' // OP_RETURN, PUSH_DATA(44665478, 4e)
const data = 'ffe50b27cd4325e9a87401e833a9caccf256e0b4ea37b6c4fb038bedc1cb247100'
const tokenUpdate: TokenUpdate = {
isDAT: false,
creationTx: 'ffe50b27cd4325e9a87401e833a9caccf256e0b4ea37b6c4fb038bedc1cb2471'
creationTx: '7124cbc1ed8b03fbc4b637eab4e056f2cccaa933e80174a8e92543cd270be5ff'
}

it('should craft dftx with OP_CODES._()', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ it('should bi-directional buffer-object-buffer', () => {

// name
'6a39446654786effe50b27cd4325e9a87401e833a9caccf256e0b4ea37b6c4fb038bedc1cb2471034f574c054e4947485408000000000000000007'

// Note(canonbrother): collateralAddress and creationTx are not updated after modified
]

fixtures.forEach(hex => {
Expand All @@ -40,7 +38,7 @@ const tokenUpdateAny: TokenUpdateAny = {
mintable: true,
tradeable: true,
isDAT: true,
creationTx: 'd819f622ced3616e3c02e5337b54cbf921c364e182a80925219e1f60461ee5fc'
creationTx: 'fce51e46601f9e212509a882e164c321f9cb547b33e5023c6e61d3ce22f619d8'
}

it('should craft dftx with OP_CODES._()', () => {
Expand Down
12 changes: 7 additions & 5 deletions packages/jellyfish-transaction/src/script/defi/dftx_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class CTokenCreate extends ComposableBuffer<TokenCreate> {
* Note(canonbrother): Only 'isDAT' flag modification allowed before Bayfront fork (<10000)
*/
export interface TokenUpdate {
creationTx: string // -----------------| hex
creationTx: string // -----------------| 32 bytes hex string
isDAT: boolean // ---------------------| 1 byte bitmask start, position 0
}

Expand All @@ -82,8 +82,8 @@ export class CTokenUpdate extends ComposableBuffer<TokenUpdate> {

composers (tu: TokenUpdate): BufferComposer[] {
return [
ComposableBuffer.hex(32, () => tu.creationTx, v => tu.creationTx = v),
ComposableBuffer.bitmask1Byte(3, () => [tu.isDAT], v => {
ComposableBuffer.hexBEBufferLE(32, () => tu.creationTx, v => tu.creationTx = v),
ComposableBuffer.bitmask1Byte(1, () => [tu.isDAT], v => {
tu.isDAT = v[0]
})
]
Expand All @@ -92,9 +92,11 @@ export class CTokenUpdate extends ComposableBuffer<TokenUpdate> {

/**
* TokenUpdateAny DeFi Transaction
*
* Note(canonbrother): collateralAddress and creationTx are be able to be updated
*/
export interface TokenUpdateAny extends TokenCreate {
creationTx: string // -----------------| hex
creationTx: string // -----------------| 32 bytes hex string
}

/**
Expand All @@ -107,7 +109,7 @@ export class CTokenUpdateAny extends ComposableBuffer<TokenUpdateAny> {

composers (tua: TokenUpdateAny): BufferComposer[] {
return [
ComposableBuffer.hex(32, () => tua.creationTx, v => tua.creationTx = v),
ComposableBuffer.hexBEBufferLE(32, () => tua.creationTx, v => tua.creationTx = v),
ComposableBuffer.varUIntUtf8BE(() => tua.symbol, v => tua.symbol = v),
ComposableBuffer.varUIntUtf8BE(() => tua.name, v => tua.name = v),
ComposableBuffer.uInt8(() => tua.decimal, v => tua.decimal = v),
Expand Down

0 comments on commit 03f3713

Please sign in to comment.