converted to macro for feature specific functions
This commit is contained in:
parent
5527c87045
commit
0b6e3c5b99
|
@ -1,4 +1,5 @@
|
|||
use crate::prelude::*;
|
||||
use crate::*;
|
||||
use anchor_lang::{Discriminator, Owner, ZeroCopy};
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use std::cell::Ref;
|
||||
|
@ -107,12 +108,12 @@ impl AttestationPermissionAccountData {
|
|||
self.permissions & p as u32 != 0
|
||||
}
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
|
||||
pub async fn fetch(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
pubkey: Pubkey,
|
||||
) -> std::result::Result<Self, switchboard_common::Error> {
|
||||
crate::client::load_account(client, pubkey).await
|
||||
cfg_client! {
|
||||
pub async fn fetch(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
pubkey: Pubkey,
|
||||
) -> std::result::Result<Self, switchboard_common::Error> {
|
||||
crate::client::load_account(client, pubkey).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::prelude::*;
|
||||
use crate::*;
|
||||
use anchor_lang::{Discriminator, Owner, ZeroCopy};
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use std::cell::Ref;
|
||||
|
@ -114,12 +115,12 @@ impl AttestationQueueAccountData {
|
|||
.any(|x| x.to_vec() == mr_enclave.to_vec())
|
||||
}
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
|
||||
pub async fn fetch(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
pubkey: Pubkey,
|
||||
) -> std::result::Result<Self, switchboard_common::Error> {
|
||||
crate::client::load_account(client, pubkey).await
|
||||
cfg_client! {
|
||||
pub async fn fetch(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
pubkey: Pubkey,
|
||||
) -> std::result::Result<Self, switchboard_common::Error> {
|
||||
crate::client::load_account(client, pubkey).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::prelude::*;
|
||||
use crate::*;
|
||||
use anchor_lang::{Discriminator, Owner, ZeroCopy};
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use std::cell::Ref;
|
||||
|
@ -146,12 +147,12 @@ impl QuoteAccountData {
|
|||
true
|
||||
}
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
|
||||
pub async fn fetch(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
pubkey: Pubkey,
|
||||
) -> std::result::Result<Self, switchboard_common::Error> {
|
||||
crate::client::load_account(client, pubkey).await
|
||||
cfg_client! {
|
||||
pub async fn fetch(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
pubkey: Pubkey,
|
||||
) -> std::result::Result<Self, switchboard_common::Error> {
|
||||
crate::client::load_account(client, pubkey).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::super::accounts::*;
|
||||
use crate::prelude::*;
|
||||
use crate::*;
|
||||
use anchor_lang::solana_program::entrypoint::ProgramResult;
|
||||
use anchor_lang::solana_program::instruction::Instruction;
|
||||
use anchor_lang::solana_program::program::{invoke, invoke_signed};
|
||||
|
@ -202,204 +202,202 @@ impl<'info> FunctionVerify<'info> {
|
|||
]
|
||||
}
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
|
||||
pub async fn build(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
fn_signer: std::sync::Arc<solana_sdk::signer::keypair::Keypair>,
|
||||
pubkeys: &FunctionVerifyPubkeys,
|
||||
mr_enclave: [u8; 32],
|
||||
) -> std::result::Result<Instruction, switchboard_common::error::Error> {
|
||||
let fn_signer_pubkey = crate::client::to_pubkey(fn_signer)?;
|
||||
cfg_client! {
|
||||
pub async fn build(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
fn_signer: std::sync::Arc<solana_sdk::signer::keypair::Keypair>,
|
||||
pubkeys: &FunctionVerifyPubkeys,
|
||||
mr_enclave: [u8; 32],
|
||||
) -> std::result::Result<Instruction, switchboard_common::error::Error> {
|
||||
let fn_signer_pubkey = crate::client::to_pubkey(fn_signer)?;
|
||||
|
||||
let current_time = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs() as i64;
|
||||
let current_time = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs() as i64;
|
||||
|
||||
let fn_data: FunctionAccountData = load_account(&client, pubkeys.function).await?;
|
||||
let fn_data: FunctionAccountData = load_account(&client, pubkeys.function).await?;
|
||||
|
||||
let verifier_quote: QuoteAccountData = load_account(&client, pubkeys.verifier).await?;
|
||||
let verifier_quote: QuoteAccountData = load_account(&client, pubkeys.verifier).await?;
|
||||
|
||||
let queue_data: AttestationQueueAccountData =
|
||||
crate::client::load_account(&client, fn_data.attestation_queue).await?;
|
||||
let queue_data: AttestationQueueAccountData =
|
||||
crate::client::load_account(&client, fn_data.attestation_queue).await?;
|
||||
|
||||
// let escrow = fn_data.escrow;
|
||||
let (fn_quote, _) = Pubkey::find_program_address(
|
||||
&[b"QuoteAccountData", &pubkeys.function.to_bytes()],
|
||||
&SWITCHBOARD_ATTESTATION_PROGRAM_ID,
|
||||
);
|
||||
// let escrow = fn_data.escrow;
|
||||
let (fn_quote, _) = Pubkey::find_program_address(
|
||||
&[b"QuoteAccountData", &pubkeys.function.to_bytes()],
|
||||
&SWITCHBOARD_ATTESTATION_PROGRAM_ID,
|
||||
);
|
||||
|
||||
let (verifier_permission, _) = Pubkey::find_program_address(
|
||||
&[
|
||||
b"PermissionAccountData",
|
||||
&queue_data.authority.to_bytes(),
|
||||
&fn_data.attestation_queue.to_bytes(),
|
||||
&pubkeys.payer.to_bytes(),
|
||||
],
|
||||
&SWITCHBOARD_ATTESTATION_PROGRAM_ID,
|
||||
);
|
||||
let (verifier_permission, _) = Pubkey::find_program_address(
|
||||
&[
|
||||
b"PermissionAccountData",
|
||||
&queue_data.authority.to_bytes(),
|
||||
&fn_data.attestation_queue.to_bytes(),
|
||||
&pubkeys.payer.to_bytes(),
|
||||
],
|
||||
&SWITCHBOARD_ATTESTATION_PROGRAM_ID,
|
||||
);
|
||||
|
||||
let (fn_permission, _) = Pubkey::find_program_address(
|
||||
&[
|
||||
b"PermissionAccountData",
|
||||
&queue_data.authority.to_bytes(),
|
||||
&fn_data.attestation_queue.to_bytes(),
|
||||
&pubkeys.function.to_bytes(),
|
||||
],
|
||||
&SWITCHBOARD_ATTESTATION_PROGRAM_ID,
|
||||
);
|
||||
let (fn_permission, _) = Pubkey::find_program_address(
|
||||
&[
|
||||
b"PermissionAccountData",
|
||||
&queue_data.authority.to_bytes(),
|
||||
&fn_data.attestation_queue.to_bytes(),
|
||||
&pubkeys.function.to_bytes(),
|
||||
],
|
||||
&SWITCHBOARD_ATTESTATION_PROGRAM_ID,
|
||||
);
|
||||
|
||||
let (state, _) =
|
||||
Pubkey::find_program_address(&[b"STATE"], &SWITCHBOARD_ATTESTATION_PROGRAM_ID);
|
||||
let (state, _) =
|
||||
Pubkey::find_program_address(&[b"STATE"], &SWITCHBOARD_ATTESTATION_PROGRAM_ID);
|
||||
|
||||
let accounts = FunctionVerifyAccounts {
|
||||
function: pubkeys.function,
|
||||
fn_signer: fn_signer_pubkey,
|
||||
fn_quote,
|
||||
verifier_quote: pubkeys.verifier,
|
||||
secured_signer: verifier_quote.authority,
|
||||
attestation_queue: fn_data.attestation_queue,
|
||||
escrow: fn_data.escrow,
|
||||
receiver: pubkeys.reward_receiver,
|
||||
verifier_permission,
|
||||
fn_permission,
|
||||
state,
|
||||
token_program: anchor_spl::token::ID,
|
||||
payer: pubkeys.payer,
|
||||
system_program: anchor_lang::solana_program::system_program::ID,
|
||||
};
|
||||
let accounts = FunctionVerifyAccounts {
|
||||
function: pubkeys.function,
|
||||
fn_signer: fn_signer_pubkey,
|
||||
fn_quote,
|
||||
verifier_quote: pubkeys.verifier,
|
||||
secured_signer: verifier_quote.authority,
|
||||
attestation_queue: fn_data.attestation_queue,
|
||||
escrow: fn_data.escrow,
|
||||
receiver: pubkeys.reward_receiver,
|
||||
verifier_permission,
|
||||
fn_permission,
|
||||
state,
|
||||
token_program: anchor_spl::token::ID,
|
||||
payer: pubkeys.payer,
|
||||
system_program: anchor_lang::solana_program::system_program::ID,
|
||||
};
|
||||
|
||||
let next_allowed_timestamp = fn_data
|
||||
.next_execution_timestamp()
|
||||
.map(|x| x.timestamp())
|
||||
.unwrap_or(i64::MAX);
|
||||
let next_allowed_timestamp = fn_data
|
||||
.next_execution_timestamp()
|
||||
.map(|x| x.timestamp())
|
||||
.unwrap_or(i64::MAX);
|
||||
|
||||
Ok(Self::build_ix(
|
||||
accounts,
|
||||
current_time,
|
||||
next_allowed_timestamp,
|
||||
false,
|
||||
mr_enclave,
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
|
||||
fn build_ix(
|
||||
accounts: FunctionVerifyAccounts,
|
||||
observed_time: i64,
|
||||
next_allowed_timestamp: i64,
|
||||
is_failure: bool,
|
||||
mr_enclave: [u8; 32],
|
||||
) -> Instruction {
|
||||
Instruction {
|
||||
program_id: SWITCHBOARD_ATTESTATION_PROGRAM_ID,
|
||||
accounts: accounts.to_account_metas(None),
|
||||
data: FunctionVerifyParams {
|
||||
observed_time,
|
||||
Ok(Self::build_ix(
|
||||
accounts,
|
||||
current_time,
|
||||
next_allowed_timestamp,
|
||||
is_failure,
|
||||
false,
|
||||
mr_enclave,
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
fn build_ix(
|
||||
accounts: FunctionVerifyAccounts,
|
||||
observed_time: i64,
|
||||
next_allowed_timestamp: i64,
|
||||
is_failure: bool,
|
||||
mr_enclave: [u8; 32],
|
||||
) -> Instruction {
|
||||
Instruction {
|
||||
program_id: SWITCHBOARD_ATTESTATION_PROGRAM_ID,
|
||||
accounts: accounts.to_account_metas(None),
|
||||
data: FunctionVerifyParams {
|
||||
observed_time,
|
||||
next_allowed_timestamp,
|
||||
is_failure,
|
||||
mr_enclave,
|
||||
}
|
||||
.data(),
|
||||
}
|
||||
.data(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
|
||||
pub struct FunctionVerifyAccounts {
|
||||
pub function: Pubkey,
|
||||
pub fn_signer: Pubkey,
|
||||
pub fn_quote: Pubkey,
|
||||
pub verifier_quote: Pubkey,
|
||||
pub secured_signer: Pubkey,
|
||||
pub attestation_queue: Pubkey,
|
||||
pub escrow: Pubkey,
|
||||
pub receiver: Pubkey,
|
||||
pub verifier_permission: Pubkey,
|
||||
pub fn_permission: Pubkey,
|
||||
pub state: Pubkey,
|
||||
pub token_program: Pubkey,
|
||||
pub payer: Pubkey,
|
||||
pub system_program: Pubkey,
|
||||
}
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
|
||||
impl ToAccountMetas for FunctionVerifyAccounts {
|
||||
fn to_account_metas(&self, _: Option<bool>) -> Vec<AccountMeta> {
|
||||
vec![
|
||||
AccountMeta {
|
||||
pubkey: self.function,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.fn_signer,
|
||||
is_signer: true,
|
||||
is_writable: false,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.fn_quote,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.verifier_quote,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.secured_signer,
|
||||
is_signer: true,
|
||||
is_writable: false,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.attestation_queue,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.escrow,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.receiver,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.verifier_permission,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.fn_permission,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.state,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.token_program,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.payer,
|
||||
is_signer: true,
|
||||
is_writable: true,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.system_program,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
},
|
||||
]
|
||||
cfg_client! {
|
||||
pub struct FunctionVerifyAccounts {
|
||||
pub function: Pubkey,
|
||||
pub fn_signer: Pubkey,
|
||||
pub fn_quote: Pubkey,
|
||||
pub verifier_quote: Pubkey,
|
||||
pub secured_signer: Pubkey,
|
||||
pub attestation_queue: Pubkey,
|
||||
pub escrow: Pubkey,
|
||||
pub receiver: Pubkey,
|
||||
pub verifier_permission: Pubkey,
|
||||
pub fn_permission: Pubkey,
|
||||
pub state: Pubkey,
|
||||
pub token_program: Pubkey,
|
||||
pub payer: Pubkey,
|
||||
pub system_program: Pubkey,
|
||||
}
|
||||
|
||||
impl ToAccountMetas for FunctionVerifyAccounts {
|
||||
fn to_account_metas(&self, _: Option<bool>) -> Vec<AccountMeta> {
|
||||
vec![
|
||||
AccountMeta {
|
||||
pubkey: self.function,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.fn_signer,
|
||||
is_signer: true,
|
||||
is_writable: false,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.fn_quote,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.verifier_quote,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.secured_signer,
|
||||
is_signer: true,
|
||||
is_writable: false,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.attestation_queue,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.escrow,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.receiver,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.verifier_permission,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.fn_permission,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.state,
|
||||
is_signer: false,
|
||||
is_writable: true,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.token_program,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.payer,
|
||||
is_signer: true,
|
||||
is_writable: true,
|
||||
},
|
||||
AccountMeta {
|
||||
pubkey: self.system_program,
|
||||
is_signer: false,
|
||||
is_writable: false,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,12 +123,12 @@ impl OracleAccountData {
|
|||
))
|
||||
}
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
|
||||
pub async fn fetch(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
pubkey: Pubkey,
|
||||
) -> std::result::Result<Self, switchboard_common::Error> {
|
||||
crate::client::load_account(client, pubkey).await
|
||||
cfg_client! {
|
||||
pub async fn fetch(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
pubkey: Pubkey,
|
||||
) -> std::result::Result<Self, switchboard_common::Error> {
|
||||
crate::client::load_account(client, pubkey).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,12 +156,13 @@ impl OracleQueueAccountData {
|
|||
))
|
||||
}
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
|
||||
pub async fn fetch(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
pubkey: Pubkey,
|
||||
) -> std::result::Result<Self, switchboard_common::Error> {
|
||||
crate::client::load_account(client, pubkey).await
|
||||
cfg_client! {
|
||||
pub async fn fetch(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
pubkey: Pubkey,
|
||||
) -> std::result::Result<Self, switchboard_common::Error> {
|
||||
crate::client::load_account(client, pubkey).await
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,12 +124,12 @@ impl VrfAccountData {
|
|||
Ok(self.current_round.result)
|
||||
}
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
|
||||
pub async fn fetch(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
pubkey: Pubkey,
|
||||
) -> std::result::Result<Self, switchboard_common::Error> {
|
||||
crate::client::load_account(client, pubkey).await
|
||||
cfg_client! {
|
||||
pub async fn fetch(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
pubkey: Pubkey,
|
||||
) -> std::result::Result<Self, switchboard_common::Error> {
|
||||
crate::client::load_account(client, pubkey).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,12 +134,12 @@ impl VrfLiteAccountData {
|
|||
Ok(self.result)
|
||||
}
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
|
||||
pub async fn fetch(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
pubkey: Pubkey,
|
||||
) -> std::result::Result<Self, switchboard_common::Error> {
|
||||
crate::client::load_account(client, pubkey).await
|
||||
cfg_client! {
|
||||
pub async fn fetch(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
pubkey: Pubkey,
|
||||
) -> std::result::Result<Self, switchboard_common::Error> {
|
||||
crate::client::load_account(client, pubkey).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,13 +97,13 @@ impl VrfPoolAccountData {
|
|||
))
|
||||
}
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
|
||||
pub async fn fetch(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
pubkey: Pubkey,
|
||||
) -> std::result::Result<Self, switchboard_common::Error> {
|
||||
crate::client::load_account(client, pubkey).await
|
||||
cfg_client! {
|
||||
pub async fn fetch(
|
||||
client: &solana_client::rpc_client::RpcClient,
|
||||
pubkey: Pubkey,
|
||||
) -> std::result::Result<Self, switchboard_common::Error> {
|
||||
crate::client::load_account(client, pubkey).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue