From e4fc56f119fffda4eef5676aa9f87ef03a7ae0ae Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Fri, 9 Dec 2016 21:21:05 +0300 Subject: [PATCH] GetBlockResponse struct --- rpc/src/v1/traits/blockchain.rs | 2 +- rpc/src/v1/types/get_block_response.rs | 59 +++++++++++++++++++ rpc/src/v1/types/get_transaction_response.rs | 2 +- rpc/src/v1/types/get_tx_out_response.rs | 2 +- .../v1/types/get_tx_out_set_info_response.rs | 2 +- rpc/src/v1/types/mod.rs.in | 2 + rpc/src/v1/types/raw_block.rs | 3 + 7 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 rpc/src/v1/types/raw_block.rs diff --git a/rpc/src/v1/traits/blockchain.rs b/rpc/src/v1/traits/blockchain.rs index f6b0a45f..34f74362 100644 --- a/rpc/src/v1/traits/blockchain.rs +++ b/rpc/src/v1/traits/blockchain.rs @@ -18,7 +18,7 @@ build_rpc_trait! { fn block_hash(&self, u32) -> Result; /// Get proof-of-work difficulty as a multiple of the minimum difficulty #[rpc(name = "getdifficulty")] - fn difficulty(&self) -> Result; + fn difficulty(&self) -> Result; /// Get information on given block. #[rpc(name = "getblock")] fn block(&self, H256, Option) -> Result; diff --git a/rpc/src/v1/types/get_block_response.rs b/rpc/src/v1/types/get_block_response.rs index e0cdc9d9..35ab58c0 100644 --- a/rpc/src/v1/types/get_block_response.rs +++ b/rpc/src/v1/types/get_block_response.rs @@ -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, + /// 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, + /// Hash of next block + pub nextblockhash: Option, +} + +#[cfg(test)] +mod tests { + #[test] + fn block_serialize() { + + } } \ No newline at end of file diff --git a/rpc/src/v1/types/get_transaction_response.rs b/rpc/src/v1/types/get_transaction_response.rs index d2f511ff..3a926574 100644 --- a/rpc/src/v1/types/get_transaction_response.rs +++ b/rpc/src/v1/types/get_transaction_response.rs @@ -1,3 +1,3 @@ #[derive(Debug, Serialize, Deserialize)] pub struct GetTransactionResponse { -} \ No newline at end of file +} diff --git a/rpc/src/v1/types/get_tx_out_response.rs b/rpc/src/v1/types/get_tx_out_response.rs index e87edf9b..e7bfc620 100644 --- a/rpc/src/v1/types/get_tx_out_response.rs +++ b/rpc/src/v1/types/get_tx_out_response.rs @@ -1,3 +1,3 @@ #[derive(Debug, Serialize, Deserialize)] pub struct GetTxOutResponse { -} \ No newline at end of file +} diff --git a/rpc/src/v1/types/get_tx_out_set_info_response.rs b/rpc/src/v1/types/get_tx_out_set_info_response.rs index a71ffc4f..b7afb50d 100644 --- a/rpc/src/v1/types/get_tx_out_set_info_response.rs +++ b/rpc/src/v1/types/get_tx_out_set_info_response.rs @@ -1,3 +1,3 @@ #[derive(Debug, Serialize, Deserialize)] pub struct GetTxOutSetInfoResponse { -} \ No newline at end of file +} diff --git a/rpc/src/v1/types/mod.rs.in b/rpc/src/v1/types/mod.rs.in index 5599425b..d1b2ffe5 100644 --- a/rpc/src/v1/types/mod.rs.in +++ b/rpc/src/v1/types/mod.rs.in @@ -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; diff --git a/rpc/src/v1/types/raw_block.rs b/rpc/src/v1/types/raw_block.rs new file mode 100644 index 00000000..3ac34003 --- /dev/null +++ b/rpc/src/v1/types/raw_block.rs @@ -0,0 +1,3 @@ +use super::bytes::Bytes; + +pub type RawBlock = Bytes;