Struct switchboard_solana::prelude::FunctionRunner
source · 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.
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
impl FunctionRunner
pub async fn set_priority_fee(&self, priority_fee: u64)
pub async fn set_compute_limit(&self, compute_limit: u32)
sourcepub fn new_with_client(client: RpcClient) -> Result<Self, SbError>
pub fn new_with_client(client: RpcClient) -> Result<Self, SbError>
Create a new FunctionRunner instance with a provided RPC client.
sourcepub fn new(
url: &str,
commitment: Option<CommitmentConfig>
) -> Result<Self, SbError>
pub fn new( url: &str, commitment: Option<CommitmentConfig> ) -> Result<Self, SbError>
Create a new FunctionRunner from an RPC endpoint and commitment level.
sourcepub fn new_from_cluster(
cluster: Cluster,
commitment: Option<CommitmentConfig>
) -> Result<Self, SbError>
pub fn new_from_cluster( cluster: Cluster, commitment: Option<CommitmentConfig> ) -> Result<Self, SbError>
Create a new FunctionRunner for a given cluster.
sourcepub fn from_env(commitment: Option<CommitmentConfig>) -> Result<Self, SbError>
pub fn from_env(commitment: Option<CommitmentConfig>) -> Result<Self, SbError>
Loads the FunctionRunner from runtime settings.
pub fn is_scheduled_function(&self) -> bool
pub fn is_routine(&self) -> bool
pub fn is_request(&self) -> bool
sourcepub async fn load_params(&mut self) -> Result<Vec<u8>, SbError>
pub async fn load_params(&mut self) -> Result<Vec<u8>, SbError>
Load the function parameters for the given function run.
sourcepub async fn load_serde_params<T: DeserializeOwned>(
&mut self
) -> Result<T, SbError>
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(())
}
sourcepub fn assert_mr_enclave(&self) -> Result<(), SbError>
pub fn assert_mr_enclave(&self) -> Result<(), SbError>
Assert that a FunctionAccountData
contains the generated MrEnclave in its config
sourcepub fn get_associated_token_address(
owner: Pubkey,
mint: Option<Pubkey>
) -> Pubkey
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.
sourcepub fn upsert_feed(
&self,
name: &[u8; 32],
value: Decimal
) -> (Pubkey, Instruction)
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.
sourcepub async fn get_function_result(
&self,
ixs: Vec<Instruction>,
error_code: u8,
_commitment: Option<CommitmentConfig>
) -> Result<FunctionResult, SbError>
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.
sourcepub async fn emit(
&self,
ixs: Vec<Instruction>,
commitment: Option<CommitmentConfig>
) -> Result<(), SbError>
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.
sourcepub async fn emit_error(
&self,
error_code: u8,
commitment: Option<CommitmentConfig>
) -> Result<(), SbError>
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.
sourcepub async fn load_function_data(
&self
) -> Result<Box<FunctionAccountData>, SbError>
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.
sourcepub async fn load_accounts(&mut self) -> Result<(), SbError>
pub async fn load_accounts(&mut self) -> Result<(), SbError>
Load all of the accounts
pub async fn load_function( &mut self ) -> Result<(Pubkey, Box<FunctionAccountData>), SbError>
sourcepub async fn load_routine_data(
&self
) -> Result<Box<FunctionRoutineAccountData>, SbError>
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.
pub async fn load_routine( &mut self ) -> Result<(Pubkey, Box<FunctionRoutineAccountData>), SbError>
sourcepub async fn load_request_data(
&self
) -> Result<Box<FunctionRequestAccountData>, SbError>
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.
pub async fn load_request( &mut self ) -> Result<(Pubkey, Box<FunctionRequestAccountData>), SbError>
Trait Implementations§
source§impl Clone for FunctionRunner
impl Clone for FunctionRunner
source§fn clone(&self) -> FunctionRunner
fn clone(&self) -> FunctionRunner
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more