chore(docs): add method name to RPC handler implementation (#1737)

This commit is contained in:
chirag-bgh
2023-03-13 19:07:39 +05:30
committed by GitHub
parent 31411681ed
commit 2bd73199c2
7 changed files with 34 additions and 0 deletions

View File

@ -26,26 +26,31 @@ impl<N> AdminApiServer for AdminApi<N>
where
N: NetworkInfo + Peers + 'static,
{
/// Handler for `admin_addPeer`
fn add_peer(&self, record: NodeRecord) -> RpcResult<bool> {
self.network.add_peer(record.id, record.tcp_addr());
Ok(true)
}
/// Handler for `admin_removePeer`
fn remove_peer(&self, record: NodeRecord) -> RpcResult<bool> {
self.network.remove_peer(record.id, PeerKind::Basic);
Ok(true)
}
/// Handler for `admin_addTrustedPeer`
fn add_trusted_peer(&self, record: NodeRecord) -> RpcResult<bool> {
self.network.add_trusted_peer(record.id, record.tcp_addr());
Ok(true)
}
/// Handler for `admin_removeTrustedPeer`
fn remove_trusted_peer(&self, record: NodeRecord) -> RpcResult<bool> {
self.network.remove_peer(record.id, PeerKind::Trusted);
Ok(true)
}
/// Handler for `admin_peerEvents`
fn subscribe_peer_events(
&self,
_subscription_sink: jsonrpsee::SubscriptionSink,
@ -53,6 +58,7 @@ where
todo!()
}
/// Handler for `admin_nodeInfo`
async fn node_info(&self) -> RpcResult<NodeInfo> {
let enr = self.network.local_node_record();
let status = self.network.network_status().await.to_rpc_result()?;

View File

@ -31,23 +31,28 @@ impl<Eth> DebugApiServer for DebugApi<Eth>
where
Eth: EthApiSpec + 'static,
{
/// Handler for `debug_getRawHeader`
async fn raw_header(&self, _block_id: BlockId) -> RpcResult<Bytes> {
Err(internal_rpc_err("unimplemented"))
}
/// Handler for `debug_getRawBlock`
async fn raw_block(&self, _block_id: BlockId) -> RpcResult<Bytes> {
Err(internal_rpc_err("unimplemented"))
}
/// Handler for `debug_getRawTransaction`
/// Returns the bytes of the transaction for the given hash.
async fn raw_transaction(&self, _hash: H256) -> RpcResult<Bytes> {
Err(internal_rpc_err("unimplemented"))
}
/// Handler for `debug_getRawReceipts`
async fn raw_receipts(&self, _block_id: BlockId) -> RpcResult<Vec<Bytes>> {
Err(internal_rpc_err("unimplemented"))
}
/// Handler for `debug_getBadBlocks`
async fn bad_blocks(&self) -> RpcResult<Vec<RichBlock>> {
Err(internal_rpc_err("unimplemented"))
}

View File

@ -58,6 +58,7 @@ impl EngineApi {
#[async_trait]
impl EngineApiServer for EngineApi {
/// Handler for `engine_getPayloadV1`
/// See also <https://github.com/ethereum/execution-apis/blob/8db51dcd2f4bdfbd9ad6e4a7560aac97010ad063/src/engine/specification.md#engine_newpayloadv1>
/// Caution: This should not accept the `withdrawals` field
async fn new_payload_v1(&self, payload: ExecutionPayload) -> Result<PayloadStatus> {
@ -69,6 +70,7 @@ impl EngineApiServer for EngineApi {
.await
}
/// Handler for `engine_getPayloadV2`
/// See also <https://github.com/ethereum/execution-apis/blob/8db51dcd2f4bdfbd9ad6e4a7560aac97010ad063/src/engine/specification.md#engine_newpayloadv1>
async fn new_payload_v2(&self, payload: ExecutionPayload) -> Result<PayloadStatus> {
let (tx, rx) = oneshot::channel();
@ -79,6 +81,7 @@ impl EngineApiServer for EngineApi {
.await
}
/// Handler for `engine_forkchoiceUpdatedV1`
/// See also <https://github.com/ethereum/execution-apis/blob/8db51dcd2f4bdfbd9ad6e4a7560aac97010ad063/src/engine/specification.md#engine_forkchoiceUpdatedV1>
///
/// Caution: This should not accept the `withdrawals` field
@ -100,6 +103,7 @@ impl EngineApiServer for EngineApi {
.await
}
/// Handler for `engine_forkchoiceUpdatedV2`
/// See also <https://github.com/ethereum/execution-apis/blob/main/src/engine/specification.md#engine_forkchoiceupdatedv2>
async fn fork_choice_updated_v2(
&self,
@ -119,6 +123,7 @@ impl EngineApiServer for EngineApi {
.await
}
/// Handler for `engine_getPayloadV1`
/// See also <https://github.com/ethereum/execution-apis/blob/8db51dcd2f4bdfbd9ad6e4a7560aac97010ad063/src/engine/specification.md#engine_getPayloadV1>
///
/// Caution: This should not return the `withdrawals` field
@ -127,12 +132,14 @@ impl EngineApiServer for EngineApi {
self.delegate_request(EngineApiMessage::GetPayload(payload_id, tx), rx).await
}
/// Handler for `engine_getPayloadV2`
/// See also <https://github.com/ethereum/execution-apis/blob/main/src/engine/specification.md#engine_getpayloadv2>
async fn get_payload_v2(&self, payload_id: H64) -> Result<ExecutionPayload> {
let (tx, rx) = oneshot::channel();
self.delegate_request(EngineApiMessage::GetPayload(payload_id, tx), rx).await
}
/// Handler for `engine_getPayloadBodiesByHashV1`
/// See also <https://github.com/ethereum/execution-apis/blob/6452a6b194d7db269bf1dbd087a267251d3cc7f8/src/engine/shanghai.md#engine_getpayloadbodiesbyhashv1>
async fn get_payload_bodies_by_hash_v1(
&self,
@ -142,6 +149,7 @@ impl EngineApiServer for EngineApi {
self.delegate_request(EngineApiMessage::GetPayloadBodiesByHash(block_hashes, tx), rx).await
}
/// Handler for `engine_getPayloadBodiesByRangeV1`
/// See also <https://github.com/ethereum/execution-apis/blob/6452a6b194d7db269bf1dbd087a267251d3cc7f8/src/engine/shanghai.md#engine_getpayloadbodiesbyrangev1>
async fn get_payload_bodies_by_range_v1(
&self,
@ -152,6 +160,7 @@ impl EngineApiServer for EngineApi {
self.delegate_request(EngineApiMessage::GetPayloadBodiesByRange(start, count, tx), rx).await
}
/// Handler for `engine_exchangeTransitionConfigurationV1`
/// See also <https://github.com/ethereum/execution-apis/blob/8db51dcd2f4bdfbd9ad6e4a7560aac97010ad063/src/engine/specification.md#engine_exchangeTransitionConfigurationV1>
async fn exchange_transition_configuration(
&self,
@ -162,6 +171,7 @@ impl EngineApiServer for EngineApi {
.await
}
/// Handler for `engine_exchangeCapabilitiesV1`
/// See also <https://github.com/ethereum/execution-apis/blob/6452a6b194d7db269bf1dbd087a267251d3cc7f8/src/engine/common.md#capabilities>
async fn exchange_capabilities(&self, _capabilities: Vec<String>) -> Result<Vec<String>> {
Ok(CAPABILITIES.into_iter().map(str::to_owned).collect())

View File

@ -54,18 +54,22 @@ where
Client: BlockProvider + EvmEnvProvider + 'static,
Pool: TransactionPool + 'static,
{
/// Handler for `eth_newFilter`
async fn new_filter(&self, filter: Filter) -> RpcResult<FilterId> {
self.inner.install_filter(FilterKind::Log(Box::new(filter))).await
}
/// Handler for `eth_newBlockFilter`
async fn new_block_filter(&self) -> RpcResult<FilterId> {
self.inner.install_filter(FilterKind::Block).await
}
/// Handler for `eth_newPendingTransactionFilter`
async fn new_pending_transaction_filter(&self) -> RpcResult<FilterId> {
self.inner.install_filter(FilterKind::PendingTransaction).await
}
/// Handler for `eth_getFilterChanges`
async fn filter_changes(&self, id: FilterId) -> RpcResult<FilterChanges> {
let info = self.inner.client.chain_info().to_rpc_result()?;
let best_number = info.best_number;
@ -136,10 +140,12 @@ where
}
}
/// Handler for `eth_getFilterLogs`
async fn filter_logs(&self, _id: FilterId) -> RpcResult<Vec<Log>> {
todo!()
}
/// Handler for `eth_uninstallFilter`
async fn uninstall_filter(&self, id: FilterId) -> RpcResult<bool> {
let mut filters = self.inner.active_filters.inner.lock().await;
if filters.remove(&id).is_some() {
@ -150,6 +156,7 @@ where
}
}
/// Handler for `eth_getLogs`
async fn logs(&self, _filter: Filter) -> RpcResult<Vec<Log>> {
todo!()
}

View File

@ -60,6 +60,7 @@ where
Events: ChainEventSubscriptions + Clone + 'static,
Network: SyncStateProvider + Clone + 'static,
{
/// Handler for `eth_subscribe`
fn subscribe(
&self,
mut sink: SubscriptionSink,

View File

@ -29,14 +29,17 @@ where
Net: PeersInfo + 'static,
Eth: EthApiSpec + 'static,
{
/// Handler for `net_version`
fn version(&self) -> Result<String> {
Ok(self.eth.chain_id().to_string())
}
/// Handler for `net_peerCount`
fn peer_count(&self) -> Result<PeerCount> {
Ok(PeerCount::Hex(self.network.num_connected_peers().into()))
}
/// Handler for `net_listening`
fn is_listening(&self) -> Result<bool> {
Ok(true)
}

View File

@ -25,11 +25,13 @@ impl<N> Web3ApiServer for Web3Api<N>
where
N: NetworkInfo + 'static,
{
/// Handler for `web3_clientVersion`
async fn client_version(&self) -> RpcResult<String> {
let status = self.network.network_status().await.to_rpc_result()?;
Ok(status.client_version)
}
/// Handler for `web3_sha3`
fn sha3(&self, input: Bytes) -> RpcResult<H256> {
Ok(keccak256(input))
}