mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 06:21:02 +00:00
RPC Module for Relays (#80)
* Test defining an RPC API * Add wrapper clients for the RPC API * Implement most Ethereum RPCs Does not include RPCs that require the bridge contract. * Implement a few of the Substrate RPCs Still missing proper error handling, as well as decoding responses from the Substrate node. * Make error handling more ergonomic * Implement Substrate RPCs that use `state_call` * Implement rest of Substrate RPCs * Implement `eth_call` RPC This can be used to implement higher level requests like fetching Substrate headers from an Ethereum node. * Build some of the higher level Ethereum RPCs Uses the new Ethereum RPC interface to do so * Build some of the higher level Substrate RPCs * Remove old Ethereum RPC methods * Remove old Substrate RPC methods * Add some documentation to Substrate RPCs * Fix typo in enum construction * Revert commits `0f0435d` to `ca75502` This range of commits was mainly trying to integrate the new RPC interface into the existing codebase, however this turned out to be a little out of scope for the current PR. Instead this work will be incorporated into a PR which aims to close #72. * Add documentation to RPCs * Rename functions in RPC API to conform to snake_case * Check that header contains a number and hash * Put doc comments on trait instead of impl methods * Remove expect() calls * Replace runtime API enums with consts * Accept Bytes when submitting extrinsic Let's us avoid using a runtime specific Extrinsic. * Add strictly typed arguments to RPC API Missing two methods right now, which require a `serde::Deserialize` implemenation before they can be changed. * Add `chain_getBlock` Substrate RPC * Use typed arguments for `eth_estimateGas` and `eth_call` * Silence dead code warnings * Add check for logs bloom * Remove unused variables * Add documentation to RPC error enums
This commit is contained in:
committed by
Bastian Köcher
parent
792226c9fd
commit
0e7666e63b
@@ -0,0 +1,98 @@
|
||||
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Bridges Common.
|
||||
|
||||
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity Bridges Common is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
use jsonrpsee::raw::client::RawClientError;
|
||||
use jsonrpsee::transport::http::RequestError;
|
||||
use serde_json;
|
||||
|
||||
type RpcHttpError = RawClientError<RequestError>;
|
||||
|
||||
/// Contains common errors that can occur when
|
||||
/// interacting with a Substrate or Ethereum node
|
||||
/// through RPC.
|
||||
#[derive(Debug)]
|
||||
pub enum RpcError {
|
||||
/// The arguments to the RPC method failed to serialize.
|
||||
Serialization(serde_json::Error),
|
||||
/// An error occured when interacting with an Ethereum node.
|
||||
Ethereum(EthereumNodeError),
|
||||
/// An error occured when interacting with a Substrate node.
|
||||
Substrate(SubstrateNodeError),
|
||||
/// An error that can occur when making an HTTP request to
|
||||
/// an JSON-RPC client.
|
||||
Request(RpcHttpError),
|
||||
/// The response from the client could not be SCALE decoded.
|
||||
Decoding(codec::Error),
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for RpcError {
|
||||
fn from(err: serde_json::Error) -> Self {
|
||||
Self::Serialization(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<EthereumNodeError> for RpcError {
|
||||
fn from(err: EthereumNodeError) -> Self {
|
||||
Self::Ethereum(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SubstrateNodeError> for RpcError {
|
||||
fn from(err: SubstrateNodeError) -> Self {
|
||||
Self::Substrate(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RpcHttpError> for RpcError {
|
||||
fn from(err: RpcHttpError) -> Self {
|
||||
Self::Request(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<codec::Error> for RpcError {
|
||||
fn from(err: codec::Error) -> Self {
|
||||
Self::Decoding(err)
|
||||
}
|
||||
}
|
||||
|
||||
/// Errors that can occur only when interacting with
|
||||
/// an Ethereum node through RPC.
|
||||
#[derive(Debug)]
|
||||
pub enum EthereumNodeError {
|
||||
/// Failed to parse response.
|
||||
ResponseParseFailed(String),
|
||||
/// We have received a header with missing fields.
|
||||
IncompleteHeader,
|
||||
/// We have received a receipt missing a `gas_used` field.
|
||||
IncompleteReceipt,
|
||||
/// An invalid Substrate block number was received from
|
||||
/// an Ethereum node.
|
||||
InvalidSubstrateBlockNumber,
|
||||
}
|
||||
|
||||
/// Errors that can occur only when interacting with
|
||||
/// a Substrate node through RPC.
|
||||
#[derive(Debug)]
|
||||
pub enum SubstrateNodeError {
|
||||
/// Request start failed.
|
||||
StartRequestFailed(RequestError),
|
||||
/// Error serializing request.
|
||||
RequestSerialization(serde_json::Error),
|
||||
/// Failed to parse response.
|
||||
ResponseParseFailed,
|
||||
}
|
||||
Reference in New Issue
Block a user