Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
888 changes: 525 additions & 363 deletions Cargo.lock

Large diffs are not rendered by default.

153 changes: 79 additions & 74 deletions Cargo.toml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fp-storage = { workspace = true, features = ["default"] }
[dev-dependencies]
futures = { workspace = true }
maplit = "1.0.2"
tempfile = "3.14.0"
tempfile = "3.17.1"
# Substrate
sc-block-builder = { workspace = true }
sp-consensus = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion client/mapping-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ethereum = { workspace = true }
ethereum-types = { workspace = true }
scale-codec = { workspace = true }
sqlx = { workspace = true, features = ["runtime-tokio-native-tls", "sqlite"] }
tempfile = "3.14.0"
tempfile = "3.17.1"
tokio = { workspace = true, features = ["sync"] }
# Substrate
sc-block-builder = { workspace = true }
Expand Down
6 changes: 5 additions & 1 deletion client/rpc-core/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ pub trait EthApi {
number_or_hash: Option<BlockNumberOrHash>,
) -> RpcResult<U256>;

/// Returns all pending transactions.
#[method(name = "eth_pendingTransactions")]
async fn pending_transactions(&self) -> RpcResult<Vec<Transaction>>;

// ########################################################################
// Fee
// ########################################################################
Expand All @@ -214,7 +218,7 @@ pub trait EthApi {
#[method(name = "eth_feeHistory")]
async fn fee_history(
&self,
block_count: U256,
block_count: BlockCount,
newest_block: BlockNumberOrHash,
reward_percentiles: Option<Vec<f64>>,
) -> RpcResult<FeeHistory>;
Expand Down
133 changes: 133 additions & 0 deletions client/rpc-core/src/types/block_count.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// This file is part of Frontier.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use std::{fmt, str::FromStr};

use ethereum_types::U256;
use serde::{
de::{Error, Visitor},
Deserialize, Deserializer, Serialize, Serializer,
};

/// Represents An RPC Api block count param, which can take the form of a number, an hex string, or a 32-bytes array
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum BlockCount {
/// U256
U256(U256),
/// Number
Num(u64),
}

impl<'a> Deserialize<'a> for BlockCount {
fn deserialize<D>(deserializer: D) -> Result<BlockCount, D::Error>
where
D: Deserializer<'a>,
{
deserializer.deserialize_any(BlockCountVisitor)
}
}

impl Serialize for BlockCount {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match *self {
BlockCount::U256(ref x) => x.serialize(serializer),
BlockCount::Num(ref x) => serializer.serialize_str(&format!("0x{:x}", x)),
}
}
}

struct BlockCountVisitor;

impl From<BlockCount> for U256 {
fn from(block_count: BlockCount) -> U256 {
match block_count {
BlockCount::Num(n) => U256::from(n),
BlockCount::U256(n) => n,
}
}
}

impl From<BlockCount> for u64 {
fn from(block_count: BlockCount) -> u64 {
match block_count {
BlockCount::Num(n) => n,
BlockCount::U256(n) => n.as_u64(),
}
}
}

impl<'a> Visitor<'a> for BlockCountVisitor {
type Value = BlockCount;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(
formatter,
"an intenger, a (both 0x-prefixed or not) hex string or byte array containing between (0; 32] bytes"
)
}

fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: Error,
{
let number = value.parse::<u64>();
match number {
Ok(n) => Ok(BlockCount::Num(n)),
Err(_) => U256::from_str(value).map(BlockCount::U256).map_err(|_| {
Error::custom("Invalid block count: non-decimal or missing 0x prefix".to_string())
}),
}
}

fn visit_string<E>(self, value: String) -> Result<Self::Value, E>
where
E: Error,
{
self.visit_str(value.as_ref())
}

fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E>
where
E: Error,
{
Ok(BlockCount::Num(value))
}
}

