converted to macro for feature specific functions

This commit is contained in:
Conner Gallagher 2023-06-13 20:07:20 -06:00
parent 5527c87045
commit 0b6e3c5b99
9 changed files with 240 additions and 238 deletions

View File

@ -1,4 +1,5 @@
use crate::prelude::*; use crate::prelude::*;
use crate::*;
use anchor_lang::{Discriminator, Owner, ZeroCopy}; use anchor_lang::{Discriminator, Owner, ZeroCopy};
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
use std::cell::Ref; use std::cell::Ref;
@ -107,12 +108,12 @@ impl AttestationPermissionAccountData {
self.permissions & p as u32 != 0 self.permissions & p as u32 != 0
} }
#[cfg(feature = "client")] cfg_client! {
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
pub async fn fetch( pub async fn fetch(
client: &solana_client::rpc_client::RpcClient, client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey, pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> { ) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await crate::client::load_account(client, pubkey).await
} }
}
} }

View File

@ -1,4 +1,5 @@
use crate::prelude::*; use crate::prelude::*;
use crate::*;
use anchor_lang::{Discriminator, Owner, ZeroCopy}; use anchor_lang::{Discriminator, Owner, ZeroCopy};
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
use std::cell::Ref; use std::cell::Ref;
@ -114,12 +115,12 @@ impl AttestationQueueAccountData {
.any(|x| x.to_vec() == mr_enclave.to_vec()) .any(|x| x.to_vec() == mr_enclave.to_vec())
} }
#[cfg(feature = "client")] cfg_client! {
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
pub async fn fetch( pub async fn fetch(
client: &solana_client::rpc_client::RpcClient, client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey, pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> { ) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await crate::client::load_account(client, pubkey).await
} }
}
} }

View File

@ -1,4 +1,5 @@
use crate::prelude::*; use crate::prelude::*;
use crate::*;
use anchor_lang::{Discriminator, Owner, ZeroCopy}; use anchor_lang::{Discriminator, Owner, ZeroCopy};
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
use std::cell::Ref; use std::cell::Ref;
@ -146,12 +147,12 @@ impl QuoteAccountData {
true true
} }
#[cfg(feature = "client")] cfg_client! {
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
pub async fn fetch( pub async fn fetch(
client: &solana_client::rpc_client::RpcClient, client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey, pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> { ) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await crate::client::load_account(client, pubkey).await
} }
}
} }

View File

@ -1,5 +1,5 @@
use super::super::accounts::*;
use crate::prelude::*; use crate::prelude::*;
use crate::*;
use anchor_lang::solana_program::entrypoint::ProgramResult; use anchor_lang::solana_program::entrypoint::ProgramResult;
use anchor_lang::solana_program::instruction::Instruction; use anchor_lang::solana_program::instruction::Instruction;
use anchor_lang::solana_program::program::{invoke, invoke_signed}; use anchor_lang::solana_program::program::{invoke, invoke_signed};
@ -202,8 +202,7 @@ impl<'info> FunctionVerify<'info> {
] ]
} }
#[cfg(feature = "client")] cfg_client! {
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
pub async fn build( pub async fn build(
client: &solana_client::rpc_client::RpcClient, client: &solana_client::rpc_client::RpcClient,
fn_signer: std::sync::Arc<solana_sdk::signer::keypair::Keypair>, fn_signer: std::sync::Arc<solana_sdk::signer::keypair::Keypair>,
@ -284,8 +283,7 @@ impl<'info> FunctionVerify<'info> {
)) ))
} }
#[cfg(feature = "client")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
fn build_ix( fn build_ix(
accounts: FunctionVerifyAccounts, accounts: FunctionVerifyAccounts,
observed_time: i64, observed_time: i64,
@ -305,11 +303,11 @@ impl<'info> FunctionVerify<'info> {
.data(), .data(),
} }
} }
}
} }
#[cfg(feature = "client")] cfg_client! {
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))] pub struct FunctionVerifyAccounts {
pub struct FunctionVerifyAccounts {
pub function: Pubkey, pub function: Pubkey,
pub fn_signer: Pubkey, pub fn_signer: Pubkey,
pub fn_quote: Pubkey, pub fn_quote: Pubkey,
@ -324,10 +322,9 @@ pub struct FunctionVerifyAccounts {
pub token_program: Pubkey, pub token_program: Pubkey,
pub payer: Pubkey, pub payer: Pubkey,
pub system_program: Pubkey, pub system_program: Pubkey,
} }
#[cfg(feature = "client")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))] impl ToAccountMetas for FunctionVerifyAccounts {
impl ToAccountMetas for FunctionVerifyAccounts {
fn to_account_metas(&self, _: Option<bool>) -> Vec<AccountMeta> { fn to_account_metas(&self, _: Option<bool>) -> Vec<AccountMeta> {
vec![ vec![
AccountMeta { AccountMeta {
@ -402,4 +399,5 @@ impl ToAccountMetas for FunctionVerifyAccounts {
}, },
] ]
} }
}
} }

View File

@ -123,12 +123,12 @@ impl OracleAccountData {
)) ))
} }
#[cfg(feature = "client")] cfg_client! {
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
pub async fn fetch( pub async fn fetch(
client: &solana_client::rpc_client::RpcClient, client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey, pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> { ) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await crate::client::load_account(client, pubkey).await
} }
}
} }

View File

@ -156,12 +156,13 @@ impl OracleQueueAccountData {
)) ))
} }
#[cfg(feature = "client")] cfg_client! {
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
pub async fn fetch( pub async fn fetch(
client: &solana_client::rpc_client::RpcClient, client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey, pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> { ) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await crate::client::load_account(client, pubkey).await
} }
}
} }

View File

@ -124,12 +124,12 @@ impl VrfAccountData {
Ok(self.current_round.result) Ok(self.current_round.result)
} }
#[cfg(feature = "client")] cfg_client! {
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
pub async fn fetch( pub async fn fetch(
client: &solana_client::rpc_client::RpcClient, client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey, pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> { ) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await crate::client::load_account(client, pubkey).await
} }
}
} }

View File

@ -134,12 +134,12 @@ impl VrfLiteAccountData {
Ok(self.result) Ok(self.result)
} }
#[cfg(feature = "client")] cfg_client! {
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
pub async fn fetch( pub async fn fetch(
client: &solana_client::rpc_client::RpcClient, client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey, pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> { ) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await crate::client::load_account(client, pubkey).await
} }
}
} }

View File

@ -97,14 +97,14 @@ impl VrfPoolAccountData {
)) ))
} }
#[cfg(feature = "client")] cfg_client! {
#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
pub async fn fetch( pub async fn fetch(
client: &solana_client::rpc_client::RpcClient, client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey, pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> { ) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await crate::client::load_account(client, pubkey).await
} }
}
} }
// impl Discriminator for VrfPoolAccountData { // impl Discriminator for VrfPoolAccountData {