anza-xyz / anza-xyz/pinocchio

[Feature] Add InstructionParser Derive Macro

Offen
#405 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Rust
Sterne
951
Forks
228
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

## Problem

Currently, every Pinocchio program needs to manually parse instructions from byte data:

```rust
pub fn process_instruction(
program_id: &Address,
accounts: &mut [AccountView],
instruction_data: &[u8],
) -> ProgramResult {
if instruction_data.is_empty() {
return Err(ProgramError::InvalidInstructionData);
}

match instruction_data[0] {
1 => {
if instruction_data.len() < 9 {
return Err(ProgramError::InvalidInstructionData);
}
let amount_bytes = [
instruction_data[1],
instruction_data[2],
instruction_data[3],
instruction_data[4],
instruction_data[5],
instruction_data[6],
instruction_data[7],
instruction_data[8],
];
let amount = u64::from_le_bytes(amount_bytes);
handle_transfer(..., amount)?;
}
2 => {
// Repeat the same parsing logic for each instruction
}
_ => return Err(ProgramError::InvalidInstructionData),
}
Ok(())
}

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.