Skip to content

Commit

Permalink
Implement Interactive CLI (MystenLabs#357)
Browse files Browse the repository at this point in the history
* * renamed cli to wallet
* use conf file instead of account/ committee files and arg values
* removed create accounts command
* added add-address command

* removed benchmark from CLI commands

* revert client.rs code

* more refactoring
* got structopt working with shellfish

add sync client command

added transfer command

added objects command

cli refactoring

* get_owned_objects don't need to be async

* fixup after rebase

* * port should be u16
* added fastx binary for genesis and start authorities

* * more verbose

* * remove portpicker
* new PortAllocator

* * move call using args instead of config file

* * minor improvements

* * remove shellfish
* command completion using rustyline
* new Config trait for easy loading/storing config files
* address some PR comment

* fixup after rebase

* replace rustyline with reedline to avoid BSL license

* fixup after rebase

* * command completion support multiple command flag

* Revert "replace rustyline with reedline to avoid BSL license"

This reverts commit 371dce41

* * fixup after revert
* allow BSL-1.0 license

* * allow BSL-1.0 license

* * add back clear command

* * bugfix genesis not writing to wallet.conf

* fixup after rebase

* use unescape crate to handle unescaping string
address PR comments

* fixup after rebase
  • Loading branch information
patrickkuo authored Feb 9, 2022
1 parent 7a1575c commit 232da92
Show file tree
Hide file tree
Showing 17 changed files with 1,180 additions and 18 deletions.
1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ allow = [
"ISC",
"CC0-1.0",
"LicenseRef-ring",
"BSL-1.0",
#"Apache-2.0 WITH LLVM-exception",
]
# List of explictly disallowed licenses
Expand Down
20 changes: 16 additions & 4 deletions fastpay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ edition = "2021"
[dependencies]
anyhow = "1.0.53"
bytes = "1.1.0"
clap = "3.0.13"
futures = "0.3.19"
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.78"
Expand All @@ -36,9 +35,14 @@ fastx-adapter = { path = "../fastx_programmability/adapter" }
fastx-network = { path = "../network_utils" }
fastx-types = { path = "../fastx_types" }

move-package = { git = "https://github.com/diem/move", rev="62b5a5075378ae6a7102bbfc1fb33b57ba6125d2" }
move-core-types = { git = "https://github.com/diem/move", rev="62b5a5075378ae6a7102bbfc1fb33b57ba6125d2", features=["address20"] }
move-bytecode-verifier = { git = "https://github.com/diem/move", rev="62b5a5075378ae6a7102bbfc1fb33b57ba6125d2" }
move-package = { git = "https://github.com/diem/move", rev = "62b5a5075378ae6a7102bbfc1fb33b57ba6125d2" }
move-core-types = { git = "https://github.com/diem/move", rev = "62b5a5075378ae6a7102bbfc1fb33b57ba6125d2", features = ["address20"] }
move-bytecode-verifier = { git = "https://github.com/diem/move", rev = "62b5a5075378ae6a7102bbfc1fb33b57ba6125d2" }

rustyline = "9.1.2"
rustyline-derive = "0.6.0"
colored = "2.0.0"
unescape = "0.1.0"

[[bin]]
name = "client"
Expand All @@ -51,3 +55,11 @@ path = "src/server.rs"
[[bin]]
name = "bench"
path = "src/bench.rs"

[[bin]]
name = "wallet"
path = "src/wallet.rs"

[[bin]]
name = "fastx"
path = "src/fastx.rs"
2 changes: 1 addition & 1 deletion fastpay/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct ClientServerBenchmark {
db_dir: String,
/// Base port number
#[structopt(long, default_value = "9555")]
port: u32,
port: u16,
/// Size of the FastPay committee
#[structopt(long, default_value = "10")]
committee_size: usize,
Expand Down
124 changes: 123 additions & 1 deletion fastpay/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ use fastx_types::{
messages::{CertifiedOrder, OrderKind},
};

use crate::utils::Config;
use fastx_network::transport;
use fastx_types::object::Object;
use move_core_types::language_storage::TypeTag;
use move_core_types::{identifier::Identifier, transaction_argument::TransactionArgument};
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use std::fmt::{Debug, Display, Formatter};
use std::time::Duration;
use std::{
collections::{BTreeMap, BTreeSet},
fs::{self, read_to_string, File, OpenOptions},
Expand All @@ -27,7 +31,7 @@ pub struct AuthorityConfig {
)]
pub address: FastPayAddress,
pub host: String,
pub base_port: u32,
pub base_port: u16,
pub database_path: String,
}

Expand Down Expand Up @@ -312,3 +316,121 @@ impl Default for InitialStateConfig {
Self::new()
}
}

