File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -845,6 +845,11 @@ pub trait RpcApi: Sized {
845
845
self . call ( "getnewaddress" , & [ opt_into_json ( label) ?, opt_into_json ( address_type) ?] )
846
846
}
847
847
848
+ /// Generate new address for receiving change
849
+ fn get_raw_change_address ( & self , address_type : Option < json:: AddressType > ) -> Result < Address > {
850
+ self . call ( "getrawchangeaddress" , & [ opt_into_json ( address_type) ?] )
851
+ }
852
+
848
853
fn get_address_info ( & self , address : & Address ) -> Result < json:: GetAddressInfoResult > {
849
854
self . call ( "getaddressinfo" , & [ address. to_string ( ) . into ( ) ] )
850
855
}
Original file line number Diff line number Diff line change @@ -136,6 +136,7 @@ fn main() {
136
136
test_get_mining_info ( & cl) ;
137
137
test_get_blockchain_info ( & cl) ;
138
138
test_get_new_address ( & cl) ;
139
+ test_get_raw_change_address ( & cl) ;
139
140
test_dump_private_key ( & cl) ;
140
141
test_generate ( & cl) ;
141
142
test_get_balance_generate_to_address ( & cl) ;
@@ -238,6 +239,17 @@ fn test_get_new_address(cl: &Client) {
238
239
assert_eq ! ( addr. address_type( ) , Some ( bitcoin:: AddressType :: P2sh ) ) ;
239
240
}
240
241
242
+ fn test_get_raw_change_address ( cl : & Client ) {
243
+ let addr = cl. get_raw_change_address ( Some ( json:: AddressType :: Legacy ) ) . unwrap ( ) ;
244
+ assert_eq ! ( addr. address_type( ) , Some ( bitcoin:: AddressType :: P2pkh ) ) ;
245
+
246
+ let addr = cl. get_raw_change_address ( Some ( json:: AddressType :: Bech32 ) ) . unwrap ( ) ;
247
+ assert_eq ! ( addr. address_type( ) , Some ( bitcoin:: AddressType :: P2wpkh ) ) ;
248
+
249
+ let addr = cl. get_raw_change_address ( Some ( json:: AddressType :: P2shSegwit ) ) . unwrap ( ) ;
250
+ assert_eq ! ( addr. address_type( ) , Some ( bitcoin:: AddressType :: P2sh ) ) ;
251
+ }
252
+
241
253
fn test_dump_private_key ( cl : & Client ) {
242
254
let addr = cl. get_new_address ( None , Some ( json:: AddressType :: Bech32 ) ) . unwrap ( ) ;
243
255
let sk = cl. dump_private_key ( & addr) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments