@ -1,11 +1,11 @@
use crate ::model ::WalletInfo ;
use crate ::model ::WalletInfo ;
use anyhow ::{ anyhow , Context , Result } ;
use anyhow ::{ Context , Result } ;
use bdk ::bitcoin ::util ::bip32 ::ExtendedPrivKey ;
use bdk ::bitcoin ::util ::bip32 ::ExtendedPrivKey ;
use bdk ::bitcoin ::util ::psbt ::PartiallySignedTransaction ;
use bdk ::bitcoin ::util ::psbt ::PartiallySignedTransaction ;
use bdk ::bitcoin ::{ Amount , PublicKey , Transaction , Txid } ;
use bdk ::bitcoin ::{ Amount , PublicKey , Transaction , Txid } ;
use bdk ::blockchain ::{ ElectrumBlockchain , NoopProgress } ;
use bdk ::blockchain ::{ ElectrumBlockchain , NoopProgress } ;
use bdk ::wallet ::AddressIndex ;
use bdk ::wallet ::AddressIndex ;
use bdk ::{ electrum_client , Error , KeychainKind , SignOptions } ;
use bdk ::{ electrum_client , KeychainKind , SignOptions } ;
use cfd_protocol ::{ PartyParams , WalletExt } ;
use cfd_protocol ::{ PartyParams , WalletExt } ;
use rocket ::serde ::json ::Value ;
use rocket ::serde ::json ::Value ;
use std ::path ::Path ;
use std ::path ::Path ;
@ -98,29 +98,24 @@ impl Wallet {
let wallet = self . wallet . lock ( ) . await ;
let wallet = self . wallet . lock ( ) . await ;
// TODO: Optimize this match to be a map_err / more readable in general
// TODO: Optimize this match to be a map_err / more readable in general
let txid = tx . txid ( ) ;
let txid = tx . txid ( ) ;
match wallet . broadcast ( tx ) {
Ok ( txid ) = > Ok ( txid ) ,
let result = wallet . broadcast ( tx ) ;
Err ( e ) = > {
if let Error ::Electrum ( electrum_client ::Error ::Protocol ( ref value ) ) = e {
if let Err ( & bdk ::Error ::Electrum ( electrum_client ::Error ::Protocol ( ref value ) ) ) =
let error_code = match parse_rpc_protocol_error_code ( value ) {
result . as_ref ( )
Ok ( error_code ) = > error_code ,
{
Err ( inner ) = > {
let error_code = parse_rpc_protocol_error_code ( value ) . with_context ( | | {
tracing ::error ! (
format ! ( "Failed to parse electrum error response '{:?}'" , value )
"Failed to parse error code from RPC message: {}" ,
} ) ? ;
inner
) ;
if error_code = = i64 ::from ( RpcErrorCode ::RpcVerifyAlreadyInChain ) {
return Err ( anyhow ! ( e ) ) ;
return Ok ( txid ) ;
}
} ;
if error_code = = i64 ::from ( RpcErrorCode ::RpcVerifyAlreadyInChain ) {
return Ok ( txid ) ;
}
}
Err ( anyhow ! ( e ) )
}
}
}
}
let txid = result ? ;
Ok ( txid )
}
}
}
}