Skip to content

Commit

Permalink
Merge pull request #82 from L2-Technology/expose-balance
Browse files Browse the repository at this point in the history
expose channel balance
  • Loading branch information
johncantrell97 authored Jun 8, 2022
2 parents cd74d6f + 736a37d commit e772430
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
26 changes: 15 additions & 11 deletions senseicore/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1440,21 +1440,25 @@ impl LightningNode {

let responses = self.open_channels(requests).await;

let peer_connection_infos = responses
.iter()
.map(|(request, _result)| &request.node_connection_string[..])
.collect::<Vec<_>>();

let _ = self
.persister
.batch_persist_channel_peers(&peer_connection_infos);

Ok(NodeResponse::OpenChannels {
channels,
results: responses
.into_iter()
.map(|(request, result)| match result {
Ok(temp_channel_id) => {
let _ = self
.persister
.persist_channel_peer(&request.node_connection_string);
OpenChannelResult {
error: false,
error_message: None,
temp_channel_id: Some(hex_utils::hex_str(&temp_channel_id)),
}
}
.map(|(_request, result)| match result {
Ok(temp_channel_id) => OpenChannelResult {
error: false,
error_message: None,
temp_channel_id: Some(hex_utils::hex_str(&temp_channel_id)),
},
Err(e) => OpenChannelResult {
error: true,
error_message: Some(e.to_string()),
Expand Down
15 changes: 14 additions & 1 deletion senseicore/src/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ impl SenseiPersister {
String::new()
}

pub fn batch_persist_channel_peers(&self, peer_infos: &[&str]) -> std::io::Result<()> {
let mut peer_data = self.get_raw_channel_peer_data();
for peer_info in peer_infos {
peer_data.push_str(peer_info);
peer_data.push('\n');
}
self.store.persist("channel_peer_data", &peer_data)
}

pub fn persist_channel_peer(&self, peer_info: &str) -> std::io::Result<()> {
let mut peer_data = self.get_raw_channel_peer_data();
peer_data.push_str(peer_info);
Expand All @@ -239,7 +248,11 @@ impl SenseiPersister {
Ok((pubkey, socket_addr)) => {
peer_data.insert(pubkey, socket_addr);
}
Err(e) => return Err(e),
Err(_e) => {
// ignore these errors for now
// might need a way to lock reads while writing to this key
// or use separate table for peers
}
}
}
Ok(peer_data)
Expand Down
5 changes: 5 additions & 0 deletions web-admin/src/channels/components/ChannelsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const ChannelRow = ({ result, extraClass, attributes }) => {
let columnKeyComponentMap = {
inboundCapacityMsat: AmountColumn,
outboundCapacityMsat: AmountColumn,
balanceMsat: AmountColumn,
isPublic: VisibilityColumn,
status: StatusColumn,
alias: AliasColumn,
Expand Down Expand Up @@ -165,6 +166,10 @@ const ChannelsList = () => {
key: "displayChannelId",
label: "Channel Id",
},
{
key: "balanceMsat",
label: "Balance (sats)",
},
{
key: "inboundCapacityMsat",
label: "Receive Capacity (sats)",
Expand Down

0 comments on commit e772430

Please sign in to comment.