#[cfg(test)]
mod tests {
use super::*;

fn match_block_number(block_count: BlockCount) -> Option<U256> {
match block_count {
BlockCount::Num(n) => Some(U256::from(n)),
BlockCount::U256(n) => Some(n),
}
}

#[test]
fn block_number_deserialize() {
let bn_dec: BlockCount = serde_json::from_str(r#""42""#).unwrap();
let bn_hex: BlockCount = serde_json::from_str(r#""0x45""#).unwrap();
assert_eq!(match_block_number(bn_dec).unwrap(), U256::from(42));
assert_eq!(match_block_number(bn_hex).unwrap(), U256::from("0x45"));
}
}
2 changes: 2 additions & 0 deletions client/rpc-core/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

mod account_info;
mod block;
mod block_count;
mod block_number;
mod bytes;
mod call_request;
Expand All @@ -45,6 +46,7 @@ pub use self::txpool::{Summary, TransactionMap, TxPoolResult};
pub use self::{
account_info::{AccountInfo, EthAccount, ExtAccountInfo, RecoveredAccount, StorageProof},
block::{Block, BlockTransactions, Header, Rich, RichBlock, RichHeader},
block_count::BlockCount,
block_number::BlockNumberOrHash,
bytes::Bytes,
call_request::CallStateOverride,
Expand Down
5 changes: 3 additions & 2 deletions client/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jsonrpsee = { workspace = true, features = ["server", "macros"] }
libsecp256k1 = { workspace = true }
log = { workspace = true }
prometheus = { version = "0.13.4", default-features = false }
rand = "0.8"
rand = "0.9"
rlp = { workspace = true }
scale-codec = { workspace = true }
schnellru = "0.2.4"
Expand All @@ -35,7 +35,6 @@ sc-network = { workspace = true }
sc-network-sync = { workspace = true }
sc-rpc = { workspace = true }
sc-service = { workspace = true }
sc-transaction-pool = { workspace = true }
sc-transaction-pool-api = { workspace = true }
sc-utils = { workspace = true }
sp-api = { workspace = true, features = ["default"] }
Expand All @@ -49,6 +48,8 @@ sp-io = { workspace = true, features = ["default"] }
sp-runtime = { workspace = true, features = ["default"] }
sp-state-machine = { workspace = true, features = ["default"] }
sp-storage = { workspace = true, features = ["default"] }
sp-timestamp = { workspace = true, features = ["default"], optional = true }
sp-trie = { workspace = true, features = ["default"] }
# Frontier
fc-api = { workspace = true }
fc-mapping-sync = { workspace = true }
Expand Down
15 changes: 5 additions & 10 deletions client/rpc/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ use ethereum_types::{H256, U256};
use jsonrpsee::core::RpcResult;
// Substrate
use sc_client_api::backend::{Backend, StorageProvider};
use sc_transaction_pool::ChainApi;
use sc_transaction_pool_api::InPoolTransaction;
use sc_transaction_pool_api::{InPoolTransaction, TransactionPool};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_core::hashing::keccak_256;
Expand All @@ -37,14 +36,14 @@ use crate::{
frontier_backend_client, internal_err,
};

impl<B, C, P, CT, BE, A, CIDP, EC> Eth<B, C, P, CT, BE, A, CIDP, EC>
impl<B, C, P, CT, BE, CIDP, EC> Eth<B, C, P, CT, BE, CIDP, EC>
where
B: BlockT,
C: ProvideRuntimeApi<B>,
C::Api: EthereumRuntimeRPCApi<B>,
C: HeaderBackend<B> + StorageProvider<B, BE> + 'static,
BE: Backend<B> + 'static,
A: ChainApi<Block = B>,
P: TransactionPool<Block = B, Hash = B::Hash> + 'static,
{
pub async fn block_by_hash(&self, hash: H256, full: bool) -> RpcResult<Option<RichBlock>> {
let BlockInfo {
Expand Down Expand Up @@ -145,7 +144,6 @@ where
// ready validated pool
xts.extend(
graph
.validated_pool()
.ready()
.map(|in_pool_tx| in_pool_tx.data().as_ref().clone())
.collect::<Vec<<B as BlockT>::Extrinsic>>(),
Expand All @@ -154,10 +152,9 @@ where
// future validated pool
xts.extend(
graph
.validated_pool()
.futures()
.iter()
.map(|(_hash, extrinsic)| extrinsic.as_ref().clone())
.map(|in_pool_tx| in_pool_tx.data().as_ref().clone())
.collect::<Vec<<B as BlockT>::Extrinsic>>(),
);

Expand Down Expand Up @@ -197,9 +194,7 @@ where
) -> RpcResult<Option<U256>> {
if let BlockNumberOrHash::Pending = number_or_hash {
// get the pending transactions count
return Ok(Some(U256::from(
self.graph.validated_pool().ready().count(),
)));
return Ok(Some(U256::from(self.graph.ready().count())));
}

let block_info = self.block_info_by_number(number_or_hash).await?;
Expand Down
4 changes: 1 addition & 3 deletions client/rpc/src/eth/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use ethereum_types::{H160, U256, U64};
use jsonrpsee::core::RpcResult;
// Substrate
use sc_client_api::backend::{Backend, StorageProvider};
use sc_transaction_pool::ChainApi;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_consensus::SyncOracle;
Expand All @@ -31,14 +30,13 @@ use fp_rpc::EthereumRuntimeRPCApi;

use crate::{eth::Eth, internal_err};

impl<B, C, P, CT, BE, A, CIDP, EC> Eth<B, C, P, CT, BE, A, CIDP, EC>
impl<B, C, P, CT, BE, CIDP, EC> Eth<B, C, P, CT, BE, CIDP, EC>
where
B: BlockT,
C: ProvideRuntimeApi<B>,
C::Api: EthereumRuntimeRPCApi<B>,
C: HeaderBackend<B> + StorageProvider<B, BE> + 'static,
BE: Backend<B>,
A: ChainApi<Block = B>,
{
pub fn protocol_version(&self) -> RpcResult<u64> {
Ok(1)
Expand Down
Loading
Loading