From 4275ca3ba1f47f63a8b8289d1a39b3f0be45c749 Mon Sep 17 00:00:00 2001 From: chris-belcher Date: Sun, 30 Jan 2022 13:59:17 +0000 Subject: [PATCH] Rename "swap_coin" to "swapcoin" "Swapcoin" is now a noun, so "swap coin" or "swap_coin" is confusing and not a good name. Renaming. This commit breaks compatibility with old .teleport wallet files. --- src/maker_protocol.rs | 6 +-- src/taker_protocol.rs | 10 ++--- src/wallet_sync.rs | 70 ++++++++++++++++----------------- tests/test_standard_coinswap.rs | 6 +-- 4 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/maker_protocol.rs b/src/maker_protocol.rs index 6254738f..a038d8c0 100644 --- a/src/maker_protocol.rs +++ b/src/maker_protocol.rs @@ -717,7 +717,7 @@ async fn handle_senders_and_receivers_contract_sigs( outgoing_swapcoins .iter() .for_each(|outgoing_swapcoin| w.add_outgoing_swapcoin(outgoing_swapcoin.clone())); - w.update_swap_coins_list()?; + w.update_swapcoins_list()?; let mut my_funding_txids = Vec::::new(); for my_funding_tx in connection_state.pending_funding_txes.as_ref().unwrap() { @@ -799,7 +799,7 @@ fn handle_hash_preimage( }); } - wallet_ref.update_swap_coins_list()?; + wallet_ref.update_swapcoins_list()?; Ok(Some(MakerToTakerMessage::PrivateKeyHandover( PrivateKeyHandover { swapcoin_private_keys, @@ -818,7 +818,7 @@ fn handle_private_key_handover( .ok_or(Error::Protocol("multisig_redeemscript not found"))? .apply_privkey(swapcoin_private_key.key)? } - wallet_ref.update_swap_coins_list()?; + wallet_ref.update_swapcoins_list()?; log::info!("Successfully Completed Coinswap"); Ok(None) } diff --git a/src/taker_protocol.rs b/src/taker_protocol.rs index a183222d..e644764c 100644 --- a/src/taker_protocol.rs +++ b/src/taker_protocol.rs @@ -147,7 +147,7 @@ async fn send_coinswap( for outgoing_swapcoin in &outgoing_swapcoins { wallet.add_outgoing_swapcoin(outgoing_swapcoin.clone()); } - wallet.update_swap_coins_list().unwrap(); + wallet.update_swapcoins_list().unwrap(); log::debug!("My Funding Tx: {:#?}", my_funding_txes); log::debug!("Outgoing SwapCoins: {:#?}", outgoing_swapcoins); @@ -266,7 +266,7 @@ async fn send_coinswap( &maker_sign_sender_and_receiver_contracts, )? } else { - let next_swapcoins = create_watch_only_swap_coins( + let next_swapcoins = create_watch_only_swapcoins( rpc, &maker_sign_sender_and_receiver_contracts, &next_peer_multisig_pubkeys, @@ -438,7 +438,7 @@ async fn send_coinswap( for incoming_swapcoin in &incoming_swapcoins { wallet.add_incoming_swapcoin(incoming_swapcoin.clone()); } - wallet.update_swap_coins_list().unwrap(); + wallet.update_swapcoins_list().unwrap(); let mut outgoing_privkeys: Option> = None; for (index, maker_address) in active_maker_addresses.iter().enumerate() { @@ -534,7 +534,7 @@ async fn send_coinswap( .unwrap() .other_privkey = incoming_swapcoin.other_privkey; } - wallet.update_swap_coins_list().unwrap(); + wallet.update_swapcoins_list().unwrap(); log::info!("Successfully Completed Coinswap"); Ok(()) @@ -1011,7 +1011,7 @@ fn sign_senders_contract_txes( .map_err(|_| Error::Protocol("error with signing contract tx")) } -fn create_watch_only_swap_coins( +fn create_watch_only_swapcoins( rpc: &Client, maker_sign_sender_and_receiver_contracts: &SignSendersAndReceiversContractTxes, next_peer_multisig_pubkeys: &[PublicKey], diff --git a/src/wallet_sync.rs b/src/wallet_sync.rs index 139bc84c..b6a06e3d 100644 --- a/src/wallet_sync.rs +++ b/src/wallet_sync.rs @@ -70,8 +70,8 @@ struct WalletFileData { seedphrase: String, extension: String, external_index: u32, - incoming_swap_coins: Vec, - outgoing_swap_coins: Vec, + incoming_swapcoins: Vec, + outgoing_swapcoins: Vec, prevout_to_contract_map: HashMap, } @@ -80,8 +80,8 @@ pub struct Wallet { wallet_file_name: String, external_index: u32, initial_address_import_count: usize, - incoming_swap_coins: HashMap, - outgoing_swap_coins: HashMap, + incoming_swapcoins: HashMap, + outgoing_swapcoins: HashMap, } pub enum WalletSyncAddressAmount { @@ -443,15 +443,15 @@ impl Wallet { self.master_key, self.external_index ); - for (multisig_redeemscript, swapcoin) in &self.incoming_swap_coins { + for (multisig_redeemscript, swapcoin) in &self.incoming_swapcoins { Self::print_script_and_coin(multisig_redeemscript, swapcoin); } - for (multisig_redeemscript, swapcoin) in &self.outgoing_swap_coins { + for (multisig_redeemscript, swapcoin) in &self.outgoing_swapcoins { Self::print_script_and_coin(multisig_redeemscript, swapcoin); } println!( "swapcoin count = {}", - self.incoming_swap_coins.len() + self.outgoing_swap_coins.len() + self.incoming_swapcoins.len() + self.outgoing_swapcoins.len() ); } @@ -480,8 +480,8 @@ impl Wallet { seedphrase, extension, external_index: 0, - incoming_swap_coins: Vec::new(), - outgoing_swap_coins: Vec::new(), + incoming_swapcoins: Vec::new(), + outgoing_swapcoins: Vec::new(), prevout_to_contract_map: HashMap::::new(), }; let wallet_file = File::create(wallet_file_name)?; @@ -521,9 +521,9 @@ impl Wallet { let xprv = ExtendedPrivKey::new_master(NETWORK, &seed.0).unwrap(); log::debug!(target: "wallet", - "loaded wallet file, external_index={} incoming_swap_coins={} outgoing_swap_coins={}", + "loaded wallet file, external_index={} incoming_swapcoins={} outgoing_swapcoins={}", wallet_file_data.external_index, - wallet_file_data.incoming_swap_coins.len(), wallet_file_data.outgoing_swap_coins.len()); + wallet_file_data.incoming_swapcoins.len(), wallet_file_data.outgoing_swapcoins.len()); let wallet = Wallet { master_key: xprv, @@ -533,13 +533,13 @@ impl Wallet { WalletSyncAddressAmount::Normal => 5000, WalletSyncAddressAmount::Testing => 6, }, - incoming_swap_coins: wallet_file_data - .incoming_swap_coins + incoming_swapcoins: wallet_file_data + .incoming_swapcoins .iter() .map(|sc| (sc.get_multisig_redeemscript(), sc.clone())) .collect::>(), - outgoing_swap_coins: wallet_file_data - .outgoing_swap_coins + outgoing_swapcoins: wallet_file_data + .outgoing_swapcoins .iter() .map(|sc| (sc.get_multisig_redeemscript(), sc.clone())) .collect::>(), @@ -560,15 +560,15 @@ impl Wallet { self.external_index } - pub fn update_swap_coins_list(&self) -> Result<(), Error> { + pub fn update_swapcoins_list(&self) -> Result<(), Error> { let mut wallet_file_data = Wallet::load_wallet_file_data(&self.wallet_file_name)?; - wallet_file_data.incoming_swap_coins = self - .incoming_swap_coins + wallet_file_data.incoming_swapcoins = self + .incoming_swapcoins .values() .cloned() .collect::>(); - wallet_file_data.outgoing_swap_coins = self - .outgoing_swap_coins + wallet_file_data.outgoing_swapcoins = self + .outgoing_swapcoins .values() .cloned() .collect::>(); @@ -581,35 +581,35 @@ impl Wallet { &self, multisig_redeemscript: &Script, ) -> Option<&IncomingSwapCoin> { - self.incoming_swap_coins.get(multisig_redeemscript) + self.incoming_swapcoins.get(multisig_redeemscript) } pub fn find_outgoing_swapcoin( &self, multisig_redeemscript: &Script, ) -> Option<&OutgoingSwapCoin> { - self.outgoing_swap_coins.get(multisig_redeemscript) + self.outgoing_swapcoins.get(multisig_redeemscript) } pub fn find_incoming_swapcoin_mut( &mut self, multisig_redeemscript: &Script, ) -> Option<&mut IncomingSwapCoin> { - self.incoming_swap_coins.get_mut(multisig_redeemscript) + self.incoming_swapcoins.get_mut(multisig_redeemscript) } pub fn add_incoming_swapcoin(&mut self, coin: IncomingSwapCoin) { - self.incoming_swap_coins + self.incoming_swapcoins .insert(coin.get_multisig_redeemscript(), coin); } pub fn add_outgoing_swapcoin(&mut self, coin: OutgoingSwapCoin) { - self.outgoing_swap_coins + self.outgoing_swapcoins .insert(coin.get_multisig_redeemscript(), coin); } - pub fn get_swap_coins_count(&self) -> usize { - self.incoming_swap_coins.len() + self.outgoing_swap_coins.len() + pub fn get_swapcoins_count(&self) -> usize { + self.incoming_swapcoins.len() + self.outgoing_swapcoins.len() } //this function is used in two places @@ -776,7 +776,7 @@ impl Wallet { .collect::>(); let mut swapcoin_descriptors_to_import = self - .incoming_swap_coins + .incoming_swapcoins .values() .map(|sc| { format!( @@ -790,7 +790,7 @@ impl Wallet { .collect::>(); swapcoin_descriptors_to_import.extend( - self.outgoing_swap_coins + self.outgoing_swapcoins .values() .map(|sc| { format!( @@ -854,7 +854,7 @@ impl Wallet { fn create_contract_scriptpubkey_outgoing_swapcoin_hashmap( &self, ) -> HashMap { - self.outgoing_swap_coins + self.outgoing_swapcoins .values() .map(|osc| { ( @@ -868,7 +868,7 @@ impl Wallet { fn create_contract_scriptpubkey_incoming_swapcoin_hashmap( &self, ) -> HashMap { - self.incoming_swap_coins + self.incoming_swapcoins .values() .map(|isc| { ( @@ -1034,7 +1034,7 @@ impl Wallet { .map_err(|e| Error::Rpc(e))?; let completed_coinswap_hashvalues = self - .incoming_swap_coins + .incoming_swapcoins .values() .filter(|sc| sc.other_privkey.is_some()) .map(|sc| sc.get_hashvalue()) @@ -1114,7 +1114,7 @@ impl Wallet { .map_err(|e| Error::Rpc(e))?; let listunspent = rpc.list_unspent(Some(0), Some(9999999), None, None, None)?; - let (incoming_swap_coins_utxos, outgoing_swap_coins_utxos): (Vec<_>, Vec<_>) = listunspent + let (incoming_swapcoins_utxos, outgoing_swapcoins_utxos): (Vec<_>, Vec<_>) = listunspent .iter() .map(|u| { ( @@ -1127,11 +1127,11 @@ impl Wallet { .partition(|isc_osc_u| isc_osc_u.0.is_some()); Ok(( - incoming_swap_coins_utxos + incoming_swapcoins_utxos .iter() .map(|isc_osc_u| (*isc_osc_u.0.unwrap(), isc_osc_u.2.clone())) .collect::>(), - outgoing_swap_coins_utxos + outgoing_swapcoins_utxos .iter() .map(|isc_osc_u| (*isc_osc_u.1.unwrap(), isc_osc_u.2.clone())) .collect::>(), diff --git a/tests/test_standard_coinswap.rs b/tests/test_standard_coinswap.rs index cddcaca2..f62feefe 100644 --- a/tests/test_standard_coinswap.rs +++ b/tests/test_standard_coinswap.rs @@ -213,9 +213,9 @@ async fn test_standard_coinswap() { Wallet::load_wallet_from_file(&MAKER2, WalletSyncAddressAmount::Testing).unwrap(); // Check assertions - assert_eq!(taker_wallet.get_swap_coins_count(), 6); - assert_eq!(maker1_wallet.get_swap_coins_count(), 6); - assert_eq!(maker2_wallet.get_swap_coins_count(), 6); + assert_eq!(taker_wallet.get_swapcoins_count(), 6); + assert_eq!(maker1_wallet.get_swapcoins_count(), 6); + assert_eq!(maker2_wallet.get_swapcoins_count(), 6); let rpc = teleport::get_bitcoin_rpc().unwrap();