Skip to content

Commit

Permalink
move wallet into refwallet crate
Browse files Browse the repository at this point in the history
  • Loading branch information
yeastplume committed Feb 13, 2019
1 parent da288f0 commit fe853d2
Show file tree
Hide file tree
Showing 32 changed files with 413 additions and 422 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
36 changes: 36 additions & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -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" }
Expand Down
Binary file removed config/src/.lib.rs.swp
Binary file not shown.
Binary file removed config/src/.types.rs.swp
Binary file not shown.
7 changes: 3 additions & 4 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,19 @@ use toml;

use crate::comments::insert_comments;
use crate::core::global;
use crate::p2p;
use crate::servers::ServerConfig;
use crate::types::{
ConfigError, ConfigMembers, GlobalConfig, GlobalWalletConfig, GlobalWalletConfigMembers,
ConfigError, GlobalWalletConfig, GlobalWalletConfigMembers,
};
use crate::util::LoggingConfig;
use crate::wallet::WalletConfig;
use crate::types::WalletConfig;

/// Wallet configuration file name
pub const WALLET_CONFIG_FILE_NAME: &'static str = "grin-wallet.toml";
const WALLET_LOG_FILE_NAME: &'static str = "grin-wallet.log";
const GRIN_HOME: &'static str = ".grin";
/// Wallet data directory
pub const GRIN_WALLET_DIR: &'static str = "wallet_data";
/// API secret
pub const API_SECRET_FILE_NAME: &'static str = ".api_secret";

fn get_grin_path(chain_type: &global::ChainTypes) -> Result<PathBuf, ConfigError> {
Expand Down
4 changes: 2 additions & 2 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
82 changes: 81 additions & 1 deletion config/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChainTypes>,
/// 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<u16>,
/// Location of the secret for basic auth on the Owner API
pub api_secret_path: Option<String>,
/// Location of the node api secret for basic auth on the Grin API
pub node_api_secret_path: Option<String>,
/// 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<bool>,
/// 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<bool>,
/// TLS certificate file
pub tls_certificate_file: Option<String>,
/// TLS certificate private key file
pub tls_certificate_key: Option<String>,
/// 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<bool>,
/// The exploding lifetime (minutes) for keybase notification on coins received
pub keybase_notify_ttl: Option<u16>,
}

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 {
Expand Down
1 change: 1 addition & 0 deletions libwallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
8 changes: 8 additions & 0 deletions libwallet/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,11 @@ impl From<committed::Error> for Error {
}
}
}

impl From<store::Error> for Error {
fn from(error: store::Error) -> Error {
Error::from(ErrorKind::Backend(format!("{}", error)))
}
}


1 change: 1 addition & 0 deletions libwallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
43 changes: 43 additions & 0 deletions refwallet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "grin_refwallet"
version = "1.1.0"
authors = ["Grin Developers <[email protected]>"]
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" }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions src/bin/wallet/lib.rs → refwallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<store::Error> 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 {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit fe853d2

Please sign in to comment.