Skip to content

Commit

Permalink
chore: add alias when creating peer node connection
Browse files Browse the repository at this point in the history
  • Loading branch information
tobi-bams committed Nov 28, 2024
1 parent ae94328 commit a0d5dd2
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 11 deletions.
9 changes: 7 additions & 2 deletions app/src/api/cln.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ export async function create_channel(
return await clnCmd("AddChannel", tag, { pubkey, amount, satsperbyte });
}

export async function add_peer(tag: string, pubkey: string, host: string) {
return await clnCmd("AddPeer", tag, { pubkey, host });
export async function add_peer(
tag: string,
pubkey: string,
host: string,
alias?: string
) {
return await clnCmd("AddPeer", tag, { pubkey, host, alias });
}
9 changes: 7 additions & 2 deletions app/src/api/lnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ export async function list_channels(tag: string) {
return await lndCmd("ListChannels", tag);
}

export async function add_peer(tag: string, pubkey: string, host: string) {
return await lndCmd("AddPeer", tag, { pubkey, host });
export async function add_peer(
tag: string,
pubkey: string,
host: string,
alias?: string
) {
return await lndCmd("AddPeer", tag, { pubkey, host, alias });
}

export async function list_peers(tag: string) {
Expand Down
16 changes: 13 additions & 3 deletions app/src/lnd/Peers.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@
let error_notification = false;
let error_message = false;
let isUpdate = false;
let peerAlias = "";
async function addPeer() {
message = "";
if (type === "Cln") {
const peer = await CLN.add_peer(tag, pubkey, host);
const peer = await CLN.add_peer(tag, pubkey, host, peerAlias);
show_notification = true;
if (typeof peer === "string") {
Expand All @@ -69,6 +70,8 @@
if (peer) {
pubkey = "";
host = "";
peerAlias = "";
await handleGetLightningPeers();
const peersData = await CLN.list_peers(tag);
const thepeers = await parseClnListPeerRes(peersData);
peersStore.update((peer) => {
Expand All @@ -77,11 +80,12 @@
createdPeerForOnboarding.update(() => true);
}
} else {
if (await add_peer(tag, pubkey, host)) {
if (await add_peer(tag, pubkey, host, peerAlias)) {
show_notification = true;
pubkey = "";
host = "";
peerAlias = "";
await handleGetLightningPeers();
setTimeout(async () => {
const peersData = await list_peers(tag);
peersStore.update((ps) => {
Expand Down Expand Up @@ -217,6 +221,12 @@
bind:value={host}
/>
<div class="spacer" />
<TextInput
labelText={"Alias"}
placeholder={"Peer Alias"}
bind:value={peerAlias}
/>
<div class="spacer" />
<center
><Button
disabled={addDisabled}
Expand Down
1 change: 1 addition & 0 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ pub struct TestMine {
pub struct AddPeer {
pub pubkey: String,
pub host: String,
pub alias: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down
37 changes: 33 additions & 4 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::auth;
use crate::builder;
use crate::cmd::*;
use crate::config;
use crate::config::LightningPeer;
use crate::config::Role;
use crate::config::User;
use crate::config::{Clients, Node, Stack, State, STATE};
Expand Down Expand Up @@ -523,8 +524,22 @@ pub async fn handle(
Some(serde_json::to_string(&channel_list.channels)?)
}
LndCmd::AddPeer(peer) => {
let result = client.add_peer(peer).await?;
Some(serde_json::to_string(&result)?)
if let Some(alias) = peer.alias.clone() {
add_new_lightning_peer(
&mut state,
LightningPeer {
pubkey: peer.pubkey.clone(),
alias,
},
&mut must_save_stack,
);
let client = state.clients.lnd.get_mut(tag).context("no lnd client")?;
let result = client.add_peer(peer).await?;
Some(serde_json::to_string(&result)?)
} else {
let result = client.add_peer(peer).await?;
Some(serde_json::to_string(&result)?)
}
}
LndCmd::ListPeers => {
let result = client.list_peers().await?;
Expand Down Expand Up @@ -604,8 +619,22 @@ pub async fn handle(
} else {
peer.host
};
let result = client.connect_peer(&peer.pubkey, &host, port).await?;
Some(serde_json::to_string(&result)?)
if let Some(alias) = peer.alias.clone() {
add_new_lightning_peer(
&mut state,
LightningPeer {
alias,
pubkey: peer.pubkey.clone(),
},
&mut must_save_stack,
);
let client = state.clients.cln.get_mut(tag).context("no cln client")?;
let result = client.connect_peer(&peer.pubkey, &host, port).await?;
Some(serde_json::to_string(&result)?)
} else {
let result = client.connect_peer(&peer.pubkey, &host, port).await?;
Some(serde_json::to_string(&result)?)
}
}
ClnCmd::AddChannel(channel) => {
let channel = client
Expand Down

0 comments on commit a0d5dd2

Please sign in to comment.