Skip to content

Commit

Permalink
fmt: add rustfmt.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed May 15, 2023
1 parent 30dbda3 commit 325d9d1
Show file tree
Hide file tree
Showing 39 changed files with 374 additions and 312 deletions.
9 changes: 9 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Since version 2.23 (released in August 2019), git-blame has a feature
# to ignore or bypass certain commits.
#
# This file contains a list of commits that are not likely what you
# are looking for in a blame, such as mass reformatting or renaming.
# You can set this file as a default ignore file for blame by running
# the following command.
#
# $ git config blame.ignoreRevsFile .git-blame-ignore-revs
15 changes: 8 additions & 7 deletions crates/abi/src/coder/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<'a> Decoder<'a> {
#[inline]
fn child(&self, offset: usize) -> Result<Decoder<'a>, Error> {
if offset > self.buf.len() {
return Err(Error::Overrun);
return Err(Error::Overrun)
}
Ok(Self {
buf: &self.buf[offset..],
Expand Down Expand Up @@ -192,12 +192,12 @@ impl<'a> Decoder<'a> {
if self.validate {
let padded_len = util::round_up_nearest_multiple(len, 32);
if self.offset + padded_len > self.buf.len() {
return Err(Error::Overrun);
return Err(Error::Overrun)
}
if !util::check_zeroes(self.peek(self.offset + len..self.offset + padded_len)?) {
return Err(Error::Other(Cow::Borrowed(
"Non-empty bytes after packed array",
)));
)))
}
}
let res = self.peek_len(len)?;
Expand Down Expand Up @@ -234,7 +234,7 @@ impl<'a> Decoder<'a> {
#[inline]
pub fn decode<T: TokenType>(&mut self, data: &[u8]) -> Result<T> {
if data.is_empty() {
return Err(Error::Overrun);
return Err(Error::Overrun)
}
T::decode_from(self)
}
Expand All @@ -243,18 +243,19 @@ impl<'a> Decoder<'a> {
#[inline]
pub fn decode_sequence<T: TokenType + TokenSeq>(&mut self, data: &[u8]) -> Result<T> {
if data.is_empty() {
return Err(Error::Overrun);
return Err(Error::Overrun)
}
T::decode_sequence(self)
}
}

/// Decodes ABI compliant vector of bytes into vector of tokens described by types param.
/// Decodes ABI compliant vector of bytes into vector of tokens described by
/// types param.
pub fn decode<T: TokenSeq>(data: &[u8], validate: bool) -> Result<T> {
let mut decoder = Decoder::new(data, validate);
let res = decoder.decode_sequence::<T>(data)?;
if validate && encode(&res) != data {
return Err(Error::ReserMismatch);
return Err(Error::ReserMismatch)
}
Ok(res)
}
Expand Down
6 changes: 1 addition & 5 deletions crates/abi/src/coder/impl_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ where
{
if N == 0 {
// SAFETY: An empty array is always inhabited and has no validity invariants.
return unsafe { Ok(mem::zeroed()) };
return unsafe { Ok(mem::zeroed()) }
}

struct Guard<'a, T, const N: usize> {
Expand Down Expand Up @@ -62,8 +62,6 @@ where
Ok(unsafe { array_assume_init(array) })
}

/* ----------------------------------------- MaybeUninit ---------------------------------------- */

/// [`MaybeUninit::slice_assume_init_mut`]
#[inline(always)]
unsafe fn slice_assume_init_mut<T>(slice: &mut [MaybeUninit<T>]) -> &mut [T] {
Expand Down Expand Up @@ -96,8 +94,6 @@ unsafe fn transpose<T, const N: usize>(array: [MaybeUninit<T>; N]) -> MaybeUnini
mem::transmute_copy::<[MaybeUninit<T>; N], MaybeUninit<[T; N]>>(&mem::ManuallyDrop::new(&array))
}

/* --------------------------------------------- Vec -------------------------------------------- */

/// [`Vec::into_flattened`].
#[inline]
pub(crate) fn into_flattened<T, const N: usize>(vec: Vec<[T; N]>) -> Vec<T> {
Expand Down
3 changes: 1 addition & 2 deletions crates/abi/src/coder/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
//! - Tuples (T, U, V, ...)
//! - Dynamic-length byte arrays `u8[]`

use crate::no_std_prelude::*;
use crate::{Decoder, Encoder, Result, Word};
use crate::{no_std_prelude::*, Decoder, Encoder, Result, Word};
use core::fmt;
use ethers_primitives::{Address, U256};

Expand Down
15 changes: 8 additions & 7 deletions crates/abi/src/eip712.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ use ethers_primitives::{keccak256, Address, B256, U256};
#[cfg_attr(feature = "eip712-serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "eip712-serde", serde(rename_all = "camelCase"))]
pub struct Eip712Domain {
/// The user readable name of signing domain, i.e. the name of the DApp or the protocol.
/// The user readable name of signing domain, i.e. the name of the DApp or
/// the protocol.
#[cfg_attr(
feature = "eip712-serde",
serde(default, skip_serializing_if = "Option::is_none")
)]
pub name: Option<Cow<'static, str>>,

/// The current major version of the signing domain. Signatures from different versions are not
/// compatible.
/// The current major version of the signing domain. Signatures from
/// different versions are not compatible.
#[cfg_attr(
feature = "eip712-serde",
serde(default, skip_serializing_if = "Option::is_none")
)]
pub version: Option<Cow<'static, str>>,

