Skip to content

Commit

Permalink
implement swap parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed Dec 16, 2024
1 parent 6ce0a2d commit af7020c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
24 changes: 17 additions & 7 deletions swapd/src/public_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub mod swap_api {
}

const FAKE_PREIMAGE: [u8; 32] = [0; 32];
const MIN_SWAP_AMOUNT_CONF_TARGET: i32 = 12;

pub struct SwapServerParams<C, CF, CR, L, P, R, F>
where
C: ChainClient,
Expand Down Expand Up @@ -126,7 +128,19 @@ where
}

async fn get_swap_parameters(&self) -> Result<SwapParameters, Status> {
todo!();
let fee_estimate = self
.fee_estimator
.estimate_fee(MIN_SWAP_AMOUNT_CONF_TARGET)
.await?;
// Assume a transaction weight of 1000.
let min_utxo_amount_sat = (fee_estimate.sat_per_kw as u64) * 3 / 2;

Ok(SwapParameters {
lock_time: self.swap_service.lock_time(),
max_swap_amount_sat: self.max_swap_amount_sat,
min_swap_amount_sat: min_utxo_amount_sat,
min_utxo_amount_sat,
})
}
}
#[tonic::async_trait]
Expand Down Expand Up @@ -223,9 +237,7 @@ where
max_swap_amount_sat = parameters.max_swap_amount_sat,
"invoice amount exceeds max swap amount"
);
return Err(Status::invalid_argument(
"amount exceeds max swap amount",
));
return Err(Status::invalid_argument("amount exceeds max swap amount"));
}

if amount_sat < parameters.min_swap_amount_sat {
Expand All @@ -234,9 +246,7 @@ where
min_swap_amount_sat = parameters.min_swap_amount_sat,
"invoice amount is below min swap amount"
);
return Err(Status::invalid_argument(
"amount is below min swap amount",
));
return Err(Status::invalid_argument("amount is below min swap amount"));
}

let hash = invoice.payment_hash();
Expand Down
4 changes: 4 additions & 0 deletions swapd/src/swap/swap_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ where
Ok(tx)
}

pub fn lock_time(&self) -> u32 {
self.lock_time
}

pub fn partial_sign_refund_tx(
&self,
swap: &Swap,
Expand Down

0 comments on commit af7020c

Please sign in to comment.