From 1219d3d9803c4dd42777231f8d4b98f562fb04df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=97=E5=AE=87?= Date: Tue, 21 Jun 2022 01:45:50 +0800 Subject: [PATCH] Update `create_wallet` to support Core v0.23.0 --- client/src/client.rs | 12 +++++++++--- integration_test/run.sh | 4 ++++ integration_test/src/main.rs | 38 ++++++++++++++++++++++++++---------- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/client/src/client.rs b/client/src/client.rs index 57f70678..ea03c6fc 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -271,22 +271,28 @@ pub trait RpcApi: Sized { fn create_wallet( &self, - wallet: &str, + wallet_name: &str, disable_private_keys: Option, blank: Option, passphrase: Option<&str>, avoid_reuse: Option, + descriptors: Option, + load_on_startup: Option, + external_signer: Option, ) -> Result { let mut args = [ - wallet.into(), + wallet_name.into(), opt_into_json(disable_private_keys)?, opt_into_json(blank)?, opt_into_json(passphrase)?, opt_into_json(avoid_reuse)?, + opt_into_json(descriptors)?, + opt_into_json(load_on_startup)?, + opt_into_json(external_signer)?, ]; self.call( "createwallet", - handle_defaults(&mut args, &[false.into(), false.into(), into_json("")?, false.into()]), + handle_defaults(&mut args, &[false.into(), false.into(), into_json("")?, false.into(), true.into(), false.into(), false.into()]), ) } diff --git a/integration_test/run.sh b/integration_test/run.sh index a442ae47..6fc26a19 100755 --- a/integration_test/run.sh +++ b/integration_test/run.sh @@ -21,11 +21,15 @@ sleep 3 BLOCKFILTERARG="" if bitcoind -version | grep -q "v0\.\(19\|2\)"; then BLOCKFILTERARG="-blockfilterindex=1" +elif bitcoind -version | grep -q "v\(22\|23\)"; then + BLOCKFILTERARG="-blockfilterindex=1" fi FALLBACKFEEARG="" if bitcoind -version | grep -q "v0\.2"; then FALLBACKFEEARG="-fallbackfee=0.00001000" +elif bitcoind -version | grep -q "v\(22\|23\)"; then + FALLBACKFEEARG="-fallbackfee=0.00001000" fi bitcoind -regtest $BLOCKFILTERARG $FALLBACKFEEARG \ diff --git a/integration_test/src/main.rs b/integration_test/src/main.rs index a8b7a33e..adf0f2bb 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -27,8 +27,8 @@ use bitcoin::hashes::hex::{FromHex, ToHex}; use bitcoin::hashes::Hash; use bitcoin::secp256k1; use bitcoin::{ - Address, Amount, Network, OutPoint, PrivateKey, Script, EcdsaSighashType, SignedAmount, Transaction, - TxIn, TxOut, Txid, Witness, + Address, Amount, EcdsaSighashType, Network, OutPoint, PrivateKey, Script, SignedAmount, + Transaction, TxIn, TxOut, Txid, Witness, }; use bitcoincore_rpc::bitcoincore_rpc_json::{ GetBlockTemplateModes, GetBlockTemplateRules, ScanTxOutRequest, @@ -134,7 +134,7 @@ fn main() { unsafe { VERSION = cl.version().unwrap() }; println!("Version: {}", version()); - cl.create_wallet("testwallet", None, None, None, None).unwrap(); + cl.create_wallet("testwallet", None, None, None, None, Some(false), None, None).unwrap(); test_get_mining_info(&cl); test_get_blockchain_info(&cl); @@ -596,8 +596,9 @@ fn test_sign_raw_transaction_with_send_raw_transaction(cl: &Client) { }], }; - let res = - cl.sign_raw_transaction_with_key(&tx, &[sk], None, Some(EcdsaSighashType::All.into())).unwrap(); + let res = cl + .sign_raw_transaction_with_key(&tx, &[sk], None, Some(EcdsaSighashType::All.into())) + .unwrap(); assert!(res.complete); let _ = cl.send_raw_transaction(&res.transaction().unwrap()).unwrap(); } @@ -936,6 +937,9 @@ fn test_create_wallet(cl: &Client) { blank: Option, passphrase: Option<&'a str>, avoid_reuse: Option, + descriptors: Option, + load_on_startup: Option, + external_signer: Option, } let mut wallet_params = vec![ @@ -945,6 +949,9 @@ fn test_create_wallet(cl: &Client) { blank: None, passphrase: None, avoid_reuse: None, + descriptors: None, + load_on_startup: None, + external_signer: None, }, WalletParams { name: wallet_names[1], @@ -952,6 +959,9 @@ fn test_create_wallet(cl: &Client) { blank: None, passphrase: None, avoid_reuse: None, + descriptors: None, + load_on_startup: None, + external_signer: None, }, WalletParams { name: wallet_names[2], @@ -959,6 +969,9 @@ fn test_create_wallet(cl: &Client) { blank: Some(true), passphrase: None, avoid_reuse: None, + descriptors: None, + load_on_startup: None, + external_signer: None, }, ]; @@ -969,6 +982,9 @@ fn test_create_wallet(cl: &Client) { blank: None, passphrase: Some("pass"), avoid_reuse: None, + descriptors: None, + load_on_startup: None, + external_signer: None, }); wallet_params.push(WalletParams { name: wallet_names[4], @@ -976,6 +992,9 @@ fn test_create_wallet(cl: &Client) { blank: None, passphrase: None, avoid_reuse: Some(true), + descriptors: None, + load_on_startup: None, + external_signer: None, }); } @@ -987,6 +1006,9 @@ fn test_create_wallet(cl: &Client) { wallet_param.blank, wallet_param.passphrase, wallet_param.avoid_reuse, + wallet_param.descriptors, + wallet_param.load_on_startup, + wallet_param.external_signer, ) .unwrap(); @@ -1081,11 +1103,7 @@ fn test_add_ban(cl: &Client) { let res = cl.list_banned().unwrap(); assert_eq!(res.len(), 0); - assert_error_message!( - cl.add_ban("INVALID_STRING", 0, false), - -30, - "Error: Invalid IP/Subnet" - ); + assert_error_message!(cl.add_ban("INVALID_STRING", 0, false), -30, "Error: Invalid IP/Subnet"); } fn test_set_network_active(cl: &Client) {