Skip to content

Commit

Permalink
Add hex view for transaction data
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcph4 committed Jan 20, 2025
1 parent 656d5f9 commit 6cfc941
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 24 additions & 4 deletions src/ui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ use ratatui::{
symbols,
text::{Line, Span, Text},
widgets::{
Bar, BarChart, BarGroup, Block, List, ListItem, Paragraph, Wrap,
Bar, BarChart, BarGroup, Block, Borders, List, ListItem, Paragraph,
},
Frame,
};

use crate::{
db::Database,
utils::{
self, etherscan_block_url, etherscan_transaction_url, to_ether,
to_gwei, useful_gas_price, BuilderIdentity,
self, etherscan_block_url, etherscan_transaction_url, grab_range,
to_ether, to_gwei, useful_gas_price, BuilderIdentity,
},
};

Expand Down Expand Up @@ -256,6 +256,10 @@ impl App {
Span::styled("Value: ", Style::new().bold()),
Span::raw(format!("{} Ether", to_ether(tx.value()))),
]),
Line::from(vec![
Span::styled("Input: ", Style::new().bold()),
Span::raw(format!("({} bytes)", tx.input().len())),
]),
];
let transaction_header_text = Paragraph::new(Text::from(lines));
frame.render_widget(transaction_header_text, chunks[0]);
Expand Down Expand Up @@ -505,8 +509,24 @@ impl App {
frame: &mut Frame,
area: Rect,
) {
let mut lines = vec![];

for i in 0..(bytes.len().div_ceil(32)) {
lines.push(Line::from(vec![
Span::styled(
format!("{:#06x}", i * 32),
Style::new().underlined(),
),
Span::raw(format!(
" {}",
&grab_range(bytes, i * 32, (i + 1) * 32).to_string()[2..]
)),
]));
}

frame.render_widget(
Paragraph::new(format!("{}", bytes)).wrap(Wrap { trim: true }),
Paragraph::new(Text::from(lines))
.block(Block::default().borders(Borders::ALL)),
area,
);
}
Expand Down
10 changes: 10 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,13 @@ pub fn to_ether(x: U256) -> f64 {
pub fn useful_gas_price(tx: &Transaction) -> u128 {
tx.max_fee_per_gas()
}

pub fn grab_range(xs: &Bytes, a: usize, b: usize) -> Bytes {
if a >= xs.len() {
Bytes::from(vec![])
} else if b > xs.len() {
Bytes::from(xs[a..xs.len()].to_vec())
} else {
Bytes::from(xs[a..b].to_vec())
}
}

0 comments on commit 6cfc941

Please sign in to comment.