Skip to content

Commit 2e87fa5

Browse files
committed
added importdescriptors command, updated createwallet command with descriptors parameter and added bech32m address type
1 parent 99467e7 commit 2e87fa5

File tree

4 files changed

+94
-9
lines changed

4 files changed

+94
-9
lines changed

Diff for: client/src/client.rs

+33-2
Original file line numberDiff line numberDiff line change
@@ -276,20 +276,52 @@ pub trait RpcApi: Sized {
276276
blank: Option<bool>,
277277
passphrase: Option<&str>,
278278
avoid_reuse: Option<bool>,
279+
descriptors: Option<bool>,
279280
) -> Result<json::LoadWalletResult> {
280281
let mut args = [
281282
wallet.into(),
282283
opt_into_json(disable_private_keys)?,
283284
opt_into_json(blank)?,
284285
opt_into_json(passphrase)?,
285286
opt_into_json(avoid_reuse)?,
287+
opt_into_json(descriptors)?,
286288
];
287289
self.call(
288290
"createwallet",
289-
handle_defaults(&mut args, &[false.into(), false.into(), into_json("")?, false.into()]),
291+
handle_defaults(
292+
&mut args,
293+
&[false.into(), false.into(), into_json("")?, false.into(), false.into()],
294+
),
290295
)
291296
}
292297

298+
fn import_descriptors(
299+
&self,
300+
descriptor: &str,
301+
change_descriptor: &str,
302+
) -> Result<Vec<json::ImportDescriptorResult>> {
303+
let ex_descriptor = json::ImportDescriptorRequest {
304+
active: true,
305+
descriptor: descriptor.to_string(),
306+
range: [0, 100],
307+
next_index: 0,
308+
timestamp: "now".to_string(),
309+
internal: false,
310+
};
311+
312+
let in_descriptor = json::ImportDescriptorRequest {
313+
active: true,
314+
descriptor: change_descriptor.to_string(),
315+
range: [0, 100],
316+
next_index: 0,
317+
timestamp: "now".to_string(),
318+
internal: true,
319+
};
320+
321+
let arg = into_json([ex_descriptor, in_descriptor])?;
322+
self.call("importdescriptors", &[arg])
323+
}
324+
293325
fn list_wallets(&self) -> Result<Vec<String>> {
294326
self.call("listwallets", &[])
295327
}
@@ -1136,7 +1168,6 @@ impl RpcApi for Client {
11361168
if log_enabled!(Debug) {
11371169
debug!(target: "bitcoincore_rpc", "JSON-RPC request: {} {}", cmd, serde_json::Value::from(args));
11381170
}
1139-
11401171
let resp = self.client.send_request(req).map_err(Error::from);
11411172
log_response(cmd, &resp);
11421173
Ok(resp?.result()?)

Diff for: integration_test/run.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ PID1=$!
1919
sleep 3
2020

2121
BLOCKFILTERARG=""
22-
if bitcoind -version | grep -q "v0\.\(19\|2\)"; then
22+
if bitcoind -version | grep -q "v\(0\.19\|0\.2\|2\)"; then
2323
BLOCKFILTERARG="-blockfilterindex=1"
2424
fi
2525

2626
FALLBACKFEEARG=""
27-
if bitcoind -version | grep -q "v0\.2"; then
27+
if bitcoind -version | grep -q "v\(0\.2\|2\)"; then
2828
FALLBACKFEEARG="-fallbackfee=0.00001000"
2929
fi
3030

Diff for: integration_test/src/main.rs

+35-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extern crate lazy_static;
1717
extern crate log;
1818

1919
use std::collections::HashMap;
20+
use std::str::FromStr;
2021

2122
use bitcoincore_rpc::json;
2223
use bitcoincore_rpc::jsonrpc::error::Error as JsonRpcError;
@@ -125,15 +126,13 @@ fn main() {
125126
log::set_logger(&LOGGER).map(|()| log::set_max_level(log::LevelFilter::max())).unwrap();
126127

127128
let rpc_url = format!("{}/wallet/testwallet", get_rpc_url());
128-
let auth = get_auth();
129-
130-
let cl = Client::new(&rpc_url, auth).unwrap();
129+
let cl = Client::new(&rpc_url, get_auth()).unwrap();
131130

132131
test_get_network_info(&cl);
133132
unsafe { VERSION = cl.version().unwrap() };
134133
println!("Version: {}", version());
135134

136-
cl.create_wallet("testwallet", None, None, None, None).unwrap();
135+
cl.create_wallet("testwallet", None, None, None, None, None).unwrap();
137136

138137
test_get_mining_info(&cl);
139138
test_get_blockchain_info(&cl);
@@ -203,6 +202,11 @@ fn main() {
203202
//TODO load_wallet(&self, wallet: &str) -> Result<json::LoadWalletResult> {
204203
//TODO unload_wallet(&self, wallet: Option<&str>) -> Result<()> {
205204
//TODO backup_wallet(&self, destination: Option<&str>) -> Result<()> {
205+
206+
let rpc_url = format!("{}/wallet/testdescriptorwallet", get_rpc_url());
207+
let desc_cl = Client::new(&rpc_url, get_auth()).unwrap();
208+
209+
test_descriptor_wallet(&desc_cl);
206210
test_stop(cl);
207211
}
208212

@@ -905,6 +909,7 @@ fn test_create_wallet(cl: &Client) {
905909
blank: Option<bool>,
906910
passphrase: Option<&'a str>,
907911
avoid_reuse: Option<bool>,
912+
descriptors: Option<bool>,
908913
}
909914

910915
let mut wallet_params = vec![
@@ -914,20 +919,23 @@ fn test_create_wallet(cl: &Client) {
914919
blank: None,
915920
passphrase: None,
916921
avoid_reuse: None,
922+
descriptors: None,
917923
},
918924
WalletParams {
919925
name: wallet_names[1],
920926
disable_private_keys: Some(true),
921927
blank: None,
922928
passphrase: None,
923929
avoid_reuse: None,
930+
descriptors: None,
924931
},
925932
WalletParams {
926933
name: wallet_names[2],
927934
disable_private_keys: None,
928935
blank: Some(true),
929936
passphrase: None,
930937
avoid_reuse: None,
938+
descriptors: None,
931939
},
932940
];
933941

@@ -938,13 +946,15 @@ fn test_create_wallet(cl: &Client) {
938946
blank: None,
939947
passphrase: Some("pass"),
940948
avoid_reuse: None,
949+
descriptors: None,
941950
});
942951
wallet_params.push(WalletParams {
943952
name: wallet_names[4],
944953
disable_private_keys: None,
945954
blank: None,
946955
passphrase: None,
947956
avoid_reuse: Some(true),
957+
descriptors: None,
948958
});
949959
}
950960

