@defichain/jellyfish-transaction
Advanced tools
Comparing version 0.9.0 to 0.10.1
@@ -81,2 +81,12 @@ import BigNumber from 'bignumber.js'; | ||
/** | ||
* Same behavior with `hex` when the field is defined | ||
* `toBuffer` resulted empty SmartBuffer | ||
* | ||
* @param length of the bytes to read/set | ||
* @param getter to read HEX String and write as the same ordered Buffer | ||
* @param setter to read ordered Buffer and set as the same ordered HEX String | ||
* @throws Error if getter() is defined && length != getter().length in set | ||
*/ | ||
static optionalHex(length: number, getter: () => string | undefined, setter: (data: string | undefined) => void): BufferComposer; | ||
/** | ||
* BE ordered HEX String with length specified, encoded in LE order buffer. | ||
@@ -83,0 +93,0 @@ * Different from BufferComposer.hex, this will reorder the Buffer from LE to BE and BE to LE. |
@@ -162,2 +162,31 @@ "use strict"; | ||
/** | ||
* Same behavior with `hex` when the field is defined | ||
* `toBuffer` resulted empty SmartBuffer | ||
* | ||
* @param length of the bytes to read/set | ||
* @param getter to read HEX String and write as the same ordered Buffer | ||
* @param setter to read ordered Buffer and set as the same ordered HEX String | ||
* @throws Error if getter() is defined && length != getter().length in set | ||
*/ | ||
static optionalHex(length, getter, setter) { | ||
return { | ||
fromBuffer: (buffer) => { | ||
const buff = Buffer.from(buffer.readBuffer(length)); | ||
if (buff.length > 0) { | ||
setter(buff.toString('hex')); | ||
} | ||
}, | ||
toBuffer: (buffer) => { | ||
const hex = getter(); | ||
if (hex === undefined) { | ||
return; | ||
} | ||
if (hex.length !== length * 2) { | ||
throw new Error('ComposableBuffer.optionalHex.toBuffer invalid as length != getter().length'); | ||
} | ||
buffer.writeBuffer(Buffer.from(hex, 'hex')); | ||
} | ||
}; | ||
} | ||
/** | ||
* BE ordered HEX String with length specified, encoded in LE order buffer. | ||
@@ -164,0 +193,0 @@ * Different from BufferComposer.hex, this will reorder the Buffer from LE to BE and BE to LE. |
@@ -32,3 +32,3 @@ import { BufferComposer, ComposableBuffer } from '../../buffer/buffer_composer'; | ||
/** | ||
* Composable TokenMint, C stands for Composable. | ||
* Composable TokenCreate, C stands for Composable. | ||
* Immutable by design, bi-directional fromBuffer, toBuffer deep composer. | ||
@@ -41,1 +41,33 @@ */ | ||
} | ||
/** | ||
* TokenUpdate DeFi Transaction | ||
* Note(canonbrother): Only 'isDAT' flag modification allowed before Bayfront fork (<10000) | ||
*/ | ||
export interface TokenUpdate { | ||
creationTx: string; | ||
isDAT: boolean; | ||
} | ||
/** | ||
* Composable CTokenUpdate, C stands for Composable. | ||
* Immutable by design, bi-directional fromBuffer, toBuffer deep composer. | ||
*/ | ||
export declare class CTokenUpdate extends ComposableBuffer<TokenUpdate> { | ||
static OP_CODE: number; | ||
static OP_NAME: string; | ||
composers(tu: TokenUpdate): BufferComposer[]; | ||
} | ||
/** | ||
* TokenUpdateAny DeFi Transaction | ||
*/ | ||
export interface TokenUpdateAny extends TokenCreate { | ||
creationTx: string; | ||
} | ||
/** | ||
* Composable TokenUpdateAny, C stands for Composable. | ||
* Immutable by design, bi-directional fromBuffer, toBuffer deep composer. | ||
*/ | ||
export declare class CTokenUpdateAny extends ComposableBuffer<TokenUpdateAny> { | ||
static OP_CODE: number; | ||
static OP_NAME: string; | ||
composers(tua: TokenUpdateAny): BufferComposer[]; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CTokenCreate = exports.CTokenMint = void 0; | ||
exports.CTokenUpdateAny = exports.CTokenUpdate = exports.CTokenCreate = exports.CTokenMint = void 0; | ||
const buffer_composer_1 = require("../../buffer/buffer_composer"); | ||
@@ -21,3 +21,3 @@ const dftx_balance_1 = require("./dftx_balance"); | ||
/** | ||
* Composable TokenMint, C stands for Composable. | ||
* Composable TokenCreate, C stands for Composable. | ||
* Immutable by design, bi-directional fromBuffer, toBuffer deep composer. | ||
@@ -43,1 +43,41 @@ */ | ||
CTokenCreate.OP_NAME = 'OP_DEFI_TX_TOKEN_CREATE'; | ||
/** | ||
* Composable CTokenUpdate, C stands for Composable. | ||
* Immutable by design, bi-directional fromBuffer, toBuffer deep composer. | ||
*/ | ||
class CTokenUpdate extends buffer_composer_1.ComposableBuffer { | ||
composers(tu) { | ||
return [ | ||
buffer_composer_1.ComposableBuffer.hexBEBufferLE(32, () => tu.creationTx, v => tu.creationTx = v), | ||
buffer_composer_1.ComposableBuffer.bitmask1Byte(1, () => [tu.isDAT], v => { | ||
tu.isDAT = v[0]; | ||
}) | ||
]; | ||
} | ||
} | ||
exports.CTokenUpdate = CTokenUpdate; | ||
CTokenUpdate.OP_CODE = 0x4e; /// 'N' | ||
CTokenUpdate.OP_NAME = 'OP_DEFI_TX_TOKEN_UPDATE'; | ||
/** | ||
* Composable TokenUpdateAny, C stands for Composable. | ||
* Immutable by design, bi-directional fromBuffer, toBuffer deep composer. | ||
*/ | ||
class CTokenUpdateAny extends buffer_composer_1.ComposableBuffer { | ||
composers(tua) { | ||
return [ | ||
buffer_composer_1.ComposableBuffer.hexBEBufferLE(32, () => tua.creationTx, v => tua.creationTx = v), | ||
buffer_composer_1.ComposableBuffer.varUIntUtf8BE(() => tua.symbol, v => tua.symbol = v), | ||
buffer_composer_1.ComposableBuffer.varUIntUtf8BE(() => tua.name, v => tua.name = v), | ||
buffer_composer_1.ComposableBuffer.uInt8(() => tua.decimal, v => tua.decimal = v), | ||
buffer_composer_1.ComposableBuffer.bigNumberUInt64(() => tua.limit, v => tua.limit = v), | ||
buffer_composer_1.ComposableBuffer.bitmask1Byte(3, () => [tua.isDAT, tua.tradeable, tua.mintable], v => { | ||
tua.isDAT = v[0]; | ||
tua.tradeable = v[1]; | ||
tua.mintable = v[2]; | ||
}) | ||
]; | ||
} | ||
} | ||
exports.CTokenUpdateAny = CTokenUpdateAny; | ||
CTokenUpdateAny.OP_CODE = 0x6e; /// 'n' | ||
CTokenUpdateAny.OP_NAME = 'OP_DEFI_TX_TOKEN_UPDATE_ANY'; |
@@ -6,2 +6,3 @@ "use strict"; | ||
const dftx_account_1 = require("./dftx_account"); | ||
const dftx_masternode_1 = require("./dftx_masternode"); | ||
const dftx_misc_1 = require("./dftx_misc"); | ||
@@ -71,2 +72,6 @@ const dftx_pool_1 = require("./dftx_pool"); | ||
return compose(dftx_token_1.CTokenCreate.OP_NAME, d => new dftx_token_1.CTokenCreate(d)); | ||
case dftx_token_1.CTokenUpdate.OP_CODE: | ||
return compose(dftx_token_1.CTokenUpdate.OP_NAME, d => new dftx_token_1.CTokenUpdate(d)); | ||
case dftx_token_1.CTokenUpdateAny.OP_CODE: | ||
return compose(dftx_token_1.CTokenUpdateAny.OP_NAME, d => new dftx_token_1.CTokenUpdateAny(d)); | ||
case dftx_account_1.CUtxosToAccount.OP_CODE: | ||
@@ -90,2 +95,6 @@ return compose(dftx_account_1.CUtxosToAccount.OP_NAME, d => new dftx_account_1.CUtxosToAccount(d)); | ||
return compose(dftx_misc_1.CAutoAuthPrep.OP_NAME, () => new dftx_misc_1.CAutoAuthPrep()); | ||
case dftx_masternode_1.CCreateMasterNode.OP_CODE: | ||
return compose(dftx_masternode_1.CCreateMasterNode.OP_NAME, d => new dftx_masternode_1.CCreateMasterNode(d)); | ||
case dftx_masternode_1.CResignMasterNode.OP_CODE: | ||
return compose(dftx_masternode_1.CResignMasterNode.OP_NAME, d => new dftx_masternode_1.CResignMasterNode(d)); | ||
default: | ||
@@ -92,0 +101,0 @@ return compose(dftx_unmapped_1.CDeFiOpUnmapped.OP_NAME, d => new dftx_unmapped_1.CDeFiOpUnmapped(d)); |
@@ -13,5 +13,6 @@ /// <reference types="node" /> | ||
import { PoolAddLiquidity, PoolRemoveLiquidity, PoolSwap } from './defi/dftx_pool'; | ||
import { TokenCreate, TokenMint } from './defi/dftx_token'; | ||
import { TokenCreate, TokenUpdate, TokenUpdateAny, TokenMint } from './defi/dftx_token'; | ||
import { AccountToAccount, AccountToUtxos, AnyAccountToAccount, UtxosToAccount } from './defi/dftx_account'; | ||
import { AppointOracle, RemoveOracle, UpdateOracle, SetOracleData } from './defi/dftx_oracles'; | ||
import { CreateMasterNode, ResignMasterNode } from './defi/dftx_masternode'; | ||
/** | ||
@@ -80,2 +81,4 @@ * @param num to map as OPCode, 1 byte long | ||
OP_DEFI_TX_TOKEN_CREATE: (tokenCreate: TokenCreate) => OP_DEFI_TX; | ||
OP_DEFI_TX_TOKEN_UPDATE: (tokenUpdate: TokenUpdate) => OP_DEFI_TX; | ||
OP_DEFI_TX_TOKEN_UPDATE_ANY: (tokenUpdateAny: TokenUpdateAny) => OP_DEFI_TX; | ||
OP_DEFI_TX_UTXOS_TO_ACCOUNT: (utxosToAccount: UtxosToAccount) => OP_DEFI_TX; | ||
@@ -90,2 +93,4 @@ OP_DEFI_TX_ACCOUNT_TO_UTXOS: (accountToUtxos: AccountToUtxos) => OP_DEFI_TX; | ||
OP_DEFI_TX_AUTO_AUTH_PREP: () => OP_DEFI_TX; | ||
OP_DEFI_TX_CREATE_MASTER_NODE: (createMasterNode: CreateMasterNode) => OP_DEFI_TX; | ||
OP_DEFI_TX_RESIGN_MASTER_NODE: (resignMasterNode: ResignMasterNode) => OP_DEFI_TX; | ||
OP_0: constants.OP_0; | ||
@@ -92,0 +97,0 @@ OP_FALSE: constants.OP_FALSE; |
@@ -40,2 +40,3 @@ "use strict"; | ||
const dftx_misc_1 = require("./defi/dftx_misc"); | ||
const dftx_masternode_1 = require("./defi/dftx_masternode"); | ||
/** | ||
@@ -165,2 +166,18 @@ * @param num to map as OPCode, 1 byte long | ||
}, | ||
OP_DEFI_TX_TOKEN_UPDATE: (tokenUpdate) => { | ||
return new defi_1.OP_DEFI_TX({ | ||
signature: dftx_1.CDfTx.SIGNATURE, | ||
type: dftx_token_1.CTokenUpdate.OP_CODE, | ||
name: dftx_token_1.CTokenUpdate.OP_NAME, | ||
data: tokenUpdate | ||
}); | ||
}, | ||
OP_DEFI_TX_TOKEN_UPDATE_ANY: (tokenUpdateAny) => { | ||
return new defi_1.OP_DEFI_TX({ | ||
signature: dftx_1.CDfTx.SIGNATURE, | ||
type: dftx_token_1.CTokenUpdateAny.OP_CODE, | ||
name: dftx_token_1.CTokenUpdateAny.OP_NAME, | ||
data: tokenUpdateAny | ||
}); | ||
}, | ||
OP_DEFI_TX_UTXOS_TO_ACCOUNT: (utxosToAccount) => { | ||
@@ -238,2 +255,18 @@ return new defi_1.OP_DEFI_TX({ | ||
}, | ||
OP_DEFI_TX_CREATE_MASTER_NODE: (createMasterNode) => { | ||
return new defi_1.OP_DEFI_TX({ | ||
signature: dftx_1.CDfTx.SIGNATURE, | ||
type: dftx_masternode_1.CCreateMasterNode.OP_CODE, | ||
name: dftx_masternode_1.CCreateMasterNode.OP_NAME, | ||
data: createMasterNode | ||
}); | ||
}, | ||
OP_DEFI_TX_RESIGN_MASTER_NODE: (resignMasterNode) => { | ||
return new defi_1.OP_DEFI_TX({ | ||
signature: dftx_1.CDfTx.SIGNATURE, | ||
type: dftx_masternode_1.CResignMasterNode.OP_CODE, | ||
name: dftx_masternode_1.CResignMasterNode.OP_NAME, | ||
data: resignMasterNode | ||
}); | ||
}, | ||
OP_0: new constants.OP_0(), | ||
@@ -240,0 +273,0 @@ OP_FALSE: new constants.OP_FALSE(), |
{ | ||
"private": false, | ||
"name": "@defichain/jellyfish-transaction", | ||
"version": "0.9.0", | ||
"version": "0.10.1", | ||
"description": "A collection of TypeScript + JavaScript tools and libraries for DeFi Blockchain developers to build decentralized finance on Bitcoin", | ||
@@ -41,10 +41,10 @@ "keywords": [ | ||
"dependencies": { | ||
"@defichain/jellyfish-crypto": "^0.9.0", | ||
"@defichain/jellyfish-crypto": "^0.10.1", | ||
"smart-buffer": "^4.1.0" | ||
}, | ||
"devDependencies": { | ||
"@defichain/jellyfish-api-core": "^0.9.0", | ||
"@defichain/jellyfish-api-jsonrpc": "^0.9.0", | ||
"@defichain/testcontainers": "^0.9.0" | ||
"@defichain/jellyfish-api-core": "^0.10.1", | ||
"@defichain/jellyfish-api-jsonrpc": "^0.10.1", | ||
"@defichain/testcontainers": "^0.10.1" | ||
} | ||
} |
149869
62
4148
+ Added@defichain/jellyfish-crypto@0.10.1(transitive)
- Removed@defichain/jellyfish-crypto@0.9.0(transitive)