updated ethabi to version 4.0 (#6742)
* updated ethabi to version 4.0 * ethabi 4.0.1
This commit is contained in:
parent
9fa639ede9
commit
8365f4d80e
14
Cargo.lock
generated
14
Cargo.lock
generated
@ -542,9 +542,10 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ethabi"
|
||||
version = "2.0.0"
|
||||
version = "4.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -829,7 +830,6 @@ name = "ethcore-secretstore"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethabi 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore 1.9.0",
|
||||
"ethcore-bigint 0.1.3",
|
||||
"ethcore-bytes 0.1.0",
|
||||
@ -1813,7 +1813,7 @@ dependencies = [
|
||||
name = "native-contract-generator"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ethabi 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethabi 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"heck 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -1822,7 +1822,7 @@ name = "native-contracts"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethabi 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethabi 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore-bigint 0.1.3",
|
||||
"futures 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"native-contract-generator 0.1.0",
|
||||
@ -2199,7 +2199,7 @@ dependencies = [
|
||||
name = "parity-hash-fetch"
|
||||
version = "1.9.0"
|
||||
dependencies = [
|
||||
"ethabi 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethabi 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore-bigint 0.1.3",
|
||||
"ethcore-bytes 0.1.0",
|
||||
"ethcore-util 1.9.0",
|
||||
@ -2385,7 +2385,7 @@ dependencies = [
|
||||
name = "parity-updater"
|
||||
version = "1.9.0"
|
||||
dependencies = [
|
||||
"ethabi 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethabi 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethcore 1.9.0",
|
||||
"ethcore-bigint 0.1.3",
|
||||
"ethcore-bytes 0.1.0",
|
||||
@ -3709,7 +3709,7 @@ dependencies = [
|
||||
"checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3"
|
||||
"checksum error-chain 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd5c82c815138e278b8dcdeffc49f27ea6ffb528403e9dea4194f2e3dd40b143"
|
||||
"checksum eth-secp256k1 0.5.6 (git+https://github.com/paritytech/rust-secp256k1)" = "<none>"
|
||||
"checksum ethabi 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0c3d62319ee0f35abf20afe8859dd2668195912614346447bb2dee9fb8da7c62"
|
||||
"checksum ethabi 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c819a3adef0413a2519cbd9a19a35dd1c20c7a0110705beaba8aa4aa87eda95f"
|
||||
"checksum fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b1ee15a7050e5580b3712877157068ea713b245b080ff302ae2ca973cfcd9baa"
|
||||
"checksum flate2 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "e6234dd4468ae5d1e2dbb06fe2b058696fdc50a339c68a393aefbf00bc81e423"
|
||||
"checksum fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6cc484842f1e2884faf56f529f960cc12ad8c71ce96cc7abba0a067c98fee344"
|
||||
|
@ -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" }
|
||||
|
@ -5,5 +5,5 @@ version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
ethabi = "2.0"
|
||||
ethabi = "4.0"
|
||||
heck = "0.2"
|
||||
|
@ -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),
|
||||
}
|
||||
@ -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>;
|
||||
@ -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,
|
||||
@ -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.
|
||||
@ -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}))
|
||||
}}
|
||||
@ -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() {
|
||||
|
@ -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() {
|
||||
@ -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()
|
||||
|
@ -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"
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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" }
|
||||
|
@ -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;
|
||||
|
@ -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" }
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user