Skip to content

Commit

Permalink
Updating node implementation versions, adding logging and comments, r…
Browse files Browse the repository at this point in the history
…emoving trailing whitespace
  • Loading branch information
bjohnson5 committed Dec 6, 2024
1 parent 1d91b24 commit 637d542
Show file tree
Hide file tree
Showing 19 changed files with 292 additions and 185 deletions.
18 changes: 9 additions & 9 deletions blast_cli/src/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,48 +101,48 @@ impl BlastTab for ConfigureTab {
[Constraint::Percentage(5), Constraint::Percentage(95)],
)
.split(area);

let layout1 = Layout::new(
Direction::Horizontal,
[Constraint::Percentage(50), Constraint::Percentage(50)],
)
.split(l[1]);

let layout = Layout::new(
Direction::Vertical,
[Constraint::Percentage(33), Constraint::Percentage(33), Constraint::Percentage(33)],
).split(layout1[1]);

let e: Vec<ListItem> = self.events.items.clone().iter()
.map(|i| ListItem::new(vec![text::Line::from(Span::raw(i.clone()))])).collect();
let etasks = List::new(e)
.block(Block::bordered().title("Events"))
.highlight_style(Style::default().fg(Color::LightYellow).add_modifier(Modifier::BOLD))
.highlight_symbol("> ");
frame.render_stateful_widget(etasks, layout[0], &mut self.events.state);

let c: Vec<ListItem> = self.channels.items.clone().iter()
.map(|i| ListItem::new(vec![text::Line::from(Span::raw(i.clone()))])).collect();
let ctasks = List::new(c)
.block(Block::bordered().title("Channels"))
.highlight_style(Style::default().fg(Color::LightYellow).add_modifier(Modifier::BOLD))
.highlight_symbol("> ");
frame.render_stateful_widget(ctasks, layout[1], &mut self.channels.state);

let a: Vec<ListItem> = self.activity.items.clone().iter()
.map(|i| ListItem::new(vec![text::Line::from(Span::raw(i.clone()))])).collect();
let atasks = List::new(a)
.block(Block::bordered().title("Activity"))
.highlight_style(Style::default().fg(Color::LightYellow).add_modifier(Modifier::BOLD))
.highlight_symbol("> ");
frame.render_stateful_widget(atasks, layout[2], &mut self.activity.state);

let vertical = Layout::vertical([
Constraint::Length(3),
Constraint::Min(1),
]);
let [input_area, messages_area] = vertical.areas(layout1[0]);

