From fe853d29b3649e4718274f16f4d4f2927577c819 Mon Sep 17 00:00:00 2001 From: yeastplume Date: Wed, 13 Feb 2019 16:39:34 +0000 Subject: [PATCH] move wallet into refwallet crate --- .gitignore | 15 + Cargo.lock | 36 ++ Cargo.toml | 5 +- config/src/.lib.rs.swp | Bin 12288 -> 0 bytes config/src/.types.rs.swp | Bin 12288 -> 0 bytes config/src/config.rs | 7 +- config/src/lib.rs | 4 +- config/src/types.rs | 82 ++- libwallet/Cargo.toml | 1 + libwallet/src/error.rs | 8 + libwallet/src/lib.rs | 1 + refwallet/Cargo.toml | 43 ++ .../wallet => refwallet/src}/adapters/file.rs | 0 .../wallet => refwallet/src}/adapters/http.rs | 0 .../src}/adapters/keybase.rs | 0 .../wallet => refwallet/src}/adapters/mod.rs | 0 .../wallet => refwallet/src}/adapters/null.rs | 0 .../wallet => refwallet/src}/adapters/util.rs | 0 {src/bin/wallet => refwallet/src}/command.rs | 0 .../wallet => refwallet/src}/controller.rs | 0 {src/bin/wallet => refwallet/src}/display.rs | 0 {src/bin/wallet => refwallet/src}/error.rs | 0 {src/bin/wallet => refwallet/src}/lib.rs | 7 +- .../wallet => refwallet/src}/lmdb_wallet.rs | 9 +- .../src}/node_clients/http.rs | 0 .../src}/node_clients/mod.rs | 0 .../src}/test_framework/mod.rs | 0 .../src}/test_framework/testclient.rs | 0 {src/bin/wallet => refwallet/src}/types.rs | 79 +-- src/bin/cmd/config.rs | 29 +- src/bin/grin-wallet.rs | 34 +- src/bin/grin-wallet.yml | 475 ++++++++---------- 32 files changed, 413 insertions(+), 422 deletions(-) create mode 100644 .gitignore delete mode 100644 config/src/.lib.rs.swp delete mode 100644 config/src/.types.rs.swp create mode 100644 refwallet/Cargo.toml rename {src/bin/wallet => refwallet/src}/adapters/file.rs (100%) rename {src/bin/wallet => refwallet/src}/adapters/http.rs (100%) rename {src/bin/wallet => refwallet/src}/adapters/keybase.rs (100%) rename {src/bin/wallet => refwallet/src}/adapters/mod.rs (100%) rename {src/bin/wallet => refwallet/src}/adapters/null.rs (100%) rename {src/bin/wallet => refwallet/src}/adapters/util.rs (100%) rename {src/bin/wallet => refwallet/src}/command.rs (100%) rename {src/bin/wallet => refwallet/src}/controller.rs (100%) rename {src/bin/wallet => refwallet/src}/display.rs (100%) rename {src/bin/wallet => refwallet/src}/error.rs (100%) rename {src/bin/wallet => refwallet/src}/lib.rs (92%) rename {src/bin/wallet => refwallet/src}/lmdb_wallet.rs (98%) rename {src/bin/wallet => refwallet/src}/node_clients/http.rs (100%) rename {src/bin/wallet => refwallet/src}/node_clients/mod.rs (100%) rename {src/bin/wallet => refwallet/src}/test_framework/mod.rs (100%) rename {src/bin/wallet => refwallet/src}/test_framework/testclient.rs (100%) rename {src/bin/wallet => refwallet/src}/types.rs (74%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..728c195b5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.swp +.DS_Store +.grin* +node* +!node_clients +!node_clients.rs +target +*/Cargo.lock +*.iml +grin.log +wallet.seed +test_output +wallet_data +wallet/db +.idea/ diff --git a/Cargo.lock b/Cargo.lock index 0f4d7b543..4c85ba420 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -646,6 +646,7 @@ dependencies = [ "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "grin_core 1.1.0", "grin_keychain 1.1.0", + "grin_store 1.1.0", "grin_util 1.1.0", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -691,6 +692,39 @@ dependencies = [ "serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "grin_refwallet" +version = "1.1.0" +dependencies = [ + "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "grin_api 1.1.0", + "grin_chain 1.1.0", + "grin_core 1.1.0", + "grin_keychain 1.1.0", + "grin_libwallet 1.1.0", + "grin_store 1.1.0", + "grin_util 1.1.0", + "grin_wallet_config 1.1.0", + "hyper 0.12.19 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "prettytable-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", + "term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-retry 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "grin_secp256k1zkp" version = "0.7.4" @@ -761,8 +795,10 @@ dependencies = [ "grin_chain 1.1.0", "grin_core 1.1.0", "grin_keychain 1.1.0", + "grin_libwallet 1.1.0", "grin_store 1.1.0", "grin_util 1.1.0", + "grin_wallet_config 1.1.0", "hyper 0.12.19 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "prettytable-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index d57cbc1d7..cff57ed3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ name = "grin-wallet" path = "src/bin/grin-wallet.rs" [workspace] -members = ["libwallet", "config"] +members = ["config", "libwallet", "refwallet"] [dependencies] clap = { version = "2.31", features = ["yaml"] } @@ -43,6 +43,9 @@ uuid = { version = "0.6", features = ["serde", "v4"] } url = "1.7.0" chrono = { version = "0.4.4", features = ["serde"] } +grin_libwallet = { path = "./libwallet", version = "1.1.0" } +grin_wallet_config = { path = "./config", version = "1.1.0" } + grin_api = { path = "../grin/api", version = "1.1.0" } grin_core = { path = "../grin/core", version = "1.1.0" } grin_keychain = { path = "../grin/keychain", version = "1.1.0" } diff --git a/config/src/.lib.rs.swp b/config/src/.lib.rs.swp deleted file mode 100644 index e374fc0efa2a888180d2c707d8eab183a4a6c512..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 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 bw0ny7?b*AZ7SU-IM=ieetO& Result { diff --git a/config/src/lib.rs b/config/src/lib.rs index a58f8db45..b801137d3 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -30,5 +30,5 @@ mod comments; pub mod config; pub mod types; -pub use crate::config::{initial_setup_wallet, GRIN_WALLET_DIR}; -pub use crate::types::{ConfigError, GlobalWalletConfig}; +pub use crate::config::{initial_setup_wallet, GRIN_WALLET_DIR, WALLET_CONFIG_FILE_NAME}; +pub use crate::types::{ConfigError, GlobalWalletConfig, WalletConfig}; diff --git a/config/src/types.rs b/config/src/types.rs index 9aee3e445..ff24a5dd3 100644 --- a/config/src/types.rs +++ b/config/src/types.rs @@ -18,9 +18,89 @@ use std::fmt; use std::io; use std::path::PathBuf; +use crate::core::global::ChainTypes; use crate::util::LoggingConfig; -use crate::wallet::WalletConfig; +/// Command-line wallet configuration +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct WalletConfig { + /// Chain parameters (default to Mainnet if none at the moment) + pub chain_type: Option, + /// The api interface/ip_address that this api server (i.e. this wallet) will run + /// by default this is 127.0.0.1 (and will not accept connections from external clients) + pub api_listen_interface: String, + /// The port this wallet will run on + pub api_listen_port: u16, + /// The port this wallet's owner API will run on + pub owner_api_listen_port: Option, + /// Location of the secret for basic auth on the Owner API + pub api_secret_path: Option, + /// Location of the node api secret for basic auth on the Grin API + pub node_api_secret_path: Option, + /// The api address of a running server node against which transaction inputs + /// will be checked during send + pub check_node_api_http_addr: String, + /// Whether to include foreign API endpoints on the Owner API + pub owner_api_include_foreign: Option, + /// The directory in which wallet files are stored + pub data_file_dir: String, + /// If Some(true), don't cache commits alongside output data + /// speed improvement, but your commits are in the database + pub no_commit_cache: Option, + /// TLS certificate file + pub tls_certificate_file: Option, + /// TLS certificate private key file + pub tls_certificate_key: Option, + /// Whether to use the black background color scheme for command line + /// if enabled, wallet command output color will be suitable for black background terminal + pub dark_background_color_scheme: Option, + /// The exploding lifetime (minutes) for keybase notification on coins received + pub keybase_notify_ttl: Option, +} + +impl Default for WalletConfig { + fn default() -> WalletConfig { + WalletConfig { + chain_type: Some(ChainTypes::Mainnet), + api_listen_interface: "127.0.0.1".to_string(), + api_listen_port: 3415, + owner_api_listen_port: Some(WalletConfig::default_owner_api_listen_port()), + api_secret_path: Some(".api_secret".to_string()), + node_api_secret_path: Some(".api_secret".to_string()), + check_node_api_http_addr: "http://127.0.0.1:3413".to_string(), + owner_api_include_foreign: Some(false), + data_file_dir: ".".to_string(), + no_commit_cache: Some(false), + tls_certificate_file: None, + tls_certificate_key: None, + dark_background_color_scheme: Some(true), + keybase_notify_ttl: Some(1440), + } + } +} + +impl WalletConfig { + /// API Listen address + pub fn api_listen_addr(&self) -> String { + format!("{}:{}", self.api_listen_interface, self.api_listen_port) + } + + /// Default listener port + pub fn default_owner_api_listen_port() -> u16 { + 3420 + } + + /// Use value from config file, defaulting to sensible value if missing. + pub fn owner_api_listen_port(&self) -> u16 { + self.owner_api_listen_port + .unwrap_or(WalletConfig::default_owner_api_listen_port()) + } + + /// Owner API listen address + pub fn owner_api_listen_addr(&self) -> String { + format!("127.0.0.1:{}", self.owner_api_listen_port()) + } +} /// Error type wrapping config errors. #[derive(Debug)] pub enum ConfigError { diff --git a/libwallet/Cargo.toml b/libwallet/Cargo.toml index a4f0acc4f..f2e22ec12 100644 --- a/libwallet/Cargo.toml +++ b/libwallet/Cargo.toml @@ -23,6 +23,7 @@ log = "0.4" uuid = { version = "0.6", features = ["serde", "v4"] } chrono = { version = "0.4.4", features = ["serde"] } +grin_store = { path = "../../grin/store", version = "1.1.0" } grin_core = { path = "../../grin/core", version = "1.1.0" } grin_keychain = { path = "../../grin/keychain", version = "1.1.0" } grin_util = { path = "../../grin/util", version = "1.1.0" } diff --git a/libwallet/src/error.rs b/libwallet/src/error.rs index 491e78e09..869f85b44 100644 --- a/libwallet/src/error.rs +++ b/libwallet/src/error.rs @@ -298,3 +298,11 @@ impl From for Error { } } } + +impl From for Error { + fn from(error: store::Error) -> Error { + Error::from(ErrorKind::Backend(format!("{}", error))) + } +} + + diff --git a/libwallet/src/lib.rs b/libwallet/src/lib.rs index 7447b0c08..c710a9282 100644 --- a/libwallet/src/lib.rs +++ b/libwallet/src/lib.rs @@ -27,6 +27,7 @@ extern crate grin_core as core; extern crate grin_keychain as keychain; extern crate grin_util as util; +extern crate grin_store as store; use blake2_rfc as blake2; diff --git a/refwallet/Cargo.toml b/refwallet/Cargo.toml new file mode 100644 index 000000000..484ed6f47 --- /dev/null +++ b/refwallet/Cargo.toml @@ -0,0 +1,43 @@ +[package] +name = "grin_refwallet" +version = "1.1.0" +authors = ["Grin Developers "] +description = "Simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format." +license = "Apache-2.0" +repository = "https://github.com/mimblewimble/grin" +keywords = [ "crypto", "grin", "mimblewimble" ] +readme = "README.md" +exclude = ["**/*.grin", "**/*.grin2"] +#build = "src/build/build.rs" +edition = "2018" + +[dependencies] +blake2-rfc = "0.2" +failure = "0.1" +failure_derive = "0.1" +futures = "0.1" +hyper = "0.12" +rand = "0.5" +serde = "1" +serde_derive = "1" +serde_json = "1" +log = "0.4" +prettytable-rs = "0.7" +ring = "0.13" +term = "0.5" +tokio = "= 0.1.11" +tokio-core = "0.1" +tokio-retry = "0.1" +uuid = { version = "0.6", features = ["serde", "v4"] } +url = "1.7.0" +chrono = { version = "0.4.4", features = ["serde"] } + +grin_libwallet = { path = "../libwallet", version = "1.1.0" } +grin_wallet_config = { path = "../config", version = "1.1.0" } + +grin_core = { path = "../../grin/core", version = "1.1.0" } +grin_keychain = { path = "../../grin/keychain", version = "1.1.0" } +grin_chain = { path = "../../grin/chain", version = "1.1.0" } +grin_util = { path = "../../grin/util", version = "1.1.0" } +grin_api = { path = "../../grin/api", version = "1.1.0" } +grin_store = { path = "../../grin/store", version = "1.1.0" } diff --git a/src/bin/wallet/adapters/file.rs b/refwallet/src/adapters/file.rs similarity index 100% rename from src/bin/wallet/adapters/file.rs rename to refwallet/src/adapters/file.rs diff --git a/src/bin/wallet/adapters/http.rs b/refwallet/src/adapters/http.rs similarity index 100% rename from src/bin/wallet/adapters/http.rs rename to refwallet/src/adapters/http.rs diff --git a/src/bin/wallet/adapters/keybase.rs b/refwallet/src/adapters/keybase.rs similarity index 100% rename from src/bin/wallet/adapters/keybase.rs rename to refwallet/src/adapters/keybase.rs diff --git a/src/bin/wallet/adapters/mod.rs b/refwallet/src/adapters/mod.rs similarity index 100% rename from src/bin/wallet/adapters/mod.rs rename to refwallet/src/adapters/mod.rs diff --git a/src/bin/wallet/adapters/null.rs b/refwallet/src/adapters/null.rs similarity index 100% rename from src/bin/wallet/adapters/null.rs rename to refwallet/src/adapters/null.rs diff --git a/src/bin/wallet/adapters/util.rs b/refwallet/src/adapters/util.rs similarity index 100% rename from src/bin/wallet/adapters/util.rs rename to refwallet/src/adapters/util.rs diff --git a/src/bin/wallet/command.rs b/refwallet/src/command.rs similarity index 100% rename from src/bin/wallet/command.rs rename to refwallet/src/command.rs diff --git a/src/bin/wallet/controller.rs b/refwallet/src/controller.rs similarity index 100% rename from src/bin/wallet/controller.rs rename to refwallet/src/controller.rs diff --git a/src/bin/wallet/display.rs b/refwallet/src/display.rs similarity index 100% rename from src/bin/wallet/display.rs rename to refwallet/src/display.rs diff --git a/src/bin/wallet/error.rs b/refwallet/src/error.rs similarity index 100% rename from src/bin/wallet/error.rs rename to refwallet/src/error.rs diff --git a/src/bin/wallet/lib.rs b/refwallet/src/lib.rs similarity index 92% rename from src/bin/wallet/lib.rs rename to refwallet/src/lib.rs index 72325fec9..8fd6de7d2 100644 --- a/src/bin/wallet/lib.rs +++ b/refwallet/src/lib.rs @@ -25,18 +25,18 @@ extern crate serde_derive; extern crate log; use failure; use grin_api as api; -#[macro_use] extern crate grin_core as core; use grin_keychain as keychain; use grin_store as store; use grin_util as util; +use grin_libwallet as libwallet; +extern crate grin_wallet_config as config; mod adapters; pub mod command; pub mod controller; pub mod display; mod error; -pub mod libwallet; pub mod lmdb_wallet; mod node_clients; pub mod test_framework; @@ -53,7 +53,8 @@ pub use crate::libwallet::types::{ }; pub use crate::lmdb_wallet::{wallet_db_exists, LMDBBackend}; pub use crate::node_clients::{create_coinbase, HTTPNodeClient}; -pub use crate::types::{EncryptedWalletSeed, WalletConfig, WalletSeed, SEED_FILE}; +pub use crate::types::{EncryptedWalletSeed, WalletSeed, SEED_FILE}; +use config::WalletConfig; use crate::util::Mutex; use std::sync::Arc; diff --git a/src/bin/wallet/lmdb_wallet.rs b/refwallet/src/lmdb_wallet.rs similarity index 98% rename from src/bin/wallet/lmdb_wallet.rs rename to refwallet/src/lmdb_wallet.rs index 39eabdea8..bf59f619b 100644 --- a/src/bin/wallet/lmdb_wallet.rs +++ b/refwallet/src/lmdb_wallet.rs @@ -33,10 +33,11 @@ use crate::core::core::Transaction; use crate::core::{global, ser}; use crate::libwallet::types::*; use crate::libwallet::{internal, Error, ErrorKind}; -use crate::types::{WalletConfig, WalletSeed}; +use crate::types::WalletSeed; use crate::util; use crate::util::secp::constants::SECRET_KEY_SIZE; use crate::util::ZeroingString; +use config::WalletConfig; pub const DB_DIR: &'static str = "db"; pub const TX_SAVE_DIR: &'static str = "saved_txs"; @@ -49,12 +50,6 @@ const TX_LOG_ENTRY_PREFIX: u8 = 't' as u8; const TX_LOG_ID_PREFIX: u8 = 'i' as u8; const ACCOUNT_PATH_MAPPING_PREFIX: u8 = 'a' as u8; -impl From for Error { - fn from(error: store::Error) -> Error { - Error::from(ErrorKind::Backend(format!("{}", error))) - } -} - /// test to see if database files exist in the current directory. If so, /// use a DB backend for all operations pub fn wallet_db_exists(config: WalletConfig) -> bool { diff --git a/src/bin/wallet/node_clients/http.rs b/refwallet/src/node_clients/http.rs similarity index 100% rename from src/bin/wallet/node_clients/http.rs rename to refwallet/src/node_clients/http.rs diff --git a/src/bin/wallet/node_clients/mod.rs b/refwallet/src/node_clients/mod.rs similarity index 100% rename from src/bin/wallet/node_clients/mod.rs rename to refwallet/src/node_clients/mod.rs diff --git a/src/bin/wallet/test_framework/mod.rs b/refwallet/src/test_framework/mod.rs similarity index 100% rename from src/bin/wallet/test_framework/mod.rs rename to refwallet/src/test_framework/mod.rs diff --git a/src/bin/wallet/test_framework/testclient.rs b/refwallet/src/test_framework/testclient.rs similarity index 100% rename from src/bin/wallet/test_framework/testclient.rs rename to refwallet/src/test_framework/testclient.rs diff --git a/src/bin/wallet/types.rs b/refwallet/src/types.rs similarity index 74% rename from src/bin/wallet/types.rs rename to refwallet/src/types.rs index 5031e0fb7..5b4dbb98e 100644 --- a/src/bin/wallet/types.rs +++ b/refwallet/src/types.rs @@ -24,91 +24,14 @@ use serde_json; use ring::aead; use ring::{digest, pbkdf2}; -use crate::core::global::ChainTypes; use crate::error::{Error, ErrorKind}; use crate::keychain::{mnemonic, Keychain}; use crate::util; use failure::ResultExt; +use config::WalletConfig; pub const SEED_FILE: &'static str = "wallet.seed"; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -pub struct WalletConfig { - // Chain parameters (default to Testnet3 if none at the moment) - pub chain_type: Option, - // The api interface/ip_address that this api server (i.e. this wallet) will run - // by default this is 127.0.0.1 (and will not accept connections from external clients) - pub api_listen_interface: String, - // The port this wallet will run on - pub api_listen_port: u16, - // The port this wallet's owner API will run on - pub owner_api_listen_port: Option, - /// Location of the secret for basic auth on the Owner API - pub api_secret_path: Option, - /// Location of the node api secret for basic auth on the Grin API - pub node_api_secret_path: Option, - // The api address of a running server node against which transaction inputs - // will be checked during send - pub check_node_api_http_addr: String, - // Whether to include foreign API endpoints on the Owner API - pub owner_api_include_foreign: Option, - // The directory in which wallet files are stored - pub data_file_dir: String, - /// If Some(true), don't cache commits alongside output data - /// speed improvement, but your commits are in the database - pub no_commit_cache: Option, - /// TLS certificate file - pub tls_certificate_file: Option, - /// TLS certificate private key file - pub tls_certificate_key: Option, - /// Whether to use the black background color scheme for command line - /// if enabled, wallet command output color will be suitable for black background terminal - pub dark_background_color_scheme: Option, - // The exploding lifetime (minutes) for keybase notification on coins received - pub keybase_notify_ttl: Option, -} - -impl Default for WalletConfig { - fn default() -> WalletConfig { - WalletConfig { - chain_type: Some(ChainTypes::Mainnet), - api_listen_interface: "127.0.0.1".to_string(), - api_listen_port: 3415, - owner_api_listen_port: Some(WalletConfig::default_owner_api_listen_port()), - api_secret_path: Some(".api_secret".to_string()), - node_api_secret_path: Some(".api_secret".to_string()), - check_node_api_http_addr: "http://127.0.0.1:3413".to_string(), - owner_api_include_foreign: Some(false), - data_file_dir: ".".to_string(), - no_commit_cache: Some(false), - tls_certificate_file: None, - tls_certificate_key: None, - dark_background_color_scheme: Some(true), - keybase_notify_ttl: Some(1440), - } - } -} - -impl WalletConfig { - pub fn api_listen_addr(&self) -> String { - format!("{}:{}", self.api_listen_interface, self.api_listen_port) - } - - pub fn default_owner_api_listen_port() -> u16 { - 3420 - } - - /// Use value from config file, defaulting to sensible value if missing. - pub fn owner_api_listen_port(&self) -> u16 { - self.owner_api_listen_port - .unwrap_or(WalletConfig::default_owner_api_listen_port()) - } - - pub fn owner_api_listen_addr(&self) -> String { - format!("127.0.0.1:{}", self.owner_api_listen_port()) - } -} - #[derive(Clone, Debug, PartialEq)] pub struct WalletSeed(Vec); diff --git a/src/bin/cmd/config.rs b/src/bin/cmd/config.rs index 61b4a0544..d7c39fa3e 100644 --- a/src/bin/cmd/config.rs +++ b/src/bin/cmd/config.rs @@ -13,37 +13,10 @@ // limitations under the License. /// Grin configuration file output command -use crate::config::{config, GlobalConfig, GlobalWalletConfig, GRIN_WALLET_DIR}; +use crate::config::{config, GlobalWalletConfig, GRIN_WALLET_DIR}; use crate::core::global; use std::env; -/// Create a config file in the current directory -pub fn config_command_server(chain_type: &global::ChainTypes, file_name: &str) { - let mut default_config = GlobalConfig::for_chain(chain_type); - let current_dir = env::current_dir().unwrap_or_else(|e| { - panic!("Error creating config file: {}", e); - }); - let mut config_file_name = current_dir.clone(); - config_file_name.push(file_name); - if config_file_name.exists() { - panic!( - "{} already exists in the current directory. Please remove it first", - file_name - ); - } - default_config.update_paths(¤t_dir); - default_config - .write_to_file(config_file_name.to_str().unwrap()) - .unwrap_or_else(|e| { - panic!("Error creating config file: {}", e); - }); - - println!( - "{} file configured and created in current directory", - file_name - ); -} - /// Create a config file in the current directory pub fn config_command_wallet(chain_type: &global::ChainTypes, file_name: &str) { let mut default_config = GlobalWalletConfig::for_chain(chain_type); diff --git a/src/bin/grin-wallet.rs b/src/bin/grin-wallet.rs index 8b2b71cce..26c841c2f 100644 --- a/src/bin/grin-wallet.rs +++ b/src/bin/grin-wallet.rs @@ -19,15 +19,12 @@ extern crate clap; #[macro_use] extern crate log; -use crate::config::config::{SERVER_CONFIG_FILE_NAME, WALLET_CONFIG_FILE_NAME}; use crate::core::global; use crate::util::init_logger; use clap::App; use grin_api as api; -use grin_config as config; +use grin_wallet_config as config; use grin_core as core; -use grin_p2p as p2p; -use grin_servers as servers; use grin_util as util; use std::process::exit; @@ -41,7 +38,7 @@ pub mod built_info { pub fn info_strings() -> (String, String) { ( format!( - "This is Grin version {}{}, built for {} by {}.", + "This is Grin Wallet version {}{}, built for {} by {}.", built_info::PKG_VERSION, built_info::GIT_VERSION.map_or_else(|| "".to_owned(), |v| format!(" (git {})", v)), built_info::TARGET, @@ -89,7 +86,7 @@ fn real_main() -> i32 { // (if desired) if let ("init", Some(init_args)) = wallet_args.subcommand() { if init_args.is_present("here") { - cmd::config_command_wallet(&chain_type, WALLET_CONFIG_FILE_NAME); + cmd::config_command_wallet(&chain_type, config::WALLET_CONFIG_FILE_NAME); } } } @@ -118,28 +115,9 @@ fn real_main() -> i32 { w.config_file_path.as_ref().unwrap().to_str().unwrap() ); wallet_config = Some(w); - } - // When the subscommand is 'server' take into account the 'config_file' flag - ("server", Some(server_args)) => { - if let Some(_path) = server_args.value_of("config_file") { - node_config = Some(config::GlobalConfig::new(_path).unwrap_or_else(|e| { - panic!("Error loading server configuration: {}", e); - })); - } else { - node_config = Some( - config::initial_setup_server(&chain_type).unwrap_or_else(|e| { - panic!("Error loading server configuration: {}", e); - }), - ); - } - } + }, // Otherwise load up the node config as usual _ => { - node_config = Some( - config::initial_setup_server(&chain_type).unwrap_or_else(|e| { - panic!("Error loading server configuration: {}", e); - }), - ); } } @@ -167,7 +145,7 @@ fn real_main() -> i32 { log_build_info(); // Execute subcommand - match args.subcommand() { + /*match args.subcommand() { // server commands and options ("server", Some(server_args)) => { cmd::server_command(Some(server_args), node_config.unwrap()) @@ -183,5 +161,5 @@ fn real_main() -> i32 { // this could possibly become the way to configure most things // with most command line options being phased out _ => cmd::server_command(None, node_config.unwrap()), - } + }*/ } diff --git a/src/bin/grin-wallet.yml b/src/bin/grin-wallet.yml index 94a18e0a1..9b207e105 100644 --- a/src/bin/grin-wallet.yml +++ b/src/bin/grin-wallet.yml @@ -12,292 +12,227 @@ args: help: Run grin as a local-only network. Doesn't block peer connections but will not connect to any peer or seed long: usernet takes_value: false + - pass: + help: Wallet passphrase used to encrypt wallet seed + short: p + long: pass + takes_value: true + - account: + help: Wallet account to use for this operation + short: a + long: account + takes_value: true + default_value: default + - data_dir: + help: Directory in which to store wallet files + short: dd + long: data_dir + takes_value: true + - external: + help: Listen on 0.0.0.0 interface to allow external connections (default is 127.0.0.1) + short: e + long: external + takes_value: false + - show_spent: + help: Show spent outputs on wallet output commands + short: s + long: show_spent + takes_value: false + - api_server_address: + help: Api address of running node on which to check inputs and post transactions + short: r + long: api_server_address + takes_value: true subcommands: - - server: - about: Control the Grin server + - account: + about: List wallet accounts or create a new account args: - - config_file: - help: Path to a grin-server.toml configuration file + - create: + help: Create a new wallet account with provided name short: c - long: config_file + long: create takes_value: true + - listen: + about: Runs the wallet in listening mode waiting for transactions + args: - port: - help: Port to start the P2P server on - short: p + help: Port on which to run the wallet listener + short: l long: port takes_value: true - - api_port: - help: Port on which to start the api server (e.g. transaction pool api) - short: api - long: api_port + - method: + help: Which method to use for communication + short: m + long: method + possible_values: + - http + - keybase + default_value: http + takes_value: true + - owner_api: + about: Runs the wallet's local web API + - send: + about: Builds a transaction to send coins and sends to the specified listener directly + args: + - amount: + help: Number of coins to send with optional fraction, e.g. 12.423 + index: 1 + - minimum_confirmations: + help: Minimum number of confirmations required for an output to be spendable + short: c + long: min_conf + default_value: "10" takes_value: true - - seed: - help: Override seed node(s) to connect to + - selection_strategy: + help: Coin/Output selection strategy. short: s - long: seed + long: selection + possible_values: + - all + - smallest + default_value: all + takes_value: true + - estimate_selection_strategies: + help: Estimates all possible Coin/Output selection strategies. + short: e + long: estimate-selection + - change_outputs: + help: Number of change outputs to generate (mainly for testing) + short: o + long: change_outputs + default_value: "1" takes_value: true - - wallet_url: - help: The wallet listener to which mining rewards will be sent - short: w - long: wallet_url + - method: + help: Method for sending this transaction + short: m + long: method + possible_values: + - http + - file + - self + - keybase + default_value: http takes_value: true - subcommands: - - config: - about: Generate a configuration grin-server.toml file in the current directory - - run: - about: Run the Grin server in this console - - client: - about: Communicates with the Grin server - subcommands: - - status: - about: Current status of the Grin chain - - listconnectedpeers: - about: Print a list of currently connected peers - - ban: - about: Ban peer - args: - - peer: - help: Peer ip and port (e.g. 10.12.12.13:13414) - short: p - long: peer - required: true - takes_value: true - - unban: - about: Unban peer - args: - - peer: - help: Peer ip and port (e.g. 10.12.12.13:13414) - short: p - long: peer - required: true - takes_value: true - - wallet: - about: Wallet software for Grin + - dest: + help: Send the transaction to the provided server (start with http://) or save as file. + short: d + long: dest + takes_value: true + - fluff: + help: Fluff the transaction (ignore Dandelion relay protocol) + short: f + long: fluff + - message: + help: Optional participant message to include + short: g + long: message + takes_value: true + - stored_tx: + help: If present, use the previously stored Unconfirmed transaction with given id + short: t + long: stored_tx + takes_value: true + - receive: + about: Processes a transaction file to accept a transfer from a sender args: - - pass: - help: Wallet passphrase used to encrypt wallet seed - short: p - long: pass + - message: + help: Optional participant message to include + short: g + long: message + takes_value: true + - input: + help: Partial transaction to process, expects the sender's transaction file. + short: i + long: input takes_value: true - - account: - help: Wallet account to use for this operation - short: a - long: account + - finalize: + about: Processes a receiver's transaction file to finalize a transfer. + args: + - input: + help: Partial transaction to process, expects the receiver's transaction file. + short: i + long: input takes_value: true - default_value: default - - data_dir: - help: Directory in which to store wallet files - short: dd - long: data_dir + - fluff: + help: Fluff the transaction (ignore Dandelion relay protocol) + short: f + long: fluff + - outputs: + about: Raw wallet output info (list of outputs) + - txs: + about: Display transaction information + args: + - id: + help: If specified, display transaction with given Id and all associated Inputs/Outputs + short: i + long: id takes_value: true - - external: - help: Listen on 0.0.0.0 interface to allow external connections (default is 127.0.0.1) - short: e - long: external + - repost: + about: Reposts a stored, completed but unconfirmed transaction to the chain, or dumps it to a file + args: + - id: + help: Transaction ID containing the stored completed transaction + short: i + long: id + takes_value: true + - dumpfile: + help: File name to duMp the transaction to instead of posting + short: m + long: dumpfile + takes_value: true + - fluff: + help: Fluff the transaction (ignore Dandelion relay protocol) + short: f + long: fluff + - cancel: + about: Cancels an previously created transaction, freeing previously locked outputs for use again + args: + - id: + help: The ID of the transaction to cancel + short: i + long: id + takes_value: true + - txid: + help: The TxID UUID of the transaction to cancel + short: t + long: txid + takes_value: true + - info: + about: Basic wallet contents summary + args: + - minimum_confirmations: + help: Minimum number of confirmations required for an output to be spendable + short: c + long: min_conf + default_value: "10" + takes_value: true + - init: + about: Initialize a new wallet seed file and database + args: + - here: + help: Create wallet files in the current directory instead of the default ~/.grin directory + short: h + long: here takes_value: false - - show_spent: - help: Show spent outputs on wallet output commands + - short_wordlist: + help: Generate a 12-word recovery phrase/seed instead of default 24 short: s - long: show_spent + long: short_wordlist takes_value: false - - api_server_address: - help: Api address of running node on which to check inputs and post transactions - short: r - long: api_server_address - takes_value: true - subcommands: - - account: - about: List wallet accounts or create a new account - args: - - create: - help: Create a new wallet account with provided name - short: c - long: create - takes_value: true - - listen: - about: Runs the wallet in listening mode waiting for transactions - args: - - port: - help: Port on which to run the wallet listener - short: l - long: port - takes_value: true - - method: - help: Which method to use for communication - short: m - long: method - possible_values: - - http - - keybase - default_value: http - takes_value: true - - owner_api: - about: Runs the wallet's local web API -# Turned off, for now -# - web: -# about: Runs the local web wallet which can be accessed through a browser - - send: - about: Builds a transaction to send coins and sends to the specified listener directly - args: - - amount: - help: Number of coins to send with optional fraction, e.g. 12.423 - index: 1 - - minimum_confirmations: - help: Minimum number of confirmations required for an output to be spendable - short: c - long: min_conf - default_value: "10" - takes_value: true - - selection_strategy: - help: Coin/Output selection strategy. - short: s - long: selection - possible_values: - - all - - smallest - default_value: all - takes_value: true - - estimate_selection_strategies: - help: Estimates all possible Coin/Output selection strategies. - short: e - long: estimate-selection - - change_outputs: - help: Number of change outputs to generate (mainly for testing) - short: o - long: change_outputs - default_value: "1" - takes_value: true - - method: - help: Method for sending this transaction - short: m - long: method - possible_values: - - http - - file - - self - - keybase - default_value: http - takes_value: true - - dest: - help: Send the transaction to the provided server (start with http://) or save as file. - short: d - long: dest - takes_value: true - - fluff: - help: Fluff the transaction (ignore Dandelion relay protocol) - short: f - long: fluff - - message: - help: Optional participant message to include - short: g - long: message - takes_value: true - - stored_tx: - help: If present, use the previously stored Unconfirmed transaction with given id - short: t - long: stored_tx - takes_value: true - - receive: - about: Processes a transaction file to accept a transfer from a sender - args: - - message: - help: Optional participant message to include - short: g - long: message - takes_value: true - - input: - help: Partial transaction to process, expects the sender's transaction file. - short: i - long: input - takes_value: true - - finalize: - about: Processes a receiver's transaction file to finalize a transfer. - args: - - input: - help: Partial transaction to process, expects the receiver's transaction file. - short: i - long: input - takes_value: true - - fluff: - help: Fluff the transaction (ignore Dandelion relay protocol) - short: f - long: fluff - - outputs: - about: Raw wallet output info (list of outputs) - - txs: - about: Display transaction information - args: - - id: - help: If specified, display transaction with given Id and all associated Inputs/Outputs - short: i - long: id - takes_value: true - - repost: - about: Reposts a stored, completed but unconfirmed transaction to the chain, or dumps it to a file - args: - - id: - help: Transaction ID containing the stored completed transaction - short: i - long: id - takes_value: true - - dumpfile: - help: File name to duMp the transaction to instead of posting - short: m - long: dumpfile - takes_value: true - - fluff: - help: Fluff the transaction (ignore Dandelion relay protocol) - short: f - long: fluff - - cancel: - about: Cancels an previously created transaction, freeing previously locked outputs for use again - args: - - id: - help: The ID of the transaction to cancel - short: i - long: id - takes_value: true - - txid: - help: The TxID UUID of the transaction to cancel - short: t - long: txid - takes_value: true - - info: - about: Basic wallet contents summary - args: - - minimum_confirmations: - help: Minimum number of confirmations required for an output to be spendable - short: c - long: min_conf - default_value: "10" - takes_value: true - - init: - about: Initialize a new wallet seed file and database - args: - - here: - help: Create wallet files in the current directory instead of the default ~/.grin directory - short: h - long: here - takes_value: false - - short_wordlist: - help: Generate a 12-word recovery phrase/seed instead of default 24 - short: s - long: short_wordlist - takes_value: false - - recover: - help: Initialize new wallet using a recovery phrase - short: r - long: recover - takes_value: false - recover: - about: Recover a wallet.seed file from a recovery phrase (default) or displays a recovery phrase for an existing seed file - args: - - display: - help: Display wallet recovery phrase - short: d - long: display - takes_value: false - - restore: - about: Restores a wallet contents from a seed file - - check: - about: Checks a wallet's outputs against a live node, repairing and restoring missing outputs if required + help: Initialize new wallet using a recovery phrase + short: r + long: recover + takes_value: false + - recover: + about: Recover a wallet.seed file from a recovery phrase (default) or displays a recovery phrase for an existing seed file + args: + - display: + help: Display wallet recovery phrase + short: d + long: display + takes_value: false + - restore: + about: Restores a wallet contents from a seed file + - check: + about: Checks a wallet's outputs against a live node, repairing and restoring missing outputs if required