diff --git a/lib/ain-cpp-imports/src/bridge.rs b/lib/ain-cpp-imports/src/bridge.rs index 8750d3b63a4..1108a186e05 100644 --- a/lib/ain-cpp-imports/src/bridge.rs +++ b/lib/ain-cpp-imports/src/bridge.rs @@ -5,7 +5,7 @@ pub mod ffi { fn getChainId() -> u64; fn isMining() -> bool; - fn publishEthTransaction(data: Vec) -> bool; + fn publishEthTransaction(data: Vec) -> String; fn getAccounts() -> Vec; fn getDatadir() -> String; fn getDifficulty(_block_hash: [u8; 32]) -> u32; diff --git a/lib/ain-cpp-imports/src/lib.rs b/lib/ain-cpp-imports/src/lib.rs index df5a623a180..352d9f2032b 100644 --- a/lib/ain-cpp-imports/src/lib.rs +++ b/lib/ain-cpp-imports/src/lib.rs @@ -16,7 +16,7 @@ mod ffi { pub fn isMining() -> bool { unimplemented!("{}", UNIMPL_MSG) } - pub fn publishEthTransaction(_data: Vec) -> bool { + pub fn publishEthTransaction(_data: Vec) -> String { unimplemented!("{}", UNIMPL_MSG) } pub fn getAccounts() -> Vec { @@ -55,7 +55,7 @@ pub fn is_mining() -> Result> { Ok(is_mining) } -pub fn publish_eth_transaction(data: Vec) -> Result> { +pub fn publish_eth_transaction(data: Vec) -> Result> { let publish = ffi::publishEthTransaction(data); Ok(publish) } diff --git a/lib/ain-grpc/src/rpc/eth.rs b/lib/ain-grpc/src/rpc/eth.rs index e3e33b3a266..3d2ff0c2178 100644 --- a/lib/ain-grpc/src/rpc/eth.rs +++ b/lib/ain-grpc/src/rpc/eth.rs @@ -554,30 +554,31 @@ impl MetachainRPCServer for MetachainRPCModule { hex::decode(raw_tx).map_err(|e| Error::Custom(format!("Eror decoding TX {e:?}")))?; 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!(target:"rpc", - "[send_raw_transaction] signed_tx sender : {:#x}", - signed_tx.sender - ); - debug!(target:"rpc", - "[send_raw_transaction] signed_tx nonce : {:#x}", - signed_tx.nonce() - ); - debug!(target:"rpc", - "[send_raw_transaction] transaction hash : {:#x}", - signed_tx.transaction.hash() - ); - - Ok(format!("{:#x}", signed_tx.transaction.hash())) - } - Ok(false) => { - debug!(target:"rpc","[send_raw_transaction] Could not publish raw transaction: {tx}"); - Err(Error::Custom(format!( - "Could not publish raw transaction: {tx}" - ))) + Ok(res_string) => { + if res_string.is_empty() { + let signed_tx = SignedTx::try_from(raw_tx) + .map_err(|e| Error::Custom(format!("TX error {e:?}")))?; + + debug!(target:"rpc", + "[send_raw_transaction] signed_tx sender : {:#x}", + signed_tx.sender + ); + debug!(target:"rpc", + "[send_raw_transaction] signed_tx nonce : {:#x}", + signed_tx.nonce() + ); + debug!(target:"rpc", + "[send_raw_transaction] transaction hash : {:#x}", + signed_tx.transaction.hash() + ); + + Ok(format!("{:#x}", signed_tx.transaction.hash())) + } else { + debug!(target:"rpc","[send_raw_transaction] Could not publish raw transaction: {tx}"); + Err(Error::Custom(format!( + "Could not publish raw transaction: {tx} resaon: {res_string}" + ))) + } } Err(e) => { debug!(target:"rpc","[send_raw_transaction] Error publishing TX {e:?}"); diff --git a/src/ffi/ffiexports.cpp b/src/ffi/ffiexports.cpp index 4ab5f862e65..e2632d98883 100644 --- a/src/ffi/ffiexports.cpp +++ b/src/ffi/ffiexports.cpp @@ -12,7 +12,7 @@ bool isMining() { return gArgs.GetBoolArg("-gen", false); } -bool publishEthTransaction(rust::Vec rawTransaction) { +rust::string publishEthTransaction(rust::Vec rawTransaction) { std::vector evmTx(rawTransaction.size()); std::copy(rawTransaction.begin(), rawTransaction.end(), evmTx.begin()); CDataStream metadata(DfTxMarker, SER_NETWORK, PROTOCOL_VERSION); @@ -44,11 +44,11 @@ bool publishEthTransaction(rust::Vec rawTransaction) { try { execTestTx(CTransaction(rawTx), targetHeight, optAuthTx); send(MakeTransactionRef(std::move(rawTx)), optAuthTx)->GetHash().ToString(); - } catch (...) { - return false; + } catch (std::runtime_error& e) { + return e.what(); } - return true; + return {}; } rust::vec getAccounts() { diff --git a/src/ffi/ffiexports.h b/src/ffi/ffiexports.h index bfb50ebaac1..20e718d5da7 100644 --- a/src/ffi/ffiexports.h +++ b/src/ffi/ffiexports.h @@ -6,7 +6,7 @@ uint64_t getChainId(); bool isMining(); -bool publishEthTransaction(rust::Vec rawTransaction); +rust::string publishEthTransaction(rust::Vec rawTransaction); rust::vec getAccounts(); rust::string getDatadir(); uint32_t getDifficulty(std::array blockHash);