Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(provider): add examples to raw_request{,dyn} #486

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions crates/provider/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,24 @@ pub trait Provider<T: Transport + Clone = BoxTransport, N: Network = Ethereum>:
/* ---------------------------------------- raw calls --------------------------------------- */

/// Sends a raw JSON-RPC request.
///
/// # Examples
///
/// ```no_run
/// # async fn example(provider: impl alloy_provider::Provider) -> Result<(), Box<dyn std::error::Error>> {
/// use alloy_rpc_types::BlockNumberOrTag;
///
/// // No parameters: `()`
/// let block_number = provider.raw_request("eth_blockNumber".into(), ()).await?;
///
/// // One parameter: `(param,)` or `[param]`
/// let block = provider.raw_request("eth_getBlockByNumber".into(), (BlockNumberOrTag::Latest,)).await?;
///
/// // Two or more parameters: `(param1, param2, ...)` or `[param1, param2, ...]`
/// let full_block = provider.raw_request("eth_getBlockByNumber".into(), (BlockNumberOrTag::Latest, true)).await?;
/// # Ok(())
/// # }
/// ```
async fn raw_request<P, R>(&self, method: Cow<'static, str>, params: P) -> TransportResult<R>
where
P: RpcParam,
Expand All @@ -1038,6 +1056,27 @@ pub trait Provider<T: Transport + Clone = BoxTransport, N: Network = Ethereum>:
}

/// Sends a raw JSON-RPC request with type-erased parameters and return.
///
/// # Examples
///
/// ```no_run
/// # async fn example(provider: impl alloy_provider::Provider) -> Result<(), Box<dyn std::error::Error>> {
/// use alloy_rpc_types::BlockNumberOrTag;
///
/// // No parameters: `()`
/// let params = serde_json::value::to_raw_value(&())?;
/// let block_number = provider.raw_request_dyn("eth_blockNumber".into(), &params).await?;
///
/// // One parameter: `(param,)` or `[param]`
/// let params = serde_json::value::to_raw_value(&(BlockNumberOrTag::Latest,))?;
/// let block = provider.raw_request_dyn("eth_getBlockByNumber".into(), &params).await?;
///
/// // Two or more parameters: `(param1, param2, ...)` or `[param1, param2, ...]`
/// let params = serde_json::value::to_raw_value(&(BlockNumberOrTag::Latest, true))?;
/// let full_block = provider.raw_request_dyn("eth_getBlockByNumber".into(), &params).await?;
/// # Ok(())
/// # }
/// ```
async fn raw_request_dyn(
&self,
method: Cow<'static, str>,
Expand Down
2 changes: 2 additions & 0 deletions crates/rpc-types/src/eth/log.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unknown_lints, non_local_definitions)]

use alloy_primitives::{LogData, B256};
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 2 additions & 0 deletions crates/rpc-types/src/eth/transaction/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unknown_lints, non_local_definitions)]

use crate::{Log, WithOtherFields};
use alloy_consensus::{AnyReceiptEnvelope, ReceiptEnvelope, TxType};
use alloy_primitives::{Address, B256};
Expand Down
Loading