@@ -14,7 +14,7 @@ use regex::Regex;
14
14
use cosmrs:: tx:: Tx ;
15
15
use prost:: Message ;
16
16
use crate :: utils:: format_token_amount_with_denom;
17
- use log:: { info, error, warn} ;
17
+ use log:: { info, error, warn, debug } ;
18
18
19
19
20
20
#[ derive( Serialize , Deserialize , Debug ) ]
@@ -53,7 +53,7 @@ pub async fn broadcast_tx(
53
53
let broadcast_url = get_osmosis_broadcast_tx_url ( ) ;
54
54
let broadcast_body = json ! ( {
55
55
"tx_bytes" : tx_base64,
56
- "mode" : 2
56
+ "mode" : "BROADCAST_MODE_ASYNC"
57
57
} ) ;
58
58
let response = client. post ( broadcast_url)
59
59
. json ( & broadcast_body)
@@ -71,8 +71,14 @@ pub async fn broadcast_tx(
71
71
info ! ( ">>> Transaction broadcasted" ) ;
72
72
73
73
// Store the broadcasted transaction
74
- let txhash = response_json[ "tx_response" ] [ "txhash" ] . as_str ( ) . unwrap ( ) ;
75
- let code = response_json[ "tx_response" ] [ "code" ] . as_u64 ( ) ;
74
+ let txhash = match response_json[ "tx_response" ] [ "txhash" ] . as_str ( ) {
75
+ Some ( hash) => hash,
76
+ None => return Err ( anyhow:: anyhow!( "Failed to get txhash from response" ) ) ,
77
+ } ;
78
+ let code = match response_json[ "tx_response" ] [ "code" ] . as_u64 ( ) {
79
+ Some ( code) => Some ( code) ,
80
+ None => return Err ( anyhow:: anyhow!( "Failed to get code from response" ) ) ,
81
+ } ;
76
82
let raw_log = response_json[ "tx_response" ] [ "raw_log" ] . as_str ( ) . map ( String :: from) ;
77
83
let _ = store_broadcasted_transaction (
78
84
sender_address,
@@ -272,7 +278,7 @@ async fn poll_transaction_status(txhash: &str, account_id: &str) -> Result<Optio
272
278
Ok ( ( code, raw_log, gas_used, tokens_in, tokens_out) ) => {
273
279
if code. is_some ( ) {
274
280
// Transaction was executed
275
- update_transaction_status ( txhash, account_id, "executed" , code, raw_log, gas_used, tokens_in, tokens_out) . await ?;
281
+ update_transaction ( txhash, account_id, "executed" , code, raw_log, gas_used, tokens_in, tokens_out) . await ?;
276
282
return Ok ( code) ;
277
283
} else {
278
284
info ! ( "... Transaction not yet confirmed" ) ;
@@ -290,8 +296,8 @@ async fn poll_transaction_status(txhash: &str, account_id: &str) -> Result<Optio
290
296
}
291
297
292
298
293
- // Function to update the transaction status in the JSON file
294
- async fn update_transaction_status (
299
+ // Function to update the transaction details in the JSON file
300
+ async fn update_transaction (
295
301
txhash : & str ,
296
302
account_id : & str ,
297
303
status : & str ,
@@ -320,6 +326,8 @@ async fn update_transaction_status(
320
326
transaction[ "tokens_in" ] = json ! ( tokens_in) ;
321
327
transaction[ "tokens_out" ] = json ! ( tokens_out) ;
322
328
329
+ debug ! ( "update_transaction: {}" , transaction) ;
330
+
323
331
// Write the updated transactions back to the file
324
332
fs:: write ( file_path, serde_json:: to_string_pretty ( & transactions) ?) ?;
325
333
}
@@ -331,7 +339,7 @@ async fn update_transaction_status(
331
339
// Function to handle timeout scenario
332
340
async fn update_transaction_with_timeout ( txhash : & str ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
333
341
// Implement your logic to update the transaction with timeout error here
334
- update_transaction_status ( txhash, "account_id" , "timeout" , None , None , None , None , None ) . await ?;
342
+ update_transaction ( txhash, "account_id" , "timeout" , None , None , None , None , None ) . await ?;
335
343
Ok ( ( ) )
336
344
}
337
345
0 commit comments