Skip to content

Commit

Permalink
chore(clippy): apply lint suggestions (alloy-rs#903)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored and ben186 committed Jul 27, 2024
1 parent 285c7b2 commit c122087
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 105 deletions.
16 changes: 8 additions & 8 deletions crates/consensus/src/receipt/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ impl<'de> serde::Deserialize<'de> for Eip658Value {
Ok(Eip658Value::Eip658(v))
}

fn visit_str<E: de::Error>(self, v: &str) -> Result<Self::Value, E> {
match v {
"0x" | "0x0" | "false" => Ok(Eip658Value::Eip658(false)),
"0x1" | "true" => Ok(Eip658Value::Eip658(true)),
_ => v.parse::<B256>().map(Eip658Value::PostState).map_err(de::Error::custom),
}
}

fn visit_bytes<E: de::Error>(self, v: &[u8]) -> Result<Self::Value, E> {
B256::try_from(v).map(Eip658Value::PostState).map_err(de::Error::custom)
}
Expand All @@ -120,14 +128,6 @@ impl<'de> serde::Deserialize<'de> for Eip658Value {

Ok(Eip658Value::PostState(bytes.into()))
}

fn visit_str<E: de::Error>(self, v: &str) -> Result<Self::Value, E> {
match v {
"0x" | "0x0" | "false" => Ok(Eip658Value::Eip658(false)),
"0x1" | "true" => Ok(Eip658Value::Eip658(true)),
_ => v.parse::<B256>().map(Eip658Value::PostState).map_err(de::Error::custom),
}
}
}

deserializer.deserialize_any(Visitor)
Expand Down
90 changes: 45 additions & 45 deletions crates/consensus/src/transaction/eip4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ impl Transaction for TxEip4844Variant {
}
}

fn nonce(&self) -> u64 {
match self {
Self::TxEip4844(tx) => tx.nonce,
Self::TxEip4844WithSidecar(tx) => tx.tx().nonce,
}
}

