mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-12-04 04:43:58 +01:00
Merge upstream staging into contracts
Brings the branch current with staging for review.
- ed25519-dalek 1.0.0-pre.4 to 2: PublicKey is now VerifyingKey, Keypair
is replaced by SigningKey, and from_bytes takes a fixed-size array.
Ported the contract proof code and the V5 slate serializers, following
the pattern staging already uses in v4_bin.
- owner_single_use and foreign_single_use now take the wallet instance
and a config path rather than an optional API handle. Updated the
contract call sites in command.rs and the contract tests.
- update_tx_slate_state moved to api_impl::types; dropped the local copy.
- Took staging's fixed-size-array form of the slate signature guards; it
is equivalent to 25a5434 and keeps the file in sync with upstream.
- The grin node is now a submodule, so a build needs
git submodule update --init.
This commit is contained in:
+55
-41
@@ -14,9 +14,9 @@
|
||||
|
||||
//! Foreign API External Definition
|
||||
|
||||
use crate::config::TorConfig;
|
||||
use crate::keychain::Keychain;
|
||||
use crate::libwallet::api_impl::foreign;
|
||||
use crate::libwallet::api_impl::types::update_tx_slate_state;
|
||||
use crate::libwallet::contract::proofs::InvoiceProof;
|
||||
use crate::libwallet::contract::types::{ContractNewArgsAPI, ContractSetupArgsAPI};
|
||||
use crate::libwallet::{
|
||||
@@ -26,7 +26,7 @@ use crate::libwallet::{
|
||||
use crate::try_slatepack_sync_workflow;
|
||||
use crate::util::secp::key::SecretKey;
|
||||
use crate::util::Mutex;
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
use ed25519_dalek::VerifyingKey as DalekPublicKey;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// ForeignAPI Middleware Check callback
|
||||
@@ -69,15 +69,14 @@ where
|
||||
{
|
||||
/// Wallet instance
|
||||
pub wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
||||
/// Wallet configuration path
|
||||
config_path: crate::ConfigPath,
|
||||
/// Flag to normalize some output during testing. Can mostly be ignored.
|
||||
pub doctest_mode: bool,
|
||||
/// foreign check middleware
|
||||
middleware: Option<ForeignCheckMiddleware>,
|
||||
/// Stored keychain mask (in case the stored wallet seed is tokenized)
|
||||
keychain_mask: Option<SecretKey>,
|
||||
/// Optional TOR configuration, holding address of sender and
|
||||
/// data directory
|
||||
tor_config: Mutex<Option<TorConfig>>,
|
||||
}
|
||||
|
||||
impl<'a, L, C, K> Foreign<'a, L, C, K>
|
||||
@@ -97,6 +96,7 @@ where
|
||||
/// # Arguments
|
||||
/// * `wallet_in` - A reference-counted mutex containing an implementation of the
|
||||
/// [`WalletBackend`](../grin_wallet_libwallet/types/trait.WalletBackend.html) trait.
|
||||
/// * `config_path` - Path to the wallet configuration file
|
||||
/// * `keychain_mask` - Mask value stored internally to use when calling a wallet
|
||||
/// whose seed has been XORed with a token value (such as when running the foreign
|
||||
/// and owner listeners in the same instance)
|
||||
@@ -108,6 +108,7 @@ where
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use std::path::PathBuf;
|
||||
/// use grin_keychain as keychain;
|
||||
/// use grin_util as util;
|
||||
/// use grin_core;
|
||||
@@ -142,7 +143,7 @@ where
|
||||
///
|
||||
/// // A NodeClient must first be created to handle communication between
|
||||
/// // the wallet and the node.
|
||||
/// let node_client = HTTPNodeClient::new(&wallet_config.check_node_api_http_addr, None).unwrap();
|
||||
/// let node_client = HTTPNodeClient::new(&wallet_config.check_node_api_http_addr, None, wallet_config.api_request_timeout()).unwrap();
|
||||
///
|
||||
/// // impls::DefaultWalletImpl is provided for convenience in instantiating the wallet
|
||||
/// // It contains the LMDBBackend, DefaultLCProvider (lifecycle) and ExtKeychain used
|
||||
@@ -166,39 +167,30 @@ where
|
||||
/// // All wallet functions operate on an Arc::Mutex to allow multithreading where needed
|
||||
/// let mut wallet = Arc::new(Mutex::new(wallet));
|
||||
///
|
||||
/// let api_foreign = Foreign::new(wallet.clone(), None, None, false);
|
||||
/// let api_foreign = Foreign::new(wallet.clone(), PathBuf::from(dir).join("grin-wallet.toml"), None, None, false);
|
||||
/// // .. perform wallet operations
|
||||
///
|
||||
/// ```
|
||||
|
||||
pub fn new(
|
||||
pub fn new<P>(
|
||||
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
||||
config_path: P,
|
||||
keychain_mask: Option<SecretKey>,
|
||||
middleware: Option<ForeignCheckMiddleware>,
|
||||
doctest_mode: bool,
|
||||
) -> Self {
|
||||
) -> Self
|
||||
where
|
||||
P: Into<crate::ConfigPath>,
|
||||
{
|
||||
Foreign {
|
||||
wallet_inst,
|
||||
config_path: config_path.into(),
|
||||
doctest_mode,
|
||||
middleware,
|
||||
keychain_mask,
|
||||
tor_config: Mutex::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the TOR configuration for this instance of the ForeignAPI, used during
|
||||
/// `recieve_tx` when a return address is specified
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `tor_config` - The optional [TorConfig](#) to use
|
||||
/// # Returns
|
||||
/// * Nothing
|
||||
|
||||
pub fn set_tor_config(&self, tor_config: Option<TorConfig>) {
|
||||
let mut lock = self.tor_config.lock();
|
||||
*lock = tor_config;
|
||||
}
|
||||
|
||||
/// Return the version capabilities of the running ForeignApi Node
|
||||
/// # Arguments
|
||||
/// None
|
||||
@@ -209,7 +201,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env_foreign!(wallet, wallet_config);
|
||||
///
|
||||
/// let mut api_foreign = Foreign::new(wallet.clone(), None, None, false);
|
||||
/// let mut api_foreign = Foreign::new(wallet.clone(), std::path::PathBuf::from("grin-wallet.toml"), None, None, false);
|
||||
///
|
||||
/// let version_info = api_foreign.check_version();
|
||||
/// // check and proceed accordingly
|
||||
@@ -261,7 +253,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env_foreign!(wallet, wallet_config);
|
||||
///
|
||||
/// let mut api_foreign = Foreign::new(wallet.clone(), None, None, false);
|
||||
/// let mut api_foreign = Foreign::new(wallet.clone(), std::path::PathBuf::from("grin-wallet.toml"), None, None, false);
|
||||
///
|
||||
/// let block_fees = BlockFees {
|
||||
/// fees: 800000,
|
||||
@@ -336,7 +328,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env_foreign!(wallet, wallet_config);
|
||||
///
|
||||
/// let mut api_foreign = Foreign::new(wallet.clone(), None, None, false);
|
||||
/// let mut api_foreign = Foreign::new(wallet.clone(), std::path::PathBuf::from("grin-wallet.toml"), None, None, false);
|
||||
/// # let slate = Slate::blank(2, false);
|
||||
///
|
||||
/// // . . .
|
||||
@@ -356,6 +348,10 @@ where
|
||||
r_addr: Option<String>,
|
||||
) -> Result<Slate, Error> {
|
||||
let mut w_lock = self.wallet_inst.lock();
|
||||
let tor_config = r_addr
|
||||
.as_ref()
|
||||
.map(|_| crate::tor_config::load(&self.config_path.get()))
|
||||
.transpose()?;
|
||||
let w = w_lock.lc_provider()?.wallet_inst()?;
|
||||
if let Some(m) = self.middleware.as_ref() {
|
||||
m(
|
||||
@@ -373,18 +369,32 @@ where
|
||||
)?;
|
||||
match r_addr {
|
||||
Some(a) => {
|
||||
let tor_config_lock = self.tor_config.lock();
|
||||
let res = try_slatepack_sync_workflow(
|
||||
&ret_slate,
|
||||
&a,
|
||||
tor_config_lock.clone(),
|
||||
None,
|
||||
true,
|
||||
self.doctest_mode,
|
||||
);
|
||||
let tc = tor_config.ok_or_else(|| {
|
||||
Error::TorConfig("Tor config was not loaded with a return address".into())
|
||||
})?;
|
||||
let can_send = tc.send_tor(None);
|
||||
if self.doctest_mode || !can_send {
|
||||
return Ok(ret_slate);
|
||||
}
|
||||
let res = try_slatepack_sync_workflow(&ret_slate, &a, Some(tc), None, true);
|
||||
match res {
|
||||
Ok(s) => Ok(s.unwrap()),
|
||||
Err(_) => Ok(ret_slate),
|
||||
Ok(s) => {
|
||||
let parent_key_id = w.parent_key_id();
|
||||
match update_tx_slate_state(
|
||||
w,
|
||||
(&self.keychain_mask).as_ref(),
|
||||
&parent_key_id,
|
||||
&s,
|
||||
) {
|
||||
Ok(_) => {}
|
||||
Err(e) => error!("Error on updating slate state: {}", e),
|
||||
}
|
||||
Ok(s)
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Error on sending over Tor: {}", e);
|
||||
Ok(ret_slate)
|
||||
}
|
||||
}
|
||||
}
|
||||
None => Ok(ret_slate),
|
||||
@@ -419,8 +429,8 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env_foreign!(wallet, wallet_config);
|
||||
///
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let mut api_foreign = Foreign::new(wallet.clone(), None, None, false);
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let mut api_foreign = Foreign::new(wallet.clone(), std::path::PathBuf::from("grin-wallet.toml"), None, None, false);
|
||||
///
|
||||
/// // . . .
|
||||
/// // Issue the invoice tx via the owner API
|
||||
@@ -528,8 +538,12 @@ macro_rules! doctest_helper_setup_doc_env_foreign {
|
||||
wallet_config.data_file_dir = dir.to_owned();
|
||||
let pw = ZeroingString::from("");
|
||||
|
||||
let node_client =
|
||||
HTTPNodeClient::new(&wallet_config.check_node_api_http_addr, None).unwrap();
|
||||
let node_client = HTTPNodeClient::new(
|
||||
&wallet_config.check_node_api_http_addr,
|
||||
None,
|
||||
wallet_config.api_request_timeout(),
|
||||
)
|
||||
.unwrap();
|
||||
let mut wallet =
|
||||
Box::new(DefaultWalletImpl::<HTTPNodeClient>::new(node_client.clone()).unwrap())
|
||||
as Box<
|
||||
|
||||
+24
-2
@@ -21,6 +21,8 @@ use crate::libwallet::{
|
||||
};
|
||||
use crate::{Foreign, ForeignCheckMiddlewareFn};
|
||||
use easy_jsonrpc_mw;
|
||||
use grin_wallet_config::initial_setup_wallet;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Public definition used to generate Foreign jsonrpc api.
|
||||
/// * When running `grin-wallet listen` with defaults, the V2 api is available at
|
||||
@@ -365,6 +367,14 @@ pub fn run_doctest_foreign(
|
||||
let _ = fs::remove_dir_all(test_dir);
|
||||
global::set_local_chain_type(ChainTypes::AutomatedTesting);
|
||||
|
||||
let _ = fs::create_dir_all(test_dir);
|
||||
let config = initial_setup_wallet(
|
||||
&ChainTypes::AutomatedTesting,
|
||||
Some(PathBuf::from(test_dir)),
|
||||
false,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut wallet_proxy: WalletProxy<
|
||||
DefaultLCProvider<LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
@@ -513,8 +523,20 @@ pub fn run_doctest_foreign(
|
||||
}
|
||||
|
||||
let mut api_foreign = match init_invoice_tx {
|
||||
false => Foreign::new(wallet1, mask1, Some(test_check_middleware), true),
|
||||
true => Foreign::new(wallet2, mask2, Some(test_check_middleware), true),
|
||||
false => Foreign::new(
|
||||
wallet1,
|
||||
config.config_file_path,
|
||||
mask1,
|
||||
Some(test_check_middleware),
|
||||
true,
|
||||
),
|
||||
true => Foreign::new(
|
||||
wallet2,
|
||||
config.config_file_path,
|
||||
mask2,
|
||||
Some(test_check_middleware),
|
||||
true,
|
||||
),
|
||||
};
|
||||
api_foreign.doctest_mode = true;
|
||||
let foreign_api = &api_foreign as &dyn ForeignRpc;
|
||||
|
||||
@@ -42,12 +42,15 @@ mod foreign_rpc;
|
||||
mod owner;
|
||||
mod owner_rpc;
|
||||
|
||||
mod tor_config;
|
||||
mod types;
|
||||
|
||||
pub use crate::foreign::{Foreign, ForeignCheckMiddleware, ForeignCheckMiddlewareFn};
|
||||
pub use crate::foreign_rpc::ForeignRpc;
|
||||
pub use crate::owner::{try_slatepack_sync_workflow, Owner};
|
||||
pub use crate::owner_rpc::OwnerRpc;
|
||||
#[doc(hidden)]
|
||||
pub use crate::tor_config::ConfigPath;
|
||||
|
||||
pub use crate::foreign_rpc::foreign_rpc as foreign_rpc_client;
|
||||
pub use crate::foreign_rpc::run_doctest_foreign;
|
||||
|
||||
+263
-174
@@ -14,19 +14,14 @@
|
||||
|
||||
//! Owner API External Definition
|
||||
|
||||
use chrono::prelude::*;
|
||||
use ed25519_dalek::SecretKey as DalekSecretKey;
|
||||
use grin_wallet_libwallet::mwixnet::{MixnetReqCreationParams, SwapReq};
|
||||
use grin_wallet_libwallet::RetrieveTxQueryArgs;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::config::{TorConfig, WalletConfig};
|
||||
use crate::core::core::OutputFeatures;
|
||||
use crate::core::global;
|
||||
use crate::impls::HttpSlateSender;
|
||||
use crate::impls::SlateSender as _;
|
||||
use crate::impls::TorSlateSender;
|
||||
use crate::keychain::{Identifier, Keychain};
|
||||
use crate::libwallet::api_impl::owner_updater::{start_updater_log_thread, StatusMessage};
|
||||
use crate::libwallet::api_impl::types::update_tx_slate_state;
|
||||
use crate::libwallet::api_impl::{owner, owner_updater};
|
||||
use crate::libwallet::contract::proofs::InvoiceProof;
|
||||
use crate::libwallet::contract::types::{
|
||||
@@ -40,13 +35,25 @@ use crate::libwallet::{
|
||||
use crate::util::logger::LoggingConfig;
|
||||
use crate::util::secp::{key::SecretKey, pedersen::Commitment};
|
||||
use crate::util::{from_hex, static_secp_instance, Mutex, ZeroingString};
|
||||
use grin_wallet_config::config::{
|
||||
reload_global_config, update_global_config, WALLET_CONFIG_FILE_NAME,
|
||||
};
|
||||
use grin_wallet_libwallet::mwixnet::{MixnetReqCreationParams, SwapReq};
|
||||
use grin_wallet_libwallet::RetrieveTxQueryArgs;
|
||||
use grin_wallet_util::OnionV3Address;
|
||||
|
||||
use chrono::prelude::*;
|
||||
use ed25519_dalek::SigningKey as DalekSecretKey;
|
||||
use std::convert::TryFrom;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Main interface into all wallet API functions.
|
||||
/// Wallet APIs are split into two seperate blocks of functionality
|
||||
@@ -68,11 +75,13 @@ where
|
||||
C: NodeClient + 'static,
|
||||
K: Keychain + 'static,
|
||||
{
|
||||
/// contain all methods to manage the wallet
|
||||
/// Contains all methods to manage the wallet
|
||||
pub wallet_inst: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K>>>>,
|
||||
/// Wallet configuration path
|
||||
config_path: crate::ConfigPath,
|
||||
/// Flag to normalize some output during testing. Can mostly be ignored.
|
||||
pub doctest_mode: bool,
|
||||
/// retail TLD during doctest
|
||||
/// Retail TLD during doctest
|
||||
pub doctest_retain_tld: bool,
|
||||
/// Share ECDH key
|
||||
pub shared_key: Arc<Mutex<Option<SecretKey>>>,
|
||||
@@ -85,9 +94,6 @@ where
|
||||
/// Holds all update and status messages returned by the
|
||||
/// updater process
|
||||
updater_messages: Arc<Mutex<Vec<StatusMessage>>>,
|
||||
/// Optional TOR configuration, holding address of sender and
|
||||
/// data directory
|
||||
tor_config: Mutex<Option<TorConfig>>,
|
||||
}
|
||||
|
||||
impl<L, C, K> Owner<L, C, K>
|
||||
@@ -106,15 +112,17 @@ where
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `wallet_in` - A reference-counted mutex containing an implementation of the
|
||||
/// [`WalletBackend`](../grin_wallet_libwallet/types/trait.WalletBackend.html) trait.
|
||||
/// * `custom_channel` - A custom MPSC Tx/Rx pair to capture status
|
||||
/// updates
|
||||
/// [`WalletBackend`](../grin_wallet_libwallet/types/trait.WalletBackend.html) trait.
|
||||
/// * `config_path` - Path to the wallet configuration file
|
||||
///
|
||||
/// # Returns
|
||||
/// * An instance of the OwnerApi holding a reference to the provided wallet
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use std::path::PathBuf;
|
||||
/// use grin_keychain as keychain;
|
||||
/// use grin_util as util;
|
||||
/// use grin_core;
|
||||
@@ -148,7 +156,7 @@ where
|
||||
///
|
||||
/// // A NodeClient must first be created to handle communication between
|
||||
/// // the wallet and the node.
|
||||
/// let node_client = HTTPNodeClient::new(&wallet_config.check_node_api_http_addr, None).unwrap();
|
||||
/// let node_client = HTTPNodeClient::new(&wallet_config.check_node_api_http_addr, None, wallet_config.api_request_timeout()).unwrap();
|
||||
///
|
||||
/// // impls::DefaultWalletImpl is provided for convenience in instantiating the wallet
|
||||
/// // It contains the WalletBackend, DefaultLCProvider (lifecycle) and ExtKeychain used
|
||||
@@ -172,15 +180,19 @@ where
|
||||
/// // All wallet functions operate on an Arc::Mutex to allow multithreading where needed
|
||||
/// let mut wallet = Arc::new(Mutex::new(wallet));
|
||||
///
|
||||
/// let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let api_owner = Owner::new(wallet.clone(), None, PathBuf::from(dir).join("grin-wallet.toml"));
|
||||
/// // .. perform wallet operations
|
||||
///
|
||||
/// ```
|
||||
|
||||
pub fn new(
|
||||
pub fn new<P>(
|
||||
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K>>>>,
|
||||
custom_channel: Option<Sender<StatusMessage>>,
|
||||
) -> Self {
|
||||
config_path: P,
|
||||
) -> Self
|
||||
where
|
||||
P: Into<crate::ConfigPath>,
|
||||
{
|
||||
let updater_running = Arc::new(AtomicBool::new(false));
|
||||
let updater = Arc::new(Mutex::new(owner_updater::Updater::new(
|
||||
wallet_inst.clone(),
|
||||
@@ -199,6 +211,7 @@ where
|
||||
|
||||
Owner {
|
||||
wallet_inst,
|
||||
config_path: config_path.into(),
|
||||
doctest_mode: false,
|
||||
doctest_retain_tld: false,
|
||||
shared_key: Arc::new(Mutex::new(None)),
|
||||
@@ -206,21 +219,49 @@ where
|
||||
updater_running,
|
||||
status_tx: Mutex::new(Some(tx)),
|
||||
updater_messages,
|
||||
tor_config: Mutex::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the active wallet configuration path.
|
||||
pub fn config_path(&self) -> PathBuf {
|
||||
self.config_path.get()
|
||||
}
|
||||
|
||||
/// Return the shared wallet configuration path.
|
||||
#[doc(hidden)]
|
||||
pub fn shared_config_path(&self) -> crate::ConfigPath {
|
||||
self.config_path.clone()
|
||||
}
|
||||
|
||||
/// Set the TOR configuration for this instance of the OwnerAPI, used during
|
||||
/// `init_send_tx` when send args are present and a TOR address is specified
|
||||
/// `init_send_tx` when send args are present and a TOR address is specified,
|
||||
/// this will also update persistent config and will restart foreign listener
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `tor_config` - The optional [TorConfig](#) to use
|
||||
/// # Returns
|
||||
/// * Nothing
|
||||
/// * Result Containing:
|
||||
/// * `Ok(())` if the config was correctly saved
|
||||
/// * or [`libwallet::Error`](../grin_wallet_libwallet/struct.Error.html) if an error is encountered.
|
||||
///
|
||||
|
||||
pub fn set_tor_config(&self, tor_config: Option<TorConfig>) {
|
||||
let mut lock = self.tor_config.lock();
|
||||
*lock = tor_config;
|
||||
pub fn set_tor_config(&self, tor_config: Option<TorConfig>) -> Result<(), Error> {
|
||||
let _wallet_lock = self.wallet_inst.lock();
|
||||
update_global_config(&self.config_path(), |config| {
|
||||
if let Some(tor_config) = tor_config {
|
||||
config.members.tor = Some(tor_config);
|
||||
} else if let Some(tor) = config.members.tor.as_mut() {
|
||||
tor.use_tor_listener = false;
|
||||
tor.skip_send_attempt = Some(true);
|
||||
} else {
|
||||
let mut tor_config = config.tor_config();
|
||||
tor_config.use_tor_listener = false;
|
||||
tor_config.skip_send_attempt = Some(true);
|
||||
config.members.tor = Some(tor_config);
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.map_err(|e| Error::TorConfig(format!("{}", e)))
|
||||
}
|
||||
|
||||
/// Returns a list of accounts stored in the wallet (i.e. mappings between
|
||||
@@ -245,7 +286,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
///
|
||||
/// let result = api_owner.accounts(None);
|
||||
///
|
||||
@@ -296,7 +337,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
///
|
||||
/// let result = api_owner.create_account_path(None, "account1");
|
||||
///
|
||||
@@ -343,7 +384,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
///
|
||||
/// let result = api_owner.create_account_path(None, "account1");
|
||||
///
|
||||
@@ -399,7 +440,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let show_spent = false;
|
||||
/// let update_from_node = true;
|
||||
/// let tx_id = None;
|
||||
@@ -470,7 +511,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let update_from_node = true;
|
||||
/// let tx_id = None;
|
||||
/// let tx_slate_id = None;
|
||||
@@ -549,7 +590,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let update_from_node = true;
|
||||
/// let minimum_confirmations=10;
|
||||
///
|
||||
@@ -636,7 +677,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// // Attempt to create a transaction using the 'default' account
|
||||
/// let args = InitTxArgs {
|
||||
/// src_acct_name: None,
|
||||
@@ -666,41 +707,33 @@ where
|
||||
args: InitTxArgs,
|
||||
) -> Result<Slate, Error> {
|
||||
let send_args = args.send_args.clone();
|
||||
let slate = {
|
||||
let (slate, tor_config) = {
|
||||
let mut w_lock = self.wallet_inst.lock();
|
||||
let tor_config = send_args
|
||||
.as_ref()
|
||||
.map(|_| crate::tor_config::load(&self.config_path()))
|
||||
.transpose()?;
|
||||
let w = w_lock.lc_provider()?.wallet_inst()?;
|
||||
owner::init_send_tx(w, keychain_mask, args, self.doctest_mode)?
|
||||
let slate = owner::init_send_tx(w, keychain_mask, args, self.doctest_mode)?;
|
||||
(slate, tor_config)
|
||||
};
|
||||
// Helper functionality. If send arguments exist, attempt to send sync and
|
||||
// finalize
|
||||
let skip_tor = match send_args.as_ref() {
|
||||
None => false,
|
||||
Some(sa) => sa.skip_tor,
|
||||
};
|
||||
match send_args {
|
||||
Some(sa) => {
|
||||
let tor_config_lock = self.tor_config.lock();
|
||||
let tc = tor_config_lock.clone();
|
||||
let tc = match tc {
|
||||
Some(mut c) => {
|
||||
c.skip_send_attempt = Some(skip_tor);
|
||||
Some(c)
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
let res = try_slatepack_sync_workflow(
|
||||
&slate,
|
||||
&sa.dest,
|
||||
tc,
|
||||
None,
|
||||
false,
|
||||
self.doctest_mode,
|
||||
);
|
||||
let tc = tor_config.ok_or_else(|| {
|
||||
Error::TorConfig("Tor config was not loaded with send arguments".into())
|
||||
})?;
|
||||
let can_send = tc.send_tor(sa.skip_tor);
|
||||
if self.doctest_mode || !can_send {
|
||||
return Ok(slate);
|
||||
}
|
||||
let res = try_slatepack_sync_workflow(&slate, &sa.dest, Some(tc), None, false);
|
||||
match res {
|
||||
Ok(Some(s)) => {
|
||||
Ok(s) => {
|
||||
self.tx_lock_outputs(keychain_mask, &s)?;
|
||||
let ret_slate = self.finalize_tx(keychain_mask, &s)?;
|
||||
if sa.post_tx {
|
||||
self.tx_lock_outputs(keychain_mask, &s)?;
|
||||
let ret_slate = self.finalize_tx(keychain_mask, &s)?;
|
||||
let result = self.post_tx(keychain_mask, &ret_slate, sa.fluff);
|
||||
match result {
|
||||
Ok(_) => {
|
||||
@@ -713,13 +746,13 @@ where
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.tx_lock_outputs(keychain_mask, &s)?;
|
||||
let ret_slate = self.finalize_tx(keychain_mask, &s)?;
|
||||
Ok(ret_slate)
|
||||
}
|
||||
}
|
||||
Ok(None) => Ok(slate),
|
||||
Err(_) => Ok(slate),
|
||||
Err(e) => {
|
||||
error!("Error on sending over Tor: {}", e);
|
||||
Ok(slate)
|
||||
}
|
||||
}
|
||||
}
|
||||
None => Ok(slate),
|
||||
@@ -748,7 +781,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
///
|
||||
/// let args = IssueInvoiceTxArgs {
|
||||
/// amount: 60_000_000_000,
|
||||
@@ -854,7 +887,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
///
|
||||
/// // . . .
|
||||
/// // The slate has been recieved from the invoicer, somehow
|
||||
@@ -883,33 +916,52 @@ where
|
||||
slate: &Slate,
|
||||
args: InitTxArgs,
|
||||
) -> Result<Slate, Error> {
|
||||
let mut w_lock = self.wallet_inst.lock();
|
||||
let w = w_lock.lc_provider()?.wallet_inst()?;
|
||||
let send_args = args.send_args.clone();
|
||||
let slate = owner::process_invoice_tx(w, keychain_mask, slate, args, self.doctest_mode)?;
|
||||
let (slate, tor_config) = {
|
||||
let mut w_lock = self.wallet_inst.lock();
|
||||
let tor_config = send_args
|
||||
.as_ref()
|
||||
.map(|_| crate::tor_config::load(&self.config_path()))
|
||||
.transpose()?;
|
||||
let w = w_lock.lc_provider()?.wallet_inst()?;
|
||||
let slate =
|
||||
owner::process_invoice_tx(w, keychain_mask, slate, args, self.doctest_mode)?;
|
||||
(slate, tor_config)
|
||||
};
|
||||
// Helper functionality. If send arguments exist, attempt to send
|
||||
match send_args {
|
||||
Some(sa) => {
|
||||
let tor_config_lock = self.tor_config.lock();
|
||||
let tc = tor_config_lock.clone();
|
||||
let tc = match tc {
|
||||
Some(mut c) => {
|
||||
c.skip_send_attempt = Some(sa.skip_tor);
|
||||
Some(c)
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
let res = try_slatepack_sync_workflow(
|
||||
&slate,
|
||||
&sa.dest,
|
||||
tc,
|
||||
None,
|
||||
true,
|
||||
self.doctest_mode,
|
||||
);
|
||||
let tc = tor_config.ok_or_else(|| {
|
||||
Error::TorConfig("Tor config was not loaded with send arguments".into())
|
||||
})?;
|
||||
let can_send = tc.send_tor(sa.skip_tor);
|
||||
if self.doctest_mode || !can_send {
|
||||
return Ok(slate);
|
||||
}
|
||||
let res = try_slatepack_sync_workflow(&slate, &sa.dest, Some(tc), None, true);
|
||||
match res {
|
||||
Ok(s) => Ok(s.unwrap()),
|
||||
Err(_) => Ok(slate),
|
||||
Ok(s) => {
|
||||
// Update slate state.
|
||||
{
|
||||
let mut w_lock = self.wallet_inst.lock();
|
||||
let w = w_lock.lc_provider()?.wallet_inst()?;
|
||||
let parent_key_id = w.parent_key_id();
|
||||
match update_tx_slate_state(w, keychain_mask, &parent_key_id, &s) {
|
||||
Ok(_) => {}
|
||||
Err(e) => error!("Error on updating slate state: {}", e),
|
||||
}
|
||||
}
|
||||
// Output slatepack message to file.
|
||||
match output_slatepack_file(&self, keychain_mask, &s, &sa.dest) {
|
||||
Ok(_) => {}
|
||||
Err(e) => error!("Error on saving output slatepack message: {}", e),
|
||||
}
|
||||
Ok(s)
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Error on sending over Tor: {}", e);
|
||||
Ok(slate)
|
||||
}
|
||||
}
|
||||
}
|
||||
None => Ok(slate),
|
||||
@@ -947,7 +999,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let args = InitTxArgs {
|
||||
/// src_acct_name: None,
|
||||
/// amount: 2_000_000_000,
|
||||
@@ -1009,7 +1061,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let args = InitTxArgs {
|
||||
/// src_acct_name: None,
|
||||
/// amount: 2_000_000_000,
|
||||
@@ -1068,7 +1120,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let args = InitTxArgs {
|
||||
/// src_acct_name: None,
|
||||
/// amount: 2_000_000_000,
|
||||
@@ -1139,7 +1191,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let args = InitTxArgs {
|
||||
/// src_acct_name: None,
|
||||
/// amount: 2_000_000_000,
|
||||
@@ -1210,7 +1262,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let update_from_node = true;
|
||||
/// let tx_id = None;
|
||||
/// let tx_slate_id = None;
|
||||
@@ -1254,7 +1306,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let result = api_owner.scan(
|
||||
/// None,
|
||||
/// Some(20000),
|
||||
@@ -1294,7 +1346,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let result = api_owner.scan(
|
||||
/// None,
|
||||
/// Some(20000),
|
||||
@@ -1358,7 +1410,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let result = api_owner.scan(
|
||||
/// None,
|
||||
/// Some(20000),
|
||||
@@ -1416,7 +1468,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let result = api_owner.node_height(None);
|
||||
///
|
||||
/// if let Ok(node_height_result) = result {
|
||||
@@ -1473,7 +1525,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let result = api_owner.get_top_level_directory();
|
||||
///
|
||||
/// if let Ok(dir) = result {
|
||||
@@ -1498,6 +1550,9 @@ where
|
||||
/// Set [`get_top_level_directory`](struct.Owner.html#method.get_top_level_directory) for a
|
||||
/// description of the top level directory and default paths.
|
||||
///
|
||||
/// The wallet must be closed and the updater stopped before changing this directory.
|
||||
/// Open the wallet again afterwards to load its database from the new location.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `dir`: The new top-level directory path (either relative to current directory or
|
||||
@@ -1521,7 +1576,7 @@ where
|
||||
/// # .ok_or("Failed to convert tmpdir path to string.".to_owned())
|
||||
/// # .unwrap();
|
||||
///
|
||||
/// let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from(dir));
|
||||
/// let result = api_owner.set_top_level_directory(dir);
|
||||
///
|
||||
/// if let Ok(dir) = result {
|
||||
@@ -1530,9 +1585,25 @@ where
|
||||
/// ```
|
||||
|
||||
pub fn set_top_level_directory(&self, dir: &str) -> Result<(), Error> {
|
||||
if self.updater_running.load(Ordering::Relaxed) {
|
||||
return Err(Error::Lifecycle(
|
||||
"Stop the updater before changing the top-level directory".into(),
|
||||
));
|
||||
}
|
||||
let mut w_lock = self.wallet_inst.lock();
|
||||
let lc = w_lock.lc_provider()?;
|
||||
lc.set_top_level_directory(dir)
|
||||
if lc.wallet_inst().is_ok() {
|
||||
return Err(Error::Lifecycle(
|
||||
"Close the wallet before changing the top-level directory".into(),
|
||||
));
|
||||
}
|
||||
let config_path = PathBuf::from(dir).join(WALLET_CONFIG_FILE_NAME);
|
||||
if config_path.exists() {
|
||||
reload_global_config(&config_path)?;
|
||||
}
|
||||
lc.set_top_level_directory(dir)?;
|
||||
self.config_path.set(config_path);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Create a `grin-wallet.toml` configuration file in the top-level directory for the
|
||||
@@ -1571,7 +1642,7 @@ where
|
||||
/// # .ok_or("Failed to convert tmpdir path to string.".to_owned())
|
||||
/// # .unwrap();
|
||||
///
|
||||
/// let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from(dir));
|
||||
/// let _ = api_owner.set_top_level_directory(dir);
|
||||
///
|
||||
/// let result = api_owner.create_config(&ChainTypes::Mainnet, None, None, None);
|
||||
@@ -1640,7 +1711,7 @@ where
|
||||
/// # .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 = Owner::new(wallet.clone(), None, std::path::PathBuf::from(dir));
|
||||
/// let _ = api_owner.set_top_level_directory(dir);
|
||||
///
|
||||
/// // Create configuration
|
||||
@@ -1707,7 +1778,7 @@ where
|
||||
/// # .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 = Owner::new(wallet.clone(), None, std::path::PathBuf::from(dir));
|
||||
/// let _ = api_owner.set_top_level_directory(dir);
|
||||
///
|
||||
/// // Create configuration
|
||||
@@ -1764,7 +1835,7 @@ where
|
||||
/// use grin_core::global::ChainTypes;
|
||||
///
|
||||
/// // Set up as above
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
///
|
||||
/// let res = api_owner.close_wallet(None);
|
||||
///
|
||||
@@ -1800,7 +1871,7 @@ where
|
||||
/// use grin_core::global::ChainTypes;
|
||||
///
|
||||
/// // Set up as above
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
///
|
||||
/// let pw = ZeroingString::from("my_password");
|
||||
/// let res = api_owner.get_mnemonic(None, pw);
|
||||
@@ -1845,7 +1916,7 @@ where
|
||||
/// use grin_core::global::ChainTypes;
|
||||
///
|
||||
/// // Set up as above
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
///
|
||||
/// let old = ZeroingString::from("my_password");
|
||||
/// let new = ZeroingString::from("new_password");
|
||||
@@ -1888,7 +1959,7 @@ where
|
||||
/// use grin_core::global::ChainTypes;
|
||||
///
|
||||
/// // Set up as above
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
///
|
||||
/// let res = api_owner.delete_wallet(None);
|
||||
///
|
||||
@@ -1944,7 +2015,7 @@ where
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// // Set up as above
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
///
|
||||
/// let res = api_owner.start_updater(None, Duration::from_secs(60));
|
||||
///
|
||||
@@ -1999,7 +2070,7 @@ where
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// // Set up as above
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
///
|
||||
/// let res = api_owner.start_updater(None, Duration::from_secs(60));
|
||||
///
|
||||
@@ -2041,7 +2112,7 @@ where
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// // Set up as above
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
///
|
||||
/// let res = api_owner.start_updater(None, Duration::from_secs(60));
|
||||
///
|
||||
@@ -2107,7 +2178,7 @@ where
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// // Set up as above
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
///
|
||||
/// let res = api_owner.get_slatepack_address(None, 0);
|
||||
///
|
||||
@@ -2147,7 +2218,7 @@ where
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// // Set up as above
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
///
|
||||
/// let res = api_owner.get_slatepack_secret_key(None, 0);
|
||||
///
|
||||
@@ -2188,9 +2259,8 @@ where
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// // Set up as above
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
///
|
||||
/// let mut api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let args = InitTxArgs {
|
||||
/// src_acct_name: None,
|
||||
/// amount: 2_000_000_000,
|
||||
@@ -2258,7 +2328,7 @@ where
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// // Set up as above
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// // ... receive a slatepack from somewhere
|
||||
/// # let slatepack_string = String::from("");
|
||||
/// let res = api_owner.slate_from_slatepack_message(
|
||||
@@ -2308,7 +2378,7 @@ where
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// // Set up as above
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// # let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// # let slatepack_string = String::from("");
|
||||
/// // .. receive a slatepack from somewhere
|
||||
/// let res = api_owner.decode_slatepack_message(
|
||||
@@ -2366,7 +2436,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let update_from_node = true;
|
||||
/// let tx_id = None;
|
||||
/// let tx_slate_id = Some(Uuid::parse_str("0436430c-2b02-624c-2032-570501212b00").unwrap());
|
||||
@@ -2462,7 +2532,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let update_from_node = true;
|
||||
/// let tx_id = None;
|
||||
/// let tx_slate_id = Some(Uuid::parse_str("0436430c-2b02-624c-2032-570501212b00").unwrap());
|
||||
@@ -2524,7 +2594,7 @@ where
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let api_owner = Owner::new(wallet.clone(), None);
|
||||
/// let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let keychain_mask = None;
|
||||
/// let params = MixnetReqCreationParams {
|
||||
/// server_keys: vec![], // Public keys here in secret key representation
|
||||
@@ -2571,83 +2641,63 @@ pub fn try_slatepack_sync_workflow(
|
||||
slate: &Slate,
|
||||
dest: &str,
|
||||
tor_config: Option<TorConfig>,
|
||||
tor_sender: Option<HttpSlateSender>,
|
||||
tor_sender: Option<TorSlateSender>,
|
||||
send_to_finalize: bool,
|
||||
test_mode: bool,
|
||||
) -> Result<Option<Slate>, Error> {
|
||||
if let Some(tc) = &tor_config {
|
||||
if tc.skip_send_attempt == Some(true) {
|
||||
return Ok(None);
|
||||
}
|
||||
}
|
||||
) -> Result<Slate, Error> {
|
||||
let mut ret_slate = Slate::blank(2, false);
|
||||
let mut send_sync = |mut sender: HttpSlateSender, method_str: &str| match sender
|
||||
.send_tx(&slate, send_to_finalize)
|
||||
{
|
||||
Ok(s) => {
|
||||
ret_slate = s;
|
||||
return Ok(());
|
||||
}
|
||||
Err(e) => {
|
||||
debug!(
|
||||
"Send ({}): Could not send Slate via {}: {}",
|
||||
method_str, method_str, e
|
||||
);
|
||||
return Err(e);
|
||||
}
|
||||
let mut send_sync = |mut sender: TorSlateSender, method_str: &str| {
|
||||
return match sender.send_tx(&slate, send_to_finalize) {
|
||||
Ok(s) => {
|
||||
ret_slate = s;
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
debug!(
|
||||
"Send ({}): Could not send Slate via {}: {}",
|
||||
method_str, method_str, e
|
||||
);
|
||||
Err(e)
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Try parsing Slatepack address
|
||||
// Try parsing Slatepack address.
|
||||
match SlatepackAddress::try_from(dest) {
|
||||
Ok(address) => {
|
||||
let tor_addr = OnionV3Address::try_from(&address).unwrap();
|
||||
// Try sending to the destination via TOR
|
||||
let tor_addr = OnionV3Address::try_from(&address).map_err(|_| {
|
||||
Error::SlatepackAddress(format!(
|
||||
"Destination {} is not a valid Onion address.",
|
||||
dest
|
||||
))
|
||||
})?;
|
||||
// Try sending to the destination via Tor.
|
||||
let sender = match tor_sender {
|
||||
None => {
|
||||
if test_mode {
|
||||
None
|
||||
} else {
|
||||
match HttpSlateSender::with_socks_proxy(
|
||||
&tor_addr.to_http_str(),
|
||||
&tor_config.as_ref().unwrap().socks_proxy_addr,
|
||||
&tor_config.as_ref().unwrap().send_config_dir,
|
||||
tor_config.as_ref().unwrap().bridge.clone(),
|
||||
tor_config.as_ref().unwrap().proxy.clone(),
|
||||
) {
|
||||
Ok(s) => Some(s),
|
||||
if let Some(tc) = tor_config {
|
||||
match TorSlateSender::new(&tor_addr.to_http_str(), tc) {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
debug!("Send (TOR): Cannot create TOR Slate sender {:?}", e);
|
||||
None
|
||||
debug!("Send (Tor): Cannot create TOR Slate sender {:?}", e);
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(s) => {
|
||||
if test_mode {
|
||||
None
|
||||
} else {
|
||||
Some(s)
|
||||
return Err(Error::TorConfig("Tor config is not set".to_string()));
|
||||
}
|
||||
}
|
||||
Some(s) => s,
|
||||
};
|
||||
if let Some(s) = sender {
|
||||
warn!("Attempting to send transaction via TOR");
|
||||
match send_sync(s, "TOR") {
|
||||
Ok(_) => return Ok(Some(ret_slate)),
|
||||
Err(e) => {
|
||||
debug!("Unable to send via TOR: {}", e);
|
||||
warn!("Unable to send transaction via TOR");
|
||||
}
|
||||
}
|
||||
warn!("Attempting to send transaction via Tor");
|
||||
match send_sync(sender, "Tor") {
|
||||
Ok(_) => Ok(ret_slate),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
debug!("Send (TOR): Destination is not SlatepackAddress {:?}", e);
|
||||
warn!("Destination is not a valid Slatepack address. Will output Slatepack.")
|
||||
error!("Destination {} is not a valid Slatepack address.", dest);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
@@ -2697,8 +2747,12 @@ macro_rules! doctest_helper_setup_doc_env {
|
||||
wallet_config.data_file_dir = dir.to_owned();
|
||||
let pw = ZeroingString::from("");
|
||||
|
||||
let node_client =
|
||||
HTTPNodeClient::new(&wallet_config.check_node_api_http_addr, None).unwrap();
|
||||
let node_client = HTTPNodeClient::new(
|
||||
&wallet_config.check_node_api_http_addr,
|
||||
None,
|
||||
wallet_config.api_request_timeout(),
|
||||
)
|
||||
.unwrap();
|
||||
let mut wallet =
|
||||
Box::new(DefaultWalletImpl::<HTTPNodeClient>::new(node_client.clone()).unwrap())
|
||||
as Box<
|
||||
@@ -2715,3 +2769,38 @@ macro_rules! doctest_helper_setup_doc_env {
|
||||
let mut $wallet = Arc::new(Mutex::new(wallet));
|
||||
};
|
||||
}
|
||||
|
||||
/// Output slatepack message to file.
|
||||
fn output_slatepack_file<L, C, K>(
|
||||
api: &Owner<L, C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
slate: &Slate,
|
||||
dest: &str,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
L: WalletLCProvider<'static, C, K> + 'static,
|
||||
C: NodeClient + 'static,
|
||||
K: Keychain + 'static,
|
||||
{
|
||||
let address = match SlatepackAddress::try_from(dest) {
|
||||
Ok(a) => Some(a),
|
||||
Err(_) => None,
|
||||
};
|
||||
// encrypt for recipient by default
|
||||
let recipients = match address.clone() {
|
||||
Some(a) => vec![a],
|
||||
None => vec![],
|
||||
};
|
||||
let message = api.create_slatepack_message(keychain_mask, &slate, Some(0), recipients)?;
|
||||
let tld = api.get_top_level_directory()?;
|
||||
|
||||
// Create a directory to which files will be output.
|
||||
let slate_dir = format!("{}/{}", tld, "slatepack");
|
||||
let _ = std::fs::create_dir_all(slate_dir.clone());
|
||||
let out_file_name = format!("{}/{}.{}.slatepack", slate_dir, slate.id, slate.state);
|
||||
|
||||
let mut output = File::create(out_file_name.clone())?;
|
||||
output.write_all(&message.as_bytes())?;
|
||||
output.sync_all()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+21
-5
@@ -39,6 +39,7 @@ use easy_jsonrpc_mw;
|
||||
use grin_wallet_util::OnionV3Address;
|
||||
use rand::thread_rng;
|
||||
use std::convert::TryFrom;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -1241,6 +1242,9 @@ pub trait OwnerRpc {
|
||||
|
||||
/**
|
||||
Networked version of [Owner::set_top_level_directory](struct.Owner.html#method.set_top_level_directory).
|
||||
|
||||
The wallet must be closed and the updater stopped before calling this method. Running listeners
|
||||
should be restarted after opening the wallet from the new directory.
|
||||
```
|
||||
# grin_wallet_api::doctest_helper_json_rpc_owner_assert_response!(
|
||||
# r#"
|
||||
@@ -2500,7 +2504,7 @@ where
|
||||
}
|
||||
|
||||
fn set_tor_config(&self, tor_config: Option<TorConfig>) -> Result<(), Error> {
|
||||
Owner::set_tor_config(self, tor_config);
|
||||
Owner::set_tor_config(self, tor_config)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -2564,6 +2568,7 @@ pub fn run_doctest_owner(
|
||||
) -> Result<Option<serde_json::Value>, String> {
|
||||
use easy_jsonrpc_mw::Handler;
|
||||
use grin_keychain::ExtKeychain;
|
||||
use grin_wallet_config::initial_setup_wallet;
|
||||
use grin_wallet_impls::test_framework::{self, LocalWalletClient, WalletProxy};
|
||||
use grin_wallet_impls::{DefaultLCProvider, DefaultWalletImpl};
|
||||
use grin_wallet_libwallet::{api_impl, WalletInst};
|
||||
@@ -2577,6 +2582,14 @@ pub fn run_doctest_owner(
|
||||
let _ = fs::remove_dir_all(test_dir);
|
||||
global::set_local_chain_type(ChainTypes::AutomatedTesting);
|
||||
|
||||
let _ = fs::create_dir_all(test_dir);
|
||||
let config = initial_setup_wallet(
|
||||
&ChainTypes::AutomatedTesting,
|
||||
Some(PathBuf::from(test_dir)),
|
||||
false,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut wallet_proxy: WalletProxy<
|
||||
DefaultLCProvider<LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
@@ -2584,11 +2597,11 @@ pub fn run_doctest_owner(
|
||||
> = WalletProxy::new(test_dir);
|
||||
let chain = wallet_proxy.chain.clone();
|
||||
|
||||
let rec_phrase_1 = util::ZeroingString::from(
|
||||
let rec_phrase_1 = ZeroingString::from(
|
||||
"fat twenty mean degree forget shell check candy immense awful \
|
||||
flame next during february bulb bike sun wink theory day kiwi embrace peace lunch",
|
||||
);
|
||||
let empty_string = util::ZeroingString::from("");
|
||||
let empty_string = ZeroingString::from("");
|
||||
|
||||
let client1 = LocalWalletClient::new("wallet1", wallet_proxy.tx.clone());
|
||||
let mut wallet1 =
|
||||
@@ -2623,7 +2636,7 @@ pub fn run_doctest_owner(
|
||||
|
||||
let mut slate_outer = Slate::blank(2, false);
|
||||
|
||||
let rec_phrase_2 = util::ZeroingString::from(
|
||||
let rec_phrase_2 = ZeroingString::from(
|
||||
"hour kingdom ripple lunch razor inquiry coyote clay stamp mean \
|
||||
sell finish magic kid tiny wage stand panther inside settle feed song hole exile",
|
||||
);
|
||||
@@ -2746,8 +2759,11 @@ pub fn run_doctest_owner(
|
||||
);
|
||||
}
|
||||
|
||||
let mut api_owner = Owner::new(wallet1, None);
|
||||
let mut api_owner = Owner::new(wallet1, None, config.config_file_path);
|
||||
api_owner.doctest_mode = true;
|
||||
if request["method"] == "set_top_level_directory" {
|
||||
api_owner.close_wallet(None).unwrap();
|
||||
}
|
||||
let owner_api = &api_owner as &dyn OwnerRpc;
|
||||
let res = owner_api.handle_request(request).as_option();
|
||||
let _ = fs::remove_dir_all(test_dir);
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright 2026 The Grin Developers
|
||||
//
|
||||
// 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.
|
||||
|
||||
use crate::config::TorConfig;
|
||||
use crate::libwallet::Error;
|
||||
use crate::util::Mutex;
|
||||
use grin_wallet_config::config::get_global_config;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Shared path to the active wallet configuration.
|
||||
#[doc(hidden)]
|
||||
#[derive(Clone)]
|
||||
pub struct ConfigPath(Arc<Mutex<PathBuf>>);
|
||||
|
||||
impl ConfigPath {
|
||||
pub(crate) fn get(&self) -> PathBuf {
|
||||
self.0.lock().clone()
|
||||
}
|
||||
|
||||
pub(crate) fn set(&self, path: PathBuf) {
|
||||
*self.0.lock() = path;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PathBuf> for ConfigPath {
|
||||
fn from(path: PathBuf) -> Self {
|
||||
Self(Arc::new(Mutex::new(path)))
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn load(config_path: &Path) -> Result<TorConfig, Error> {
|
||||
Ok(get_global_config(config_path)?.tor_config())
|
||||
}
|
||||
+1
-1
@@ -16,7 +16,7 @@ use crate::libwallet::slate_versions::ser as dalek_ser;
|
||||
use crate::libwallet::Error;
|
||||
use crate::util::secp::key::{PublicKey, SecretKey};
|
||||
use crate::util::{from_hex, ToHex};
|
||||
use ed25519_dalek::SecretKey as DalekSecretKey;
|
||||
use ed25519_dalek::SigningKey as DalekSecretKey;
|
||||
|
||||
use base64;
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
Reference in New Issue
Block a user