Skip to content
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

refactor: consolidate JSON requests and responses #279

Merged
merged 55 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
282621b
243: copied client
gregorydemay Sep 13, 2024
a0ab713
243: copied eth_rpc_client
gregorydemay Sep 13, 2024
ab382a0
243: copied providers
gregorydemay Sep 13, 2024
cca8be7
243: copied eth_rpc
gregorydemay Sep 13, 2024
b3ab56f
243: copied requests
gregorydemay Sep 13, 2024
3476f9b
243: copied responses
gregorydemay Sep 13, 2024
7095174
243: copied tests
gregorydemay Sep 13, 2024
e819020
243: fixing rpc_client
gregorydemay Sep 13, 2024
82798b7
243: copy numeric
gregorydemay Sep 13, 2024
5226948
243: copy checked_amount
gregorydemay Sep 13, 2024
4511a34
243: fix checked_amount
gregorydemay Sep 13, 2024
671b94f
243: fix numeric
gregorydemay Sep 13, 2024
e1753fb
243: copy eth_rpc tests
gregorydemay Sep 13, 2024
7f69fe6
243: fix requests
gregorydemay Sep 13, 2024
317915c
243: fix response
gregorydemay Sep 13, 2024
821599b
243: remove reduce_with_min_by_key
gregorydemay Sep 13, 2024
8a2fac8
243: copy eth_rpc_error
gregorydemay Sep 13, 2024
5b97b19
243: fix eth_rpc_error
gregorydemay Sep 13, 2024
cb3484c
243: fix eth_rpc
gregorydemay Sep 13, 2024
8bcbf18
243: clean-up
gregorydemay Sep 13, 2024
6c93dc5
243: fix client instantiation and eth_get_logs
gregorydemay Sep 13, 2024
e081cac
243: fix eth_get_block_by_number
gregorydemay Sep 13, 2024
6b4e493
243: fix eth_get_transaction_receipt
gregorydemay Sep 13, 2024
344d59b
243: fix eth_get_transaction_count
gregorydemay Sep 13, 2024
daf4e9f
243: fix eth_fee_history
gregorydemay Sep 13, 2024
7f44a2b
243: fix eth_send_raw_transaction
gregorydemay Sep 13, 2024
e036b22
243: it compiles!
gregorydemay Sep 13, 2024
c552b93
243: remove has_http_outcall_error_matching
gregorydemay Sep 13, 2024
ee10dd2
243: tests compile!
gregorydemay Sep 13, 2024
4e5ef50
243: clean-up
gregorydemay Sep 13, 2024
4300498
243: fix unit tests
gregorydemay Sep 16, 2024
dfebc55
243: remove cketh_common
gregorydemay Sep 16, 2024
d0c8094
243: Clippy
gregorydemay Sep 16, 2024
79946f5
243: format
gregorydemay Sep 16, 2024
714a12a
243: format
gregorydemay Sep 16, 2024
9e733ad
Merge branch 'main' of https://github.com/internet-computer-protocol/…
rvanasa Sep 16, 2024
bee5cd7
243: simplify instantiation
gregorydemay Sep 17, 2024
68ee463
243: remove providers.rs
gregorydemay Sep 17, 2024
ff50c3a
243: unit tests
gregorydemay Sep 17, 2024
c861949
243: remove CanisterTransport
gregorydemay Sep 17, 2024
63c608c
243: move GetLogsParam
gregorydemay Sep 17, 2024
b738c49
243: move LogEntry
gregorydemay Sep 17, 2024
bea91ec
243: move Block
gregorydemay Sep 17, 2024
da4eb9d
243: move FeeHistoryParams and FeeHistory
gregorydemay Sep 17, 2024
aaf05a5
243: move SendRawTransactionResult
gregorydemay Sep 17, 2024
8970e38
243: move BlockSpec and BlockTag
gregorydemay Sep 17, 2024
dfff4b2
243: move GetBlockByNumberParams
gregorydemay Sep 17, 2024
072789b
243: move requests under json module
gregorydemay Sep 17, 2024
1afd9b9
243: move responses under json module
gregorydemay Sep 17, 2024
20bf9f3
243: format
gregorydemay Sep 17, 2024
fffcdfe
Merge branch 'main' into gdemay/243-cketh-client-reorg
gregorydemay Sep 18, 2024
eb3a2f5
formatting
gregorydemay Sep 18, 2024
06a0614
243: remove FromStr for BlockSpec
gregorydemay Sep 18, 2024
1c93961
243: add Rust docs
gregorydemay Sep 18, 2024
c7634e2
243: change to 2 MiB
gregorydemay Sep 18, 2024
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
53 changes: 27 additions & 26 deletions src/candid_rpc/cketh_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@

