Merge #16383: rpcwallet: default include_watchonly to true for watchonly wallets
pull/764/head72eaab073b
tests: functional watch-only wallet tests (William Casarin)72ffbdc579
doc: add release note for include_watchonly default changes (William Casarin)003a3c73c0
rpcwallet: document include_watchonly default for watchonly wallets (William Casarin)a50d9e6c0b
rpcwallet: default include_watchonly to true for watchonly wallets (William Casarin) Pull request description: Right now it's a bit annoying to deal with watchonly wallets, many rpc commands have an `include_watchonly` argument that needs to be explicitly set. Wallets created with `createwallet` can have a `disable_private_keys` parameter, for those wallets we already know that they are watchonly, so there's no reason to have to explicitly ask for it for every command. Instead we check this wallet flag when the `include_watchonly` parameter isn't set. ACKs for top commit: achow101: Code review ACK72eaab073b
Sjors: ACK72eaab073b
promag: ACK72eaab073b
, code review only, didn't look closely to the test. kallewoof: ACK72eaab073b
fanquake: ACK72eaab073b
- I've looked over the changes, they make sense to me. Compiled and ran the tests etc. Tree-SHA512: d3646b55e97f386594d7efc994f0712f3888475c6a5dc7f131ac9f8c49bf5d4677182b88f42b34152abe1ad101ecadd152b4c20e9d3c1267190db36f77ab8bd7
commit
0d65106dce
@ -0,0 +1,8 @@
|
||||
RPC changes
|
||||
-----------
|
||||
|
||||
RPCs which have an `include_watchonly` argument or `includeWatching`
|
||||
option now default to `true` for watch-only wallets. Affected RPCs
|
||||
are: `getbalance`, `listreceivedbyaddress`, `listreceivedbylabel`,
|
||||
`listtransactions`, `listsinceblock`, `gettransaction`,
|
||||
`walletcreatefundedpsbt`, and `fundrawtransaction`.
|
@ -0,0 +1,107 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2018-2019 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
"""Test createwallet arguments.
|
||||
"""
|
||||
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
assert_raises_rpc_error
|
||||
)
|
||||
|
||||
|
||||
class CreateWalletWatchonlyTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = False
|
||||
self.num_nodes = 1
|
||||
self.supports_cli = True
|
||||
|
||||
def skip_test_if_missing_module(self):
|
||||
self.skip_if_no_wallet()
|
||||
|
||||
def run_test(self):
|
||||
node = self.nodes[0]
|
||||
|
||||
self.nodes[0].createwallet(wallet_name='default')
|
||||
def_wallet = node.get_wallet_rpc('default')
|
||||
|
||||
a1 = def_wallet.getnewaddress()
|
||||
wo_change = def_wallet.getnewaddress()
|
||||
wo_addr = def_wallet.getnewaddress()
|
||||
|
||||
self.nodes[0].createwallet(wallet_name='wo', disable_private_keys=True)
|
||||
wo_wallet = node.get_wallet_rpc('wo')
|
||||
|
||||
wo_wallet.importpubkey(pubkey=def_wallet.getaddressinfo(wo_addr)['pubkey'])
|
||||
wo_wallet.importpubkey(pubkey=def_wallet.getaddressinfo(wo_change)['pubkey'])
|
||||
|
||||
# generate some btc for testing
|
||||
node.generatetoaddress(101, a1)
|
||||
|
||||
# send 1 btc to our watch-only address
|
||||
txid = def_wallet.sendtoaddress(wo_addr, 1)
|
||||
self.nodes[0].generate(1)
|
||||
|
||||
# getbalance
|
||||
self.log.info('include_watchonly should default to true for watch-only wallets')
|
||||
self.log.info('Testing getbalance watch-only defaults')
|
||||
assert_equal(wo_wallet.getbalance(), 1)
|
||||
assert_equal(len(wo_wallet.listtransactions()), 1)
|
||||
assert_equal(wo_wallet.getbalance(include_watchonly=False), 0)
|
||||
|
||||
self.log.info('Testing listreceivedbyaddress watch-only defaults')
|
||||
result = wo_wallet.listreceivedbyaddress()
|
||||
assert_equal(len(result), 1)
|
||||
assert_equal(result[0]["involvesWatchonly"], True)
|
||||
result = wo_wallet.listreceivedbyaddress(include_watchonly=False)
|
||||
assert_equal(len(result), 0)
|
||||
|
||||
self.log.info('Testing listreceivedbylabel watch-only defaults')
|
||||
result = wo_wallet.listreceivedbylabel()
|
||||
assert_equal(len(result), 1)
|
||||
assert_equal(result[0]["involvesWatchonly"], True)
|
||||
result = wo_wallet.listreceivedbylabel(include_watchonly=False)
|
||||
assert_equal(len(result), 0)
|
||||
|
||||
self.log.info('Testing listtransactions watch-only defaults')
|
||||
result = wo_wallet.listtransactions()
|
||||
assert_equal(len(result), 1)
|
||||
assert_equal(result[0]["involvesWatchonly"], True)
|
||||
result = wo_wallet.listtransactions(include_watchonly=False)
|
||||
assert_equal(len(result), 0)
|
||||
|
||||
self.log.info('Testing listsinceblock watch-only defaults')
|
||||
result = wo_wallet.listsinceblock()
|
||||
assert_equal(len(result["transactions"]), 1)
|
||||
assert_equal(result["transactions"][0]["involvesWatchonly"], True)
|
||||
result = wo_wallet.listsinceblock(include_watchonly=False)
|
||||
assert_equal(len(result["transactions"]), 0)
|
||||
|
||||
self.log.info('Testing gettransaction watch-only defaults')
|
||||
result = wo_wallet.gettransaction(txid)
|
||||
assert_equal(result["details"][0]["involvesWatchonly"], True)
|
||||
result = wo_wallet.gettransaction(txid=txid, include_watchonly=False)
|
||||
assert_equal(len(result["details"]), 0)
|
||||
|
||||
self.log.info('Testing walletcreatefundedpsbt watch-only defaults')
|
||||
inputs = []
|
||||
outputs = [{a1: 0.5}]
|
||||
options = {'changeAddress': wo_change}
|
||||
no_wo_options = {'changeAddress': wo_change, 'includeWatching': False}
|
||||
|
||||
result = wo_wallet.walletcreatefundedpsbt(inputs=inputs, outputs=outputs, options=options)
|
||||
assert_equal("psbt" in result, True)
|
||||
assert_raises_rpc_error(-4, "Insufficient funds", wo_wallet.walletcreatefundedpsbt, inputs, outputs, 0, no_wo_options)
|
||||
|
||||
self.log.info('Testing fundrawtransaction watch-only defaults')
|
||||
rawtx = wo_wallet.createrawtransaction(inputs=inputs, outputs=outputs)
|
||||
result = wo_wallet.fundrawtransaction(hexstring=rawtx, options=options)
|
||||
assert_equal("hex" in result, True)
|
||||
assert_raises_rpc_error(-4, "Insufficient funds", wo_wallet.fundrawtransaction, rawtx, no_wo_options)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
CreateWalletWatchonlyTest().main()
|
Loading…
Reference in new issue