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 8bfbc94
Show file tree
Hide file tree
Showing 31 changed files with 165 additions and 154 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
12 changes: 6 additions & 6 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,7 +243,7 @@ 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)
}
Expand All @@ -254,7 +254,7 @@ 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
2 changes: 1 addition & 1 deletion 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
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
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
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
30 changes: 15 additions & 15 deletions crates/dyn-abi/src/eip712/coerce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) fn address(value: &serde_json::Value) -> Result<DynSolValue, DynAbiEr

pub(crate) fn bool(value: &serde_json::Value) -> Result<DynSolValue, DynAbiError> {
if let Some(bool) = value.as_bool() {
return Ok(DynSolValue::Bool(bool));
return Ok(DynSolValue::Bool(bool))
}

let bool = value
Expand All @@ -42,36 +42,36 @@ pub(crate) fn fixed_bytes(n: usize, value: &serde_json::Value) -> Result<DynSolV
let mut word: Word = Default::default();
let min = if buf.len() > n { n } else { buf.len() };
word[..min].copy_from_slice(&buf[..min]);
return Ok(DynSolValue::FixedBytes(word, n));
return Ok(DynSolValue::FixedBytes(word, n))
}

Err(DynAbiError::type_mismatch(DynSolType::FixedBytes(n), value))
}

pub(crate) fn int(n: usize, value: &serde_json::Value) -> Result<DynSolValue, DynAbiError> {
if let Some(num) = value.as_i64() {
return Ok(DynSolValue::Int(I256::try_from(num).unwrap(), n));
return Ok(DynSolValue::Int(I256::try_from(num).unwrap(), n))
}

if let Some(Ok(i)) = value.as_str().map(|s| s.parse()) {
return Ok(DynSolValue::Int(i, n));
return Ok(DynSolValue::Int(i, n))
}

Err(DynAbiError::type_mismatch(DynSolType::Int(n), value))
}

pub(crate) fn uint(n: usize, value: &serde_json::Value) -> Result<DynSolValue, DynAbiError> {
if let Some(num) = value.as_u64() {
return Ok(DynSolValue::Uint(U256::from(num), n));
return Ok(DynSolValue::Uint(U256::from(num), n))
}

if let Some(s) = value.as_str() {
let s = s.strip_prefix("0x").unwrap_or(s);
if let Ok(int) = U256::from_str_radix(s, 10) {
return Ok(DynSolValue::Uint(int, n));
return Ok(DynSolValue::Uint(int, n))
}
if let Ok(int) = U256::from_str_radix(s, 16) {
return Ok(DynSolValue::Uint(int, n));
return Ok(DynSolValue::Uint(int, n))
}
}

Expand All @@ -95,7 +95,7 @@ pub(crate) fn tuple(
return Err(DynAbiError::type_mismatch(
DynSolType::Tuple(inner.to_vec()),
value,
));
))
}

let tuple = arr
Expand All @@ -104,7 +104,7 @@ pub(crate) fn tuple(
.map(|(v, t)| t.coerce(v))
.collect::<Result<Vec<_>, _>>()?;

return Ok(DynSolValue::Tuple(tuple));
return Ok(DynSolValue::Tuple(tuple))
}

Err(DynAbiError::type_mismatch(
Expand All @@ -123,7 +123,7 @@ pub(crate) fn array(
.map(|v| inner.coerce(v))
.collect::<Result<Vec<_>, _>>()?;

return Ok(DynSolValue::Array(array));
return Ok(DynSolValue::Array(array))
}

Err(DynAbiError::type_mismatch(
Expand All @@ -142,15 +142,15 @@ pub(crate) fn fixed_array(
return Err(DynAbiError::type_mismatch(
DynSolType::FixedArray(Box::new(inner.clone()), n),
value,
));
))
}

let array = arr
.iter()
.map(|v| inner.coerce(v))
.collect::<Result<Vec<_>, _>>()?;

return Ok(DynSolValue::FixedArray(array));
return Ok(DynSolValue::FixedArray(array))
}

Err(DynAbiError::type_mismatch(
Expand Down Expand Up @@ -178,14 +178,14 @@ pub(crate) fn coerce_custom_struct(
tuple: inner.to_vec(),
},
value,
));
))
}
}
return Ok(DynSolValue::CustomStruct {
name: name.to_string(),
prop_names: prop_names.to_vec(),
tuple,
});
})
}

