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

feat: add missing admin_* methods #991

Merged
merged 10 commits into from
Jul 3, 2024
21 changes: 21 additions & 0 deletions crates/provider/src/ext/admin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! This module extends the Ethereum JSON-RPC provider with the Admin namespace's RPC methods.
use crate::Provider;
use alloy_network::Network;
use alloy_primitives::U128;
use alloy_rpc_types_admin::{NodeInfo, PeerInfo};
use alloy_transport::{Transport, TransportResult};

Expand Down Expand Up @@ -31,6 +32,17 @@ pub trait AdminApi<N, T>: Send + Sync {
/// Returns general information about the node as well as information about the running p2p
/// protocols (e.g. `eth`, `snap`).
async fn node_info(&self) -> TransportResult<NodeInfo>;

/// Subscribe to events received by peers over the network.
///
/// Like other subscription methods, this returns the ID of the subscription, which is then used
/// in all events subsequently.
///
/// To unsubscribe from peer events, call `unsubscribe_peer_events`.
alexfertel marked this conversation as resolved.
Show resolved Hide resolved
async fn subscribe_peer_events(&self) -> TransportResult<Option<U128>>;
DaniPopes marked this conversation as resolved.
Show resolved Hide resolved

/// Cancel subscription with `id`.
async fn unsubscribe_peer_events(&self, id: U128) -> TransportResult<bool>;
alexfertel marked this conversation as resolved.
Show resolved Hide resolved
}

#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
Expand Down Expand Up @@ -64,6 +76,15 @@ where
async fn node_info(&self) -> TransportResult<NodeInfo> {
self.client().request("admin_nodeInfo", ()).await
}

async fn subscribe_peer_events(&self) -> TransportResult<Option<U128>> {
self.client().request("admin_peerEvents_subscribe", ()).await
}

async fn unsubscribe_peer_events(&self, id: U128) -> TransportResult<bool> {
let id = format!("{id:#x}");
self.client().request("admin_peerEvents_unsubscribe", (id,)).await
}
}

#[cfg(test)]
Expand Down
Loading