pink_web3/
lib.rs

1//! Ethereum JSON-RPC client (Web3).
2
3#![allow(
4    clippy::type_complexity,
5    clippy::wrong_self_convention,
6    clippy::single_match,
7    clippy::let_unit_value,
8    clippy::match_wild_err_arm
9)]
10#![warn(missing_docs)]
11// select! in WS transport
12#![recursion_limit = "256"]
13#![cfg_attr(not(any(feature = "std", feature = "test", test)), no_std)]
14
15#[cfg(test)]
16use jsonrpc_core as rpc;
17
18#[macro_use]
19extern crate alloc;
20
21pub use ethabi;
22// it needs to be before other modules
23// otherwise the macro for tests is not available.
24#[macro_use]
25pub mod helpers;
26
27mod prelude {
28    pub(crate) use alloc::borrow::ToOwned as _;
29    pub(crate) use alloc::string::String;
30    pub(crate) use alloc::string::ToString as _;
31    pub(crate) use alloc::vec;
32    pub(crate) use alloc::vec::Vec;
33    #[cfg(not(any(feature = "std", feature = "test", test)))]
34    pub(crate) use core as std;
35}
36
37use prelude::*;
38
39/// Re-export of the `futures` crate.
40#[macro_use]
41pub extern crate futures;
42
43pub mod api;
44pub mod confirm;
45pub mod contract;
46pub mod error;
47pub mod keys;
48pub mod signing;
49pub mod transports;
50pub mod types;
51
52pub use crate::{
53    api::{Accounts, Eth, Web3},
54    error::{Error, Result},
55};
56
57/// Assigned RequestId
58pub type RequestId = usize;
59
60type Value<'a> = &'a dyn erased_serde::Serialize;
61
62// TODO [ToDr] The transport most likely don't need to be thread-safe.
63// (though it has to be Send)
64/// Transport implementation
65pub trait Transport: Clone {
66    /// The type of future this transport returns when a call is made.
67    type Out: core::future::Future<Output = Result<Vec<u8>>>;
68
69    /// Execute remote method with given parameters.
70    fn execute(&self, method: &'static str, params: Vec<Value>) -> Self::Out;
71}
72
73impl<T: Transport> Transport for &T {
74    type Out = T::Out;
75
76    fn execute(&self, method: &'static str, params: Vec<Value>) -> Self::Out {
77        (*self).execute(method, params)
78    }
79}