Skip to content

Commit dcf2112

Browse files
committed
Add safe flag to listunspent result
1 parent af61d9f commit dcf2112

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

qa/rpc-tests/listtransactions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ def get_unconfirmed_utxo_entry(node, txid_to_match):
126126
assert_array_result(self.nodes[1].listtransactions(), {"txid": txid_1}, {"bip125-replaceable":"no"})
127127

128128
# Tx2 will build off txid_1, still not opting in to RBF.
129+
utxo_to_use = get_unconfirmed_utxo_entry(self.nodes[0], txid_1)
130+
assert_equal(utxo_to_use["safe"], True)
129131
utxo_to_use = get_unconfirmed_utxo_entry(self.nodes[1], txid_1)
132+
utxo_to_use = get_unconfirmed_utxo_entry(self.nodes[1], txid_1)
133+
assert_equal(utxo_to_use["safe"], False)
130134

131135
# Create tx2 using createrawtransaction
132136
inputs = [{"txid":utxo_to_use["txid"], "vout":utxo_to_use["vout"]}]

src/wallet/rpcwallet.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,9 +2506,7 @@ UniValue listunspent(const JSONRPCRequest& request)
25062506
" ,...\n"
25072507
" ]\n"
25082508
"4. include_unsafe (bool, optional, default=true) Include outputs that are not safe to spend\n"
2509-
" because they come from unconfirmed untrusted transactions or unconfirmed\n"
2510-
" replacement transactions (cases where we are less sure that a conflicting\n"
2511-
" transaction won't be mined).\n"
2509+
" See description of \"safe\" attribute below.\n"
25122510
"\nResult\n"
25132511
"[ (array of json object)\n"
25142512
" {\n"
@@ -2521,7 +2519,10 @@ UniValue listunspent(const JSONRPCRequest& request)
25212519
" \"confirmations\" : n, (numeric) The number of confirmations\n"
25222520
" \"redeemScript\" : n (string) The redeemScript if scriptPubKey is P2SH\n"
25232521
" \"spendable\" : xxx, (bool) Whether we have the private keys to spend this output\n"
2524-
" \"solvable\" : xxx (bool) Whether we know how to spend this output, ignoring the lack of keys\n"
2522+
" \"solvable\" : xxx, (bool) Whether we know how to spend this output, ignoring the lack of keys\n"
2523+
" \"safe\" : xxx (bool) Whether this output is considered safe to spend. Unconfirmed transactions\n"
2524+
" from outside keys and unconfirmed replacement transactions are considered unsafe\n"
2525+
" and are not eligible for spending by fundrawtransaction and sendtoaddress.\n"
25252526
" }\n"
25262527
" ,...\n"
25272528
"]\n"
@@ -2606,6 +2607,7 @@ UniValue listunspent(const JSONRPCRequest& request)
26062607
entry.push_back(Pair("confirmations", out.nDepth));
26072608
entry.push_back(Pair("spendable", out.fSpendable));
26082609
entry.push_back(Pair("solvable", out.fSolvable));
2610+
entry.push_back(Pair("safe", out.fSafe));
26092611
results.push_back(entry);
26102612
}
26112613

0 commit comments

Comments
 (0)