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]
name = "switchboard-solana"
version = "0.3.8"
version = "0.3.9"
edition = "2021"
description = "A Rust library to interact with Switchboard accounts."
readme = "README.md"
@ -22,6 +22,7 @@ cpi = ["no-entrypoint"]
client = [
"switchboard-common/sgx",
"solana-client",
"solana-sdk",
"bincode",
"sgx-quote",
"cron",
@ -29,20 +30,17 @@ client = [
]
[dependencies]
switchboard-common = { version = "0.1.3" }
switchboard-common = { version = "0.1.6" }
rust_decimal = "^1"
bytemuck = "^1"
superslice = "1"
anchor-lang = "0.28.0"
anchor-spl = "0.28.0"
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 }
# anchor-client = { version = "0.28.0", optional = true }
bincode = { version = "^1", optional = true }
sgx-quote = { version = "0.1.0", optional = true }
cron = { version = "0.12.0", 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 use attestation_program::*;
// Includes re-exports used by macros.
//
// 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.
#[macro_use]
#[doc(hidden)]
pub mod macros;
// // Includes re-exports used by macros.
// //
// // 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.
// // #[macro_use]
// #[doc(hidden)]
// pub mod macros;
mod macros;
cfg_client! {
pub mod client;
@ -24,7 +26,21 @@ cfg_client! {
pub mod 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;

View File

@ -7,14 +7,13 @@ use std::env;
use std::result::Result;
use std::str::FromStr;
use std::sync::Arc;
use switchboard_common::{Error, FunctionResult, Gramine};
use crate::attestation_program::FunctionVerify;
use crate::{QUOTE_SEED, SWITCHBOARD_ATTESTATION_PROGRAM_ID};
pub fn generate_signer() -> Arc<Keypair> {
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())
}
@ -22,7 +21,7 @@ pub async fn function_verify(
url: String,
fn_signer: Arc<Keypair>,
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 client = solana_client::rpc_client::RpcClient::new_with_commitment(
@ -30,7 +29,8 @@ pub async fn function_verify(
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 pubkeys = FunctionVerifyPubkeys::load_from_env()?;
@ -52,7 +52,7 @@ pub async fn function_verify(
let mut tx = solana_sdk::transaction::Transaction::new_unsigned(message);
tx.partial_sign(&[fn_signer.as_ref()], blockhash);
Ok(FunctionResult {
Ok(switchboard_common::FunctionResult {
version: 1,
chain: switchboard_common::Chain::Solana,
key: pubkeys.function.to_bytes(),