Skip to content

Commit

Permalink
create modules for types
Browse files Browse the repository at this point in the history
  • Loading branch information
oxarbitrage committed Oct 25, 2022
1 parent 92add9a commit 575e89d
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 85 deletions.
4 changes: 2 additions & 2 deletions zebra-rpc/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ use zebra_state::{OutputIndex, OutputLocation, TransactionLocation};
use crate::queue::Queue;

#[cfg(feature = "getblocktemplate-rpcs")]
mod get_block_template;
mod get_block_template_rpcs;

#[cfg(feature = "getblocktemplate-rpcs")]
pub use get_block_template::{GetBlockTemplateRpc, GetBlockTemplateRpcImpl};
pub use get_block_template_rpcs::{GetBlockTemplateRpc, GetBlockTemplateRpcImpl};

#[cfg(test)]
mod tests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ use jsonrpc_core::{self, BoxFuture, Error, ErrorCode, Result};
use jsonrpc_derive::rpc;
use tower::{Service, ServiceExt};

use crate::methods::{GetBlockHash, MISSING_BLOCK_ERROR_CODE};
pub(crate) mod types;

use crate::methods::{
get_block_template_rpcs::types::{
coinbase::Coinbase, default_roots::DefaultRoots, get_block_template::GetBlockTemplate,
},
GetBlockHash, MISSING_BLOCK_ERROR_CODE,
};

/// getblocktemplate RPC method signatures.
#[rpc(server)]
Expand Down Expand Up @@ -185,82 +192,6 @@ where
.boxed()
}
}
/// Documentation to be added after we document all the individual fields.
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct GetBlockTemplate {
/// Add documentation.
pub capabilities: Vec<String>,
/// Add documentation.
pub version: usize,
/// Add documentation.
#[serde(rename = "previousblockhash")]
pub previous_block_hash: String,
/// Add documentation.
#[serde(rename = "blockcommitmentshash")]
pub block_commitments_hash: String,
/// Add documentation.
#[serde(rename = "lightclientroothash")]
pub light_client_root_hash: String,
/// Add documentation.
#[serde(rename = "finalsaplingroothash")]
pub final_sapling_root_hash: String,
/// Add documentation.
#[serde(rename = "defaultroots")]
pub default_roots: DefaultRoots,
/// Add documentation.
pub transactions: Vec<Transaction>,
/// Add documentation.
#[serde(rename = "coinbasetxn")]
pub coinbase_txn: Coinbase,
/// Add documentation.
pub target: String,
/// Add documentation.
#[serde(rename = "mintime")]
pub min_time: u32,
/// Add documentation.
pub mutable: Vec<String>,
/// Add documentation.
#[serde(rename = "noncerange")]
pub nonce_range: String,
/// Add documentation.
#[serde(rename = "sigoplimit")]
pub sigop_limit: u32,
/// Add documentation.
#[serde(rename = "sizelimit")]
pub size_limit: u32,
/// Add documentation.
#[serde(rename = "curtime")]
pub cur_time: u32,
/// Add documentation.
pub bits: String,
/// Add documentation.
pub height: u32,
}

/// Documentation to be added in #5452 or #5455.
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct DefaultRoots {
/// Add documentation.
#[serde(rename = "merkleroot")]
pub merkle_root: String,
/// Add documentation.
#[serde(rename = "chainhistoryroot")]
pub chain_history_root: String,
/// Add documentation.
#[serde(rename = "authdataroot")]
pub auth_data_root: String,
/// Add documentation.
#[serde(rename = "blockcommitmentshash")]
pub block_commitments_hash: String,
}

/// Documentation and fields to be added in #5454.
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Transaction {}

/// documentation and fields to be added in #5453.
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Coinbase {}

