Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target
*.swp
*.swo
.vscode
211 changes: 128 additions & 83 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ serde = "1.0"
serde_derive = "1.0"
docopt = "0.8.1"
ethabi = { version = "5", path = "../ethabi" }
error-chain = { version = "0.11.0", default-features = false }
error-chain = { version = "0.12.0", default-features = false }

[features]
backtrace = ["error-chain/backtrace"]
Expand Down
2 changes: 1 addition & 1 deletion contract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ethabi-contract"
version = "5.1.0"
version = "5.1.1"
authors = ["Parity Technologies <admin@parity.io>"]
homepage = "https://github.com/paritytech/ethabi"
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ethabi-derive"
version = "5.1.0"
version = "5.1.3"
authors = ["Parity Technologies <admin@parity.io>"]
homepage = "https://github.com/paritytech/ethabi"
license = "MIT"
Expand All @@ -11,7 +11,7 @@ description = "Easy to use conversion of ethereum contract calls to bytecode."
proc-macro = true

[dependencies]
ethabi = { path = "../ethabi", version = "5.0" }
ethabi = { path = "../ethabi", version = "5.1" }
heck = "0.3"
syn = "0.12.12"
quote = "0.4.2"
4 changes: 2 additions & 2 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ fn template_param_type(input: &ParamType, index: usize) -> quote::Tokens {
ParamType::Int(_) => quote! { #t_ident: Into<ethabi::Int> },
ParamType::Uint(_) => quote! { #t_ident: Into<ethabi::Uint> },
ParamType::Bool => quote! { #t_ident: Into<bool> },
ParamType::String => quote! { T{}: Into<String> },
ParamType::String => quote! { #t_ident: Into<String> },
ParamType::Array(ref kind) => {
let t = rust_type(&*kind);
quote! {
Expand Down Expand Up @@ -300,7 +300,7 @@ fn from_token(kind: &ParamType, token: &quote::Tokens) -> quote::Tokens {
}
},
ParamType::FixedBytes(size) => {
let size: syn::Ident = format!("{}", size).into();
let size: syn::Index = size.into();
quote! {
{
let mut result = [0u8; #size];
Expand Down
13 changes: 8 additions & 5 deletions ethabi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
[package]
name = "ethabi"
version = "5.1.1"
version = "5.1.2"
authors = ["Parity Technologies <admin@parity.io>"]
homepage = "https://github.com/paritytech/ethabi"
license = "MIT"
keywords = ["ethereum", "eth", "abi", "solidity", "cli"]
description = "Easy to use conversion of ethereum contract calls to bytecode."

[dependencies]
rustc-hex = "1.0"
rustc-hex = "2.0"
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
tiny-keccak = "1.3"
error-chain = { version = "0.11", default-features = false }
ethereum-types = "0.3"
tiny-keccak = "1.4.2"
error-chain = { version = "0.12", default-features = false }
ethereum-types = "0.4"

[dev-dependencies]
hex-literal = "0.1.1"

[features]
backtrace = ["error-chain/backtrace"]
Expand Down
177 changes: 94 additions & 83 deletions ethabi/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,11 @@ fn decode_param(param: &ParamType, slices: &[[u8; 32]], offset: usize) -> Result

#[cfg(test)]
mod tests {
use hex::FromHex;
use {decode, Token, ParamType};

#[test]
fn decode_address() {
let encoded = "0000000000000000000000001111111111111111111111111111111111111111".from_hex().unwrap();
let encoded = hex!("0000000000000000000000001111111111111111111111111111111111111111");
let address = Token::Address([0x11u8; 20].into());
let expected = vec![address];
let decoded = decode(&[ParamType::Address], &encoded).unwrap();
Expand All @@ -219,9 +218,10 @@ mod tests {

#[test]
fn decode_two_address() {
let encoded = ("".to_owned() +
"0000000000000000000000001111111111111111111111111111111111111111" +
"0000000000000000000000002222222222222222222222222222222222222222").from_hex().unwrap();
let encoded = hex!("
0000000000000000000000001111111111111111111111111111111111111111
0000000000000000000000002222222222222222222222222222222222222222
");
let address1 = Token::Address([0x11u8; 20].into());
let address2 = Token::Address([0x22u8; 20].into());
let expected = vec![address1, address2];
Expand All @@ -231,9 +231,10 @@ mod tests {

#[test]
fn decode_fixed_array_of_addresses() {
let encoded = ("".to_owned() +
"0000000000000000000000001111111111111111111111111111111111111111" +
"0000000000000000000000002222222222222222222222222222222222222222").from_hex().unwrap();
let encoded = hex!("
0000000000000000000000001111111111111111111111111111111111111111
0000000000000000000000002222222222222222222222222222222222222222
");
let address1 = Token::Address([0x11u8; 20].into());
let address2 = Token::Address([0x22u8; 20].into());
let expected = vec![Token::FixedArray(vec![address1, address2])];
Expand All @@ -243,7 +244,7 @@ mod tests {

#[test]
fn decode_uint() {
let encoded = "1111111111111111111111111111111111111111111111111111111111111111".from_hex().unwrap();
let encoded = hex!("1111111111111111111111111111111111111111111111111111111111111111");
let uint = Token::Uint([0x11u8; 32].into());
let expected = vec![uint];
let decoded = decode(&[ParamType::Uint(32)], &encoded).unwrap();
Expand All @@ -252,7 +253,7 @@ mod tests {

#[test]
fn decode_int() {
let encoded = "1111111111111111111111111111111111111111111111111111111111111111".from_hex().unwrap();
let encoded = hex!("1111111111111111111111111111111111111111111111111111111111111111");
let int = Token::Int([0x11u8; 32].into());
let expected = vec![int];
let decoded = decode(&[ParamType::Int(32)], &encoded).unwrap();
Expand All @@ -261,11 +262,12 @@ mod tests {

#[test]
fn decode_dynamic_array_of_addresses() {
let encoded = ("".to_owned() +
"0000000000000000000000000000000000000000000000000000000000000020" +
"0000000000000000000000000000000000000000000000000000000000000002" +
"0000000000000000000000001111111111111111111111111111111111111111" +
"0000000000000000000000002222222222222222222222222222222222222222").from_hex().unwrap();
let encoded = hex!("
0000000000000000000000000000000000000000000000000000000000000020
0000000000000000000000000000000000000000000000000000000000000002
0000000000000000000000001111111111111111111111111111111111111111
0000000000000000000000002222222222222222222222222222222222222222
");
let address1 = Token::Address([0x11u8; 20].into());
let address2 = Token::Address([0x22u8; 20].into());
let addresses = Token::Array(vec![address1, address2]);
Expand All @@ -276,13 +278,14 @@ mod tests {

#[test]
fn decode_dynamic_array_of_fixed_arrays() {
let encoded = ("".to_owned() +
"0000000000000000000000000000000000000000000000000000000000000020" +
"0000000000000000000000000000000000000000000000000000000000000002" +
"0000000000000000000000001111111111111111111111111111111111111111" +
"0000000000000000000000002222222222222222222222222222222222222222" +
"0000000000000000000000003333333333333333333333333333333333333333" +
"0000000000000000000000004444444444444444444444444444444444444444").from_hex().unwrap();
let encoded = hex!("
0000000000000000000000000000000000000000000000000000000000000020
0000000000000000000000000000000000000000000000000000000000000002
0000000000000000000000001111111111111111111111111111111111111111
0000000000000000000000002222222222222222222222222222222222222222
0000000000000000000000003333333333333333333333333333333333333333
0000000000000000000000004444444444444444444444444444444444444444
");
let address1 = Token::Address([0x11u8; 20].into());
let address2 = Token::Address([0x22u8; 20].into());
let address3 = Token::Address([0x33u8; 20].into());
Expand All @@ -301,15 +304,16 @@ mod tests {

#[test]
fn decode_dynamic_array_of_dynamic_arrays() {
let encoded = ("".to_owned() +
"0000000000000000000000000000000000000000000000000000000000000020" +
"0000000000000000000000000000000000000000000000000000000000000002" +
"0000000000000000000000000000000000000000000000000000000000000080" +
"00000000000000000000000000000000000000000000000000000000000000c0" +
"0000000000000000000000000000000000000000000000000000000000000001" +
"0000000000000000000000001111111111111111111111111111111111111111" +
"0000000000000000000000000000000000000000000000000000000000000001" +
"0000000000000000000000002222222222222222222222222222222222222222").from_hex().unwrap();
let encoded = hex!("
0000000000000000000000000000000000000000000000000000000000000020
0000000000000000000000000000000000000000000000000000000000000002
0000000000000000000000000000000000000000000000000000000000000080
00000000000000000000000000000000000000000000000000000000000000c0
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000001111111111111111111111111111111111111111
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000002222222222222222222222222222222222222222
");

let address1 = Token::Address([0x11u8; 20].into());
let address2 = Token::Address([0x22u8; 20].into());
Expand All @@ -327,17 +331,18 @@ mod tests {

#[test]
fn decode_dynamic_array_of_dynamic_arrays2() {
let encoded = ("".to_owned() +
"0000000000000000000000000000000000000000000000000000000000000020" +
"0000000000000000000000000000000000000000000000000000000000000002" +
"0000000000000000000000000000000000000000000000000000000000000080" +
"00000000000000000000000000000000000000000000000000000000000000e0" +
"0000000000000000000000000000000000000000000000000000000000000002" +
"0000000000000000000000001111111111111111111111111111111111111111" +
"0000000000000000000000002222222222222222222222222222222222222222" +
"0000000000000000000000000000000000000000000000000000000000000002" +
"0000000000000000000000003333333333333333333333333333333333333333" +
"0000000000000000000000004444444444444444444444444444444444444444").from_hex().unwrap();
let encoded = hex!("
0000000000000000000000000000000000000000000000000000000000000020
0000000000000000000000000000000000000000000000000000000000000002
0000000000000000000000000000000000000000000000000000000000000080
00000000000000000000000000000000000000000000000000000000000000e0
0000000000000000000000000000000000000000000000000000000000000002
0000000000000000000000001111111111111111111111111111111111111111
0000000000000000000000002222222222222222222222222222222222222222
0000000000000000000000000000000000000000000000000000000000000002
0000000000000000000000003333333333333333333333333333333333333333
0000000000000000000000004444444444444444444444444444444444444444
");

let address1 = Token::Address([0x11u8; 20].into());
let address2 = Token::Address([0x22u8; 20].into());
Expand All @@ -357,11 +362,12 @@ mod tests {

#[test]
fn decode_fixed_array_fixed_arrays() {
let encoded = ("".to_owned() +
"0000000000000000000000001111111111111111111111111111111111111111" +
"0000000000000000000000002222222222222222222222222222222222222222" +
"0000000000000000000000003333333333333333333333333333333333333333" +
"0000000000000000000000004444444444444444444444444444444444444444").from_hex().unwrap();
let encoded = hex!("
0000000000000000000000001111111111111111111111111111111111111111
0000000000000000000000002222222222222222222222222222222222222222
0000000000000000000000003333333333333333333333333333333333333333
0000000000000000000000004444444444444444444444444444444444444444
");
let address1 = Token::Address([0x11u8; 20].into());
let address2 = Token::Address([0x22u8; 20].into());
let address3 = Token::Address([0x33u8; 20].into());
Expand All @@ -383,15 +389,16 @@ mod tests {

#[test]
fn decode_fixed_array_of_dynamic_array_of_addresses() {
let encoded = ("".to_owned() +
"0000000000000000000000000000000000000000000000000000000000000040" +
"00000000000000000000000000000000000000000000000000000000000000a0" +
"0000000000000000000000000000000000000000000000000000000000000002" +
"0000000000000000000000001111111111111111111111111111111111111111" +
"0000000000000000000000002222222222222222222222222222222222222222" +
"0000000000000000000000000000000000000000000000000000000000000002" +
"0000000000000000000000003333333333333333333333333333333333333333" +
"0000000000000000000000004444444444444444444444444444444444444444").from_hex().unwrap();
let encoded = hex!("
0000000000000000000000000000000000000000000000000000000000000040
00000000000000000000000000000000000000000000000000000000000000a0
0000000000000000000000000000000000000000000000000000000000000002
0000000000000000000000001111111111111111111111111111111111111111
0000000000000000000000002222222222222222222222222222222222222222
0000000000000000000000000000000000000000000000000000000000000002
0000000000000000000000003333333333333333333333333333333333333333
0000000000000000000000004444444444444444444444444444444444444444
");
let address1 = Token::Address([0x11u8; 20].into());
let address2 = Token::Address([0x22u8; 20].into());
let address3 = Token::Address([0x33u8; 20].into());
Expand All @@ -413,8 +420,7 @@ mod tests {

#[test]
fn decode_fixed_bytes() {
let encoded = ("".to_owned() +
"1234000000000000000000000000000000000000000000000000000000000000").from_hex().unwrap();
let encoded = hex!("1234000000000000000000000000000000000000000000000000000000000000");
let bytes = Token::FixedBytes(vec![0x12, 0x34]);
let expected = vec![bytes];
let decoded = decode(&[ParamType::FixedBytes(2)], &encoded).unwrap();
Expand All @@ -423,10 +429,11 @@ mod tests {

#[test]
fn decode_bytes() {
let encoded = ("".to_owned() +
"0000000000000000000000000000000000000000000000000000000000000020" +
"0000000000000000000000000000000000000000000000000000000000000002" +
"1234000000000000000000000000000000000000000000000000000000000000").from_hex().unwrap();
let encoded = hex!("
0000000000000000000000000000000000000000000000000000000000000020
0000000000000000000000000000000000000000000000000000000000000002
1234000000000000000000000000000000000000000000000000000000000000
");
let bytes = Token::Bytes(vec![0x12, 0x34]);
let expected = vec![bytes];
let decoded = decode(&[ParamType::Bytes], &encoded).unwrap();
Expand All @@ -435,41 +442,45 @@ mod tests {

#[test]
fn decode_bytes2() {
let encoded = ("".to_owned() +
"0000000000000000000000000000000000000000000000000000000000000020" +
"0000000000000000000000000000000000000000000000000000000000000040" +
"1000000000000000000000000000000000000000000000000000000000000000" +
"1000000000000000000000000000000000000000000000000000000000000000").from_hex().unwrap();
let bytes = Token::Bytes(("".to_owned() +
"1000000000000000000000000000000000000000000000000000000000000000" +
"1000000000000000000000000000000000000000000000000000000000000000").from_hex().unwrap());
let encoded = hex!("
0000000000000000000000000000000000000000000000000000000000000020
0000000000000000000000000000000000000000000000000000000000000040
1000000000000000000000000000000000000000000000000000000000000000
1000000000000000000000000000000000000000000000000000000000000000
");
let bytes = Token::Bytes(hex!("
1000000000000000000000000000000000000000000000000000000000000000
1000000000000000000000000000000000000000000000000000000000000000
").to_vec());
let expected = vec![bytes];
let decoded = decode(&[ParamType::Bytes], &encoded).unwrap();
assert_eq!(decoded, expected);
}

#[test]
fn decode_two_bytes() {
let encoded = ("".to_owned() +
"0000000000000000000000000000000000000000000000000000000000000040" +
"0000000000000000000000000000000000000000000000000000000000000080" +
"000000000000000000000000000000000000000000000000000000000000001f" +
"1000000000000000000000000000000000000000000000000000000000000200" +
"0000000000000000000000000000000000000000000000000000000000000020" +
"0010000000000000000000000000000000000000000000000000000000000002").from_hex().unwrap();
let bytes1 = Token::Bytes("10000000000000000000000000000000000000000000000000000000000002".from_hex().unwrap());
let bytes2 = Token::Bytes("0010000000000000000000000000000000000000000000000000000000000002".from_hex().unwrap());
let encoded = hex!("
0000000000000000000000000000000000000000000000000000000000000040
0000000000000000000000000000000000000000000000000000000000000080
000000000000000000000000000000000000000000000000000000000000001f
1000000000000000000000000000000000000000000000000000000000000200
0000000000000000000000000000000000000000000000000000000000000020
0010000000000000000000000000000000000000000000000000000000000002
");
let bytes1 = Token::Bytes(hex!("10000000000000000000000000000000000000000000000000000000000002").to_vec());
let bytes2 = Token::Bytes(hex!("0010000000000000000000000000000000000000000000000000000000000002").to_vec());
let expected = vec![bytes1, bytes2];
let decoded = decode(&[ParamType::Bytes, ParamType::Bytes], &encoded).unwrap();
assert_eq!(decoded, expected);
}

#[test]
fn decode_string() {
let encoded = ("".to_owned() +
"0000000000000000000000000000000000000000000000000000000000000020" +
"0000000000000000000000000000000000000000000000000000000000000009" +
"6761766f66796f726b0000000000000000000000000000000000000000000000").from_hex().unwrap();
let encoded = hex!("
0000000000000000000000000000000000000000000000000000000000000020
0000000000000000000000000000000000000000000000000000000000000009
6761766f66796f726b0000000000000000000000000000000000000000000000
");
let s = Token::String("gavofyork".to_owned());
let expected = vec![s];
let decoded = decode(&[ParamType::String], &encoded).unwrap();
Expand Down
Loading