wallet/rpc/getbalances: add entry for 'mine.used' balance in results
This commit is contained in:
parent
44d8172323
commit
53c3c1ea9e
2 changed files with 31 additions and 0 deletions
|
@ -2409,6 +2409,7 @@ static UniValue getbalances(const JSONRPCRequest& request)
|
|||
" \"trusted\": xxx (numeric) trusted balance (outputs created by the wallet or confirmed outputs)\n"
|
||||
" \"untrusted_pending\": xxx (numeric) untrusted pending balance (outputs created by others that are in the mempool)\n"
|
||||
" \"immature\": xxx (numeric) balance from immature coinbase outputs\n"
|
||||
" \"used\": xxx (numeric) (only present if avoid_reuse is set) balance from coins sent to addresses that were previously spent from (potentially privacy violating)\n"
|
||||
" },\n"
|
||||
" \"watchonly\": { (object) watchonly balances (not present if wallet does not watch anything)\n"
|
||||
" \"trusted\": xxx (numeric) trusted balance (outputs created by the wallet or confirmed outputs)\n"
|
||||
|
@ -2441,6 +2442,12 @@ static UniValue getbalances(const JSONRPCRequest& request)
|
|||
balances_mine.pushKV("trusted", ValueFromAmount(bal.m_mine_trusted));
|
||||
balances_mine.pushKV("untrusted_pending", ValueFromAmount(bal.m_mine_untrusted_pending));
|
||||
balances_mine.pushKV("immature", ValueFromAmount(bal.m_mine_immature));
|
||||
if (wallet.IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE)) {
|
||||
// If the AVOID_REUSE flag is set, bal has been set to just the un-reused address balance. Get
|
||||
// the total balance, and then subtract bal to get the reused address balance.
|
||||
const auto full_bal = wallet.GetBalance(0, false);
|
||||
balances_mine.pushKV("used", ValueFromAmount(full_bal.m_mine_trusted + full_bal.m_mine_untrusted_pending - bal.m_mine_trusted - bal.m_mine_untrusted_pending));
|
||||
}
|
||||
balances.pushKV("mine", balances_mine);
|
||||
}
|
||||
if (wallet.HaveWatchOnly()) {
|
||||
|
|
|
@ -63,6 +63,12 @@ def assert_unspent(node, total_count=None, total_sum=None, reused_supported=None
|
|||
if reused_sum is not None:
|
||||
assert_approx(stats["reused"]["sum"], reused_sum, 0.001)
|
||||
|
||||
def assert_balances(node, mine):
|
||||
'''Make assertions about a node's getbalances output'''
|
||||
got = node.getbalances()["mine"]
|
||||
for k,v in mine.items():
|
||||
assert_approx(got[k], v, 0.001)
|
||||
|
||||
class AvoidReuseTest(BitcoinTestFramework):
|
||||
|
||||
def set_test_params(self):
|
||||
|
@ -140,6 +146,10 @@ class AvoidReuseTest(BitcoinTestFramework):
|
|||
|
||||
# listunspent should show 1 single, unused 10 btc output
|
||||
assert_unspent(self.nodes[1], total_count=1, total_sum=10, reused_supported=True, reused_count=0)
|
||||
# getbalances should show no used, 10 btc trusted
|
||||
assert_balances(self.nodes[1], mine={"used": 0, "trusted": 10})
|
||||
# node 0 should not show a used entry, as it does not enable avoid_reuse
|
||||
assert("used" not in self.nodes[0].getbalances()["mine"])
|
||||
|
||||
self.nodes[1].sendtoaddress(retaddr, 5)
|
||||
self.nodes[0].generate(1)
|
||||
|
@ -147,6 +157,8 @@ class AvoidReuseTest(BitcoinTestFramework):
|
|||
|
||||
# listunspent should show 1 single, unused 5 btc output
|
||||
assert_unspent(self.nodes[1], total_count=1, total_sum=5, reused_supported=True, reused_count=0)
|
||||
# getbalances should show no used, 5 btc trusted
|
||||
assert_balances(self.nodes[1], mine={"used": 0, "trusted": 5})
|
||||
|
||||
self.nodes[0].sendtoaddress(fundaddr, 10)
|
||||
self.nodes[0].generate(1)
|
||||
|
@ -154,11 +166,15 @@ class AvoidReuseTest(BitcoinTestFramework):
|
|||
|
||||
# listunspent should show 2 total outputs (5, 10 btc), one unused (5), one reused (10)
|
||||
assert_unspent(self.nodes[1], total_count=2, total_sum=15, reused_count=1, reused_sum=10)
|
||||
# getbalances should show 10 used, 5 btc trusted
|
||||
assert_balances(self.nodes[1], mine={"used": 10, "trusted": 5})
|
||||
|
||||
self.nodes[1].sendtoaddress(address=retaddr, amount=10, avoid_reuse=False)
|
||||
|
||||
# listunspent should show 1 total outputs (5 btc), unused
|
||||
assert_unspent(self.nodes[1], total_count=1, total_sum=5, reused_count=0)
|
||||
# getbalances should show no used, 5 btc trusted
|
||||
assert_balances(self.nodes[1], mine={"used": 0, "trusted": 5})
|
||||
|
||||
# node 1 should now have about 5 btc left (for both cases)
|
||||
assert_approx(self.nodes[1].getbalance(), 5, 0.001)
|
||||
|
@ -183,6 +199,8 @@ class AvoidReuseTest(BitcoinTestFramework):
|
|||
|
||||
# listunspent should show 1 single, unused 10 btc output
|
||||
assert_unspent(self.nodes[1], total_count=1, total_sum=10, reused_supported=True, reused_count=0)
|
||||
# getbalances should show no used, 10 btc trusted
|
||||
assert_balances(self.nodes[1], mine={"used": 0, "trusted": 10})
|
||||
|
||||
self.nodes[1].sendtoaddress(retaddr, 5)
|
||||
self.nodes[0].generate(1)
|
||||
|
@ -190,6 +208,8 @@ class AvoidReuseTest(BitcoinTestFramework):
|
|||
|
||||
# listunspent should show 1 single, unused 5 btc output
|
||||
assert_unspent(self.nodes[1], total_count=1, total_sum=5, reused_supported=True, reused_count=0)
|
||||
# getbalances should show no used, 5 btc trusted
|
||||
assert_balances(self.nodes[1], mine={"used": 0, "trusted": 5})
|
||||
|
||||
self.nodes[0].sendtoaddress(fundaddr, 10)
|
||||
self.nodes[0].generate(1)
|
||||
|
@ -197,6 +217,8 @@ class AvoidReuseTest(BitcoinTestFramework):
|
|||
|
||||
# listunspent should show 2 total outputs (5, 10 btc), one unused (5), one reused (10)
|
||||
assert_unspent(self.nodes[1], total_count=2, total_sum=15, reused_count=1, reused_sum=10)
|
||||
# getbalances should show 10 used, 5 btc trusted
|
||||
assert_balances(self.nodes[1], mine={"used": 10, "trusted": 5})
|
||||
|
||||
# node 1 should now have a balance of 5 (no dirty) or 15 (including dirty)
|
||||
assert_approx(self.nodes[1].getbalance(), 5, 0.001)
|
||||
|
@ -208,6 +230,8 @@ class AvoidReuseTest(BitcoinTestFramework):
|
|||
|
||||
# listunspent should show 2 total outputs (1, 10 btc), one unused (1), one reused (10)
|
||||
assert_unspent(self.nodes[1], total_count=2, total_sum=11, reused_count=1, reused_sum=10)
|
||||
# getbalances should show 10 used, 1 btc trusted
|
||||
assert_balances(self.nodes[1], mine={"used": 10, "trusted": 1})
|
||||
|
||||
# node 1 should now have about 1 btc left (no dirty) and 11 (including dirty)
|
||||
assert_approx(self.nodes[1].getbalance(), 1, 0.001)
|
||||
|
|
Loading…
Add table
Reference in a new issue