File tree Expand file tree Collapse file tree 15 files changed +53
-0
lines changed Expand file tree Collapse file tree 15 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ crate::impl_client_v17__get_received_by_address!();
127
127
crate :: impl_client_v17__get_transaction!( ) ;
128
128
crate :: impl_client_v17__get_unconfirmed_balance!( ) ;
129
129
crate :: impl_client_v17__get_wallet_info!( ) ;
130
+ crate :: impl_client_v17__import_address!( ) ;
130
131
crate :: impl_client_v17__import_privkey!( ) ;
131
132
crate :: impl_client_v17__list_address_groupings!( ) ;
132
133
crate :: impl_client_v17__list_labels!( ) ;
Original file line number Diff line number Diff line change @@ -282,6 +282,22 @@ macro_rules! impl_client_v17__get_wallet_info {
282
282
} ;
283
283
}
284
284
285
+ /// Implements Bitcoin Core JSON-RPC API method `importaddress`.
286
+ #[ macro_export]
287
+ macro_rules! impl_client_v17__import_address {
288
+ ( ) => {
289
+ impl Client {
290
+ pub fn import_address( & self , address: & Address ) -> Result <( ) > {
291
+ match self . call( "importaddress" , & [ into_json( address) ?] ) {
292
+ Ok ( serde_json:: Value :: Null ) => Ok ( ( ) ) ,
293
+ Ok ( res) => Err ( Error :: Returned ( res. to_string( ) ) ) ,
294
+ Err ( err) => Err ( err. into( ) ) ,
295
+ }
296
+ }
297
+ }
298
+ } ;
299
+ }
300
+
285
301
/// Implements Bitcoin Core JSON-RPC API method `importprivkey`.
286
302
#[ macro_export]
287
303
macro_rules! impl_client_v17__import_privkey {
Original file line number Diff line number Diff line change @@ -142,6 +142,7 @@ crate::impl_client_v18__get_received_by_label!();
142
142
crate :: impl_client_v17__get_transaction!( ) ;
143
143
crate :: impl_client_v17__get_unconfirmed_balance!( ) ;
144
144
crate :: impl_client_v17__get_wallet_info!( ) ;
145
+ crate :: impl_client_v17__import_address!( ) ;
145
146
crate :: impl_client_v17__import_privkey!( ) ;
146
147
crate :: impl_client_v17__list_address_groupings!( ) ;
147
148
crate :: impl_client_v17__list_labels!( ) ;
Original file line number Diff line number Diff line change @@ -138,6 +138,7 @@ crate::impl_client_v17__get_received_by_address!();
138
138
crate :: impl_client_v17__get_transaction!( ) ;
139
139
crate :: impl_client_v17__get_unconfirmed_balance!( ) ;
140
140
crate :: impl_client_v17__get_wallet_info!( ) ;
141
+ crate :: impl_client_v17__import_address!( ) ;
141
142
crate :: impl_client_v17__import_privkey!( ) ;
142
143
crate :: impl_client_v17__list_address_groupings!( ) ;
143
144
crate :: impl_client_v18__list_received_by_label!( ) ;
Original file line number Diff line number Diff line change @@ -135,6 +135,7 @@ crate::impl_client_v17__get_received_by_address!();
135
135
crate :: impl_client_v17__get_transaction!( ) ;
136
136
crate :: impl_client_v17__get_unconfirmed_balance!( ) ;
137
137
crate :: impl_client_v17__get_wallet_info!( ) ;
138
+ crate :: impl_client_v17__import_address!( ) ;
138
139
crate :: impl_client_v17__import_privkey!( ) ;
139
140
crate :: impl_client_v17__list_address_groupings!( ) ;
140
141
crate :: impl_client_v17__list_labels!( ) ;
Original file line number Diff line number Diff line change @@ -137,6 +137,7 @@ crate::impl_client_v17__get_received_by_address!();
137
137
crate :: impl_client_v17__get_transaction!( ) ;
138
138
crate :: impl_client_v17__get_unconfirmed_balance!( ) ;
139
139
crate :: impl_client_v17__get_wallet_info!( ) ;
140
+ crate :: impl_client_v17__import_address!( ) ;
140
141
crate :: impl_client_v17__import_privkey!( ) ;
141
142
crate :: impl_client_v17__list_address_groupings!( ) ;
142
143
crate :: impl_client_v17__list_labels!( ) ;
Original file line number Diff line number Diff line change @@ -137,6 +137,7 @@ crate::impl_client_v17__get_received_by_address!();
137
137
crate :: impl_client_v17__get_transaction!( ) ;
138
138
crate :: impl_client_v17__get_unconfirmed_balance!( ) ;
139
139
crate :: impl_client_v17__get_wallet_info!( ) ;
140
+ crate :: impl_client_v17__import_address!( ) ;
140
141
crate :: impl_client_v17__import_privkey!( ) ;
141
142
crate :: impl_client_v17__list_address_groupings!( ) ;
142
143
crate :: impl_client_v18__list_received_by_label!( ) ;
Original file line number Diff line number Diff line change @@ -139,6 +139,7 @@ crate::impl_client_v17__get_received_by_address!();
139
139
crate :: impl_client_v17__get_transaction!( ) ;
140
140
crate :: impl_client_v17__get_unconfirmed_balance!( ) ;
141
141
crate :: impl_client_v17__get_wallet_info!( ) ;
142
+ crate :: impl_client_v17__import_address!( ) ;
142
143
crate :: impl_client_v17__import_privkey!( ) ;
143
144
crate :: impl_client_v17__list_address_groupings!( ) ;
144
145
crate :: impl_client_v18__list_received_by_label!( ) ;
Original file line number Diff line number Diff line change @@ -136,6 +136,7 @@ crate::impl_client_v17__get_received_by_address!();
136
136
crate :: impl_client_v17__get_transaction!( ) ;
137
137
crate :: impl_client_v17__get_unconfirmed_balance!( ) ;
138
138
crate :: impl_client_v17__get_wallet_info!( ) ;
139
+ crate :: impl_client_v17__import_address!( ) ;
139
140
crate :: impl_client_v17__import_privkey!( ) ;
140
141
crate :: impl_client_v17__list_address_groupings!( ) ;
141
142
crate :: impl_client_v18__list_received_by_label!( ) ;
Original file line number Diff line number Diff line change @@ -136,6 +136,7 @@ crate::impl_client_v17__get_received_by_address!();
136
136
crate :: impl_client_v17__get_transaction!( ) ;
137
137
crate :: impl_client_v17__get_unconfirmed_balance!( ) ;
138
138
crate :: impl_client_v17__get_wallet_info!( ) ;
139
+ crate :: impl_client_v17__import_address!( ) ;
139
140
crate :: impl_client_v17__import_privkey!( ) ;
140
141
crate :: impl_client_v17__list_address_groupings!( ) ;
141
142
crate :: impl_client_v18__list_received_by_label!( ) ;
Original file line number Diff line number Diff line change @@ -142,6 +142,7 @@ crate::impl_client_v17__get_received_by_address!();
142
142
crate :: impl_client_v17__get_transaction!( ) ;
143
143
crate :: impl_client_v17__get_unconfirmed_balance!( ) ;
144
144
crate :: impl_client_v17__get_wallet_info!( ) ;
145
+ crate :: impl_client_v17__import_address!( ) ;
145
146
crate :: impl_client_v17__import_privkey!( ) ;
146
147
crate :: impl_client_v17__list_address_groupings!( ) ;
147
148
crate :: impl_client_v17__list_labels!( ) ;
Original file line number Diff line number Diff line change @@ -138,6 +138,7 @@ crate::impl_client_v17__get_received_by_address!();
138
138
crate :: impl_client_v17__get_transaction!( ) ;
139
139
crate :: impl_client_v17__get_unconfirmed_balance!( ) ;
140
140
crate :: impl_client_v17__get_wallet_info!( ) ;
141
+ crate :: impl_client_v17__import_address!( ) ;
141
142
crate :: impl_client_v17__import_privkey!( ) ;
142
143
crate :: impl_client_v17__list_address_groupings!( ) ;
143
144
crate :: impl_client_v18__list_received_by_label!( ) ;
Original file line number Diff line number Diff line change @@ -140,6 +140,7 @@ crate::impl_client_v17__get_received_by_address!();
140
140
crate :: impl_client_v17__get_transaction!( ) ;
141
141
crate :: impl_client_v17__get_unconfirmed_balance!( ) ;
142
142
crate :: impl_client_v17__get_wallet_info!( ) ;
143
+ crate :: impl_client_v17__import_address!( ) ;
143
144
crate :: impl_client_v17__import_privkey!( ) ;
144
145
crate :: impl_client_v17__list_address_groupings!( ) ;
145
146
crate :: impl_client_v18__list_received_by_label!( ) ;
Original file line number Diff line number Diff line change @@ -140,6 +140,7 @@ crate::impl_client_v17__get_received_by_address!();
140
140
crate :: impl_client_v17__get_transaction!( ) ;
141
141
crate :: impl_client_v17__get_unconfirmed_balance!( ) ;
142
142
crate :: impl_client_v17__get_wallet_info!( ) ;
143
+ crate :: impl_client_v17__import_address!( ) ;
143
144
crate :: impl_client_v17__import_privkey!( ) ;
144
145
crate :: impl_client_v17__list_address_groupings!( ) ;
145
146
crate :: impl_client_v18__list_received_by_label!( ) ;
Original file line number Diff line number Diff line change @@ -286,6 +286,30 @@ fn wallet__get_transaction__modelled() {
286
286
model. unwrap ( ) ;
287
287
}
288
288
289
+ #[ test]
290
+ fn wallet__import_address ( ) {
291
+ let node = match ( ) {
292
+ #[ cfg( feature = "v22_and_below" ) ]
293
+ ( ) => Node :: with_wallet ( Wallet :: Default , & [ ] ) ,
294
+ #[ cfg( not( feature = "v22_and_below" ) ) ]
295
+ ( ) => {
296
+ let node = Node :: with_wallet ( Wallet :: None , & [ "-deprecatedrpc=create_bdb" ] ) ;
297
+ node. client . create_legacy_wallet ( "wallet_name" ) . expect ( "createlegacywallet" ) ;
298
+ node
299
+ }
300
+ } ;
301
+
302
+ let privkey =
303
+ PrivateKey :: from_wif ( "cVt4o7BGAig1UXywgGSmARhxMdzP5qvQsxKkSsc1XEkw3tDTQFpy" ) . unwrap ( ) ;
304
+
305
+ // Derive the address from the private key
306
+ let secp = bitcoin:: secp256k1:: Secp256k1 :: new ( ) ;
307
+ let pubkey = privkey. public_key ( & secp) ;
308
+ let addr = bitcoin:: Address :: p2pkh ( & pubkey, privkey. network ) ;
309
+
310
+ node. client . import_address ( & addr) . expect ( "importaddress" ) ;
311
+ }
312
+
289
313
#[ cfg( not( feature = "v17" ) ) ]
290
314
#[ test]
291
315
fn wallet__list_received_by_label__modelled ( ) {
You can’t perform that action at this time.
0 commit comments