diff --git a/src/indexer/types.ts b/src/indexer/types.ts index ea50f08..cc16c51 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; + satValue: number; address?: string; scriptPubKey: Buffer; runeId: RuneLocation; diff --git a/src/indexer/updater.ts b/src/indexer/updater.ts index 98090ab..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 } }[]; + 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, + satValue: output.value, }); } } @@ -466,6 +467,7 @@ export class RuneUpdater implements RuneBlockIndex { runeTicker: additionalBalance.runeTicker, amount: additionalBalance.amount, spentTxid: tx.txid, + satValue: additionalBalance.satValue, }); } } 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 b60e62f..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, @@ -790,6 +805,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); storage.getUtxoBalance.mockResolvedValueOnce([ @@ -801,6 +817,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); storage.getEtching.mockResolvedValue({ @@ -847,6 +864,7 @@ describe('edict', () => { scriptPubKey: { hex: getDeployRunestoneHex({}), }, + value: 0, }, MAGIC_EDEN_OUTPUT, ], @@ -866,6 +884,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -940,6 +959,7 @@ describe('edict', () => { scriptPubKey: { hex: getDeployRunestoneHex({ edicts: [{ id: [888, 8], amount: 400, output: 4 }] }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -955,6 +975,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -988,6 +1009,7 @@ describe('edict', () => { scriptPubKey: { hex: getDeployRunestoneHex({}), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -1003,6 +1025,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -1040,6 +1063,7 @@ describe('edict', () => { scriptPubKey: { hex: getDeployRunestoneHex({ pointer: 2 }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -1055,6 +1079,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -1094,6 +1119,7 @@ describe('edict', () => { edicts: [{ id: [888, 8], amount: 0, output: 5 }], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -1111,6 +1137,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -1152,6 +1179,7 @@ describe('edict', () => { edicts: [{ id: [888, 8], amount: 0, output: 5 }], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -1169,6 +1197,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -1213,6 +1242,7 @@ describe('edict', () => { ], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -1230,6 +1260,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -1271,6 +1302,7 @@ describe('edict', () => { edicts: [{ id: [888, 8], amount: 50, output: 5 }], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -1288,6 +1320,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -1329,6 +1362,7 @@ describe('edict', () => { edicts: [{ id: [888, 8], amount: 140, output: 5 }], }), }, + value: 0, }, MAGIC_EDEN_OUTPUT, MAGIC_EDEN_OUTPUT, @@ -1346,6 +1380,7 @@ describe('edict', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); @@ -1388,6 +1423,7 @@ describe('no runestone', () => { scriptPubKey: { hex: Buffer.from([OP_RETURN]).toString('hex'), }, + value: 0, }, ], }; @@ -1401,6 +1437,7 @@ describe('no runestone', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); storage.getEtching.mockResolvedValue({ @@ -1437,6 +1474,7 @@ describe('no runestone', () => { scriptPubKey: { hex: Buffer.from([OP_RETURN]).toString('hex'), }, + value: 0, }, MAGIC_EDEN_OUTPUT, ], @@ -1451,6 +1489,7 @@ describe('no runestone', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); storage.getEtching.mockResolvedValue({ @@ -1489,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, ], @@ -1508,6 +1549,7 @@ describe('burning', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); storage.getEtching.mockResolvedValue({ @@ -1541,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, ], @@ -1560,6 +1604,7 @@ describe('burning', () => { runeId: { block: 888, tx: 8 }, scriptPubKey: Buffer.from('a914ea6b832a05c6ca578baa3836f3f25553d41068a587', 'hex'), address: '3P4WqXDbSLRhzo2H6MT6YFbvBKBDPLbVtQ', + satValue: 0, }, ]); storage.getEtching.mockResolvedValue({