File tree Expand file tree Collapse file tree 2 files changed +10
-7
lines changed
Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -372,12 +372,11 @@ impl<S: Sleeper> AsyncClient<S> {
372372 }
373373
374374 /// Broadcast a [`Transaction`] to Esplora
375- pub async fn broadcast ( & self , transaction : & Transaction ) -> Result < ( ) , Error > {
375+ pub async fn broadcast ( & self , transaction : & Transaction ) -> Result < Txid , Error > {
376376 let body = serialize :: < Transaction > ( transaction) . to_lower_hex_string ( ) ;
377- match self . post_request_bytes ( "/tx" , body, None ) . await {
378- Ok ( _resp) => Ok ( ( ) ) ,
379- Err ( e) => Err ( e) ,
380- }
377+ let response = self . post_request_bytes ( "/tx" , body, None ) . await ?;
378+ let txid = Txid :: from_str ( & response. text ( ) . await ?) . map_err ( |_| Error :: InvalidResponse ) ?;
379+ Ok ( txid)
381380 }
382381
383382 /// Broadcast a package of [`Transaction`] to Esplora
Original file line number Diff line number Diff line change @@ -290,7 +290,7 @@ impl BlockingClient {
290290 }
291291
292292 /// Broadcast a [`Transaction`] to Esplora
293- pub fn broadcast ( & self , transaction : & Transaction ) -> Result < ( ) , Error > {
293+ pub fn broadcast ( & self , transaction : & Transaction ) -> Result < Txid , Error > {
294294 let request = self . post_request (
295295 "/tx" ,
296296 serialize ( transaction)
@@ -305,7 +305,11 @@ impl BlockingClient {
305305 let message = resp. as_str ( ) . unwrap_or_default ( ) . to_string ( ) ;
306306 Err ( Error :: HttpResponse { status, message } )
307307 }
308- Ok ( _resp) => Ok ( ( ) ) ,
308+ Ok ( resp) => {
309+ let txid =
310+ Txid :: from_str ( resp. as_str ( ) . unwrap_or_default ( ) ) . map_err ( Error :: HexToArray ) ?;
311+ Ok ( txid)
312+ }
309313 Err ( e) => Err ( Error :: Minreq ( e) ) ,
310314 }
311315 }
You can’t perform that action at this time.
0 commit comments