From 1673e3585c4e524e796305bf46f08140f2d32f8f Mon Sep 17 00:00:00 2001 From: Mark Tan Date: Fri, 18 Nov 2022 12:22:15 +0800 Subject: [PATCH 01/31] add dftx (WIP) --- .../src/script/dftx/dftx.ts | 2 ++ .../src/script/dftx/dftx_masternode.ts | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/packages/jellyfish-transaction/src/script/dftx/dftx.ts b/packages/jellyfish-transaction/src/script/dftx/dftx.ts index 9107da7928..bb171187fb 100644 --- a/packages/jellyfish-transaction/src/script/dftx/dftx.ts +++ b/packages/jellyfish-transaction/src/script/dftx/dftx.ts @@ -225,6 +225,8 @@ export class CDfTx extends ComposableBuffer> { return compose(CAutoAuthPrep.OP_NAME, () => new CAutoAuthPrep()) case CCreateMasternode.OP_CODE: return compose(CCreateMasternode.OP_NAME, d => new CCreateMasternode(d)) + case CUpdateMasternode.OP_CODE: + return compose(CUpdateMasternode.OP_NAME, d => new CUpdateMasternode(d)) case CResignMasternode.OP_CODE: return compose(CResignMasternode.OP_NAME, d => new CResignMasternode(d)) case CSetGovernance.OP_CODE: diff --git a/packages/jellyfish-transaction/src/script/dftx/dftx_masternode.ts b/packages/jellyfish-transaction/src/script/dftx/dftx_masternode.ts index e4ba86499b..8980d2010c 100644 --- a/packages/jellyfish-transaction/src/script/dftx/dftx_masternode.ts +++ b/packages/jellyfish-transaction/src/script/dftx/dftx_masternode.ts @@ -59,3 +59,27 @@ export class CResignMasternode extends ComposableBuffer { ] } } + +/** + * UpdateMasternode DeFi Transaction + */ +export interface UpdateMasternode { + nodeId: string // --------------------------------| VarUInt{32 bytes} + // updates: +} + +/** + * Composable UpdateMasternode, C stands for Composable. + * Immutable by design, bi-directional fromBuffer, toBuffer deep composer. + */ +export class CUpdateMasternode extends ComposableBuffer { + static OP_CODE = 0x6D // 'm' + static OP_NAME = 'OP_DEFI_TX_UPDATE_MASTER_NODE' + + composers (cmn: UpdateMasternode): BufferComposer[] { + return [ + ComposableBuffer.hexBEBufferLE(32, () => cmn.nodeId, v => cmn.nodeId = v) + + ] + } +} From 9fa64e0a213176196f8af2ea9cb6b9b5f8779a7b Mon Sep 17 00:00:00 2001 From: Kven Ho Date: Fri, 18 Nov 2022 14:16:36 +0800 Subject: [PATCH 02/31] Add mapping --- packages/jellyfish-transaction/src/script/mapping.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/jellyfish-transaction/src/script/mapping.ts b/packages/jellyfish-transaction/src/script/mapping.ts index 0761d967c4..4364515020 100644 --- a/packages/jellyfish-transaction/src/script/mapping.ts +++ b/packages/jellyfish-transaction/src/script/mapping.ts @@ -123,7 +123,7 @@ import { CICXClaimDFCHTLC, ICXClaimDFCHTLC } from './dftx/dftx_icxorderbook' -import { CCreateMasternode, CreateMasternode, CResignMasternode, ResignMasternode } from './dftx/dftx_masternode' +import { CCreateMasternode, CreateMasternode, CResignMasternode, ResignMasternode, UpdateMasternode } from './dftx/dftx_masternode' /** * @param num to map as OPCode, 1 byte long @@ -389,6 +389,14 @@ export const OP_CODES = { data: resignMasternode }) }, + OP_DEFI_TX_UPDATE_MASTER_NODE: (updateMasternode: UpdateMasternode): OP_DEFI_TX => { + return new OP_DEFI_TX({ + signature: CDfTx.SIGNATURE, + type: CCreateMasternode.OP_CODE, + name: CCreateMasternode.OP_NAME, + data: updateMasternode + }) + }, OP_DEFI_TX_SET_GOVERNANCE: (setGovernance: SetGovernance) => { return new OP_DEFI_TX({ signature: CDfTx.SIGNATURE, From 0ed853b6b3fea3bfa4d2e5d907ad36e432855d7b Mon Sep 17 00:00:00 2001 From: Kven Ho Date: Sat, 19 Nov 2022 23:01:49 +0800 Subject: [PATCH 03/31] WIP --- .../src/script/dftx/dftx.ts | 4 +-- .../src/script/dftx/dftx_masternode.ts | 29 +++++++++++++++---- .../src/script/mapping.ts | 6 ++-- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/packages/jellyfish-transaction/src/script/dftx/dftx.ts b/packages/jellyfish-transaction/src/script/dftx/dftx.ts index bb171187fb..dfd46a8982 100644 --- a/packages/jellyfish-transaction/src/script/dftx/dftx.ts +++ b/packages/jellyfish-transaction/src/script/dftx/dftx.ts @@ -12,7 +12,7 @@ import { CUtxosToAccount, CSetFutureSwap } from './dftx_account' -import { CCreateMasternode, CreateMasternode, CResignMasternode, ResignMasternode } from './dftx_masternode' +import { CCreateMasternode, CreateMasternode, CResignMasternode, ResignMasternode, CUpdateMasternode, UpdateMasternode } from './dftx_masternode' import { CAutoAuthPrep } from './dftx_misc' import { CPoolAddLiquidity, @@ -226,7 +226,7 @@ export class CDfTx extends ComposableBuffer> { case CCreateMasternode.OP_CODE: return compose(CCreateMasternode.OP_NAME, d => new CCreateMasternode(d)) case CUpdateMasternode.OP_CODE: - return compose(CUpdateMasternode.OP_NAME, d => new CUpdateMasternode(d)) + return compose(CUpdateMasternode.OP_NAME, d => new CUpdateMasternode(d)) case CResignMasternode.OP_CODE: return compose(CResignMasternode.OP_NAME, d => new CResignMasternode(d)) case CSetGovernance.OP_CODE: diff --git a/packages/jellyfish-transaction/src/script/dftx/dftx_masternode.ts b/packages/jellyfish-transaction/src/script/dftx/dftx_masternode.ts index 8980d2010c..b8997baadc 100644 --- a/packages/jellyfish-transaction/src/script/dftx/dftx_masternode.ts +++ b/packages/jellyfish-transaction/src/script/dftx/dftx_masternode.ts @@ -1,5 +1,7 @@ import { SmartBuffer } from 'smart-buffer' import { BufferComposer, ComposableBuffer } from '@defichain/jellyfish-buffer' +import { Script } from '../../tx' +import { CScript } from '../../tx_composer' /** * CreateMasternode DeFi Transaction @@ -63,9 +65,16 @@ export class CResignMasternode extends ComposableBuffer { /** * UpdateMasternode DeFi Transaction */ +// export interface UpdateMasternodeValues { +// ownerAddress?: string +// operatorAddress?: string +// rewardAddress?: string +// } export interface UpdateMasternode { nodeId: string // --------------------------------| VarUInt{32 bytes} - // updates: + ownerAddress?: Script + operatorAddress?: Script + rewardAddress?: Script } /** @@ -76,10 +85,20 @@ export class CUpdateMasternode extends ComposableBuffer { static OP_CODE = 0x6D // 'm' static OP_NAME = 'OP_DEFI_TX_UPDATE_MASTER_NODE' - composers (cmn: UpdateMasternode): BufferComposer[] { - return [ - ComposableBuffer.hexBEBufferLE(32, () => cmn.nodeId, v => cmn.nodeId = v) - + composers (umn: UpdateMasternode): BufferComposer[] { + let { ownerAddress, operatorAddress, rewardAddress } = umn + const bufferComposer = [ + ComposableBuffer.hexBEBufferLE(32, () => umn.nodeId, v => umn.nodeId = v) ] + if (typeof ownerAddress !== 'undefined') { + bufferComposer.push(ComposableBuffer.single