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: replace U64 with u64 #1057

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions crates/rpc-types-engine/src/transition.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_primitives::{B256, U256, U64};
use alloy_primitives::{B256, U256};
use serde::{Deserialize, Serialize};

/// This structure contains configurable settings of the transition process.
Expand All @@ -11,5 +11,6 @@ pub struct TransitionConfiguration {
/// Maps on TERMINAL_BLOCK_HASH parameter of EIP-3675
pub terminal_block_hash: B256,
/// Maps on TERMINAL_BLOCK_NUMBER parameter of EIP-3675
pub terminal_block_number: U64,
#[serde(with = "alloy_serde::quantity")]
pub terminal_block_number: u64,
}
6 changes: 3 additions & 3 deletions crates/rpc-types-eth/src/account.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use alloy_primitives::{Address, Bytes, B256, B512, U256, U64};
use alloy_primitives::{Address, Bytes, B256, B512, U256};
use alloy_serde::storage::JsonStorageKey;
use serde::{Deserialize, Serialize};

/// Account information.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct AccountInfo {
Expand Down Expand Up @@ -32,7 +31,8 @@ pub struct EIP1186AccountProofResponse {
/// The hash of the code of the account.
pub code_hash: B256,
/// The account nonce.
pub nonce: U64,
#[serde(with = "alloy_serde::quantity")]
pub nonce: u64,
/// The hash of the storage of the account.
pub storage_hash: B256,
/// The account proof.
Expand Down
15 changes: 10 additions & 5 deletions crates/rpc-types-eth/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Block RPC types.

use crate::{ConversionError, Transaction, Withdrawal};
use alloy_primitives::{Address, BlockHash, Bloom, Bytes, B256, B64, U256, U64};
use alloy_primitives::{Address, BlockHash, Bloom, Bytes, B256, B64, U256};
use alloy_serde::OtherFields;
use serde::{ser::Error, Deserialize, Serialize, Serializer};
use std::{collections::BTreeMap, ops::Deref};
Expand Down Expand Up @@ -608,11 +608,16 @@ pub struct BlockOverrides {
pub difficulty: Option<U256>,
/// Overrides the timestamp of the block.
// Note: geth uses `time`, erigon uses `timestamp`
#[serde(default, skip_serializing_if = "Option::is_none", alias = "timestamp")]
pub time: Option<U64>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
alias = "timestamp",
with = "alloy_serde::quantity::opt"
)]
pub time: Option<u64>,
/// Overrides the gas limit of the block.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub gas_limit: Option<U64>,
#[serde(default, skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt")]
pub gas_limit: Option<u64>,
/// Overrides the coinbase address of the block.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub coinbase: Option<Address>,
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc-types-eth/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ mod tests {
let s = r#"{"transactions":[{"data":"0x70a08231000000000000000000000000000000dbc80bf780c6dc0ca16ed071b1f00cc000","to":"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"}],"blockOverride":{"timestamp":1711546233}}"#;
let bundle = serde_json::from_str::<Bundle>(s).unwrap();
assert_eq!(bundle.transactions.len(), 1);
assert_eq!(bundle.block_override.unwrap().time.unwrap().to::<u64>(), 1711546233);
assert_eq!(bundle.block_override.unwrap().time.unwrap(), 1711546233);
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions crates/rpc-types-eth/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! bindings for state overrides in eth_call

use crate::BlockOverrides;
use alloy_primitives::{Address, Bytes, B256, U256, U64};
use alloy_primitives::{Address, Bytes, B256, U256};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

Expand All @@ -16,8 +16,8 @@ pub struct AccountOverride {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub balance: Option<U256>,
/// Fake nonce to set for the account before executing the call.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub nonce: Option<U64>,
#[serde(default, skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt")]
pub nonce: Option<u64>,
/// Fake EVM bytecode to inject into the account before executing the call.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub code: Option<Bytes>,
Expand Down Expand Up @@ -113,7 +113,7 @@ mod tests {
let acc =
state_override.get(&address!("1234567890123456789012345678901234567890")).unwrap();
assert_eq!(acc.balance, Some(U256::MAX));
assert_eq!(acc.nonce, Some(U64::MAX));
assert_eq!(acc.nonce, Some(u64::MAX));
}

#[test]
Expand Down
10 changes: 5 additions & 5 deletions crates/rpc-types-eth/src/transaction/optimism.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Misc Optimism-specific types.

use alloy_primitives::{B256, U128, U64};
use alloy_primitives::{B256, U128};
use alloy_serde::OtherFields;
use serde::{Deserialize, Serialize};

Expand All @@ -27,11 +27,11 @@ pub struct OptimismTransactionFields {
#[doc(alias = "OptimismTxReceiptFields")]
pub struct OptimismTransactionReceiptFields {
/// Deposit nonce for deposit transactions post-regolith
#[serde(skip_serializing_if = "Option::is_none")]
pub deposit_nonce: Option<U64>,
#[serde(default, skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt")]
pub deposit_nonce: Option<u64>,
/// Deposit receipt version for deposit transactions post-canyon
#[serde(skip_serializing_if = "Option::is_none")]
pub deposit_receipt_version: Option<U64>,
#[serde(default, skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt")]
pub deposit_receipt_version: Option<u64>,
/// L1 fee for the transaction
#[serde(default, skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt")]
pub l1_fee: Option<u128>,
Expand Down
31 changes: 18 additions & 13 deletions crates/rpc-types-trace/src/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ pub struct AccountDiff {
/// How the code changed, if at all
pub code: Delta<Bytes>,
/// How the nonce changed, if at all
// TODO: Change type to `u64` and write custom serde for `Delta`
pub nonce: Delta<U64>,
/// All touched/changed storage values
pub storage: BTreeMap<B256, Delta<B256>>,
Expand Down Expand Up @@ -288,7 +289,8 @@ pub struct CallAction {
/// The type of the call.
pub call_type: CallType,
/// The gas available for executing the call.
pub gas: U64,
#[serde(with = "alloy_serde::quantity")]
pub gas: u64,
/// The input data provided to the call.
pub input: Bytes,
/// Address of the destination/target account.
Expand All @@ -304,7 +306,8 @@ pub struct CreateAction {
/// The address of the creator.
pub from: Address,
/// The gas available for the creation init code.
pub gas: U64,
#[serde(with = "alloy_serde::quantity")]
pub gas: u64,
/// The init code.
pub init: Bytes,
/// The value with which the new account is endowed.
Expand Down Expand Up @@ -350,7 +353,8 @@ pub struct SelfdestructAction {
#[serde(rename_all = "camelCase")]
pub struct CallOutput {
/// Gas used by the call.
pub gas_used: U64,
#[serde(with = "alloy_serde::quantity")]
pub gas_used: u64,
/// The output data of the call.
pub output: Bytes,
}
Expand All @@ -364,7 +368,8 @@ pub struct CreateOutput {
/// Contract code.
pub code: Bytes,
/// Gas used by the call.
pub gas_used: U64,
#[serde(with = "alloy_serde::quantity")]
pub gas_used: u64,
}

/// Represents the output of a trace.
Expand Down Expand Up @@ -395,18 +400,18 @@ impl TraceOutput {
}

/// Returns the gas used by this trace.
pub fn gas_used(&self) -> u64 {
pub const fn gas_used(&self) -> u64 {
match self {
Self::Call(call) => call.gas_used.to(),
Self::Create(create) => create.gas_used.to(),
Self::Call(call) => call.gas_used,
Self::Create(create) => create.gas_used,
}
}

/// Sets the gas used by this trace.
pub fn set_gas_used(&mut self, gas_used: u64) {
match self {
Self::Call(call) => call.gas_used = U64::from(gas_used),
Self::Create(create) => create.gas_used = U64::from(gas_used),
Self::Call(call) => call.gas_used = gas_used,
Self::Create(create) => create.gas_used = gas_used,
}
}
}
Expand Down Expand Up @@ -660,13 +665,13 @@ mod tests {
action: Action::Call(CallAction {
from: "0x4f4495243837681061c4743b74b3eedf548d56a5".parse::<Address>().unwrap(),
call_type: CallType::DelegateCall,
gas: U64::from(3148955),
gas: 3148955,
input: Bytes::from_str("0x585a9fd40000000000000000000000000000000000000000000000000000000000000040a47c5ad9a4af285720eae6cc174a9c75c5bbaf973b00f1a0c191327445b6581000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000ce16f69375520ab01377ce7b88f5ba8c48f8d666f61490331372e432315cd97447e3bc452d6c73a6e0536260a88ddab46f85c88d00000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000aab8cf0fbfb038751339cb61161fa11789b41a78f1b7b0e12cf8e467d403590b7a5f26f0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000646616e746f6d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a3078636531364636393337353532306162303133373763653742383866354241384334384638443636360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000045553444300000000000000000000000000000000000000000000000000000000").unwrap(),
to: "0x99b5fa03a5ea4315725c43346e55a6a6fbd94098".parse::<Address>().unwrap(),
value: U256::from(0),
}),
error: None,
result: Some(TraceOutput::Call(CallOutput { gas_used: U64::from(32364), output: Bytes::new() })),
result: Some(TraceOutput::Call(CallOutput { gas_used: 32364, output: Bytes::new() })),
subtraces: 0,
trace_address: vec![0, 10, 0],
},
Expand Down Expand Up @@ -706,12 +711,12 @@ mod tests {
trace: TransactionTrace {
action: Action::Create(CreateAction{
from: "0x4f4495243837681061c4743b74b3eedf548d56a5".parse::<Address>().unwrap(),
gas: U64::from(3438907),
gas: 3438907,
init: Bytes::from_str("0x6080604052600160005534801561001557600080fd5b50610324806100256000396000f3fe608060405234801561001057600080fd5b50600436106100355760003560e01c8062f55d9d1461003a5780631cff79cd1461004f575b600080fd5b61004d6100483660046101da565b610079565b005b61006261005d3660046101fc565b6100bb565b60405161007092919061027f565b60405180910390f35b6002600054141561009d5760405163caa30f5560e01b815260040160405180910390fd5b600260005573ffffffffffffffffffffffffffffffffffffffff8116ff5b60006060600260005414156100e35760405163caa30f5560e01b815260040160405180910390fd5b600260005573ffffffffffffffffffffffffffffffffffffffff85163b610136576040517f6f7c43f100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8473ffffffffffffffffffffffffffffffffffffffff16848460405161015d9291906102de565b6000604051808303816000865af19150503d806000811461019a576040519150601f19603f3d011682016040523d82523d6000602084013e61019f565b606091505b50600160005590969095509350505050565b803573ffffffffffffffffffffffffffffffffffffffff811681146101d557600080fd5b919050565b6000602082840312156101ec57600080fd5b6101f5826101b1565b9392505050565b60008060006040848603121561021157600080fd5b61021a846101b1565b9250602084013567ffffffffffffffff8082111561023757600080fd5b818601915086601f83011261024b57600080fd5b81358181111561025a57600080fd5b87602082850101111561026c57600080fd5b6020830194508093505050509250925092565b821515815260006020604081840152835180604085015260005b818110156102b557858101830151858201606001528201610299565b818111156102c7576000606083870101525b50601f01601f191692909201606001949350505050565b818382376000910190815291905056fea264697066735822122032cb5e746816b7fac95205c068b30da37bd40119a57265be331c162cae74712464736f6c63430008090033").unwrap(),
value: U256::from(0),
}),
error: None,
result: Some(TraceOutput::Create(CreateOutput { gas_used: U64::from(183114), address: "0x7eb6c6c1db08c0b9459a68cfdcedab64f319c138".parse::<Address>().unwrap(), code: Bytes::from_str("0x608060405234801561001057600080fd5b50600436106100355760003560e01c8062f55d9d1461003a5780631cff79cd1461004f575b600080fd5b61004d6100483660046101da565b610079565b005b61006261005d3660046101fc565b6100bb565b60405161007092919061027f565b60405180910390f35b6002600054141561009d5760405163caa30f5560e01b815260040160405180910390fd5b600260005573ffffffffffffffffffffffffffffffffffffffff8116ff5b60006060600260005414156100e35760405163caa30f5560e01b815260040160405180910390fd5b600260005573ffffffffffffffffffffffffffffffffffffffff85163b610136576040517f6f7c43f100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8473ffffffffffffffffffffffffffffffffffffffff16848460405161015d9291906102de565b6000604051808303816000865af19150503d806000811461019a576040519150601f19603f3d011682016040523d82523d6000602084013e61019f565b606091505b50600160005590969095509350505050565b803573ffffffffffffffffffffffffffffffffffffffff811681146101d557600080fd5b919050565b6000602082840312156101ec57600080fd5b6101f5826101b1565b9392505050565b60008060006040848603121561021157600080fd5b61021a846101b1565b9250602084013567ffffffffffffffff8082111561023757600080fd5b818601915086601f83011261024b57600080fd5b81358181111561025a57600080fd5b87602082850101111561026c57600080fd5b6020830194508093505050509250925092565b821515815260006020604081840152835180604085015260005b818110156102b557858101830151858201606001528201610299565b818111156102c7576000606083870101525b50601f01601f191692909201606001949350505050565b818382376000910190815291905056fea264697066735822122032cb5e746816b7fac95205c068b30da37bd40119a57265be331c162cae74712464736f6c63430008090033").unwrap() })),
result: Some(TraceOutput::Create(CreateOutput { gas_used: 183114, address: "0x7eb6c6c1db08c0b9459a68cfdcedab64f319c138".parse::<Address>().unwrap(), code: Bytes::from_str("0x608060405234801561001057600080fd5b50600436106100355760003560e01c8062f55d9d1461003a5780631cff79cd1461004f575b600080fd5b61004d6100483660046101da565b610079565b005b61006261005d3660046101fc565b6100bb565b60405161007092919061027f565b60405180910390f35b6002600054141561009d5760405163caa30f5560e01b815260040160405180910390fd5b600260005573ffffffffffffffffffffffffffffffffffffffff8116ff5b60006060600260005414156100e35760405163caa30f5560e01b815260040160405180910390fd5b600260005573ffffffffffffffffffffffffffffffffffffffff85163b610136576040517f6f7c43f100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8473ffffffffffffffffffffffffffffffffffffffff16848460405161015d9291906102de565b6000604051808303816000865af19150503d806000811461019a576040519150601f19603f3d011682016040523d82523d6000602084013e61019f565b606091505b50600160005590969095509350505050565b803573ffffffffffffffffffffffffffffffffffffffff811681146101d557600080fd5b919050565b6000602082840312156101ec57600080fd5b6101f5826101b1565b9392505050565b60008060006040848603121561021157600080fd5b61021a846101b1565b9250602084013567ffffffffffffffff8082111561023757600080fd5b818601915086601f83011261024b57600080fd5b81358181111561025a57600080fd5b87602082850101111561026c57600080fd5b6020830194508093505050509250925092565b821515815260006020604081840152835180604085015260005b818110156102b557858101830151858201606001528201610299565b818111156102c7576000606083870101525b50601f01601f191692909201606001949350505050565b818382376000910190815291905056fea264697066735822122032cb5e746816b7fac95205c068b30da37bd40119a57265be331c162cae74712464736f6c63430008090033").unwrap() })),
subtraces: 0,
trace_address: vec![0, 7, 0, 0],
},
Expand Down
Loading