From 45332025d20f1fd5f8c231160950f6de4da96fb6 Mon Sep 17 00:00:00 2001 From: Andrew Toth Date: Thu, 9 Jun 2022 15:08:41 -0400 Subject: [PATCH 1/2] Track coinbase transactions in the indexer --- src/indexer.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/indexer.rs b/src/indexer.rs index 61643dc..c2c6d99 100644 --- a/src/indexer.rs +++ b/src/indexer.rs @@ -195,10 +195,10 @@ impl Indexer { } // "listtransactions"/"listsinceblock" in fact lists transaction outputs and not transactions. - // for "receive" txs, it returns one entry per wallet-owned output in the tx. + // for "receive"/"generate"/"immature" txs, it returns one entry per wallet-owned output in the tx. // for "send" txs, it returns one entry for every output in the tx, owned or not. match ltx.detail.category { - TxCategory::Receive => { + TxCategory::Receive | TxCategory::Generate | TxCategory::Immature => { // incoming txouts are easy: bitcoind tells us the associated // address and label, giving us all the information we need in // order to save the txo to the index. @@ -212,8 +212,10 @@ impl Indexer { // the prevouts are guarranted to be indexed. buffered_outgoing.insert(ltx.info.txid, ltx.info.confirmations); } - // ignore mining-related transactions - TxCategory::Generate | TxCategory::Immature | TxCategory::Orphan => (), + TxCategory::Orphan => { + // remove orphan txs + self.purge_tx(<x.info.txid, changelog); + } }; } From 30b32b5eea892b716f142f3bced7bcd8fe336eb3 Mon Sep 17 00:00:00 2001 From: Andrew Toth Date: Thu, 9 Jun 2022 15:09:02 -0400 Subject: [PATCH 2/2] Add test for coinbase tracking --- test/tests.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/test/tests.sh b/test/tests.sh index 4623c11..a84ec66 100755 --- a/test/tests.sh +++ b/test/tests.sh @@ -16,6 +16,7 @@ source scripts/setup-env.sh # Send some funds addr=`ele1 getunusedaddress` +btc generatetoaddress 1 $addr > /dev/null btc sendtoaddress $addr 1.234 > /dev/null btc generatetoaddress 1 `btc getnewaddress` > /dev/null btc sendtoaddress $addr 5.678 > /dev/null @@ -33,17 +34,18 @@ if [[ $FEATURES == *"electrum"* ]]; then echo - Testing history hist=`ele1 onchain_history` - test `jq -r '.transactions | length' <<< "$hist"` == 2 - test `jq -r .transactions[0].confirmations <<< "$hist"` == 1 - test `jq -r .transactions[1].confirmations <<< "$hist"` == 0 - test `jq -r .summary.end_balance <<< "$hist"` == 6.912 - test `jq -r .transactions[0].bc_value <<< "$hist" | cut -d' ' -f1` == 1.234 + test `jq -r '.transactions | length' <<< "$hist"` == 3 + test `jq -r .transactions[0].confirmations <<< "$hist"` == 2 + test `jq -r .transactions[1].confirmations <<< "$hist"` == 1 + test `jq -r .transactions[2].confirmations <<< "$hist"` == 0 + test `jq -r .summary.end.BTC_balance <<< "$hist"` == 56.912 + test `jq -r .transactions[1].bc_value <<< "$hist" | cut -d' ' -f1` == 1.234 echo - Testing listunspent utxos=`ele1 listunspent` - test `jq -r length <<< "$utxos"` == 2 + test `jq -r length <<< "$utxos"` == 3 test `jq -r .[0].address <<< "$utxos"` == $addr - test `jq -r '.[] | select(.height != 0) | .value' <<< "$utxos"` == 1.234 + test `jq -r '.[] | select(.height == 112) | .value' <<< "$utxos"` == 1.234 fi # Test HTTP API @@ -55,13 +57,13 @@ if [[ $FEATURES == *"http"* ]]; then echo = Running HTTP tests = echo - Testing /txs/since/:height txs=`get /txs/since/0` - test `jq -r length <<< "$txs"` == 2 - test `jq -r .[0].funding[0].address <<< "$txs"` == $addr - test `jq -r .[0].funding[0].amount <<< "$txs"` == 123400000 - test `jq -r .[1].funding[0].amount <<< "$txs"` == 567800000 + test `jq -r length <<< "$txs"` == 3 + test `jq -r .[1].funding[0].address <<< "$txs"` == $addr + test `jq -r .[1].funding[0].amount <<< "$txs"` == 123400000 + test `jq -r .[2].funding[0].amount <<< "$txs"` == 567800000 echo - Testing /tx/:txid - txid=`jq -r .[0].txid <<< "$txs"` + txid=`jq -r .[1].txid <<< "$txs"` tx=`get /tx/$txid` test `jq -r .balance_change <<< "$tx"` == 123400000 test `jq -r .txid <<< "$tx"` == $txid