Skip to content

Commit

Permalink
Rename funding_confirms_within_blocks (#10)
Browse files Browse the repository at this point in the history
`confirms_within_blocks` -> `funding_confirms_within_blocks`
  • Loading branch information
ErikDeSmedt authored Apr 16, 2024
1 parent 53b0d1a commit 207a942
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 42 deletions.
26 changes: 13 additions & 13 deletions libs/lsp-primitives/src/lsps1/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl Lsps1OptionsBuilder {
pub struct Lsps1CreateOrderRequestBuilder {
lsp_balance_sat: Option<SatAmount>,
client_balance_sat: Option<SatAmount>,
confirms_within_blocks: Option<u8>,
funding_confirms_within_blocks: Option<u8>,
channel_expiry_blocks: Option<u32>,
token: Option<String>,
refund_onchain_address: Option<OnchainAddress>,
Expand All @@ -240,8 +240,8 @@ impl Lsps1CreateOrderRequestBuilder {
self
}

pub fn confirms_within_blocks(mut self, confirms_within_blocks: Option<u8>) -> Self {
self.confirms_within_blocks = confirms_within_blocks;
pub fn funding_confirms_within_blocks(mut self, funding_confirms_within_blocks: Option<u8>) -> Self {
self.funding_confirms_within_blocks = funding_confirms_within_blocks;
self
}

Expand Down Expand Up @@ -275,7 +275,7 @@ impl Lsps1CreateOrderRequestBuilder {
// Fields that allow for reasonable defaults
let client_balance_sat = self.client_balance_sat.unwrap_or(SatAmount::new(0));
let announce_channel = self.announce_channel.unwrap_or(false);
let confirms_within_blocks = self.confirms_within_blocks.unwrap_or(6);
let funding_confirms_within_blocks = self.funding_confirms_within_blocks.unwrap_or(6);

// Non-required fields
let token = self.token;
Expand All @@ -284,7 +284,7 @@ impl Lsps1CreateOrderRequestBuilder {
let request = Lsps1CreateOrderRequest {
lsp_balance_sat,
client_balance_sat,
confirms_within_blocks,
funding_confirms_within_blocks,
channel_expiry_blocks,
token,
refund_onchain_address,
Expand All @@ -300,7 +300,7 @@ pub struct Lsps1CreateOrderResponseBuilder {
uuid: Option<Uuid>,
lsp_balance_sat: Option<SatAmount>,
client_balance_sat: Option<SatAmount>,
confirms_within_blocks: Option<u8>,
funding_confirms_within_blocks: Option<u8>,
channel_expiry_blocks: Option<u32>,
token: Option<String>,
announce_channel: Option<bool>,
Expand All @@ -320,7 +320,7 @@ impl Lsps1CreateOrderResponseBuilder {
Self::new()
.lsp_balance_sat(request.lsp_balance_sat)
.client_balance_sat(request.client_balance_sat)
.confirms_within_blocks(request.confirms_within_blocks)
.funding_confirms_within_blocks(request.funding_confirms_within_blocks)
.channel_expiry_blocks(request.channel_expiry_blocks)
.token(request.token.unwrap_or("".to_string()))
// .refund_onchain_address(request.refund_onchain_address)
Expand All @@ -339,8 +339,8 @@ impl Lsps1CreateOrderResponseBuilder {
self.client_balance_sat = Some(client_balance_sat);
self
}
pub fn confirms_within_blocks(mut self, confirms_within_blocks: u8) -> Self {
self.confirms_within_blocks = Some(confirms_within_blocks);
pub fn funding_confirms_within_blocks(mut self, funding_confirms_within_blocks: u8) -> Self {
self.funding_confirms_within_blocks = Some(funding_confirms_within_blocks);
self
}
pub fn channel_expiry_blocks(mut self, channel_expiry_blocks: u32) -> Self {
Expand Down Expand Up @@ -387,9 +387,9 @@ impl Lsps1CreateOrderResponseBuilder {
let client_balance_sat = self
.client_balance_sat
.context("Missing field 'client_balance_sat' in Lsps1CreateOrderRequestBuilder")?;
let confirms_within_blocks = self
.confirms_within_blocks
.context("Missing field 'confirms_within_blocks' in Lsps1CreateOrderRequestBuilder")?;
let funding_confirms_within_blocks = self
.funding_confirms_within_blocks
.context("Missing field 'funding_confirms_within_blocks' in Lsps1CreateOrderRequestBuilder")?;
let channel_expiry_blocks = self
.channel_expiry_blocks
.context("Missing field 'channel_expiry_blocks' in Lsps1CreateOrderRequestBuilder")?;
Expand All @@ -415,7 +415,7 @@ impl Lsps1CreateOrderResponseBuilder {
order_id,
lsp_balance_sat,
client_balance_sat,
confirms_within_blocks,
funding_confirms_within_blocks,
channel_expiry_blocks,
token,
announce_channel,
Expand Down
8 changes: 4 additions & 4 deletions libs/lsp-primitives/src/lsps1/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct Lsps1Options {
pub struct Lsps1CreateOrderRequest {
pub lsp_balance_sat: SatAmount,
pub client_balance_sat: SatAmount,
pub confirms_within_blocks: u8,
pub funding_confirms_within_blocks: u8,
pub channel_expiry_blocks: u32,
pub token: Option<String>,
pub refund_onchain_address: Option<OnchainAddress>,
Expand All @@ -45,7 +45,7 @@ impl ExpectedFields for Lsps1CreateOrderRequest {
vec![
"lsp_balance_sat".to_string(),
"client_balance_sat".to_string(),
"confirms_within_blocks".to_string(),
"funding_confirms_within_blocks".to_string(),
"channel_expiry_blocks".to_string(),
"token".to_string(),
"refund_onchain_address".to_string(),
Expand All @@ -59,7 +59,7 @@ pub struct Lsps1CreateOrderResponse {
pub order_id: Uuid,
pub lsp_balance_sat: SatAmount,
pub client_balance_sat: SatAmount,
pub confirms_within_blocks: u8,
pub funding_confirms_within_blocks: u8,
pub channel_expiry_blocks: u32,
pub token: String,
pub announce_channel: bool,
Expand Down Expand Up @@ -197,7 +197,7 @@ mod test {
let request = Lsps1CreateOrderRequest {
lsp_balance_sat: SatAmount::new(100_000),
client_balance_sat: SatAmount::new(1_000),
confirms_within_blocks: 10,
funding_confirms_within_blocks: 10,
channel_expiry_blocks: 1000,
token: None,
refund_onchain_address: Some(onchain),
Expand Down
2 changes: 1 addition & 1 deletion libs/lsp-primitives/src/lsps1/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ mod tests {
Lsps1CreateOrderRequestBuilder::new()
.client_balance_sat(Some(SatAmount::new(0)))
.lsp_balance_sat(SatAmount::new(500_000))
.confirms_within_blocks(Some(6))
.funding_confirms_within_blocks(Some(6))
.channel_expiry_blocks(1_000)
.token(None)
.refund_onchain_address(None)
Expand Down
2 changes: 1 addition & 1 deletion plugins/lsps-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ async fn lsps1_create_order(
let create_order_request = lsps1::builders::Lsps1CreateOrderRequestBuilder::new()
.lsp_balance_sat(request.lsp_balance_sat)
.client_balance_sat(request.client_balance_sat)
.confirms_within_blocks(request.confirms_within_blocks)
.funding_confirms_within_blocks(request.funding_confirms_within_blocks)
.channel_expiry_blocks(request.channel_expiry_blocks)
.token(request.token)
.refund_onchain_address(request.refund_onchain_address)
Expand Down
2 changes: 1 addition & 1 deletion plugins/lsps-client/src/plugin_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct Lsps1CreateOrderRequest {
pub peer_id: String,
pub lsp_balance_sat: SatAmount,
pub client_balance_sat: Option<SatAmount>,
pub confirms_within_blocks: Option<u8>,
pub funding_confirms_within_blocks: Option<u8>,
pub channel_expiry_blocks: u32,
pub token: Option<String>,
pub refund_onchain_address: Option<OnchainAddress>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CREATE TABLE lsps1_order (
client_node_id TEXT NOT NULL, -- The node-id of the client
lsp_balance_sat INTEGER NOT NULL, -- as requested by the client
client_balance_sat INTEGER NOT NULL, -- as requested by the client
confirms_within_blocks INTEGER NOT NULL, -- as requested by the client
funding_confirms_within_blocks INTEGER NOT NULL, -- as requested by the client
channel_expiry_blocks INTEGER NOT NULL, -- as requested by the client
token TEXT, -- as requested by the client
refund_onchain_address TEXT, -- as requested by the client
Expand Down
2 changes: 1 addition & 1 deletion plugins/lsps-server/src/db/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Lsps1Order {
pub(crate) client_node_id: PublicKey,
pub(crate) lsp_balance_sat: SatAmount,
pub(crate) client_balance_sat: SatAmount,
pub(crate) confirms_within_blocks: u8,
pub(crate) funding_confirms_within_blocks: u8,
pub(crate) channel_expiry_blocks: u32,
pub(crate) token: Option<String>,
pub(crate) refund_onchain_address: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions plugins/lsps-server/src/db/sqlite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ mod test {
.unwrap(),
lsp_balance_sat: SatAmount::new(100_000),
client_balance_sat: SatAmount::new(0),
confirms_within_blocks: 0,
funding_confirms_within_blocks: 0,
created_at,
expires_at,
refund_onchain_address: None,
Expand Down Expand Up @@ -131,7 +131,7 @@ mod test {
assert_eq!(order.uuid, uuid);
assert_eq!(order.lsp_balance_sat, SatAmount::new(100_000));
assert_eq!(order.client_balance_sat, SatAmount::new(0));
assert_eq!(order.confirms_within_blocks, 0);
assert_eq!(order.funding_confirms_within_blocks, 0);
assert_eq!(
order.created_at.unix_timestamp(),
initial_order.created_at.unix_timestamp()
Expand Down
4 changes: 2 additions & 2 deletions plugins/lsps-server/src/db/sqlite/queries/create_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Lsps1CreateOrderQuery {
INSERT INTO lsps1_order (
uuid, client_node_id,
lsp_balance_sat, client_balance_sat,
confirms_within_blocks, channel_expiry_blocks,
funding_confirms_within_blocks, channel_expiry_blocks,
token, refund_onchain_address,
announce_channel, created_at,
expires_at
Expand All @@ -50,7 +50,7 @@ impl Lsps1CreateOrderQuery {
order.client_node_id,
order.lsp_balance_sat,
order.client_balance_sat,
order.confirms_within_blocks,
order.funding_confirms_within_blocks,
order.channel_expiry_blocks,
order.token,
order.refund_onchain_address,
Expand Down
2 changes: 1 addition & 1 deletion plugins/lsps-server/src/db/sqlite/queries/get_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl GetOrderQuery {
Lsps1OrderSqlite,
r#"SELECT
uuid, client_node_id, lsp_balance_sat,
client_balance_sat, confirms_within_blocks, channel_expiry_blocks,
client_balance_sat, funding_confirms_within_blocks, channel_expiry_blocks,
token, refund_onchain_address, announce_channel,
ord.created_at, expires_at, os.order_state_enum_id as order_state,
generation
Expand Down
6 changes: 3 additions & 3 deletions plugins/lsps-server/src/db/sqlite/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct Lsps1Order {
pub(crate) client_node_id: String,
pub(crate) lsp_balance_sat: i64,
pub(crate) client_balance_sat: i64,
pub(crate) confirms_within_blocks: i64,
pub(crate) funding_confirms_within_blocks: i64,
pub(crate) channel_expiry_blocks: i64,
pub(crate) token: Option<String>,
pub(crate) refund_onchain_address: Option<String>,
Expand Down Expand Up @@ -119,7 +119,7 @@ impl TryFrom<&Lsps1Order> for Lsps1OrderBase {
client_node_id: PublicKey::from_hex(&order.client_node_id)?,
lsp_balance_sat: SatAmount::new(u64::try_from(order.lsp_balance_sat)?),
client_balance_sat: SatAmount::new(u64::try_from(order.client_balance_sat)?),
confirms_within_blocks: u8::try_from(order.confirms_within_blocks)?,
funding_confirms_within_blocks: u8::try_from(order.funding_confirms_within_blocks)?,
channel_expiry_blocks: u32::try_from(order.channel_expiry_blocks)?,
token: order.token.clone(),
refund_onchain_address: order.refund_onchain_address.clone(),
Expand All @@ -141,7 +141,7 @@ impl TryFrom<&Lsps1OrderBase> for Lsps1Order {
client_node_id: order.client_node_id.to_hex(),
lsp_balance_sat: i64::try_from(order.lsp_balance_sat.sat_value())?,
client_balance_sat: i64::try_from(order.client_balance_sat.sat_value())?,
confirms_within_blocks: i64::try_from(order.confirms_within_blocks)?,
funding_confirms_within_blocks: i64::try_from(order.funding_confirms_within_blocks)?,
channel_expiry_blocks: i64::try_from(order.channel_expiry_blocks)?,
token: order.token.clone(),
refund_onchain_address: order.refund_onchain_address.clone(),
Expand Down
2 changes: 1 addition & 1 deletion plugins/lsps-server/src/lsps1/fee_calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl FeeCalculator for StandardFeeCalculator {
.estimates
.context("Failed to retrieve feerates")?;

let onchain_feerate_kwu = calculate_onchain_feerate(order.confirms_within_blocks, &feerates)
let onchain_feerate_kwu = calculate_onchain_feerate(order.funding_confirms_within_blocks, &feerates)
.context("Failed to compute approriate feerate")?
as u64;

Expand Down
6 changes: 3 additions & 3 deletions plugins/lsps-server/src/lsps1/hooks/custommsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ pub(crate) async fn do_lsps1_create_order(
uuid: Uuid::new_v4(),
client_node_id: context.peer_id,
announce_channel: order.announce_channel,
created_at: created_at,
expires_at: expires_at,
created_at,
expires_at,
lsp_balance_sat: order.lsp_balance_sat,
client_balance_sat: order.client_balance_sat,
confirms_within_blocks: order.confirms_within_blocks,
funding_confirms_within_blocks: order.funding_confirms_within_blocks,
channel_expiry_blocks: order.channel_expiry_blocks,
token: order.token.clone(),
refund_onchain_address: order.refund_onchain_address.as_ref().map(|x| x.to_string()),
Expand Down
2 changes: 1 addition & 1 deletion plugins/lsps-server/src/lsps1/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl BuildLsps1Order for Lsps1CreateOrderResponseBuilder {
self.uuid(order.uuid)
.lsp_balance_sat(order.lsp_balance_sat)
.client_balance_sat(order.client_balance_sat)
.confirms_within_blocks(order.confirms_within_blocks)
.funding_confirms_within_blocks(order.funding_confirms_within_blocks)
.channel_expiry_blocks(order.channel_expiry_blocks)
.token(order.token.unwrap_or("".to_string()))
.announce_channel(order.announce_channel)
Expand Down
14 changes: 7 additions & 7 deletions test/server/test_lsps1.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_lsps1_create_order_violate_options(lsps_server, lsps_client):
params = dict(
lsp_balance_sat="0",
client_balance_sat="1000001", # Too large
confirms_within_blocks=1,
funding_confirms_within_blocks=1,
channel_expiry_blocks=144,
announce_channel=False,
)
Expand All @@ -84,7 +84,7 @@ def test_lsps1_create_order_violate_options(lsps_server, lsps_client):
params=json.dumps(params),
)

assert "error" in response, "Should be optiom mismatch but returned result"
assert "error" in response, "Should be option mismatch but returned result"
error = response["error"]

assert error["code"] == 1000
Expand All @@ -98,7 +98,7 @@ def test_lsps1_create_order(lsps_server, lsps_client):
params = dict(
lsp_balance_sat="500000",
client_balance_sat="0",
confirms_within_blocks=1,
funding_confirms_within_blocks=1,
channel_expiry_blocks=144,
announce_channel=False,
)
Expand All @@ -114,7 +114,7 @@ def test_lsps1_create_order(lsps_server, lsps_client):

assert result["lsp_balance_sat"] == "500000"
assert result["client_balance_sat"] == "0"
assert result["confirms_within_blocks"] == 1
assert result["funding_confirms_within_blocks"] == 1
assert result["channel_expiry_blocks"] == 144
assert result["announce_channel"] == False

Expand All @@ -128,7 +128,7 @@ def test_lsps1_get_order_by_uuid(lsps_client, lsps_server):
params = dict(
lsp_balance_sat="500000",
client_balance_sat="0",
confirms_within_blocks=1,
funding_confirms_within_blocks=1,
channel_expiry_blocks=144,
announce_channel=False,
)
Expand All @@ -151,7 +151,7 @@ def test_lsps1_get_order_by_uuid(lsps_client, lsps_server):

assert result["lsp_balance_sat"] == "500000"
assert result["client_balance_sat"] == "0"
assert result["confirms_within_blocks"] == 1
assert result["funding_confirms_within_blocks"] == 1
assert result["channel_expiry_blocks"] == 144
assert not result["announce_channel"]

Expand All @@ -173,7 +173,7 @@ def test_pay_lsps1_order(lsps_client, lsps_server):
params = dict(
lsp_balance_sat="123456",
client_balance_sat="0",
confirms_within_blocks=1,
funding_confirms_within_blocks=1,
channel_expiry_blocks=144,
announce_channel=False,
)
Expand Down

0 comments on commit 207a942

Please sign in to comment.