fn gas_limit(&self) -> u128 {
match self {
Self::TxEip4844(tx) => tx.gas_limit,
Expand All @@ -210,20 +217,6 @@ impl Transaction for TxEip4844Variant {
None
}

fn input(&self) -> &[u8] {
match self {
Self::TxEip4844(tx) => tx.input.as_ref(),
Self::TxEip4844WithSidecar(tx) => tx.tx().input.as_ref(),
}
}

fn nonce(&self) -> u64 {
match self {
Self::TxEip4844(tx) => tx.nonce,
Self::TxEip4844WithSidecar(tx) => tx.tx().nonce,
}
}

fn to(&self) -> TxKind {
match self {
Self::TxEip4844(tx) => tx.to,
Expand All @@ -238,6 +231,13 @@ impl Transaction for TxEip4844Variant {
Self::TxEip4844WithSidecar(tx) => tx.tx.value,
}
}

fn input(&self) -> &[u8] {
match self {
Self::TxEip4844(tx) => tx.input.as_ref(),
Self::TxEip4844WithSidecar(tx) => tx.tx().input.as_ref(),
}
}
}

impl SignableTransaction<Signature> for TxEip4844Variant {
Expand All @@ -252,6 +252,15 @@ impl SignableTransaction<Signature> for TxEip4844Variant {
}
}

fn encode_for_signing(&self, out: &mut dyn alloy_rlp::BufMut) {
// A signature for a [TxEip4844WithSidecar] is a signature over the [TxEip4844Variant]
// EIP-2718 payload fields:
// (BLOB_TX_TYPE ||
// rlp([chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, to, value,
// data, access_list, max_fee_per_blob_gas, blob_versioned_hashes]))
self.tx().encode_for_signing(out);
}

fn payload_len_for_signature(&self) -> usize {
let payload_length = self.fields_len();
// 'transaction type byte length' + 'header length' + 'payload length'
Expand All @@ -270,15 +279,6 @@ impl SignableTransaction<Signature> for TxEip4844Variant {
// signature.
Signed::new_unchecked(self, signature.with_parity_bool(), hash)
}

fn encode_for_signing(&self, out: &mut dyn alloy_rlp::BufMut) {
// A signature for a [TxEip4844WithSidecar] is a signature over the [TxEip4844Variant]
// EIP-2718 payload fields:
// (BLOB_TX_TYPE ||
// rlp([chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, to, value,
// data, access_list, max_fee_per_blob_gas, blob_versioned_hashes]))
self.tx().encode_for_signing(out);
}
}

/// [EIP-4844 Blob Transaction](https://eips.ethereum.org/EIPS/eip-4844#blob-transaction)
Expand Down Expand Up @@ -608,6 +608,10 @@ impl SignableTransaction<Signature> for TxEip4844 {
self.chain_id = chain_id;
}

fn encode_for_signing(&self, out: &mut dyn alloy_rlp::BufMut) {
self.encode_for_signing(out);
}

fn payload_len_for_signature(&self) -> usize {
self.payload_len_for_signature()
}
Expand All @@ -622,25 +626,9 @@ impl SignableTransaction<Signature> for TxEip4844 {
// signature.
Signed::new_unchecked(self, signature.with_parity_bool(), hash)
}

fn encode_for_signing(&self, out: &mut dyn alloy_rlp::BufMut) {
self.encode_for_signing(out);
}
}

impl Transaction for TxEip4844 {
fn input(&self) -> &[u8] {
&self.input
}

fn to(&self) -> TxKind {
self.to.into()
}

fn value(&self) -> U256 {
self.value
}

fn chain_id(&self) -> Option<ChainId> {
Some(self.chain_id)
}
Expand All @@ -656,6 +644,18 @@ impl Transaction for TxEip4844 {
fn gas_price(&self) -> Option<u128> {
None
}

fn to(&self) -> TxKind {
self.to.into()
}

fn value(&self) -> U256 {
self.value
}

fn input(&self) -> &[u8] {
&self.input
}
}

impl Encodable for TxEip4844 {
Expand Down Expand Up @@ -840,6 +840,12 @@ impl SignableTransaction<Signature> for TxEip4844WithSidecar {
self.tx.encode_for_signing(out);
}

fn payload_len_for_signature(&self) -> usize {
// The payload length is the length of the `transaction_payload_body` list.
// The sidecar is NOT included.
self.tx.payload_len_for_signature()
}

fn into_signed(self, signature: Signature) -> Signed<Self, Signature> {
let mut buf = Vec::with_capacity(self.tx.encoded_len_with_signature(&signature, false));
// The sidecar is NOT included in the signed payload, only the transaction fields and the
Expand All @@ -855,12 +861,6 @@ impl SignableTransaction<Signature> for TxEip4844WithSidecar {
// signature.
Signed::new_unchecked(self, signature.with_parity_bool(), hash)
}

fn payload_len_for_signature(&self) -> usize {
// The payload length is the length of the `transaction_payload_body` list.
// The sidecar is NOT included.
self.tx.payload_len_for_signature()
}
}

impl Transaction for TxEip4844WithSidecar {
Expand Down
36 changes: 18 additions & 18 deletions crates/consensus/src/transaction/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ impl Transaction for TypedTransaction {
}
}

fn nonce(&self) -> u64 {
match self {
Self::Legacy(tx) => tx.nonce(),
Self::Eip2930(tx) => tx.nonce(),
Self::Eip1559(tx) => tx.nonce(),
Self::Eip4844(tx) => tx.nonce(),
}
}

fn gas_limit(&self) -> u128 {
match self {
Self::Legacy(tx) => tx.gas_limit(),
Expand All @@ -142,24 +151,6 @@ impl Transaction for TypedTransaction {
}
}

fn input(&self) -> &[u8] {
match self {
Self::Legacy(tx) => tx.input(),
Self::Eip2930(tx) => tx.input(),
Self::Eip1559(tx) => tx.input(),
Self::Eip4844(tx) => tx.input(),
}
}

fn nonce(&self) -> u64 {
match self {
Self::Legacy(tx) => tx.nonce(),
Self::Eip2930(tx) => tx.nonce(),
Self::Eip1559(tx) => tx.nonce(),
Self::Eip4844(tx) => tx.nonce(),
}
}

fn to(&self) -> TxKind {
match self {
Self::Legacy(tx) => tx.to(),
Expand All @@ -177,6 +168,15 @@ impl Transaction for TypedTransaction {
Self::Eip4844(tx) => tx.value(),
}
}

fn input(&self) -> &[u8] {
match self {
Self::Legacy(tx) => tx.input(),
Self::Eip2930(tx) => tx.input(),
Self::Eip1559(tx) => tx.input(),
Self::Eip4844(tx) => tx.input(),
}
}
}

#[cfg(feature = "serde")]
Expand Down
12 changes: 6 additions & 6 deletions crates/json-rpc/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,28 @@ impl<'de> Deserialize<'de> for Id {
write!(formatter, "a string, a number, or null")
}

fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
Ok(Id::String(v.to_owned()))
Ok(Id::Number(v))
}

fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
Ok(Id::Number(v))
Ok(Id::String(v.to_owned()))
}

fn visit_unit<E>(self) -> Result<Self::Value, E>
fn visit_none<E>(self) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
Ok(Id::None)
}

fn visit_none<E>(self) -> Result<Self::Value, E>
fn visit_unit<E>(self) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
Expand Down
8 changes: 4 additions & 4 deletions crates/json-rpc/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ impl<Payload, ErrData> FromIterator<Response<Payload, ErrData>>
let mut iter = iter.into_iter().peekable();
// return single if iter has exactly one element, else make a batch
if let Some(first) = iter.next() {
if iter.peek().is_none() {
return Self::Single(first);
return if iter.peek().is_none() {
Self::Single(first)
} else {
let mut batch = Vec::new();
batch.push(first);
batch.extend(iter);
return Self::Batch(batch);
}
Self::Batch(batch)
};
}
Self::Batch(vec![])
}
Expand Down
8 changes: 4 additions & 4 deletions crates/network/src/any/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ impl TransactionBuilder<AnyNetwork> for WithOtherFields<TransactionRequest> {
self.deref().complete_type(ty.try_into().map_err(|_| vec!["supported tx type"])?)
}

