Skip to content

Commit

Permalink
Print tx index in gastronomy-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
SupernaviX committed Nov 19, 2024
1 parent 4a03a50 commit 7e154c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 4 additions & 1 deletion gastronomy-cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl Default for Focus {
#[derive(Default)]
pub struct App<'a> {
pub file_name: PathBuf,
pub index: Option<usize>,
pub cursor: usize,
pub frames: Vec<RawFrame<'a>>,
pub source_files: BTreeMap<String, String>,
Expand Down Expand Up @@ -164,7 +165,7 @@ impl<'a> Widget for &mut App<'a> {
let location = curr_frame.location;
let ret_value = curr_frame.ret_value;

let layout = render_block_region(self.file_name.clone(), location, area, buf);
let layout = render_block_region(self.file_name.clone(), self.index, location, area, buf);

let gauge_region = layout[0];
let command_region = layout[1];
Expand Down Expand Up @@ -209,13 +210,15 @@ impl<'a> Widget for &mut App<'a> {

fn render_block_region(
file_name: PathBuf,
index: Option<usize>,
location: Option<&String>,
area: Rect,
buf: &mut Buffer,
) -> Rc<[Rect]> {
let title = Line::from(vec![
" Gastronomy Debugger (".bold(),
file_name.to_str().unwrap().bold(),
index.map(|i| format!(" #{i}")).unwrap_or_default().bold(),
")".bold(),
]);
let mut instructions = if location.is_some() {
Expand Down
15 changes: 14 additions & 1 deletion gastronomy-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::BTreeMap, path::PathBuf};

use anyhow::Result;
use anyhow::{bail, Result};
use app::App;
use clap::{command, Parser, Subcommand};
use figment::providers::Env;
Expand Down Expand Up @@ -58,6 +58,18 @@ async fn run() -> Result<(), anyhow::Error> {
source_root,
}) => {
let mut raw_programs = gastronomy::uplc::load_programs_from_file(&file, query).await?;
let index = index.or(if raw_programs.len() == 1 {
None
} else {
Some(0)
});
if index.unwrap_or_default() >= raw_programs.len() {
bail!(
"Invalid index #{}, tx only has {} redeemer(s)",
index.unwrap_or_default(),
raw_programs.len()
);
}
let raw_program = raw_programs.remove(index.unwrap_or_default());
let arguments = parameters
.iter()
Expand All @@ -80,6 +92,7 @@ async fn run() -> Result<(), anyhow::Error> {
let mut terminal = utils::init()?;
let mut app = App {
file_name: file,
index,
cursor: 0,
frames,
source_files,
Expand Down

0 comments on commit 7e154c5

Please sign in to comment.