@@ -14,6 +14,7 @@ extern crate bitcoin;
1414extern crate bitcoincore_rpc;
1515#[ macro_use]
1616extern crate lazy_static;
17+ extern crate log;
1718
1819use std:: collections:: HashMap ;
1920
@@ -29,6 +30,7 @@ use bitcoin::{
2930 Address , Amount , Network , OutPoint , PrivateKey , Script , SigHashType , SignedAmount , Transaction ,
3031 TxIn , TxOut , Txid ,
3132} ;
33+ use bitcoincore_rpc:: bitcoincore_rpc_json:: ScanTxOutRequest ;
3234
3335lazy_static ! {
3436 static ref SECP : secp256k1:: Secp256k1 <secp256k1:: All > = secp256k1:: Secp256k1 :: new( ) ;
@@ -39,6 +41,24 @@ lazy_static! {
3941 static ref FEE : Amount = Amount :: from_btc( 0.001 ) . unwrap( ) ;
4042}
4143
44+ struct StdLogger ;
45+
46+ impl log:: Log for StdLogger {
47+ fn enabled ( & self , metadata : & log:: Metadata ) -> bool {
48+ metadata. target ( ) . contains ( "jsonrpc" ) || metadata. target ( ) . contains ( "bitcoincore_rpc" )
49+ }
50+
51+ fn log ( & self , record : & log:: Record ) {
52+ if self . enabled ( record. metadata ( ) ) {
53+ println ! ( "[{}][{}]: {}" , record. level( ) , record. metadata( ) . target( ) , record. args( ) ) ;
54+ }
55+ }
56+
57+ fn flush ( & self ) { }
58+ }
59+
60+ static LOGGER : StdLogger = StdLogger ;
61+
4262/// Assert that the call returns a "deprecated" error.
4363macro_rules! assert_deprecated {
4464 ( $call: expr) => {
@@ -89,6 +109,8 @@ fn get_auth() -> bitcoincore_rpc::Auth {
89109}
90110
91111fn main ( ) {
112+ log:: set_logger ( & LOGGER ) . map ( |( ) | log:: set_max_level ( log:: LevelFilter :: max ( ) ) ) . unwrap ( ) ;
113+
92114 let rpc_url = get_rpc_url ( ) ;
93115 let auth = get_auth ( ) ;
94116
@@ -137,6 +159,7 @@ fn main() {
137159 test_combine_psbt ( & cl) ;
138160 test_finalize_psbt ( & cl) ;
139161 test_list_received_by_address ( & cl) ;
162+ test_scantxoutset ( & cl) ;
140163 test_import_public_key ( & cl) ;
141164 test_import_priv_key ( & cl) ;
142165 test_import_address ( & cl) ;
@@ -279,16 +302,33 @@ fn test_get_address_info(cl: &Client) {
279302 assert ! ( !info. hex. unwrap( ) . is_empty( ) ) ;
280303}
281304
305+ #[ allow( deprecated) ]
282306fn test_set_label ( cl : & Client ) {
283307 let addr = cl. get_new_address ( Some ( "label" ) , None ) . unwrap ( ) ;
284308 let info = cl. get_address_info ( & addr) . unwrap ( ) ;
285- assert_eq ! ( & info. label, "label" ) ;
286- assert_eq ! ( info. labels[ 0 ] . name, "label" ) ;
309+ if version ( ) >= 0_20_00_00 {
310+ assert ! ( info. label. is_none( ) ) ;
311+ assert_eq ! ( info. labels[ 0 ] , json:: GetAddressInfoResultLabel :: Simple ( "label" . into( ) ) ) ;
312+ } else {
313+ assert_eq ! ( info. label. as_ref( ) . unwrap( ) , "label" ) ;
314+ assert_eq ! ( info. labels[ 0 ] , json:: GetAddressInfoResultLabel :: WithPurpose {
315+ name: "label" . into( ) ,
316+ purpose: json:: GetAddressInfoResultLabelPurpose :: Receive ,
317+ } ) ;
318+ }
287319
288320 cl. set_label ( & addr, "other" ) . unwrap ( ) ;
289321 let info = cl. get_address_info ( & addr) . unwrap ( ) ;
290- assert_eq ! ( & info. label, "other" ) ;
291- assert_eq ! ( info. labels[ 0 ] . name, "other" ) ;
322+ if version ( ) >= 0_20_00_00 {
323+ assert ! ( info. label. is_none( ) ) ;
324+ assert_eq ! ( info. labels[ 0 ] , json:: GetAddressInfoResultLabel :: Simple ( "other" . into( ) ) ) ;
325+ } else {
326+ assert_eq ! ( info. label. as_ref( ) . unwrap( ) , "other" ) ;
327+ assert_eq ! ( info. labels[ 0 ] , json:: GetAddressInfoResultLabel :: WithPurpose {
328+ name: "other" . into( ) ,
329+ purpose: json:: GetAddressInfoResultLabelPurpose :: Receive ,
330+ } ) ;
331+ }
292332}
293333
294334fn test_send_to_address ( cl : & Client ) {
@@ -916,6 +956,20 @@ fn test_uptime(cl: &Client) {
916956 cl. uptime ( ) . unwrap ( ) ;
917957}
918958
959+ fn test_scantxoutset ( cl : & Client ) {
960+ let addr = cl. get_new_address ( None , None ) . unwrap ( ) ;
961+
962+ cl. generate_to_address ( 2 , & addr) . unwrap ( ) ;
963+ cl. generate_to_address ( 7 , & cl. get_new_address ( None , None ) . unwrap ( ) ) . unwrap ( ) ;
964+
965+ let utxos = cl
966+ . scan_tx_out_set_blocking ( & [ ScanTxOutRequest :: Single ( format ! ( "addr({})" , addr) ) ] )
967+ . unwrap ( ) ;
968+
969+ assert_eq ! ( utxos. unspents. len( ) , 2 ) ;
970+ assert_eq ! ( utxos. success, Some ( true ) ) ;
971+ }
972+
919973fn test_stop ( cl : Client ) {
920974 println ! ( "Stopping: '{}'" , cl. stop( ) . unwrap( ) ) ;
921975}
0 commit comments