Skip to content

Commit

Permalink
Merge pull request #1 from Troublor/forge_clone
Browse files Browse the repository at this point in the history
Forge clone
  • Loading branch information
ZhangZhuoSJTU authored Mar 27, 2024
2 parents 9148dbc + 6f61ba7 commit 8432289
Show file tree
Hide file tree
Showing 156 changed files with 1,384 additions and 963 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/anvil/core/src/eth/serde_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub mod sequence {
return Err(serde::de::Error::custom(format!(
"expected params sequence with length 1 but got {}",
seq.len()
)))
)));
}
Ok(seq.remove(0))
}
Expand Down Expand Up @@ -75,7 +75,7 @@ pub mod empty_params {
return Err(serde::de::Error::custom(format!(
"expected params sequence with length 0 but got {}",
seq.len()
)))
)));
}
Ok(())
}
Expand Down
62 changes: 31 additions & 31 deletions crates/anvil/core/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn transaction_request_to_typed(tx: TransactionRequest) -> Option<TypedTrans
gas_limit: gas.unwrap_or_default(),
is_system_tx: other.get_deserialized::<bool>("isSystemTx")?.ok()?,
input: input.into_input().unwrap_or_default(),
}))
}));
}

match (
Expand All @@ -81,8 +81,8 @@ pub fn transaction_request_to_typed(tx: TransactionRequest) -> Option<TypedTrans
sidecar,
) {
// legacy transaction
(Some(0), _, None, None, None, None, None, None) |
(None, Some(_), None, None, None, None, None, None) => {
(Some(0), _, None, None, None, None, None, None)
| (None, Some(_), None, None, None, None, None, None) => {
Some(TypedTransactionRequest::Legacy(TxLegacy {
nonce: nonce.unwrap_or_default().to::<u64>(),
gas_price: gas_price.unwrap_or_default().to::<u128>(),
Expand All @@ -97,8 +97,8 @@ pub fn transaction_request_to_typed(tx: TransactionRequest) -> Option<TypedTrans
}))
}
// EIP2930
(Some(1), _, None, None, _, None, None, None) |
(None, _, None, None, Some(_), None, None, None) => {
(Some(1), _, None, None, _, None, None, None)
| (None, _, None, None, Some(_), None, None, None) => {
Some(TypedTransactionRequest::EIP2930(TxEip2930 {
nonce: nonce.unwrap_or_default().to::<u64>(),
gas_price: gas_price.unwrap_or_default().to(),
Expand All @@ -114,10 +114,10 @@ pub fn transaction_request_to_typed(tx: TransactionRequest) -> Option<TypedTrans
}))
}
// EIP1559
(Some(2), None, _, _, _, _, None, None) |
(None, None, Some(_), _, _, _, None, None) |
(None, None, _, Some(_), _, _, None, None) |
(None, None, None, None, None, _, None, None) => {
(Some(2), None, _, _, _, _, None, None)
| (None, None, Some(_), _, _, _, None, None)
| (None, None, _, Some(_), _, _, None, None)
| (None, None, None, None, None, _, None, None) => {
// Empty fields fall back to the canonical transaction schema.
Some(TypedTransactionRequest::EIP1559(TxEip1559 {
nonce: nonce.unwrap_or_default().to::<u64>(),
Expand Down Expand Up @@ -214,7 +214,7 @@ impl MaybeImpersonatedTransaction {
#[cfg(feature = "impersonated-tx")]
pub fn recover(&self) -> Result<Address, alloy_primitives::SignatureError> {
if let Some(sender) = self.impersonated_sender {
return Ok(sender)
return Ok(sender);
}
self.transaction.recover()
}
Expand All @@ -227,7 +227,7 @@ impl MaybeImpersonatedTransaction {
pub fn hash(&self) -> B256 {
if self.transaction.is_impersonated() {
if let Some(sender) = self.impersonated_sender {
return self.transaction.impersonated_hash(sender)
return self.transaction.impersonated_hash(sender);
}
}
self.transaction.hash()
Expand Down Expand Up @@ -994,43 +994,43 @@ pub enum TypedReceipt {
impl TypedReceipt {
pub fn gas_used(&self) -> U256 {
match self {
TypedReceipt::Legacy(r) |
TypedReceipt::EIP1559(r) |
TypedReceipt::EIP2930(r) |
TypedReceipt::EIP4844(r) |
TypedReceipt::Deposit(r) => U256::from(r.receipt.cumulative_gas_used),
TypedReceipt::Legacy(r)
| TypedReceipt::EIP1559(r)
| TypedReceipt::EIP2930(r)
| TypedReceipt::EIP4844(r)
| TypedReceipt::Deposit(r) => U256::from(r.receipt.cumulative_gas_used),
}
}

pub fn logs_bloom(&self) -> &Bloom {
match self {
TypedReceipt::Legacy(r) |
TypedReceipt::EIP1559(r) |
TypedReceipt::EIP2930(r) |
TypedReceipt::EIP4844(r) |
TypedReceipt::Deposit(r) => &r.bloom,
TypedReceipt::Legacy(r)
| TypedReceipt::EIP1559(r)
| TypedReceipt::EIP2930(r)
| TypedReceipt::EIP4844(r)
| TypedReceipt::Deposit(r) => &r.bloom,
}
}

pub fn logs(&self) -> &Vec<Log> {
match self {
TypedReceipt::Legacy(r) |
TypedReceipt::EIP1559(r) |
TypedReceipt::EIP2930(r) |
TypedReceipt::EIP4844(r) |
TypedReceipt::Deposit(r) => &r.receipt.logs,
TypedReceipt::Legacy(r)
| TypedReceipt::EIP1559(r)
| TypedReceipt::EIP2930(r)
| TypedReceipt::EIP4844(r)
| TypedReceipt::Deposit(r) => &r.receipt.logs,
}
}
}

impl From<TypedReceipt> for ReceiptWithBloom {
fn from(val: TypedReceipt) -> Self {
match val {
TypedReceipt::Legacy(r) |
TypedReceipt::EIP1559(r) |
TypedReceipt::EIP2930(r) |
TypedReceipt::EIP4844(r) |
TypedReceipt::Deposit(r) => r,
TypedReceipt::Legacy(r)
| TypedReceipt::EIP1559(r)
| TypedReceipt::EIP2930(r)
| TypedReceipt::EIP4844(r)
| TypedReceipt::Deposit(r) => r,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/server/src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<Handler: PubSubRpcHandler> IpcEndpoint<Handler> {
Ok(connections) => connections,
Err(err) => {
error!(%err, "Failed to create IPC listener");
return Err(err)
return Err(err);
}
};

Expand Down Expand Up @@ -156,7 +156,7 @@ impl tokio_util::codec::Decoder for JsonRpcCodec {
return match String::from_utf8(bts.as_ref().to_vec()) {
Ok(val) => Ok(Some(val)),
Err(_) => Ok(None),
}
};
}
}
Ok(None)
Expand Down
16 changes: 8 additions & 8 deletions crates/anvil/server/src/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<Handler: PubSubRpcHandler> PubSubContext<Handler> {
let mut subscriptions = self.subscriptions.lock();
if let Some(idx) = subscriptions.iter().position(|(i, _)| id == i) {
trace!(target: "rpc", ?id, "removed subscription");
return Some(subscriptions.swap_remove(idx).1)
return Some(subscriptions.swap_remove(idx).1);
}
None
}
Expand Down Expand Up @@ -178,7 +178,7 @@ where
error!(target: "rpc", ?err, "Failed to send message");
}
} else {
break
break;
}
}

Expand All @@ -187,7 +187,7 @@ where
if let Poll::Ready(Err(err)) = pin.connection.poll_flush_unpin(cx) {
trace!(target: "rpc", ?err, "websocket err");
// close the connection
return Poll::Ready(())
return Poll::Ready(());
}

loop {
Expand All @@ -199,25 +199,25 @@ where
Err(err) => match err {
RequestError::Axum(err) => {
trace!(target: "rpc", ?err, "client disconnected");
return Poll::Ready(())
return Poll::Ready(());
}
RequestError::Io(err) => {
trace!(target: "rpc", ?err, "client disconnected");
return Poll::Ready(())
return Poll::Ready(());
}
RequestError::Serde(err) => {
pin.process_request(Err(err));
}
RequestError::Disconnect => {
trace!(target: "rpc", "client disconnected");
return Poll::Ready(())
return Poll::Ready(());
}
},
_ => {}
},
Poll::Ready(None) => {
trace!(target: "rpc", "socket connection finished");
return Poll::Ready(())
return Poll::Ready(());
}
Poll::Pending => break,
}
Expand Down Expand Up @@ -260,7 +260,7 @@ where
}

if !progress {
return Poll::Pending
return Poll::Pending;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn main() -> eyre::Result<()> {
&mut std::io::stdout(),
),
}
return Ok(())
return Ok(());
}

let _ = fdlimit::raise_fd_limit();
Expand Down
12 changes: 6 additions & 6 deletions crates/anvil/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ impl Future for PeriodicStateDumper {
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.get_mut();
if this.dump_state.is_none() {
return Poll::Pending
return Poll::Pending;
}

loop {
Expand All @@ -588,7 +588,7 @@ impl Future for PeriodicStateDumper {
}
Poll::Pending => {
this.in_progress_dump = Some(flush);
return Poll::Pending
return Poll::Pending;
}
}
}
Expand All @@ -598,7 +598,7 @@ impl Future for PeriodicStateDumper {
let path = this.dump_state.clone().expect("exists; see above");
this.in_progress_dump = Some(Box::pin(PeriodicStateDumper::dump_state(api, path)));
} else {
break
break;
}
}

Expand Down Expand Up @@ -628,7 +628,7 @@ impl StateFile {
}
let mut state = Self { path, state: None };
if !state.path.exists() {
return Ok(state)
return Ok(state);
}

state.state = Some(SerializableState::load(&state.path).map_err(|err| err.to_string())?);
Expand Down Expand Up @@ -663,14 +663,14 @@ impl FromStr for ForkUrl {
fn from_str(s: &str) -> Result<Self, Self::Err> {
if let Some((url, block)) = s.rsplit_once('@') {
if block == "latest" {
return Ok(ForkUrl { url: url.to_string(), block: None })
return Ok(ForkUrl { url: url.to_string(), block: None });
}
// this will prevent false positives for auths `user:[email protected]`
if !block.is_empty() && !block.contains(':') && !block.contains('.') {
let block: u64 = block
.parse()
.map_err(|_| format!("Failed to parse block number: `{block}`"))?;
return Ok(ForkUrl { url: url.to_string(), block: Some(block) })
return Ok(ForkUrl { url: url.to_string(), block: Some(block) });
}
}
Ok(ForkUrl { url: s.to_string(), block: None })
Expand Down
Loading

0 comments on commit 8432289

Please sign in to comment.