This commit is contained in:
Conner Gallagher 2023-06-13 18:37:15 -06:00
parent 51b9f47849
commit f30a77f1ad
4 changed files with 33 additions and 4531 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
[package] [package]
name = "switchboard-solana" name = "switchboard-solana"
version = "0.3.8" version = "0.3.9"
edition = "2021" edition = "2021"
description = "A Rust library to interact with Switchboard accounts." description = "A Rust library to interact with Switchboard accounts."
readme = "README.md" readme = "README.md"
@ -22,6 +22,7 @@ cpi = ["no-entrypoint"]
client = [ client = [
"switchboard-common/sgx", "switchboard-common/sgx",
"solana-client", "solana-client",
"solana-sdk",
"bincode", "bincode",
"sgx-quote", "sgx-quote",
"cron", "cron",
@ -29,20 +30,17 @@ client = [
] ]
[dependencies] [dependencies]
switchboard-common = { version = "0.1.3" } switchboard-common = { version = "0.1.6" }
rust_decimal = "^1" rust_decimal = "^1"
bytemuck = "^1" bytemuck = "^1"
superslice = "1" superslice = "1"
anchor-lang = "0.28.0" anchor-lang = "0.28.0"
anchor-spl = "0.28.0" anchor-spl = "0.28.0"
solana-program = ">= 1.14, < 1.17" solana-program = ">= 1.14, < 1.17"
solana-sdk = ">= 1.14, < 1.17" solana-sdk = { version = ">= 1.14, < 1.17", optional = true }
solana-client = { version = ">= 1.14, < 1.17", optional = true } solana-client = { version = ">= 1.14, < 1.17", optional = true }
# anchor-client = { version = "0.28.0", optional = true } # anchor-client = { version = "0.28.0", optional = true }
bincode = { version = "^1", optional = true } bincode = { version = "^1", optional = true }
sgx-quote = { version = "0.1.0", optional = true } sgx-quote = { version = "0.1.0", optional = true }
cron = { version = "0.12.0", optional = true } cron = { version = "0.12.0", optional = true }
chrono = { version = "0.4.25", optional = true } chrono = { version = "0.4.25", optional = true }
toml_datetime = "=0.6.1"
winnow = "=0.4.1"
toml_edit = "=0.19.8"

View File

@ -9,13 +9,15 @@ pub use oracle_program::*;
pub mod attestation_program; pub mod attestation_program;
pub use attestation_program::*; pub use attestation_program::*;
// Includes re-exports used by macros. // // Includes re-exports used by macros.
// // //
// This module is not intended to be part of the public API. In general, any // // This module is not intended to be part of the public API. In general, any
// `doc(hidden)` code is not part of the public and stable API. // // `doc(hidden)` code is not part of the public and stable API.
#[macro_use] // // #[macro_use]
#[doc(hidden)] // #[doc(hidden)]
pub mod macros; // pub mod macros;
mod macros;
cfg_client! { cfg_client! {
pub mod client; pub mod client;
@ -24,7 +26,21 @@ cfg_client! {
pub mod sgx; pub mod sgx;
pub use sgx::*; pub use sgx::*;
// pub use switchboard_common::{FunctionResult, Chain, Error as SwitchboardClientError}; pub use switchboard_common::{FunctionResult, Chain, Error as SwitchboardClientError};
pub mod prelude {
pub use crate::client::*;
pub use crate::sgx::*;
pub use anchor_lang as anchor;
pub use anchor_spl as spl;
pub use solana_client;
pub use anchor_lang::solana_program as solana_program;
pub use switchboard_common::{FunctionResult, Chain, Error as SwitchboardClientError};
pub use anchor_lang::prelude::*;
}
} }
// pub use anchor_lang as anchor; // pub use anchor_lang as anchor;

View File

@ -7,14 +7,13 @@ use std::env;
use std::result::Result; use std::result::Result;
use std::str::FromStr; use std::str::FromStr;
use std::sync::Arc; use std::sync::Arc;
use switchboard_common::{Error, FunctionResult, Gramine};
use crate::attestation_program::FunctionVerify; use crate::attestation_program::FunctionVerify;
use crate::{QUOTE_SEED, SWITCHBOARD_ATTESTATION_PROGRAM_ID}; use crate::{QUOTE_SEED, SWITCHBOARD_ATTESTATION_PROGRAM_ID};
pub fn generate_signer() -> Arc<Keypair> { pub fn generate_signer() -> Arc<Keypair> {
let mut randomness = [0; 32]; let mut randomness = [0; 32];
Gramine::read_rand(&mut randomness).unwrap(); switchboard_common::Gramine::read_rand(&mut randomness).unwrap();
Arc::new(keypair_from_seed(&randomness).unwrap()) Arc::new(keypair_from_seed(&randomness).unwrap())
} }
@ -22,7 +21,7 @@ pub async fn function_verify(
url: String, url: String,
fn_signer: Arc<Keypair>, fn_signer: Arc<Keypair>,
mut ixs: Vec<Instruction>, mut ixs: Vec<Instruction>,
) -> Result<FunctionResult, Error> { ) -> Result<switchboard_common::FunctionResult, switchboard_common::Error> {
let fn_signer_pubkey = crate::client::to_pubkey(fn_signer.clone())?; let fn_signer_pubkey = crate::client::to_pubkey(fn_signer.clone())?;
let client = solana_client::rpc_client::RpcClient::new_with_commitment( let client = solana_client::rpc_client::RpcClient::new_with_commitment(
@ -30,7 +29,8 @@ pub async fn function_verify(
solana_sdk::commitment_config::CommitmentConfig::processed(), solana_sdk::commitment_config::CommitmentConfig::processed(),
); );
let quote_raw = Gramine::generate_quote(&fn_signer_pubkey.to_bytes()).unwrap(); let quote_raw =
switchboard_common::Gramine::generate_quote(&fn_signer_pubkey.to_bytes()).unwrap();
let quote = Quote::parse(&quote_raw).unwrap(); let quote = Quote::parse(&quote_raw).unwrap();
let pubkeys = FunctionVerifyPubkeys::load_from_env()?; let pubkeys = FunctionVerifyPubkeys::load_from_env()?;
@ -52,7 +52,7 @@ pub async fn function_verify(
let mut tx = solana_sdk::transaction::Transaction::new_unsigned(message); let mut tx = solana_sdk::transaction::Transaction::new_unsigned(message);
tx.partial_sign(&[fn_signer.as_ref()], blockhash); tx.partial_sign(&[fn_signer.as_ref()], blockhash);
Ok(FunctionResult { Ok(switchboard_common::FunctionResult {
version: 1, version: 1,
chain: switchboard_common::Chain::Solana, chain: switchboard_common::Chain::Solana,
key: pubkeys.function.to_bytes(), key: pubkeys.function.to_bytes(),