pub fn swap_list<'a, L, C, K>(
	wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
	keychain_mask: Option<&SecretKey>,
	do_check: bool,
) -> Result<Vec<SwapListInfo>, Error>
where
	L: WalletLCProvider<'a, C, K>,
	C: NodeClient + 'a,
	K: Keychain + 'a,
{
	// Need to lock first to check if the wallet is open
	wallet_lock!(wallet_inst, w);

	let swap_id = trades::list_swap_trades()?;
	let mut result: Vec<SwapListInfo> = Vec::new();

	let node_client = w.w2n_client().clone();
	let keychain = w.keychain(keychain_mask)?;
	let skey = get_swap_storage_key(&keychain)?;

	for sw_id in &swap_id {
		let swap_lock = trades::get_swap_lock(sw_id);
		let _l = swap_lock.lock();
		let (context, mut swap) = trades::get_swap_trade(sw_id.as_str(), &skey, &*swap_lock)?;
		let trade_start_time = swap.started.timestamp();
		let info = if swap.is_seller() {
			format!(
				"Sell {} MWC for {} {}",
				core::amount_to_hr_string(swap.primary_amount, true),
				swap.secondary_currency
					.amount_to_hr_string(swap.secondary_amount, true),
				swap.secondary_currency,
			)
		} else {
			format!(
				"Buy {} MWC for {} {}",
				core::amount_to_hr_string(swap.primary_amount, true),
				swap.secondary_currency
					.amount_to_hr_string(swap.secondary_amount, true),
				swap.secondary_currency,
			)
		};

		if do_check && !swap.state.is_final_state() {
			let (state, action, expiration, _state_eta) = update_swap_status_action_impl(
				&mut swap,
				&context,
				node_client.clone(),
				&keychain,
			)?;
			result.push(SwapListInfo {
				swap_id: sw_id.clone(),
				is_seller: swap.is_seller(),
				info,
				state,
				action: Some(action),
				expiration,
				trade_start_time,
				secondary_address: swap.get_secondary_address(),
			});
		} else {
			result.push(SwapListInfo {
				swap_id: sw_id.clone(),
				is_seller: swap.is_seller(),
				info,
				state: swap.state.clone(),
				action: None,
				expiration: None,
				trade_start_time,
				secondary_address: swap.get_secondary_address(),
			});
		}
		trades::store_swap_trade(&context, &swap, &skey, &*swap_lock)?;
	}

	Ok(result)
}
/// List Swap trades. Returns SwapId + Status
List Swap trades. Returns SwapId + Status
List Swap trades . Returns SwapId + Status
pub fn swap_list<'a, L, C, K>(
	wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
	keychain_mask: Option<&SecretKey>,
	do_check: bool,
) -> Result<Vec<SwapListInfo>, Error>
where
	L: WalletLCProvider<'a, C, K>,
	C: NodeClient + 'a,
	K: Keychain + 'a,
{
	// Need to lock first to check if the wallet is open
	wallet_lock!(wallet_inst, w);
	let swap_id = trades::list_swap_trades()?;
	let mut result: Vec<SwapListInfo> = Vec::new();
	let node_client = w.w2n_client().clone();
	let keychain = w.keychain(keychain_mask)?;
	let skey = get_swap_storage_key(&keychain)?;
	for sw_id in &swap_id {
		let swap_lock = trades::get_swap_lock(sw_id);
		let _l = swap_lock.lock();
		let (context, mut swap) = trades::get_swap_trade(sw_id.as_str(), &skey, &*swap_lock)?;
		let trade_start_time = swap.started.timestamp();
		let info = if swap.is_seller() {
			format!(
				"Sell {} MWC for {} {}",
				core::amount_to_hr_string(swap.primary_amount, true),
				swap.secondary_currency
					.amount_to_hr_string(swap.secondary_amount, true),
				swap.secondary_currency,
			)
		} else {
			format!(
				"Buy {} MWC for {} {}",
				core::amount_to_hr_string(swap.primary_amount, true),
				swap.secondary_currency
					.amount_to_hr_string(swap.secondary_amount, true),
				swap.secondary_currency,
			)
		};
		if do_check && !swap.state.is_final_state() {
			let (state, action, expiration, _state_eta) = update_swap_status_action_impl(
				&mut swap,
				&context,
				node_client.clone(),
				&keychain,
			)?;
			result.push(SwapListInfo {
				swap_id: sw_id.clone(),
				is_seller: swap.is_seller(),
				info,
				state,
				action: Some(action),
				expiration,
				trade_start_time,
				secondary_address: swap.get_secondary_address(),
			});
		} else {
			result.push(SwapListInfo {
				swap_id: sw_id.clone(),
				is_seller: swap.is_seller(),
				info,
				state: swap.state.clone(),
				action: None,
				expiration: None,
				trade_start_time,
				secondary_address: swap.get_secondary_address(),
			});
		}
		trades::store_swap_trade(&context, &swap, &skey, &*swap_lock)?;
	}
	Ok(result)
}
pub fn swap_list < ' a , L , C , K > ( wallet_inst : Arc < Mutex < Box < dyn WalletInst < ' a , L , C , K > > > > , keychain_mask : Option < & SecretKey > , do_check : bool , ) -> Result < Vec < SwapListInfo > , Error > where L : WalletLCProvider < ' a , C , K > , C : NodeClient + ' a , K : Keychain + ' a , { // Need to lock first to check if the wallet is open wallet_lock ! ( wallet_inst w ) ; let swap_id = trades :: list_swap_trades ( ) ? ; let mut result : Vec < SwapListInfo > = Vec :: new ( ) ; let node_client = w . w2n_client ( ) . clone ( ) ; let keychain = w . keychain ( keychain_mask ) ? ; let skey = get_swap_storage_key ( & keychain ) ? ; for sw_id in & swap_id { let swap_lock = trades :: get_swap_lock ( sw_id ) ; let _l = swap_lock . lock ( ) ; let ( context , mut swap ) = trades :: get_swap_trade ( sw_id . as_str ( ) , & skey , & * swap_lock ) ? ; let trade_start_time = swap . started . timestamp ( ) ; let info = if swap . is_seller ( ) { format ! ( " " core amount_to_hr_string ( swap primary_amount true ) swap secondary_currency amount_to_hr_string ( swap secondary_amount true ) swap secondary_currency ) } else { format ! ( " " core amount_to_hr_string ( swap primary_amount true ) swap secondary_currency amount_to_hr_string ( swap secondary_amount true ) swap secondary_currency ) } ; if do_check && ! swap . state . is_final_state ( ) { let ( state , action , expiration , _state_eta ) = update_swap_status_action_impl ( & mut swap , & context , node_client . clone ( ) , & keychain , ) ? ; result . push ( SwapListInfo { swap_id : sw_id . clone ( ) , is_seller : swap . is_seller ( ) , info , state , action : Some ( action ) , expiration , trade_start_time , secondary_address : swap . get_secondary_address ( ) , } ) ; } else { result . push ( SwapListInfo { swap_id : sw_id . clone ( ) , is_seller : swap . is_seller ( ) , info , state : swap . state . clone ( ) , action : None , expiration : None , trade_start_time , secondary_address : swap . get_secondary_address ( ) , } ) ; } trades :: store_swap_trade ( & context , & swap , & skey , & * swap_lock ) ? ; } Ok ( result ) }
List Swap trades.
List Swap trades .
wallet_inst
Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>
keychain_mask
Option<&SecretKey>
do_check
bool
wallet_inst
Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>
keychain_mask
Option<&SecretKey>
do_check
bool