fn can_build(&self) -> bool {
self.deref().can_build()
}

fn can_submit(&self) -> bool {
self.deref().can_submit()
}

fn can_build(&self) -> bool {
self.deref().can_build()
}

#[doc(alias = "output_transaction_type")]
fn output_tx_type(&self) -> <AnyNetwork as Network>::TxType {
self.deref().output_tx_type().into()
Expand Down
8 changes: 4 additions & 4 deletions crates/network/src/ethereum/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ impl TransactionBuilder<Ethereum> for TransactionRequest {
self.to
}

fn set_kind(&mut self, kind: TxKind) {
self.to = Some(kind);
}

fn clear_kind(&mut self) {
self.to = None;
}

fn set_kind(&mut self, kind: TxKind) {
self.to = Some(kind);
}

fn value(&self) -> Option<U256> {
self.value
}
Expand Down
2 changes: 1 addition & 1 deletion crates/provider/src/provider/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub trait Provider<T: Transport + Clone = BoxTransport, N: Network = Ethereum>:
// if the base fee of the Latest block is 0 then we need check if the latest block even has
// a base fee/supports EIP1559
let base_fee_per_gas = match fee_history.latest_block_base_fee() {
Some(base_fee) if (base_fee != 0) => base_fee,
Some(base_fee) if base_fee != 0 => base_fee,
_ => {
// empty response, fetch basefee from latest block directly
self.get_block_by_number(BlockNumberOrTag::Latest, false)
Expand Down
8 changes: 4 additions & 4 deletions crates/pubsub/src/managers/in_flight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ impl InFlight {
if self.is_subscription() {
if let ResponsePayload::Success(val) = resp.payload {
let sub_id: serde_json::Result<U256> = serde_json::from_str(val.get());
match sub_id {
Ok(alias) => return Some((alias, self)),
return match sub_id {
Ok(alias) => Some((alias, self)),
Err(e) => {
let _ = self.tx.send(Err(TransportError::deser_err(e, val.get())));
return None;
None
}
}
};
}
}

Expand Down
Loading

0 comments on commit c122087

Please sign in to comment.