pallet_revive_eth_rpc/apis/polkadot_api.rs
1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17//! Polkadot-specific JSON-RPC methods.
18
19use crate::*;
20use jsonrpsee::{core::RpcResult, proc_macros::rpc};
21use sp_runtime::Weight;
22
23#[rpc(server, client)]
24pub trait PolkadotRpc {
25 /// Get the post dispatch weight for a given transaction hash.
26 #[method(name = "polkadot_postDispatchWeight")]
27 async fn post_dispatch_weight(&self, transaction_hash: H256) -> RpcResult<Option<Weight>>;
28}
29
30pub struct PolkadotRpcServerImpl {
31 client: client::Client,
32}
33
34impl PolkadotRpcServerImpl {
35 pub fn new(client: client::Client) -> Self {
36 Self { client }
37 }
38}
39
40#[async_trait]
41impl PolkadotRpcServer for PolkadotRpcServerImpl {
42 async fn post_dispatch_weight(&self, transaction_hash: H256) -> RpcResult<Option<Weight>> {
43 let weight = self.client.post_dispatch_weight(&transaction_hash).await;
44 Ok(weight)
45 }
46}