pub struct ClientConfig {
pub send_timeout: Duration,
pub recv_timeout: Duration,
pub buffer_size: usize,
pub db_path: String,
pub accounts_config_path: String,
pub committee_config_path: String,
pub accounts_config: AccountsConfig,
pub committee_config: CommitteeConfig,
}

#[derive(Serialize, Deserialize)]
pub struct AccountInfo {
#[serde(
serialize_with = "address_as_hex",
deserialize_with = "address_from_hex"
)]
pub address: FastPayAddress,
pub key_pair: KeyPair,
}

#[derive(Serialize, Deserialize)]
pub struct AuthorityInfo {
#[serde(
serialize_with = "address_as_hex",
deserialize_with = "address_from_hex"
)]
pub address: FastPayAddress,
pub host: String,
pub base_port: u16,
}

#[derive(Serialize, Deserialize)]
pub struct AuthorityPrivateInfo {
#[serde(
serialize_with = "address_as_hex",
deserialize_with = "address_from_hex"
)]
pub address: FastPayAddress,
pub key_pair: KeyPair,
pub host: String,
pub port: u16,
pub db_path: String,
}

#[derive(Serialize, Deserialize)]
pub struct WalletConfig {
pub accounts: Vec<AccountInfo>,
pub authorities: Vec<AuthorityInfo>,
pub send_timeout: Duration,
pub recv_timeout: Duration,
pub buffer_size: usize,
pub db_folder_path: String,

#[serde(skip)]
config_path: String,
}

impl Config for WalletConfig {
fn create(path: &str) -> Result<Self, anyhow::Error> {
Ok(WalletConfig {
accounts: Vec::new(),
authorities: Vec::new(),
send_timeout: Duration::from_micros(4000000),
recv_timeout: Duration::from_micros(4000000),
buffer_size: transport::DEFAULT_MAX_DATAGRAM_SIZE.to_string().parse()?,
db_folder_path: "./client_db".to_string(),
config_path: path.to_string(),
})
}

fn set_config_path(&mut self, path: &str) {
self.config_path = path.to_string();
}

fn config_path(&self) -> &str {
&*self.config_path
}
}

impl Display for WalletConfig {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Config path : {}\nClient state DB folder path : {}\nManaged addresses : {}",
self.config_path,
self.db_folder_path,
self.accounts.len()
)
}
}

#[derive(Serialize, Deserialize)]
pub struct NetworkConfig {
pub authorities: Vec<AuthorityPrivateInfo>,
pub buffer_size: usize,
#[serde(skip)]
config_path: String,
}

impl Config for NetworkConfig {
fn create(path: &str) -> Result<Self, anyhow::Error> {
Ok(Self {
authorities: Vec::new(),
buffer_size: transport::DEFAULT_MAX_DATAGRAM_SIZE.to_string().parse()?,
config_path: path.to_string(),
})
}

fn set_config_path(&mut self, path: &str) {
self.config_path = path.to_string()
}

fn config_path(&self) -> &str {
&*self.config_path
}
}
Loading

0 comments on commit 232da92

Please sign in to comment.