Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,23 @@ test: build
cargo test -p visualsign --features diagnostics --lib
cargo test -p visualsign-solana --features diagnostics --lib

# Solana preset sources, which `cargo fmt` cannot reach. `presets/mod.rs`
# declares its submodules through `include!(concat!(env!("OUT_DIR"), ...))`, a
# path that exists only after codegen, and rustfmt does not follow an `include!`
# of a generated path -- so `cargo fmt` formats `presets/mod.rs` and nothing
# beneath it. These files are enumerated so `fmt` covers them directly.
#
# `find` rather than a literal list: presets are scaffolded one directory per
# program and the set grows with each new one, so a hardcoded list drops files
# out of the gate as soon as it goes stale.
SOLANA_PRESET_SOURCES := $(shell find chain_parsers/visualsign-solana/src/presets -name '*.rs' 2>/dev/null | sort)

.PHONY: fmt
fmt:
cargo fmt
@test -n "$(SOLANA_PRESET_SOURCES)" || { echo "no preset sources found under chain_parsers/visualsign-solana/src/presets"; exit 1; }
@echo "rustfmt $(words $(SOLANA_PRESET_SOURCES)) Solana preset sources"
@rustfmt $(SOLANA_PRESET_SOURCES)

.PHONY: lint
lint:
Expand Down
6 changes: 2 additions & 4 deletions src/chain_parsers/visualsign-solana/src/presets/drift/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ mod tests {

#[test]
fn test_build_fallback_fields_renders_unknown_instruction() {
let (title, condensed, expanded) =
build_fallback_fields(DRIFT_PROGRAM_ID).unwrap();
let (title, condensed, expanded) = build_fallback_fields(DRIFT_PROGRAM_ID).unwrap();
assert_eq!(title, "Drift: Unknown Instruction");
assert_eq!(condensed.len(), 2);
assert_eq!(expanded.len(), 2);
Expand All @@ -261,8 +260,7 @@ mod tests {
fn test_build_parsed_fields_renders_deposit_instruction() {
let instruction = make_parsed_instruction("deposit");
let (title, condensed, expanded) =
build_parsed_fields(&instruction, DRIFT_PROGRAM_ID)
.unwrap();
build_parsed_fields(&instruction, DRIFT_PROGRAM_ID).unwrap();
assert_eq!(title, "Drift: deposit");
assert!(!condensed.is_empty());
assert!(!expanded.is_empty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ impl InstructionVisualizer for ExponentFinanceVisualizer {
let data = context.data();

let instruction_data_hex = hex::encode(data);
let fallback_text = format!("Program ID: {}\nData: {instruction_data_hex}", view.program_id);
let fallback_text = format!(
"Program ID: {}\nData: {instruction_data_hex}",
view.program_id
);

let parsed = parse_exponent_finance_instruction(data, &view.accounts);

Expand Down Expand Up @@ -110,11 +113,7 @@ fn parse_exponent_finance_instruction(
})
}

fn build_named_accounts(
data: &[u8],
idl: &Idl,
accounts: &[String],
) -> BTreeMap<String, String> {
fn build_named_accounts(data: &[u8], idl: &Idl, accounts: &[String]) -> BTreeMap<String, String> {
let mut named_accounts = BTreeMap::new();

let idl_instruction = idl.instructions.iter().find(|inst| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ impl InstructionVisualizer for JupiterBorrowVisualizer {
let data = context.data();

let instruction_data_hex = hex::encode(data);
let fallback_text = format!("Program ID: {}\nData: {instruction_data_hex}", view.program_id);
let fallback_text = format!(
"Program ID: {}\nData: {instruction_data_hex}",
view.program_id
);

let parsed = parse_jupiter_borrow_instruction(data, &view.accounts);

Expand Down Expand Up @@ -106,11 +109,7 @@ fn parse_jupiter_borrow_instruction(
})
}

fn build_named_accounts(
data: &[u8],
idl: &Idl,
accounts: &[String],
) -> BTreeMap<String, String> {
fn build_named_accounts(data: &[u8], idl: &Idl, accounts: &[String]) -> BTreeMap<String, String> {
let mut named_accounts = BTreeMap::new();

let idl_instruction = idl.instructions.iter().find(|inst| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ impl InstructionVisualizer for JupiterEarnVisualizer {
let data = context.data();

let instruction_data_hex = hex::encode(data);
let fallback_text = format!("Program ID: {}\nData: {instruction_data_hex}", view.program_id);
let fallback_text = format!(
"Program ID: {}\nData: {instruction_data_hex}",
view.program_id
);

let parsed = parse_jupiter_earn_instruction(data, &view.accounts);

Expand Down Expand Up @@ -106,11 +109,7 @@ fn parse_jupiter_earn_instruction(
})
}

fn build_named_accounts(
data: &[u8],
idl: &Idl,
accounts: &[String],
) -> BTreeMap<String, String> {
fn build_named_accounts(data: &[u8], idl: &Idl, accounts: &[String]) -> BTreeMap<String, String> {
let mut named_accounts = BTreeMap::new();

let idl_instruction = idl.instructions.iter().find(|inst| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ impl InstructionVisualizer for JupiterPerpsVisualizer {
let data = context.data();

let instruction_data_hex = hex::encode(data);
let fallback_text = format!("Program ID: {}\nData: {instruction_data_hex}", view.program_id);
let fallback_text = format!(
"Program ID: {}\nData: {instruction_data_hex}",
view.program_id
);

let parsed = parse_jupiter_perps_instruction(data, &view.accounts);

Expand Down Expand Up @@ -110,11 +113,7 @@ fn parse_jupiter_perps_instruction(
})
}

fn build_named_accounts(
data: &[u8],
idl: &Idl,
accounts: &[String],
) -> BTreeMap<String, String> {
fn build_named_accounts(data: &[u8], idl: &Idl, accounts: &[String]) -> BTreeMap<String, String> {
let mut named_accounts = BTreeMap::new();

let idl_instruction = idl.instructions.iter().find(|inst| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ impl InstructionVisualizer for KaminoBorrowVisualizer {
let data = context.data();

let instruction_data_hex = hex::encode(data);
let fallback_text = format!("Program ID: {}\nData: {instruction_data_hex}", view.program_id);
let fallback_text = format!(
"Program ID: {}\nData: {instruction_data_hex}",
view.program_id
);

let parsed = parse_kamino_borrow_instruction(data, &view.accounts);

Expand Down Expand Up @@ -106,11 +109,7 @@ fn parse_kamino_borrow_instruction(
})
}

fn build_named_accounts(
data: &[u8],
idl: &Idl,
accounts: &[String],
) -> BTreeMap<String, String> {
fn build_named_accounts(data: &[u8], idl: &Idl, accounts: &[String]) -> BTreeMap<String, String> {
let mut named_accounts = BTreeMap::new();

let idl_instruction = idl.instructions.iter().find(|inst| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ impl InstructionVisualizer for MeteoraDammV2Visualizer {
}),
};

let fallback_text = format!("Program ID: {}\nData: {instruction_data_hex}", view.program_id);
let fallback_text = format!(
"Program ID: {}\nData: {instruction_data_hex}",
view.program_id
);

Ok(AnnotatedPayloadField {
static_annotation: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ impl InstructionVisualizer for MeteoraDlmmVisualizer {
expanded: Some(expanded),
};

let fallback_text = format!("Program ID: {}\nData: {}", view.program_id, hex::encode(data));
let fallback_text = format!(
"Program ID: {}\nData: {}",
view.program_id,
hex::encode(data)
);

Ok(AnnotatedPayloadField {
static_annotation: None,
Expand Down Expand Up @@ -116,11 +120,7 @@ fn get_meteora_dlmm_idl() -> Option<&'static Idl> {
.as_ref()
}

fn build_named_accounts(
idl: &Idl,
data: &[u8],
accounts: &[String],
) -> Vec<(String, String)> {
fn build_named_accounts(idl: &Idl, data: &[u8], accounts: &[String]) -> Vec<(String, String)> {
if data.len() < 8 {
return Vec::new();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,7 @@ fn load_idl() -> Result<Idl, VisualSignError> {
.map_err(|e| VisualSignError::DecodeError(format!("Invalid Neutral Trade IDL: {e}")))
}

fn build_named_accounts(
data: &[u8],
accounts: &[String],
idl: &Idl,
) -> BTreeMap<String, String> {
fn build_named_accounts(data: &[u8], accounts: &[String], idl: &Idl) -> BTreeMap<String, String> {
let mut named_accounts = BTreeMap::new();

let matching_idl_instruction = idl.instructions.iter().find(|inst| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ impl InstructionVisualizer for OrcaWhirlpoolVisualizer {
expanded: Some(expanded),
};

let fallback_text = format!("Program ID: {}\nData: {}", view.program_id, hex::encode(data));
let fallback_text = format!(
"Program ID: {}\nData: {}",
view.program_id,
hex::encode(data)
);

Ok(AnnotatedPayloadField {
static_annotation: None,
Expand Down
18 changes: 5 additions & 13 deletions src/chain_parsers/visualsign-solana/src/presets/swig_wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,10 +871,7 @@ fn build_inner_instruction(
})
}

fn visualize_inner_instruction(
instruction: Instruction,
parent_depth: usize,
) -> Option<String> {
fn visualize_inner_instruction(instruction: Instruction, parent_depth: usize) -> Option<String> {
let visualizers: Vec<Box<dyn InstructionVisualizer>> = available_visualizers();
let visualizer_refs: Vec<&dyn InstructionVisualizer> =
visualizers.iter().map(|viz| viz.as_ref()).collect();
Expand Down Expand Up @@ -1140,20 +1137,15 @@ fn nested_too_deeply_field(
instruction_number: usize,
depth: usize,
) -> Result<AnnotatedPayloadField, VisualSignError> {
let summary = format!(
"Swig: Nested too deeply (depth {depth}, limit {MAX_CALL_DEPTH})"
);
let summary = format!("Swig: Nested too deeply (depth {depth}, limit {MAX_CALL_DEPTH})");
let condensed = SignablePayloadFieldListLayout {
fields: vec![make_text_field("Instruction", summary.clone())?],
};
let expanded = SignablePayloadFieldListLayout {
fields: vec![
make_text_field("Instruction Type", "Nested Too Deeply")?,
make_text_field("Nesting Depth", depth.to_string())?,
make_text_field(
"Nesting Depth Limit",
MAX_CALL_DEPTH.to_string(),
)?,
make_text_field("Nesting Depth Limit", MAX_CALL_DEPTH.to_string())?,
],
};
let preview_layout = SignablePayloadFieldPreviewLayout {
Expand Down Expand Up @@ -2772,8 +2764,8 @@ mod tests {
// data(inner_data)]
let mut data: Vec<u8> = vec![0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
for _ in 0..levels {
let inner_len = u16::try_from(data.len())
.expect("nested payload exceeds u16 bound");
let inner_len =
u16::try_from(data.len()).expect("nested payload exceeds u16 bound");
let mut next = Vec::with_capacity(data.len() + 14);
// SignV1 header: payload_len = 6 + inner_len (compact bytes wrapping `data`).
let payload_len = 6u16 + inner_len;
Expand Down
1 change: 1 addition & 0 deletions src/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
edition = "2024"
Loading