Struct switchboard_on_demand::prelude::TransactionBuilder
source · pub struct TransactionBuilder { /* private fields */ }
Expand description
Represents a transaction object used for building Solana transactions.
The TransactionBuilder
struct provides methods for constructing and manipulating Solana transactions.
It allows setting the payer, adding instructions, signers, and other transaction parameters.
The transaction can be converted to a legacy transaction format or executed directly using the Solana RPC client.
§Examples
Creating a new transaction object with a payer:
use solana_sdk::pubkey::Pubkey;
use solana_sdk::instruction::Instruction;
use std::sync::Arc;
let payer = Pubkey::new_unique();
let transaction = TransactionBuilder::new(payer);
Adding an instruction to the transaction:
use solana_sdk::pubkey::Pubkey;
use solana_sdk::instruction::Instruction;
use std::sync::Arc;
let payer = Pubkey::new_unique();
let instruction = Instruction::new_with_bincode(program_id, data);
let transaction = TransactionBuilder::new(payer)
.add_ix(instruction);
Converting the transaction object to a legacy transaction:
use solana_sdk::pubkey::Pubkey;
use solana_sdk::instruction::Instruction;
use std::sync::Arc;
let payer = Pubkey::new_unique();
let instruction = Instruction::new_with_bincode(program_id, data);
let transaction = TransactionBuilder::new(payer)
.add_ix(instruction)
.to_legacy_tx();
Implementations§
source§impl TransactionBuilder
impl TransactionBuilder
pub fn new(payer: Pubkey) -> Self
pub fn new_with_payer(payer: Arc<dyn AsSigner>) -> Self
pub fn new_with_ixs( payer: Pubkey, ixs: impl IntoIterator<Item = Instruction>, ) -> Self
pub fn new_with_payer_and_ixs( payer: Arc<dyn AsSigner>, ixs: impl IntoIterator<Item = Instruction>, ) -> Self
pub fn set_compute_units(self, compute_units: u32) -> Self
pub fn set_priority_fees(self, priority_fees: u64) -> Self
pub fn add_ix(self, ix: Instruction) -> Self
pub fn has_signer(&self, signer: Pubkey) -> bool
pub fn has_payer(&self) -> bool
pub fn add_signer(self, signer: Arc<dyn AsSigner>) -> TransactionBuilder
pub fn add_signers(self, signers: Vec<Arc<dyn AsSigner>>) -> TransactionBuilder
pub fn set_recent_blockhash(self, blockhash: Hash) -> Self
pub fn set_min_context_slot(self, min_context_slot: u64) -> Self
pub fn add_address_lookup_account( self, address_lookup_table: AddressLookupTableAccount, ) -> Self
pub fn add_address_lookup_accounts( self, address_lookup_tables: &mut Vec<AddressLookupTableAccount>, ) -> Self
pub async fn add_address_lookup_table( self, rpc: &RpcClient, address_lookup_table_pubkey: Pubkey, ) -> Self
pub async fn add_address_lookup_tables( self, rpc: &RpcClient, address_lookup_table_pubkeys: Vec<Pubkey>, ) -> Self
pub fn payer(&self) -> Pubkey
sourcepub fn required_signers(&self) -> Vec<Pubkey>
pub fn required_signers(&self) -> Vec<Pubkey>
Return a vec of all of the required signers for the transaction.
sourcepub fn signers(&self) -> Result<Vec<&dyn Signer>, OnDemandError>
pub fn signers(&self) -> Result<Vec<&dyn Signer>, OnDemandError>
Returns the stored signers for the transaction, removing any un-needed signers using the provided ixn’s AccountMeta’s.
pub fn ixs(&self) -> Result<Vec<Instruction>, OnDemandError>
pub fn build_legacy_tx( payer: Pubkey, ixs: Vec<Instruction>, signers: Vec<&dyn Signer>, recent_blockhash: Hash, ) -> Result<Transaction, OnDemandError>
pub fn to_legacy_tx(&self) -> Result<Transaction, OnDemandError>
pub fn to_legacy_tx_with_payer<T: AsSigner + Send + Sync>( &self, payer: T, ) -> Result<Transaction, OnDemandError>
pub fn to_legacy_tx_with_payer_and_blockhash<T: AsSigner + Send + Sync>( &self, payer: T, recent_blockhash: Option<Hash>, ) -> Result<Transaction, OnDemandError>
pub fn to_legacy_tx_with_blockhash( &self, recent_blockhash: Option<Hash>, ) -> Result<Transaction, OnDemandError>
pub async fn fetch_address_lookup_account( rpc: &RpcClient, address_lookup_table_pubkey: Pubkey, ) -> Result<AddressLookupTableAccount, OnDemandError>
pub async fn fetch_multiple_address_lookup_accounts( rpc: &RpcClient, address_lookup_pubkeys: Vec<Pubkey>, ) -> Result<Vec<AddressLookupTableAccount>, OnDemandError>
pub fn build_v0_tx( payer: Pubkey, ixs: Vec<Instruction>, signers: Vec<&dyn Signer>, address_lookup_accounts: Vec<AddressLookupTableAccount>, recent_blockhash: Hash, ) -> Result<VersionedTransaction, OnDemandError>
pub fn to_v0_tx(&self) -> Result<VersionedTransaction, OnDemandError>
pub fn to_v0_tx_with_payer<T: AsSigner + Send + Sync>( &self, payer: T, ) -> Result<VersionedTransaction, OnDemandError>
Trait Implementations§
source§impl Clone for TransactionBuilder
impl Clone for TransactionBuilder
source§fn clone(&self) -> TransactionBuilder
fn clone(&self) -> TransactionBuilder
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Default for TransactionBuilder
impl Default for TransactionBuilder
source§fn default() -> TransactionBuilder
fn default() -> TransactionBuilder
Returns the “default value” for a type. Read more
source§impl TryFrom<TransactionBuilder> for Transaction
impl TryFrom<TransactionBuilder> for Transaction
§type Error = OnDemandError
type Error = OnDemandError
The type returned in the event of a conversion error.
source§impl TryFrom<TransactionBuilder> for VersionedTransaction
impl TryFrom<TransactionBuilder> for VersionedTransaction
§type Error = OnDemandError
type Error = OnDemandError
The type returned in the event of a conversion error.
Auto Trait Implementations§
impl Freeze for TransactionBuilder
impl !RefUnwindSafe for TransactionBuilder
impl Send for TransactionBuilder
impl Sync for TransactionBuilder
impl Unpin for TransactionBuilder
impl !UnwindSafe for TransactionBuilder
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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 more