Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON client setup and chain CLI commands #572

Merged
merged 24 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fb4ff80
initial implementation done; still need to format cli
dutterbutter Jul 24, 2020
ef610e5
hot fix
dutterbutter Jul 24, 2020
8673926
removed wallet commands for separate PR
dutterbutter Jul 28, 2020
1d95ec8
resolved conflicts
dutterbutter Jul 28, 2020
3b301fd
Improved subcommands
dutterbutter Jul 28, 2020
c409e62
Merge branch 'main' of github.com:ChainSafe/forest into dustin/chain-cli
dutterbutter Jul 28, 2020
af6df32
ignore clippy warning from lib macro
dutterbutter Jul 28, 2020
a3e4040
Merge branch 'main' into dustin/chain-cli
dutterbutter Jul 29, 2020
21af074
Add clippy all and remove unneeded import
dutterbutter Jul 29, 2020
4f76ebe
Merge branch 'dustin/chain-cli' of github.com:ChainSafe/forest into d…
dutterbutter Jul 29, 2020
c1a7053
Uwrapping response and mapping json err
dutterbutter Jul 29, 2020
c2cb944
added import path
dutterbutter Jul 29, 2020
9a8f7bf
Hot fix
dutterbutter Jul 29, 2020
9dfb38f
linted
dutterbutter Jul 29, 2020
3f71825
Made requested changes
dutterbutter Jul 30, 2020
df2e1c5
Made requested changes
dutterbutter Jul 30, 2020
6477285
Merge branch 'main' into dustin/chain-cli
dutterbutter Jul 30, 2020
be891f2
ignore clippy warnings from jsonrpsee crate
dutterbutter Jul 30, 2020
19e612b
Merge branch 'dustin/chain-cli' of github.com:ChainSafe/forest into d…
dutterbutter Jul 30, 2020
7902bca
Merge branch 'main' into dustin/chain-cli
dutterbutter Jul 30, 2020
a923219
Merge branch 'main' into dustin/chain-cli
dutterbutter Jul 30, 2020
c27b638
update err handling
dutterbutter Jul 30, 2020
ca32801
Merge branch 'dustin/chain-cli' of github.com:ChainSafe/forest into d…
dutterbutter Jul 30, 2020
a6b85a7
Merge branch 'main' into dustin/chain-cli
dutterbutter Jul 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 158 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion blockchain/blocks/src/tipset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ pub mod tipset_json {
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};

/// Wrapper for serializing and deserializing a SignedMessage from JSON.
#[derive(Deserialize, Serialize)]
#[derive(Deserialize, Serialize, Debug)]
#[serde(transparent)]
pub struct TipsetJson(#[serde(with = "self")] pub Tipset);

Expand Down
3 changes: 2 additions & 1 deletion forest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pretty_env_logger = "0.4.0"
ctrlc = "3.1.4"
chain_sync = { path = "../blockchain/chain_sync" }
state_manager = { path = "../blockchain/state_manager" }
cid = { package = "forest_cid", path = "../ipld/cid" }
cid = { package = "forest_cid", path = "../ipld/cid", features = ["json"] }
forest_car = { path = "../ipld/car" }
blocks = { package = "forest_blocks", path = "../blockchain/blocks" }
ipld_blockstore = { path = "../ipld/blockstore", features = ["rocksdb"] }
Expand All @@ -27,6 +27,7 @@ structopt = { version = "0.3" }
beacon = { path = "../blockchain/beacon" }
hex = "0.4.2"
rpc = { path = "../node/rpc" }
rpc_client = {package = "rpc-client", path = "../node/rpc-client" }
fil_types = { path = "../types" }
serde_json = "1.0"
blake2b_simd = "0.5.9"
Expand Down
81 changes: 81 additions & 0 deletions forest/src/cli/chain_cmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use cid::Cid;
use rpc_client::{block, genesis, head, messages, new_client, read_obj};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
pub enum ChainCommands {
/// Retrieves and prints out the block specified by the given CID
#[structopt(about = "<Cid> Retrieve a block and print its details")]
Block {
#[structopt(help = "Input a valid CID")]
cid: String,
dutterbutter marked this conversation as resolved.
Show resolved Hide resolved
},

/// Prints out the genesis tipset
#[structopt(about = "Prints genesis tipset", help = "Prints genesis tipset")]
Genesis,

/// Prints out the canonical head of the chain
#[structopt(about = "Print chain head", help = "Print chain head")]
Head,

/// Reads and prints out a message referenced by the specified CID from the
/// chain blockstore
#[structopt(about = "<CID> Retrieves and prints messages by CIDs")]
Message {
#[structopt(help = "Input a valid CID")]
cid: String,
},

/// Reads and prints out ipld nodes referenced by the specified CID from chain
/// blockstore and returns raw bytes
#[structopt(about = "<CID> Read the raw bytes of an object")]
ReadObj {
#[structopt(help = "Input a valid CID")]
cid: String,
},
}

impl ChainCommands {
pub async fn run(&self) {
// TODO handle cli config
match self {
Self::Block { cid } => {
let cid: Cid = cid.parse().unwrap();
let mut client = new_client();

let blk = block(client, cid).await;
println!("{}", serde_json::to_string_pretty(&blk).unwrap());
dutterbutter marked this conversation as resolved.
Show resolved Hide resolved
}
Self::Genesis => {
let mut client = new_client();

let gen = genesis(client).await;
println!("{}", serde_json::to_string_pretty(&gen).unwrap());
}
Self::Head => {
let mut client = new_client();

let head = head(client).await;
println!("{}", serde_json::to_string_pretty(&head).unwrap());
dutterbutter marked this conversation as resolved.
Show resolved Hide resolved
}
Self::Message { cid } => {
let cid: Cid = cid.parse().unwrap();
let mut client = new_client();

let msg = messages(client, cid).await;
println!("{}", serde_json::to_string_pretty(&msg).unwrap());
}
Self::ReadObj { cid } => {
let cid: Cid = cid.parse().unwrap();
let mut client = new_client();

let obj = read_obj(client, cid).await;
println!("{}", serde_json::to_string_pretty(&obj).unwrap());
}
}
}
}
Loading