mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-12-04 04:43:58 +01:00
Add linter to CI (#823)
Co-authored-by: wiesche <wiesche89@googlemail.com>
This commit is contained in:
committed by
GitHub
co-authored by
wiesche
parent
ec1e9910af
commit
fe79256467
+25
-34
@@ -120,7 +120,7 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn rewind_hash<'a, L, C, K>(
|
||||
pub fn rewind_hash<L, C, K>(
|
||||
owner_api: &mut Owner<L, C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
) -> Result<(), Error>
|
||||
@@ -159,7 +159,7 @@ where
|
||||
let tip_height = owner_api.node_height(None)?.height;
|
||||
let start_height = match args.backwards_from_tip {
|
||||
Some(b) => tip_height.saturating_sub(b),
|
||||
None => args.start_height.unwrap_or_else(|| 1),
|
||||
None => args.start_height.unwrap_or(1),
|
||||
};
|
||||
warn!(
|
||||
"Starting view wallet output scan from height {} ...",
|
||||
@@ -184,6 +184,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn listen<L, C, K>(
|
||||
owner_api: &mut Owner<L, C, K>,
|
||||
keychain_mask: Arc<Mutex<Option<SecretKey>>>,
|
||||
@@ -222,7 +223,7 @@ where
|
||||
if let Ok(t) = api_thread {
|
||||
if !cli_mode {
|
||||
let r = t.join();
|
||||
if let Err(_) = r {
|
||||
if r.is_err() {
|
||||
error!("Error starting listener");
|
||||
return Err(Error::ListenerError);
|
||||
}
|
||||
@@ -424,11 +425,11 @@ where
|
||||
init_args = max_retry_args(init_args, amount, max_inputs);
|
||||
owner_api.init_send_tx(keychain_mask, init_args)?
|
||||
} else {
|
||||
return Err(grin_wallet_libwallet::Error::from(e));
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return Err(grin_wallet_libwallet::Error::from(e));
|
||||
return Err(e);
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -459,20 +460,15 @@ where
|
||||
};
|
||||
let init_send_tx = |init_args: InitTxArgs| -> Result<Slate, libwallet::Error> {
|
||||
let result = owner_api.init_send_tx(keychain_mask, init_args.clone());
|
||||
let slate = match result {
|
||||
Ok(s) => {
|
||||
info!(
|
||||
"Tx created: {} grin to {} (strategy '{}')",
|
||||
core::amount_to_hr_string(init_args.amount, false),
|
||||
dest.as_ref()
|
||||
.map(ToString::to_string)
|
||||
.unwrap_or_else(|| "no destination".to_string()),
|
||||
args.selection_strategy,
|
||||
);
|
||||
s
|
||||
}
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
let slate = result?;
|
||||
info!(
|
||||
"Tx created: {} grin to {} (strategy '{}')",
|
||||
core::amount_to_hr_string(init_args.amount, false),
|
||||
dest.as_ref()
|
||||
.map(ToString::to_string)
|
||||
.unwrap_or_else(|| "no destination".to_string()),
|
||||
args.selection_strategy,
|
||||
);
|
||||
Ok(slate)
|
||||
};
|
||||
slate = match init_send_tx(init_args.clone()) {
|
||||
@@ -561,6 +557,7 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn output_slatepack<L, C, K>(
|
||||
owner_api: &mut Owner<L, C, K>,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
@@ -582,7 +579,7 @@ where
|
||||
Some(a) => vec![a],
|
||||
None => vec![],
|
||||
};
|
||||
let message = owner_api.create_slatepack_message(keychain_mask, &slate, Some(0), recipients)?;
|
||||
let message = owner_api.create_slatepack_message(keychain_mask, slate, Some(0), recipients)?;
|
||||
let tld = owner_api.get_top_level_directory()?;
|
||||
|
||||
// create a directory to which files will be output
|
||||
@@ -594,12 +591,12 @@ where
|
||||
};
|
||||
|
||||
if lock {
|
||||
owner_api.tx_lock_outputs(keychain_mask, &slate)?;
|
||||
owner_api.tx_lock_outputs(keychain_mask, slate)?;
|
||||
}
|
||||
|
||||
println!("{}", out_file_name);
|
||||
let mut output = File::create(out_file_name.clone())?;
|
||||
output.write_all(&message.as_bytes())?;
|
||||
output.write_all(message.as_bytes())?;
|
||||
output.sync_all()?;
|
||||
|
||||
println!();
|
||||
@@ -695,7 +692,7 @@ where
|
||||
}
|
||||
None => {
|
||||
let msg = "No slate provided via file or direct input";
|
||||
return Err(Error::GenericError(msg.into()).into());
|
||||
return Err(Error::GenericError(msg.into()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -752,10 +749,7 @@ where
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let km = match keychain_mask.as_ref() {
|
||||
None => None,
|
||||
Some(&m) => Some(m.to_owned()),
|
||||
};
|
||||
let km = keychain_mask.as_ref().map(|&m| m.to_owned());
|
||||
|
||||
if let Some(b) = args.bridge {
|
||||
tor_config.bridge.bridge_line = Some(b);
|
||||
@@ -830,7 +824,7 @@ pub fn read_slatepack(args: ReceiveArgs) -> Result<Slatepack, Error> {
|
||||
None => match args.input_slatepack_message {
|
||||
Some(message) => packer.deser_slatepack(message.as_bytes(), false)?,
|
||||
None => {
|
||||
return Err(Error::ArgumentError("Invalid Slatepack Input".into()).into());
|
||||
return Err(Error::ArgumentError("Invalid Slatepack Input".into()));
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -942,10 +936,7 @@ where
|
||||
let is_invoice = slate.state == SlateState::Invoice2;
|
||||
|
||||
if is_invoice {
|
||||
let km = match keychain_mask.as_ref() {
|
||||
None => None,
|
||||
Some(&m) => Some(m.to_owned()),
|
||||
};
|
||||
let km = keychain_mask.as_ref().map(|&m| m.to_owned());
|
||||
controller::foreign_single_use(
|
||||
owner_api.wallet_inst.clone(),
|
||||
owner_api.config_path(),
|
||||
@@ -1258,7 +1249,7 @@ where
|
||||
// Note advanced query args not currently supported by command line client
|
||||
let (validated, txs) =
|
||||
owner_api.retrieve_txs(keychain_mask, true, args.id, args.tx_slate_id, None)?;
|
||||
let include_status = !args.id.is_some() && !args.tx_slate_id.is_some();
|
||||
let include_status = args.id.is_none() && args.tx_slate_id.is_none();
|
||||
// If view count is specified, restrict the TX list to `txs.len() - count`
|
||||
let first_tx = args
|
||||
.count
|
||||
@@ -1455,7 +1446,7 @@ where
|
||||
let tip_height = owner_api.node_height(keychain_mask)?.height;
|
||||
let start_height = match args.backwards_from_tip {
|
||||
Some(b) => tip_height.saturating_sub(b),
|
||||
None => args.start_height.unwrap_or_else(|| 1),
|
||||
None => args.start_height.unwrap_or(1),
|
||||
};
|
||||
warn!("Starting output scan from height {} ...", start_height);
|
||||
let result = owner_api.scan(keychain_mask, Some(start_height), args.delete_unconfirmed);
|
||||
|
||||
@@ -21,8 +21,8 @@ use crate::impls::tor::process as tor_process;
|
||||
use crate::impls::tor::{bridge as tor_bridge, proxy as tor_proxy};
|
||||
use crate::keychain::Keychain;
|
||||
use crate::libwallet::{
|
||||
address, Error, NodeClient, NodeVersionInfo, Slate, SlatepackAddress, WalletInst,
|
||||
WalletLCProvider, GRIN_BLOCK_HEADER_VERSION,
|
||||
address, Error, NodeClient, NodeVersionInfo, Slate, SlatepackAddress, WalletLCProvider,
|
||||
GRIN_BLOCK_HEADER_VERSION,
|
||||
};
|
||||
use crate::util::secp::key::SecretKey;
|
||||
use crate::util::{from_hex, static_secp_instance, to_base64, Mutex};
|
||||
@@ -102,29 +102,23 @@ fn init_tor_listener(
|
||||
let mut hm_tor_bridge: HashMap<String, String> = HashMap::new();
|
||||
if tor_config.bridge.bridge_line.is_some() {
|
||||
let bridge_config = tor_bridge::TorBridge::try_from(tor_config.bridge)
|
||||
.map_err(|e| Error::TorConfig(format!("{}", e).into()))?;
|
||||
.map_err(|e| Error::TorConfig(format!("{}", e)))?;
|
||||
hm_tor_bridge = bridge_config
|
||||
.to_hashmap()
|
||||
.map_err(|e| Error::TorConfig(format!("{}", e).into()))?;
|
||||
.map_err(|e| Error::TorConfig(format!("{}", e)))?;
|
||||
}
|
||||
|
||||
let mut hm_tor_poxy: HashMap<String, String> = HashMap::new();
|
||||
if tor_config.proxy.transport.is_some() || tor_config.proxy.allowed_port.is_some() {
|
||||
let proxy_config = tor_proxy::TorProxy::try_from(tor_config.proxy)
|
||||
.map_err(|e| Error::TorConfig(format!("{}", e).into()))?;
|
||||
.map_err(|e| Error::TorConfig(format!("{}", e)))?;
|
||||
hm_tor_poxy = proxy_config
|
||||
.to_hashmap()
|
||||
.map_err(|e| Error::TorConfig(format!("{}", e).into()))?;
|
||||
.map_err(|e| Error::TorConfig(format!("{}", e)))?;
|
||||
}
|
||||
|
||||
tor_config::output_tor_listener_config(
|
||||
&tor_dir,
|
||||
addr,
|
||||
&vec![sec_key],
|
||||
hm_tor_bridge,
|
||||
hm_tor_poxy,
|
||||
)
|
||||
.map_err(|e| Error::TorConfig(format!("{:?}", e).into()))?;
|
||||
tor_config::output_tor_listener_config(&tor_dir, addr, &[sec_key], hm_tor_bridge, hm_tor_poxy)
|
||||
.map_err(|e| Error::TorConfig(format!("{:?}", e)))?;
|
||||
// Start TOR process
|
||||
process
|
||||
.torrc_path(&format!("{}/torrc", tor_dir))
|
||||
@@ -139,7 +133,7 @@ fn init_tor_listener(
|
||||
/// Instantiate wallet Foreign API for a single-use (command line) call
|
||||
/// Return a function containing a loaded API context to call
|
||||
pub fn foreign_single_use<'a, L, F, C, K>(
|
||||
wallet: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
|
||||
wallet: grin_wallet_libwallet::WalletHandle<'a, L, C, K>,
|
||||
config_path: PathBuf,
|
||||
keychain_mask: Option<SecretKey>,
|
||||
f: F,
|
||||
@@ -179,9 +173,9 @@ where
|
||||
K: Keychain + 'static,
|
||||
{
|
||||
let mut router = Router::new();
|
||||
if api_secret.is_some() {
|
||||
if let Some(api_secret) = api_secret {
|
||||
let api_basic_auth =
|
||||
"Basic ".to_string() + &to_base64(&("grin:".to_string() + &api_secret.unwrap()));
|
||||
"Basic ".to_string() + &to_base64(&("grin:".to_string() + &api_secret));
|
||||
let basic_auth_middleware = Arc::new(BasicAuthMiddleware::new(
|
||||
api_basic_auth,
|
||||
&GRIN_OWNER_BASIC_REALM,
|
||||
@@ -231,8 +225,9 @@ where
|
||||
|
||||
/// Listener version, providing same API but listening for requests on a
|
||||
/// port and wrapping the calls
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn foreign_listener<L, C, K>(
|
||||
wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K> + 'static>>>,
|
||||
wallet: grin_wallet_libwallet::WalletHandle<'static, L, C, K>,
|
||||
config_path: PathBuf,
|
||||
bridge: Option<String>,
|
||||
use_tor: Option<bool>,
|
||||
@@ -258,7 +253,7 @@ where
|
||||
let mut w_lock = wallet.lock();
|
||||
let lc = w_lock.lc_provider()?;
|
||||
let w_inst = lc.wallet_inst()?;
|
||||
let k = w_inst.keychain((&mask).as_ref())?;
|
||||
let k = w_inst.keychain(mask.as_ref())?;
|
||||
let parent_key_id = w_inst.parent_key_id();
|
||||
let sec_key = address::address_from_derivation_path(&k, &parent_key_id, 0)
|
||||
.map_err(|e| Error::TorConfig(format!("{:?}", e)))?;
|
||||
@@ -400,7 +395,7 @@ where
|
||||
K: Keychain + 'static,
|
||||
{
|
||||
/// Wallet instance
|
||||
pub wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K> + 'static>>>,
|
||||
pub wallet: grin_wallet_libwallet::WalletHandle<'static, L, C, K>,
|
||||
|
||||
/// Handle to Owner API
|
||||
owner_api: Arc<Owner<L, C, K>>,
|
||||
@@ -462,7 +457,7 @@ impl OwnerV3Helpers {
|
||||
val: &serde_json::Value,
|
||||
new_key: Option<SecretKey>,
|
||||
) {
|
||||
if let Some(_) = val["result"]["Ok"].as_str() {
|
||||
if val["result"]["Ok"].as_str().is_some() {
|
||||
let mut share_key_ref = key.lock();
|
||||
*share_key_ref = new_key;
|
||||
}
|
||||
@@ -503,7 +498,7 @@ impl OwnerV3Helpers {
|
||||
.as_json_value()
|
||||
})?;
|
||||
let id = enc_req.id.clone();
|
||||
let res = enc_req.decrypt(&shared_key).map_err(|e| {
|
||||
let res = enc_req.decrypt(shared_key).map_err(|e| {
|
||||
EncryptionErrorResponse::new(1, -32002, &format!("Decryption error: {}", e))
|
||||
.as_json_value()
|
||||
})?;
|
||||
@@ -518,7 +513,7 @@ impl OwnerV3Helpers {
|
||||
) -> Result<serde_json::Value, serde_json::Value> {
|
||||
let share_key_ref = key.lock();
|
||||
let shared_key = share_key_ref.as_ref().unwrap();
|
||||
let enc_res = EncryptedResponse::from_json(id, res, &shared_key).map_err(|e| {
|
||||
let enc_res = EncryptedResponse::from_json(id, res, shared_key).map_err(|e| {
|
||||
EncryptionErrorResponse::new(1, -32003, &format!("EncryptionError: {}", e))
|
||||
.as_json_value()
|
||||
})?;
|
||||
@@ -576,10 +571,7 @@ impl OwnerV3Helpers {
|
||||
retval
|
||||
} else if val["result"]["Err"].is_string() {
|
||||
let parsed = serde_json::from_value::<String>(val["result"]["Err"].clone());
|
||||
match parsed {
|
||||
Ok(p) => Some(p),
|
||||
Err(_) => None,
|
||||
}
|
||||
parsed.ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@@ -737,7 +729,7 @@ where
|
||||
K: Keychain + 'static,
|
||||
{
|
||||
/// Wallet instance.
|
||||
pub wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K> + 'static>>>,
|
||||
pub wallet: grin_wallet_libwallet::WalletHandle<'static, L, C, K>,
|
||||
/// Wallet configuration path.
|
||||
pub config_path: ConfigPath,
|
||||
/// Keychain mask
|
||||
@@ -754,7 +746,7 @@ where
|
||||
{
|
||||
/// Create a new foreign API handler for GET methods
|
||||
pub fn new(
|
||||
wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K> + 'static>>>,
|
||||
wallet: grin_wallet_libwallet::WalletHandle<'static, L, C, K>,
|
||||
config_path: ConfigPath,
|
||||
keychain_mask: Arc<Mutex<Option<SecretKey>>>,
|
||||
test_mode: bool,
|
||||
@@ -785,7 +777,7 @@ where
|
||||
async fn handle_post_request(
|
||||
req: Request<Incoming>,
|
||||
mask: Option<SecretKey>,
|
||||
wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K> + 'static>>>,
|
||||
wallet: grin_wallet_libwallet::WalletHandle<'static, L, C, K>,
|
||||
config_path: ConfigPath,
|
||||
test_mode: bool,
|
||||
) -> Result<Response<ApiBody>, Error> {
|
||||
|
||||
+11
-21
@@ -62,7 +62,7 @@ pub fn outputs(
|
||||
]);
|
||||
|
||||
for m in outputs {
|
||||
let commit = format!("{}", m.commit.as_ref().to_hex());
|
||||
let commit = m.commit.as_ref().to_hex();
|
||||
let index = match m.output.mmr_index {
|
||||
None => "None".to_owned(),
|
||||
Some(t) => t.to_string(),
|
||||
@@ -78,7 +78,7 @@ pub fn outputs(
|
||||
};
|
||||
|
||||
let num_confirmations = format!("{}", m.output.num_confirmations(cur_height));
|
||||
let value = format!("{}", amount_to_hr_string(m.output.value, false));
|
||||
let value = amount_to_hr_string(m.output.value, false);
|
||||
let tx = match m.output.tx_log_entry {
|
||||
None => "".to_owned(),
|
||||
Some(t) => t.to_string(),
|
||||
@@ -196,7 +196,7 @@ pub fn txs(
|
||||
let amount_debited_str = amount_to_hr_string(t.amount_debited, true);
|
||||
let amount_credited_str = amount_to_hr_string(t.amount_credited, true);
|
||||
let fee = match t.fee {
|
||||
Some(f) => format!("{}", amount_to_hr_string(f.fee(), true)),
|
||||
Some(f) => amount_to_hr_string(f.fee(), true),
|
||||
None => "None".to_owned(),
|
||||
};
|
||||
let net_diff = if t.amount_credited >= t.amount_debited {
|
||||
@@ -297,24 +297,17 @@ pub fn txs(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn view_wallet_balance(w: ViewWallet, cur_height: u64, dark_background_color_scheme: bool) {
|
||||
pub fn view_wallet_balance(w: ViewWallet, cur_height: u64, _dark_background_color_scheme: bool) {
|
||||
println!(
|
||||
"\n____ View Wallet Summary Info - Block Height: {} ____\n Rewind Hash - {}\n",
|
||||
cur_height, w.rewind_hash
|
||||
);
|
||||
let mut table = table!();
|
||||
|
||||
if dark_background_color_scheme {
|
||||
table.add_row(row![
|
||||
bFG->"Total Balance",
|
||||
FG->amount_to_hr_string(w.total_balance, false)
|
||||
]);
|
||||
} else {
|
||||
table.add_row(row![
|
||||
bFG->"Total Balance",
|
||||
FG->amount_to_hr_string(w.total_balance, false)
|
||||
]);
|
||||
};
|
||||
table.add_row(row![
|
||||
bFG->"Total Balance",
|
||||
FG->amount_to_hr_string(w.total_balance, false)
|
||||
]);
|
||||
table.set_format(*prettytable::format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR);
|
||||
table.printstd();
|
||||
println!();
|
||||
@@ -351,13 +344,13 @@ pub fn view_wallet_output(
|
||||
]);
|
||||
|
||||
for m in view_wallet.output_result {
|
||||
let commit = format!("{}", m.commit);
|
||||
let commit = m.commit.as_str();
|
||||
let index = m.mmr_index;
|
||||
let height = format!("{}", m.height);
|
||||
let lock_height = format!("{}", m.lock_height);
|
||||
let is_coinbase = format!("{}", m.is_coinbase);
|
||||
let num_confirmations = format!("{}", m.num_confirmations(cur_height));
|
||||
let value = format!("{}", amount_to_hr_string(m.value, false));
|
||||
let value = amount_to_hr_string(m.value, false);
|
||||
|
||||
if dark_background_color_scheme {
|
||||
table.add_row(row![
|
||||
@@ -612,10 +605,7 @@ pub fn payment_proof(tx: &TxLogEntry) -> Result<(), Error> {
|
||||
let amount = if tx.amount_credited >= tx.amount_debited {
|
||||
amount_to_hr_string(tx.amount_credited - tx.amount_debited, true)
|
||||
} else {
|
||||
format!(
|
||||
"{}",
|
||||
amount_to_hr_string(tx.amount_debited - tx.amount_credited - fee, true)
|
||||
)
|
||||
amount_to_hr_string(tx.amount_debited - tx.amount_credited - fee, true)
|
||||
};
|
||||
|
||||
let sender_signature = match pp.sender_signature {
|
||||
|
||||
@@ -52,7 +52,7 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
api1
|
||||
);
|
||||
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
@@ -66,7 +66,7 @@ fn accounts_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
api2
|
||||
);
|
||||
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
|
||||
@@ -50,7 +50,7 @@ fn build_chain(test_dir: &'static str, block_height: usize) -> Result<(), libwal
|
||||
true,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
debug!("Mask1: {:?}", mask1);
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
@@ -63,7 +63,7 @@ fn build_chain(test_dir: &'static str, block_height: usize) -> Result<(), libwal
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
debug!("Mask2: {:?}", mask2);
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
|
||||
@@ -55,7 +55,7 @@ fn build_output_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error
|
||||
api1
|
||||
);
|
||||
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
|
||||
+18
-18
@@ -68,7 +68,7 @@ fn scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
@@ -80,7 +80,7 @@ fn scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -223,7 +223,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
false,
|
||||
_m_api
|
||||
);
|
||||
let miner_mask = (&miner_mask_i).as_ref();
|
||||
let miner_mask = miner_mask_i.as_ref();
|
||||
|
||||
// non-mining recipient wallets
|
||||
create_wallet_and_add!(
|
||||
@@ -237,7 +237,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
@@ -249,7 +249,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
false,
|
||||
_api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
// we'll restore into here
|
||||
create_wallet_and_add!(
|
||||
client3,
|
||||
@@ -262,7 +262,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
false,
|
||||
api3
|
||||
);
|
||||
let mask3 = (&mask3_i).as_ref();
|
||||
let mask3 = mask3_i.as_ref();
|
||||
// also restore into here
|
||||
create_wallet_and_add!(
|
||||
client4,
|
||||
@@ -275,7 +275,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
false,
|
||||
api4
|
||||
);
|
||||
let mask4 = (&mask4_i).as_ref();
|
||||
let mask4 = mask4_i.as_ref();
|
||||
// Simulate a recover from seed without restore into here
|
||||
create_wallet_and_add!(
|
||||
client5,
|
||||
@@ -289,7 +289,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
api5
|
||||
);
|
||||
//simulate a recover from seed without restore into here
|
||||
let mask5 = (&mask5_i).as_ref();
|
||||
let mask5 = mask5_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client6,
|
||||
wallet6,
|
||||
@@ -301,7 +301,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
false,
|
||||
api6
|
||||
);
|
||||
let mask6 = (&mask6_i).as_ref();
|
||||
let mask6 = mask6_i.as_ref();
|
||||
|
||||
create_wallet_and_add!(
|
||||
client7,
|
||||
@@ -314,7 +314,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
false,
|
||||
api7
|
||||
);
|
||||
let mask7 = (&mask7_i).as_ref();
|
||||
let mask7 = mask7_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client8,
|
||||
wallet8,
|
||||
@@ -326,7 +326,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
false,
|
||||
api8
|
||||
);
|
||||
let mask8 = (&mask8_i).as_ref();
|
||||
let mask8 = mask8_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client9,
|
||||
wallet9,
|
||||
@@ -338,7 +338,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
false,
|
||||
api9
|
||||
);
|
||||
let mask9 = (&mask9_i).as_ref();
|
||||
let mask9 = mask9_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client10,
|
||||
wallet10,
|
||||
@@ -350,7 +350,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
false,
|
||||
api10
|
||||
);
|
||||
let mask10 = (&mask10_i).as_ref();
|
||||
let mask10 = mask10_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -380,7 +380,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
miner_mask,
|
||||
m_client.clone(),
|
||||
"wallet1",
|
||||
base_amount * 1
|
||||
base_amount
|
||||
)?;
|
||||
send_to_dest!(
|
||||
miner.clone(),
|
||||
@@ -579,7 +579,7 @@ fn two_wallets_one_seed_impl(test_dir: &'static str) -> Result<(), libwallet::Er
|
||||
miner_mask,
|
||||
m_client.clone(),
|
||||
"wallet7",
|
||||
base_amount * 1
|
||||
base_amount
|
||||
)?;
|
||||
send_to_dest!(
|
||||
miner.clone(),
|
||||
@@ -710,7 +710,7 @@ fn output_scanning_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
false,
|
||||
_api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
thread::spawn(move || {
|
||||
if let Err(e) = wallet_proxy.run() {
|
||||
error!("Wallet Proxy error: {}", e);
|
||||
@@ -795,7 +795,7 @@ fn multi_batch_scan_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
thread::spawn(move || {
|
||||
if let Err(e) = wallet_proxy.run() {
|
||||
@@ -886,7 +886,7 @@ fn restore_corrupted_outputs_across_batches_impl(
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
thread::spawn(move || {
|
||||
if let Err(e) = wallet_proxy.run() {
|
||||
|
||||
@@ -109,6 +109,7 @@ pub fn create_wallet_proxy(
|
||||
WalletProxy::new(test_dir)
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn create_local_wallet(
|
||||
test_dir: &str,
|
||||
name: &str,
|
||||
@@ -116,17 +117,11 @@ pub fn create_local_wallet(
|
||||
client: LocalWalletClient,
|
||||
create_mask: bool,
|
||||
) -> (
|
||||
Arc<
|
||||
Mutex<
|
||||
Box<
|
||||
dyn WalletInst<
|
||||
'static,
|
||||
DefaultLCProvider<LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>,
|
||||
>,
|
||||
>,
|
||||
grin_wallet_libwallet::WalletHandle<
|
||||
'static,
|
||||
DefaultLCProvider<LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>,
|
||||
Option<SecretKey>,
|
||||
Owner<DefaultLCProvider<LocalWalletClient, ExtKeychain>, LocalWalletClient, ExtKeychain>,
|
||||
@@ -178,17 +173,11 @@ pub fn open_local_wallet(
|
||||
client: LocalWalletClient,
|
||||
create_mask: bool,
|
||||
) -> (
|
||||
Arc<
|
||||
Mutex<
|
||||
Box<
|
||||
dyn WalletInst<
|
||||
'static,
|
||||
DefaultLCProvider<LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>,
|
||||
>,
|
||||
>,
|
||||
grin_wallet_libwallet::WalletHandle<
|
||||
'static,
|
||||
DefaultLCProvider<LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>,
|
||||
Option<SecretKey>,
|
||||
) {
|
||||
|
||||
@@ -53,7 +53,7 @@ fn file_exchange_test_impl(test_dir: &'static str, use_bin: bool) -> Result<(),
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
@@ -65,7 +65,7 @@ fn file_exchange_test_impl(test_dir: &'static str, use_bin: bool) -> Result<(),
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
|
||||
@@ -49,7 +49,7 @@ fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
true,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
@@ -61,7 +61,7 @@ fn invoice_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
true,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
|
||||
@@ -49,7 +49,7 @@ fn late_lock_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
@@ -61,7 +61,7 @@ fn late_lock_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
|
||||
@@ -53,7 +53,7 @@ fn mwixnet_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
true,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -135,11 +135,11 @@ fn mwixnet_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
let server_pubkey_str_2 = "0c9414341f2140ed34a5a12a6479bf5a6404820d001ab81d9d3e8cc38f049b4e";
|
||||
let server_pubkey_str_3 = "b58ece97d60e71bb7e53218400b0d67bfe6a3cb7d3b4a67a44f8fb7c525cbca5";
|
||||
let server_key_1 =
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(&server_pubkey_str_1).unwrap())?;
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(server_pubkey_str_1).unwrap())?;
|
||||
let server_key_2 =
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(&server_pubkey_str_2).unwrap())?;
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(server_pubkey_str_2).unwrap())?;
|
||||
let server_key_3 =
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(&server_pubkey_str_3).unwrap())?;
|
||||
SecretKey::from_slice(&secp, &grin_util::from_hex(server_pubkey_str_3).unwrap())?;
|
||||
let params = MixnetReqCreationParams {
|
||||
server_keys: vec![server_key_1, server_key_2, server_key_3],
|
||||
fee_per_hop: 50_000_000,
|
||||
|
||||
@@ -48,7 +48,7 @@ fn no_change_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
api1
|
||||
);
|
||||
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
@@ -62,7 +62,7 @@ fn no_change_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
api2
|
||||
);
|
||||
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
|
||||
@@ -48,7 +48,7 @@ fn payment_proofs_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
|
||||
api1
|
||||
);
|
||||
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
@@ -62,7 +62,7 @@ fn payment_proofs_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
|
||||
api2
|
||||
);
|
||||
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
|
||||
@@ -52,7 +52,7 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
@@ -64,7 +64,7 @@ fn file_repost_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
|
||||
+13
-15
@@ -23,32 +23,25 @@ use grin_core::core::Transaction;
|
||||
use grin_core::global;
|
||||
use grin_keychain::ExtKeychain;
|
||||
use grin_util::secp::key::SecretKey;
|
||||
use grin_util::Mutex;
|
||||
use grin_wallet_api::Owner;
|
||||
use grin_wallet_impls::test_framework::*;
|
||||
use grin_wallet_impls::{DefaultLCProvider, PathToSlate, SlatePutter};
|
||||
use grin_wallet_libwallet as libwallet;
|
||||
use grin_wallet_libwallet::api_impl::types::InitTxArgs;
|
||||
use grin_wallet_libwallet::WalletInst;
|
||||
use log::error;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
type Wallet = Arc<
|
||||
Mutex<
|
||||
Box<
|
||||
dyn WalletInst<
|
||||
'static,
|
||||
DefaultLCProvider<LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>,
|
||||
>,
|
||||
>,
|
||||
type Wallet = grin_wallet_libwallet::WalletHandle<
|
||||
'static,
|
||||
DefaultLCProvider<LocalWalletClient, ExtKeychain>,
|
||||
LocalWalletClient,
|
||||
ExtKeychain,
|
||||
>;
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn revert(
|
||||
test_dir: &'static str,
|
||||
) -> Result<
|
||||
@@ -189,8 +182,13 @@ fn revert(
|
||||
|
||||
// Build 2 blocks at same height: 1 with the tx, 1 without
|
||||
let head = chain.head_header().unwrap();
|
||||
let block_with =
|
||||
create_block_for_wallet(&chain, head.clone(), &[tx.clone()], wallet1.clone(), mask1)?;
|
||||
let block_with = create_block_for_wallet(
|
||||
&chain,
|
||||
head.clone(),
|
||||
std::slice::from_ref(&tx),
|
||||
wallet1.clone(),
|
||||
mask1,
|
||||
)?;
|
||||
let block_without = create_block_for_wallet(&chain, head, &[], wallet1.clone(), mask1)?;
|
||||
|
||||
// Add block with tx to the chain
|
||||
|
||||
@@ -51,7 +51,7 @@ fn self_send_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
true,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
|
||||
@@ -57,7 +57,7 @@ fn output_slatepack(
|
||||
if armored {
|
||||
file = format!("{}.armored", file);
|
||||
}
|
||||
PathToSlatepack::new(file.into(), &packer, armored).put_tx(&slate, use_bin)
|
||||
PathToSlatepack::new(file.into(), &packer, armored).put_tx(slate, use_bin)
|
||||
}
|
||||
|
||||
fn slate_from_packed(
|
||||
@@ -103,7 +103,7 @@ fn slatepack_exchange_test_impl(
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
@@ -115,7 +115,7 @@ fn slatepack_exchange_test_impl(
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -217,7 +217,7 @@ fn slatepack_exchange_test_impl(
|
||||
}
|
||||
|
||||
let (mut slatepack, mut slate) =
|
||||
slate_from_packed(&send_file, use_armored, (&dec_key_2).as_ref())?;
|
||||
slate_from_packed(&send_file, use_armored, dec_key_2.as_ref())?;
|
||||
|
||||
// wallet 2 receives file, completes, sends file back
|
||||
wallet::controller::foreign_single_use(
|
||||
@@ -243,7 +243,7 @@ fn slatepack_exchange_test_impl(
|
||||
)?;
|
||||
|
||||
// wallet 1 finalizes and posts
|
||||
let (_, mut slate) = slate_from_packed(&receive_file, use_armored, (&dec_key_1).as_ref())?;
|
||||
let (_, mut slate) = slate_from_packed(&receive_file, use_armored, dec_key_1.as_ref())?;
|
||||
slate = api1.finalize_tx(mask1, &slate)?;
|
||||
// Output final file for reference
|
||||
output_slatepack(&slate, &final_file, use_armored, use_bin, None, vec![])?;
|
||||
@@ -303,7 +303,7 @@ fn slatepack_exchange_test_impl(
|
||||
selection_strategy_is_use_all: true,
|
||||
..Default::default()
|
||||
};
|
||||
let res = slate_from_packed(&send_file, use_armored, (&dec_key_1).as_ref())?;
|
||||
let res = slate_from_packed(&send_file, use_armored, dec_key_1.as_ref())?;
|
||||
slatepack = res.0;
|
||||
slate = res.1;
|
||||
slate = api1.process_invoice_tx(mask1, &slate, args)?;
|
||||
@@ -325,7 +325,7 @@ fn slatepack_exchange_test_impl(
|
||||
mask2_i.clone(),
|
||||
|api| {
|
||||
// Wallet 2 receives the invoice transaction
|
||||
let res = slate_from_packed(&receive_file, use_armored, (&dec_key_2).as_ref())?;
|
||||
let res = slate_from_packed(&receive_file, use_armored, dec_key_2.as_ref())?;
|
||||
slate = res.1;
|
||||
slate = api.finalize_tx(&slate, false)?;
|
||||
output_slatepack(&slate, &final_file, use_armored, use_bin, None, vec![])?;
|
||||
@@ -378,7 +378,7 @@ fn slatepack_exchange_test_impl(
|
||||
PathBuf::from(test_dir),
|
||||
mask2_i.clone(),
|
||||
|api| {
|
||||
let res = slate_from_packed(&send_file, use_armored, (&dec_key_2).as_ref())?;
|
||||
let res = slate_from_packed(&send_file, use_armored, dec_key_2.as_ref())?;
|
||||
let slatepack = res.0;
|
||||
slate = res.1;
|
||||
slate = api.receive_tx(&slate, None, None)?;
|
||||
@@ -398,7 +398,7 @@ fn slatepack_exchange_test_impl(
|
||||
)?;
|
||||
|
||||
// wallet 1 finalizes and posts
|
||||
let res = slate_from_packed(&receive_file, use_armored, (&dec_key_1).as_ref())?;
|
||||
let res = slate_from_packed(&receive_file, use_armored, dec_key_1.as_ref())?;
|
||||
slate = res.1;
|
||||
slate = api1.finalize_tx(mask1, &slate)?;
|
||||
// Output final file for reference
|
||||
@@ -432,7 +432,7 @@ fn slatepack_api_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -494,7 +494,7 @@ fn slatepack_address_validation(test_dir: &'static str) -> Result<(), libwallet:
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
@@ -507,7 +507,7 @@ fn slatepack_address_validation(test_dir: &'static str) -> Result<(), libwallet:
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
let proxy_thread = thread::spawn(move || {
|
||||
if let Err(e) = wallet_proxy.run() {
|
||||
|
||||
@@ -56,7 +56,7 @@ fn basic_transaction_api(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
true,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
println!("Mask1: {:?}", mask1);
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
@@ -69,7 +69,7 @@ fn basic_transaction_api(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
println!("Mask2: {:?}", mask2);
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
@@ -530,7 +530,7 @@ fn tx_rollback(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
@@ -542,7 +542,7 @@ fn tx_rollback(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
@@ -592,10 +592,10 @@ fn tx_rollback(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
api1.retrieve_outputs(mask1, true, false, Some(tx.unwrap().id))?;
|
||||
for m in output_mappings.clone() {
|
||||
if m.output.status == OutputStatus::Locked {
|
||||
locked_count = locked_count + 1;
|
||||
locked_count += 1;
|
||||
}
|
||||
if m.output.status == OutputStatus::Unconfirmed {
|
||||
unconfirmed_count = unconfirmed_count + 1;
|
||||
unconfirmed_count += 1;
|
||||
}
|
||||
}
|
||||
assert_eq!(output_mappings.len(), 3);
|
||||
@@ -614,7 +614,7 @@ fn tx_rollback(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
let (_, outputs) = api2.retrieve_outputs(mask2, true, false, Some(tx.unwrap().id))?;
|
||||
for m in outputs.clone() {
|
||||
if m.output.status == OutputStatus::Unconfirmed {
|
||||
unconfirmed_count = unconfirmed_count + 1;
|
||||
unconfirmed_count += 1;
|
||||
}
|
||||
}
|
||||
assert_eq!(outputs.len(), 1);
|
||||
@@ -697,7 +697,7 @@ fn big_amount_error(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
true,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
println!("Mask1: {:?}", mask1);
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
@@ -762,16 +762,15 @@ fn big_amount_error(test_dir: &'static str) -> Result<(), libwallet::Error> {
|
||||
|
||||
match result {
|
||||
Ok(_) => {}
|
||||
Err(e) => match e {
|
||||
libwallet::Error::BigAmountError(a, fee, num_inputs) => {
|
||||
Err(e) => {
|
||||
if let libwallet::Error::BigAmountError(a, fee, num_inputs) = e {
|
||||
let (_, e_a, e_fee, e_num_inputs) =
|
||||
api1.estimate_max_sendable(mask1, true, min_confirmations)?;
|
||||
assert_eq!(e_a, a - fee);
|
||||
assert_eq!(e_fee, fee);
|
||||
assert_eq!(e_num_inputs, num_inputs);
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// let logging finish
|
||||
|
||||
@@ -48,7 +48,7 @@ fn ttl_cutoff_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
api1
|
||||
);
|
||||
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
@@ -62,7 +62,7 @@ fn ttl_cutoff_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
|
||||
api2
|
||||
);
|
||||
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
|
||||
@@ -50,10 +50,11 @@ fn test_wallet_tx_filtering(
|
||||
assert!(!txs.is_empty());
|
||||
let before_first_tx =
|
||||
txs.iter().map(|tx| tx.creation_ts).min().unwrap() - Duration::from_secs(1);
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
|
||||
// Max creation time before all test transactions
|
||||
tx_query_args.max_creation_timestamp = Some(before_first_tx);
|
||||
let mut tx_query_args = RetrieveTxQueryArgs {
|
||||
max_creation_timestamp: Some(before_first_tx),
|
||||
..Default::default()
|
||||
};
|
||||
assert!(query(tx_query_args.clone())?.is_empty());
|
||||
|
||||
// Min confirmation time should not affect creation time
|
||||
@@ -61,8 +62,10 @@ fn test_wallet_tx_filtering(
|
||||
tx_query_args.min_confirmed_timestamp = Some(before_first_tx);
|
||||
assert_eq!(query(tx_query_args)?.len(), txs.len());
|
||||
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.min_id = Some(5);
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
min_id: Some(5),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// Min ID
|
||||
let tx_results = api
|
||||
@@ -72,9 +75,11 @@ fn test_wallet_tx_filtering(
|
||||
assert_eq!(tx_results[tx_results.len() - 1].id, 33);
|
||||
|
||||
// Max ID
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.min_id = Some(5);
|
||||
tx_query_args.max_id = Some(20);
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
min_id: Some(5),
|
||||
max_id: Some(20),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
@@ -82,109 +87,133 @@ fn test_wallet_tx_filtering(
|
||||
assert_eq!(tx_results[tx_results.len() - 1].id, 20);
|
||||
|
||||
// Exclude 1 canceled
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.exclude_cancelled = Some(true);
|
||||
tx_query_args.min_id = Some(5);
|
||||
tx_query_args.max_id = Some(50);
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
exclude_cancelled: Some(true),
|
||||
min_id: Some(5),
|
||||
max_id: Some(50),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 28);
|
||||
|
||||
// Exclude 1 canceled, show confirmed only
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.exclude_cancelled = Some(true);
|
||||
tx_query_args.include_confirmed_only = Some(true);
|
||||
tx_query_args.min_id = Some(5);
|
||||
tx_query_args.max_id = Some(50);
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
exclude_cancelled: Some(true),
|
||||
include_confirmed_only: Some(true),
|
||||
min_id: Some(5),
|
||||
max_id: Some(50),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 14);
|
||||
|
||||
// show outstanding only (including canceled)
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.exclude_cancelled = Some(false);
|
||||
tx_query_args.include_outstanding_only = Some(true);
|
||||
tx_query_args.min_id = Some(5);
|
||||
tx_query_args.max_id = Some(50);
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
exclude_cancelled: Some(false),
|
||||
include_outstanding_only: Some(true),
|
||||
min_id: Some(5),
|
||||
max_id: Some(50),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 15);
|
||||
|
||||
// outstanding only and confirmed only should give empty set
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.exclude_cancelled = Some(false);
|
||||
tx_query_args.include_outstanding_only = Some(true);
|
||||
tx_query_args.include_confirmed_only = Some(true);
|
||||
tx_query_args.min_id = Some(5);
|
||||
tx_query_args.max_id = Some(50);
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
exclude_cancelled: Some(false),
|
||||
include_outstanding_only: Some(true),
|
||||
include_confirmed_only: Some(true),
|
||||
min_id: Some(5),
|
||||
max_id: Some(50),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 0);
|
||||
|
||||
// include sent only
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.include_sent_only = Some(true);
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
include_sent_only: Some(true),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 15);
|
||||
|
||||
// include received only (none in this set)
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.include_received_only = Some(true);
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
include_received_only: Some(true),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 0);
|
||||
|
||||
// include reverted only (none in this set)
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.include_reverted_only = Some(true);
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
include_reverted_only: Some(true),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 0);
|
||||
|
||||
// include coinbase only
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.include_coinbase_only = Some(true);
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
include_coinbase_only: Some(true),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 19);
|
||||
|
||||
// Amounts
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.min_amount = Some(60_000_000_000 - 59_963_300_000);
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
min_amount: Some(60_000_000_000 - 59_963_300_000),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 27);
|
||||
|
||||
// amount, should see as above with coinbases excluded
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.min_amount = Some(60_000_000_000 - 59_963_300_000);
|
||||
tx_query_args.max_amount = Some(60_000_000_000 - 1);
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
min_amount: Some(60_000_000_000 - 59_963_300_000),
|
||||
max_amount: Some(60_000_000_000 - 1),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 8);
|
||||
|
||||
// Amount - should only see coinbase (incoming)
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.min_amount = Some(60_000_000_000);
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
min_amount: Some(60_000_000_000),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
assert_eq!(tx_results.len(), 19);
|
||||
|
||||
// sort order
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.sort_order = Some(libwallet::RetrieveTxQuerySortOrder::Desc);
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
sort_order: Some(libwallet::RetrieveTxQuerySortOrder::Desc),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
@@ -193,9 +222,11 @@ fn test_wallet_tx_filtering(
|
||||
assert_eq!(tx_results[tx_results.len() - 1].id, 0);
|
||||
|
||||
// change sort field to amount desc, should have coinbases first
|
||||
let mut tx_query_args = RetrieveTxQueryArgs::default();
|
||||
tx_query_args.sort_order = Some(libwallet::RetrieveTxQuerySortOrder::Desc);
|
||||
tx_query_args.sort_field = Some(RetrieveTxQuerySortField::TotalAmount);
|
||||
let tx_query_args = RetrieveTxQueryArgs {
|
||||
sort_order: Some(libwallet::RetrieveTxQuerySortOrder::Desc),
|
||||
sort_field: Some(RetrieveTxQuerySortField::TotalAmount),
|
||||
..Default::default()
|
||||
};
|
||||
let tx_results = api
|
||||
.retrieve_txs(mask, true, None, None, Some(tx_query_args))?
|
||||
.1;
|
||||
@@ -224,7 +255,7 @@ fn build_chain_for_tx_filtering(
|
||||
true,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
debug!("Mask1: {:?}", mask1);
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
@@ -237,7 +268,7 @@ fn build_chain_for_tx_filtering(
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
debug!("Mask2: {:?}", mask2);
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
|
||||
@@ -49,7 +49,7 @@ fn updater_thread_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
|
||||
false,
|
||||
api1
|
||||
);
|
||||
let mask1 = (&mask1_i).as_ref();
|
||||
let mask1 = mask1_i.as_ref();
|
||||
create_wallet_and_add!(
|
||||
client2,
|
||||
wallet2,
|
||||
@@ -61,7 +61,7 @@ fn updater_thread_test_impl(test_dir: &'static str) -> Result<(), libwallet::Err
|
||||
false,
|
||||
api2
|
||||
);
|
||||
let mask2 = (&mask2_i).as_ref();
|
||||
let mask2 = mask2_i.as_ref();
|
||||
|
||||
// Set the wallet proxy listener running
|
||||
thread::spawn(move || {
|
||||
|
||||
Reference in New Issue
Block a user