Adds parity_getRawBlockByNumber, parity_submitRawBlock (#10609)

* adds parity_getRawBlockByNumber

(cherry picked from commit 1b418f592a03d45997f54304ca10889a96199509)

* added parity_submitRawBlock

* remove space

Co-Authored-By: Andronik Ordian <write@reusable.software>
This commit is contained in:
Seun LanLege 2019-05-10 20:20:42 +01:00 committed by GitHub
parent de91a5532d
commit 2cf0d7d775
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 0 deletions

View File

@ -39,6 +39,7 @@ mod codes {
pub const NO_NEW_WORK: i64 = -32003;
pub const NO_WORK_REQUIRED: i64 = -32004;
pub const CANNOT_SUBMIT_WORK: i64 = -32005;
pub const CANNOT_SUBMIT_BLOCK: i64 = -32006;
pub const UNKNOWN_ERROR: i64 = -32009;
pub const TRANSACTION_ERROR: i64 = -32010;
pub const EXECUTION_ERROR: i64 = -32015;
@ -246,6 +247,14 @@ pub fn unavailable_block(no_ancient_block: bool, by_hash: bool) -> Error {
}
}
pub fn cannot_submit_block(err: EthcoreError) -> Error {
Error {
code: ErrorCode::ServerError(codes::CANNOT_SUBMIT_BLOCK),
message: "Cannot submit block.".into(),
data: Some(Value::String(err.to_string())),
}
}
pub fn check_block_number_existence<'a, T, C>(
client: &'a C,
num: BlockNumber,

View File

@ -47,6 +47,8 @@ use v1::types::{
Log, Filter,
};
use Host;
use v1::helpers::errors::light_unimplemented;
use v1::types::block_number_to_id;
/// Parity implementation for light client.
pub struct ParityClient<S, OD>
@ -407,4 +409,16 @@ where
fn verify_signature(&self, is_prefixed: bool, message: Bytes, r: H256, s: H256, v: U64) -> Result<RecoveredAccount> {
verify_signature(is_prefixed, message, r, s, v, self.light_dispatch.client.signing_chain_id())
}
fn get_raw_block_by_number(&self, block: BlockNumber) -> BoxFuture<Option<Bytes>> {
Box::new(
self.fetcher()
.block(block_number_to_id(block))
.map(|block| Some(Bytes::from(block.raw().to_vec())))
)
}
fn submit_raw_block(&self, _block: Bytes) -> Result<H256> {
Err(light_unimplemented(None))
}
}

View File

@ -49,6 +49,7 @@ use v1::types::{
block_number_to_id
};
use Host;
use ethcore::verification::queue::kind::blocks::Unverified;
/// Parity implementation.
pub struct ParityClient<C, M, U> {
@ -462,4 +463,22 @@ impl<C, M, U, S> Parity for ParityClient<C, M, U> where
fn verify_signature(&self, is_prefixed: bool, message: Bytes, r: H256, s: H256, v: U64) -> Result<RecoveredAccount> {
verify_signature(is_prefixed, message, r, s, v, self.client.signing_chain_id())
}
fn get_raw_block_by_number(&self, block_number: BlockNumber) -> BoxFuture<Option<Bytes>> {
Box::new(futures::done(
Ok(
self.client
.block(block_number_to_id(block_number))
.map(|block| Bytes::from(block.raw().to_vec()))
)
))
}
fn submit_raw_block(&self, block: Bytes) -> Result<H256> {
let result = self.client.import_block(
Unverified::from_rlp(block.into_vec()).map_err(errors::rlp)?
);
Ok(result.map_err(errors::cannot_submit_block)?)
}
}

View File

@ -232,4 +232,12 @@ pub trait Parity {
/// Is allowed to skip filling transaction hash for faster query.
#[rpc(name = "parity_getLogsNoTransactionHash")]
fn logs_no_tx_hash(&self, Filter) -> BoxFuture<Vec<Log>>;
/// Returns raw block RLP with given number.
#[rpc(name = "parity_getRawBlockByNumber")]
fn get_raw_block_by_number(&self, BlockNumber) -> BoxFuture<Option<Bytes>>;
/// Submit raw block to be published to the network
#[rpc(name = "parity_submitRawBlock")]
fn submit_raw_block(&self, Bytes) -> Result<H256>;
}