let msg = vec![
"Use ".into(),
"stop".bold(),
Expand All @@ -157,15 +157,15 @@ impl BlastTab for ConfigureTab {
let text = Text::from(Line::from(msg)).patch_style(Style::default());
let help_message = Paragraph::new(text);
frame.render_widget(help_message, l[0]);

let input = Paragraph::new(self.input.as_str())
.style(match self.current_section {
ConfigureSection::Command => Style::default().fg(Color::LightYellow),
_ => Style::default(),
})
.block(Block::bordered().title("Command"));
frame.render_widget(input, input_area);

match self.current_section {
ConfigureSection::Command => {
#[allow(clippy::cast_possible_truncation)]
Expand Down
2 changes: 1 addition & 1 deletion blast_cli/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl BlastTab for LoadTab {
.iter()
.map(|i| ListItem::new(vec![text::Line::from(Span::raw(i.clone()))]))
.collect();

let tasks = List::new(tasks)
.block(Block::bordered().title("Simulations"))
.highlight_style(Style::default().fg(Color::LightYellow).add_modifier(Modifier::BOLD))
Expand Down
6 changes: 3 additions & 3 deletions blast_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ async fn run<B: Backend>(terminal: &mut Terminal<B>, mut blast_cli: BlastCli) ->
Err(e) => {
failed = true;
error_str = e;
}
}
}

// Start the simulation
Expand Down Expand Up @@ -375,7 +375,7 @@ fn ui(frame: &mut Frame, tab: &mut dyn BlastTab, error: Option<String>) {
.block(Block::bordered().title("Error"));
let area = centered_rect(60, 20, chunks[1]);
frame.render_widget(Clear, area);
frame.render_widget(error_msg, area);
frame.render_widget(error_msg, area);
},
None => {
// Draw the current page
Expand Down Expand Up @@ -572,7 +572,7 @@ async fn run_command(blast: &mut blast_core::Blast, cmd: String) -> Vec<String>
let msg = format!("Unable to open channel: {}", e);
output.push(msg);
}
}
}
},
"connect_peer" => {
let source = String::from(words.next().unwrap_or(""));
Expand Down
2 changes: 1 addition & 1 deletion blast_cli/src/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl BlastTab for NewTab {
.iter()
.map(|i| ListItem::new(i.clone()))
.collect();

let tasks = List::new(tasks)
.block(Block::bordered().title("Models"))
.highlight_style(Style::default().fg(Color::LightYellow).add_modifier(Modifier::BOLD))
Expand Down
18 changes: 9 additions & 9 deletions blast_cli/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl BlastTab for RunTab {
[Constraint::Percentage(5), Constraint::Percentage(10), Constraint::Percentage(85)],
)
.split(area);

let msg = vec![
"Press ".into(),
"s".bold(),
Expand All @@ -61,50 +61,50 @@ impl BlastTab for RunTab {
let text = Text::from(Line::from(msg)).patch_style(Style::default());
let help_message = Paragraph::new(text);
frame.render_widget(help_message, layout[0]);

let line_gauge = LineGauge::default()
.block(Block::new().title("Simulation Progress:"))
.filled_style(Style::default().fg(Color::LightBlue))
.line_set(symbols::line::THICK)
.ratio(self.progress);
frame.render_widget(line_gauge, layout[1]);

let layout2 = Layout::new(
Direction::Horizontal,
[Constraint::Percentage(50), Constraint::Percentage(50)],
)
.split(layout[2]);

let layout3 = Layout::new(
Direction::Vertical,
[Constraint::Percentage(33), Constraint::Percentage(50), Constraint::Percentage(33)],
)
.split(layout2[0]);

let e: Vec<ListItem> = self.events.items.clone().iter()
.map(|i| ListItem::new(vec![text::Line::from(Span::raw(i.clone()))])).collect();
let etasks = List::new(e)
.block(Block::bordered().title("Events"))
.highlight_style(Style::default().fg(Color::LightYellow).add_modifier(Modifier::BOLD))
.highlight_symbol("> ");
frame.render_stateful_widget(etasks, layout3[0], &mut self.events.state);

let a: Vec<ListItem> = self.activity.items.clone().iter()
.map(|i| ListItem::new(vec![text::Line::from(Span::raw(i.clone()))])).collect();
let atasks = List::new(a)
.block(Block::bordered().title("Activity"))
.highlight_style(Style::default().fg(Color::LightYellow).add_modifier(Modifier::BOLD))
.highlight_symbol("> ");
frame.render_stateful_widget(atasks, layout3[1], &mut self.activity.state);

let s: Vec<ListItem> = self.stats.items.clone().iter()
.map(|i| ListItem::new(vec![text::Line::from(Span::raw(i.clone()))])).collect();
let stasks = List::new(s)
.block(Block::bordered().title("Stats"))
.highlight_style(Style::default().fg(Color::LightYellow).add_modifier(Modifier::BOLD))
.highlight_symbol("> ");
frame.render_stateful_widget(stasks, layout3[2], &mut self.stats.state);

let x_labels = vec![
Span::styled(
format!("{}", self.window[0]),
Expand Down Expand Up @@ -259,7 +259,7 @@ impl BlastTab for RunTab {
for i in 0..20 {
self.success_rate_data[i] = self.success_rate_data[i + 1];
}

self.success_rate_data[20] = (frame as f64, succes_rate);
}
}
Expand Down
8 changes: 4 additions & 4 deletions blast_cli/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use ratatui::{

// BLAST constants
pub const BANNER: &str = r"
____ _ _____ _______
____ _ _____ _______
| _ \| | /\ / ____|__ __|
| |_) | | / \ | (___ | |
| _ <| | / /\ \ \___ \ | |
| |_) | |____ / ____ \ ____) | | |
| |_) | | / \ | (___ | |
| _ <| | / /\ \ \___ \ | |
| |_) | |____ / ____ \ ____) | | |
|____/|______/_/ \_\_____/ |_| ";

pub const TAB_TITLES: [&'static str; 4] = ["New", "Load", "Configure", "Run"];
Expand Down
4 changes: 2 additions & 2 deletions blast_core/src/blast_event_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl BlastEventManager {
Ok(n) => n,
Err(e) => return Err(format!("Error parsing argument: {}", e))
};

let blast_event = BlastEvent::CloseChannelEvent(arg0, arg1);
self.push_event(frame_num, blast_event);
Ok(())
Expand All @@ -208,7 +208,7 @@ impl BlastEventManager {
Ok(n) => n,
Err(e) => return Err(format!("Error parsing argument: {}", e))
};

let blast_event = BlastEvent::OnChainTransaction(arg0, arg1, arg2);
self.push_event(frame_num, blast_event);
Ok(())
Expand Down
36 changes: 18 additions & 18 deletions blast_core/src/blast_model_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl BlastModelManager {
return Err(format!("Failed to get the current directory: {:?}", e));
}
};

// Get the full path to the model executable
current_dir.push("../blast_models/".to_owned()+&model.config.name+"/"+&model.config.start);
let model_exe = current_dir.to_string_lossy().into_owned();
Expand Down Expand Up @@ -211,7 +211,7 @@ impl BlastModelManager {
let request = tonic::Request::new(BlastLoadRequest {
sim: sim_name
});

// Execute the load RPC
let response = match client.load(request).await {
Ok(r) => r,
Expand All @@ -225,7 +225,7 @@ impl BlastModelManager {
Ok(())
} else {
Err(String::from("Model did not load successfully"))
}
}
}

/// Tell a model to save its current state
Expand All @@ -237,7 +237,7 @@ impl BlastModelManager {
let request = tonic::Request::new(BlastSaveRequest {
sim: sim_name
});

// Execute the save RPC
let response = match client.save(request).await {
Ok(r) => r,
Expand All @@ -251,7 +251,7 @@ impl BlastModelManager {
Ok(())
} else {
Err(String::from("Model did not save successfully"))
}
}
}

/// Get a list of the currently available models
Expand All @@ -261,7 +261,7 @@ impl BlastModelManager {
Err(String::from("No models available"))
} else {
Ok(keys)
}
}
}

