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

Wallet CLI Implementation #1128

Merged
merged 55 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
2248c4b
end of day push; start scaffolding wallet commands
connormullett May 6, 2021
ac15be5
fix compiler errors
connormullett May 7, 2021
b291c8d
fix warnings; implement wallet_new in wallet_ops
connormullett May 7, 2021
0375d1a
EOD push
connormullett May 7, 2021
027f0b1
stub out wallet commands
connormullett May 10, 2021
53e61c6
add license headers
connormullett May 10, 2021
d2289a2
stub more methods; EOD push
connormullett May 10, 2021
bca3d03
stub new commands
connormullett May 11, 2021
97e100a
finish stubbing out wallet commands
connormullett May 12, 2021
d728718
Merge branch 'main' into connor/wallet-cli
connormullett May 18, 2021
4f2fb22
Merge branch 'main' into connor/wallet-cli
connormullett May 26, 2021
e4d1c7f
add flags and options for import wallet sub command
connormullett May 26, 2021
086384c
add default value to import
connormullett May 26, 2021
30d754f
pruning out forgotten bugs
connormullett May 26, 2021
aa4c334
Merge branch 'main' into connor/wallet-cli
connormullett Jun 1, 2021
54ac097
Merge branch 'main' into connor/wallet-cli
connormullett Jun 3, 2021
e51672c
fix merge conflicts from RPC cleanup
connormullett Jun 3, 2021
d6d5d83
wallet list works!
connormullett Jun 3, 2021
93b6e46
implement wallet new command
connormullett Jun 3, 2021
47e0963
Fix up some param errors, need help with rounding out sign and verify
connormullett Jun 4, 2021
ae86870
add forgotten params to some settings
connormullett Jun 4, 2021
8c1d5d0
fix up sign command; panics but passes to rpc
connormullett Jun 4, 2021
1323807
attempt at resolve address issue in sign command
connormullett Jun 4, 2021
18a5682
round out command issues
connormullett Jun 7, 2021
1ead296
add documentation and remove redundant flags
connormullett Jun 7, 2021
d0da50f
wallet sign works
connormullett Jun 7, 2021
243532d
working on verify command
connormullett Jun 7, 2021
83a12c4
add basic logic to single key imports
connormullett Jun 7, 2021
c0b3ec4
figure out formatting for key import
connormullett Jun 8, 2021
63c66be
import now works
connormullett Jun 8, 2021
045c217
remove debug print
connormullett Jun 8, 2021
7484355
sign command works
connormullett Jun 9, 2021
0cf2ccc
verify works; unexpected output
connormullett Jun 9, 2021
7e0cedc
better error handling and messages for some commands
connormullett Jun 9, 2021
982a281
god damn encoding
ec2 Jun 10, 2021
fb9d8dc
Merge branch 'connor/wallet-cli' of github.com:ChainSafe/forest into …
ec2 Jun 10, 2021
675e56a
clean up command help text
connormullett Jun 10, 2021
911435e
add missing commands to docs
connormullett Jun 10, 2021
fe99ea7
Merge branch 'main' into connor/wallet-cli
connormullett Jun 10, 2021
4bfa9eb
add work to issue #1118; add tut to readme
connormullett Jun 10, 2021
ef0c1a0
use helper instead of print and process::exit
connormullett Jun 10, 2021
cf71f5a
requested changes
connormullett Jun 11, 2021
6047fb4
Merge branch 'main' into connor/wallet-cli
connormullett Jun 11, 2021
ef9bba1
fixup default address return type
connormullett Jun 14, 2021
9cd4c7f
use type aliases for consistency
connormullett Jun 14, 2021
71f6935
use more type aliases for consistency
connormullett Jun 14, 2021
dfe2b92
wildcard import
connormullett Jun 14, 2021
ce71824
forgotten type alias
connormullett Jun 14, 2021
ee6b0f0
Merge branch 'main' into connor/wallet-cli
cryptoquick Jun 14, 2021
b027565
Fix linter. Fix capitalism.
cryptoquick Jun 14, 2021
a1b6cdf
Fix capitalism.
cryptoquick Jun 14, 2021
05c6ca5
Fix capitalism.
cryptoquick Jun 14, 2021
8cd87ab
Use RPC API constants.
cryptoquick Jun 14, 2021
90fb4c1
Fix linter.
cryptoquick Jun 14, 2021
49a9b95
Fix typos.
cryptoquick Jun 14, 2021
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
4 changes: 4 additions & 0 deletions Cargo.lock

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

