@@ -3,8 +3,8 @@ extern crate log;
33
44use bitcoincore_rpc:: RpcApi ;
55use farcaster_core:: swap:: SwapId ;
6- use farcaster_node:: bus:: ctl:: { BitcoinFundingInfo , MoneroFundingInfo } ;
7- use farcaster_node:: bus:: info:: NodeInfo ;
6+ use farcaster_node:: bus:: ctl:: { BitcoinFundingInfo , FundingInfo , MoneroFundingInfo } ;
7+ use farcaster_node:: bus:: info:: { FundingInfos , NodeInfo } ;
88use farcaster_node:: bus:: CheckpointEntry ;
99use futures:: future:: join_all;
1010use std:: collections:: HashSet ;
@@ -2731,6 +2731,16 @@ fn cli_output_to_node_info(stdout: Vec<String>) -> NodeInfo {
27312731 . unwrap ( )
27322732}
27332733
2734+ fn cli_output_to_funding_infos ( stdout : Vec < String > ) -> FundingInfos {
2735+ serde_yaml:: from_str (
2736+ & stdout
2737+ . iter ( )
2738+ . map ( |line| format ! ( "{}{}" , line, "\n " ) )
2739+ . collect :: < String > ( ) ,
2740+ )
2741+ . unwrap ( )
2742+ }
2743+
27342744async fn retry_until_offer ( args : Vec < String > ) -> Vec < String > {
27352745 for _ in 0 ..ALLOWED_RETRIES {
27362746 let ( stdout, _stderr) = run ( "../swap-cli" , args. clone ( ) ) . unwrap ( ) ;
@@ -2875,21 +2885,21 @@ async fn retry_until_bitcoin_funding_address(
28752885 for _ in 0 ..ALLOWED_RETRIES {
28762886 let ( stdout, _stderr) = run ( "../swap-cli" , args. clone ( ) ) . unwrap ( ) ;
28772887
2878- // get the btc funding address
2879- let funding_infos : Vec < BitcoinFundingInfo > = stdout
2888+ let funding_infos : Vec < BitcoinFundingInfo > = cli_output_to_funding_infos ( stdout )
2889+ . swaps_need_funding
28802890 . iter ( )
2881- . filter_map ( |element| {
2882- info ! ( "cli: {}" , element) ;
2883- if let Ok ( funding_info) = BitcoinFundingInfo :: from_str ( element) {
2884- if funding_info. swap_id == swap_id {
2885- Some ( funding_info)
2891+ . filter_map ( |f| {
2892+ if let FundingInfo :: Bitcoin ( info) = f {
2893+ if info. swap_id == swap_id {
2894+ Some ( info)
28862895 } else {
28872896 None
28882897 }
28892898 } else {
28902899 None
28912900 }
28922901 } )
2902+ . cloned ( )
28932903 . collect ( ) ;
28942904
28952905 if !funding_infos. is_empty ( ) {
@@ -2904,19 +2914,23 @@ async fn retry_until_funding_info_cleared(swap_id: SwapId, args: Vec<String>) {
29042914 for _ in 0 ..ALLOWED_RETRIES {
29052915 let ( stdout, _stderr) = run ( "../swap-cli" , args. clone ( ) ) . unwrap ( ) ;
29062916
2907- // get the btc funding address
2908- let funding_infos : Vec < BitcoinFundingInfo > = stdout
2917+ let funding_infos : Vec < FundingInfo > = cli_output_to_funding_infos ( stdout )
2918+ . swaps_need_funding
29092919 . iter ( )
2910- . filter_map ( |element| {
2911- info ! ( "cli: {}" , element) ;
2912- if let Ok ( funding_info) = BitcoinFundingInfo :: from_str ( element) {
2913- if funding_info. swap_id == swap_id {
2914- Some ( funding_info)
2920+ . filter_map ( |f| match f {
2921+ FundingInfo :: Bitcoin ( info) => {
2922+ if info. swap_id == swap_id {
2923+ Some ( FundingInfo :: Bitcoin ( info. clone ( ) ) )
2924+ } else {
2925+ None
2926+ }
2927+ }
2928+ FundingInfo :: Monero ( info) => {
2929+ if info. swap_id == swap_id {
2930+ Some ( FundingInfo :: Monero ( info. clone ( ) ) )
29152931 } else {
29162932 None
29172933 }
2918- } else {
2919- None
29202934 }
29212935 } )
29222936 . collect ( ) ;
@@ -2935,22 +2949,21 @@ async fn retry_until_monero_funding_address(
29352949) -> ( monero:: Address , monero:: Amount ) {
29362950 for _ in 0 ..ALLOWED_RETRIES {
29372951 let ( stdout, _stderr) = run ( "../swap-cli" , args. clone ( ) ) . unwrap ( ) ;
2938-
2939- // get the monero funding address
2940- let funding_infos: Vec < MoneroFundingInfo > = stdout
2952+ let funding_infos: Vec < MoneroFundingInfo > = cli_output_to_funding_infos ( stdout)
2953+ . swaps_need_funding
29412954 . iter ( )
2942- . filter_map ( |element| {
2943- info ! ( "cli: {}" , element) ;
2944- if let Ok ( funding_info) = MoneroFundingInfo :: from_str ( element) {
2945- if funding_info. swap_id == swap_id {
2946- Some ( funding_info)
2955+ . filter_map ( |f| {
2956+ if let FundingInfo :: Monero ( info) = f {
2957+ if info. swap_id == swap_id {
2958+ Some ( info)
29472959 } else {
29482960 None
29492961 }
29502962 } else {
29512963 None
29522964 }
29532965 } )
2966+ . cloned ( )
29542967 . collect ( ) ;
29552968
29562969 if !funding_infos. is_empty ( ) {
0 commit comments