-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add impl for UpdateChannelConfig Api.
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use ldk_node::bitcoin::secp256k1::PublicKey; | ||
use ldk_node::{ChannelConfig, Node, UserChannelId}; | ||
use protos::channel_config::MaxDustHtlcExposure; | ||
use protos::{UpdateChannelConfigRequest, UpdateChannelConfigResponse}; | ||
use std::str::FromStr; | ||
use std::sync::Arc; | ||
|
||
pub(crate) const UPDATE_CHANNEL_CONFIG_PATH: &str = "UpdateChannelConfig"; | ||
|
||
pub(crate) fn handle_update_channel_config_request( | ||
node: Arc<Node>, request: UpdateChannelConfigRequest, | ||
) -> Result<UpdateChannelConfigResponse, ldk_node::NodeError> { | ||
let user_channel_id: u128 = | ||
request.user_channel_id.parse().map_err(|_| ldk_node::NodeError::InvalidChannelId)?; | ||
|
||
let channel_config = proto_to_channel_config(&request.channel_config.unwrap()); | ||
|
||
let counterparty_node_id = PublicKey::from_str(&request.counterparty_node_id) | ||
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?; | ||
node.update_channel_config( | ||
&UserChannelId(user_channel_id), | ||
counterparty_node_id, | ||
Arc::new(channel_config), | ||
) | ||
.map_err(ldk_node::NodeError::from)?; | ||
|
||
Ok(UpdateChannelConfigResponse {}) | ||
} | ||
|
||
fn proto_to_channel_config(proto_channel_config: &protos::ChannelConfig) -> ChannelConfig { | ||
let channel_config = ChannelConfig::new(); | ||
|
||
match proto_channel_config.forwarding_fee_proportional_millionths { | ||
Some(forwarding_fee_proportional_millionths) => channel_config | ||
.set_forwarding_fee_proportional_millionths(forwarding_fee_proportional_millionths), | ||
None => {}, | ||
} | ||
|
||
match proto_channel_config.forwarding_fee_base_msat { | ||
Some(forwarding_fee_base_msat) => { | ||
channel_config.set_forwarding_fee_base_msat(forwarding_fee_base_msat) | ||
}, | ||
None => {}, | ||
} | ||
|
||
match proto_channel_config.cltv_expiry_delta { | ||
Some(cltv_expiry_delta) => channel_config.set_cltv_expiry_delta(cltv_expiry_delta as u16), | ||
None => {}, | ||
} | ||
|
||
match proto_channel_config.force_close_avoidance_max_fee_satoshis { | ||
Some(force_close_avoidance_max_fee_satoshis) => channel_config | ||
.set_force_close_avoidance_max_fee_satoshis(force_close_avoidance_max_fee_satoshis), | ||
None => {}, | ||
} | ||
|
||
match proto_channel_config.accept_underpaying_htlcs { | ||
Some(accept_underpaying_htlcs) => { | ||
channel_config.set_accept_underpaying_htlcs(accept_underpaying_htlcs) | ||
}, | ||
None => {}, | ||
} | ||
|
||
match &proto_channel_config.max_dust_htlc_exposure { | ||
Some(max_dust_htlc_exposure) => match max_dust_htlc_exposure { | ||
&MaxDustHtlcExposure::FixedLimitMsat(limit) => { | ||
channel_config.set_max_dust_htlc_exposure_from_fixed_limit(limit) | ||
}, | ||
&MaxDustHtlcExposure::FeeRateMultiplier(multiplier) => { | ||
channel_config.set_max_dust_htlc_exposure_from_fee_rate_multiplier(multiplier) | ||
}, | ||
}, | ||
None => {}, | ||
} | ||
// FIXME: set max_dust_htlc_exposure | ||
channel_config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters