Skip to content

Commit

Permalink
Update to latest ethereum-types and reformat with max-width 120 (#211)
Browse files Browse the repository at this point in the history
* Bump ethereum types.

* Update ethereum-types and reformat.

* Fix tests.
  • Loading branch information
tomusdrw authored Apr 11, 2019
1 parent 5503acb commit 91639ff
Show file tree
Hide file tree
Showing 41 changed files with 899 additions and 379 deletions.
47 changes: 23 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "web3"
version = "0.6.0"
version = "0.7.0"
description = "Ethereum JSON-RPC client."
homepage = "https://github.com/tomusdrw/rust-web3"
repository = "https://github.com/tomusdrw/rust-web3"
Expand All @@ -12,34 +12,33 @@ readme = "README.md"
edition = "2018"

[dependencies]
arrayvec = "0.4"
ethabi = "6.0"
ethereum-types = "0.4"
futures = "0.1"
jsonrpc-core = "8.0.1"
log = "0.4"
parking_lot = "0.7"
rustc-hex = "1.0"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
arrayvec = "0.4.10"
ethabi = "7.0.0"
ethereum-types = "0.5.2"
futures = "0.1.26"
jsonrpc-core = "11.0.0"
log = "0.4.6"
parking_lot = "0.7.1"
rustc-hex = "2.0.1"
serde = { version="1.0.90", features = ["derive"] }
serde_json = "1.0.39"
tokio-timer = "0.1"
url = "1.7"
base64 = "0.10"
derive_more = "0.14"
url = "1.7.2"
base64 = "0.10.1"
derive_more = "0.14.0"
# Optional deps
hyper = { version = "0.12", optional = true }
hyper-tls = { version = "0.3", optional = true }
native-tls = { version = "0.2", optional = true }
tokio-core = { version = "0.1", optional = true }
tokio-io = { version = "0.1", optional = true }
tokio-uds = { version = "0.1", optional = true }
websocket = { version = "0.21", optional = true }
hyper = { version = "0.12.25", optional = true }
hyper-tls = { version = "0.3.2", optional = true }
native-tls = { version = "0.2.2", optional = true }
tokio-core = { version = "0.1.17", optional = true }
tokio-io = { version = "0.1.12", optional = true }
tokio-uds = { version = "0.1.0", optional = true }
websocket = { version = "0.21.1", optional = true }

[dev-dependencies]
# For examples
tokio-core = "0.1"
rustc-hex = "1.0"
tokio-core = "0.1.17"
rustc-hex = "2.0.1"
env_logger = "0.6.0"

[features]
Expand Down
4 changes: 3 additions & 1 deletion examples/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ fn main() {
let mut event_loop = tokio_core::reactor::Core::new().unwrap();
let remote = event_loop.remote();

let http = web3::transports::Http::with_event_loop("http://localhost:8545", &event_loop.handle(), MAX_PARALLEL_REQUESTS).unwrap();
let http =
web3::transports::Http::with_event_loop("http://localhost:8545", &event_loop.handle(), MAX_PARALLEL_REQUESTS)
.unwrap();

let web3 = web3::Web3::new(web3::transports::Batch::new(http));
let _ = web3.eth().accounts();
Expand Down
13 changes: 11 additions & 2 deletions examples/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ fn main() {
opt.gas_price = Some(5.into());
opt.gas = Some(1_000_000.into());
}))
.execute(bytecode, (U256::from(1_000_000), "My Token".to_owned(), 3u64, "MT".to_owned()), my_account)
.execute(
bytecode,
(U256::from(1_000_000), "My Token".to_owned(), 3u64, "MT".to_owned()),
my_account,
)
.expect("Correct parameters are passed to the constructor.")
.wait()
.unwrap();
Expand All @@ -35,7 +39,12 @@ fn main() {

// Accessing existing contract
let contract_address = contract.address();
let contract = Contract::from_json(web3.eth(), contract_address, include_bytes!("../src/contract/res/token.json")).unwrap();
let contract = Contract::from_json(
web3.eth(),
contract_address,
include_bytes!("../src/contract/res/token.json"),
)
.unwrap();

let result = contract.query("balanceOf", (my_account,), None, Options::default(), None);
let balance_of: U256 = result.wait().unwrap();
Expand Down
5 changes: 4 additions & 1 deletion examples/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const MAX_PARALLEL_REQUESTS: usize = 64;
fn main() {
let mut event_loop = tokio_core::reactor::Core::new().unwrap();

let web3 = web3::Web3::new(web3::transports::Http::with_event_loop("http://localhost:8545", &event_loop.handle(), MAX_PARALLEL_REQUESTS).unwrap());
let web3 = web3::Web3::new(
web3::transports::Http::with_event_loop("http://localhost:8545", &event_loop.handle(), MAX_PARALLEL_REQUESTS)
.unwrap(),
);
let accounts = web3.eth().accounts().map(|accounts| {
println!("Accounts: {:?}", accounts);
});
Expand Down
62 changes: 41 additions & 21 deletions examples/simple_log_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use web3::types::FilterBuilder;

fn main() {
let mut eloop = tokio_core::reactor::Core::new().unwrap();
let web3 = web3::Web3::new(web3::transports::Http::with_event_loop("http://localhost:8545", &eloop.handle(), 1).unwrap());
let web3 =
web3::Web3::new(web3::transports::Http::with_event_loop("http://localhost:8545", &eloop.handle(), 1).unwrap());

// Get the contract bytecode for instance from Solidity compiler
let bytecode: Vec<u8> = include_str!("./build/SimpleEvent.bin").from_hex().unwrap();
Expand All @@ -20,31 +21,50 @@ fn main() {
let accounts = accounts.unwrap();
println!("accounts: {:?}", &accounts);

Contract::deploy(web3.eth(), include_bytes!("./build/SimpleEvent.abi")).unwrap().confirmations(1).poll_interval(time::Duration::from_secs(10)).options(Options::with(|opt| opt.gas = Some(3_000_000.into()))).execute(bytecode, (), accounts[0]).unwrap().then(move |contract| {
let contract = contract.unwrap();
println!("contract deployed at: {}", contract.address());
Contract::deploy(web3.eth(), include_bytes!("./build/SimpleEvent.abi"))
.unwrap()
.confirmations(1)
.poll_interval(time::Duration::from_secs(10))
.options(Options::with(|opt| opt.gas = Some(3_000_000.into())))
.execute(bytecode, (), accounts[0])
.unwrap()
.then(move |contract| {
let contract = contract.unwrap();
println!("contract deployed at: {}", contract.address());

// Filter for Hello event in our contract
let filter = FilterBuilder::default().address(vec![contract.address()]).topics(Some(vec!["0xd282f389399565f3671145f5916e51652b60eee8e5c759293a2f5771b8ddfd2e".into()]), None, None, None).build();
// Filter for Hello event in our contract
let filter = FilterBuilder::default()
.address(vec![contract.address()])
.topics(
Some(vec![
"0xd282f389399565f3671145f5916e51652b60eee8e5c759293a2f5771b8ddfd2e"
.parse()
.unwrap(),
]),
None,
None,
None,
)
.build();

let event_future = web3
.eth_filter()
.create_logs_filter(filter)
.then(|filter| {
filter.unwrap().stream(time::Duration::from_secs(0)).for_each(|log| {
println!("got log: {:?}", log);
Ok(())
let event_future = web3
.eth_filter()
.create_logs_filter(filter)
.then(|filter| {
filter.unwrap().stream(time::Duration::from_secs(0)).for_each(|log| {
println!("got log: {:?}", log);
Ok(())
})
})
})
.map_err(|_| ());
.map_err(|_| ());

let call_future = contract.call("hello", (), accounts[0], Options::default()).then(|tx| {
println!("got tx: {:?}", tx);
Ok(())
});
let call_future = contract.call("hello", (), accounts[0], Options::default()).then(|tx| {
println!("got tx: {:?}", tx);
Ok(())
});

event_future.join(call_future)
})
event_future.join(call_future)
})
}))
.unwrap();
}
62 changes: 41 additions & 21 deletions examples/simple_log_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use web3::types::FilterBuilder;

fn main() {
let mut eloop = tokio_core::reactor::Core::new().unwrap();
let web3 = web3::Web3::new(web3::transports::WebSocket::with_event_loop("ws://localhost:8546", &eloop.handle()).unwrap());
let web3 =
web3::Web3::new(web3::transports::WebSocket::with_event_loop("ws://localhost:8546", &eloop.handle()).unwrap());

// Get the contract bytecode for instance from Solidity compiler
let bytecode: Vec<u8> = include_str!("./build/SimpleEvent.bin").from_hex().unwrap();
Expand All @@ -20,31 +21,50 @@ fn main() {
let accounts = accounts.unwrap();
println!("accounts: {:?}", &accounts);

Contract::deploy(web3.eth(), include_bytes!("./build/SimpleEvent.abi")).unwrap().confirmations(1).poll_interval(time::Duration::from_secs(10)).options(Options::with(|opt| opt.gas = Some(3_000_000.into()))).execute(bytecode, (), accounts[0]).unwrap().then(move |contract| {
let contract = contract.unwrap();
println!("contract deployed at: {}", contract.address());
Contract::deploy(web3.eth(), include_bytes!("./build/SimpleEvent.abi"))
.unwrap()
.confirmations(1)
.poll_interval(time::Duration::from_secs(10))
.options(Options::with(|opt| opt.gas = Some(3_000_000.into())))
.execute(bytecode, (), accounts[0])
.unwrap()
.then(move |contract| {
let contract = contract.unwrap();
println!("contract deployed at: {}", contract.address());

// Filter for Hello event in our contract
let filter = FilterBuilder::default().address(vec![contract.address()]).topics(Some(vec!["0xd282f389399565f3671145f5916e51652b60eee8e5c759293a2f5771b8ddfd2e".into()]), None, None, None).build();
// Filter for Hello event in our contract
let filter = FilterBuilder::default()
.address(vec![contract.address()])
.topics(
Some(vec![
"0xd282f389399565f3671145f5916e51652b60eee8e5c759293a2f5771b8ddfd2e"
.parse()
.unwrap(),
]),
None,
None,
None,
)
.build();

let event_future = web3
.eth_subscribe()
.subscribe_logs(filter)
.then(|sub| {
sub.unwrap().for_each(|log| {
println!("got log: {:?}", log);
Ok(())
let event_future = web3
.eth_subscribe()
.subscribe_logs(filter)
.then(|sub| {
sub.unwrap().for_each(|log| {
println!("got log: {:?}", log);
Ok(())
})
})
})
.map_err(|_| ());
.map_err(|_| ());

let call_future = contract.call("hello", (), accounts[0], Options::default()).then(|tx| {
println!("got tx: {:?}", tx);
Ok(())
});
let call_future = contract.call("hello", (), accounts[0], Options::default()).then(|tx| {
println!("got tx: {:?}", tx);
Ok(())
});

event_future.join(call_future)
})
event_future.join(call_future)
})
}))
.unwrap();
}
10 changes: 9 additions & 1 deletion examples/simple_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ fn main() {
// Get the contract bytecode for instance from Solidity compiler
let bytecode: Vec<u8> = include_str!("./build/SimpleStorage.bin").from_hex().unwrap();
// Deploying a contract
let contract = Contract::deploy(web3.eth(), include_bytes!("./build/SimpleStorage.abi")).unwrap().confirmations(0).poll_interval(time::Duration::from_secs(10)).options(Options::with(|opt| opt.gas = Some(3_000_000.into()))).execute(bytecode, (), accounts[0]).unwrap().wait().unwrap();
let contract = Contract::deploy(web3.eth(), include_bytes!("./build/SimpleStorage.abi"))
.unwrap()
.confirmations(0)
.poll_interval(time::Duration::from_secs(10))
.options(Options::with(|opt| opt.gas = Some(3_000_000.into())))
.execute(bytecode, (), accounts[0])
.unwrap()
.wait()
.unwrap();

println!("{}", contract.address());

Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
max_width = 600
max_width = 120
Loading

0 comments on commit 91639ff

Please sign in to comment.