Skip to content

Commit

Permalink
Rename "swap_coin" to "swapcoin"
Browse files Browse the repository at this point in the history
"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.
  • Loading branch information
chris-belcher committed Jan 30, 2022
1 parent f10e1d5 commit 4275ca3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 46 deletions.
6 changes: 3 additions & 3 deletions src/maker_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Txid>::new();
for my_funding_tx in connection_state.pending_funding_txes.as_ref().unwrap() {
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
10 changes: 5 additions & 5 deletions src/taker_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<Vec<SwapCoinPrivateKey>> = None;
for (index, maker_address) in active_maker_addresses.iter().enumerate() {
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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],
Expand Down
70 changes: 35 additions & 35 deletions src/wallet_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ struct WalletFileData {
seedphrase: String,
extension: String,
external_index: u32,
incoming_swap_coins: Vec<IncomingSwapCoin>,
outgoing_swap_coins: Vec<OutgoingSwapCoin>,
incoming_swapcoins: Vec<IncomingSwapCoin>,
outgoing_swapcoins: Vec<OutgoingSwapCoin>,
prevout_to_contract_map: HashMap<OutPoint, Script>,
}

Expand All @@ -80,8 +80,8 @@ pub struct Wallet {
wallet_file_name: String,
external_index: u32,
initial_address_import_count: usize,
incoming_swap_coins: HashMap<Script, IncomingSwapCoin>,
outgoing_swap_coins: HashMap<Script, OutgoingSwapCoin>,
incoming_swapcoins: HashMap<Script, IncomingSwapCoin>,
outgoing_swapcoins: HashMap<Script, OutgoingSwapCoin>,
}

pub enum WalletSyncAddressAmount {
Expand Down Expand Up @@ -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()
);
}

Expand Down Expand Up @@ -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::<OutPoint, Script>::new(),
};
let wallet_file = File::create(wallet_file_name)?;
Expand Down Expand Up @@ -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,
Expand All @@ -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::<HashMap<Script, IncomingSwapCoin>>(),
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::<HashMap<Script, OutgoingSwapCoin>>(),
Expand All @@ -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::<Vec<IncomingSwapCoin>>();
wallet_file_data.outgoing_swap_coins = self
.outgoing_swap_coins
wallet_file_data.outgoing_swapcoins = self
.outgoing_swapcoins
.values()
.cloned()
.collect::<Vec<OutgoingSwapCoin>>();
Expand All @@ -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
Expand Down Expand Up @@ -776,7 +776,7 @@ impl Wallet {
.collect::<Vec<&String>>();

let mut swapcoin_descriptors_to_import = self
.incoming_swap_coins
.incoming_swapcoins
.values()
.map(|sc| {
format!(
Expand All @@ -790,7 +790,7 @@ impl Wallet {
.collect::<Vec<String>>();

swapcoin_descriptors_to_import.extend(
self.outgoing_swap_coins
self.outgoing_swapcoins
.values()
.map(|sc| {
format!(
Expand Down Expand Up @@ -854,7 +854,7 @@ impl Wallet {
fn create_contract_scriptpubkey_outgoing_swapcoin_hashmap(
&self,
) -> HashMap<Script, &OutgoingSwapCoin> {
self.outgoing_swap_coins
self.outgoing_swapcoins
.values()
.map(|osc| {
(
Expand All @@ -868,7 +868,7 @@ impl Wallet {
fn create_contract_scriptpubkey_incoming_swapcoin_hashmap(
&self,
) -> HashMap<Script, &IncomingSwapCoin> {
self.incoming_swap_coins
self.incoming_swapcoins
.values()
.map(|isc| {
(
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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| {
(
Expand All @@ -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::<Vec<(&IncomingSwapCoin, ListUnspentResultEntry)>>(),
outgoing_swap_coins_utxos
outgoing_swapcoins_utxos
.iter()
.map(|isc_osc_u| (*isc_osc_u.1.unwrap(), isc_osc_u.2.clone()))
.collect::<Vec<(&OutgoingSwapCoin, ListUnspentResultEntry)>>(),
Expand Down
6 changes: 3 additions & 3 deletions tests/test_standard_coinswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 4275ca3

Please sign in to comment.