/// Given a potentially negative index, find the corresponding `Height`.
///
Expand Down
6 changes: 6 additions & 0 deletions zebra-rpc/src/methods/get_block_template_rpcs/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! Types used in mining RPC methods.
pub(crate) mod coinbase;
pub(crate) mod default_roots;
pub(crate) mod get_block_template;
pub(crate) mod transaction;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! The `Coinbase` type is part of the `getblocktemplate` RPC method output.
/// documentation and fields to be added in #5453.
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Coinbase {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! The `DefaultRoots` type is part of the `getblocktemplate` RPC method output.
/// Documentation to be added in #5452 or #5455.
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct DefaultRoots {
/// Add documentation.
#[serde(rename = "merkleroot")]
pub merkle_root: String,
/// Add documentation.
#[serde(rename = "chainhistoryroot")]
pub chain_history_root: String,
/// Add documentation.
#[serde(rename = "authdataroot")]
pub auth_data_root: String,
/// Add documentation.
#[serde(rename = "blockcommitmentshash")]
pub block_commitments_hash: String,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//! The `GetBlockTempate` type is the output of the `getblocktemplate` RPC method.
use crate::methods::get_block_template_rpcs::types::{
coinbase::Coinbase, default_roots::DefaultRoots, transaction::Transaction,
};

/// Documentation to be added after we document all the individual fields.
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct GetBlockTemplate {
/// Add documentation.
pub capabilities: Vec<String>,
/// Add documentation.
pub version: usize,
/// Add documentation.
#[serde(rename = "previousblockhash")]
pub previous_block_hash: String,
/// Add documentation.
#[serde(rename = "blockcommitmentshash")]
pub block_commitments_hash: String,
/// Add documentation.
#[serde(rename = "lightclientroothash")]
pub light_client_root_hash: String,
/// Add documentation.
#[serde(rename = "finalsaplingroothash")]
pub final_sapling_root_hash: String,
/// Add documentation.
#[serde(rename = "defaultroots")]
pub default_roots: DefaultRoots,
/// Add documentation.
pub transactions: Vec<Transaction>,
/// Add documentation.
#[serde(rename = "coinbasetxn")]
pub coinbase_txn: Coinbase,
/// Add documentation.
pub target: String,
/// Add documentation.
#[serde(rename = "mintime")]
pub min_time: u32,
/// Add documentation.
pub mutable: Vec<String>,
/// Add documentation.
#[serde(rename = "noncerange")]
pub nonce_range: String,
/// Add documentation.
#[serde(rename = "sigoplimit")]
pub sigop_limit: u32,
/// Add documentation.
#[serde(rename = "sizelimit")]
pub size_limit: u32,
/// Add documentation.
#[serde(rename = "curtime")]
pub cur_time: u32,
/// Add documentation.
pub bits: String,
/// Add documentation.
pub height: u32,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! The `Transaction` type is part of the `getblocktemplate` RPC method output.
/// Documentation and fields to be added in #5454.
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Transaction {}
2 changes: 1 addition & 1 deletion zebra-rpc/src/methods/tests/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ fn snapshot_rpc_getblockhash(block_hash: GetBlockHash, settings: &insta::Setting
#[cfg(feature = "getblocktemplate-rpcs")]
/// Snapshot `getblocktemplate` response, using `cargo insta` and JSON serialization.
fn snapshot_rpc_getblocktemplate(
block_template: crate::methods::get_block_template::GetBlockTemplate,
block_template: crate::methods::get_block_template_rpcs::types::get_block_template::GetBlockTemplate,
settings: &insta::Settings,
) {
settings.bind(|| insta::assert_json_snapshot!("get_block_template", block_template));
Expand Down
10 changes: 5 additions & 5 deletions zebra-rpc/src/methods/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ async fn rpc_getblockcount() {

// Init RPC
let get_block_template_rpc =
get_block_template::GetBlockTemplateRpcImpl::new(latest_chain_tip.clone(), read_state);
get_block_template_rpcs::GetBlockTemplateRpcImpl::new(latest_chain_tip.clone(), read_state);

// Get the tip height using RPC method `get_block_count`
let get_block_count = get_block_template_rpc
Expand Down Expand Up @@ -686,7 +686,7 @@ async fn rpc_getblockcount_empty_state() {
);

let get_block_template_rpc =
get_block_template::GetBlockTemplateRpcImpl::new(latest_chain_tip.clone(), read_state);
get_block_template_rpcs::GetBlockTemplateRpcImpl::new(latest_chain_tip.clone(), read_state);

// Get the tip height using RPC method `get_block_count
let get_block_count = get_block_template_rpc.get_block_count();
Expand Down Expand Up @@ -730,7 +730,7 @@ async fn rpc_getblockhash() {
latest_chain_tip.clone(),
);
let get_block_template_rpc =
get_block_template::GetBlockTemplateRpcImpl::new(latest_chain_tip, read_state);
get_block_template_rpcs::GetBlockTemplateRpcImpl::new(latest_chain_tip, read_state);

// Query the hashes using positive indexes
for (i, block) in blocks.iter().enumerate() {
Expand Down Expand Up @@ -784,7 +784,7 @@ async fn rpc_getblocktemplate() {
latest_chain_tip.clone(),
);
let get_block_template_rpc =
get_block_template::GetBlockTemplateRpcImpl::new(latest_chain_tip, read_state);
get_block_template_rpcs::GetBlockTemplateRpcImpl::new(latest_chain_tip, read_state);

let get_block_template = get_block_template_rpc
.get_block_template()
Expand All @@ -810,7 +810,7 @@ async fn rpc_getblocktemplate() {
assert!(get_block_template.transactions.is_empty());
assert_eq!(
get_block_template.coinbase_txn,
get_block_template::Coinbase {}
get_block_template_rpcs::types::coinbase::Coinbase {}
);
assert!(get_block_template.target.is_empty());
assert_eq!(get_block_template.min_time, 0);
Expand Down

0 comments on commit 575e89d

Please sign in to comment.