Err(DynAbiError::type_mismatch(
Expand All @@ -210,7 +210,7 @@ pub(crate) fn coerce_custom_value(
return Ok(DynSolValue::CustomValue {
name: name.to_string(),
inner: word,
});
})
}

Err(DynAbiError::type_mismatch(
Expand Down
2 changes: 1 addition & 1 deletion crates/dyn-abi/src/eip712/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<'a> TryFrom<&'a str> for ComponentType<'a> {
if depth == 0 {
props.push(props_str[last..i].try_into()?);
last = i + 1;
break;
break
}
}
',' => {
Expand Down
20 changes: 9 additions & 11 deletions crates/dyn-abi/src/eip712/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use crate::{
DynAbiError, DynSolType, DynSolValue,
};
use alloc::collections::{BTreeMap, BTreeSet};
use core::cmp::Ordering;
use core::fmt;
use core::{cmp::Ordering, fmt};
use ethers_abi_enc::SolStruct;
use ethers_primitives::{keccak256, B256};
use serde::{Deserialize, Deserializer, Serialize};
Expand Down Expand Up @@ -192,7 +191,6 @@ struct DfsContext<'a> {
#[derive(Debug, Clone, Default)]
pub struct Resolver {
/// Nodes in the graph
///
// NOTE: Non-duplication of names must be enforced. See note on impl of Ord
// for TypeDef
nodes: BTreeMap<String, TypeDef>,
Expand Down Expand Up @@ -256,10 +254,10 @@ impl Resolver {
};

if context.stack.contains(type_name) {
return true;
return true
}
if context.visited.contains(ty) {
return false;
return false
}

// update visited and stack
Expand All @@ -273,7 +271,7 @@ impl Resolver {
.iter()
.any(|edge| self.detect_cycle(edge, context))
{
return true;
return true
}

context.stack.remove(type_name);
Expand Down Expand Up @@ -326,7 +324,7 @@ impl Resolver {
root_type: RootType<'_>,
) -> Result<(), DynAbiError> {
if root_type.try_basic_solidity().is_ok() {
return Ok(());
return Ok(())
}

let this_type = self
Expand All @@ -352,7 +350,7 @@ impl Resolver {
pub fn linearize(&self, type_name: &str) -> Result<Vec<&TypeDef>, DynAbiError> {
let mut context = DfsContext::default();
if self.detect_cycle(type_name, &mut context) {
return Err(DynAbiError::circular_dependency(type_name));
return Err(DynAbiError::circular_dependency(type_name))
}
let root_type = type_name.try_into()?;
let mut resolution = vec![];
Expand All @@ -364,7 +362,7 @@ impl Resolver {
/// struct.
fn resolve_root_type(&self, root_type: RootType<'_>) -> Result<DynSolType, DynAbiError> {
if root_type.try_basic_solidity().is_ok() {
return root_type.resolve_basic_solidity();
return root_type.resolve_basic_solidity()
}

let ty = self
Expand Down Expand Up @@ -411,7 +409,7 @@ impl Resolver {
/// the type is mising, or contains a circular dependency.
pub fn resolve(&self, type_name: &str) -> Result<DynSolType, DynAbiError> {
if self.detect_cycle(type_name, &mut Default::default()) {
return Err(DynAbiError::circular_dependency(type_name));
return Err(DynAbiError::circular_dependency(type_name))
}
self.unchecked_resolve(type_name.try_into()?)
}
Expand Down Expand Up @@ -464,7 +462,7 @@ impl Resolver {
/// encoded as their `encodeData` hash.
pub fn eip712_data_word(&self, value: &DynSolValue) -> Result<B256, DynAbiError> {
if let Some(word) = value.as_word() {
return Ok(word);
return Ok(word)
}

match value {
Expand Down
Loading

0 comments on commit 8bfbc94

Please sign in to comment.