pub struct Message {
pub header: MessageHeader,
pub config: TransactionConfig,
pub lifetime_specifier: Hash,
pub account_keys: Vec<Address>,
pub instructions: Vec<CompiledInstruction>,
}target_os=solana only.Expand description
A V1 transaction message (SIMD-0385) supporting 4KB transactions with inline compute budget.
§Important
This message format does not support bincode binary serialization. Use the provided
serialize and deserialize functions for binary encoding/decoding.
Fields§
§header: MessageHeaderThe message header describing signer/readonly account counts.
config: TransactionConfigConfiguration for transaction parameters.
lifetime_specifier: HashThe lifetime specifier (blockhash) that determines when this transaction expires.
account_keys: Vec<Address>All account addresses referenced by this message.
The length should be specified as an u8. Unlike V0, V1 does not support
address lookup tables. The ordering of the addresses is unchanged from prior
transaction formats:
-
num_required_signatures-num_readonly_signed_accountsadditional addresses for which the transaction contains signatures and are loaded as writable, of which the first is the fee payer. -
num_readonly_signed_accountsaddresses for which the transaction contains signatures and are loaded as readonly. -
num_addresses-num_required_signatures-num_readonly_unsigned_accountsaddresses for which the transaction does not contain signatures and are loaded as writable. -
num_readonly_unsigned_accountsaddresses for which the transaction does not contain signatures and are loaded as readonly.
instructions: Vec<CompiledInstruction>Program instructions to execute.
Implementations§
Source§impl Message
impl Message
Sourcepub fn new(
header: MessageHeader,
config: TransactionConfig,
lifetime_specifier: Hash,
account_keys: Vec<Address>,
instructions: Vec<CompiledInstruction>,
) -> Self
pub fn new( header: MessageHeader, config: TransactionConfig, lifetime_specifier: Hash, account_keys: Vec<Address>, instructions: Vec<CompiledInstruction>, ) -> Self
Create a new V1 message.
Sourcepub fn try_compile(
payer: &Address,
instructions: &[Instruction],
recent_blockhash: Hash,
) -> Result<Self, CompileError>
pub fn try_compile( payer: &Address, instructions: &[Instruction], recent_blockhash: Hash, ) -> Result<Self, CompileError>
Create a signable transaction message from a payer public key,
recent_blockhash, list of instructions and a transaction config.
§Examples
This example uses the solana_rpc_client, solana_account, and anyhow crates.
use anyhow::Result;
use solana_instruction::{AccountMeta, Instruction};
use solana_keypair::Keypair;
use solana_message::{VersionedMessage, v1};
use solana_address::Address;
use solana_rpc_client::rpc_client::RpcClient;
use solana_signer::Signer;
use solana_transaction::versioned::VersionedTransaction;
fn create_v1_tx(
client: &RpcClient,
instruction: Instruction,
payer: &Keypair,
) -> Result<VersionedTransaction> {
let blockhash = client.get_latest_blockhash()?;
let tx = VersionedTransaction::try_new(
VersionedMessage::V1(v1::Message::try_compile(
&payer.pubkey(),
&[instruction],
blockhash,
)?),
&[payer],
)?;
Ok(tx)
}Sourcepub fn try_compile_with_config(
payer: &Address,
instructions: &[Instruction],
recent_blockhash: Hash,
config: TransactionConfig,
) -> Result<Self, CompileError>
pub fn try_compile_with_config( payer: &Address, instructions: &[Instruction], recent_blockhash: Hash, config: TransactionConfig, ) -> Result<Self, CompileError>
Create a signable transaction message from a payer public key,
recent_blockhash, list of instructions and a transaction config.
§Examples
This example uses the solana_rpc_client, solana_account, and anyhow crates.
use anyhow::Result;
use solana_instruction::{AccountMeta, Instruction};
use solana_keypair::Keypair;
use solana_message::{VersionedMessage, v1, v1::TransactionConfig};
use solana_address::Address;
use solana_rpc_client::rpc_client::RpcClient;
use solana_signer::Signer;
use solana_transaction::versioned::VersionedTransaction;
fn create_v1_tx(
client: &RpcClient,
instruction: Instruction,
payer: &Keypair,
) -> Result<VersionedTransaction> {
let blockhash = client.get_latest_blockhash()?;
let tx = VersionedTransaction::try_new(
VersionedMessage::V1(v1::Message::try_compile_with_config(
&payer.pubkey(),
&[instruction],
blockhash,
TransactionConfig::empty().with_compute_unit_limit(100),
)?),
&[payer],
)?;
Ok(tx)
}Sourcepub fn is_signer(&self, index: usize) -> bool
pub fn is_signer(&self, index: usize) -> bool
Account keys are ordered with signers first: [signers..., non-signers...].
An index falls in the signer region if it’s less than num_required_signatures.
Sourcepub fn is_signer_writable(&self, index: usize) -> bool
pub fn is_signer_writable(&self, index: usize) -> bool
Returns true if the account at this index is both a signer and writable.
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 any instruction invokes the account at this index as a program.
Sourcepub fn is_upgradeable_loader_present(&self) -> bool
pub fn is_upgradeable_loader_present(&self) -> bool
Returns true if the BPF upgradeable loader is present in the account keys.
Sourcepub fn is_maybe_writable(
&self,
key_index: usize,
reserved_account_keys: Option<&HashSet<Address>>,
) -> bool
pub fn is_maybe_writable( &self, key_index: usize, reserved_account_keys: Option<&HashSet<Address>>, ) -> bool
Returns true if the account at the specified index was requested as
writable.
§Important
Before loading addresses, we can’t demote write locks properly so this should
not be used by the runtime. The reserved_account_keys parameter is optional
to allow clients to approximate writability without requiring fetching the latest
set of reserved account keys.
Program accounts are demoted from writable to readonly, unless the upgradeable loader is present in which case they are left as writable since upgradeable programs need to be writable for upgrades.
pub fn demote_program_id(&self, i: usize) -> bool
Sourcepub fn serialize(&self) -> Vec<u8> ⓘ
Available on crate feature wincode only.
pub fn serialize(&self) -> Vec<u8> ⓘ
wincode only.Serialize this message with the V1 version prefix byte.
pub fn validate(&self) -> Result<(), MessageError>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
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, C: Config> SchemaRead<'de, C> for Message
Available on crate feature wincode only.
impl<'de, C: Config> SchemaRead<'de, C> for Message
wincode only.Source§impl<C: ConfigCore> SchemaWrite<C> for Message
Available on crate feature wincode only.
impl<C: ConfigCore> SchemaWrite<C> for Message
wincode only.impl Eq for Message
impl StructuralPartialEq for Message
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.