16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ Importing the snapshot only needs to happen during the first run. Following this
./target/release/forest
```

### Interacting with Forest via CLI

When the Forest daemon is started, an admin token will be displayed. You will need this for commands that require a higher level of authorization (like a password). Forest, as mentioned above, uses multiaddresses for networking. This is no different in the CLI. To set the host and the port to use, if not using the default port or using a remote host, set the `FULLNODE_API_INFO` environment variable. This is also where you can set a token for authentication.

```
FULLNODE_API_INFO="<token goes here>:/ip4/<host>/tcp/<port>/http
```

Note that if a token is not present in the FULLNODE_API_INFO env variable, the colon is removed.

Forest developers will prepend this variable to cli commands over using `export` on Linux or its equivelant on Windows. This will look like the following:
cryptoquick marked this conversation as resolved.
Show resolved Hide resolved

```
FULLNODE_API_INFO="..." forest auth api-info -p admin
```

### Documentation
https://chainsafe.github.io/forest/

Expand Down
6 changes: 0 additions & 6 deletions blockchain/chain/src/store/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,13 +1020,7 @@ mod tests {
use super::*;
use address::Address;
use async_std::sync::Arc;
use async_std::{
fs::{remove_file, File},
io::{BufReader, BufWriter},
};
use cid::Code::{Blake2b256, Identity};
use state_tree::StateTree;
use types::StateTreeVersion;

#[test]
fn genesis_test() {
Expand Down
13 changes: 1 addition & 12 deletions blockchain/chain_sync/src/chain_muxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,23 +837,12 @@ where
#[cfg(test)]
mod tests {
use std::convert::TryFrom;
use std::sync::Arc;
use std::time::Duration;

use async_std::channel::{bounded, Sender};
use async_std::task;

use crate::validation::TipsetValidator;
use beacon::{BeaconPoint, MockBeacon};
use chain::ChainStore;
use cid::Cid;
use db::MemoryDB;
use fil_types::verifier::MockVerifier;
use forest_libp2p::NetworkEvent;
use message::{SignedMessage, UnsignedMessage};
use message_pool::{test_provider::TestApi, MessagePool};
use state_manager::StateManager;
use test_utils::{construct_dummy_header, construct_messages};
use test_utils::construct_messages;

#[test]
fn compute_msg_meta_given_msgs_test() {
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ pub mod json {
Secp256k1,
}

#[derive(Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
#[serde(transparent)]
pub struct SignatureTypeJson(#[serde(with = "self")] pub SignatureType);

Expand Down
75 changes: 75 additions & 0 deletions docs/CLI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

# CLI

The forest CLI allows for operations to interact with a Filecoin node and the blockchain.
cryptoquick marked this conversation as resolved.
Show resolved Hide resolved


## Environment Variables
For nodes not running on a non-default port, or when interacting with a node remotely, you will need
to provide the multiaddress information for the node. You will need to either set the environment variable
`FULLNODE_API_INFO`, or prepend it to the command, like so:

`FULLNODE_API_INFO="..." forest wallet new -s bls`

On linux, you can set the environment variable with the following syntax
cryptoquick marked this conversation as resolved.
Show resolved Hide resolved

`export FULLNOPDE_API_INFO="..."`

Setting your API info this way will limit the value to your current session. Look online for ways to persist
this variable if desired.

The syntax for the `FULLNODE_API_INFO` variable is as follows:

`<admin_token>:/ip4/<ip of host>/tcp/<port>/http`

This will use IPv4, tcp, and http when communicating with the RPC API. The admin token can be found when starting
cryptoquick marked this conversation as resolved.
Show resolved Hide resolved
the forest daemon. This will be needed to create tokens with certain permissions such as read, write, sign, or admin.
cryptoquick marked this conversation as resolved.
Show resolved Hide resolved

## Wallet

All wallet commands require write permissions to interact with the keystore

Balance
Retrieve the fil balance of a given address
cryptoquick marked this conversation as resolved.
Show resolved Hide resolved
Usage: `forest wallet balance <address>`

Default
Get the default, persisted address from the keystore
Usage: `forest wallet default`

Has
Check if an address exists in the keystore
shows true/false if exists or doesn't
Usage: `forest wallet has <address>`

List
Display the keys in the keystore
Usage: `forest wallet list`

New
Create a new wallet
The signature type can either be secp256k1 or bls. Defaults to use bls
Usage: `forest wallet new <bls/secp256k1>`

Set-default
Set an address to be the default address of the keystore
Usage: `forest wallet set-default <address>`

Import
Import a private key to the keystore and create a new address.
The default format for importing keys is hex encoded JSON. Use the `export`
command to get formatted keys for importing.
Usage: `forest wallet import <hex encoded json key>`

Export
Export a key by address. Use a wallet address to export a key. Returns a formatted key
to be used to import on another node, or into a new keystore.
Usage: `forest wallet export <address>`

Sign
Use an address to sign a vector of bytes
Usage: `forest wallet sign -m <hex message> -a <address>`

Verify
Verify the message's integrity with an address and signature
Usage: `forest wallet verify -m <hex message> -a <address> -s <signature>`
File renamed without changes.
3 changes: 3 additions & 0 deletions forest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2018"

[dependencies]
address = { package = "forest_address", version = "0.3" }
base64 = "0.13"
forest_libp2p = { path = "../node/forest_libp2p" }
utils = { path = "../node/utils" }
db = { package = "forest_db", version = "0.1" }
Expand All @@ -21,6 +22,7 @@ chain_sync = { path = "../blockchain/chain_sync" }
state_manager = { path = "../blockchain/state_manager" }
cid = { package = "forest_cid", version = "0.3", features = ["json"] }
forest_car = { path = "../ipld/car" }
forest_crypto = { version = "0.5.2", features = ["json"] }
tokio = { version = "1.0", features = ["sync"] }
num-bigint = { path = "../utils/bigint", package = "forest_bigint" }
blocks = { package = "forest_blocks", path = "../blockchain/blocks" }
Expand All @@ -34,6 +36,7 @@ rpc_client = { package = "rpc-client", path = "../node/rpc-client" }
rpc-api = { path = "../node/rpc-api", version = "0.1" }
fil_types = "0.2"
serde_json = "1.0"
message = { package = "forest_message", version = "0.7", features = ["blst"] }
message_pool = { package = "message_pool", path = "../blockchain/message_pool" }
wallet = { package = "key_management", path = "../key_management" }
uuid = { version = "0.8.2", features = ["v4"] }
Expand Down
9 changes: 9 additions & 0 deletions forest/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ mod chain_cmd;
mod config;
mod fetch_params_cmd;
mod genesis_cmd;
mod wallet_cmd;

pub(super) use self::auth_cmd::AuthCommands;
pub(super) use self::chain_cmd::ChainCommands;
pub use self::config::Config;
pub(super) use self::fetch_params_cmd::FetchCommands;
pub(super) use self::genesis_cmd::GenesisCommands;
pub(super) use self::wallet_cmd::WalletCommands;

use jsonrpc_v2::Error as JsonRpcError;
use serde::Serialize;
Expand Down Expand Up @@ -59,6 +61,8 @@ pub enum Subcommand {

#[structopt(name = "genesis", about = "Work with blockchain genesis")]
Genesis(GenesisCommands),
#[structopt(name = "wallet", about = "Manage wallet")]
Wallet(WalletCommands),
}

/// Daemon process command line options.
Expand Down Expand Up @@ -204,6 +208,11 @@ pub(super) fn handle_rpc_err(e: JsonRpcError) {
}
}

pub(super) fn cli_error_and_die(msg: &str, code: i32) {
println!("Error: {}", msg);
std::process::exit(code);
}

/// Prints a plain HTTP JSON-RPC response result
pub(super) fn print_rpc_res(res: Result<String, JsonRpcError>) {
match res {
Expand Down
Loading