Struct solana_sdk::message::v0::Message
source · pub struct Message {
pub header: MessageHeader,
pub account_keys: Vec<Pubkey, Global>,
pub recent_blockhash: Hash,
pub instructions: Vec<CompiledInstruction, Global>,
pub address_table_lookups: Vec<MessageAddressTableLookup, Global>,
}
Expand description
A Safecoin transaction message (v0).
This message format supports succinct account loading with on-chain address lookup tables.
See the message
module documentation for further description.
Fields§
§header: MessageHeader
The message header, identifying signed and read-only account_keys
.
Header values only describe static account_keys
, they do not describe
any additional account keys loaded via address table lookups.
account_keys: Vec<Pubkey, Global>
List of accounts loaded by this transaction.
recent_blockhash: Hash
The blockhash of a recent block.
instructions: Vec<CompiledInstruction, Global>
Instructions that invoke a designated program, are executed in sequence, and committed in one atomic transaction if all succeed.
Notes
Program indexes must index into the list of message account_keys
because
program id’s cannot be dynamically loaded from a lookup table.
Account indexes must index into the list of addresses constructed from the concatenation of three key lists:
- message
account_keys
- ordered list of keys loaded from
writable
lookup table indexes - ordered list of keys loaded from
readable
lookup table indexes
address_table_lookups: Vec<MessageAddressTableLookup, Global>
List of address table lookups used to load additional accounts for this transaction.
Implementations§
source§impl Message
impl Message
sourcepub fn try_compile(
payer: &Pubkey,
instructions: &[Instruction],
address_lookup_table_accounts: &[AddressLookupTableAccount],
recent_blockhash: Hash
) -> Result<Message, CompileError>
pub fn try_compile( payer: &Pubkey, instructions: &[Instruction], address_lookup_table_accounts: &[AddressLookupTableAccount], recent_blockhash: Hash ) -> Result<Message, CompileError>
Create a signable transaction message from a payer
public key,
recent_blockhash
, list of instructions
, and a list of
address_lookup_table_accounts
.
Examples
This example uses the solana_address_lookup_table_program
, safecoin_client
, solana_sdk
, and anyhow
crates.
use anyhow::Result;
use solana_address_lookup_table_program::state::AddressLookupTable;
use safecoin_client::rpc_client::RpcClient;
use solana_sdk::{
address_lookup_table_account::AddressLookupTableAccount,
instruction::{AccountMeta, Instruction},
message::{VersionedMessage, v0},
pubkey::Pubkey,
signature::{Keypair, Signer},
transaction::VersionedTransaction,
};
fn create_tx_with_address_table_lookup(
client: &RpcClient,
instruction: Instruction,
address_lookup_table_key: Pubkey,
payer: &Keypair,
) -> Result<VersionedTransaction> {
let raw_account = client.get_account(&address_lookup_table_key)?;
let address_lookup_table = AddressLookupTable::deserialize(&raw_account.data)?;
let address_lookup_table_account = AddressLookupTableAccount {
key: address_lookup_table_key,
addresses: address_lookup_table.addresses.to_vec(),
};
let blockhash = client.get_latest_blockhash()?;
let tx = VersionedTransaction::try_new(
VersionedMessage::V0(v0::Message::try_compile(
&payer.pubkey(),
&[instruction],
&[address_lookup_table_account],
blockhash,
)?),
&[payer],
)?;
Ok(tx)
}
sourcepub fn serialize(&self) -> Vec<u8, Global> ⓘ
pub fn serialize(&self) -> Vec<u8, Global> ⓘ
Serialize this message with a version #0 prefix using bincode encoding.
sourcepub fn is_key_called_as_program(&self, key_index: usize) -> bool
pub fn is_key_called_as_program(&self, key_index: usize) -> bool
Returns true if the account at the specified index is called as a program by an instruction
sourcepub fn is_maybe_writable(&self, key_index: usize) -> bool
pub fn is_maybe_writable(&self, key_index: usize) -> bool
Returns true if the account at the specified index was requested as writable. Before loading addresses, we can’t demote write locks for dynamically loaded addresses so this should not be used by the runtime.