Skip to content

Commit

Permalink
Update create_wallet to support Core v0.23.0
Browse files Browse the repository at this point in the history
  • Loading branch information
evanlinjin committed Jun 20, 2022
1 parent 657eebd commit 1219d3d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
12 changes: 9 additions & 3 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,22 +271,28 @@ pub trait RpcApi: Sized {

fn create_wallet(
&self,
wallet: &str,
wallet_name: &str,
disable_private_keys: Option<bool>,
blank: Option<bool>,
passphrase: Option<&str>,
avoid_reuse: Option<bool>,
descriptors: Option<bool>,
load_on_startup: Option<bool>,
external_signer: Option<bool>,
) -> Result<json::LoadWalletResult> {
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()]),
)
}

Expand Down
4 changes: 4 additions & 0 deletions integration_test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
38 changes: 28 additions & 10 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -936,6 +937,9 @@ fn test_create_wallet(cl: &Client) {
blank: Option<bool>,
passphrase: Option<&'a str>,
avoid_reuse: Option<bool>,
descriptors: Option<bool>,
load_on_startup: Option<bool>,
external_signer: Option<bool>,
}

let mut wallet_params = vec![
Expand All @@ -945,20 +949,29 @@ 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],
disable_private_keys: Some(true),
blank: None,
passphrase: None,
avoid_reuse: None,
descriptors: None,
load_on_startup: None,
external_signer: None,
},
WalletParams {
name: wallet_names[2],
disable_private_keys: None,
blank: Some(true),
passphrase: None,
avoid_reuse: None,
descriptors: None,
load_on_startup: None,
external_signer: None,
},
];

Expand All @@ -969,13 +982,19 @@ 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],
disable_private_keys: None,
blank: None,
passphrase: None,
avoid_reuse: Some(true),
descriptors: None,
load_on_startup: None,
external_signer: None,
});
}

Expand All @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1219d3d

Please sign in to comment.