use crate::rpc_client::checked_amount::CheckedAmountOf;
use crate::rpc_client::eth_rpc::{Hash, Quantity};
use crate::rpc_client::json::requests::BlockSpec;
use evm_rpc_types::{BlockTag, Hex, Hex20, Hex256, Hex32, HexByte, Nat256};
/**/
pub(super) fn into_block_spec(value: BlockTag) -> crate::rpc_client::eth_rpc::BlockSpec {
use crate::rpc_client::eth_rpc::{self, BlockSpec};

pub(super) fn into_block_spec(value: BlockTag) -> BlockSpec {
use crate::rpc_client::json::requests;
match value {
BlockTag::Number(n) => BlockSpec::Number(into_checked_amount_of(n)),
BlockTag::Latest => BlockSpec::Tag(eth_rpc::BlockTag::Latest),
BlockTag::Safe => BlockSpec::Tag(eth_rpc::BlockTag::Safe),
BlockTag::Finalized => BlockSpec::Tag(eth_rpc::BlockTag::Finalized),
BlockTag::Earliest => BlockSpec::Tag(eth_rpc::BlockTag::Earliest),
BlockTag::Pending => BlockSpec::Tag(eth_rpc::BlockTag::Pending),
BlockTag::Latest => BlockSpec::Tag(requests::BlockTag::Latest),
BlockTag::Safe => BlockSpec::Tag(requests::BlockTag::Safe),
BlockTag::Finalized => BlockSpec::Tag(requests::BlockTag::Finalized),
BlockTag::Earliest => BlockSpec::Tag(requests::BlockTag::Earliest),
BlockTag::Pending => BlockSpec::Tag(requests::BlockTag::Pending),
}
}

pub(super) fn into_get_logs_param(
value: evm_rpc_types::GetLogsArgs,
) -> crate::rpc_client::eth_rpc::GetLogsParam {
crate::rpc_client::eth_rpc::GetLogsParam {
) -> crate::rpc_client::json::requests::GetLogsParam {
crate::rpc_client::json::requests::GetLogsParam {
from_block: value.from_block.map(into_block_spec).unwrap_or_default(),
to_block: value.to_block.map(into_block_spec).unwrap_or_default(),
address: value
Expand All @@ -44,12 +45,12 @@ pub(super) fn into_get_logs_param(
}

pub(super) fn from_log_entries(
value: Vec<crate::rpc_client::eth_rpc::LogEntry>,
value: Vec<crate::rpc_client::json::responses::LogEntry>,
) -> Vec<evm_rpc_types::LogEntry> {
value.into_iter().map(from_log_entry).collect()
}

fn from_log_entry(value: crate::rpc_client::eth_rpc::LogEntry) -> evm_rpc_types::LogEntry {
fn from_log_entry(value: crate::rpc_client::json::responses::LogEntry) -> evm_rpc_types::LogEntry {
evm_rpc_types::LogEntry {
address: from_address(value.address),
topics: value.topics.into_iter().map(|t| t.0.into()).collect(),
Expand All @@ -65,16 +66,16 @@ fn from_log_entry(value: crate::rpc_client::eth_rpc::LogEntry) -> evm_rpc_types:

pub(super) fn into_fee_history_params(
value: evm_rpc_types::FeeHistoryArgs,
) -> crate::rpc_client::eth_rpc::FeeHistoryParams {
crate::rpc_client::eth_rpc::FeeHistoryParams {
) -> crate::rpc_client::json::requests::FeeHistoryParams {
crate::rpc_client::json::requests::FeeHistoryParams {
block_count: into_quantity(value.block_count),
highest_block: into_block_spec(value.newest_block),
reward_percentiles: value.reward_percentiles.unwrap_or_default(),
}
}

pub(super) fn from_fee_history(
value: crate::rpc_client::eth_rpc::FeeHistory,
value: crate::rpc_client::json::responses::FeeHistory,
) -> evm_rpc_types::FeeHistory {
evm_rpc_types::FeeHistory {
oldest_block: from_checked_amount_of(value.oldest_block),
Expand All @@ -94,24 +95,24 @@ pub(super) fn from_fee_history(

pub(super) fn into_get_transaction_count_params(
value: evm_rpc_types::GetTransactionCountArgs,
) -> crate::rpc_client::requests::GetTransactionCountParams {
crate::rpc_client::requests::GetTransactionCountParams {
) -> crate::rpc_client::json::requests::GetTransactionCountParams {
crate::rpc_client::json::requests::GetTransactionCountParams {
address: ic_ethereum_types::Address::new(value.address.into()),
block: into_block_spec(value.block),
}
}

pub(super) fn from_transaction_receipt(
value: crate::rpc_client::responses::TransactionReceipt,
value: crate::rpc_client::json::responses::TransactionReceipt,
) -> evm_rpc_types::TransactionReceipt {
evm_rpc_types::TransactionReceipt {
block_hash: Hex32::from(value.block_hash.0),
block_number: from_checked_amount_of(value.block_number),
effective_gas_price: from_checked_amount_of(value.effective_gas_price),
gas_used: from_checked_amount_of(value.gas_used),
status: match value.status {
crate::rpc_client::responses::TransactionStatus::Success => Nat256::from(1_u8),
crate::rpc_client::responses::TransactionStatus::Failure => Nat256::from(0_u8),
crate::rpc_client::json::responses::TransactionStatus::Success => Nat256::from(1_u8),
crate::rpc_client::json::responses::TransactionStatus::Failure => Nat256::from(0_u8),
},
transaction_hash: Hex32::from(value.transaction_hash.0),
// TODO 243: responses types from querying JSON-RPC providers should be strongly typed
Expand All @@ -128,7 +129,7 @@ pub(super) fn from_transaction_receipt(
}
}

pub(super) fn from_block(value: crate::rpc_client::eth_rpc::Block) -> evm_rpc_types::Block {
pub(super) fn from_block(value: crate::rpc_client::json::responses::Block) -> evm_rpc_types::Block {
evm_rpc_types::Block {
base_fee_per_gas: value.base_fee_per_gas.map(from_checked_amount_of),
number: from_checked_amount_of(value.number),
Expand Down Expand Up @@ -164,19 +165,19 @@ pub(super) fn from_block(value: crate::rpc_client::eth_rpc::Block) -> evm_rpc_ty

pub(super) fn from_send_raw_transaction_result(
transaction_hash: Option<Hex32>,
value: crate::rpc_client::eth_rpc::SendRawTransactionResult,
value: crate::rpc_client::json::responses::SendRawTransactionResult,
) -> evm_rpc_types::SendRawTransactionStatus {
match value {
crate::rpc_client::eth_rpc::SendRawTransactionResult::Ok => {
crate::rpc_client::json::responses::SendRawTransactionResult::Ok => {
evm_rpc_types::SendRawTransactionStatus::Ok(transaction_hash)
}
crate::rpc_client::eth_rpc::SendRawTransactionResult::InsufficientFunds => {
crate::rpc_client::json::responses::SendRawTransactionResult::InsufficientFunds => {
evm_rpc_types::SendRawTransactionStatus::InsufficientFunds
}
crate::rpc_client::eth_rpc::SendRawTransactionResult::NonceTooLow => {
crate::rpc_client::json::responses::SendRawTransactionResult::NonceTooLow => {
evm_rpc_types::SendRawTransactionStatus::NonceTooLow
}
crate::rpc_client::eth_rpc::SendRawTransactionResult::NonceTooHigh => {
crate::rpc_client::json::responses::SendRawTransactionResult::NonceTooHigh => {
evm_rpc_types::SendRawTransactionStatus::NonceTooHigh
}
}
Expand Down
Loading