Skip to content

Commit

Permalink
make host optional, clean up logs and borrowing
Browse files Browse the repository at this point in the history
  • Loading branch information
wbobeirne committed Sep 11, 2023
1 parent 4c34123 commit a3ed557
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct ChannelRequest {
capacity: i64,
push_amount: i64,
pubkey: String,
host: String,
host: Option<String>,
}

#[derive(Clone, Serialize)]
Expand All @@ -32,10 +32,6 @@ pub async fn open_channel(
anyhow::bail!("push_amount must be less than or equal to capacity");
}

println!("pubkey: {:?}", payload.pubkey);
println!("capacity: {:?}", payload.capacity);
println!("push_amount: {:?}", payload.push_amount);

let node_pubkey_result = hex::decode(payload.pubkey.clone());
let node_pubkey = match node_pubkey_result {
Ok(pubkey) => pubkey,
Expand All @@ -50,16 +46,18 @@ pub async fn open_channel(
.lightning_client
.clone();

lightning_client
.connect_peer(lnrpc::ConnectPeerRequest {
addr: Some(lnrpc::LightningAddress {
pubkey: payload.pubkey.clone(),
host: payload.host,
}),
..Default::default()
})
.await
.ok();
if let Some(host) = payload.host {
lightning_client
.connect_peer(lnrpc::ConnectPeerRequest {
addr: Some(lnrpc::LightningAddress {
pubkey: payload.pubkey.clone(),
host,
}),
..Default::default()
})
.await
.ok();
}

lightning_client
.open_channel_sync(lnrpc::OpenChannelRequest {
Expand All @@ -72,11 +70,9 @@ pub async fn open_channel(
.into_inner()
};

println!("channel_point: {:?}", channel_point);

let txid = match &channel_point.funding_txid {
Some(channel_point::FundingTxid::FundingTxidBytes(bytes)) => hex::encode(bytes.clone()),
Some(channel_point::FundingTxid::FundingTxidStr(string)) => string.clone(),
let txid = match channel_point.funding_txid {
Some(channel_point::FundingTxid::FundingTxidBytes(bytes)) => hex::encode(bytes),
Some(channel_point::FundingTxid::FundingTxidStr(string)) => string,
None => anyhow::bail!("failed to open channel"),
};

Expand Down

0 comments on commit a3ed557

Please sign in to comment.