Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track coinbase outputs #104

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(&ltx.info.txid, changelog);
}
};
}

Expand Down
26 changes: 14 additions & 12 deletions test/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down