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

API Lifecycle Implementation, Pt. 1 #211

Merged
merged 17 commits into from Sep 2, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

doctests for lifecycle functions

  • Loading branch information...
yeastplume committed Aug 27, 2019
commit 7dc80302c75f8c6549ca4a2c8ee6cd426044e6af
@@ -625,7 +625,7 @@ pub fn run_doctest_foreign(
>;
let lc = wallet1.lc_provider().unwrap();
let _ = lc.set_top_level_directory(&format!("{}/wallet1", test_dir));
lc.create_wallet(None, Some(rec_phrase_1), 32, empty_string.clone())
lc.create_wallet(None, Some(rec_phrase_1), 32, empty_string.clone(), false)
.unwrap();
let mask1 = lc
.open_wallet(None, empty_string.clone(), use_token, true)
@@ -660,7 +660,7 @@ pub fn run_doctest_foreign(
>;
let lc = wallet2.lc_provider().unwrap();
let _ = lc.set_top_level_directory(&format!("{}/wallet2", test_dir));
lc.create_wallet(None, Some(rec_phrase_2), 32, empty_string.clone())
lc.create_wallet(None, Some(rec_phrase_2), 32, empty_string.clone(), false)
.unwrap();
let mask2 = lc
.open_wallet(None, empty_string.clone(), use_token, true)
@@ -29,7 +29,7 @@ use crate::libwallet::{
WalletLCProvider,
};
use crate::util::secp::key::SecretKey;
use crate::util::{LoggingConfig, Mutex, ZeroingString};
use crate::util::{from_hex, static_secp_instance, LoggingConfig, Mutex, ZeroingString};
use std::sync::Arc;

/// Main interface into all wallet API functions.
@@ -1289,7 +1289,7 @@ where
) -> Result<(), Error> {
let mut w_lock = self.wallet_inst.lock();
let lc = w_lock.lc_provider()?;
lc.create_wallet(name, mnemonic, mnemonic_length as usize, password)
lc.create_wallet(name, mnemonic, mnemonic_length as usize, password, self.doctest_mode)
}

/// Open a wallet, returning the token
@@ -1299,6 +1299,18 @@ where
password: ZeroingString,
use_mask: bool,
) -> Result<Option<SecretKey>, Error> {
// just return a representative string for doctest mode
if self.doctest_mode {
let secp_inst = static_secp_instance();
let secp = secp_inst.lock();
return Ok(Some(SecretKey::from_slice(
&secp,
&from_hex(
"d096b3cb75986b3b13f80b8f5243a9edf0af4c74ac37578c5a12cfb5b59b1868".to_owned(),
)
.unwrap(),
)?));
}
let mut w_lock = self.wallet_inst.lock();
let lc = w_lock.lc_provider()?;
lc.open_wallet(name, password, use_mask, self.doctest_mode)
@@ -1414,7 +1414,7 @@ pub fn run_doctest_owner(
>;
let lc = wallet1.lc_provider().unwrap();
let _ = lc.set_top_level_directory(&format!("{}/wallet1", test_dir));
lc.create_wallet(None, Some(rec_phrase_1), 32, empty_string.clone())
lc.create_wallet(None, Some(rec_phrase_1), 32, empty_string.clone(), false)
.unwrap();
let mask1 = lc
.open_wallet(None, empty_string.clone(), use_token, true)
@@ -1449,7 +1449,7 @@ pub fn run_doctest_owner(
>;
let lc = wallet2.lc_provider().unwrap();
let _ = lc.set_top_level_directory(&format!("{}/wallet2", test_dir));
lc.create_wallet(None, Some(rec_phrase_2), 32, empty_string.clone())
lc.create_wallet(None, Some(rec_phrase_2), 32, empty_string.clone(), false)
.unwrap();
let mask2 = lc
.open_wallet(None, empty_string.clone(), use_token, true)
@@ -1375,15 +1375,102 @@ pub trait OwnerRpcS {

fn set_top_level_directory(&self, dir: String) -> Result<(), ErrorKind>;

/// TODO: DOCS + TESTS TBD
/**
Networked version of [Owner::create_config](struct.Owner.html#method.create_config).
Both the `wallet_config` and `logging_config` parameters can be `null`, the examples
below are for illustration. Note that the values provided for `log_file_path` and `data_file_dir`
will be ignored and replaced with the actual values based on the value of `get_top_level_directory`
```
# grin_wallet_api::doctest_helper_json_rpc_owner_assert_response!(
# r#"
{
"jsonrpc": "2.0",
"method": "create_config",
"params": {
"chain_type": "Mainnet",
"wallet_config": {
"chain_type": null,
"api_listen_interface": "127.0.0.1",
"api_listen_port": 3415,
"owner_api_listen_port": 3420,
"api_secret_path": null,
"node_api_secret_path": null,
"check_node_api_http_addr": "http://127.0.0.1:3413",
"owner_api_include_foreign": false,
"data_file_dir": "/path/to/data/file/dir",
"no_commit_cache": null,
"tls_certificate_file": null,
"tls_certificate_key": null,
"dark_background_color_scheme": null,
"keybase_notify_ttl": null
},
"logging_config": {
"log_to_stdout": false,
"stdout_log_level": "Info",
"log_to_file": true,
"file_log_level": "Debug",
"log_file_path": "/path/to/log/file",
"log_file_append": true,
"log_max_size": null,
"log_max_files": null,
"tui_running": null
}
},
"id": 1
}
# "#
# ,
# r#"
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"Ok": null
}
}
# "#
# , true, 5, false, false, false);
```
*/
fn create_config(
&self,
chain_type: global::ChainTypes,
wallet_config: Option<WalletConfig>,
logging_config: Option<LoggingConfig>,
) -> Result<(), ErrorKind>;

/// TODO: DOCS + TESTS TBD
/**
Networked version of [Owner::create_wallet](struct.Owner.html#method.create_wallet).
```
# grin_wallet_api::doctest_helper_json_rpc_owner_assert_response!(
# r#"
{
"jsonrpc": "2.0",
"method": "create_wallet",
"params": {
"name": null,
"mnemonic": null,
"mnemonic_length": 0,
"password": "my_secret_password"
},
"id": 1
}
# "#
# ,
# r#"
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"Ok": null
}
}
# "#
# , true, 0, false, false, false);
```
*/

fn create_wallet(
&self,
name: Option<String>,
@@ -1392,7 +1479,35 @@ pub trait OwnerRpcS {
password: String,
) -> Result<(), ErrorKind>;

/// TODO: DOCS + TESTS TBD
/**
Networked version of [Owner::open_wallet](struct.Owner.html#method.open_wallet).
```
# grin_wallet_api::doctest_helper_json_rpc_owner_assert_response!(
# r#"
{
"jsonrpc": "2.0",
"method": "open_wallet",
"params": {
"name": null,
"password": "my_secret_password"
},
"id": 1
}
# "#
# ,
# r#"
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"Ok": "d096b3cb75986b3b13f80b8f5243a9edf0af4c74ac37578c5a12cfb5b59b1868"
}
}
# "#
# , true, 5, false, false, false);
```
*/

fn open_wallet(&self, name: Option<String>, password: String) -> Result<Token, ErrorKind>;
}

@@ -80,6 +80,7 @@ where
args.recovery_phrase,
args.list_length,
args.password.clone(),
false,
)?;

let m = p.get_mnemonic(None, args.password)?;
@@ -122,7 +122,7 @@ pub fn create_local_wallet(
>;
let lc = wallet.lc_provider().unwrap();
let _ = lc.set_top_level_directory(&format!("{}/{}", test_dir, name));
lc.create_wallet(None, mnemonic, 32, ZeroingString::from(""))
lc.create_wallet(None, mnemonic, 32, ZeroingString::from(""), false)
.unwrap();
let mask = lc
.open_wallet(None, ZeroingString::from(""), create_mask, false)
@@ -157,14 +157,17 @@ where
mnemonic: Option<ZeroingString>,
mnemonic_length: usize,
password: ZeroingString,
test_mode: bool,
) -> Result<(), Error> {
let mut data_dir_name = PathBuf::from(self.data_dir.clone());
data_dir_name.push(GRIN_WALLET_DIR);
let data_dir_name = data_dir_name.to_str().unwrap();
let exists = WalletSeed::seed_file_exists(&data_dir_name);
if let Ok(true) = exists {
let msg = format!("Wallet seed already exists at: {}", data_dir_name);
return Err(ErrorKind::WalletSeedExists(msg))?;
if !test_mode {
if let Ok(true) = exists {
let msg = format!("Wallet seed already exists at: {}", data_dir_name);
return Err(ErrorKind::WalletSeedExists(msg))?;
}
}
let _ = WalletSeed::init_file(&data_dir_name, mnemonic_length, mnemonic, password);
info!("Wallet seed file created");
@@ -75,6 +75,7 @@ where
mnemonic: Option<ZeroingString>,
mnemonic_length: usize,
password: ZeroingString,
test_mode: bool,
) -> Result<(), Error>;

///
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.