Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Adds parity_getRawBlockByNumber, parity_submitRawBlock #10609

Merged
merged 3 commits into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions rpc/src/v1/helpers/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions rpc/src/v1/impls/light/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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))
}
}
19 changes: 19 additions & 0 deletions rpc/src/v1/impls/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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)?)
}
}
8 changes: 8 additions & 0 deletions rpc/src/v1/traits/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}