Skip to content

Commit

Permalink
Use CallRequest type from rust-web3 crate (paritytech#101)
Browse files Browse the repository at this point in the history
* Use `CallRequest` type from rust-web3 crate

* Change CallRequest's `to` field to be optional

Required due to changes in upstream `rust-web3` crate.
  • Loading branch information
HCastano authored and serban300 committed Apr 9, 2024
1 parent febea20 commit ba7f394
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bridges/relays/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
19 changes: 8 additions & 11 deletions bridges/relays/ethereum/src/ethereum_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.

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};
Expand All @@ -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;

Expand Down Expand Up @@ -87,15 +89,6 @@ impl Default for EthereumSigningParams {
/// Ethereum client type.
pub type Client = RawClient<HttpTransportClient>;

/// Ethereum contract call request.
#[derive(Debug, Default, PartialEq, Serialize)]
pub struct CallRequest {
/// Contract address.
pub to: Option<Address>,
/// Call data.
pub data: Option<Bytes>,
}

/// All possible errors that can occur during interacting with Ethereum node.
#[derive(Debug)]
pub enum Error {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -398,6 +394,7 @@ async fn submit_ethereum_transaction(
CallRequest {
to: contract_address,
data: Some(encoded_call.clone().into()),
..Default::default()
}
)
.await
Expand Down
2 changes: 1 addition & 1 deletion bridges/relays/ethereum/src/ethereum_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ba7f394

Please sign in to comment.