Skip to content

Commit 3bb64ac

Browse files
committed
added bech32m address type and create wallet w/ descriptors
added import descriptors feature fixing tests updates added tests properly
1 parent af7ac9f commit 3bb64ac

File tree

4 files changed

+69
-7
lines changed

4 files changed

+69
-7
lines changed

client/src/client.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -276,20 +276,46 @@ 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(&self, descriptor: &str, change_descriptor: &str) -> Result<bool> {
299+
let ex_descriptor = json::DescriptorFormat {
300+
descriptor: descriptor.to_string(),
301+
timestamp: "now".to_string(),
302+
active: true,
303+
range: [0, 100],
304+
internal: false,
305+
};
306+
307+
let in_descriptor = json::DescriptorFormat {
308+
descriptor: change_descriptor.to_string(),
309+
timestamp: "now".to_string(),
310+
active: true,
311+
range: [0, 999],
312+
internal: true,
313+
};
314+
315+
let args = [into_json(ex_descriptor)?, into_json(in_descriptor)?];
316+
self.call("importdescriptors", &args)
317+
}
318+
293319
fn list_wallets(&self) -> Result<Vec<String>> {
294320
self.call("listwallets", &[])
295321
}

integration_test/run.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,28 @@ BLOCKFILTERARG=""
2222
if bitcoind -version | grep -q "v0\.\(19\|2\)"; then
2323
BLOCKFILTERARG="-blockfilterindex=1"
2424
fi
25+
BLOCKFILTERARG="-blockfilterindex=1"
2526

2627
FALLBACKFEEARG=""
2728
if bitcoind -version | grep -q "v0\.2"; then
2829
FALLBACKFEEARG="-fallbackfee=0.00001000"
2930
fi
31+
FALLBACKFEEARG="-fallbackfee=0.00001000"
3032

3133
bitcoind -regtest $BLOCKFILTERARG $FALLBACKFEEARG \
3234
-datadir=${TESTDIR}/2 \
3335
-connect=127.0.0.1:12348 \
34-
-rpcport=12349 \
36+
-rpcport=18443 \
3537
-server=1 \
3638
-printtoconsole=0 &
3739
PID2=$!
3840

3941
# Let it connect to the other node.
4042
sleep 5
4143

42-
RPC_URL=http://localhost:12349 \
44+
RPC_URL=http://localhost:18443 \
4345
RPC_COOKIE=${TESTDIR}/2/regtest/.cookie \
46+
RUST_LOG=debug \
4447
cargo run
4548

4649
RESULT=$?

integration_test/src/main.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ use bitcoin::{
3232
Address, Amount, Network, OutPoint, PrivateKey, Script, SigHashType, SignedAmount, Transaction,
3333
TxIn, TxOut, Txid,
3434
};
35-
use bitcoincore_rpc_json::{
36-
GetBlockTemplateModes, GetBlockTemplateRules, ScanTxOutRequest,
37-
};
35+
use bitcoincore_rpc_json::{GetBlockTemplateModes, GetBlockTemplateRules, ScanTxOutRequest};
3836

3937
lazy_static! {
4038
static ref SECP: secp256k1::Secp256k1<secp256k1::All> = secp256k1::Secp256k1::new();
@@ -135,7 +133,9 @@ fn main() {
135133
unsafe { VERSION = cl.version().unwrap() };
136134
println!("Version: {}", version());
137135

138-
cl.create_wallet("testwallet", None, None, None, None).unwrap();
136+
test_import_descriptors(&cl);
137+
138+
cl.create_wallet("testwallet", None, None, None, None, None).unwrap();
139139

140140
test_get_mining_info(&cl);
141141
test_get_blockchain_info(&cl);
@@ -907,6 +907,7 @@ fn test_create_wallet(cl: &Client) {
907907
blank: Option<bool>,
908908
passphrase: Option<&'a str>,
909909
avoid_reuse: Option<bool>,
910+
descriptors: Option<bool>,
910911
}
911912

912913
let mut wallet_params = vec![
@@ -916,20 +917,23 @@ fn test_create_wallet(cl: &Client) {
916917
blank: None,
917918
passphrase: None,
918919
avoid_reuse: None,
920+
descriptors: None,
919921
},
920922
WalletParams {
921923
name: wallet_names[1],
922924
disable_private_keys: Some(true),
923925
blank: None,
924926
passphrase: None,
925927
avoid_reuse: None,
928+
descriptors: None,
926929
},
927930
WalletParams {
928931
name: wallet_names[2],
929932
disable_private_keys: None,
930933
blank: Some(true),
931934
passphrase: None,
932935
avoid_reuse: None,
936+
descriptors: None,
933937
},
934938
];
935939

@@ -940,13 +944,15 @@ fn test_create_wallet(cl: &Client) {
940944
blank: None,
941945
passphrase: Some("pass"),
942946
avoid_reuse: None,
947+
descriptors: None,
943948
});
944949
wallet_params.push(WalletParams {
945950
name: wallet_names[4],
946951
disable_private_keys: None,
947952
blank: None,
948953
passphrase: None,
949954
avoid_reuse: Some(true),
955+
descriptors: None,
950956
});
951957
}
952958

@@ -958,6 +964,7 @@ fn test_create_wallet(cl: &Client) {
958964
wallet_param.blank,
959965
wallet_param.passphrase,
960966
wallet_param.avoid_reuse,
967+
wallet_param.descriptors,
961968
)
962969
.unwrap();
963970

@@ -1000,6 +1007,17 @@ fn test_create_wallet(cl: &Client) {
10001007
assert!(wallet_list.iter().zip(wallet_names).all(|(a, b)| a == b));
10011008
}
10021009

1010+
fn test_import_descriptors(cl: &Client) {
1011+
cl.create_wallet("testwallet", Some(false), Some(true), Some(""), Some(false), Some(true))
1012+
.unwrap();
1013+
1014+
let descriptor = "wpkh(tprv8ZgxMBicQKsPeTNzU5evMToRhHA9h3UCxbpzrzjUWUd6TQktkhmY82dQx5f6QaFpSWMzZxKz16xQFGeW7ykPjYuTetU6ep9aFTpAt7jKhPU/44'/0'/0'/0/*)#w2lyh4jx";
1015+
let x = cl.import_descriptors(descriptor, descriptor);
1016+
x.unwrap();
1017+
cl.get_new_address(None, Some(json::AddressType::Bech32m)).unwrap();
1018+
cl.unload_wallet(Some("testwallet")).unwrap();
1019+
}
1020+
10031021
fn test_get_tx_out_set_info(cl: &Client) {
10041022
cl.get_tx_out_set_info().unwrap();
10051023
}

json/src/lib.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,8 @@ 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,15 @@ where
16861689
}
16871690
Ok(Some(res))
16881691
}
1692+
1693+
/// Descriptor Format
1694+
#[derive(Serialize, Clone, PartialEq, Eq, Debug)]
1695+
#[serde(rename_all = "camelCase")]
1696+
pub struct DescriptorFormat {
1697+
#[serde(rename = "desc")]
1698+
pub descriptor: String,
1699+
pub active: bool,
1700+
pub range: [i64; 2],
1701+
pub timestamp: String,
1702+
pub internal: bool,
1703+
}

0 commit comments

Comments
 (0)