pub struct FunctionRunner {
Show 19 fields pub request_type: SolanaFunctionRequestType, pub client: Arc<RpcClient>, pub signer: Pubkey, pub function: Pubkey, pub payer: Pubkey, pub verifier: Pubkey, pub reward_receiver: Pubkey, pub function_data: Option<Box<FunctionAccountData>>, pub verifier_enclave_signer: Option<Pubkey>, pub queue_authority: Option<Pubkey>, pub function_routine_key: Option<Pubkey>, pub function_routine_data: Option<Box<FunctionRoutineAccountData>>, pub function_request_key: Option<Pubkey>, pub function_request_data: Option<Box<FunctionRequestAccountData>>, pub attestation_queue: Option<Pubkey>, pub switchboard_state: Pubkey, pub switchboard: Pubkey, pub priority_fee: Arc<Mutex<Option<u64>>>, pub compute_limit: Arc<Mutex<Option<u32>>>, /* private fields */
}
Expand description

An object containing the context to execute a Switchboard Function. Inititlizing this object will load all required variables from the runtime to execute and sign an output transaction to be verified and committed by the switchboard network.

use switchboard_solana::FunctionRunner;

let runner = FunctionRunner::from_env(None)?;

Fields§

§request_type: SolanaFunctionRequestType

The type of Switchboard function being run.

§client: Arc<RpcClient>

The Solana RPC client to make rpc requests.

§signer: Pubkey

The pubkey of the enclave generated signer.

§function: Pubkey

The FunctionAccount pubkey being run.

§payer: Pubkey

The pubkey of the account that will pay for emitted transactions.

§verifier: Pubkey

The VerifierAccount that will verify this function run.

§reward_receiver: Pubkey

The VerifierAccount’s specified reward receiver.

§function_data: Option<Box<FunctionAccountData>>

The hex encoded FunctionAccountData, used to speed up RPC calls.

§verifier_enclave_signer: Option<Pubkey>

The pubkey of the VerifierAccount’s enclave signer.

§queue_authority: Option<Pubkey>§function_routine_key: Option<Pubkey>§function_routine_data: Option<Box<FunctionRoutineAccountData>>§function_request_key: Option<Pubkey>§function_request_data: Option<Box<FunctionRequestAccountData>>§attestation_queue: Option<Pubkey>

The AttestationQueueAccount for this request.

§switchboard_state: Pubkey

The Switchboard State pubkey.

§switchboard: Pubkey

The Attestation program id.

§priority_fee: Arc<Mutex<Option<u64>>>

The optional specified Priority Fee

§compute_limit: Arc<Mutex<Option<u32>>>

The optional specified Compute Budget limit

Implementations§

source§

impl FunctionRunner

source

pub async fn set_priority_fee(&self, priority_fee: u64)

source

pub async fn set_compute_limit(&self, compute_limit: u32)

source

pub fn new_with_client(client: RpcClient) -> Result<Self, SbError>

Create a new FunctionRunner instance with a provided RPC client.

source

pub fn new( url: &str, commitment: Option<CommitmentConfig> ) -> Result<Self, SbError>

Create a new FunctionRunner from an RPC endpoint and commitment level.

source

pub fn new_from_cluster( cluster: Cluster, commitment: Option<CommitmentConfig> ) -> Result<Self, SbError>

Create a new FunctionRunner for a given cluster.

source

pub fn from_env(commitment: Option<CommitmentConfig>) -> Result<Self, SbError>

Loads the FunctionRunner from runtime settings.

source

pub fn is_scheduled_function(&self) -> bool

source

pub fn is_routine(&self) -> bool

source

pub fn is_request(&self) -> bool

source

pub async fn load_params(&mut self) -> Result<Vec<u8>, SbError>

Load the function parameters for the given function run.

source

pub async fn load_serde_params<T: DeserializeOwned>( &mut self ) -> Result<T, SbError>

Loads the parameters from the client and deserializes them into a given type using serde.

§Example
use switchboard_solana::client::FunctionRunner;

#[derive(serde::Deserialize)]
struct MyParams {
    name: String,
    age: u8,
}

async fn my_function() -> Result<(), switchboard_solana::SbError> {
    let mut runner = FunctionRunner::new();
    let params: MyParams = runner.load_serde_params().await?;
    println!("Name: {}, Age: {}", params.name, params.age);
    Ok(())
}
source

pub fn assert_mr_enclave(&self) -> Result<(), SbError>

Assert that a FunctionAccountData contains the generated MrEnclave in its config

source

pub fn get_associated_token_address( owner: Pubkey, mint: Option<Pubkey> ) -> Pubkey

Returns the associated token address for a given owner and mint. If the mint is not provided, the native SOL mint is used.

source

pub fn upsert_feed( &self, name: &[u8; 32], value: Decimal ) -> (Pubkey, Instruction)

Generate instruction to upsert a feed owned by the given function Returns the feed pubkey and the upsert instrcution to be used in the function.

source

pub async fn get_function_result( &self, ixs: Vec<Instruction>, error_code: u8, _commitment: Option<CommitmentConfig> ) -> Result<FunctionResult, SbError>

Generates a FunctionResult object to be emitted at the end of this function run. This function result will be used be the quote verification sidecar to verify the output was run inside the function’s enclave and sign the transaction to send back on chain.

source

pub async fn emit( &self, ixs: Vec<Instruction>, commitment: Option<CommitmentConfig> ) -> Result<(), SbError>

Emits a serialized FunctionResult object to send to the quote verification sidecar.

source

pub async fn emit_error( &self, error_code: u8, commitment: Option<CommitmentConfig> ) -> Result<(), SbError>

Emit an error and relay the error code on-chain for your downstream program to handle.

source

pub async fn load_function_data( &self ) -> Result<Box<FunctionAccountData>, SbError>

Function Methods Loads the data of the function account provided by the FUNCTION_DATA environment variable.

source

pub async fn load_accounts(&mut self) -> Result<(), SbError>

Load all of the accounts

source

pub async fn load_function( &mut self ) -> Result<(Pubkey, Box<FunctionAccountData>), SbError>

source

pub async fn load_routine_data( &self ) -> Result<Box<FunctionRoutineAccountData>, SbError>

Routine Methods If this execution is tied to a function routine, load the data of the execution function routine account.

source

pub async fn load_routine( &mut self ) -> Result<(Pubkey, Box<FunctionRoutineAccountData>), SbError>

source

pub async fn load_request_data( &self ) -> Result<Box<FunctionRequestAccountData>, SbError>

Request Methods If this execution is tied to a function request, load the data of the execution function request account.

source

pub async fn load_request( &mut self ) -> Result<(Pubkey, Box<FunctionRequestAccountData>), SbError>

Trait Implementations§

source§

impl Clone for FunctionRunner

source§

fn clone(&self) -> FunctionRunner

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Display for FunctionRunner

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more