@@ -19,6 +19,7 @@ extern crate log;
19
19
use bitcoincore_rpc:: core_rpc_json as bitcoincore_rpc_json;
20
20
21
21
use std:: collections:: HashMap ;
22
+ use std:: str:: FromStr ;
22
23
23
24
use bitcoincore_rpc:: json;
24
25
use bitcoincore_rpc:: jsonrpc:: error:: Error as JsonRpcError ;
@@ -32,9 +33,7 @@ use bitcoin::{
32
33
Address , Amount , Network , OutPoint , PrivateKey , Script , SigHashType , SignedAmount , Transaction ,
33
34
TxIn , TxOut , Txid ,
34
35
} ;
35
- use bitcoincore_rpc_json:: {
36
- GetBlockTemplateModes , GetBlockTemplateRules , ScanTxOutRequest ,
37
- } ;
36
+ use bitcoincore_rpc_json:: { GetBlockTemplateModes , GetBlockTemplateRules , ScanTxOutRequest } ;
38
37
39
38
lazy_static ! {
40
39
static ref SECP : secp256k1:: Secp256k1 <secp256k1:: All > = secp256k1:: Secp256k1 :: new( ) ;
@@ -127,15 +126,13 @@ fn main() {
127
126
log:: set_logger ( & LOGGER ) . map ( |( ) | log:: set_max_level ( log:: LevelFilter :: max ( ) ) ) . unwrap ( ) ;
128
127
129
128
let rpc_url = format ! ( "{}/wallet/testwallet" , get_rpc_url( ) ) ;
130
- let auth = get_auth ( ) ;
131
-
132
- let cl = Client :: new ( & rpc_url, auth) . unwrap ( ) ;
129
+ let cl = Client :: new ( & rpc_url, get_auth ( ) ) . unwrap ( ) ;
133
130
134
131
test_get_network_info ( & cl) ;
135
132
unsafe { VERSION = cl. version ( ) . unwrap ( ) } ;
136
133
println ! ( "Version: {}" , version( ) ) ;
137
134
138
- cl. create_wallet ( "testwallet" , None , None , None , None ) . unwrap ( ) ;
135
+ cl. create_wallet ( "testwallet" , None , None , None , None , None ) . unwrap ( ) ;
139
136
140
137
test_get_mining_info ( & cl) ;
141
138
test_get_blockchain_info ( & cl) ;
@@ -205,6 +202,11 @@ fn main() {
205
202
//TODO load_wallet(&self, wallet: &str) -> Result<json::LoadWalletResult> {
206
203
//TODO unload_wallet(&self, wallet: Option<&str>) -> Result<()> {
207
204
//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) ;
208
210
test_stop ( cl) ;
209
211
}
210
212
@@ -907,6 +909,7 @@ fn test_create_wallet(cl: &Client) {
907
909
blank : Option < bool > ,
908
910
passphrase : Option < & ' a str > ,
909
911
avoid_reuse : Option < bool > ,
912
+ descriptors : Option < bool > ,
910
913
}
911
914
912
915
let mut wallet_params = vec ! [
@@ -916,20 +919,23 @@ fn test_create_wallet(cl: &Client) {
916
919
blank: None ,
917
920
passphrase: None ,
918
921
avoid_reuse: None ,
922
+ descriptors: None ,
919
923
} ,
920
924
WalletParams {
921
925
name: wallet_names[ 1 ] ,
922
926
disable_private_keys: Some ( true ) ,
923
927
blank: None ,
924
928
passphrase: None ,
925
929
avoid_reuse: None ,
930
+ descriptors: None ,
926
931
} ,
927
932
WalletParams {
928
933
name: wallet_names[ 2 ] ,
929
934
disable_private_keys: None ,
930
935
blank: Some ( true ) ,
931
936
passphrase: None ,
932
937
avoid_reuse: None ,
938
+ descriptors: None ,
933
939
} ,
934
940
] ;
935
941
@@ -940,13 +946,15 @@ fn test_create_wallet(cl: &Client) {
940
946
blank : None ,
941
947
passphrase : Some ( "pass" ) ,
942
948
avoid_reuse : None ,
949
+ descriptors : None ,
943
950
} ) ;
944
951
wallet_params. push ( WalletParams {
945
952
name : wallet_names[ 4 ] ,
946
953
disable_private_keys : None ,
947
954
blank : None ,
948
955
passphrase : None ,
949
956
avoid_reuse : Some ( true ) ,
957
+ descriptors : None ,
950
958
} ) ;
951
959
}
952
960
@@ -958,6 +966,7 @@ fn test_create_wallet(cl: &Client) {
958
966
wallet_param. blank ,
959
967
wallet_param. passphrase ,
960
968
wallet_param. avoid_reuse ,
969
+ wallet_param. descriptors ,
961
970
)
962
971
. unwrap ( ) ;
963
972
@@ -1052,3 +1061,25 @@ fn test_getblocktemplate(cl: &Client) {
1052
1061
fn test_stop ( cl : Client ) {
1053
1062
println ! ( "Stopping: '{}'" , cl. stop( ) . unwrap( ) ) ;
1054
1063
}
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
+ vec ! [
1078
+ json:: ImportDescriptorRequest :: new( "wpkh(tprv8ZgxMBicQKsPeRBCAfUGsZhyHy9dwWyPqhSJmaMnMJQWWtt8L2SkTeHaiF82CUCGtiTiHAs3cMkjdKckGKiCWeYtvMPF1jDTWYTryRMicpx/86h/1h/0h/0/*)#ymr4jlz6" , false ) ,
1079
+ json:: ImportDescriptorRequest :: new( "wpkh(tprv8ZgxMBicQKsPeRBCAfUGsZhyHy9dwWyPqhSJmaMnMJQWWtt8L2SkTeHaiF82CUCGtiTiHAs3cMkjdKckGKiCWeYtvMPF1jDTWYTryRMicpx/86h/1h/0h/1/*)#40x502jz" , true ) ,
1080
+ ]
1081
+ ) . unwrap ( ) ;
1082
+
1083
+ let add = cl. get_new_address ( None , Some ( json:: AddressType :: Bech32 ) ) . unwrap ( ) ;
1084
+ assert_eq ! ( add, Address :: from_str( "bcrt1q7crcza94drr00skmu5x0n00rhmwnthde2frhwk" ) . unwrap( ) ) ;
1085
+ }
0 commit comments