/// Start a given number of nodes for the given model name
Expand All @@ -273,7 +273,7 @@ impl BlastModelManager {
let request = tonic::Request::new(BlastStartRequest {
num_nodes: num_nodes,
});

// Execute the start RPC
let response = match client.start_nodes(request).await {
Ok(r) => r,
Expand Down Expand Up @@ -369,7 +369,7 @@ impl BlastModelManager {
return Err(format!("RPC wallet_balance failed: {:?}", e));
}
};

Ok(response.get_ref().balance.clone())
}

Expand All @@ -393,7 +393,7 @@ impl BlastModelManager {
return Err(format!("RPC channel_balance failed: {:?}", e));
}
};

Ok(response.get_ref().balance.clone())
}

Expand All @@ -417,7 +417,7 @@ impl BlastModelManager {
return Err(format!("RPC list_channels failed: {:?}", e));
}
};

Ok(response.get_ref().channels.clone())
}

Expand Down Expand Up @@ -480,7 +480,7 @@ impl BlastModelManager {
return Err(format!("RPC open_channel failed: {:?}", e));
}
};

// Determine if the RPC was successful
if response.get_ref().success {
Ok(())
Expand All @@ -489,7 +489,7 @@ impl BlastModelManager {
}
}

/// Close a channel with chan_id from a node with source_id
/// Close a channel with chan_id from a node with source_id
pub async fn close_channel(&mut self, source_id: String, chan_id: i64) -> Result<(), String> {
// Get the model name from the node_id (example node_id: model_name-0000)
let model_name: String = get_model_from_node(source_id.clone());
Expand All @@ -510,7 +510,7 @@ impl BlastModelManager {
return Err(format!("RPC close_channel failed: {:?}", e));
}
};

// Determine if the RPC was successful
if response.get_ref().success {
Ok(())
Expand Down Expand Up @@ -544,7 +544,7 @@ impl BlastModelManager {
return Err(format!("RPC connect_peer failed: {:?}", e));
}
};

// Determine if the RPC was successful
if response.get_ref().success {
Ok(())
Expand Down Expand Up @@ -576,7 +576,7 @@ impl BlastModelManager {
return Err(format!("RPC disconnect_peer failed: {:?}", e));
}
};

// Determine if the RPC was successful
if response.get_ref().success {
Ok(())
Expand Down Expand Up @@ -605,7 +605,7 @@ impl BlastModelManager {
return Err(format!("RPC get_btc_address failed: {:?}", e));
}
};

Ok(response.get_ref().address.clone())
}

Expand All @@ -629,7 +629,7 @@ impl BlastModelManager {
return Err(format!("RPC get_listen_address failed: {:?}", e));
}
};

Ok(response.get_ref().address.clone())
}

Expand All @@ -655,7 +655,7 @@ impl BlastModelManager {
fn get_model_from_node(node_id: String) -> String {
// Split the input string on the '-' character
let parts: Vec<&str> = node_id.split('-').collect();

// Return the first part, or an empty string if the input was empty
parts.get(0).unwrap_or(&"").to_string()
}
Expand Down
2 changes: 1 addition & 1 deletion blast_core/src/blast_simln_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl BlastSimLnManager {
Ok(())
},
None => return Err(anyhow!("Simln not setup. Call set_simln before starting the simulation")),
}
}
}

/// Stop SimLn simulation
Expand Down
Loading

0 comments on commit 637d542

Please sign in to comment.