File tree Expand file tree Collapse file tree 2 files changed +12
-9
lines changed
Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -371,13 +371,12 @@ impl<S: Sleeper> AsyncClient<S> {
371371 . await
372372 }
373373
374- /// Broadcast a [`Transaction`] to Esplora.
375- pub async fn broadcast ( & self , transaction : & Transaction ) -> Result < ( ) , Error > {
374+ /// Broadcast a [`Transaction`] to Esplora
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`]s to Esplora.
Original file line number Diff line number Diff line change @@ -289,8 +289,8 @@ impl BlockingClient {
289289 self . get_opt_response_json ( & format ! ( "/tx/{txid}/outspend/{index}" ) )
290290 }
291291
292- /// Broadcast a [`Transaction`] to Esplora.
293- pub fn broadcast ( & self , transaction : & Transaction ) -> Result < ( ) , Error > {
292+ /// Broadcast a [`Transaction`] to Esplora
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