Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
make abigen reproducible
Browse files Browse the repository at this point in the history
  • Loading branch information
nanne007 committed Feb 19, 2021
1 parent 6f26490 commit 7545e68
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
6 changes: 3 additions & 3 deletions ethers-contract/ethers-contract-abigen/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ethers_core::{
use inflector::Inflector;
use proc_macro2::{Ident, Literal, TokenStream};
use quote::quote;
use std::collections::HashMap;
use std::collections::BTreeMap;
use syn::{Path, Visibility};

/// Internal shared context for generating smart contract bindings.
Expand All @@ -32,7 +32,7 @@ pub(crate) struct Context {
contract_name: Ident,

/// Manually specified method aliases.
method_aliases: HashMap<String, Ident>,
method_aliases: BTreeMap<String, Ident>,

/// Derives added to event structs and enums.
event_derives: Vec<Path>,
Expand Down Expand Up @@ -122,7 +122,7 @@ impl Context {
// NOTE: We only check for duplicate signatures here, since if there are
// duplicate aliases, the compiler will produce a warning because a
// method will be re-defined.
let mut method_aliases = HashMap::new();
let mut method_aliases = BTreeMap::new();
for (signature, alias) in args.method_aliases.into_iter() {
let alias = syn::parse_str(&alias)?;
if method_aliases.insert(signature.clone(), alias).is_some() {
Expand Down
18 changes: 12 additions & 6 deletions ethers-contract/ethers-contract-abigen/src/contract/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ use anyhow::Result;
use inflector::Inflector;
use proc_macro2::{Literal, TokenStream};
use quote::quote;
use std::collections::BTreeMap;
use std::iter::FromIterator;
use syn::Path;

impl Context {
/// Expands each event to a struct + its impl Detokenize block
pub fn events_declaration(&self) -> Result<TokenStream> {
let data_types = self
.abi
.events()
let sorted_events = BTreeMap::from_iter(self.abi.events.clone().into_iter());
let data_types = sorted_events
.clone()
.values()
.flatten()
.map(|event| expand_event(event, &self.event_derives))
.collect::<Result<Vec<_>>>()?;

Expand All @@ -26,9 +30,11 @@ impl Context {
}

pub fn events(&self) -> Result<TokenStream> {
let data_types = self
.abi
.events()
let sorted_events = BTreeMap::from_iter(self.abi.events.clone().into_iter());
let data_types = sorted_events
.clone()
.values()
.flatten()
.map(|event| expand_filter(event))
.collect::<Vec<_>>();

Expand Down
10 changes: 6 additions & 4 deletions ethers-contract/ethers-contract-abigen/src/contract/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ use anyhow::{anyhow, Context as _, Result};
use inflector::Inflector;
use proc_macro2::{Literal, TokenStream};
use quote::quote;
use std::collections::BTreeMap;
use std::iter::FromIterator;
use syn::Ident;

/// Expands a context into a method struct containing all the generated bindings
/// to the Solidity contract methods.
impl Context {
pub(crate) fn methods(&self) -> Result<TokenStream> {
let mut aliases = self.method_aliases.clone();

let functions = self
.abi
.functions()
let sorted_functions = BTreeMap::from_iter(self.abi.functions.clone().into_iter());
let functions = sorted_functions
.values()
.flatten()
.map(|function| {
let signature = function.abi_signature();
expand_function(function, aliases.remove(&signature))
Expand Down

0 comments on commit 7545e68

Please sign in to comment.