Skip to content

Commit 645ae33

Browse files
authored
Merge pull request #20 from braydonf/0.12.1-bitcore-inputconfs
rpc: add input confirmations to getrawtransaction
2 parents 956b424 + fea930a commit 645ae33

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

qa/rpc-tests/spentindex.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ def run_test(self):
103103
assert_equal(txVerbose3["vin"][0]["value"], Decimal(unspent[0]["amount"]))
104104
assert_equal(txVerbose3["vin"][0]["valueSat"], amount)
105105

106+
# Check that the input confirmations work for mempool unconfirmed transactions
107+
assert_equal(txVerbose3["vin"][0].has_key("height"), False)
108+
assert_equal(txVerbose3["vin"][0]["confirmations"], 0)
109+
106110
# Check the database index
107111
self.nodes[0].generate(1)
108112
self.sync_all()
@@ -112,6 +116,10 @@ def run_test(self):
112116
assert_equal(txVerbose4["vin"][0]["value"], Decimal(unspent[0]["amount"]))
113117
assert_equal(txVerbose4["vin"][0]["valueSat"], amount)
114118

119+
# Check that the input confirmations work
120+
assert_equal(txVerbose4["vin"][0]["height"], 107)
121+
assert_equal(txVerbose4["vin"][0]["confirmations"], 1)
122+
115123
print "Passed\n"
116124

117125

src/rpcrawtransaction.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
8383
CSpentIndexValue spentInfo;
8484
CSpentIndexKey spentKey(txin.prevout.hash, txin.prevout.n);
8585
if (GetSpentIndex(spentKey, spentInfo)) {
86+
// Unconfirmed spentInfo have a height of -1, block 0 is unspendable
87+
if (spentInfo.blockHeight > 0) {
88+
in.push_back(Pair("height", spentInfo.blockHeight));
89+
in.push_back(Pair("confirmations", 1 + chainActive.Height() - spentInfo.blockHeight));
90+
} else {
91+
in.push_back(Pair("confirmations", 0));
92+
}
8693
in.push_back(Pair("value", ValueFromAmount(spentInfo.satoshis)));
8794
in.push_back(Pair("valueSat", spentInfo.satoshis));
8895
if (spentInfo.addressType == 1) {

0 commit comments

Comments
 (0)