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 @@ -886,6 +886,11 @@ pub trait RpcApi: Sized {
886
886
self . call ( "getnewaddress" , & [ opt_into_json ( label) ?, opt_into_json ( address_type) ?] )
887
887
}
888
888
889
+ /// Generate new address for receiving change
890
+ fn get_raw_change_address ( & self , address_type : Option < json:: AddressType > ) -> Result < Address > {
891
+ self . call ( "getrawchangeaddress" , & [ opt_into_json ( address_type) ?] )
892
+ }
893
+
889
894
fn get_address_info ( & self , address : & Address ) -> Result < json:: GetAddressInfoResult > {
890
895
self . call ( "getaddressinfo" , & [ address. to_string ( ) . into ( ) ] )
891
896
}
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) ;
@@ -241,6 +242,17 @@ fn test_get_new_address(cl: &Client) {
241
242
assert_eq ! ( addr. address_type( ) , Some ( bitcoin:: AddressType :: P2sh ) ) ;
242
243
}
243
244
245
+ fn test_get_raw_change_address ( cl : & Client ) {
246
+ let addr = cl. get_raw_change_address ( Some ( json:: AddressType :: Legacy ) ) . unwrap ( ) ;
247
+ assert_eq ! ( addr. address_type( ) , Some ( bitcoin:: AddressType :: P2pkh ) ) ;
248
+
249
+ let addr = cl. get_raw_change_address ( Some ( json:: AddressType :: Bech32 ) ) . unwrap ( ) ;
250
+ assert_eq ! ( addr. address_type( ) , Some ( bitcoin:: AddressType :: P2wpkh ) ) ;
251
+
252
+ let addr = cl. get_raw_change_address ( Some ( json:: AddressType :: P2shSegwit ) ) . unwrap ( ) ;
253
+ assert_eq ! ( addr. address_type( ) , Some ( bitcoin:: AddressType :: P2sh ) ) ;
254
+ }
255
+
244
256
fn test_dump_private_key ( cl : & Client ) {
245
257
let addr = cl. get_new_address ( None , Some ( json:: AddressType :: Bech32 ) ) . unwrap ( ) ;
246
258
let sk = cl. dump_private_key ( & addr) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments