-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat(rpc): Add ots_ namespace and trait bindings for Otterscan Endpoints #3778
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b0f2e11
Adding ots_ namespace and trait bindings
ZePedroResende 92852f7
code review
ZePedroResende ab84d33
code review
ZePedroResende fdb04f3
code review
ZePedroResende a39b60a
Missing vec
ZePedroResende 33bc94e
Types code review
ZePedroResende 6f286f8
Fix block_number type
ZePedroResende 77fe385
Merge branch 'main' into traits
mattsse 9babe78
Merge branch 'main' into traits
mattsse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| use jsonrpsee::{core::RpcResult, proc_macros::rpc}; | ||
| use reth_primitives::{Address, BlockId, BlockNumberOrTag, TxHash, H256}; | ||
| use reth_rpc_types::{ | ||
| BlockDetails, ContractCreator, InternalOperation, OtsBlockTransactions, TraceEntry, | ||
| Transaction, TransactionsWithReceipts, | ||
| }; | ||
|
|
||
| /// Otterscan rpc interface. | ||
| #[cfg_attr(not(feature = "client"), rpc(server, namespace = "ots"))] | ||
| #[cfg_attr(feature = "client", rpc(server, client, namespace = "ots"))] | ||
| pub trait Otterscan { | ||
| /// Check if a certain address contains a deployed code. | ||
| #[method(name = "hasCode")] | ||
| async fn has_code(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<bool>; | ||
|
|
||
| /// Very simple API versioning scheme. Every time we add a new capability, the number is | ||
| /// incremented. This allows for Otterscan to check if the node contains all API it | ||
| /// needs. | ||
| #[method(name = "getApiLevel")] | ||
| async fn get_api_level(&self) -> RpcResult<u64>; | ||
|
|
||
| /// Return the internal ETH transfers inside a transaction. | ||
| #[method(name = "getInternalOperations")] | ||
| async fn get_internal_operations(&self, tx_hash: TxHash) -> RpcResult<Vec<InternalOperation>>; | ||
|
|
||
| /// Given a transaction hash, returns its raw revert reason. | ||
| #[method(name = "getTransactionError")] | ||
| async fn get_transaction_error(&self, tx_hash: TxHash) -> RpcResult<String>; | ||
|
|
||
| /// Extract all variations of calls, contract creation and self-destructs and returns a call | ||
| /// tree. | ||
| #[method(name = "traceTransaction")] | ||
| async fn trace_transaction(&self, tx_hash: TxHash) -> RpcResult<TraceEntry>; | ||
|
|
||
| /// Tailor-made and expanded version of eth_getBlockByNumber for block details page in | ||
| /// Otterscan. | ||
| #[method(name = "getBlockDetails")] | ||
| async fn get_block_details( | ||
| &self, | ||
| block_number: BlockNumberOrTag, | ||
| ) -> RpcResult<Option<BlockDetails>>; | ||
|
|
||
| /// Tailor-made and expanded version of eth_getBlockByHash for block details page in Otterscan. | ||
| #[method(name = "getBlockDetailsByHash")] | ||
| async fn get_block_details_by_hash(&self, block_hash: H256) -> RpcResult<Option<BlockDetails>>; | ||
|
|
||
| /// Get paginated transactions for a certain block. Also remove some verbose fields like logs. | ||
| #[method(name = "getBlockTransactions")] | ||
| async fn get_block_transactions( | ||
| &self, | ||
| block_number: BlockNumberOrTag, | ||
| page_number: usize, | ||
| page_size: usize, | ||
| ) -> RpcResult<OtsBlockTransactions>; | ||
|
|
||
| /// Gets paginated inbound/outbound transaction calls for a certain address. | ||
| #[method(name = "searchTransactionsBefore")] | ||
| async fn search_transactions_before( | ||
| &self, | ||
| address: Address, | ||
| block_number: BlockNumberOrTag, | ||
| page_size: usize, | ||
| ) -> RpcResult<TransactionsWithReceipts>; | ||
|
|
||
| /// Gets paginated inbound/outbound transaction calls for a certain address. | ||
| #[method(name = "searchTransactionsAfter")] | ||
| async fn search_transactions_after( | ||
| &self, | ||
| address: Address, | ||
| block_number: BlockNumberOrTag, | ||
| page_size: usize, | ||
| ) -> RpcResult<TransactionsWithReceipts>; | ||
|
|
||
| /// Gets the transaction hash for a certain sender address, given its nonce. | ||
| #[method(name = "getTransactionBySenderAndNonce")] | ||
| async fn get_transaction_by_sender_and_nonce( | ||
| &self, | ||
| sender: Address, | ||
| nonce: u64, | ||
| ) -> RpcResult<Option<Transaction>>; | ||
|
|
||
| /// Gets the transaction hash and the address who created a contract. | ||
| #[method(name = "getContractCreator")] | ||
| async fn get_contract_creator(&self, address: Address) -> RpcResult<Option<ContractCreator>>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| use crate::{Block, Transaction, TransactionReceipt}; | ||
| use reth_primitives::{Address, Bytes, U256}; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| /// Operation type enum for `InternalOperation` struct | ||
| #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
| pub enum OperationType { | ||
| /// Operation Transfer | ||
| OpTransfer = 0, | ||
| /// Operation Contract self destruct | ||
| OpSelfDestruct = 1, | ||
| /// Operation Create | ||
| OpCreate = 2, | ||
| /// Operation Create2 | ||
| OpCreate2 = 3, | ||
| } | ||
|
|
||
| /// Custom struct for otterscan `getInternalOperations` RPC response | ||
| #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
| pub struct InternalOperation { | ||
| r#type: OperationType, | ||
| from: Address, | ||
| to: Address, | ||
| value: u128, | ||
| } | ||
|
|
||
| /// Custom struct for otterscan `traceTransaction` RPC response | ||
| #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
| pub struct TraceEntry { | ||
| r#type: String, | ||
| depth: u32, | ||
| from: Address, | ||
| to: Address, | ||
| value: u128, | ||
| input: Bytes, | ||
| } | ||
|
|
||
| /// Internal issuance struct for `BlockDetails` struct | ||
| #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct InternalIssuance { | ||
| block_reward: U256, | ||
| uncle_reward: U256, | ||
| issuance: U256, | ||
| } | ||
|
|
||
| /// Custom `Block` struct that includes transaction count for Otterscan responses | ||
| #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct OtsBlock { | ||
| #[serde(flatten)] | ||
| block: Block, | ||
| transaction_count: usize, | ||
| } | ||
|
|
||
| /// Custom struct for otterscan `getBlockDetails` RPC response | ||
| #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct BlockDetails { | ||
| block: OtsBlock, | ||
| issuance: InternalIssuance, | ||
| total_fees: U256, | ||
| } | ||
|
|
||
| /// Custom transaction receipt struct for otterscan `OtsBlockTransactions` struct | ||
| #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct OtsTransactionReceipt { | ||
| #[serde(flatten)] | ||
| receipt: TransactionReceipt, | ||
| timestamp: u64, | ||
| } | ||
|
|
||
| /// Custom struct for otterscan `getBlockTransactions` RPC response | ||
| #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
| pub struct OtsBlockTransactions { | ||
| fullblock: OtsBlock, | ||
| receipts: Vec<OtsTransactionReceipt>, | ||
| } | ||
|
|
||
| /// Custom struct for otterscan `searchTransactionsAfter`and `searchTransactionsBefore` RPC | ||
| /// responses | ||
| #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct TransactionsWithReceipts { | ||
| txs: Vec<Transaction>, | ||
| receipts: Vec<OtsTransactionReceipt>, | ||
| first_page: bool, | ||
| last_page: bool, | ||
| } | ||
|
|
||
| /// Custom struct for otterscan `getContractCreator` RPC responses | ||
| #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] | ||
| pub struct ContractCreator { | ||
| tx: Transaction, | ||
| creator: Address, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| #![allow(dead_code, unused_variables)] | ||
| use crate::result::internal_rpc_err; | ||
| use async_trait::async_trait; | ||
| use jsonrpsee::core::RpcResult; | ||
| use reth_primitives::{Address, BlockId, BlockNumberOrTag, TxHash, H256}; | ||
| use reth_rpc_api::{EthApiServer, OtterscanServer}; | ||
| use reth_rpc_types::{ | ||
| BlockDetails, ContractCreator, InternalOperation, OtsBlockTransactions, TraceEntry, | ||
| Transaction, TransactionsWithReceipts, | ||
| }; | ||
|
|
||
| /// Otterscan Api | ||
| #[derive(Debug)] | ||
| pub struct OtterscanApi<Eth> { | ||
| eth: Eth, | ||
| } | ||
|
|
||
| impl<Eth> OtterscanApi<Eth> { | ||
| /// Creates a new instance of `Otterscan`. | ||
| pub fn new(eth: Eth) -> Self { | ||
| Self { eth } | ||
| } | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl<Eth> OtterscanServer for OtterscanApi<Eth> | ||
| where | ||
| Eth: EthApiServer, | ||
|
Collaborator
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. this might not be enough to fully support the otterscan API, but it is sufficient for now, but can reevaluate later, see TraceApiImpl for example |
||
| { | ||
| /// Handler for `ots_hasCode` | ||
| async fn has_code(&self, address: Address, block_number: Option<BlockId>) -> RpcResult<bool> { | ||
| Err(internal_rpc_err("unimplemented")) | ||
| } | ||
|
|
||
| /// Handler for `ots_getApiLevel` | ||
| async fn get_api_level(&self) -> RpcResult<u64> { | ||
| Err(internal_rpc_err("unimplemented")) | ||
| } | ||
|
|
||
| /// Handler for `ots_getInternalOperations` | ||
| async fn get_internal_operations(&self, tx_hash: TxHash) -> RpcResult<Vec<InternalOperation>> { | ||
| Err(internal_rpc_err("unimplemented")) | ||
| } | ||
|
|
||
| /// Handler for `ots_getTransactionError` | ||
| async fn get_transaction_error(&self, tx_hash: TxHash) -> RpcResult<String> { | ||
| Err(internal_rpc_err("unimplemented")) | ||
| } | ||
|
|
||
| /// Handler for `ots_traceTransaction` | ||
| async fn trace_transaction(&self, tx_hash: TxHash) -> RpcResult<TraceEntry> { | ||
| Err(internal_rpc_err("unimplemented")) | ||
| } | ||
|
|
||
| /// Handler for `ots_getBlockDetails` | ||
| async fn get_block_details( | ||
| &self, | ||
| block_number: BlockNumberOrTag, | ||
| ) -> RpcResult<Option<BlockDetails>> { | ||
| Err(internal_rpc_err("unimplemented")) | ||
| } | ||
|
|
||
| /// Handler for `getBlockDetailsByHash` | ||
| async fn get_block_details_by_hash(&self, block_hash: H256) -> RpcResult<Option<BlockDetails>> { | ||
| Err(internal_rpc_err("unimplemented")) | ||
| } | ||
|
|
||
| /// Handler for `getBlockTransactions` | ||
| async fn get_block_transactions( | ||
| &self, | ||
| block_number: BlockNumberOrTag, | ||
| page_number: usize, | ||
| page_size: usize, | ||
| ) -> RpcResult<OtsBlockTransactions> { | ||
| Err(internal_rpc_err("unimplemented")) | ||
| } | ||
|
|
||
| /// Handler for `searchTransactionsBefore` | ||
| async fn search_transactions_before( | ||
| &self, | ||
| address: Address, | ||
| block_number: BlockNumberOrTag, | ||
| page_size: usize, | ||
| ) -> RpcResult<TransactionsWithReceipts> { | ||
| Err(internal_rpc_err("unimplemented")) | ||
| } | ||
|
|
||
| /// Handler for `searchTransactionsAfter` | ||
| async fn search_transactions_after( | ||
| &self, | ||
| address: Address, | ||
| block_number: BlockNumberOrTag, | ||
| page_size: usize, | ||
| ) -> RpcResult<TransactionsWithReceipts> { | ||
| Err(internal_rpc_err("unimplemented")) | ||
| } | ||
|
|
||
| /// Handler for `getTransactionBySenderAndNonce` | ||
| async fn get_transaction_by_sender_and_nonce( | ||
| &self, | ||
| sender: Address, | ||
| nonce: u64, | ||
| ) -> RpcResult<Option<Transaction>> { | ||
| Err(internal_rpc_err("unimplemented")) | ||
| } | ||
|
|
||
| /// Handler for `getContractCreator` | ||
| async fn get_contract_creator(&self, address: Address) -> RpcResult<Option<ContractCreator>> { | ||
| Err(internal_rpc_err("unimplemented")) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.