mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-06 12:37:23 +00:00
Add tests & Service's Configuration has optional fields that shouldn't be optional (#4842)
Related to #4776 Related to https://github.com/paritytech/polkadot/pull/832 To summarize the changes: 1. I did not manage to validate with types the service's Configuration. But I did reduce the possibility of errors by moving all the "fill" functions to their respective structopts 2. I split params.rs to multiple modules: one module params for just CLI parameters and one module commands for CLI subcommands (and RunCmd). Every command and params are in their own file so things are grouped better together and easier to remove 3. I removed the run and run_subcommand helpers as they are not helping much anymore. Running a command is always a set of 3 commands: 1. init 2. update config 3. run. This still allow the user to change the config before arguments get parsed or right after. 4. I added tests for all subcommands. 5. [deleted] Overall the aim is to improve the situation with the Configuration and the optional parameters, add tests, make the API more consistent and simpler.
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#![warn(missing_docs)]
|
||||
|
||||
pub mod cli;
|
||||
pub mod command;
|
||||
|
||||
use std::{
|
||||
fmt,
|
||||
@@ -37,8 +38,10 @@ use sp_runtime::{
|
||||
traits::{Block, HashFor, NumberFor, Hash}
|
||||
};
|
||||
|
||||
use command::{BlockAddress, ExtrinsicAddress};
|
||||
|
||||
/// A helper type for a generic block input.
|
||||
pub type BlockAddressFor<TBlock> = cli::BlockAddress<
|
||||
pub type BlockAddressFor<TBlock> = BlockAddress<
|
||||
<HashFor<TBlock> as Hash>::Output,
|
||||
NumberFor<TBlock>
|
||||
>;
|
||||
@@ -148,10 +151,10 @@ impl<TBlock: Block, TPrinter: PrettyPrinter<TBlock>> Inspector<TBlock, TPrinter>
|
||||
|
||||
fn get_block(&self, input: BlockAddressFor<TBlock>) -> Result<TBlock, Error> {
|
||||
Ok(match input {
|
||||
cli::BlockAddress::Bytes(bytes) => {
|
||||
BlockAddress::Bytes(bytes) => {
|
||||
TBlock::decode(&mut &*bytes)?
|
||||
},
|
||||
cli::BlockAddress::Number(number) => {
|
||||
BlockAddress::Number(number) => {
|
||||
let id = BlockId::number(number);
|
||||
let not_found = format!("Could not find block {:?}", id);
|
||||
let body = self.chain.block_body(&id)?
|
||||
@@ -160,7 +163,7 @@ impl<TBlock: Block, TPrinter: PrettyPrinter<TBlock>> Inspector<TBlock, TPrinter>
|
||||
.ok_or_else(|| Error::NotFound(not_found.clone()))?;
|
||||
TBlock::new(header, body)
|
||||
},
|
||||
cli::BlockAddress::Hash(hash) => {
|
||||
BlockAddress::Hash(hash) => {
|
||||
let id = BlockId::hash(hash);
|
||||
let not_found = format!("Could not find block {:?}", id);
|
||||
let body = self.chain.block_body(&id)?
|
||||
@@ -175,7 +178,7 @@ impl<TBlock: Block, TPrinter: PrettyPrinter<TBlock>> Inspector<TBlock, TPrinter>
|
||||
/// Get a pretty-printed extrinsic.
|
||||
pub fn extrinsic(
|
||||
&self,
|
||||
input: cli::ExtrinsicAddress<<HashFor<TBlock> as Hash>::Output, NumberFor<TBlock>>,
|
||||
input: ExtrinsicAddress<<HashFor<TBlock> as Hash>::Output, NumberFor<TBlock>>,
|
||||
) -> Result<String, Error> {
|
||||
struct ExtrinsicPrinter<'a, A: Block, B>(A::Extrinsic, &'a B);
|
||||
impl<'a, A: Block, B: PrettyPrinter<A>> fmt::Display for ExtrinsicPrinter<'a, A, B> {
|
||||
@@ -185,7 +188,7 @@ impl<TBlock: Block, TPrinter: PrettyPrinter<TBlock>> Inspector<TBlock, TPrinter>
|
||||
}
|
||||
|
||||
let ext = match input {
|
||||
cli::ExtrinsicAddress::Block(block, index) => {
|
||||
ExtrinsicAddress::Block(block, index) => {
|
||||
let block = self.get_block(block)?;
|
||||
block.extrinsics()
|
||||
.get(index)
|
||||
@@ -194,7 +197,7 @@ impl<TBlock: Block, TPrinter: PrettyPrinter<TBlock>> Inspector<TBlock, TPrinter>
|
||||
"Could not find extrinsic {} in block {:?}", index, block
|
||||
)))?
|
||||
},
|
||||
cli::ExtrinsicAddress::Bytes(bytes) => {
|
||||
ExtrinsicAddress::Bytes(bytes) => {
|
||||
TBlock::Extrinsic::decode(&mut &*bytes)?
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user