Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
feat: windows ipc provider (named pipe) (#1976)
Browse files Browse the repository at this point in the history
* fmt: imports

* fix: ipc tests

* fmt

* chore: move ws macros

* chore: gate ipc to unix family

* chore: make tokio optional

* feat: initial named_pipe

* feat: windows ipc

* chore: update Provider

* chore: clippy

* chore: use Path instead of OsStr

* chore: clippy

* fix: docs

* lf

* lf

* test: better subscription tests

* docs

* fix: ipc doctest

* chore: make winapi optional

* fix: optional tokio
  • Loading branch information
DaniPopes authored Jan 3, 2023
1 parent 04e3021 commit 4fd742f
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 163 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions ethers-providers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ bytes = { version = "1.3.0", default-features = false, optional = true }
once_cell = "1.17.0"
hashers = "1.0.1"

[target.'cfg(target_family = "windows")'.dependencies]
winapi = { version = "0.3", optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
# tokio
tokio = { version = "1.18", features = ["time"] }
tokio = { version = "1.18", default-features = false, features = ["time"] }
tokio-tungstenite = { version = "0.18.0", default-features = false, features = [
"connect",
], optional = true }
Expand All @@ -71,8 +74,9 @@ tempfile = "3.3.0"
[features]
default = ["ws", "rustls"]
celo = ["ethers-core/celo"]

ws = ["tokio-tungstenite", "futures-channel"]
ipc = ["tokio/io-util", "bytes", "futures-channel"]
ipc = ["tokio/io-util", "bytes", "futures-channel", "winapi"]

openssl = ["tokio-tungstenite/native-tls", "reqwest/native-tls"]
# we use the webpki roots so we can build static binaries w/o any root cert dependencies
Expand Down
9 changes: 6 additions & 3 deletions ethers-providers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#![deny(rustdoc::broken_intra_doc_links)]
#![allow(clippy::type_complexity)]
#![doc = include_str!("../README.md")]

mod transports;
use futures_util::future::join_all;
pub use transports::*;

mod provider;
Expand Down Expand Up @@ -40,7 +40,11 @@ pub mod erc;

use async_trait::async_trait;
use auto_impl::auto_impl;
use ethers_core::types::transaction::{eip2718::TypedTransaction, eip2930::AccessListWithGasUsed};
use ethers_core::types::{
transaction::{eip2718::TypedTransaction, eip2930::AccessListWithGasUsed},
*,
};
use futures_util::future::join_all;
use serde::{de::DeserializeOwned, Serialize};
use std::{error::Error, fmt::Debug, future::Future, pin::Pin};
use url::Url;
Expand Down Expand Up @@ -75,7 +79,6 @@ pub trait JsonRpcClient: Debug + Send + Sync {
R: DeserializeOwned;
}

use ethers_core::types::*;
pub trait FromErr<T> {
fn from(src: T) -> Self;
}
Expand Down
27 changes: 15 additions & 12 deletions ethers-providers/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,24 @@ use ethers_core::{
abi::{self, Detokenize, ParamType},
types::{
transaction::{eip2718::TypedTransaction, eip2930::AccessListWithGasUsed},
Address, Block, BlockId, BlockNumber, BlockTrace, Bytes, EIP1186ProofResponse, FeeHistory,
Filter, FilterBlockOption, GethDebugTracingCallOptions, GethDebugTracingOptions, GethTrace,
Log, NameOrAddress, Selector, Signature, Trace, TraceFilter, TraceType, Transaction,
TransactionReceipt, TransactionRequest, TxHash, TxpoolContent, TxpoolInspect, TxpoolStatus,
H256, U256, U64,
Address, Block, BlockId, BlockNumber, BlockTrace, Bytes, Chain, EIP1186ProofResponse,
FeeHistory, Filter, FilterBlockOption, GethDebugTracingCallOptions,
GethDebugTracingOptions, GethTrace, Log, NameOrAddress, Selector, Signature, Trace,
TraceFilter, TraceType, Transaction, TransactionReceipt, TransactionRequest, TxHash,
TxpoolContent, TxpoolInspect, TxpoolStatus, H256, U256, U64,
},
utils,
};
use futures_util::{lock::Mutex, try_join};
use hex::FromHex;
use serde::{de::DeserializeOwned, Serialize};
use thiserror::Error;
use url::{ParseError, Url};

use ethers_core::types::Chain;
use futures_util::{lock::Mutex, try_join};
use std::{
collections::VecDeque, convert::TryFrom, fmt::Debug, str::FromStr, sync::Arc, time::Duration,
};
use thiserror::Error;
use tracing::trace;
use tracing_futures::Instrument;
use url::{ParseError, Url};

#[derive(Copy, Clone)]
pub enum NodeClient {
Expand Down Expand Up @@ -1415,9 +1413,14 @@ impl Provider<crate::Ws> {
}
}

#[cfg(all(target_family = "unix", feature = "ipc"))]
#[cfg(all(feature = "ipc", any(unix, windows)))]
impl Provider<crate::Ipc> {
/// Direct connection to an IPC socket.
#[cfg_attr(unix, doc = "Connects to the Unix socket at the provided path.")]
#[cfg_attr(windows, doc = "Connects to the named pipe at the provided path.\n")]
#[cfg_attr(
windows,
doc = r"Note: the path must be the fully qualified, like: `\\.\pipe\<name>`."
)]
pub async fn connect_ipc(path: impl AsRef<std::path::Path>) -> Result<Self, ProviderError> {
let ipc = crate::Ipc::connect(path).await?;
Ok(Self::new(ipc))
Expand Down
7 changes: 3 additions & 4 deletions ethers-providers/src/transports/common.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// Code adapted from: https://github.com/althea-net/guac_rs/tree/master/web3/src/jsonrpc
use std::fmt;

use ethers_core::types::U256;
use serde::{
de::{self, MapAccess, Unexpected, Visitor},
Deserialize, Serialize,
};
use serde_json::{value::RawValue, Value};
use std::fmt;
use thiserror::Error;

use ethers_core::types::U256;

#[derive(Deserialize, Debug, Clone, Error)]
/// A JSON-RPC 2.0 error
#[derive(Deserialize, Debug, Clone, Error)]
pub struct JsonRpcError {
/// The error code
pub code: i64,
Expand Down
5 changes: 2 additions & 3 deletions ethers-providers/src/transports/http.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Code adapted from: https://github.com/althea-net/guac_rs/tree/master/web3/src/jsonrpc
use crate::{provider::ProviderError, JsonRpcClient};

use super::common::{Authorization, JsonRpcError, Request, Response};
use crate::{provider::ProviderError, JsonRpcClient};
use async_trait::async_trait;
use reqwest::{header::HeaderValue, Client, Error as ReqwestError};
use serde::{de::DeserializeOwned, Serialize};
Expand All @@ -11,8 +12,6 @@ use std::{
use thiserror::Error;
use url::Url;

use super::common::{Authorization, JsonRpcError, Request, Response};

/// A low-level JSON-RPC Client over HTTP.
///
/// # Example
Expand Down
Loading

0 comments on commit 4fd742f

Please sign in to comment.