Skip to content

Commit

Permalink
Merge pull request #20 from braydonf/0.12.1-bitcore-inputconfs
Browse files Browse the repository at this point in the history
rpc: add input confirmations to getrawtransaction
  • Loading branch information
kleetus authored Jun 15, 2016
2 parents 956b424 + fea930a commit 645ae33
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions qa/rpc-tests/spentindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ def run_test(self):
assert_equal(txVerbose3["vin"][0]["value"], Decimal(unspent[0]["amount"]))
assert_equal(txVerbose3["vin"][0]["valueSat"], amount)

# Check that the input confirmations work for mempool unconfirmed transactions
assert_equal(txVerbose3["vin"][0].has_key("height"), False)
assert_equal(txVerbose3["vin"][0]["confirmations"], 0)

# Check the database index
self.nodes[0].generate(1)
self.sync_all()
Expand All @@ -112,6 +116,10 @@ def run_test(self):
assert_equal(txVerbose4["vin"][0]["value"], Decimal(unspent[0]["amount"]))
assert_equal(txVerbose4["vin"][0]["valueSat"], amount)

# Check that the input confirmations work
assert_equal(txVerbose4["vin"][0]["height"], 107)
assert_equal(txVerbose4["vin"][0]["confirmations"], 1)

print "Passed\n"


Expand Down
7 changes: 7 additions & 0 deletions src/rpcrawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
CSpentIndexValue spentInfo;
CSpentIndexKey spentKey(txin.prevout.hash, txin.prevout.n);
if (GetSpentIndex(spentKey, spentInfo)) {
// Unconfirmed spentInfo have a height of -1, block 0 is unspendable
if (spentInfo.blockHeight > 0) {
in.push_back(Pair("height", spentInfo.blockHeight));
in.push_back(Pair("confirmations", 1 + chainActive.Height() - spentInfo.blockHeight));
} else {
in.push_back(Pair("confirmations", 0));
}
in.push_back(Pair("value", ValueFromAmount(spentInfo.satoshis)));
in.push_back(Pair("valueSat", spentInfo.satoshis));
if (spentInfo.addressType == 1) {
Expand Down

0 comments on commit 645ae33

Please sign in to comment.