mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
Merge bitcoin/bitcoin#20583: rpc: Add missing BlockUntilSyncedToCurrentChain to wallet RPCs
fa5362a9a0
rpc: Add missing BlockUntilSyncedToCurrentChain to wallet RPCs (MarcoFalke) Pull request description: Wallet RPCs that allow a rescan based on block-timestamp or block-height need to sync with the active chain first, because the user might assume the wallet is up-to-date with the latest block they got reported via a blockchain RPC. ACKs for top commit: meshcollider: utACKfa5362a9a0
Tree-SHA512: d4831f1f08f854f9a49fc969de86c438f856e41c2163c801a6ff36dc2f6299cb342b44663279c524a8b7ca9a50895db1243cd7d49bed79277ada857213f20a26
This commit is contained in:
commit
89ea2b3809
3 changed files with 15 additions and 5 deletions
|
@ -1346,6 +1346,11 @@ RPCHelpMan importmulti()
|
||||||
{
|
{
|
||||||
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(mainRequest);
|
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(mainRequest);
|
||||||
if (!pwallet) return NullUniValue;
|
if (!pwallet) return NullUniValue;
|
||||||
|
CWallet& wallet{*pwallet};
|
||||||
|
|
||||||
|
// Make sure the results are valid at least up to the most recent block
|
||||||
|
// the user could have gotten from another RPC command prior to now
|
||||||
|
wallet.BlockUntilSyncedToCurrentChain();
|
||||||
|
|
||||||
RPCTypeCheck(mainRequest.params, {UniValue::VARR, UniValue::VOBJ});
|
RPCTypeCheck(mainRequest.params, {UniValue::VARR, UniValue::VOBJ});
|
||||||
|
|
||||||
|
@ -1649,6 +1654,11 @@ RPCHelpMan importdescriptors()
|
||||||
{
|
{
|
||||||
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(main_request);
|
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(main_request);
|
||||||
if (!pwallet) return NullUniValue;
|
if (!pwallet) return NullUniValue;
|
||||||
|
CWallet& wallet{*pwallet};
|
||||||
|
|
||||||
|
// Make sure the results are valid at least up to the most recent block
|
||||||
|
// the user could have gotten from another RPC command prior to now
|
||||||
|
wallet.BlockUntilSyncedToCurrentChain();
|
||||||
|
|
||||||
// Make sure wallet is a descriptor wallet
|
// Make sure wallet is a descriptor wallet
|
||||||
if (!pwallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
|
if (!pwallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
|
||||||
|
|
|
@ -3304,6 +3304,11 @@ static RPCHelpMan rescanblockchain()
|
||||||
{
|
{
|
||||||
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
|
||||||
if (!pwallet) return NullUniValue;
|
if (!pwallet) return NullUniValue;
|
||||||
|
CWallet& wallet{*pwallet};
|
||||||
|
|
||||||
|
// Make sure the results are valid at least up to the most recent block
|
||||||
|
// the user could have gotten from another RPC command prior to now
|
||||||
|
wallet.BlockUntilSyncedToCurrentChain();
|
||||||
|
|
||||||
WalletRescanReserver reserver(*pwallet);
|
WalletRescanReserver reserver(*pwallet);
|
||||||
if (!reserver.reserve()) {
|
if (!reserver.reserve()) {
|
||||||
|
|
|
@ -65,7 +65,6 @@ class ImportMultiTest(BitcoinTestFramework):
|
||||||
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
|
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
|
||||||
self.generate(self.nodes[1], 1, sync_fun=self.no_op)
|
self.generate(self.nodes[1], 1, sync_fun=self.no_op)
|
||||||
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
||||||
self.nodes[1].syncwithvalidationinterfacequeue() # Sync the timestamp to the wallet, so that importmulti works
|
|
||||||
|
|
||||||
node0_address1 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
node0_address1 = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress())
|
||||||
|
|
||||||
|
@ -260,7 +259,6 @@ class ImportMultiTest(BitcoinTestFramework):
|
||||||
self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00)
|
self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00)
|
||||||
self.generate(self.nodes[1], 1, sync_fun=self.no_op)
|
self.generate(self.nodes[1], 1, sync_fun=self.no_op)
|
||||||
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
||||||
self.nodes[1].syncwithvalidationinterfacequeue()
|
|
||||||
|
|
||||||
self.log.info("Should import a p2sh")
|
self.log.info("Should import a p2sh")
|
||||||
self.test_importmulti({"scriptPubKey": {"address": multisig.p2sh_addr},
|
self.test_importmulti({"scriptPubKey": {"address": multisig.p2sh_addr},
|
||||||
|
@ -281,7 +279,6 @@ class ImportMultiTest(BitcoinTestFramework):
|
||||||
self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00)
|
self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00)
|
||||||
self.generate(self.nodes[1], 1, sync_fun=self.no_op)
|
self.generate(self.nodes[1], 1, sync_fun=self.no_op)
|
||||||
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
||||||
self.nodes[1].syncwithvalidationinterfacequeue()
|
|
||||||
|
|
||||||
self.log.info("Should import a p2sh with respective redeem script")
|
self.log.info("Should import a p2sh with respective redeem script")
|
||||||
self.test_importmulti({"scriptPubKey": {"address": multisig.p2sh_addr},
|
self.test_importmulti({"scriptPubKey": {"address": multisig.p2sh_addr},
|
||||||
|
@ -302,7 +299,6 @@ class ImportMultiTest(BitcoinTestFramework):
|
||||||
self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00)
|
self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00)
|
||||||
self.generate(self.nodes[1], 1, sync_fun=self.no_op)
|
self.generate(self.nodes[1], 1, sync_fun=self.no_op)
|
||||||
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
||||||
self.nodes[1].syncwithvalidationinterfacequeue()
|
|
||||||
|
|
||||||
self.log.info("Should import a p2sh with respective redeem script and private keys")
|
self.log.info("Should import a p2sh with respective redeem script and private keys")
|
||||||
self.test_importmulti({"scriptPubKey": {"address": multisig.p2sh_addr},
|
self.test_importmulti({"scriptPubKey": {"address": multisig.p2sh_addr},
|
||||||
|
@ -328,7 +324,6 @@ class ImportMultiTest(BitcoinTestFramework):
|
||||||
self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00)
|
self.nodes[1].sendtoaddress(multisig.p2sh_addr, 10.00)
|
||||||
self.generate(self.nodes[1], 1, sync_fun=self.no_op)
|
self.generate(self.nodes[1], 1, sync_fun=self.no_op)
|
||||||
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']
|
||||||
self.nodes[1].syncwithvalidationinterfacequeue()
|
|
||||||
|
|
||||||
self.log.info("Should import a p2sh with respective redeem script and private keys")
|
self.log.info("Should import a p2sh with respective redeem script and private keys")
|
||||||
self.test_importmulti({"scriptPubKey": {"address": multisig.p2sh_addr},
|
self.test_importmulti({"scriptPubKey": {"address": multisig.p2sh_addr},
|
||||||
|
|
Loading…
Add table
Reference in a new issue