pub struct Message {
pub header: MessageHeader,
pub account_keys: Vec<Address>,
pub recent_blockhash: Hash,
pub instructions: Vec<CompiledInstruction>,
pub address_table_lookups: Vec<MessageAddressTableLookup>,
}Expand description
A Solana transaction message (v0).
This message format supports succinct account loading with on-chain address lookup tables.
See the crate documentation for further description.
Fields§
§header: MessageHeaderThe 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<Address>List of accounts loaded by this transaction.
recent_blockhash: HashThe blockhash of a recent block.
instructions: Vec<CompiledInstruction>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
writablelookup table indexes - ordered list of keys loaded from
readablelookup table indexes
address_table_lookups: Vec<MessageAddressTableLookup>List of address table lookups used to load additional accounts for this transaction.
Implementations§
Source§impl Message
impl Message
Sourcepub fn sanitize(&self) -> Result<(), SanitizeError>
Available on non-target_os=solana only.
pub fn sanitize(&self) -> Result<(), SanitizeError>
target_os=solana only.Sanitize message fields and compiled instruction indexes
Source§impl Message
impl Message
Sourcepub fn try_compile(
payer: &Address,
instructions: &[Instruction],
address_lookup_table_accounts: &[AddressLookupTableAccount],
recent_blockhash: Hash,
) -> Result<Self, CompileError>
Available on non-target_os=solana only.
pub fn try_compile( payer: &Address, instructions: &[Instruction], address_lookup_table_accounts: &[AddressLookupTableAccount], recent_blockhash: Hash, ) -> Result<Self, CompileError>
target_os=solana only.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_rpc_client, solana_account, and anyhow crates.
use anyhow::Result;
use solana_address_lookup_table_interface::state::{AddressLookupTable, LookupTableMeta};
use solana_instruction::{AccountMeta, Instruction};
use solana_keypair::Keypair;
use solana_message::{AddressLookupTableAccount, VersionedMessage, v0};
use solana_address::Address;
use solana_rpc_client::rpc_client::RpcClient;
use solana_signer::Signer;
use solana_transaction::versioned::VersionedTransaction;
fn create_tx_with_address_table_lookup(
client: &RpcClient,
instruction: Instruction,
address_lookup_table_key: Address,
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> ⓘ
Available on non-target_os=solana and crate feature wincode only.
pub fn serialize(&self) -> Vec<u8> ⓘ
target_os=solana and crate feature wincode only.Serialize this message with a version #0 prefix using wincode encoding.
Sourcepub fn is_key_called_as_program(&self, key_index: usize) -> bool
Available on non-target_os=solana only.
pub fn is_key_called_as_program(&self, key_index: usize) -> bool
target_os=solana only.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,
reserved_account_keys: Option<&HashSet<Address>>,
) -> bool
Available on non-target_os=solana only.
pub fn is_maybe_writable( &self, key_index: usize, reserved_account_keys: Option<&HashSet<Address>>, ) -> bool
target_os=solana only.Returns true if the account at the specified index was requested as
writable. Before loading addresses, we can’t demote write locks properly
so this should not be used by the runtime. The reserved_account_keys
param is optional to allow clients to approximate writability without
requiring fetching the latest set of reserved account keys.
Trait Implementations§
Source§impl AbiExample for Message
Available on non-target_os=solana only.
impl AbiExample for Message
target_os=solana only.Source§impl<'de> Deserialize<'de> for Message
Available on non-target_os=solana only.
impl<'de> Deserialize<'de> for Message
target_os=solana only.Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'de, WincodeConfig: Config> SchemaRead<'de, WincodeConfig> for Message
Available on non-target_os=solana only.
impl<'de, WincodeConfig: Config> SchemaRead<'de, WincodeConfig> for Message
target_os=solana only.Source§impl<WincodeConfig: Config> SchemaWrite<WincodeConfig> for Message
Available on non-target_os=solana only.
impl<WincodeConfig: Config> SchemaWrite<WincodeConfig> for Message
target_os=solana only.impl Eq for Message
target_os=solana only.impl StructuralPartialEq for Message
target_os=solana only.Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
Blanket Implementations§
Source§impl<T> AbiEnumVisitor for T
impl<T> AbiEnumVisitor for T
default fn visit_for_abi( &self, _digester: &mut AbiDigester, ) -> Result<AbiDigester, DigestError>
Source§impl<T> AbiEnumVisitor for Twhere
T: Serialize + AbiExample,
impl<T> AbiEnumVisitor for Twhere
T: Serialize + AbiExample,
default fn visit_for_abi( &self, digester: &mut AbiDigester, ) -> Result<AbiDigester, DigestError>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<'de, T> Deserialize<'de> for Twhere
T: SchemaRead<'de, Configuration>,
impl<'de, T> Deserialize<'de> for Twhere
T: SchemaRead<'de, Configuration>,
Source§impl<'de, T, C> Deserialize<'de, C> for Twhere
C: Config,
T: SchemaRead<'de, C>,
impl<'de, T, C> Deserialize<'de, C> for Twhere
C: Config,
T: SchemaRead<'de, C>,
Source§impl<T, C> DeserializeOwned<C> for Twhere
C: Config,
T: SchemaReadOwned<C>,
impl<T, C> DeserializeOwned<C> for Twhere
C: Config,
T: SchemaReadOwned<C>,
Source§fn deserialize_from<'de>(src: impl Reader<'de>) -> Result<Self::Dst, ReadError>
fn deserialize_from<'de>(src: impl Reader<'de>) -> Result<Self::Dst, ReadError>
Reader into a new Self::Dst.Source§fn deserialize_from_into<'de>(
src: impl Reader<'de>,
dst: &mut MaybeUninit<Self::Dst>,
) -> Result<(), ReadError>
fn deserialize_from_into<'de>( src: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>, ) -> Result<(), ReadError>
Reader into dst.Source§impl<T> DeserializeOwned for Twhere
T: SchemaReadOwned<Configuration>,
impl<T> DeserializeOwned for Twhere
T: SchemaReadOwned<Configuration>,
Source§fn deserialize_from<'de>(src: impl Reader<'de>) -> Result<Self::Dst, ReadError>
fn deserialize_from<'de>(src: impl Reader<'de>) -> Result<Self::Dst, ReadError>
Reader into a new Self::Dst.Source§fn deserialize_from_into<'de>(
src: impl Reader<'de>,
dst: &mut MaybeUninit<Self::Dst>,
) -> Result<(), ReadError>
fn deserialize_from_into<'de>( src: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>, ) -> Result<(), ReadError>
Reader into dst.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T, C> Serialize<C> for T
impl<T, C> Serialize<C> for T
Source§fn serialize(src: &Self::Src, config: C) -> Result<Vec<u8>, WriteError>
fn serialize(src: &Self::Src, config: C) -> Result<Vec<u8>, WriteError>
alloc only.Vec of bytes.Source§fn serialize_into(
dst: impl Writer,
src: &Self::Src,
config: C,
) -> Result<(), WriteError>
fn serialize_into( dst: impl Writer, src: &Self::Src, config: C, ) -> Result<(), WriteError>
Writer.Source§fn serialized_size(src: &Self::Src, config: C) -> Result<u64, WriteError>
fn serialized_size(src: &Self::Src, config: C) -> Result<u64, WriteError>
Source§impl<T> Serialize for T
impl<T> Serialize for T
Source§fn serialize(src: &Self::Src) -> Result<Vec<u8>, WriteError>
fn serialize(src: &Self::Src) -> Result<Vec<u8>, WriteError>
alloc only.Vec of bytes.