Auto merge of #2522 - bitcartel:2446_coinbase_field_listunspent, r=daira
Add generated field to listunspent output Closes #2446
This commit is contained in:
@@ -72,6 +72,18 @@ class WalletTest (BitcoinTestFramework):
|
|||||||
node0utxos = self.nodes[0].listunspent(1)
|
node0utxos = self.nodes[0].listunspent(1)
|
||||||
assert_equal(len(node0utxos), 3)
|
assert_equal(len(node0utxos), 3)
|
||||||
|
|
||||||
|
# Check 'generated' field of listunspent
|
||||||
|
# Node 0: has one coinbase utxo and two regular utxos
|
||||||
|
assert_equal(sum(int(uxto["generated"] is True) for uxto in node0utxos), 1)
|
||||||
|
# Node 1: has 101 coinbase utxos and no regular utxos
|
||||||
|
node1utxos = self.nodes[1].listunspent(1)
|
||||||
|
assert_equal(len(node1utxos), 101)
|
||||||
|
assert_equal(sum(int(uxto["generated"] is True) for uxto in node1utxos), 101)
|
||||||
|
# Node 2: has no coinbase utxos and two regular utxos
|
||||||
|
node2utxos = self.nodes[2].listunspent(1)
|
||||||
|
assert_equal(len(node2utxos), 2)
|
||||||
|
assert_equal(sum(int(uxto["generated"] is True) for uxto in node2utxos), 0)
|
||||||
|
|
||||||
# create both transactions
|
# create both transactions
|
||||||
txns_to_send = []
|
txns_to_send = []
|
||||||
for utxo in node0utxos:
|
for utxo in node0utxos:
|
||||||
|
|||||||
@@ -2334,6 +2334,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
|
|||||||
" {\n"
|
" {\n"
|
||||||
" \"txid\" : \"txid\", (string) the transaction id \n"
|
" \"txid\" : \"txid\", (string) the transaction id \n"
|
||||||
" \"vout\" : n, (numeric) the vout value\n"
|
" \"vout\" : n, (numeric) the vout value\n"
|
||||||
|
" \"generated\" : true|false (boolean) true if txout is a coinbase transaction output\n"
|
||||||
" \"address\" : \"address\", (string) the zcash address\n"
|
" \"address\" : \"address\", (string) the zcash address\n"
|
||||||
" \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n"
|
" \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n"
|
||||||
" \"scriptPubKey\" : \"key\", (string) the script key\n"
|
" \"scriptPubKey\" : \"key\", (string) the script key\n"
|
||||||
@@ -2396,6 +2397,7 @@ UniValue listunspent(const UniValue& params, bool fHelp)
|
|||||||
UniValue entry(UniValue::VOBJ);
|
UniValue entry(UniValue::VOBJ);
|
||||||
entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
|
entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
|
||||||
entry.push_back(Pair("vout", out.i));
|
entry.push_back(Pair("vout", out.i));
|
||||||
|
entry.push_back(Pair("generated", out.tx->IsCoinBase()));
|
||||||
CTxDestination address;
|
CTxDestination address;
|
||||||
if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) {
|
if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) {
|
||||||
entry.push_back(Pair("address", CBitcoinAddress(address).ToString()));
|
entry.push_back(Pair("address", CBitcoinAddress(address).ToString()));
|
||||||
|
|||||||
Reference in New Issue
Block a user