@@ -956,6 +966,7 @@ fn test_create_wallet(cl: &Client) {
956966
wallet_param.blank,
957967
wallet_param.passphrase,
958968
wallet_param.avoid_reuse,
969+
wallet_param.descriptors,
959970
)
960971
.unwrap();
961972

@@ -1050,3 +1061,23 @@ fn test_getblocktemplate(cl: &Client) {
10501061
fn test_stop(cl: Client) {
10511062
println!("Stopping: '{}'", cl.stop().unwrap());
10521063
}
1064+
1065+
fn test_descriptor_wallet(cl: &Client) {
1066+
cl.create_wallet(
1067+
"testdescriptorwallet",
1068+
Some(false),
1069+
Some(true),
1070+
Some(""),
1071+
Some(false),
1072+
Some(true),
1073+
)
1074+
.unwrap();
1075+
1076+
cl.import_descriptors(
1077+
"wpkh(tprv8ZgxMBicQKsPeRBCAfUGsZhyHy9dwWyPqhSJmaMnMJQWWtt8L2SkTeHaiF82CUCGtiTiHAs3cMkjdKckGKiCWeYtvMPF1jDTWYTryRMicpx/86h/1h/0h/0/*)#ymr4jlz6",
1078+
"wpkh(tprv8ZgxMBicQKsPeRBCAfUGsZhyHy9dwWyPqhSJmaMnMJQWWtt8L2SkTeHaiF82CUCGtiTiHAs3cMkjdKckGKiCWeYtvMPF1jDTWYTryRMicpx/86h/1h/0h/1/*)#40x502jz",
1079+
).unwrap();
1080+
1081+
let add = cl.get_new_address(None, Some(json::AddressType::Bech32)).unwrap();
1082+
assert_eq!(add, Address::from_str("bcrt1q7crcza94drr00skmu5x0n00rhmwnthde2frhwk").unwrap());
1083+
}

Diff for: json/src/lib.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -1066,11 +1066,13 @@ pub struct GetPeerInfoResult {
10661066
}
10671067

10681068
#[derive(Copy, Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
1069-
#[serde(rename_all = "lowercase")]
1069+
#[serde(rename_all = "snake_case")]
10701070
pub enum GetPeerInfoResultNetwork {
10711071
Ipv4,
10721072
Ipv6,
10731073
Onion,
1074+
I2p,
1075+
NotPubliclyRoutable,
10741076
// this is undocumented upstream
10751077
Unroutable,
10761078
}
@@ -1607,6 +1609,7 @@ pub enum AddressType {
16071609
Legacy,
16081610
P2shSegwit,
16091611
Bech32,
1612+
Bech32m,
16101613
}
16111614

16121615
/// Used to represent arguments that can either be an address or a public key.
@@ -1686,3 +1689,23 @@ where
16861689
}
16871690
Ok(Some(res))
16881691
}
1692+
1693+
/// Import Descriptor Request
1694+
#[derive(Serialize, Clone, PartialEq, Eq, Debug)]
1695+
pub struct ImportDescriptorRequest {
1696+
pub active: bool,
1697+
#[serde(rename = "desc")]
1698+
pub descriptor: String,
1699+
pub range: [i64; 2],
1700+
pub next_index: i64,
1701+
pub timestamp: String,
1702+
pub internal: bool,
1703+
}
1704+
1705+
/// Imported Descriptor Result
1706+
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
1707+
pub struct ImportDescriptorResult {
1708+
pub success: bool,
1709+
pub warnings: Option<Vec<String>>,
1710+
pub error: Option<String>,
1711+
}

0 commit comments

Comments
 (0)