From 3c135b0f32b4a40bc1c0ac7c261e18144285118f Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Wed, 20 May 2020 11:53:41 -0400 Subject: [PATCH] Use `CallRequest` type from rust-web3 crate (#101) * Use `CallRequest` type from rust-web3 crate * Change CallRequest's `to` field to be optional Required due to changes in upstream `rust-web3` crate. --- bridges/relays/ethereum/Cargo.toml | 2 +- .../relays/ethereum/src/ethereum_client.rs | 19 ++++++++----------- bridges/relays/ethereum/src/ethereum_types.rs | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/bridges/relays/ethereum/Cargo.toml b/bridges/relays/ethereum/Cargo.toml index c41b13d22ed42..4a05cba9420eb 100644 --- a/bridges/relays/ethereum/Cargo.toml +++ b/bridges/relays/ethereum/Cargo.toml @@ -28,7 +28,7 @@ serde = { version = "1.0.110", features = ["derive"] } serde_json = "1.0.53" sp-bridge-eth-poa = { path = "../../primitives/ethereum-poa" } time = "0.2" -web3 = "0.11" +web3 = { git = "https://github.com/tomusdrw/rust-web3" } # Substrate Based Dependencies [dependencies.frame-system] diff --git a/bridges/relays/ethereum/src/ethereum_client.rs b/bridges/relays/ethereum/src/ethereum_client.rs index 974d5ddeff7ba..110c8733c03b6 100644 --- a/bridges/relays/ethereum/src/ethereum_client.rs +++ b/bridges/relays/ethereum/src/ethereum_client.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Parity Bridges Common. If not, see . -use crate::ethereum_types::{Address, Bytes, EthereumHeaderId, Header, Receipt, TransactionHash, H256, U256, U64}; +use crate::ethereum_types::{ + Address, Bytes, CallRequest, EthereumHeaderId, Header, Receipt, TransactionHash, H256, U256, U64, +}; use crate::substrate_types::{GrandpaJustification, Hash as SubstrateHash, QueuedSubstrateHeader, SubstrateHeaderId}; use crate::sync_types::{HeaderId, MaybeConnectionError}; use crate::{bail_on_arg_error, bail_on_error}; @@ -24,7 +26,7 @@ use jsonrpsee::common::Params; use jsonrpsee::raw::{RawClient, RawClientError}; use jsonrpsee::transport::http::{HttpTransportClient, RequestError}; use parity_crypto::publickey::KeyPair; -use serde::{de::DeserializeOwned, Serialize}; +use serde::de::DeserializeOwned; use serde_json::{from_value, to_value}; use std::collections::HashSet; @@ -87,15 +89,6 @@ impl Default for EthereumSigningParams { /// Ethereum client type. pub type Client = RawClient; -/// Ethereum contract call request. -#[derive(Debug, Default, PartialEq, Serialize)] -pub struct CallRequest { - /// Contract address. - pub to: Option
, - /// Call data. - pub data: Option, -} - /// All possible errors that can occur during interacting with Ethereum node. #[derive(Debug)] pub enum Error { @@ -225,6 +218,7 @@ pub async fn best_substrate_block( to_value(CallRequest { to: Some(contract_address), data: Some(encoded_call.into()), + ..Default::default() }) .map_err(|e| Error::RequestSerialization(e)), client @@ -258,6 +252,7 @@ pub async fn substrate_header_known( to_value(CallRequest { to: Some(contract_address), data: Some(encoded_call.into()), + ..Default::default() }) .map_err(|e| Error::RequestSerialization(e)), client @@ -311,6 +306,7 @@ pub async fn incomplete_substrate_headers( to_value(CallRequest { to: Some(contract_address), data: Some(encoded_call.into()), + ..Default::default() }) .map_err(|e| Error::RequestSerialization(e)), client @@ -398,6 +394,7 @@ async fn submit_ethereum_transaction( CallRequest { to: contract_address, data: Some(encoded_call.clone().into()), + ..Default::default() } ) .await diff --git a/bridges/relays/ethereum/src/ethereum_types.rs b/bridges/relays/ethereum/src/ethereum_types.rs index 4731570d4d873..fcd87952e40d5 100644 --- a/bridges/relays/ethereum/src/ethereum_types.rs +++ b/bridges/relays/ethereum/src/ethereum_types.rs @@ -18,7 +18,7 @@ use crate::substrate_types::{into_substrate_ethereum_header, into_substrate_ethe use crate::sync_types::{HeaderId, HeadersSyncPipeline, QueuedHeader, SourceHeader}; use codec::Encode; -pub use web3::types::{Address, Bytes, H256, U128, U256, U64}; +pub use web3::types::{Address, Bytes, CallRequest, H256, U128, U256, U64}; /// When header is just received from the Ethereum node, we check that it has /// both number and hash fields filled.