/// The EIP-155 chain id. The user-agent should refuse signing if it does not match the
/// currently active chain.
/// The EIP-155 chain id. The user-agent should refuse signing if it does
/// not match the currently active chain.
#[cfg_attr(
feature = "eip712-serde",
serde(
Expand All @@ -47,8 +48,8 @@ pub struct Eip712Domain {
)]
pub verifying_contract: Option<Address>,

/// A disambiguating salt for the protocol. This can be used as a domain separator of last
/// resort.
/// A disambiguating salt for the protocol. This can be used as a domain
/// separator of last resort.
#[cfg_attr(
feature = "eip712-serde",
serde(default, skip_serializing_if = "Option::is_none")
Expand Down
4 changes: 2 additions & 2 deletions crates/abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
//! ## [`sol!`]
//!
//! The [`sol!`] procedural macro provides a convenient way to define
//! custom [`SolType`]s and reference primitive ones. See [its documentation][sol!]
//! for details on how to use it.
//! custom [`SolType`]s and reference primitive ones. See
//! [its documentation][sol!] for details on how to use it.
//!
//! ## [`SolStruct`]
//!
Expand Down
9 changes: 6 additions & 3 deletions crates/abi/src/types/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::{no_std_prelude::*, token::TokenSeq, Result, SolType};
/// ### Implementer's Guide
///
/// We do not recommend implementing this trait directly. Instead, we recommend
/// using the [`sol`][crate::sol] proc macro to parse a Solidity function definition.
/// using the [`sol`][crate::sol] proc macro to parse a Solidity function
/// definition.
pub trait SolCall: Sized {
/// The underlying tuple type which represents this type's members.
///
Expand All @@ -30,14 +31,16 @@ pub trait SolCall: Sized {
/// The size of the encoded data in bytes, **without** its selector.
fn data_size(&self) -> usize;

/// ABI decode this call's arguments from the given slice, **without** its selector.
/// ABI decode this call's arguments from the given slice, **without** its
/// selector.
#[inline]
fn decode_raw(data: &[u8], validate: bool) -> Result<Self> {
let tuple = <Self::Tuple as SolType>::decode(data, validate)?;
Ok(Self::from_rust(tuple))
}

/// ABI decode this call's arguments from the given slice, **with** the selector.
/// ABI decode this call's arguments from the given slice, **with** the
/// selector.
#[inline]
fn decode(data: &[u8], validate: bool) -> Result<Self> {
let data = data
Expand Down
13 changes: 8 additions & 5 deletions crates/abi/src/types/data_type.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Solidity Primitives. These are the types that are built into Solidity.

use crate::no_std_prelude::{String as RustString, *};
use crate::{token::*, util, Result, SolType, Word};
use crate::{
no_std_prelude::{String as RustString, *},
token::*,
util, Result, SolType, Word,
};
use alloc::borrow::Cow;
use core::marker::PhantomData;
use ethers_primitives::{keccak256, Address as RustAddress, I256, U256};
Expand Down Expand Up @@ -38,7 +41,7 @@ impl SolType for Address {
#[inline]
fn type_check(token: &Self::TokenType) -> Result<()> {
if !util::check_zeroes(&token.inner()[..12]) {
return Err(Self::type_check_fail(token.as_slice()));
return Err(Self::type_check_fail(token.as_slice()))
}
Ok(())
}
Expand Down Expand Up @@ -357,7 +360,7 @@ impl SolType for Bool {
#[inline]
fn type_check(token: &Self::TokenType) -> Result<()> {
if !util::check_bool(token.inner()) {
return Err(Self::type_check_fail(token.as_slice()));
return Err(Self::type_check_fail(token.as_slice()))
}
Ok(())
}
Expand Down Expand Up @@ -467,7 +470,7 @@ impl SolType for String {
#[inline]
fn type_check(token: &Self::TokenType) -> Result<()> {
if core::str::from_utf8(token.as_slice()).is_err() {
return Err(Self::type_check_fail(token.as_slice()));
return Err(Self::type_check_fail(token.as_slice()))
}
Ok(())
}
Expand Down
9 changes: 6 additions & 3 deletions crates/abi/src/types/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use ethers_primitives::U256;
/// ### Implementer's Guide
///
/// We do not recommend implementing this trait directly. Instead, we recommend
/// using the [`sol`][crate::sol] proc macro to parse a Solidity error definition.
/// using the [`sol`][crate::sol] proc macro to parse a Solidity error
/// definition.
pub trait SolError: Sized {
/// The underlying tuple type which represents the error's members.
///
Expand All @@ -36,14 +37,16 @@ pub trait SolError: Sized {
/// The size of the encoded data in bytes, **without** its selector.
fn data_size(&self) -> usize;

/// ABI decode this call's arguments from the given slice, **without** its selector.
/// ABI decode this call's arguments from the given slice, **without** its
/// selector.
#[inline]
fn decode_raw(data: &[u8], validate: bool) -> Result<Self> {
let tuple = <Self::Tuple as SolType>::decode(data, validate)?;
Ok(Self::from_rust(tuple))
}

/// ABI decode this error's arguments from the given slice, **with** the selector.
/// ABI decode this error's arguments from the given slice, **with** the
/// selector.
#[inline]
fn decode(data: &[u8], validate: bool) -> Result<Self> {
let data = data
Expand Down
13 changes: 8 additions & 5 deletions crates/abi/src/types/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ type TupleTokenTypeFor<T> = <TupleFor<T> as SolType>::TokenType;
/// # Implementer's Guide
///
/// We do not recommend implementing this trait directly. Instead, we recommend
/// using the [`sol`][crate::sol] proc macro to parse a Solidity struct definition.
/// using the [`sol`][crate::sol] proc macro to parse a Solidity struct
/// definition.
///
/// # Note
///
/// Special attention should be paid to [`eip712_encode_type`] for complex Solidity types.
/// Nested Solidity structs **must** properly encode their type.
/// Special attention should be paid to [`eip712_encode_type`] for complex
/// Solidity types. Nested Solidity structs **must** properly encode their type.
///
/// To be clear, a struct with a nested struct must encode the nested struct's type as well.
/// To be clear, a struct with a nested struct must encode the nested struct's
/// type as well.
///
/// See [EIP-712#definition-of-encodetype][ref] for more details.
///
Expand All @@ -41,7 +43,8 @@ pub trait SolStruct {
const NAME: &'static str;

/// The field types and names. Type is a Solidity string, and must conform
/// to the name of the Solidty type at the same index in the associated tuple.
/// to the name of the Solidty type at the same index in the associated
/// tuple.
///
/// Used in [`eip712_encode_type`][SolStruct::eip712_encode_type].
const FIELDS: &'static [(&'static str, &'static str)];
Expand Down
3 changes: 2 additions & 1 deletion crates/abi/src/types/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ pub trait SolType {
/// Non-standard Packed Mode ABI encoding.
///
/// This is different from normal ABI encoding:
/// - types shorter than 32 bytes are concatenated directly, without padding or sign extension;
/// - types shorter than 32 bytes are concatenated directly, without padding
/// or sign extension;
/// - dynamic types are encoded in-place and without the length;
/// - array elements are padded, but still encoded in-place.
///
Expand Down
4 changes: 2 additions & 2 deletions crates/abi/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub(crate) const fn round_up_nearest_multiple(value: usize, padding: usize) -> u
#[inline]
pub(crate) fn check_fixed_bytes(word: Word, len: usize) -> bool {
if word.is_empty() {
return true;
return true
}
match len {
0 => panic!("cannot have bytes0"),
Expand All @@ -55,7 +55,7 @@ pub(crate) fn as_u32(word: Word, type_check: bool) -> Result<u32> {
return Err(Error::type_check_fail(
&word[..],
"Solidity pointer (uint32)",
));
))
}

let result = ((word[28] as u32) << 24)
Expand Down
Loading

0 comments on commit 325d9d1

Please sign in to comment.