diff --git a/client/src/client.rs b/client/src/client.rs index 9218dcc..5d4985b 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -110,6 +110,10 @@ impl Client { } } + pub async fn send_raw_transaction(&self, bytes: &Vec) -> Result> { + self.execution.send_raw_transaction(bytes).await + } + pub fn get_gas_price(&self) -> Result { let payload = self.get_payload(&None)?; let base_fee = U256::from_little_endian(&payload.base_fee_per_gas.to_bytes_le()); diff --git a/client/src/rpc.rs b/client/src/rpc.rs index 307f935..5d52ed6 100644 --- a/client/src/rpc.rs +++ b/client/src/rpc.rs @@ -10,7 +10,7 @@ use jsonrpsee::{ }; use super::Client; -use common::utils::u64_to_hex_string; +use common::utils::{hex_str_to_bytes, u64_to_hex_string}; use execution::types::{CallOpts, ExecutionBlock}; pub struct Rpc { @@ -61,6 +61,8 @@ trait EthRpc { async fn block_number(&self) -> Result; #[method(name = "getBlockByNumber")] async fn get_block_by_number(&self, num: &str, full_tx: bool) -> Result; + #[method(name = "sendRawTransaction")] + async fn send_raw_transaction(&self, bytes: &str) -> Result; } #[rpc(client, server, namespace = "net")] @@ -154,6 +156,13 @@ impl EthRpcServer for RpcInner { Ok(block) } + + async fn send_raw_transaction(&self, bytes: &str) -> Result { + let client = self.client.lock().await; + let bytes = convert_err(hex_str_to_bytes(bytes))?; + let tx_hash = convert_err(client.send_raw_transaction(&bytes).await)?; + Ok(hex::encode(tx_hash)) + } } #[async_trait] diff --git a/execution/src/execution.rs b/execution/src/execution.rs index a083fac..8172e9d 100644 --- a/execution/src/execution.rs +++ b/execution/src/execution.rs @@ -97,6 +97,10 @@ impl ExecutionClient { Ok(code) } + pub async fn send_raw_transaction(&self, bytes: &Vec) -> Result> { + self.rpc.send_raw_transaction(bytes).await + } + pub fn get_block(&self, payload: &ExecutionPayload) -> Result { let empty_nonce = "0x0000000000000000".to_string(); let empty_uncle_hash = "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"; diff --git a/execution/src/rpc.rs b/execution/src/rpc.rs index 9a2d1d9..e01163d 100644 --- a/execution/src/rpc.rs +++ b/execution/src/rpc.rs @@ -44,6 +44,14 @@ impl Rpc { hex_str_to_bytes(&code) } + pub async fn send_raw_transaction(&self, bytes: &Vec) -> Result> { + let client = self.client()?; + let bytes_hex = format!("0x{}", hex::encode(bytes)); + let params = rpc_params!(bytes_hex); + let tx_hash: String = client.request("eth_sendRawTransaction", params).await?; + hex_str_to_bytes(&tx_hash) + } + fn client(&self) -> Result { Ok(HttpClientBuilder::default().build(&self.rpc)?) }