mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 07:41:08 +00:00
Make export blocks default to json on stdout (#5090)
* Make export blocks default to json on stdout * Multiline instead of single line to stay under 100 cols * Change --json flag to --binary, defaulting to json
This commit is contained in:
@@ -742,7 +742,7 @@ pub trait ServiceBuilderCommand {
|
||||
output: impl Write + 'static,
|
||||
from: NumberFor<Self::Block>,
|
||||
to: Option<NumberFor<Self::Block>>,
|
||||
json: bool
|
||||
binary: bool
|
||||
) -> Pin<Box<dyn Future<Output = Result<(), Error>>>>;
|
||||
|
||||
/// Performs a revert of `blocks` blocks.
|
||||
|
||||
@@ -203,7 +203,7 @@ impl<
|
||||
mut output: impl Write + 'static,
|
||||
from: NumberFor<TBl>,
|
||||
to: Option<NumberFor<TBl>>,
|
||||
json: bool
|
||||
binary: bool
|
||||
) -> Pin<Box<dyn Future<Output = Result<(), Error>>>> {
|
||||
let client = self.client;
|
||||
let mut block = from;
|
||||
@@ -230,7 +230,7 @@ impl<
|
||||
|
||||
if !wrote_header {
|
||||
info!("Exporting blocks from #{} to #{}", block, last);
|
||||
if !json {
|
||||
if binary {
|
||||
let last_: u64 = last.saturated_into::<u64>();
|
||||
let block_: u64 = block.saturated_into::<u64>();
|
||||
let len: u64 = last_ - block_ + 1;
|
||||
@@ -241,13 +241,13 @@ impl<
|
||||
|
||||
match client.block(&BlockId::number(block))? {
|
||||
Some(block) => {
|
||||
if json {
|
||||
if binary {
|
||||
output.write_all(&block.encode())?;
|
||||
} else {
|
||||
serde_json::to_writer(&mut output, &block)
|
||||
.map_err(|e| format!("Error writing JSON: {}", e))?;
|
||||
} else {
|
||||
output.write_all(&block.encode())?;
|
||||
}
|
||||
},
|
||||
},
|
||||
// Reached end of the chain.
|
||||
None => return std::task::Poll::Ready(Ok(())),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user