12 unstable releases (3 breaking)
0.4.1 | Sep 6, 2024 |
---|---|
0.4.0 | Sep 6, 2024 |
0.3.7 | Sep 6, 2024 |
0.2.1 | Sep 6, 2024 |
0.1.0 | Sep 1, 2024 |
#7 in #signers
26KB
408 lines
Solana Transaction Introspection
Deserialize signed Solana transactions into instructions, signers and blockhash from Ed25519Instruction data for use in payment channels and other L2 settlement scenarios.
Features
- Deserialize Transactions onchain: Deserialize Ed25519Instruction data into a
SignedTransaction
- Return signers: List signers of Ed25519Instruction to validate in your program
Data Structures
SignedTransaction
A struct representing the signed transaction, containing the following fields:
header
: ASignedTransactionHeader
including the number of signers and readonly accounts.signers
: A vector of unique public keys representing the signers of the transaction.recent_blockhash
: The blockhash at the time the transaction was created.instructions
: A vector ofSignedTransactionInstruction
structs representing the transaction's instructions.
SignedTransactionHeader
A struct that holds metadata about the transaction:
signers
: Number of writable signers.readonly_signers
: Number of readonly signers.readonly
: Number of readonly accounts.
SignedTransactionInstruction
A struct representing a single instruction in the transaction:
program_id
: The program ID associated with this instruction.accounts
: A vector of public keys representing the accounts involved in the instruction.data
: A vector of bytes representing the instruction data.
Usage
To deserialize a signed transaction from bytes:
use solana_program::pubkey;
use solana_signer_transaction::SignedTransaction;
fn main() {
let transaction_bytes = [/* Ed25519Instruction data */];
let transaction = SignedTransaction::from_bytes(&transaction_bytes).unwrap();
// Access transaction components
println!("{:?}", transaction.signers);
println!("{:?}", transaction.recent_blockhash);
println!("{:?}", transaction.instructions);
}
Testing
Unit tests are included to verify the correctness of deserialization.
Running Tests
cargo test
License
This project is licensed under the MIT License. See the LICENSE file for details.
Dependencies
~11–20MB
~303K SLoC