Skip to content

Commit

Permalink
[feature] hyperledger-iroha#2899: Add multi-instructions subcommand into
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Pesterev <pesterev@pm.me>
  • Loading branch information
pesterev committed Oct 27, 2022
1 parent b442a66 commit ee213b9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
50 changes: 50 additions & 0 deletions client_cli/multi-instr-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"Register": {
"Identifiable": {
"NewDomain": {
"id": "neverland",
"logo": null,
"metadata": {}
}
}
}
},
{
"Register": {
"Identifiable": {
"NewAccount": {
"id": "steve@neverland",
"signatories": [
"ed0120cc25624d62896d3a0bfd8940f928dc2abf27cc57cefeb442aa96d9081aae58a1"
],
"metadata": {}
}
}
}
},
{
"Register": {
"Identifiable": {
"NewAssetDefinition": {
"id": "sapporo#neverland",
"value_type": "Quantity",
"mintable": "Infinitely",
"metadata": {}
}
}
}
},
{
"Mint": {
"object": {
"U32": 1010
},
"destination_id": {
"Id": {
"AssetId": "sapporo##steve@neverland"
}
}
}
}
]
22 changes: 21 additions & 1 deletion client_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ pub enum Subcommand {
Wasm(wasm::Args),
/// The subcommand related to block streaming
Blocks(blocks::Args),
/// The subcommand related to multi-instructions as Json
Json(json::Args),
}

/// Runs subcommand
Expand All @@ -128,7 +130,7 @@ macro_rules! match_run_all {
impl RunArgs for Subcommand {
fn run(self, cfg: &ClientConfiguration) -> Result<()> {
use Subcommand::*;
match_run_all!((self, cfg), { Domain, Account, Asset, Peer, Events, Wasm, Blocks })
match_run_all!((self, cfg), { Domain, Account, Asset, Peer, Events, Wasm, Blocks, Json })
}
}

Expand Down Expand Up @@ -854,3 +856,21 @@ mod wasm {
}
}
}

mod json {
use std::io::BufReader;

use super::*;

/// Subcommand for submitting multi-instructions
#[derive(Debug, StructOpt)]
pub struct Args;

impl RunArgs for Args {
fn run(self, cfg: &ClientConfiguration) -> Result<()> {
let reader = BufReader::new(stdin());
let instructions: Vec<Instruction> = serde_json::from_reader(reader)?;
submit(instructions, cfg, UnlimitedMetadata::new()).wrap_err("Failed to submit parsed instructions")
}
}
}

0 comments on commit ee213b9

Please sign in to comment.