From 5423fa1a72759dcb35a893c6db37f67db48d1ede Mon Sep 17 00:00:00 2001 From: KyleO_O <> Date: Wed, 8 May 2024 11:47:01 +0800 Subject: [PATCH 1/5] feat: add value field to RuneUtxoBalance --- src/indexer/types.ts | 1 + src/indexer/updater.ts | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/indexer/types.ts b/src/indexer/types.ts index ea50f08..d20471c 100644 --- a/src/indexer/types.ts +++ b/src/indexer/types.ts @@ -101,6 +101,7 @@ export type RuneSpentUtxoBalance = RuneUtxoBalance & { spentTxid: string }; export type RuneUtxoBalance = { txid: string; vout: number; + value?: number; address?: string; scriptPubKey: Buffer; runeId: RuneLocation; diff --git a/src/indexer/updater.ts b/src/indexer/updater.ts index 98090ab..90dd30b 100644 --- a/src/indexer/updater.ts +++ b/src/indexer/updater.ts @@ -32,7 +32,7 @@ function isScriptPubKeyHexOpReturn(scriptPubKeyHex: string) { export type UpdaterTx = { txid: string; vin: ({ txid: string; vout: number; txinwitness: string[] } | { coinbase: string })[]; - vout: { scriptPubKey: { hex: string; address?: string } }[]; + vout: { scriptPubKey: { hex: string; address?: string }, value?: number }[]; }; export class RuneUpdater implements RuneBlockIndex { @@ -298,6 +298,7 @@ export class RuneUpdater implements RuneBlockIndex { txid: tx.txid, vout, address: output.scriptPubKey.address, + value: output.value, }); } } @@ -466,6 +467,7 @@ export class RuneUpdater implements RuneBlockIndex { runeTicker: additionalBalance.runeTicker, amount: additionalBalance.amount, spentTxid: tx.txid, + value: additionalBalance.value, }); } } From 6241dc00da6751a013e2016da6b7a342a3f0e553 Mon Sep 17 00:00:00 2001 From: KyleO_O <> Date: Sat, 11 May 2024 11:24:42 +0800 Subject: [PATCH 2/5] fix: fix value to satValue in RuneUtxoBalance --- src/indexer/types.ts | 2 +- src/indexer/updater.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/indexer/types.ts b/src/indexer/types.ts index d20471c..cc16c51 100644 --- a/src/indexer/types.ts +++ b/src/indexer/types.ts @@ -101,7 +101,7 @@ export type RuneSpentUtxoBalance = RuneUtxoBalance & { spentTxid: string }; export type RuneUtxoBalance = { txid: string; vout: number; - value?: number; + satValue: number; address?: string; scriptPubKey: Buffer; runeId: RuneLocation; diff --git a/src/indexer/updater.ts b/src/indexer/updater.ts index 90dd30b..ddf5919 100644 --- a/src/indexer/updater.ts +++ b/src/indexer/updater.ts @@ -298,7 +298,7 @@ export class RuneUpdater implements RuneBlockIndex { txid: tx.txid, vout, address: output.scriptPubKey.address, - value: output.value, + satValue: output.value ?? 0, }); } } @@ -467,7 +467,7 @@ export class RuneUpdater implements RuneBlockIndex { runeTicker: additionalBalance.runeTicker, amount: additionalBalance.amount, spentTxid: tx.txid, - value: additionalBalance.value, + satValue: additionalBalance.satValue, }); } } From 36721d301abd761c31187414ab0517a681758c7a Mon Sep 17 00:00:00 2001 From: KyleO_O <> Date: Sat, 11 May 2024 11:31:57 +0800 Subject: [PATCH 3/5] fix: fix test/updater.test.ts for utxoBalance --- test/updater.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/updater.test.ts b/test/updater.test.ts index b60e62f..a341585 100644 --- a/test/updater.test.ts +++ b/test/updater.test.ts @@ -790,6 +790,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); storage.getUtxoBalance.mockResolvedValueOnce([ @@ -801,6 +802,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); storage.getEtching.mockResolvedValue({ @@ -866,6 +868,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -955,6 +958,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -1003,6 +1007,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -1055,6 +1060,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -1111,6 +1117,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -1169,6 +1176,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -1230,6 +1238,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -1288,6 +1297,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -1346,6 +1356,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -1401,6 +1412,7 @@ describe('no runestone', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); storage.getEtching.mockResolvedValue({ @@ -1451,6 +1463,7 @@ describe('no runestone', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); storage.getEtching.mockResolvedValue({ @@ -1508,6 +1521,7 @@ describe('burning', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); storage.getEtching.mockResolvedValue({ @@ -1560,6 +1574,7 @@ describe('burning', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); storage.getEtching.mockResolvedValue({ From 341f9afb9502bfde7c2940aba824e345bdbe6f06 Mon Sep 17 00:00:00 2001 From: KyleO_O <> Date: Mon, 13 May 2024 11:38:13 +0800 Subject: [PATCH 4/5] fix: make value is a required field --- src/indexer/updater.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/indexer/updater.ts b/src/indexer/updater.ts index ddf5919..fecff2d 100644 --- a/src/indexer/updater.ts +++ b/src/indexer/updater.ts @@ -32,7 +32,7 @@ function isScriptPubKeyHexOpReturn(scriptPubKeyHex: string) { export type UpdaterTx = { txid: string; vin: ({ txid: string; vout: number; txinwitness: string[] } | { coinbase: string })[]; - vout: { scriptPubKey: { hex: string; address?: string }, value?: number }[]; + vout: { scriptPubKey: { hex: string; address?: string }, value: number }[]; }; export class RuneUpdater implements RuneBlockIndex { @@ -298,7 +298,7 @@ export class RuneUpdater implements RuneBlockIndex { txid: tx.txid, vout, address: output.scriptPubKey.address, - satValue: output.value ?? 0, + satValue: output.value, }); } } From 9471650fb879e752e28a1dda5bf9615240cb67d5 Mon Sep 17 00:00:00 2001 From: KyleO_O <> Date: Mon, 13 May 2024 11:44:44 +0800 Subject: [PATCH 5/5] fix: fix update.test.ts for value --- test/fixtures.ts | 1 + test/updater.test.ts | 44 +++++++++++++++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/test/fixtures.ts b/test/fixtures.ts index 24adb5a..32a7226 100644 --- a/test/fixtures.ts +++ b/test/fixtures.ts @@ -84,4 +84,5 @@ export const MAGIC_EDEN_OUTPUT = { hex: 'a914ea6b832a05c6ca578baa3836f3f25553d41068a587', address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', }, + value: 0, }; diff --git a/test/updater.test.ts b/test/updater.test.ts index a341585..f1dc56d 100644 --- a/test/updater.test.ts +++ b/test/updater.test.ts @@ -35,7 +35,7 @@ describe('deploy', () => { txid: 'txid', vin: [{ txid: 'parenttxid', vout: 1, txinwitness: [] }], vout: [ - { scriptPubKey: { hex: getDeployRunestoneHex({ etching: { rune: 'AAAAAAAAAAAAAA' } }) } }, + { scriptPubKey: { hex: getDeployRunestoneHex({ etching: { rune: 'AAAAAAAAAAAAAA' } }) }, value: 0 }, ], }; @@ -50,7 +50,7 @@ describe('deploy', () => { { txid: 'txid', vin: [{ txid: 'parenttxid', vout: 1, txinwitness: [] }], - vout: [{ scriptPubKey: { hex: getDeployRunestoneHex({ etching: { rune: 'AAAA' } }) } }], + vout: [{ scriptPubKey: { hex: getDeployRunestoneHex({ etching: { rune: 'AAAA' } }) }, value: 0 }], }, 88 ); @@ -73,6 +73,7 @@ describe('deploy', () => { scriptPubKey: { hex: getDeployRunestoneHex({ etching: { rune: 'AAAAAAAAAAAAAAAAAAAAAAAAAAA' } }), }, + value: 0, }, ], }; @@ -95,7 +96,7 @@ describe('deploy', () => { txid: 'txid', vin: [{ txid: 'parenttxid', vout: 1, txinwitness: ['08d6e3604a356bcf23', 'dead'] }], vout: [ - { scriptPubKey: { hex: getDeployRunestoneHex({ etching: { rune: 'AAAAAAAAAAAAAA' } }) } }, + { scriptPubKey: { hex: getDeployRunestoneHex({ etching: { rune: 'AAAAAAAAAAAAAA' } }) }, value: 0 }, ], }; rpc.getrawtransaction.mockResolvedValue({ @@ -121,7 +122,7 @@ describe('deploy', () => { txid: 'txid', vin: [{ txid: 'parenttxid', vout: 1, txinwitness: ['08d6e3604a356bcf23', 'dead'] }], vout: [ - { scriptPubKey: { hex: getDeployRunestoneHex({ etching: { rune: 'AAAAAAAAAAAAAA' } }) } }, + { scriptPubKey: { hex: getDeployRunestoneHex({ etching: { rune: 'AAAAAAAAAAAAAA' } }) }, value: 0 }, ], }; rpc.getrawtransaction.mockResolvedValue({ @@ -143,7 +144,7 @@ describe('deploy', () => { txid: 'txid', vin: [{ txid: 'parenttxid', vout: 1, txinwitness: ['04d6e3604a04356bcf23', 'dead'] }], vout: [ - { scriptPubKey: { hex: getDeployRunestoneHex({ etching: { rune: 'AAAAAAAAAAAAAA' } }) } }, + { scriptPubKey: { hex: getDeployRunestoneHex({ etching: { rune: 'AAAAAAAAAAAAAA' } }) }, value: 0 }, ], }; rpc.getrawtransaction.mockResolvedValue({ @@ -164,7 +165,7 @@ describe('deploy', () => { txid: 'txid', vin: [{ txid: 'parenttxid', vout: 1, txinwitness: ['08d6e3604a356bcf23', 'dead'] }], vout: [ - { scriptPubKey: { hex: getDeployRunestoneHex({ etching: { rune: 'AAAAAAAAAAAAAA' } }) } }, + { scriptPubKey: { hex: getDeployRunestoneHex({ etching: { rune: 'AAAAAAAAAAAAAA' } }) }, value: 0 }, ], }; rpc.getrawtransaction.mockResolvedValue({ @@ -189,7 +190,7 @@ describe('deploy', () => { const tx: UpdaterTx = { txid: 'txid', vin: [{ txid: 'parenttxid', vout: 1, txinwitness: [] }], - vout: [{ scriptPubKey: { hex: getDeployRunestoneHex({ etching: {} }) } }], + vout: [{ scriptPubKey: { hex: getDeployRunestoneHex({ etching: {} }) }, value: 0 }], }; await runeUpdater.indexRunes(tx, 88); @@ -210,6 +211,7 @@ describe('deploy', () => { scriptPubKey: { hex: getDeployRunestoneHex({ etching: { rune: 'AAAAAAAAAAAAAA' }, pointer: 123 }), }, + value: 0, }, ], }; @@ -246,6 +248,7 @@ describe('deploy', () => { edicts: [{ id: [0, 0], amount: 123, output: 1 }], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, ], @@ -283,6 +286,7 @@ describe('deploy', () => { ], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -338,6 +342,7 @@ describe('deploy', () => { edicts: [{ id: [0, 0], amount: 500, output: 1 }], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, ], @@ -374,6 +379,7 @@ describe('deploy', () => { ], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, ], @@ -410,6 +416,7 @@ describe('deploy', () => { ], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -456,6 +463,7 @@ describe('mint', () => { mint: [876543, 21], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, ], @@ -510,6 +518,7 @@ describe('mint', () => { mint: [876543, 21], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, ], @@ -561,6 +570,7 @@ describe('mint', () => { mint: [876543, 21], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, ], @@ -614,6 +624,7 @@ describe('mint', () => { pointer: 0, }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, ], @@ -661,6 +672,7 @@ describe('mint', () => { mint: [876543, 21], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -718,6 +730,7 @@ test('mint is valid for etching in same block', async () => { etching: { terms: { amount: 100, cap: 1 } }, }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, ], @@ -735,6 +748,7 @@ test('mint is valid for etching in same block', async () => { mint: [100000, 21], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, ], @@ -775,6 +789,7 @@ describe('edict', () => { ], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -849,6 +864,7 @@ describe('edict', () => { scriptPubKey: { hex: getDeployRunestoneHex({}), }, + value: 0, }, MAGIC_EDEN_OUTPUT, ], @@ -943,6 +959,7 @@ describe('edict', () => { scriptPubKey: { hex: getDeployRunestoneHex({ edicts: [{ id: [888, 8], amount: 400, output: 4 }] }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -992,6 +1009,7 @@ describe('edict', () => { scriptPubKey: { hex: getDeployRunestoneHex({}), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -1045,6 +1063,7 @@ describe('edict', () => { scriptPubKey: { hex: getDeployRunestoneHex({ pointer: 2 }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -1100,6 +1119,7 @@ describe('edict', () => { edicts: [{ id: [888, 8], amount: 0, output: 5 }], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -1159,6 +1179,7 @@ describe('edict', () => { edicts: [{ id: [888, 8], amount: 0, output: 5 }], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -1221,6 +1242,7 @@ describe('edict', () => { ], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -1280,6 +1302,7 @@ describe('edict', () => { edicts: [{ id: [888, 8], amount: 50, output: 5 }], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -1339,6 +1362,7 @@ describe('edict', () => { edicts: [{ id: [888, 8], amount: 140, output: 5 }], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -1399,6 +1423,7 @@ describe('no runestone', () => { scriptPubKey: { hex: Buffer.from([OP_RETURN]).toString('hex'), }, + value: 0, }, ], }; @@ -1449,6 +1474,7 @@ describe('no runestone', () => { scriptPubKey: { hex: Buffer.from([OP_RETURN]).toString('hex'), }, + value: 0, }, MAGIC_EDEN_OUTPUT, ], @@ -1502,11 +1528,13 @@ describe('burning', () => { scriptPubKey: { hex: getDeployRunestoneHex({ edicts: [{ id: [888, 8], amount: 400, output: 1 }] }), }, + value: 0, }, { scriptPubKey: { hex: Buffer.from([OP_RETURN]).toString('hex'), }, + value: 0, }, MAGIC_EDEN_OUTPUT, ], @@ -1555,11 +1583,13 @@ describe('burning', () => { vout: [ { scriptPubKey: { hex: getDeployRunestoneHex({ pointer: 1 }) }, + value: 0, }, { scriptPubKey: { hex: Buffer.from([OP_RETURN]).toString('hex'), }, + value: 0, }, MAGIC_EDEN_OUTPUT, ],