Skip to content

Commit

Permalink
fix: address review comments
Browse files Browse the repository at this point in the history
taken from
#622 (review)
  • Loading branch information
hydra-yse committed Jan 2, 2025
1 parent c880da3 commit 617a070
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SwapUpdatedTask : TaskProtocol {
func getSwapId(details: PaymentDetails?) -> String? {
if let details = details {
switch details {
case let .bitcoin(swapId, _, _, _, _):
case let .bitcoin(swapId, _, _, _, _, _):
return swapId
case let .lightning(swapId, _, _, _, _, _, _, _, _, _):
return swapId
Expand Down
7 changes: 3 additions & 4 deletions lib/core/src/chain/liquid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use async_trait::async_trait;
use boltz_client::ToHex;
use log::{info, warn};
use lwk_wollet::elements::hex::FromHex;
use lwk_wollet::elements::BlockHeader;
use lwk_wollet::{
elements::{
pset::serialize::Serialize, Address, BlockHash, OutPoint, Script, Transaction, Txid,
Expand All @@ -27,7 +26,7 @@ const LIQUID_ESPLORA_URL: &str = "https://lq1.breez.technology/liquid/api";
#[async_trait]
pub trait LiquidChainService: Send + Sync {
/// Get the blockchain latest block
async fn tip(&mut self) -> Result<BlockHeader>;
async fn tip(&mut self) -> Result<u32>;

/// Broadcast a transaction
async fn broadcast(&self, tx: &Transaction, swap_id: Option<&str>) -> Result<Txid>;
Expand Down Expand Up @@ -100,8 +99,8 @@ impl HybridLiquidChainService {

#[async_trait]
impl LiquidChainService for HybridLiquidChainService {
async fn tip(&mut self) -> Result<BlockHeader> {
Ok(self.electrum_client.tip()?)
async fn tip(&mut self) -> Result<u32> {
Ok(self.electrum_client.tip()?.height)
}

async fn broadcast(&self, tx: &Transaction, swap_id: Option<&str>) -> Result<Txid> {
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,8 +1282,8 @@ pub struct PaymentSwapData {
pub refund_tx_amount_sat: Option<u64>,

/// Present only for chain swaps.
/// In case of an outgoing chain swap, it's the Bitcoin address which will receive the funds
/// In case of an incoming chain swap, it's the Liquid address which will receive the funds
/// In case of an incoming chain swap, it's the Bitcoin address which will receive the funds
/// In case of an outgoing chain swap, it's the Liquid address which will receive the funds
pub claim_address: Option<String>,

/// Payment status derived from the swap status
Expand Down
13 changes: 5 additions & 8 deletions lib/core/src/recover/recoverer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,8 @@ impl Recoverer {
log::warn!("Could not apply recovered data for Send swap {swap_id}: recovery data not found");
continue;
};
let timeout_block_height =
send_swap.get_boltz_create_response()?.timeout_block_height as u32;
let is_expired = liquid_tip.height >= timeout_block_height;
let timeout_block_height = send_swap.timeout_block_height as u32;
let is_expired = liquid_tip >= timeout_block_height;
if let Some(new_state) = recovered_data.derive_partial_state(is_expired) {
send_swap.state = new_state;
}
Expand All @@ -184,10 +183,8 @@ impl Recoverer {
log::warn!("Could not apply recovered data for Receive swap {swap_id}: recovery data not found");
continue;
};
let timeout_block_height = receive_swap
.get_boltz_create_response()?
.timeout_block_height;
let is_expired = liquid_tip.height >= timeout_block_height;
let timeout_block_height = receive_swap.timeout_block_height;
let is_expired = liquid_tip >= timeout_block_height;
if let Some(new_state) = recovered_data.derive_partial_state(is_expired) {
receive_swap.state = new_state;
}
Expand Down Expand Up @@ -247,7 +244,7 @@ impl Recoverer {
log::warn!("Could not apply recovered data for outgoing Chain swap {swap_id}: recovery data not found");
continue;
};
let is_expired = liquid_tip.height >= chain_swap.timeout_block_height;
let is_expired = liquid_tip >= chain_swap.timeout_block_height;
if let Some(new_state) = recovered_data.derive_partial_state(is_expired) {
chain_swap.state = new_state;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ impl LiquidSdk {
tokio::select! {
_ = interval.tick() => {
// Get the Liquid tip and process a new block
let liquid_tip_res = cloned.liquid_chain_service.lock().await.tip().await.map(|tip| tip.height);
let liquid_tip_res = cloned.liquid_chain_service.lock().await.tip().await;
let is_new_liquid_block = match &liquid_tip_res {
Ok(height) => {
debug!("Got Liquid tip: {height}");
Expand Down Expand Up @@ -2325,7 +2325,7 @@ impl LiquidSdk {
match partial_sync {
false => {
let bitcoin_height = self.bitcoin_chain_service.lock().await.tip()?.height as u32;
let liquid_height = self.liquid_chain_service.lock().await.tip().await?.height;
let liquid_height = self.liquid_chain_service.lock().await.tip().await?;
let final_swap_states = [PaymentState::Complete, PaymentState::Failed];

let send_swaps = self
Expand Down
2 changes: 2 additions & 0 deletions lib/core/src/sync/model/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub(crate) struct SendSyncData {
pub(crate) refund_private_key: String,
pub(crate) payer_amount_sat: u64,
pub(crate) receiver_amount_sat: u64,
#[serde(default)]
pub(crate) timeout_block_height: u64,
pub(crate) created_at: u32,
pub(crate) preimage: Option<String>,
Expand Down Expand Up @@ -173,6 +174,7 @@ pub(crate) struct ReceiveSyncData {
pub(crate) payer_amount_sat: u64,
pub(crate) receiver_amount_sat: u64,
pub(crate) mrh_address: String,
#[serde(default)]
pub(crate) timeout_block_height: u32,
pub(crate) created_at: u32,
pub(crate) payment_hash: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion lib/core/src/sync/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) mod sync;

const MESSAGE_PREFIX: &[u8; 13] = b"realtimesync:";
lazy_static! {
static ref CURRENT_SCHEMA_VERSION: Version = Version::parse("0.0.1").unwrap();
static ref CURRENT_SCHEMA_VERSION: Version = Version::parse("0.1.0").unwrap();
}

#[derive(Copy, Clone)]
Expand Down
16 changes: 3 additions & 13 deletions lib/core/src/test_utils/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use electrum_client::{
};
use lwk_wollet::{
bitcoin::constants::genesis_block,
elements::{BlockHash, BlockHeader, TxMerkleNode, Txid as ElementsTxid},
hashes::Hash,
elements::{BlockHash, Txid as ElementsTxid},
History,
};

Expand Down Expand Up @@ -64,17 +63,8 @@ impl MockLiquidChainService {

#[async_trait]
impl LiquidChainService for MockLiquidChainService {
async fn tip(&mut self) -> Result<BlockHeader> {
let block_enc = BlockHash::engine();
let merkle_enc = TxMerkleNode::engine();
Ok(BlockHeader {
version: 0,
prev_blockhash: BlockHash::from_engine(block_enc),
merkle_root: TxMerkleNode::from_engine(merkle_enc),
time: 0,
height: 0,
ext: Default::default(),
})
async fn tip(&mut self) -> Result<u32> {
Ok(0)
}

async fn broadcast(
Expand Down

0 comments on commit 617a070

Please sign in to comment.