Skip to content

Commit

Permalink
chore: add rustfmt.toml (gakonst#537)
Browse files Browse the repository at this point in the history
* chore: add rustfmt.toml

* rustfmt

* chore: Update readme with fmt info

* ci: update ci

* chore: rustfmt

* rustfmt

* rustfmt

* ci: install libudev

* chore(clippy): make clippy happy

* chore(clippy): make clippy happy

* revert ci

* ci: install libudev
  • Loading branch information
mattsse authored Oct 29, 2021
1 parent eede86d commit dcf2002
Show file tree
Hide file tree
Showing 122 changed files with 1,267 additions and 3,017 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,22 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install stable toolchain
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy
override: true
- name: Install Dependencies
run: sudo apt-get install libudev-dev
- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true
- name: cargo fmt
run: cargo fmt --all -- --check
run: cargo +nightly fmt --all -- --check
- name: cargo clippy
run: cargo clippy -- -D warnings
run: cargo +nightly clippy --all --all-features -- -D warnings

wasm:
name: WASM
Expand Down
20 changes: 10 additions & 10 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ Thanks for your help improving the project! We are so happy to have you! We have
[a contributing guide](https://github.com/gakonst/ethers-rs/blob/master/CONTRIBUTING.md) to
help you get involved in the ethers-rs project.

If you make a Pull Request, do not forget to add your changes in the [CHANGELOG](CHANGELOG.md).
If you make a Pull Request, do not forget to add your changes in the [CHANGELOG](CHANGELOG.md) and ensure your code if
properly formatted with `cargo +nightly fmt` and clippy is happy `cargo clippy`, you can even try to let clippy fix simple
issues itself: `cargo +nightly clippy --fix -Z unstable-options`

## Related Projects

Expand Down
43 changes: 15 additions & 28 deletions ethers-contract/ethers-contract-abigen/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ mod methods;
mod structs;
mod types;

use super::util;
use super::Abigen;
use crate::contract::structs::InternalStructs;
use crate::rawabi::RawAbi;
use super::{util, Abigen};
use crate::{contract::structs::InternalStructs, rawabi::RawAbi};
use anyhow::{anyhow, Context as _, Result};
use ethers_core::abi::{Abi, AbiParser};

Expand Down Expand Up @@ -38,14 +36,8 @@ pub struct ExpandedContract {
impl ExpandedContract {
/// Merges everything into a single module
pub fn into_tokens(self) -> TokenStream {
let ExpandedContract {
module,
imports,
contract,
events,
call_structs,
abi_structs,
} = self;
let ExpandedContract { module, imports, contract, events, call_structs, abi_structs } =
self;
quote! {
// export all the created data types
pub use #module::*;
Expand Down Expand Up @@ -96,10 +88,8 @@ impl Context {
/// Expands the whole rust contract
pub fn expand(&self) -> Result<ExpandedContract> {
let name = &self.contract_name;
let name_mod = util::ident(&format!(
"{}_mod",
self.contract_name.to_string().to_lowercase()
));
let name_mod =
util::ident(&format!("{}_mod", self.contract_name.to_string().to_lowercase()));

let abi_name = super::util::safe_ident(&format!("{}_ABI", name.to_string().to_uppercase()));

Expand Down Expand Up @@ -182,16 +172,16 @@ impl Context {
};

// try to extract all the solidity structs from the normal JSON ABI
// we need to parse the json abi again because we need the internalType fields which are omitted by ethabi. If the ABI was defined as human readable we use the `internal_structs` from the Abi Parser
// we need to parse the json abi again because we need the internalType fields which are
// omitted by ethabi. If the ABI was defined as human readable we use the `internal_structs`
// from the Abi Parser
let internal_structs = if human_readable {
let mut internal_structs = InternalStructs::default();
// the types in the abi_parser are already valid rust types so simply clone them to make it consistent with the `RawAbi` variant
internal_structs.rust_type_names.extend(
abi_parser
.function_params
.values()
.map(|ty| (ty.clone(), ty.clone())),
);
// the types in the abi_parser are already valid rust types so simply clone them to make
// it consistent with the `RawAbi` variant
internal_structs
.rust_type_names
.extend(abi_parser.function_params.values().map(|ty| (ty.clone(), ty.clone())));
internal_structs.function_params = abi_parser.function_params.clone();
internal_structs.outputs = abi_parser.outputs.clone();

Expand All @@ -212,10 +202,7 @@ impl Context {
for (signature, alias) in args.method_aliases.into_iter() {
let alias = syn::parse_str(&alias)?;
if method_aliases.insert(signature.clone(), alias).is_some() {
return Err(anyhow!(
"duplicate method signature '{}' in method aliases",
signature,
));
return Err(anyhow!("duplicate method signature '{}' in method aliases", signature,))
}
}

Expand Down
93 changes: 19 additions & 74 deletions ethers-contract/ethers-contract-abigen/src/contract/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Context {

/// The name ident of the events enum
fn expand_event_enum_name(&self) -> Ident {
util::ident(&format!("{}Events", self.contract_name.to_string()))
util::ident(&format!("{}Events", self.contract_name))
}

/// Expands the `events` function that bundles all declared events of this contract
Expand All @@ -112,10 +112,7 @@ impl Context {
let ty = if iter.next().is_some() {
self.expand_event_enum_name()
} else {
expand_struct_name(
event,
self.event_aliases.get(&event.abi_signature()).cloned(),
)
expand_struct_name(event, self.event_aliases.get(&event.abi_signature()).cloned())
};

quote! {
Expand Down Expand Up @@ -149,7 +146,7 @@ impl Context {
.map(SolStruct::name)
.map(util::ident)
{
return Ok(quote! {::std::vec::Vec<#ty>});
return Ok(quote! {::std::vec::Vec<#ty>})
}
}
quote! { #ethers_core::types::H256 }
Expand All @@ -165,19 +162,15 @@ impl Context {
.map(util::ident)
{
let size = Literal::usize_unsuffixed(*size);
return Ok(quote! {[#ty; #size]});
return Ok(quote! {[#ty; #size]})
}
}
quote! { #ethers_core::types::H256 }
}
(ParamType::Tuple(..), true) => {
// represents a struct
if let Some(ty) = self
.abi_parser
.structs
.get(&input.name)
.map(SolStruct::name)
.map(util::ident)
if let Some(ty) =
self.abi_parser.structs.get(&input.name).map(SolStruct::name).map(util::ident)
{
quote! {#ty}
} else {
Expand Down Expand Up @@ -337,12 +330,8 @@ mod tests {
}

fn test_context_with_alias(sig: &str, alias: &str) -> Context {
Context::from_abigen(
Abigen::new("TestToken", "[]")
.unwrap()
.add_event_alias(sig, alias),
)
.unwrap()
Context::from_abigen(Abigen::new("TestToken", "[]").unwrap().add_event_alias(sig, alias))
.unwrap()
}

#[test]
Expand Down Expand Up @@ -385,21 +374,9 @@ mod tests {
let event = Event {
name: "Transfer".into(),
inputs: vec![
EventParam {
name: "from".into(),
kind: ParamType::Address,
indexed: true,
},
EventParam {
name: "to".into(),
kind: ParamType::Address,
indexed: true,
},
EventParam {
name: "amount".into(),
kind: ParamType::Uint(256),
indexed: false,
},
EventParam { name: "from".into(), kind: ParamType::Address, indexed: true },
EventParam { name: "to".into(), kind: ParamType::Address, indexed: true },
EventParam { name: "amount".into(), kind: ParamType::Uint(256), indexed: false },
],
anonymous: false,
};
Expand All @@ -417,16 +394,8 @@ mod tests {
let event = Event {
name: "Foo".into(),
inputs: vec![
EventParam {
name: "a".into(),
kind: ParamType::Bool,
indexed: false,
},
EventParam {
name: String::new(),
kind: ParamType::Address,
indexed: false,
},
EventParam { name: "a".into(), kind: ParamType::Bool, indexed: false },
EventParam { name: String::new(), kind: ParamType::Address, indexed: false },
],
anonymous: false,
};
Expand All @@ -449,16 +418,8 @@ mod tests {
let event = Event {
name: "Foo".into(),
inputs: vec![
EventParam {
name: "a".into(),
kind: ParamType::Bool,
indexed: false,
},
EventParam {
name: String::new(),
kind: ParamType::Address,
indexed: false,
},
EventParam { name: "a".into(), kind: ParamType::Bool, indexed: false },
EventParam { name: String::new(), kind: ParamType::Address, indexed: false },
],
anonymous: false,
};
Expand All @@ -482,16 +443,8 @@ mod tests {
let event = Event {
name: "Foo".into(),
inputs: vec![
EventParam {
name: String::new(),
kind: ParamType::Bool,
indexed: false,
},
EventParam {
name: String::new(),
kind: ParamType::Address,
indexed: false,
},
EventParam { name: String::new(), kind: ParamType::Bool, indexed: false },
EventParam { name: String::new(), kind: ParamType::Address, indexed: false },
],
anonymous: false,
};
Expand All @@ -511,16 +464,8 @@ mod tests {
let event = Event {
name: "Foo".into(),
inputs: vec![
EventParam {
name: String::new(),
kind: ParamType::Bool,
indexed: false,
},
EventParam {
name: String::new(),
kind: ParamType::Address,
indexed: false,
},
EventParam { name: String::new(), kind: ParamType::Bool, indexed: false },
EventParam { name: String::new(), kind: ParamType::Address, indexed: false },
],
anonymous: false,
};
Expand Down
Loading

0 comments on commit dcf2002

Please sign in to comment.