GetBlockResponse struct

This commit is contained in:
Svyatoslav Nikolsky 2016-12-09 21:21:05 +03:00
parent 6304a40ab7
commit e4fc56f119
7 changed files with 68 additions and 4 deletions

View File

@ -18,7 +18,7 @@ build_rpc_trait! {
fn block_hash(&self, u32) -> Result<H256, Error>;
/// Get proof-of-work difficulty as a multiple of the minimum difficulty
#[rpc(name = "getdifficulty")]
fn difficulty(&self) -> Result<u32, Error>;
fn difficulty(&self) -> Result<f64, Error>;
/// Get information on given block.
#[rpc(name = "getblock")]
fn block(&self, H256, Option<bool>) -> Result<GetBlockResponse, Error>;

View File

@ -1,3 +1,62 @@
use super::bytes::Bytes;
use super::hash::H256;
use super::raw_block::RawBlock;
/// Response to getblock RPC request
#[derive(Debug, Serialize, Deserialize)]
pub enum GetBlockResponse {
/// When asking for short response
Short(RawBlock),
/// When asking for verbose response
Verbose(Block),
}
/// Verbose block information
#[derive(Debug, Serialize, Deserialize)]
pub struct Block {
/// Block hash
pub hash: H256,
/// Number of confirmations. -1 if block is on the side chain
pub confirmations: i64,
/// Block size
pub size: u32,
/// Block size, excluding witness data
pub strippedsize: u32,
/// Block weight
pub weight: u32,
/// Block height
pub height: u32,
/// Block version
pub version: u32,
/// Block version as hex
#[serde(rename = "versionHex")]
pub version_hex: Bytes,
/// Merkle root of this block
pub merkleroot: H256,
/// Transactions ids
pub tx: Vec<H256>,
/// Block time in seconds since epoch (Jan 1 1970 GMT)
pub time: u32,
/// Median block time in seconds since epoch (Jan 1 1970 GMT)
pub mediantime: u32,
/// Block nonce
pub nonce: u32,
/// Block nbits
pub bits: u32,
/// Block difficulty
pub difficulty: f64,
/// Expected number of hashes required to produce the chain up to this block (in hex)
pub chainwork: H256,
/// Hash of previous block
pub previousblockhash: Option<H256>,
/// Hash of next block
pub nextblockhash: Option<H256>,
}
#[cfg(test)]
mod tests {
#[test]
fn block_serialize() {
}
}

View File

@ -1,3 +1,3 @@
#[derive(Debug, Serialize, Deserialize)]
pub struct GetTransactionResponse {
}
}

View File

@ -1,3 +1,3 @@
#[derive(Debug, Serialize, Deserialize)]
pub struct GetTxOutResponse {
}
}

View File

@ -1,3 +1,3 @@
#[derive(Debug, Serialize, Deserialize)]
pub struct GetTxOutSetInfoResponse {
}
}

View File

@ -6,6 +6,7 @@ mod get_transaction_response;
mod get_tx_out_response;
mod get_tx_out_set_info_response;
mod hash;
mod raw_block;
mod raw_transaction;
pub use self::block_template::{BlockTemplate, BlockTemplateTransaction};
@ -16,4 +17,5 @@ pub use self::get_transaction_response::GetTransactionResponse;
pub use self::get_tx_out_response::GetTxOutResponse;
pub use self::get_tx_out_set_info_response::GetTxOutSetInfoResponse;
pub use self::hash::H256;
pub use self::raw_block::RawBlock;
pub use self::raw_transaction::RawTransaction;

View File

@ -0,0 +1,3 @@
use super::bytes::Bytes;
pub type RawBlock = Bytes;