rpc: add input confirmations to getrawtransaction
This commit is contained in:
parent
bd8328ceb9
commit
fea930aa8c
@ -103,6 +103,10 @@ class SpentIndexTest(BitcoinTestFramework):
|
|||||||
assert_equal(txVerbose3["vin"][0]["value"], Decimal(unspent[0]["amount"]))
|
assert_equal(txVerbose3["vin"][0]["value"], Decimal(unspent[0]["amount"]))
|
||||||
assert_equal(txVerbose3["vin"][0]["valueSat"], 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
|
# Check the database index
|
||||||
self.nodes[0].generate(1)
|
self.nodes[0].generate(1)
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
@ -112,6 +116,10 @@ class SpentIndexTest(BitcoinTestFramework):
|
|||||||
assert_equal(txVerbose4["vin"][0]["value"], Decimal(unspent[0]["amount"]))
|
assert_equal(txVerbose4["vin"][0]["value"], Decimal(unspent[0]["amount"]))
|
||||||
assert_equal(txVerbose4["vin"][0]["valueSat"], 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"
|
print "Passed\n"
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,6 +83,13 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
|
|||||||
CSpentIndexValue spentInfo;
|
CSpentIndexValue spentInfo;
|
||||||
CSpentIndexKey spentKey(txin.prevout.hash, txin.prevout.n);
|
CSpentIndexKey spentKey(txin.prevout.hash, txin.prevout.n);
|
||||||
if (GetSpentIndex(spentKey, spentInfo)) {
|
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("value", ValueFromAmount(spentInfo.satoshis)));
|
||||||
in.push_back(Pair("valueSat", spentInfo.satoshis));
|
in.push_back(Pair("valueSat", spentInfo.satoshis));
|
||||||
if (spentInfo.addressType == 1) {
|
if (spentInfo.addressType == 1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user