2019-11-18 13:49:51 +03:00
|
|
|
// Copyright 2019 The Grin Develope;
|
2019-03-17 22:14:58 +03:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
//! Generic implementation of owner API functions
|
|
|
|
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
2019-03-26 19:02:31 +03:00
|
|
|
use crate::grin_core::core::hash::Hashed;
|
|
|
|
use crate::grin_core::core::Transaction;
|
|
|
|
use crate::grin_core::ser;
|
|
|
|
use crate::grin_util;
|
2019-08-06 14:50:41 +03:00
|
|
|
use crate::grin_util::secp::key::SecretKey;
|
2019-11-06 13:04:42 +03:00
|
|
|
use crate::grin_util::Mutex;
|
2019-03-17 22:14:58 +03:00
|
|
|
|
2019-11-18 13:49:51 +03:00
|
|
|
use crate::api_impl::owner_updater::StatusMessage;
|
2019-03-26 19:02:31 +03:00
|
|
|
use crate::grin_keychain::{Identifier, Keychain};
|
2019-11-06 13:04:42 +03:00
|
|
|
use crate::internal::{keys, scan, selection, tx, updater};
|
2019-03-17 22:14:58 +03:00
|
|
|
use crate::slate::Slate;
|
2019-04-25 09:59:45 +03:00
|
|
|
use crate::types::{AcctPathMapping, NodeClient, TxLogEntry, TxWrapper, WalletBackend, WalletInfo};
|
2019-05-01 22:12:23 +03:00
|
|
|
use crate::{
|
2019-11-06 13:04:42 +03:00
|
|
|
wallet_lock, InitTxArgs, IssueInvoiceTxArgs, NodeHeightResult, OutputCommitMapping,
|
|
|
|
ScannedBlockInfo, TxLogEntryType, WalletInitStatus, WalletInst, WalletLCProvider,
|
2019-05-01 22:12:23 +03:00
|
|
|
};
|
2019-11-06 13:04:42 +03:00
|
|
|
use crate::{Error, ErrorKind};
|
2019-11-18 13:49:51 +03:00
|
|
|
use std::sync::mpsc::Sender;
|
2019-11-06 13:04:42 +03:00
|
|
|
use std::sync::Arc;
|
2019-03-17 22:14:58 +03:00
|
|
|
|
|
|
|
const USER_MESSAGE_MAX_LEN: usize = 256;
|
|
|
|
|
|
|
|
/// List of accounts
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
pub fn accounts<'a, T: ?Sized, C, K>(w: &mut T) -> Result<Vec<AcctPathMapping>, Error>
|
2019-03-17 22:14:58 +03:00
|
|
|
where
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
T: WalletBackend<'a, C, K>,
|
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
2019-03-17 22:14:58 +03:00
|
|
|
{
|
|
|
|
keys::accounts(&mut *w)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// new account path
|
2019-08-06 14:50:41 +03:00
|
|
|
pub fn create_account_path<'a, T: ?Sized, C, K>(
|
|
|
|
w: &mut T,
|
|
|
|
keychain_mask: Option<&SecretKey>,
|
|
|
|
label: &str,
|
|
|
|
) -> Result<Identifier, Error>
|
2019-03-17 22:14:58 +03:00
|
|
|
where
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
T: WalletBackend<'a, C, K>,
|
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
2019-03-17 22:14:58 +03:00
|
|
|
{
|
2019-08-06 14:50:41 +03:00
|
|
|
keys::new_acct_path(&mut *w, keychain_mask, label)
|
2019-03-17 22:14:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// set active account
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
pub fn set_active_account<'a, T: ?Sized, C, K>(w: &mut T, label: &str) -> Result<(), Error>
|
2019-03-17 22:14:58 +03:00
|
|
|
where
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
T: WalletBackend<'a, C, K>,
|
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
2019-03-17 22:14:58 +03:00
|
|
|
{
|
|
|
|
w.set_parent_key_id_by_name(label)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// retrieve outputs
|
2019-11-06 13:04:42 +03:00
|
|
|
pub fn retrieve_outputs<'a, L, C, K>(
|
|
|
|
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
2019-08-06 14:50:41 +03:00
|
|
|
keychain_mask: Option<&SecretKey>,
|
2019-11-18 13:49:51 +03:00
|
|
|
status_send_channel: &Option<Sender<StatusMessage>>,
|
2019-03-17 22:14:58 +03:00
|
|
|
include_spent: bool,
|
|
|
|
refresh_from_node: bool,
|
|
|
|
tx_id: Option<u32>,
|
2019-03-22 15:03:25 +03:00
|
|
|
) -> Result<(bool, Vec<OutputCommitMapping>), Error>
|
2019-03-17 22:14:58 +03:00
|
|
|
where
|
2019-11-06 13:04:42 +03:00
|
|
|
L: WalletLCProvider<'a, C, K>,
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
2019-03-17 22:14:58 +03:00
|
|
|
{
|
|
|
|
let mut validated = false;
|
|
|
|
if refresh_from_node {
|
2019-11-18 13:49:51 +03:00
|
|
|
validated = update_wallet_state(
|
|
|
|
wallet_inst.clone(),
|
|
|
|
keychain_mask,
|
|
|
|
status_send_channel,
|
|
|
|
false,
|
|
|
|
)?;
|
2019-03-17 22:14:58 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 13:04:42 +03:00
|
|
|
wallet_lock!(wallet_inst, w);
|
|
|
|
let parent_key_id = w.parent_key_id();
|
|
|
|
|
2019-03-17 22:14:58 +03:00
|
|
|
Ok((
|
|
|
|
validated,
|
2019-08-06 14:50:41 +03:00
|
|
|
updater::retrieve_outputs(
|
2019-11-06 13:04:42 +03:00
|
|
|
&mut **w,
|
2019-08-06 14:50:41 +03:00
|
|
|
keychain_mask,
|
|
|
|
include_spent,
|
|
|
|
tx_id,
|
|
|
|
Some(&parent_key_id),
|
|
|
|
)?,
|
2019-03-17 22:14:58 +03:00
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Retrieve txs
|
2019-11-06 13:04:42 +03:00
|
|
|
pub fn retrieve_txs<'a, L, C, K>(
|
|
|
|
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
2019-08-06 14:50:41 +03:00
|
|
|
keychain_mask: Option<&SecretKey>,
|
2019-11-18 13:49:51 +03:00
|
|
|
status_send_channel: &Option<Sender<StatusMessage>>,
|
2019-03-17 22:14:58 +03:00
|
|
|
refresh_from_node: bool,
|
|
|
|
tx_id: Option<u32>,
|
|
|
|
tx_slate_id: Option<Uuid>,
|
|
|
|
) -> Result<(bool, Vec<TxLogEntry>), Error>
|
|
|
|
where
|
2019-11-06 13:04:42 +03:00
|
|
|
L: WalletLCProvider<'a, C, K>,
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
2019-03-17 22:14:58 +03:00
|
|
|
{
|
|
|
|
let mut validated = false;
|
|
|
|
if refresh_from_node {
|
2019-11-18 13:49:51 +03:00
|
|
|
validated = update_wallet_state(
|
|
|
|
wallet_inst.clone(),
|
|
|
|
keychain_mask,
|
|
|
|
status_send_channel,
|
|
|
|
false,
|
|
|
|
)?;
|
2019-03-17 22:14:58 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 13:04:42 +03:00
|
|
|
wallet_lock!(wallet_inst, w);
|
|
|
|
let parent_key_id = w.parent_key_id();
|
|
|
|
let txs = updater::retrieve_txs(&mut **w, tx_id, tx_slate_id, Some(&parent_key_id), false)?;
|
2019-09-24 11:56:10 +03:00
|
|
|
|
|
|
|
Ok((validated, txs))
|
2019-03-17 22:14:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Retrieve summary info
|
2019-11-06 13:04:42 +03:00
|
|
|
pub fn retrieve_summary_info<'a, L, C, K>(
|
|
|
|
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
2019-08-06 14:50:41 +03:00
|
|
|
keychain_mask: Option<&SecretKey>,
|
2019-11-18 13:49:51 +03:00
|
|
|
status_send_channel: &Option<Sender<StatusMessage>>,
|
2019-03-17 22:14:58 +03:00
|
|
|
refresh_from_node: bool,
|
|
|
|
minimum_confirmations: u64,
|
|
|
|
) -> Result<(bool, WalletInfo), Error>
|
|
|
|
where
|
2019-11-06 13:04:42 +03:00
|
|
|
L: WalletLCProvider<'a, C, K>,
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
2019-03-17 22:14:58 +03:00
|
|
|
{
|
|
|
|
let mut validated = false;
|
|
|
|
if refresh_from_node {
|
2019-11-18 13:49:51 +03:00
|
|
|
validated = update_wallet_state(
|
|
|
|
wallet_inst.clone(),
|
|
|
|
keychain_mask,
|
|
|
|
status_send_channel,
|
|
|
|
false,
|
|
|
|
)?;
|
2019-03-17 22:14:58 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 13:04:42 +03:00
|
|
|
wallet_lock!(wallet_inst, w);
|
|
|
|
let parent_key_id = w.parent_key_id();
|
|
|
|
let wallet_info = updater::retrieve_info(&mut **w, &parent_key_id, minimum_confirmations)?;
|
2019-03-17 22:14:58 +03:00
|
|
|
Ok((validated, wallet_info))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Initiate tx as sender
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
pub fn init_send_tx<'a, T: ?Sized, C, K>(
|
2019-03-17 22:14:58 +03:00
|
|
|
w: &mut T,
|
2019-08-06 14:50:41 +03:00
|
|
|
keychain_mask: Option<&SecretKey>,
|
2019-03-29 19:00:02 +03:00
|
|
|
args: InitTxArgs,
|
2019-03-22 15:03:25 +03:00
|
|
|
use_test_rng: bool,
|
2019-03-17 22:14:58 +03:00
|
|
|
) -> Result<Slate, Error>
|
|
|
|
where
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
T: WalletBackend<'a, C, K>,
|
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
2019-03-17 22:14:58 +03:00
|
|
|
{
|
2019-03-29 19:00:02 +03:00
|
|
|
let parent_key_id = match args.src_acct_name {
|
2019-03-17 22:14:58 +03:00
|
|
|
Some(d) => {
|
2019-03-29 19:00:02 +03:00
|
|
|
let pm = w.get_acct_path(d)?;
|
2019-03-17 22:14:58 +03:00
|
|
|
match pm {
|
|
|
|
Some(p) => p.path,
|
|
|
|
None => w.parent_key_id(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => w.parent_key_id(),
|
|
|
|
};
|
|
|
|
|
2019-03-29 19:00:02 +03:00
|
|
|
let message = match args.message {
|
2019-03-17 22:14:58 +03:00
|
|
|
Some(mut m) => {
|
|
|
|
m.truncate(USER_MESSAGE_MAX_LEN);
|
|
|
|
Some(m)
|
|
|
|
}
|
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
|
2019-03-29 19:00:02 +03:00
|
|
|
let mut slate = tx::new_tx_slate(&mut *w, args.amount, 2, use_test_rng)?;
|
|
|
|
|
|
|
|
// if we just want to estimate, don't save a context, just send the results
|
|
|
|
// back
|
|
|
|
if let Some(true) = args.estimate_only {
|
|
|
|
let (total, fee) = tx::estimate_send_tx(
|
|
|
|
&mut *w,
|
2019-08-06 14:50:41 +03:00
|
|
|
keychain_mask,
|
2019-03-29 19:00:02 +03:00
|
|
|
args.amount,
|
|
|
|
args.minimum_confirmations,
|
|
|
|
args.max_outputs as usize,
|
|
|
|
args.num_change_outputs as usize,
|
|
|
|
args.selection_strategy_is_use_all,
|
|
|
|
&parent_key_id,
|
|
|
|
)?;
|
|
|
|
slate.amount = total;
|
|
|
|
slate.fee = fee;
|
|
|
|
return Ok(slate);
|
|
|
|
}
|
2019-03-17 22:14:58 +03:00
|
|
|
|
|
|
|
let context = tx::add_inputs_to_slate(
|
|
|
|
&mut *w,
|
2019-08-06 14:50:41 +03:00
|
|
|
keychain_mask,
|
2019-03-17 22:14:58 +03:00
|
|
|
&mut slate,
|
2019-03-29 19:00:02 +03:00
|
|
|
args.minimum_confirmations,
|
|
|
|
args.max_outputs as usize,
|
|
|
|
args.num_change_outputs as usize,
|
|
|
|
args.selection_strategy_is_use_all,
|
2019-03-17 22:14:58 +03:00
|
|
|
&parent_key_id,
|
|
|
|
0,
|
|
|
|
message,
|
2019-05-01 22:12:23 +03:00
|
|
|
true,
|
2019-03-22 15:03:25 +03:00
|
|
|
use_test_rng,
|
2019-03-17 22:14:58 +03:00
|
|
|
)?;
|
|
|
|
|
|
|
|
// Save the aggsig context in our DB for when we
|
|
|
|
// recieve the transaction back
|
|
|
|
{
|
2019-08-06 14:50:41 +03:00
|
|
|
let mut batch = w.batch(keychain_mask)?;
|
2019-05-23 18:27:57 +03:00
|
|
|
batch.save_private_context(slate.id.as_bytes(), 0, &context)?;
|
2019-03-17 22:14:58 +03:00
|
|
|
batch.commit()?;
|
|
|
|
}
|
2019-03-29 19:00:02 +03:00
|
|
|
if let Some(v) = args.target_slate_version {
|
2019-03-17 22:14:58 +03:00
|
|
|
slate.version_info.orig_version = v;
|
|
|
|
}
|
|
|
|
Ok(slate)
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:12:23 +03:00
|
|
|
/// Initiate a transaction as the recipient (invoicing)
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
pub fn issue_invoice_tx<'a, T: ?Sized, C, K>(
|
2019-05-01 22:12:23 +03:00
|
|
|
w: &mut T,
|
2019-08-06 14:50:41 +03:00
|
|
|
keychain_mask: Option<&SecretKey>,
|
2019-05-01 22:12:23 +03:00
|
|
|
args: IssueInvoiceTxArgs,
|
|
|
|
use_test_rng: bool,
|
|
|
|
) -> Result<Slate, Error>
|
|
|
|
where
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
T: WalletBackend<'a, C, K>,
|
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
2019-05-01 22:12:23 +03:00
|
|
|
{
|
|
|
|
let parent_key_id = match args.dest_acct_name {
|
|
|
|
Some(d) => {
|
|
|
|
let pm = w.get_acct_path(d)?;
|
|
|
|
match pm {
|
|
|
|
Some(p) => p.path,
|
|
|
|
None => w.parent_key_id(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => w.parent_key_id(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let message = match args.message {
|
|
|
|
Some(mut m) => {
|
|
|
|
m.truncate(USER_MESSAGE_MAX_LEN);
|
|
|
|
Some(m)
|
|
|
|
}
|
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut slate = tx::new_tx_slate(&mut *w, args.amount, 2, use_test_rng)?;
|
|
|
|
let context = tx::add_output_to_slate(
|
|
|
|
&mut *w,
|
2019-08-06 14:50:41 +03:00
|
|
|
keychain_mask,
|
2019-05-01 22:12:23 +03:00
|
|
|
&mut slate,
|
|
|
|
&parent_key_id,
|
|
|
|
1,
|
|
|
|
message,
|
|
|
|
true,
|
|
|
|
use_test_rng,
|
|
|
|
)?;
|
|
|
|
|
|
|
|
// Save the aggsig context in our DB for when we
|
|
|
|
// recieve the transaction back
|
|
|
|
{
|
2019-08-06 14:50:41 +03:00
|
|
|
let mut batch = w.batch(keychain_mask)?;
|
2019-05-23 18:27:57 +03:00
|
|
|
batch.save_private_context(slate.id.as_bytes(), 1, &context)?;
|
2019-05-01 22:12:23 +03:00
|
|
|
batch.commit()?;
|
|
|
|
}
|
|
|
|
|
2019-05-31 10:33:23 +03:00
|
|
|
if let Some(v) = args.target_slate_version {
|
|
|
|
slate.version_info.orig_version = v;
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:12:23 +03:00
|
|
|
Ok(slate)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Receive an invoice tx, essentially adding inputs to whatever
|
|
|
|
/// output was specified
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
pub fn process_invoice_tx<'a, T: ?Sized, C, K>(
|
2019-05-01 22:12:23 +03:00
|
|
|
w: &mut T,
|
2019-08-06 14:50:41 +03:00
|
|
|
keychain_mask: Option<&SecretKey>,
|
2019-05-01 22:12:23 +03:00
|
|
|
slate: &Slate,
|
|
|
|
args: InitTxArgs,
|
|
|
|
use_test_rng: bool,
|
|
|
|
) -> Result<Slate, Error>
|
|
|
|
where
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
T: WalletBackend<'a, C, K>,
|
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
2019-05-01 22:12:23 +03:00
|
|
|
{
|
|
|
|
let mut ret_slate = slate.clone();
|
|
|
|
let parent_key_id = match args.src_acct_name {
|
|
|
|
Some(d) => {
|
|
|
|
let pm = w.get_acct_path(d.to_owned())?;
|
|
|
|
match pm {
|
|
|
|
Some(p) => p.path,
|
|
|
|
None => w.parent_key_id(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => w.parent_key_id(),
|
|
|
|
};
|
|
|
|
// Don't do this multiple times
|
|
|
|
let tx = updater::retrieve_txs(
|
|
|
|
&mut *w,
|
|
|
|
None,
|
|
|
|
Some(ret_slate.id),
|
|
|
|
Some(&parent_key_id),
|
|
|
|
use_test_rng,
|
|
|
|
)?;
|
|
|
|
for t in &tx {
|
|
|
|
if t.tx_type == TxLogEntryType::TxSent {
|
|
|
|
return Err(ErrorKind::TransactionAlreadyReceived(ret_slate.id.to_string()).into());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let message = match args.message {
|
|
|
|
Some(mut m) => {
|
|
|
|
m.truncate(USER_MESSAGE_MAX_LEN);
|
|
|
|
Some(m)
|
|
|
|
}
|
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
|
2019-05-21 12:00:19 +03:00
|
|
|
// update slate current height
|
2019-11-05 00:10:05 +03:00
|
|
|
ret_slate.height = w.w2n_client().get_chain_tip()?.0;
|
2019-05-21 12:00:19 +03:00
|
|
|
|
2019-05-01 22:12:23 +03:00
|
|
|
let context = tx::add_inputs_to_slate(
|
|
|
|
&mut *w,
|
2019-08-06 14:50:41 +03:00
|
|
|
keychain_mask,
|
2019-05-01 22:12:23 +03:00
|
|
|
&mut ret_slate,
|
|
|
|
args.minimum_confirmations,
|
|
|
|
args.max_outputs as usize,
|
|
|
|
args.num_change_outputs as usize,
|
|
|
|
args.selection_strategy_is_use_all,
|
|
|
|
&parent_key_id,
|
|
|
|
0,
|
|
|
|
message,
|
|
|
|
false,
|
|
|
|
use_test_rng,
|
|
|
|
)?;
|
|
|
|
|
|
|
|
// Save the aggsig context in our DB for when we
|
|
|
|
// recieve the transaction back
|
|
|
|
{
|
2019-08-06 14:50:41 +03:00
|
|
|
let mut batch = w.batch(keychain_mask)?;
|
2019-05-23 18:27:57 +03:00
|
|
|
batch.save_private_context(slate.id.as_bytes(), 0, &context)?;
|
2019-05-01 22:12:23 +03:00
|
|
|
batch.commit()?;
|
|
|
|
}
|
|
|
|
|
2019-05-31 10:33:23 +03:00
|
|
|
if let Some(v) = args.target_slate_version {
|
|
|
|
ret_slate.version_info.orig_version = v;
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:12:23 +03:00
|
|
|
Ok(ret_slate)
|
|
|
|
}
|
|
|
|
|
2019-03-17 22:14:58 +03:00
|
|
|
/// Lock sender outputs
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
pub fn tx_lock_outputs<'a, T: ?Sized, C, K>(
|
2019-05-23 18:27:57 +03:00
|
|
|
w: &mut T,
|
2019-08-06 14:50:41 +03:00
|
|
|
keychain_mask: Option<&SecretKey>,
|
2019-05-23 18:27:57 +03:00
|
|
|
slate: &Slate,
|
|
|
|
participant_id: usize,
|
|
|
|
) -> Result<(), Error>
|
2019-03-17 22:14:58 +03:00
|
|
|
where
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
T: WalletBackend<'a, C, K>,
|
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
2019-03-17 22:14:58 +03:00
|
|
|
{
|
2019-08-06 14:50:41 +03:00
|
|
|
let context = w.get_private_context(keychain_mask, slate.id.as_bytes(), participant_id)?;
|
|
|
|
selection::lock_tx_context(&mut *w, keychain_mask, slate, &context)
|
2019-03-17 22:14:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Finalize slate
|
2019-08-06 14:50:41 +03:00
|
|
|
pub fn finalize_tx<'a, T: ?Sized, C, K>(
|
|
|
|
w: &mut T,
|
|
|
|
keychain_mask: Option<&SecretKey>,
|
|
|
|
slate: &Slate,
|
|
|
|
) -> Result<Slate, Error>
|
2019-03-17 22:14:58 +03:00
|
|
|
where
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
T: WalletBackend<'a, C, K>,
|
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
2019-03-17 22:14:58 +03:00
|
|
|
{
|
2019-03-22 15:03:25 +03:00
|
|
|
let mut sl = slate.clone();
|
2019-08-06 14:50:41 +03:00
|
|
|
let context = w.get_private_context(keychain_mask, sl.id.as_bytes(), 0)?;
|
|
|
|
tx::complete_tx(&mut *w, keychain_mask, &mut sl, 0, &context)?;
|
2019-09-24 11:56:10 +03:00
|
|
|
tx::update_stored_tx(&mut *w, keychain_mask, &mut sl, false)?;
|
2019-08-06 14:50:41 +03:00
|
|
|
tx::update_message(&mut *w, keychain_mask, &mut sl)?;
|
2019-03-17 22:14:58 +03:00
|
|
|
{
|
2019-08-06 14:50:41 +03:00
|
|
|
let mut batch = w.batch(keychain_mask)?;
|
2019-05-23 18:27:57 +03:00
|
|
|
batch.delete_private_context(sl.id.as_bytes(), 0)?;
|
2019-03-17 22:14:58 +03:00
|
|
|
batch.commit()?;
|
|
|
|
}
|
2019-03-22 15:03:25 +03:00
|
|
|
Ok(sl)
|
2019-03-17 22:14:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// cancel tx
|
2019-11-06 13:04:42 +03:00
|
|
|
pub fn cancel_tx<'a, L, C, K>(
|
|
|
|
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
2019-08-06 14:50:41 +03:00
|
|
|
keychain_mask: Option<&SecretKey>,
|
2019-11-18 13:49:51 +03:00
|
|
|
status_send_channel: &Option<Sender<StatusMessage>>,
|
2019-03-17 22:14:58 +03:00
|
|
|
tx_id: Option<u32>,
|
|
|
|
tx_slate_id: Option<Uuid>,
|
|
|
|
) -> Result<(), Error>
|
|
|
|
where
|
2019-11-06 13:04:42 +03:00
|
|
|
L: WalletLCProvider<'a, C, K>,
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
2019-03-17 22:14:58 +03:00
|
|
|
{
|
2019-11-18 13:49:51 +03:00
|
|
|
if !update_wallet_state(
|
|
|
|
wallet_inst.clone(),
|
|
|
|
keychain_mask,
|
|
|
|
status_send_channel,
|
|
|
|
false,
|
|
|
|
)? {
|
2019-03-17 22:14:58 +03:00
|
|
|
return Err(ErrorKind::TransactionCancellationError(
|
|
|
|
"Can't contact running Grin node. Not Cancelling.",
|
|
|
|
))?;
|
|
|
|
}
|
2019-11-06 13:04:42 +03:00
|
|
|
wallet_lock!(wallet_inst, w);
|
|
|
|
let parent_key_id = w.parent_key_id();
|
|
|
|
tx::cancel_tx(&mut **w, keychain_mask, &parent_key_id, tx_id, tx_slate_id)
|
2019-03-17 22:14:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// get stored tx
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
pub fn get_stored_tx<'a, T: ?Sized, C, K>(
|
2019-03-17 22:14:58 +03:00
|
|
|
w: &T,
|
|
|
|
entry: &TxLogEntry,
|
|
|
|
) -> Result<Option<Transaction>, Error>
|
|
|
|
where
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
T: WalletBackend<'a, C, K>,
|
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
2019-03-17 22:14:58 +03:00
|
|
|
{
|
|
|
|
w.get_stored_tx(entry)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Posts a transaction to the chain
|
|
|
|
/// take a client impl instead of wallet so as not to have to lock the wallet
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
pub fn post_tx<'a, C>(client: &C, tx: &Transaction, fluff: bool) -> Result<(), Error>
|
2019-03-17 22:14:58 +03:00
|
|
|
where
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
C: NodeClient + 'a,
|
2019-03-17 22:14:58 +03:00
|
|
|
{
|
2019-09-26 10:33:33 +03:00
|
|
|
let tx_hex = grin_util::to_hex(ser::ser_vec(tx, ser::ProtocolVersion(1)).unwrap());
|
2019-03-17 22:14:58 +03:00
|
|
|
let res = client.post_tx(&TxWrapper { tx_hex: tx_hex }, fluff);
|
|
|
|
if let Err(e) = res {
|
|
|
|
error!("api: post_tx: failed with error: {}", e);
|
|
|
|
Err(e)
|
|
|
|
} else {
|
|
|
|
debug!(
|
|
|
|
"api: post_tx: successfully posted tx: {}, fluff? {}",
|
|
|
|
tx.hash(),
|
|
|
|
fluff
|
|
|
|
);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// verify slate messages
|
|
|
|
pub fn verify_slate_messages(slate: &Slate) -> Result<(), Error> {
|
|
|
|
slate.verify_messages()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// check repair
|
2019-11-06 13:04:42 +03:00
|
|
|
/// Accepts a wallet inst instead of a raw wallet so it can
|
|
|
|
/// lock as little as possible
|
|
|
|
pub fn scan<'a, L, C, K>(
|
|
|
|
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
2019-08-06 14:50:41 +03:00
|
|
|
keychain_mask: Option<&SecretKey>,
|
2019-11-06 13:04:42 +03:00
|
|
|
start_height: Option<u64>,
|
2019-08-06 14:50:41 +03:00
|
|
|
delete_unconfirmed: bool,
|
2019-11-18 13:49:51 +03:00
|
|
|
status_send_channel: &Option<Sender<StatusMessage>>,
|
2019-08-06 14:50:41 +03:00
|
|
|
) -> Result<(), Error>
|
2019-03-17 22:14:58 +03:00
|
|
|
where
|
2019-11-06 13:04:42 +03:00
|
|
|
L: WalletLCProvider<'a, C, K>,
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
2019-03-17 22:14:58 +03:00
|
|
|
{
|
2019-11-06 13:04:42 +03:00
|
|
|
update_outputs(wallet_inst.clone(), keychain_mask, true)?;
|
|
|
|
let tip = {
|
|
|
|
wallet_lock!(wallet_inst, w);
|
|
|
|
w.w2n_client().get_chain_tip()?
|
|
|
|
};
|
|
|
|
|
|
|
|
let start_height = match start_height {
|
|
|
|
Some(h) => h,
|
|
|
|
None => 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut info = scan::scan(
|
|
|
|
wallet_inst.clone(),
|
|
|
|
keychain_mask,
|
|
|
|
delete_unconfirmed,
|
|
|
|
start_height,
|
|
|
|
tip.0,
|
2019-11-18 13:49:51 +03:00
|
|
|
status_send_channel,
|
2019-11-06 13:04:42 +03:00
|
|
|
)?;
|
2019-11-05 00:10:05 +03:00
|
|
|
info.hash = tip.1;
|
|
|
|
|
2019-11-06 13:04:42 +03:00
|
|
|
wallet_lock!(wallet_inst, w);
|
2019-11-05 00:10:05 +03:00
|
|
|
let mut batch = w.batch(keychain_mask)?;
|
|
|
|
batch.save_last_scanned_block(info)?;
|
|
|
|
batch.commit()?;
|
|
|
|
|
|
|
|
Ok(())
|
2019-03-17 22:14:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// node height
|
2019-11-06 13:04:42 +03:00
|
|
|
pub fn node_height<'a, L, C, K>(
|
|
|
|
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
2019-08-06 14:50:41 +03:00
|
|
|
keychain_mask: Option<&SecretKey>,
|
|
|
|
) -> Result<NodeHeightResult, Error>
|
2019-03-17 22:14:58 +03:00
|
|
|
where
|
2019-11-06 13:04:42 +03:00
|
|
|
L: WalletLCProvider<'a, C, K>,
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
2019-03-17 22:14:58 +03:00
|
|
|
{
|
2019-11-06 13:04:42 +03:00
|
|
|
let res = {
|
|
|
|
wallet_lock!(wallet_inst, w);
|
|
|
|
w.w2n_client().get_chain_tip()
|
|
|
|
};
|
2019-03-17 22:14:58 +03:00
|
|
|
match res {
|
2019-11-05 00:10:05 +03:00
|
|
|
Ok(r) => Ok(NodeHeightResult {
|
|
|
|
height: r.0,
|
|
|
|
header_hash: r.1,
|
2019-03-29 19:00:02 +03:00
|
|
|
updated_from_node: true,
|
|
|
|
}),
|
2019-03-17 22:14:58 +03:00
|
|
|
Err(_) => {
|
2019-11-18 13:49:51 +03:00
|
|
|
let outputs = retrieve_outputs(wallet_inst, keychain_mask, &None, true, false, None)?;
|
2019-03-22 15:03:25 +03:00
|
|
|
let height = match outputs.1.iter().map(|m| m.output.height).max() {
|
2019-03-17 22:14:58 +03:00
|
|
|
Some(height) => height,
|
|
|
|
None => 0,
|
|
|
|
};
|
2019-03-29 19:00:02 +03:00
|
|
|
Ok(NodeHeightResult {
|
|
|
|
height,
|
2019-11-05 00:10:05 +03:00
|
|
|
header_hash: "".to_owned(),
|
2019-03-29 19:00:02 +03:00
|
|
|
updated_from_node: false,
|
|
|
|
})
|
2019-03-17 22:14:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-05 00:10:05 +03:00
|
|
|
/// Experimental, wrap the entire definition of how a wallet's state is updated
|
2019-11-18 13:49:51 +03:00
|
|
|
pub fn update_wallet_state<'a, L, C, K>(
|
2019-11-06 13:04:42 +03:00
|
|
|
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
2019-11-05 00:10:05 +03:00
|
|
|
keychain_mask: Option<&SecretKey>,
|
2019-11-18 13:49:51 +03:00
|
|
|
status_send_channel: &Option<Sender<StatusMessage>>,
|
2019-11-05 00:10:05 +03:00
|
|
|
update_all: bool,
|
|
|
|
) -> Result<bool, Error>
|
|
|
|
where
|
2019-11-06 13:04:42 +03:00
|
|
|
L: WalletLCProvider<'a, C, K>,
|
2019-11-05 00:10:05 +03:00
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
|
|
|
{
|
2019-11-06 13:04:42 +03:00
|
|
|
let parent_key_id = {
|
|
|
|
wallet_lock!(wallet_inst, w);
|
|
|
|
w.parent_key_id().clone()
|
|
|
|
};
|
|
|
|
let client = {
|
|
|
|
wallet_lock!(wallet_inst, w);
|
|
|
|
w.w2n_client().clone()
|
|
|
|
};
|
|
|
|
|
2019-11-05 00:10:05 +03:00
|
|
|
// Step 1: Update outputs and transactions purely based on UTXO state
|
2019-11-18 13:49:51 +03:00
|
|
|
if let Some(ref s) = status_send_channel {
|
|
|
|
let _ = s.send(StatusMessage::UpdatingOutputs(
|
|
|
|
"Updating outputs from node".to_owned(),
|
|
|
|
));
|
|
|
|
}
|
2019-11-06 13:04:42 +03:00
|
|
|
let mut result = update_outputs(wallet_inst.clone(), keychain_mask, update_all)?;
|
|
|
|
|
2019-11-05 00:10:05 +03:00
|
|
|
if !result {
|
2019-11-18 13:49:51 +03:00
|
|
|
if let Some(ref s) = status_send_channel {
|
|
|
|
let _ = s.send(StatusMessage::UpdateWarning(
|
|
|
|
"Updater Thread unable to contact node".to_owned(),
|
|
|
|
));
|
|
|
|
}
|
2019-11-05 00:10:05 +03:00
|
|
|
return Ok(result);
|
|
|
|
}
|
|
|
|
|
2019-11-18 13:49:51 +03:00
|
|
|
if let Some(ref s) = status_send_channel {
|
|
|
|
let _ = s.send(StatusMessage::UpdatingTransactions(
|
|
|
|
"Updating transactions".to_owned(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2019-11-05 00:10:05 +03:00
|
|
|
// Step 2: Update outstanding transactions with no change outputs by kernel
|
2019-11-06 13:04:42 +03:00
|
|
|
let mut txs = {
|
|
|
|
wallet_lock!(wallet_inst, w);
|
|
|
|
updater::retrieve_txs(&mut **w, None, None, Some(&parent_key_id), true)?
|
|
|
|
};
|
|
|
|
result = update_txs_via_kernel(wallet_inst.clone(), keychain_mask, &mut txs)?;
|
2019-11-05 00:10:05 +03:00
|
|
|
if !result {
|
2019-11-18 13:49:51 +03:00
|
|
|
if let Some(ref s) = status_send_channel {
|
|
|
|
let _ = s.send(StatusMessage::UpdateWarning(
|
|
|
|
"Updater Thread unable to contact node".to_owned(),
|
|
|
|
));
|
|
|
|
}
|
2019-11-05 00:10:05 +03:00
|
|
|
return Ok(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step 3: Scan back a bit on the chain
|
2019-11-06 13:04:42 +03:00
|
|
|
let res = client.get_chain_tip();
|
|
|
|
// if we can't get the tip, don't continue
|
|
|
|
let tip = match res {
|
|
|
|
Ok(t) => t,
|
2019-11-18 13:49:51 +03:00
|
|
|
Err(_) => {
|
|
|
|
if let Some(ref s) = status_send_channel {
|
|
|
|
let _ = s.send(StatusMessage::UpdateWarning(
|
|
|
|
"Updater Thread unable to contact node".to_owned(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
return Ok(false);
|
|
|
|
}
|
2019-11-06 13:04:42 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Check if this is a restored wallet that needs a full scan
|
|
|
|
let last_scanned_block = {
|
|
|
|
wallet_lock!(wallet_inst, w);
|
|
|
|
match w.init_status()? {
|
|
|
|
WalletInitStatus::InitNeedsScanning => ScannedBlockInfo {
|
|
|
|
height: 0,
|
|
|
|
hash: "".to_owned(),
|
|
|
|
start_pmmr_index: 0,
|
|
|
|
last_pmmr_index: 0,
|
|
|
|
},
|
|
|
|
WalletInitStatus::InitNoScanning => ScannedBlockInfo {
|
|
|
|
height: tip.clone().0,
|
|
|
|
hash: tip.clone().1,
|
|
|
|
start_pmmr_index: 0,
|
|
|
|
last_pmmr_index: 0,
|
|
|
|
},
|
|
|
|
WalletInitStatus::InitComplete => w.last_scanned_block()?,
|
|
|
|
}
|
|
|
|
};
|
2019-11-05 00:10:05 +03:00
|
|
|
|
|
|
|
let start_index = last_scanned_block.height.saturating_sub(100);
|
|
|
|
|
|
|
|
if last_scanned_block.height == 0 {
|
2019-11-18 13:49:51 +03:00
|
|
|
let msg = format!("This wallet's contents has not been initialized with a full chain scan, performing scan now.
|
|
|
|
This operation may take a while for the first scan, but should be much quicker once the initial scan is done.");
|
|
|
|
if let Some(ref s) = status_send_channel {
|
|
|
|
let _ = s.send(StatusMessage::FullScanWarn(msg));
|
|
|
|
}
|
2019-11-05 00:10:05 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 13:04:42 +03:00
|
|
|
let mut info = scan::scan(
|
|
|
|
wallet_inst.clone(),
|
|
|
|
keychain_mask,
|
|
|
|
false,
|
|
|
|
start_index,
|
|
|
|
tip.0,
|
2019-11-18 13:49:51 +03:00
|
|
|
status_send_channel,
|
2019-11-06 13:04:42 +03:00
|
|
|
)?;
|
|
|
|
|
2019-11-05 00:10:05 +03:00
|
|
|
info.hash = tip.1;
|
|
|
|
|
2019-11-06 13:04:42 +03:00
|
|
|
wallet_lock!(wallet_inst, w);
|
2019-11-05 00:10:05 +03:00
|
|
|
let mut batch = w.batch(keychain_mask)?;
|
|
|
|
batch.save_last_scanned_block(info)?;
|
2019-11-06 13:04:42 +03:00
|
|
|
// init considered complete after first successful update
|
|
|
|
batch.save_init_status(WalletInitStatus::InitComplete)?;
|
2019-11-05 00:10:05 +03:00
|
|
|
batch.commit()?;
|
|
|
|
|
|
|
|
Ok(result)
|
|
|
|
}
|
2019-03-17 22:14:58 +03:00
|
|
|
|
|
|
|
/// Attempt to update outputs in wallet, return whether it was successful
|
2019-11-06 13:04:42 +03:00
|
|
|
fn update_outputs<'a, L, C, K>(
|
|
|
|
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
2019-08-06 14:50:41 +03:00
|
|
|
keychain_mask: Option<&SecretKey>,
|
|
|
|
update_all: bool,
|
2019-08-13 11:36:21 +03:00
|
|
|
) -> Result<bool, Error>
|
2019-03-17 22:14:58 +03:00
|
|
|
where
|
2019-11-06 13:04:42 +03:00
|
|
|
L: WalletLCProvider<'a, C, K>,
|
Merge milestone/2.1.0 into master (#199)
* version bump for next potential release
* Merge master into milestone/2.1.0 (#182)
* Derive --version output dynamically from cargo package version (#174)
* add --txid to the `wallet txs` command (#176)
* add --txid to the `wallet txs` command
* add test for `wallet txs` command with `--txid` parameter
* Refactor - Split WalletCommAdapter into multiple traits (#180)
* Derive --version output dynamically from cargo package version (#174)
* add server auth argument to http client
* Revert "add server auth argument to http client"
This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.
* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing
* Split WalletCommAdapter into four traits, one for each of its intended behaviors.
* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
* Remove unused "params" argument from listen method.
* Re-add previously existing TODO comment
* Fix non-test build
* completely Fix non-test build
* Full Lifecycle API Support (#184)
* refactoring wallet lib traits
* rustfmt
* rustfmt
* add new files
* explicit lifetime specifiers on all wallet traits
* rustfmt
* modify apis to use new walletinst
* rustfmt
* converting controller crate
* rustfmt
* controller crate compiling
* rustfmt
* compilation
* rustfmt
* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl
* rustfmt
* full compilation, changing recovery + init to new model
* rustfmt
* wallet initialisation working, init command output and flow identical to v2.0.0 wallet
* rustfmt
* fix listener and owner api startup
* rustfmt
* rustfmt
* move encryption test
* rustfmt
* fix api doctests
* rustfmt
* fix for most tests in controller crate
* rustfmt
* fix for check tests in controller crate
* fix main wallet tests
* rustfmt
* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow
* rustfmt
* update keybase adapter to use new wallet format
* rustfmt
* test fix
* remove debug output
2019-07-29 15:25:03 +03:00
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
2019-03-17 22:14:58 +03:00
|
|
|
{
|
2019-11-06 13:04:42 +03:00
|
|
|
wallet_lock!(wallet_inst, w);
|
2019-03-17 22:14:58 +03:00
|
|
|
let parent_key_id = w.parent_key_id();
|
2019-11-06 13:04:42 +03:00
|
|
|
match updater::refresh_outputs(&mut **w, keychain_mask, &parent_key_id, update_all) {
|
2019-08-13 11:36:21 +03:00
|
|
|
Ok(_) => Ok(true),
|
|
|
|
Err(e) => {
|
|
|
|
if let ErrorKind::InvalidKeychainMask = e.kind() {
|
|
|
|
return Err(e);
|
|
|
|
}
|
|
|
|
Ok(false)
|
|
|
|
}
|
2019-03-17 22:14:58 +03:00
|
|
|
}
|
|
|
|
}
|
2019-09-24 11:56:10 +03:00
|
|
|
|
|
|
|
/// Update transactions that need to be validated via kernel lookup
|
2019-11-06 13:04:42 +03:00
|
|
|
fn update_txs_via_kernel<'a, L, C, K>(
|
|
|
|
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
2019-09-24 11:56:10 +03:00
|
|
|
keychain_mask: Option<&SecretKey>,
|
|
|
|
txs: &mut Vec<TxLogEntry>,
|
|
|
|
) -> Result<bool, Error>
|
|
|
|
where
|
2019-11-06 13:04:42 +03:00
|
|
|
L: WalletLCProvider<'a, C, K>,
|
2019-09-24 11:56:10 +03:00
|
|
|
C: NodeClient + 'a,
|
|
|
|
K: Keychain + 'a,
|
|
|
|
{
|
2019-11-06 13:04:42 +03:00
|
|
|
let parent_key_id = {
|
|
|
|
wallet_lock!(wallet_inst, w);
|
|
|
|
w.parent_key_id().clone()
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut client = {
|
|
|
|
wallet_lock!(wallet_inst, w);
|
|
|
|
w.w2n_client().clone()
|
|
|
|
};
|
|
|
|
|
|
|
|
let height = match client.get_chain_tip() {
|
2019-11-05 00:10:05 +03:00
|
|
|
Ok(h) => h.0,
|
2019-09-24 11:56:10 +03:00
|
|
|
Err(_) => return Ok(false),
|
|
|
|
};
|
2019-11-06 13:04:42 +03:00
|
|
|
|
2019-09-24 11:56:10 +03:00
|
|
|
for tx in txs.iter_mut() {
|
|
|
|
if tx.confirmed {
|
|
|
|
continue;
|
|
|
|
}
|
2019-10-03 17:15:25 +03:00
|
|
|
if tx.amount_debited != 0 && tx.amount_credited != 0 {
|
|
|
|
continue;
|
|
|
|
}
|
2019-09-24 11:56:10 +03:00
|
|
|
if let Some(e) = tx.kernel_excess {
|
2019-11-06 13:04:42 +03:00
|
|
|
let res = client.get_kernel(&e, tx.kernel_lookup_min_height, Some(height));
|
2019-09-24 11:56:10 +03:00
|
|
|
let kernel = match res {
|
|
|
|
Ok(k) => k,
|
|
|
|
Err(_) => return Ok(false),
|
|
|
|
};
|
|
|
|
if let Some(k) = kernel {
|
|
|
|
debug!("Kernel Retrieved: {:?}", k);
|
2019-11-06 13:04:42 +03:00
|
|
|
wallet_lock!(wallet_inst, w);
|
2019-09-24 11:56:10 +03:00
|
|
|
let mut batch = w.batch(keychain_mask)?;
|
|
|
|
tx.confirmed = true;
|
|
|
|
tx.update_confirmation_ts();
|
|
|
|
batch.save_tx_log_entry(tx.clone(), &parent_key_id)?;
|
|
|
|
batch.commit()?;
|
|
|
|
}
|
2019-10-03 17:15:25 +03:00
|
|
|
} else {
|
|
|
|
warn!("Attempted to update via kernel excess for transaction {:?}, but kernel excess was not stored", tx.tx_slate_id);
|
2019-09-24 11:56:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(true)
|
|
|
|
}
|