Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

updated ethabi to version 4.0 #6742

Merged
merged 3 commits into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion ethcore/native_contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
build = "build.rs"

[dependencies]
ethabi = "2.0"
ethabi = "4.0"
futures = "0.1"
byteorder = "1.0"
ethcore-bigint = { path = "../../util/bigint" }
Expand Down
2 changes: 1 addition & 1 deletion ethcore/native_contracts/generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]

[dependencies]
ethabi = "2.0"
ethabi = "4.0"
heck = "0.2"
35 changes: 17 additions & 18 deletions ethcore/native_contracts/generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@
//! due to missing crates or name collisions. This will change when
//! it can be ported to a procedural macro.

use ethabi::Contract;
use ethabi::spec::{Interface, ParamType, Error as AbiError};
use heck::SnakeCase;

extern crate ethabi;
extern crate heck;

use ethabi::{Contract, ParamType};
use heck::SnakeCase;

/// Errors in generation.
#[derive(Debug)]
pub enum Error {
/// Bad ABI.
Abi(AbiError),
Abi(ethabi::Error),
/// Unsupported parameter type in given function.
UnsupportedType(String, ParamType),
}
Expand All @@ -41,13 +40,13 @@ pub enum Error {
/// a struct which can be used to call it.
// TODO: make this a proc macro when that's possible.
pub fn generate_module(struct_name: &str, abi: &str) -> Result<String, Error> {
let contract = Contract::new(Interface::load(abi.as_bytes()).map_err(Error::Abi)?);
let contract = Contract::load(abi.as_bytes()).map_err(Error::Abi)?;
let functions = generate_functions(&contract)?;

Ok(format!(r##"
use byteorder::{{BigEndian, ByteOrder}};
use futures::{{future, Future, IntoFuture}};
use ethabi::{{Contract, Interface, Token, Event}};
use ethabi::{{Contract, Token, Event}};
use bigint;

type BoxFuture<A, B> = Box<Future<Item = A, Error = B> + Send>;
Expand All @@ -66,8 +65,8 @@ impl {name} {{
/// Create a new instance of `{name}` with an address.
/// Calls can be made, given a callback for dispatching calls asynchronously.
pub fn new(address: bigint::prelude::H160) -> Self {{
let contract = Contract::new(Interface::load(ABI.as_bytes())
.expect("ABI checked at generation-time; qed"));
let contract = Contract::load(ABI.as_bytes())
.expect("ABI checked at generation-time; qed");
{name} {{
contract: contract,
address: address,
Expand All @@ -92,16 +91,16 @@ impl {name} {{
fn generate_functions(contract: &Contract) -> Result<String, Error> {
let mut functions = String::new();
for function in contract.functions() {
let name = function.name();
let name = &function.name;
let snake_name = name.to_snake_case();
let inputs = function.input_params();
let outputs = function.output_params();
let inputs: Vec<_> = function.inputs.iter().map(|i| i.kind.clone()).collect();
let outputs: Vec<_> = function.outputs.iter().map(|i| i.kind.clone()).collect();

let (input_params, to_tokens) = input_params_codegen(&inputs)
.map_err(|bad_type| Error::UnsupportedType(name.into(), bad_type))?;
.map_err(|bad_type| Error::UnsupportedType(name.clone(), bad_type))?;

let (output_type, decode_outputs) = output_params_codegen(&outputs)
.map_err(|bad_type| Error::UnsupportedType(name.into(), bad_type))?;
.map_err(|bad_type| Error::UnsupportedType(name.clone(), bad_type))?;

functions.push_str(&format!(r##"
/// Call the function "{abi_name}" on the contract.
Expand All @@ -115,17 +114,17 @@ pub fn {snake_name}<F, U>(&self, call: F, {params}) -> BoxFuture<{output_type},
U::Future: Send + 'static
{{
let function = self.contract.function(r#"{abi_name}"#)
.expect("function existence checked at compile-time; qed");
.expect("function existence checked at compile-time; qed").clone();
let call_addr = self.address;

let call_future = match function.encode_call({to_tokens}) {{
let call_future = match function.encode_input(&{to_tokens}) {{
Ok(call_data) => (call)(call_addr, call_data),
Err(e) => return Box::new(future::err(format!("Error encoding call: {{:?}}", e))),
}};

Box::new(call_future
.into_future()
.and_then(move |out| function.decode_output(out).map_err(|e| format!("{{:?}}", e)))
.and_then(move |out| function.decode_output(&out).map_err(|e| format!("{{:?}}", e)))
.map(Vec::into_iter)
.and_then(|mut outputs| {decode_outputs}))
}}
Expand Down Expand Up @@ -325,7 +324,7 @@ fn detokenize(name: &str, output_type: ParamType) -> String {

#[cfg(test)]
mod tests {
use ethabi::spec::ParamType;
use ethabi::ParamType;

#[test]
fn input_types() {
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/engines/validator_set/safe_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl ValidatorSafeContract {
.filter(move |l| check_log(l))
.filter_map(|log| {
let topics = log.topics.iter().map(|x| x.0.clone()).collect();
event.decode_log(topics, log.data.clone()).ok()
event.parse_log((topics, log.data.clone()).into()).ok()
});

match decoded_events.next() {
Expand All @@ -285,7 +285,7 @@ impl ValidatorSafeContract {

// decode log manually until the native contract generator is
// good enough to do it for us.
let validators_token = &matched_event[1].value;
let validators_token = &matched_event.params[1].value;

let validators = validators_token.clone().to_array()
.and_then(|a| a.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion hash-fetch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ native-contracts = { path = "../ethcore/native_contracts" }
hash = { path = "../util/hash" }

[dev-dependencies]
ethabi = "2.0"
ethabi = "4.0"
parking_lot = "0.4"
4 changes: 2 additions & 2 deletions hash-fetch/src/urlhint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ pub mod tests {
// given
let registrar = FakeRegistrar::new();
let resolve_result = {
use ethabi::{Encoder, Token};
Encoder::encode(vec![Token::String(String::new()), Token::FixedBytes(vec![0; 20]), Token::Address([0; 20])])
use ethabi::{encode, Token};
encode(&[Token::String(String::new()), Token::FixedBytes(vec![0; 20]), Token::Address([0; 20])])
};
registrar.responses.lock()[1] = Ok(resolve_result);

Expand Down
1 change: 0 additions & 1 deletion secret_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ tokio-io = "0.1.0"
tokio-service = "0.1"
tokio-proto = "0.1"
url = "1.0"
ethabi = "2.0"
ethcore = { path = "../ethcore" }
ethcore-bytes = { path = "../util/bytes" }
ethcore-devtools = { path = "../devtools" }
Expand Down
1 change: 0 additions & 1 deletion secret_store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ extern crate tokio_service;
extern crate tokio_proto;
extern crate url;

extern crate ethabi;
extern crate ethcore;
extern crate ethcore_devtools as devtools;
extern crate ethcore_bytes as bytes;
Expand Down
2 changes: 1 addition & 1 deletion updater/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ethcore-ipc-codegen = { path = "../ipc/codegen" }

[dependencies]
log = "0.3"
ethabi = "2.0"
ethabi = "4.0"
target_info = "0.1"
ethcore = { path = "../ethcore" }
ethsync = { path = "../sync" }
Expand Down