From a5cad26ee7d5e58b8f26c12d8826f45d009b9d9a Mon Sep 17 00:00:00 2001 From: Jouzo <15011228+Jouzo@users.noreply.github.com> Date: Mon, 8 May 2023 10:19:31 +0100 Subject: [PATCH] Debug send_raw_transaction and return RPC error when could not publish eth tx via cpp_imports (#1975) --- lib/ain-grpc/src/rpc.rs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/ain-grpc/src/rpc.rs b/lib/ain-grpc/src/rpc.rs index b53ef32279..7f9305c3f3 100644 --- a/lib/ain-grpc/src/rpc.rs +++ b/lib/ain-grpc/src/rpc.rs @@ -377,18 +377,25 @@ impl MetachainRPCServer for MetachainRPCModule { let raw_tx = tx.strip_prefix("0x").unwrap_or(tx); let hex = hex::decode(raw_tx).map_err(|e| Error::Custom(format!("Eror decoding TX {e:?}")))?; - let stat = ain_cpp_imports::publish_eth_transaction(hex) - .map_err(|e| Error::Custom(format!("Error publishing TX {e:?}")))?; - let signed_tx = - SignedTx::try_from(raw_tx).map_err(|e| Error::Custom(format!("TX error {e:?}")))?; - - debug!( - "Transaction status: {:?}, hash: {}", - stat, - signed_tx.transaction.hash() - ); - Ok(format!("{:#x}", signed_tx.transaction.hash())) + match ain_cpp_imports::publish_eth_transaction(hex) { + Ok(true) => { + let signed_tx = SignedTx::try_from(raw_tx) + .map_err(|e| Error::Custom(format!("TX error {e:?}")))?; + debug!( + "Publishing transaction with hash: {:#x}", + signed_tx.transaction.hash() + ); + Ok(format!("{:#x}", signed_tx.transaction.hash())) + } + Ok(false) => { + debug!("Could not publish raw transaction: {tx}"); + Err(Error::Custom(format!( + "Could not publish raw transaction: {tx}" + ))) + } + Err(e) => Err(Error::Custom(format!("Error publishing TX {e:?}"))), + } } fn get_transaction_count(