-
Notifications
You must be signed in to change notification settings - Fork 22
feat: add eth_sendRawTransaction client support
#467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c20ee34
a3d81d3
0db5cc2
0177a4e
9a56210
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| use crate::{Block, FeeHistory, Hex, LogEntry, MultiRpcResult, Nat256}; | ||
| use crate::{ | ||
| Block, FeeHistory, Hex, JsonRpcError, LogEntry, MultiRpcResult, Nat256, RpcError, | ||
| SendRawTransactionStatus, ValidationError, | ||
| }; | ||
|
|
||
| impl From<MultiRpcResult<Vec<LogEntry>>> for MultiRpcResult<Vec<alloy_rpc_types::Log>> { | ||
| fn from(result: MultiRpcResult<Vec<LogEntry>>) -> Self { | ||
|
|
@@ -33,3 +36,26 @@ impl From<MultiRpcResult<Hex>> for MultiRpcResult<alloy_primitives::Bytes> { | |
| result.map(alloy_primitives::Bytes::from) | ||
| } | ||
| } | ||
|
|
||
| impl From<MultiRpcResult<SendRawTransactionStatus>> for MultiRpcResult<alloy_primitives::B256> { | ||
| fn from(result: MultiRpcResult<SendRawTransactionStatus>) -> Self { | ||
| result.and_then(|status| match status { | ||
| SendRawTransactionStatus::Ok(maybe_hash) => match maybe_hash { | ||
| Some(hash) => Ok(alloy_primitives::B256::from(hash)), | ||
| None => Err(RpcError::ValidationError(ValidationError::Custom( | ||
| "Unable to compute transaction hash".to_string(), | ||
| ))), | ||
| }, | ||
| error => Err(RpcError::JsonRpcError(JsonRpcError { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gregorydemay I noticed that we do some extra parsing for the result of IIUC the JSON-RPC processing is done to avoid getting inconsistent results due to differing error codes/messages between providers. However, I think it would be also OK to return the canonicalized errors still as a JSON-RPC error, just with a standardized error message and code. In terms of error canonicalization, I think the exact message is not very important, but the code is less clear to me. Most providers return something along the lines of Another direction, would be to add a new optional flag to the RPC config for Finally, we could either create a new WDYT?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah I see, that makes sense. I've changed the return type to be |
||
| code: -32_000, | ||
| message: match error { | ||
| SendRawTransactionStatus::Ok(_) => unreachable!(), | ||
| SendRawTransactionStatus::InsufficientFunds => "Insufficient funds", | ||
| SendRawTransactionStatus::NonceTooLow => "Nonce too low", | ||
| SendRawTransactionStatus::NonceTooHigh => "Nonce too high", | ||
| } | ||
| .to_string(), | ||
| })), | ||
| }) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a follow-up PR: here we could build an actual transaction with
alloyand sign it with t-sig. The example then becomes rather long though, especially with signing. Some ideas:alloytransactionseth_sendTransactionwhere we wouldn't need to do the transaction serializationThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!