From 1ea1c5723ac5c55dde9f526603db6c5bec43a559 Mon Sep 17 00:00:00 2001 From: i5hi Date: Wed, 26 Jun 2024 18:24:18 +0530 Subject: [PATCH] Minor fixes --- src/swaps/bitcoinv2.rs | 6 +++--- src/swaps/boltz.rs | 3 --- src/swaps/boltzv2.rs | 13 +++++++++---- src/swaps/liquidv2.rs | 12 ++++++------ tests/chain_swaps.rs | 15 +++++++++------ 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/swaps/bitcoinv2.rs b/src/swaps/bitcoinv2.rs index 80ee808..30649bf 100644 --- a/src/swaps/bitcoinv2.rs +++ b/src/swaps/bitcoinv2.rs @@ -127,7 +127,7 @@ impl BtcSwapScriptV2 { pub fn musig_keyagg_cache(&self) -> MusigKeyAggCache { match (self.swap_type, self.side.clone()) { - (SwapType::ReverseSubmarine, _) | (SwapType::Chain, Some(Side::To)) => { + (SwapType::ReverseSubmarine, _) | (SwapType::Chain, Some(Side::Claim)) => { let pubkeys = [self.sender_pubkey.inner, self.receiver_pubkey.inner]; MusigKeyAggCache::new(&Secp256k1::new(), &pubkeys) } @@ -257,8 +257,8 @@ impl BtcSwapScriptV2 { let funding_addrs = Address::from_str(&chain_swap_details.lockup_address)?.assume_checked(); let (sender_pubkey, receiver_pubkey) = match side { - Side::From => (our_pubkey, chain_swap_details.server_public_key), - Side::To => (chain_swap_details.server_public_key, our_pubkey), + Side::Lockup => (our_pubkey, chain_swap_details.server_public_key), + Side::Claim => (chain_swap_details.server_public_key, our_pubkey), }; Ok(BtcSwapScriptV2 { diff --git a/src/swaps/boltz.rs b/src/swaps/boltz.rs index a9a77d5..db791f1 100644 --- a/src/swaps/boltz.rs +++ b/src/swaps/boltz.rs @@ -472,7 +472,6 @@ pub enum ChainSwapStates { TransactionServerMempool, TransactionServerConfirmed, TransactionClaimed, - TransactionClaimPending, TransactionLockupFailed, SwapExpired, TransactionFailed, @@ -493,7 +492,6 @@ impl ToString for ChainSwapStates { "transaction.server.confirmed".to_string() } ChainSwapStates::TransactionClaimed => "transaction.claimed".to_string(), - ChainSwapStates::TransactionClaimPending => "transaction.claim.pending".to_string(), ChainSwapStates::TransactionLockupFailed => "transaction.lockupFailed".to_string(), ChainSwapStates::SwapExpired => "swap.expired".to_string(), ChainSwapStates::TransactionFailed => "transaction.failed".to_string(), @@ -514,7 +512,6 @@ impl FromStr for ChainSwapStates { "transaction.server.mempool" => Ok(ChainSwapStates::TransactionServerMempool), "transaction.server.confirmed" => Ok(ChainSwapStates::TransactionServerConfirmed), "transaction.claimed" => Ok(ChainSwapStates::TransactionClaimed), - "transaction.claim.pending" => Ok(ChainSwapStates::TransactionClaimPending), "transaction.lockupFailed" => Ok(ChainSwapStates::TransactionLockupFailed), "swap.expired" => Ok(ChainSwapStates::SwapExpired), "transaction.failed" => Ok(ChainSwapStates::TransactionFailed), diff --git a/src/swaps/boltzv2.rs b/src/swaps/boltzv2.rs index c25e86f..4c477d3 100644 --- a/src/swaps/boltzv2.rs +++ b/src/swaps/boltzv2.rs @@ -724,8 +724,8 @@ impl CreateReverseResponse { #[derive(Debug, Clone, PartialEq)] pub enum Side { - From, - To, + Lockup, + Claim, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -778,8 +778,13 @@ impl CreateChainResponse { from_chain: Chain, to_chain: Chain, ) -> Result<(), Error> { - self.validate_side(Side::From, from_chain, &self.lockup_details, refund_pubkey)?; - self.validate_side(Side::To, to_chain, &self.claim_details, claim_pubkey) + self.validate_side( + Side::Lockup, + from_chain, + &self.lockup_details, + refund_pubkey, + )?; + self.validate_side(Side::Claim, to_chain, &self.claim_details, claim_pubkey) } fn validate_side( diff --git a/src/swaps/liquidv2.rs b/src/swaps/liquidv2.rs index c8ecea0..da0c709 100644 --- a/src/swaps/liquidv2.rs +++ b/src/swaps/liquidv2.rs @@ -255,8 +255,8 @@ impl LBtcSwapScriptV2 { let funding_addrs = Address::from_str(&chain_swap_details.lockup_address)?; let (sender_pubkey, receiver_pubkey) = match side { - Side::From => (our_pubkey, chain_swap_details.server_public_key), - Side::To => (chain_swap_details.server_public_key, our_pubkey), + Side::Lockup => (our_pubkey, chain_swap_details.server_public_key), + Side::Claim => (chain_swap_details.server_public_key, our_pubkey), }; let blinding_str = chain_swap_details @@ -312,7 +312,7 @@ impl LBtcSwapScriptV2 { pub fn musig_keyagg_cache(&self) -> MusigKeyAggCache { match (self.swap_type, self.side.clone()) { - (SwapType::ReverseSubmarine, _) | (SwapType::Chain, Some(Side::To)) => { + (SwapType::ReverseSubmarine, _) | (SwapType::Chain, Some(Side::Claim)) => { let pubkeys = [self.sender_pubkey.inner, self.receiver_pubkey.inner]; MusigKeyAggCache::new(&Secp256k1::new(), &pubkeys) } @@ -438,7 +438,7 @@ impl LBtcSwapScriptV2 { } /// Fetch utxo for script from BoltzApi - pub fn fetch_utxo_boltz( + pub fn fetch_lockup_utxo_boltz( &self, network_config: &ElectrumConfig, boltz_url: &str, @@ -524,7 +524,7 @@ impl LBtcSwapTxV2 { let (funding_outpoint, funding_utxo) = match swap_script.fetch_utxo(&network_config) { Ok(r) => r, - Err(_) => swap_script.fetch_utxo_boltz(&network_config, &boltz_url, &swap_id)?, + Err(_) => swap_script.fetch_lockup_utxo_boltz(&network_config, &boltz_url, &swap_id)?, }; let electrum = network_config.build_client()?; @@ -557,7 +557,7 @@ impl LBtcSwapTxV2 { let address = Address::from_str(&output_address)?; let (funding_outpoint, funding_utxo) = match swap_script.fetch_utxo(&network_config) { Ok(r) => r, - Err(_) => swap_script.fetch_utxo_boltz(&network_config, &boltz_url, &swap_id)?, + Err(_) => swap_script.fetch_lockup_utxo_boltz(&network_config, &boltz_url, &swap_id)?, }; let electrum = network_config.build_client()?; diff --git a/tests/chain_swaps.rs b/tests/chain_swaps.rs index 856fb3b..6f518ea 100644 --- a/tests/chain_swaps.rs +++ b/tests/chain_swaps.rs @@ -54,7 +54,7 @@ fn bitcoin_liquid_v2_chain() { let lockup_details: ChainSwapDetails = create_chain_response.clone().lockup_details; let lockup_script = BtcSwapScriptV2::chain_from_swap_resp( - Side::From, + Side::Lockup, lockup_details.clone(), refund_public_key, ) @@ -78,9 +78,12 @@ fn bitcoin_liquid_v2_chain() { let claim_details: ChainSwapDetails = create_chain_response.claim_details; - let claim_script = - LBtcSwapScriptV2::chain_from_swap_resp(Side::To, claim_details.clone(), claim_public_key) - .unwrap(); + let claim_script = LBtcSwapScriptV2::chain_from_swap_resp( + Side::Claim, + claim_details.clone(), + claim_public_key, + ) + .unwrap(); let claim_address = "tlq1qq0y3xudhc909fur3ktaws0yrhjv3ld9c2fk5hqzjfmgqurl0cy4z8yc8d9h54lj7ddwatzegwamyqhp4vttxj26wml4s9vecx".to_string(); let lq_address = EAddress::from_str(&claim_address).unwrap(); @@ -289,7 +292,7 @@ fn liquid_bitcoin_v2_chain() { let lockup_details: ChainSwapDetails = create_chain_response.clone().lockup_details; let lockup_script = LBtcSwapScriptV2::chain_from_swap_resp( - Side::From, + Side::Lockup, lockup_details.clone(), refund_public_key, ) @@ -318,7 +321,7 @@ fn liquid_bitcoin_v2_chain() { let claim_details: ChainSwapDetails = create_chain_response.claim_details; let claim_script = - BtcSwapScriptV2::chain_from_swap_resp(Side::To, claim_details.clone(), claim_public_key) + BtcSwapScriptV2::chain_from_swap_resp(Side::Claim, claim_details.clone(), claim_public_key) .unwrap(); let claim_address = "tb1qra2cdypld3hyq3f84630cvj9d0lmzv66vn4k28".to_string();