diff --git a/Cargo.lock b/Cargo.lock index cc8c7d3c7..92d3bd5c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1580,7 +1580,7 @@ version = "0.1.0" dependencies = [ "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethcore-util 1.8.0", + "ethcore-bigint 0.1.3", "futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "native-contract-generator 0.1.0", ] diff --git a/ethcore/native_contracts/Cargo.toml b/ethcore/native_contracts/Cargo.toml index 5dc18c8f5..2f91a4848 100644 --- a/ethcore/native_contracts/Cargo.toml +++ b/ethcore/native_contracts/Cargo.toml @@ -9,7 +9,7 @@ build = "build.rs" ethabi = "2.0" futures = "0.1" byteorder = "1.0" -ethcore-util = { path = "../../util" } +ethcore-bigint = { path = "../../util/bigint" } [build-dependencies] native-contract-generator = { path = "generator" } diff --git a/ethcore/native_contracts/generator/src/lib.rs b/ethcore/native_contracts/generator/src/lib.rs index 793ad6085..996ee4969 100644 --- a/ethcore/native_contracts/generator/src/lib.rs +++ b/ethcore/native_contracts/generator/src/lib.rs @@ -15,7 +15,7 @@ // along with Parity. If not, see . //! Rust code contract generator. -//! The code generated will require a dependence on the `ethcore-util`, +//! The code generated will require a dependence on the `ethcore-bigint::prelude`, //! `ethabi`, `byteorder`, and `futures` crates. //! This currently isn't hygienic, so compilation of generated code may fail //! due to missing crates or name collisions. This will change when @@ -48,14 +48,14 @@ pub fn generate_module(struct_name: &str, abi: &str) -> Result { use byteorder::{{BigEndian, ByteOrder}}; use futures::{{future, Future, IntoFuture, BoxFuture}}; use ethabi::{{Contract, Interface, Token, Event}}; -use util; +use bigint; /// Generated Rust bindings to an Ethereum contract. #[derive(Clone, Debug)] pub struct {name} {{ contract: Contract, /// Address to make calls to. - pub address: util::Address, + pub address: bigint::prelude::H160, }} const ABI: &'static str = r#"{abi_str}"#; @@ -63,7 +63,7 @@ const ABI: &'static str = r#"{abi_str}"#; 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: util::Address) -> Self {{ + pub fn new(address: bigint::prelude::H160) -> Self {{ let contract = Contract::new(Interface::load(ABI.as_bytes()) .expect("ABI checked at generation-time; qed")); {name} {{ @@ -108,7 +108,7 @@ fn generate_functions(contract: &Contract) -> Result { /// Outputs: {abi_outputs:?} pub fn {snake_name}(&self, call: F, {params}) -> BoxFuture<{output_type}, String> where - F: FnOnce(util::Address, Vec) -> U, + F: FnOnce(bigint::prelude::H160, Vec) -> U, U: IntoFuture, Error=String>, U::Future: Send + 'static {{ @@ -217,8 +217,8 @@ fn output_params_codegen(outputs: &[ParamType]) -> Result<(String, String), Para // create code for an argument type from param type. fn rust_type(input: ParamType) -> Result { Ok(match input { - ParamType::Address => "util::Address".into(), - ParamType::FixedBytes(len) if len <= 32 => format!("util::H{}", len * 8), + ParamType::Address => "bigint::prelude::H160".into(), + ParamType::FixedBytes(len) if len <= 32 => format!("bigint::prelude::H{}", len * 8), ParamType::Bytes | ParamType::FixedBytes(_) => "Vec".into(), ParamType::Int(width) => match width { 8 | 16 | 32 | 64 => format!("i{}", width), @@ -226,7 +226,7 @@ fn rust_type(input: ParamType) -> Result { }, ParamType::Uint(width) => match width { 8 | 16 | 32 | 64 => format!("u{}", width), - 128 | 160 | 256 => format!("util::U{}", width), + 128 | 160 | 256 => format!("bigint::prelude::U{}", width), _ => return Err(ParamType::Uint(width)), }, ParamType::Bool => "bool".into(), @@ -259,8 +259,8 @@ fn tokenize(name: &str, input: ParamType) -> (bool, String) { }, ParamType::Uint(width) => format!( "let mut r = [0; 32]; {}.to_big_endian(&mut r); Token::Uint(r)", - if width <= 64 { format!("util::U256::from({} as u64)", name) } - else { format!("util::U256::from({})", name) } + if width <= 64 { format!("bigint::prelude::U256::from({} as u64)", name) } + else { format!("bigint::prelude::U256::from({})", name) } ), ParamType::Bool => format!("Token::Bool({})", name), ParamType::String => format!("Token::String({})", name), @@ -281,11 +281,11 @@ fn tokenize(name: &str, input: ParamType) -> (bool, String) { // panics on unsupported types. fn detokenize(name: &str, output_type: ParamType) -> String { match output_type { - ParamType::Address => format!("{}.to_address().map(util::H160)", name), + ParamType::Address => format!("{}.to_address().map(bigint::prelude::H160)", name), ParamType::Bytes => format!("{}.to_bytes()", name), ParamType::FixedBytes(len) if len <= 32 => { // ensure no panic on slice too small. - let read_hash = format!("b.resize({}, 0); util::H{}::from_slice(&b[..{}])", + let read_hash = format!("b.resize({}, 0); bigint::prelude::H{}::from_slice(&b[..{}])", len, len * 8, len); format!("{}.to_fixed_bytes().map(|mut b| {{ {} }})", @@ -302,8 +302,8 @@ fn detokenize(name: &str, output_type: ParamType) -> String { } ParamType::Uint(width) => { let read_uint = match width { - 8 | 16 | 32 | 64 => format!("util::U256(u).low_u64() as u{}", width), - _ => format!("util::U{}::from(&u[..])", width), + 8 | 16 | 32 | 64 => format!("bigint::prelude::U256(u).low_u64() as u{}", width), + _ => format!("bigint::prelude::U{}::from(&u[..])", width), }; format!("{}.to_uint().map(|u| {})", name, read_uint) @@ -328,30 +328,30 @@ mod tests { #[test] fn input_types() { assert_eq!(::input_params_codegen(&[]).unwrap().0, ""); - assert_eq!(::input_params_codegen(&[ParamType::Address]).unwrap().0, "param_0: util::Address, "); + assert_eq!(::input_params_codegen(&[ParamType::Address]).unwrap().0, "param_0: bigint::prelude::H160, "); assert_eq!(::input_params_codegen(&[ParamType::Address, ParamType::Bytes]).unwrap().0, - "param_0: util::Address, param_1: Vec, "); + "param_0: bigint::prelude::H160, param_1: Vec, "); } #[test] fn output_types() { assert_eq!(::output_params_codegen(&[]).unwrap().0, "()"); - assert_eq!(::output_params_codegen(&[ParamType::Address]).unwrap().0, "(util::Address)"); + assert_eq!(::output_params_codegen(&[ParamType::Address]).unwrap().0, "(bigint::prelude::H160)"); assert_eq!(::output_params_codegen(&[ParamType::Address, ParamType::Array(Box::new(ParamType::Bytes))]).unwrap().0, - "(util::Address, Vec>)"); + "(bigint::prelude::H160, Vec>)"); } #[test] fn rust_type() { - assert_eq!(::rust_type(ParamType::FixedBytes(32)).unwrap(), "util::H256"); + assert_eq!(::rust_type(ParamType::FixedBytes(32)).unwrap(), "bigint::prelude::H256"); assert_eq!(::rust_type(ParamType::Array(Box::new(ParamType::FixedBytes(32)))).unwrap(), - "Vec"); + "Vec"); assert_eq!(::rust_type(ParamType::Uint(64)).unwrap(), "u64"); assert!(::rust_type(ParamType::Uint(63)).is_err()); assert_eq!(::rust_type(ParamType::Int(32)).unwrap(), "i32"); - assert_eq!(::rust_type(ParamType::Uint(256)).unwrap(), "util::U256"); + assert_eq!(::rust_type(ParamType::Uint(256)).unwrap(), "bigint::prelude::U256"); } // codegen tests will need bootstrapping of some kind. diff --git a/ethcore/native_contracts/src/lib.rs b/ethcore/native_contracts/src/lib.rs index e35a4ec19..9b73ace79 100644 --- a/ethcore/native_contracts/src/lib.rs +++ b/ethcore/native_contracts/src/lib.rs @@ -21,7 +21,7 @@ extern crate futures; extern crate byteorder; extern crate ethabi; -extern crate ethcore_util as util; +extern crate ethcore_bigint as bigint; mod registry; mod urlhint;