Skip to content

Commit

Permalink
get wallet transaction count (#228)
Browse files Browse the repository at this point in the history
Co-authored-by: Haider Ali <[email protected]>
  • Loading branch information
haider-rs and Haider Ali authored Mar 29, 2024
1 parent 4ed222d commit d1d0f56
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions chains/ethereum/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use rosetta_ethereum_types::TxHash;
pub use types::{
Address, AtBlock, BlockFull, Bloom, CallContract, CallResult, EIP1186ProofResponse,
EthereumMetadata, EthereumMetadataParams, GetBalance, GetProof, GetStorageAt,
GetTransactionReceipt, Header, Log, PartialBlock, Query, QueryItem, QueryResult, SealedHeader,
SignedTransaction, StorageProof, TransactionReceipt, H256,
GetTransactionCount, GetTransactionReceipt, Header, Log, PartialBlock, Query, QueryItem,
QueryResult, SealedHeader, SignedTransaction, StorageProof, TransactionReceipt, H256,
};

pub mod query {
Expand Down
23 changes: 23 additions & 0 deletions chains/ethereum/config/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,23 @@ impl QueryT for GetBalance {
}
impl_query_item!(GetBalance);

/// Returns the number of transactions sent from an address.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "scale-info", derive(scale_info::TypeInfo))]
#[cfg_attr(feature = "scale-codec", derive(parity_scale_codec::Encode, parity_scale_codec::Decode))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct GetTransactionCount {
/// Account address
pub address: Address,
/// Balance at the block
pub block: AtBlock,
}

impl QueryT for GetTransactionCount {
type Result = u64;
}
impl_query_item!(GetTransactionCount);

/// Executes a new message call immediately without creating a transaction on the blockchain.
#[derive(Clone, Default, PartialEq, Eq, Debug, Hash)]
#[cfg_attr(feature = "scale-info", derive(scale_info::TypeInfo))]
Expand Down Expand Up @@ -315,6 +332,9 @@ pub enum Query {
/// Returns the balance of the account of given address.
#[cfg_attr(feature = "serde", serde(rename = "eth_getBalance"))]
GetBalance(GetBalance),
/// Returns the number of transactions sent from an address.
#[cfg_attr(feature = "serde", serde(rename = "eth_getTransactionCount"))]
GetTransactionCount(GetTransactionCount),
/// Returns the value from a storage position at a given address.
#[cfg_attr(feature = "serde", serde(rename = "eth_getStorageAt"))]
GetStorageAt(GetStorageAt),
Expand Down Expand Up @@ -439,6 +459,9 @@ pub enum QueryResult {
/// Returns the balance of the account of given address.
#[cfg_attr(feature = "serde", serde(rename = "eth_getBalance"))]
GetBalance(<GetBalance as QueryT>::Result),
/// Returns the number of transactions sent from an address.
#[cfg_attr(feature = "serde", serde(rename = "eth_getTransactionCount"))]
GetTransactionCount(<GetTransactionCount as QueryT>::Result),
/// Returns the value from a storage position at a given address.
#[cfg_attr(feature = "serde", serde(rename = "eth_getStorageAt"))]
GetStorageAt(<GetStorageAt as QueryT>::Result),
Expand Down
9 changes: 7 additions & 2 deletions chains/ethereum/server/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ use rosetta_config_ethereum::{
},
query::GetBlock,
CallContract, CallResult, EthereumMetadata, EthereumMetadataParams, GetBalance, GetProof,
GetStorageAt, GetTransactionReceipt, Query as EthQuery, QueryResult as EthQueryResult,
SubmitResult, Subscription,
GetStorageAt, GetTransactionCount, GetTransactionReceipt, Query as EthQuery,
QueryResult as EthQueryResult, SubmitResult, Subscription,
};

use rosetta_core::{
crypto::{address::Address, PublicKey},
types::{BlockIdentifier, PartialBlockIdentifier},
Expand Down Expand Up @@ -397,6 +398,10 @@ where
let balance = self.backend.get_balance(*address, *block).await?;
EthQueryResult::GetBalance(balance)
},
EthQuery::GetTransactionCount(GetTransactionCount { address, block }) => {
let nonce = self.backend.get_transaction_count(*address, *block).await?;
EthQueryResult::GetTransactionCount(nonce)
},
EthQuery::GetStorageAt(GetStorageAt { address, at, block }) => {
let value = self.backend.storage(*address, *at, *block).await?;
EthQueryResult::GetStorageAt(value)
Expand Down

0 comments on commit d1d0f56

Please sign in to comment.