Skip to content

Commit

Permalink
feat(getinfo) : specify address inside getinfo
Browse files Browse the repository at this point in the history
This commit adds the address inside `getinfo` command.
Changelog:
- Adds `NetworkInfo` response inside lampo_common::model
  • Loading branch information
Harshit933 committed May 25, 2024
1 parent 1f92659 commit cea5b07
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lampo-common/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod connect;
mod getinfo;
mod invoice;
mod keysend;
mod network;
mod new_addr;
mod on_chain;
mod open_channel;
Expand All @@ -28,6 +29,7 @@ pub mod response {
pub use crate::model::getinfo::GetInfo;
pub use crate::model::invoice::response::*;
pub use crate::model::keysend::response::*;
pub use crate::model::network::response::*;
pub use crate::model::new_addr::response::*;
pub use crate::model::on_chain::response::*;
pub use crate::model::open_channel::response::*;
Expand Down
2 changes: 2 additions & 0 deletions lampo-common/src/model/getinfo.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::model::network::response::NetworkInfo;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
Expand All @@ -9,4 +10,5 @@ pub struct GetInfo {
pub alias: String,
pub blockheight: u32,
pub lampo_dir: String,
pub address: Vec<NetworkInfo>,
}
9 changes: 9 additions & 0 deletions lampo-common/src/model/network.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This could work as a network command in future like that of `getnetworkinfo` inside bitcoin.
pub mod response {
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct NetworkInfo {
pub address: String,
pub port: u64,
}
}
14 changes: 14 additions & 0 deletions lampod/src/ln/inventory_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::sync::Arc;

use lampo_common::error;
use lampo_common::json;
use lampo_common::model::response::NetworkInfo;

use super::{LampoChannelManager, LampoPeerManager};
use crate::actions::InventoryHandler;
Expand Down Expand Up @@ -39,6 +40,18 @@ impl InventoryHandler for LampoInventoryManager {
let (_, height) = self.channel_manager.onchain.backend.get_best_block()?;
let blockheight = height.unwrap_or_default();
let lampo_dir = self.channel_manager.conf.root_path.to_string();
// We provide a vector here as there may be other types of address in future like tor and ipv6.
let address = self
.channel_manager
.conf
.announce_addr
.clone()
.unwrap_or("127.0.0.1".to_string());
let port = self.channel_manager.conf.port.clone();
let mut address_vec = Vec::new();
// For now we don't iterate as there is only one type of address.
let address_info = NetworkInfo { address, port };
address_vec.push(address_info);
let getinfo = GetInfo {
node_id: self.channel_manager.manager().get_our_node_id().to_string(),
peers: self.peer_manager.manager().list_peers().len(),
Expand All @@ -47,6 +60,7 @@ impl InventoryHandler for LampoInventoryManager {
alias,
blockheight,
lampo_dir,
address: address_vec,
};
let getinfo = json::to_value(getinfo)?;
chan.send(getinfo)?;
Expand Down

0 comments on commit cea5b07

Please sign in to comment.