Less cloning and additional pattern simplifications (#326)

* API cleanup

* Config cleanup

* Impl cleanup

* Libwallet cleanup

* Additionnal simplification
This commit is contained in:
Quentin Le Sceller
2020-02-07 09:39:56 +00:00
committed by GitHub
parent 2d264db91a
commit 1116bc5545
35 changed files with 554 additions and 616 deletions
+23 -23
View File
@@ -121,10 +121,10 @@ where
/// let mut wallet_config = WalletConfig::default();
/// # let dir = tempdir().map_err(|e| format!("{:#?}", e)).unwrap();
/// # let dir = dir
/// # .path()
/// # .to_str()
/// # .ok_or("Failed to convert tmpdir path to string.".to_owned())
/// # .unwrap();
/// # .path()
/// # .to_str()
/// # .ok_or("Failed to convert tmpdir path to string.".to_owned())
/// # .unwrap();
/// # wallet_config.data_file_dir = dir.to_owned();
///
/// // A NodeClient must first be created to handle communication between
@@ -137,7 +137,7 @@ where
/// // These traits can be replaced with alternative implementations if desired
///
/// let mut wallet = Box::new(DefaultWalletImpl::<'static, HTTPNodeClient>::new(node_client.clone()).unwrap())
/// as Box<WalletInst<'static, DefaultLCProvider<HTTPNodeClient, ExtKeychain>, HTTPNodeClient, ExtKeychain>>;
/// as Box<WalletInst<'static, DefaultLCProvider<HTTPNodeClient, ExtKeychain>, HTTPNodeClient, ExtKeychain>>;
///
/// // Wallet LifeCycle Provider provides all functions init wallet and work with seeds, etc...
/// let lc = wallet.lc_provider().unwrap();
@@ -236,17 +236,17 @@ where
/// let mut api_foreign = Foreign::new(wallet.clone(), None, None);
///
/// let block_fees = BlockFees {
/// fees: 800000,
/// height: 234323,
/// key_id: None,
/// fees: 800000,
/// height: 234323,
/// key_id: None,
/// };
/// // Build a new coinbase output
///
/// let res = api_foreign.build_coinbase(&block_fees);
/// let res = api_foreign.build_coinbase(&block_fees);
///
/// if let Ok(cb_data) = res {
/// // cb_data is populated with coinbase output info
/// // ...
/// // cb_data is populated with coinbase output info
/// // ...
/// }
/// ```
@@ -294,13 +294,13 @@ where
/// # let slate = Slate::blank(2);
/// // Receive a slate via some means
///
/// let res = api_foreign.verify_slate_messages(&slate);
/// let res = api_foreign.verify_slate_messages(&slate);
///
/// if let Err(e) = res {
/// // Messages don't validate, likely return an error
/// // ...
/// // Messages don't validate, likely return an error
/// // ...
/// } else {
/// // Slate messages are fine
/// // Slate messages are fine
/// }
///
///
@@ -370,8 +370,8 @@ where
/// let result = api_foreign.receive_tx(&slate, None, None);
///
/// if let Ok(slate) = result {
/// // Send back to recipient somehow
/// // ...
/// // Send back to recipient somehow
/// // ...
/// }
/// ```
@@ -433,15 +433,15 @@ where
/// // . . .
/// // Issue the invoice tx via the owner API
/// let args = IssueInvoiceTxArgs {
/// amount: 10_000_000_000,
/// ..Default::default()
/// amount: 10_000_000_000,
/// ..Default::default()
/// };
/// let result = api_owner.issue_invoice_tx(None, args);
///
/// // If result okay, send to payer, who will apply the transaction via their
/// // owner API, then send back the slate
/// // ...
/// # let slate = Slate::blank(2);
/// // If result okay, send to payer, who will apply the transaction via their
/// // owner API, then send back the slate
/// // ...
/// # let slate = Slate::blank(2);
///
/// let slate = api_foreign.finalize_invoice_tx(&slate);
/// // if okay, then post via the owner API
+1 -3
View File
@@ -674,9 +674,7 @@ pub fn run_doctest_foreign(
let _ = lc.set_top_level_directory(&format!("{}/wallet2", test_dir));
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)
.unwrap();
let mask2 = lc.open_wallet(None, empty_string, use_token, true).unwrap();
let wallet2 = Arc::new(Mutex::new(wallet2));
wallet_proxy.add_wallet(
+186 -186
View File
@@ -127,10 +127,10 @@ where
/// let mut wallet_config = WalletConfig::default();
/// # let dir = tempdir().map_err(|e| format!("{:#?}", e)).unwrap();
/// # let dir = dir
/// # .path()
/// # .to_str()
/// # .ok_or("Failed to convert tmpdir path to string.".to_owned())
/// # .unwrap();
/// # .path()
/// # .to_str()
/// # .ok_or("Failed to convert tmpdir path to string.".to_owned())
/// # .unwrap();
/// # wallet_config.data_file_dir = dir.to_owned();
///
/// // A NodeClient must first be created to handle communication between
@@ -143,7 +143,7 @@ where
/// // These traits can be replaced with alternative implementations if desired
///
/// let mut wallet = Box::new(DefaultWalletImpl::<'static, HTTPNodeClient>::new(node_client.clone()).unwrap())
/// as Box<WalletInst<'static, DefaultLCProvider<HTTPNodeClient, ExtKeychain>, HTTPNodeClient, ExtKeychain>>;
/// as Box<WalletInst<'static, DefaultLCProvider<HTTPNodeClient, ExtKeychain>, HTTPNodeClient, ExtKeychain>>;
///
/// // Wallet LifeCycle Provider provides all functions init wallet and work with seeds, etc...
/// let lc = wallet.lc_provider().unwrap();
@@ -236,7 +236,7 @@ where
/// let result = api_owner.accounts(None);
///
/// if let Ok(accts) = result {
/// //...
/// //...
/// }
/// ```
@@ -287,7 +287,7 @@ where
/// let result = api_owner.create_account_path(None, "account1");
///
/// if let Ok(identifier) = result {
/// //...
/// //...
/// }
/// ```
@@ -334,8 +334,8 @@ where
/// let result = api_owner.create_account_path(None, "account1");
///
/// if let Ok(identifier) = result {
/// // set the account active
/// let result2 = api_owner.set_active_account(None, "account1");
/// // set the account active
/// let result2 = api_owner.set_active_account(None, "account1");
/// }
/// ```
@@ -393,7 +393,7 @@ where
/// let result = api_owner.retrieve_outputs(None, show_spent, update_from_node, tx_id);
///
/// if let Ok((was_updated, output_mappings)) = result {
/// //...
/// //...
/// }
/// ```
@@ -462,7 +462,7 @@ where
/// let result = api_owner.retrieve_txs(None, update_from_node, tx_id, tx_slate_id);
///
/// if let Ok((was_updated, tx_log_entries)) = result {
/// //...
/// //...
/// }
/// ```
@@ -538,7 +538,7 @@ where
/// let result = api_owner.retrieve_summary_info(None, update_from_node, minimum_confirmations);
///
/// if let Ok((was_updated, summary_info)) = result {
/// //...
/// //...
/// }
/// ```
@@ -619,25 +619,25 @@ where
/// let mut api_owner = Owner::new(wallet.clone(), None);
/// // Attempt to create a transaction using the 'default' account
/// let args = InitTxArgs {
/// src_acct_name: None,
/// amount: 2_000_000_000,
/// minimum_confirmations: 2,
/// max_outputs: 500,
/// num_change_outputs: 1,
/// selection_strategy_is_use_all: false,
/// message: Some("Have some Grins. Love, Yeastplume".to_owned()),
/// ..Default::default()
/// src_acct_name: None,
/// amount: 2_000_000_000,
/// minimum_confirmations: 2,
/// max_outputs: 500,
/// num_change_outputs: 1,
/// selection_strategy_is_use_all: false,
/// message: Some("Have some Grins. Love, Yeastplume".to_owned()),
/// ..Default::default()
/// };
/// let result = api_owner.init_send_tx(
/// None,
/// args,
/// None,
/// args,
/// );
///
/// if let Ok(slate) = result {
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// api_owner.tx_lock_outputs(None, &slate, 0);
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// api_owner.tx_lock_outputs(None, &slate, 0);
/// }
/// ```
@@ -710,14 +710,14 @@ where
/// let mut api_owner = Owner::new(wallet.clone(), None);
///
/// let args = IssueInvoiceTxArgs {
/// amount: 60_000_000_000,
/// ..Default::default()
/// amount: 60_000_000_000,
/// ..Default::default()
/// };
/// let result = api_owner.issue_invoice_tx(None, args);
///
/// if let Ok(slate) = result {
/// // if okay, send to the payer to add their inputs
/// // . . .
/// // if okay, send to the payer to add their inputs
/// // . . .
/// }
/// ```
pub fn issue_invoice_tx(
@@ -768,21 +768,21 @@ where
/// // The slate has been recieved from the invoicer, somehow
/// # let slate = Slate::blank(2);
/// let args = InitTxArgs {
/// src_acct_name: None,
/// amount: slate.amount,
/// minimum_confirmations: 2,
/// max_outputs: 500,
/// num_change_outputs: 1,
/// selection_strategy_is_use_all: false,
/// ..Default::default()
/// };
/// src_acct_name: None,
/// amount: slate.amount,
/// minimum_confirmations: 2,
/// max_outputs: 500,
/// num_change_outputs: 1,
/// selection_strategy_is_use_all: false,
/// ..Default::default()
/// };
///
/// let result = api_owner.process_invoice_tx(None, &slate, args);
///
/// if let Ok(slate) = result {
/// // If result okay, send back to the invoicer
/// // . . .
/// }
/// // If result okay, send back to the invoicer
/// // . . .
/// }
/// ```
pub fn process_invoice_tx(
@@ -829,25 +829,25 @@ where
///
/// let mut api_owner = Owner::new(wallet.clone(), None);
/// let args = InitTxArgs {
/// src_acct_name: None,
/// amount: 2_000_000_000,
/// minimum_confirmations: 10,
/// max_outputs: 500,
/// num_change_outputs: 1,
/// selection_strategy_is_use_all: false,
/// message: Some("Remember to lock this when we're happy this is sent".to_owned()),
/// ..Default::default()
/// src_acct_name: None,
/// amount: 2_000_000_000,
/// minimum_confirmations: 10,
/// max_outputs: 500,
/// num_change_outputs: 1,
/// selection_strategy_is_use_all: false,
/// message: Some("Remember to lock this when we're happy this is sent".to_owned()),
/// ..Default::default()
/// };
/// let result = api_owner.init_send_tx(
/// None,
/// args,
/// None,
/// args,
/// );
///
/// if let Ok(slate) = result {
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// api_owner.tx_lock_outputs(None, &slate, 0);
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// api_owner.tx_lock_outputs(None, &slate, 0);
/// }
/// ```
@@ -893,29 +893,29 @@ where
///
/// let mut api_owner = Owner::new(wallet.clone(), None);
/// let args = InitTxArgs {
/// src_acct_name: None,
/// amount: 2_000_000_000,
/// minimum_confirmations: 10,
/// max_outputs: 500,
/// num_change_outputs: 1,
/// selection_strategy_is_use_all: false,
/// message: Some("Finalize this tx now".to_owned()),
/// ..Default::default()
/// src_acct_name: None,
/// amount: 2_000_000_000,
/// minimum_confirmations: 10,
/// max_outputs: 500,
/// num_change_outputs: 1,
/// selection_strategy_is_use_all: false,
/// message: Some("Finalize this tx now".to_owned()),
/// ..Default::default()
/// };
/// let result = api_owner.init_send_tx(
/// None,
/// args,
/// None,
/// args,
/// );
///
/// if let Ok(slate) = result {
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// let res = api_owner.tx_lock_outputs(None, &slate, 0);
/// //
/// // Retrieve slate back from recipient
/// //
/// let res = api_owner.finalize_tx(None, &slate);
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// let res = api_owner.tx_lock_outputs(None, &slate, 0);
/// //
/// // Retrieve slate back from recipient
/// //
/// let res = api_owner.finalize_tx(None, &slate);
/// }
/// ```
@@ -953,30 +953,30 @@ where
///
/// let mut api_owner = Owner::new(wallet.clone(), None);
/// let args = InitTxArgs {
/// src_acct_name: None,
/// amount: 2_000_000_000,
/// minimum_confirmations: 10,
/// max_outputs: 500,
/// num_change_outputs: 1,
/// selection_strategy_is_use_all: false,
/// message: Some("Post this tx".to_owned()),
/// ..Default::default()
/// src_acct_name: None,
/// amount: 2_000_000_000,
/// minimum_confirmations: 10,
/// max_outputs: 500,
/// num_change_outputs: 1,
/// selection_strategy_is_use_all: false,
/// message: Some("Post this tx".to_owned()),
/// ..Default::default()
/// };
/// let result = api_owner.init_send_tx(
/// None,
/// args,
/// None,
/// args,
/// );
///
/// if let Ok(slate) = result {
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// let res = api_owner.tx_lock_outputs(None, &slate, 0);
/// //
/// // Retrieve slate back from recipient
/// //
/// let res = api_owner.finalize_tx(None, &slate);
/// let res = api_owner.post_tx(None, &slate.tx, true);
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// let res = api_owner.tx_lock_outputs(None, &slate, 0);
/// //
/// // Retrieve slate back from recipient
/// //
/// let res = api_owner.finalize_tx(None, &slate);
/// let res = api_owner.post_tx(None, &slate.tx, true);
/// }
/// ```
@@ -1025,29 +1025,29 @@ where
///
/// let mut api_owner = Owner::new(wallet.clone(), None);
/// let args = InitTxArgs {
/// src_acct_name: None,
/// amount: 2_000_000_000,
/// minimum_confirmations: 10,
/// max_outputs: 500,
/// num_change_outputs: 1,
/// selection_strategy_is_use_all: false,
/// message: Some("Cancel this tx".to_owned()),
/// ..Default::default()
/// src_acct_name: None,
/// amount: 2_000_000_000,
/// minimum_confirmations: 10,
/// max_outputs: 500,
/// num_change_outputs: 1,
/// selection_strategy_is_use_all: false,
/// message: Some("Cancel this tx".to_owned()),
/// ..Default::default()
/// };
/// let result = api_owner.init_send_tx(
/// None,
/// args,
/// None,
/// args,
/// );
///
/// if let Ok(slate) = result {
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// let res = api_owner.tx_lock_outputs(None, &slate, 0);
/// //
/// // We didn't get the slate back, or something else went wrong
/// //
/// let res = api_owner.cancel_tx(None, None, Some(slate.id.clone()));
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// let res = api_owner.tx_lock_outputs(None, &slate, 0);
/// //
/// // We didn't get the slate back, or something else went wrong
/// //
/// let res = api_owner.cancel_tx(None, None, Some(slate.id.clone()));
/// }
/// ```
@@ -1098,8 +1098,8 @@ where
/// let result = api_owner.retrieve_txs(None, update_from_node, tx_id, tx_slate_id);
///
/// if let Ok((was_updated, tx_log_entries)) = result {
/// let stored_tx = api_owner.get_stored_tx(None, &tx_log_entries[0]).unwrap();
/// //...
/// let stored_tx = api_owner.get_stored_tx(None, &tx_log_entries[0]).unwrap();
/// //...
/// }
/// ```
@@ -1141,29 +1141,29 @@ where
///
/// let mut api_owner = Owner::new(wallet.clone(), None);
/// let args = InitTxArgs {
/// src_acct_name: None,
/// amount: 2_000_000_000,
/// minimum_confirmations: 10,
/// max_outputs: 500,
/// num_change_outputs: 1,
/// selection_strategy_is_use_all: false,
/// message: Some("Just verify messages".to_owned()),
/// ..Default::default()
/// src_acct_name: None,
/// amount: 2_000_000_000,
/// minimum_confirmations: 10,
/// max_outputs: 500,
/// num_change_outputs: 1,
/// selection_strategy_is_use_all: false,
/// message: Some("Just verify messages".to_owned()),
/// ..Default::default()
/// };
/// let result = api_owner.init_send_tx(
/// None,
/// args,
/// None,
/// args,
/// );
///
/// if let Ok(slate) = result {
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// let res = api_owner.tx_lock_outputs(None, &slate, 0);
/// //
/// // Retrieve slate back from recipient
/// //
/// let res = api_owner.verify_slate_messages(None, &slate);
/// // Send slate somehow
/// // ...
/// // Lock our outputs if we're happy the slate was (or is being) sent
/// let res = api_owner.tx_lock_outputs(None, &slate, 0);
/// //
/// // Retrieve slate back from recipient
/// //
/// let res = api_owner.verify_slate_messages(None, &slate);
/// }
/// ```
pub fn verify_slate_messages(
@@ -1221,14 +1221,14 @@ where
///
/// let mut api_owner = Owner::new(wallet.clone(), None);
/// let result = api_owner.scan(
/// None,
/// Some(20000),
/// false,
/// None,
/// Some(20000),
/// false,
/// );
///
/// if let Ok(_) = result {
/// // Wallet outputs should be consistent with what's on chain
/// // ...
/// // Wallet outputs should be consistent with what's on chain
/// // ...
/// }
/// ```
@@ -1281,11 +1281,11 @@ where
/// let result = api_owner.node_height(None);
///
/// if let Ok(node_height_result) = result {
/// if node_height_result.updated_from_node {
/// //we can assume node_height_result.height is relatively safe to use
/// if node_height_result.updated_from_node {
/// //we can assume node_height_result.height is relatively safe to use
///
/// }
/// //...
/// }
/// //...
/// }
/// ```
@@ -1338,8 +1338,8 @@ where
/// let result = api_owner.get_top_level_directory();
///
/// if let Ok(dir) = result {
/// println!("Top level directory is: {}", dir);
/// //...
/// println!("Top level directory is: {}", dir);
/// //...
/// }
/// ```
@@ -1377,16 +1377,16 @@ where
///
/// # let dir = tempdir().map_err(|e| format!("{:#?}", e)).unwrap();
/// # let dir = dir
/// # .path()
/// # .to_str()
/// # .ok_or("Failed to convert tmpdir path to string.".to_owned())
/// # .unwrap();
/// # .path()
/// # .to_str()
/// # .ok_or("Failed to convert tmpdir path to string.".to_owned())
/// # .unwrap();
///
/// let api_owner = Owner::new(wallet.clone(), None);
/// let result = api_owner.set_top_level_directory(dir);
///
/// if let Ok(dir) = result {
/// //...
/// //...
/// }
/// ```
@@ -1427,10 +1427,10 @@ where
///
/// # let dir = tempdir().map_err(|e| format!("{:#?}", e)).unwrap();
/// # let dir = dir
/// # .path()
/// # .to_str()
/// # .ok_or("Failed to convert tmpdir path to string.".to_owned())
/// # .unwrap();
/// # .path()
/// # .to_str()
/// # .ok_or("Failed to convert tmpdir path to string.".to_owned())
/// # .unwrap();
///
/// let api_owner = Owner::new(wallet.clone(), None);
/// let _ = api_owner.set_top_level_directory(dir);
@@ -1438,7 +1438,7 @@ where
/// let result = api_owner.create_config(&ChainTypes::Mainnet, None, None, None);
///
/// if let Ok(_) = result {
/// //...
/// //...
/// }
/// ```
@@ -1490,29 +1490,29 @@ where
///
/// use grin_core::global::ChainTypes;
///
/// // note that the WalletInst struct does not necessarily need to contain an
/// // instantiated wallet
/// // note that the WalletInst struct does not necessarily need to contain an
/// // instantiated wallet
///
/// let dir = "path/to/wallet/dir";
///
/// # let dir = tempdir().map_err(|e| format!("{:#?}", e)).unwrap();
/// # let dir = dir
/// # .path()
/// # .to_str()
/// # .ok_or("Failed to convert tmpdir path to string.".to_owned())
/// # .unwrap();
/// # .path()
/// # .to_str()
/// # .ok_or("Failed to convert tmpdir path to string.".to_owned())
/// # .unwrap();
/// let api_owner = Owner::new(wallet.clone(), None);
/// let _ = api_owner.set_top_level_directory(dir);
///
/// // Create configuration
/// let result = api_owner.create_config(&ChainTypes::Mainnet, None, None, None);
///
/// // create new wallet wirh random seed
/// let pw = ZeroingString::from("my_password");
/// // create new wallet wirh random seed
/// let pw = ZeroingString::from("my_password");
/// let result = api_owner.create_wallet(None, None, 0, pw);
///
/// if let Ok(r) = result {
/// //...
/// //...
/// }
/// ```
@@ -1558,31 +1558,31 @@ where
///
/// use grin_core::global::ChainTypes;
///
/// // note that the WalletInst struct does not necessarily need to contain an
/// // instantiated wallet
/// // note that the WalletInst struct does not necessarily need to contain an
/// // instantiated wallet
/// let dir = "path/to/wallet/dir";
///
/// # let dir = tempdir().map_err(|e| format!("{:#?}", e)).unwrap();
/// # let dir = dir
/// # .path()
/// # .to_str()
/// # .ok_or("Failed to convert tmpdir path to string.".to_owned())
/// # .unwrap();
/// # .path()
/// # .to_str()
/// # .ok_or("Failed to convert tmpdir path to string.".to_owned())
/// # .unwrap();
/// let api_owner = Owner::new(wallet.clone(), None);
/// let _ = api_owner.set_top_level_directory(dir);
///
/// // Create configuration
/// let result = api_owner.create_config(&ChainTypes::Mainnet, None, None, None);
///
/// // create new wallet wirh random seed
/// let pw = ZeroingString::from("my_password");
/// // create new wallet wirh random seed
/// let pw = ZeroingString::from("my_password");
/// let _ = api_owner.create_wallet(None, None, 0, pw.clone());
///
/// let result = api_owner.open_wallet(None, pw, true);
///
/// if let Ok(m) = result {
/// // use this mask in all subsequent calls
/// let mask = m;
/// // use this mask in all subsequent calls
/// let mask = m;
/// }
/// ```
@@ -1626,13 +1626,13 @@ where
///
/// use grin_core::global::ChainTypes;
///
/// // Set up as above
/// // Set up as above
/// # let api_owner = Owner::new(wallet.clone(), None);
///
/// let res = api_owner.close_wallet(None);
///
/// if let Ok(_) = res {
/// // ...
/// // ...
/// }
/// ```
@@ -1662,14 +1662,14 @@ where
///
/// use grin_core::global::ChainTypes;
///
/// // Set up as above
/// // Set up as above
/// # let api_owner = Owner::new(wallet.clone(), None);
///
/// let pw = ZeroingString::from("my_password");
/// let pw = ZeroingString::from("my_password");
/// let res = api_owner.get_mnemonic(None, pw);
///
/// if let Ok(mne) = res {
/// // ...
/// // ...
/// }
/// ```
pub fn get_mnemonic(
@@ -1707,15 +1707,15 @@ where
///
/// use grin_core::global::ChainTypes;
///
/// // Set up as above
/// // Set up as above
/// # let api_owner = Owner::new(wallet.clone(), None);
///
/// let old = ZeroingString::from("my_password");
/// let new = ZeroingString::from("new_password");
/// let old = ZeroingString::from("my_password");
/// let new = ZeroingString::from("new_password");
/// let res = api_owner.change_password(None, old, new);
///
/// if let Ok(mne) = res {
/// // ...
/// // ...
/// }
/// ```
pub fn change_password(
@@ -1750,13 +1750,13 @@ where
///
/// use grin_core::global::ChainTypes;
///
/// // Set up as above
/// // Set up as above
/// # let api_owner = Owner::new(wallet.clone(), None);
///
/// let res = api_owner.delete_wallet(None);
///
/// if let Ok(_) = res {
/// // ...
/// // ...
/// }
/// ```
@@ -2066,7 +2066,7 @@ where
/// let result = api_owner.retrieve_payment_proof(None, update_from_node, tx_id, tx_slate_id);
///
/// if let Ok(p) = result {
/// //...
/// //...
/// }
/// ```
@@ -2137,10 +2137,10 @@ where
/// // The proof will likely be exported as JSON to be provided to another party
///
/// if let Ok(p) = result {
/// let valid = api_owner.verify_payment_proof(None, &p);
/// if let Ok(_) = valid {
/// //...
/// }
/// let valid = api_owner.verify_payment_proof(None, &p);
/// if let Ok(_) = valid {
/// //...
/// }
/// }
/// ```
+3 -5
View File
@@ -1344,7 +1344,7 @@ where
fn get_stored_tx(&self, tx: &TxLogEntry) -> Result<Option<TransactionV3>, ErrorKind> {
Owner::get_stored_tx(self, None, tx)
.map(|x| x.map(|y| TransactionV3::from(y)))
.map(|x| x.map(TransactionV3::from))
.map_err(|e| e.kind())
}
@@ -1458,9 +1458,7 @@ pub fn run_doctest_owner(
let _ = lc.set_top_level_directory(&format!("{}/wallet2", test_dir));
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)
.unwrap();
let mask2 = lc.open_wallet(None, empty_string, use_token, true).unwrap();
let wallet2 = Arc::new(Mutex::new(wallet2));
if mask2.is_some() {
@@ -1558,7 +1556,7 @@ pub fn run_doctest_owner(
}
if payment_proof {
let _ = api_impl::owner::post_tx(&client1, &slate_outer.tx, true).unwrap();
api_impl::owner::post_tx(&client1, &slate_outer.tx, true).unwrap();
}
if perform_tx && lock_tx && finalize_tx {
+6 -8
View File
@@ -2130,7 +2130,7 @@ where
tx: &TxLogEntry,
) -> Result<Option<TransactionV3>, ErrorKind> {
Owner::get_stored_tx(self, (&token.keychain_mask).as_ref(), tx)
.map(|x| x.map(|y| TransactionV3::from(y)))
.map(|x| x.map(TransactionV3::from))
.map_err(|e| e.kind())
}
@@ -2173,21 +2173,19 @@ where
let secp = secp_inst.lock();
let sec_key = SecretKey::new(&secp, &mut thread_rng());
let mut shared_pubkey = ecdh_pubkey.ecdh_pubkey.clone();
let mut shared_pubkey = ecdh_pubkey.ecdh_pubkey;
shared_pubkey
.mul_assign(&secp, &sec_key)
.map_err(|e| ErrorKind::Secp(e))?;
.map_err(ErrorKind::Secp)?;
let x_coord = shared_pubkey.serialize_vec(&secp, true);
let shared_key =
SecretKey::from_slice(&secp, &x_coord[1..]).map_err(|e| ErrorKind::Secp(e))?;
let shared_key = SecretKey::from_slice(&secp, &x_coord[1..]).map_err(ErrorKind::Secp)?;
{
let mut s = self.shared_key.lock();
*s = Some(shared_key);
}
let pub_key =
PublicKey::from_secret_key(&secp, &sec_key).map_err(|e| ErrorKind::Secp(e))?;
let pub_key = PublicKey::from_secret_key(&secp, &sec_key).map_err(ErrorKind::Secp)?;
Ok(ECDHPubkey {
ecdh_pubkey: pub_key,
@@ -2247,7 +2245,7 @@ where
let n = name.as_ref().map(|s| s.as_str());
let res =
Owner::get_mnemonic(self, n, ZeroingString::from(password)).map_err(|e| e.kind())?;
Ok(format!("{}", &*res))
Ok((&*res).to_string())
}
fn change_password(