This commit is contained in:
Conner Gallagher 2023-06-13 15:00:48 -06:00
parent 42e02e6e2f
commit d4c46e3db9
32 changed files with 493 additions and 363 deletions

8
.changeset/README.md Normal file
View File

@ -0,0 +1,8 @@
# Changesets
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

11
.changeset/config.json Normal file
View File

@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}

View File

@ -797,6 +797,15 @@ dependencies = [
"libc",
]
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
dependencies = [
"serde",
]
[[package]]
name = "hmac"
version = "0.8.1"
@ -1755,8 +1764,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f"
[[package]]
name = "switchboard-v2"
version = "0.1.23"
name = "switchboard-common"
version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3432650dcf9ba9f8512ecd2d2424dba1accd21a2f57019964f193087fda7b4"
dependencies = [
"hex",
"serde",
"serde_json",
"sha2 0.10.6",
]
[[package]]
name = "switchboard-solana"
version = "0.0.1"
dependencies = [
"anchor-lang",
"anchor-spl",
@ -1764,6 +1785,7 @@ dependencies = [
"rust_decimal",
"solana-program",
"superslice",
"switchboard-common",
"toml_datetime",
"toml_edit",
"winnow",
@ -1777,7 +1799,7 @@ dependencies = [
"anchor-spl",
"bytemuck",
"solana-program",
"switchboard-v2",
"switchboard-solana",
]
[[package]]

View File

@ -212,6 +212,91 @@ importers:
specifier: ^4.9.3
version: 4.9.4
examples/03_basic_function:
dependencies:
'@coral-xyz/anchor':
specifier: ^0.27.0
version: 0.27.0
'@coral-xyz/borsh':
specifier: ^0.27.0
version: 0.27.0(@solana/web3.js@1.73.3)
'@project-serum/borsh':
specifier: ^0.2.5
version: 0.2.5(@solana/web3.js@1.73.3)
'@solana/spl-token':
specifier: ^0.3.6
version: 0.3.6(@solana/web3.js@1.73.3)
'@solana/web3.js':
specifier: ^1.73.3
version: 1.73.3
'@switchboard-xyz/common':
specifier: ^2.2.0
version: 2.2.0
'@switchboard-xyz/oracle':
specifier: ^2.1.13
version: 2.1.13
'@switchboard-xyz/solana.js':
specifier: workspace:*
version: link:../../javascript/solana.js
chalk:
specifier: ^4.1.2
version: 4.1.2
dotenv:
specifier: ^16.0.1
version: 16.0.3
yargs:
specifier: ^17.5.1
version: 17.6.2
devDependencies:
'@types/chai':
specifier: ^4.3.0
version: 4.3.4
'@types/mocha':
specifier: ^9.0.0
version: 9.1.1
'@types/node':
specifier: ^17.0.45
version: 17.0.45
'@typescript-eslint/eslint-plugin':
specifier: ^5.44.0
version: 5.44.0(@typescript-eslint/parser@5.44.0)(eslint@8.42.0)(typescript@4.9.4)
'@typescript-eslint/parser':
specifier: ^5.44.0
version: 5.44.0(eslint@8.42.0)(typescript@4.9.4)
chai:
specifier: ^4.3.6
version: 4.3.7
eslint:
specifier: ^8.28.0
version: 8.42.0
mocha:
specifier: ^9.0.3
version: 9.2.2
npm-run-all:
specifier: ^4.1.5
version: 4.1.5
prettier:
specifier: ^2.4.1
version: 2.7.1
prettier-plugin-organize-imports:
specifier: ^2.3.4
version: 2.3.4(prettier@2.7.1)(typescript@4.9.4)
shx:
specifier: ^0.3.4
version: 0.3.4
switchboard-solana:
specifier: workspace:*
version: link:../../rust/switchboard-solana
ts-mocha:
specifier: ^9.0.2
version: 9.0.2(mocha@9.2.2)
ts-node:
specifier: ^10.9.1
version: 10.9.1(@types/node@17.0.45)(typescript@4.9.4)
typescript:
specifier: ^4.9.3
version: 4.9.4
javascript/feed-walkthrough:
dependencies:
'@solana/web3.js':
@ -7139,7 +7224,7 @@ packages:
file:javascript/solana.js:
resolution: {directory: javascript/solana.js, type: directory}
name: '@switchboard-xyz/solana.js'
version: 2.3.0-beta.5
version: 2.3.0-beta.6
engines: {node: '>=16.0.0', npm: '>=7.0.0'}
dependencies:
'@coral-xyz/anchor': 0.27.0

View File

@ -91,25 +91,11 @@ dependencies = [
[[package]]
name = "anchor-attribute-access-control"
version = "0.26.0"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf7d535e1381be3de2c0716c0a1c1e32ad9df1042cddcf7bc18d743569e53319"
checksum = "faa5be5b72abea167f87c868379ba3c2be356bfca9e6f474fd055fa0f7eeb4f2"
dependencies = [
"anchor-syn 0.26.0",
"anyhow",
"proc-macro2 1.0.59",
"quote 1.0.28",
"regex",
"syn 1.0.109",
]
[[package]]
name = "anchor-attribute-access-control"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d5e1a413b311b039d29b61d0dbb401c9dbf04f792497ceca87593454bf6d7dd"
dependencies = [
"anchor-syn 0.27.0",
"anchor-syn",
"anyhow",
"proc-macro2 1.0.59",
"quote 1.0.28",
@ -119,28 +105,13 @@ dependencies = [
[[package]]
name = "anchor-attribute-account"
version = "0.26.0"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3bcd731f21048a032be27c7791701120e44f3f6371358fc4261a7f716283d29"
checksum = "f468970344c7c9f9d03b4da854fd7c54f21305059f53789d0045c1dd803f0018"
dependencies = [
"anchor-syn 0.26.0",
"anchor-syn",
"anyhow",
"bs58 0.4.0",
"proc-macro2 1.0.59",
"quote 1.0.28",
"rustversion",
"syn 1.0.109",
]
[[package]]
name = "anchor-attribute-account"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cca9aeaf633c6e2365fed0525dcac68610be58eee5dc69d3b86fe0b1d4b320b9"
dependencies = [
"anchor-syn 0.27.0",
"anyhow",
"bs58 0.4.0",
"bs58 0.5.0",
"proc-macro2 1.0.59",
"quote 1.0.28",
"rustversion",
@ -149,45 +120,22 @@ dependencies = [
[[package]]
name = "anchor-attribute-constant"
version = "0.26.0"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1be64a48e395fe00b8217287f226078be2cf32dae42fdf8a885b997945c3d28"
checksum = "59948e7f9ef8144c2aefb3f32a40c5fce2798baeec765ba038389e82301017ef"
dependencies = [
"anchor-syn 0.26.0",
"proc-macro2 1.0.59",
"syn 1.0.109",
]
[[package]]
name = "anchor-attribute-constant"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "788e44f9e8501dabeb6f9229da0f3268fb2ae3208912608ffaa056a72031296f"
dependencies = [
"anchor-syn 0.27.0",
"anchor-syn",
"proc-macro2 1.0.59",
"syn 1.0.109",
]
[[package]]
name = "anchor-attribute-error"
version = "0.26.0"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38ea6713d1938c0da03656ff8a693b17dc0396da66d1ba320557f07e86eca0d4"
checksum = "fc753c9d1c7981cb8948cf7e162fb0f64558999c0413058e2d43df1df5448086"
dependencies = [
"anchor-syn 0.26.0",
"proc-macro2 1.0.59",
"quote 1.0.28",
"syn 1.0.109",
]
[[package]]
name = "anchor-attribute-error"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea0c4d8c7e4a2605ede6fcdced9690288b2f74e24768619a85229d57e597bc97"
dependencies = [
"anchor-syn 0.27.0",
"anchor-syn",
"proc-macro2 1.0.59",
"quote 1.0.28",
"syn 1.0.109",
@ -195,51 +143,11 @@ dependencies = [
[[package]]
name = "anchor-attribute-event"
version = "0.26.0"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d401f11efb3644285685f8339829a9786d43ed7490bb1699f33c478d04d5a582"
checksum = "f38b4e172ba1b52078f53fdc9f11e3dc0668ad27997838a0aad2d148afac8c97"
dependencies = [
"anchor-syn 0.26.0",
"anyhow",
"proc-macro2 1.0.59",
"quote 1.0.28",
"syn 1.0.109",
]
[[package]]
name = "anchor-attribute-event"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a3b07d5c5d87b5edc72428b447b8e9ee1143b83dd1afc6a6b1d352c6a6164d8"
dependencies = [
"anchor-syn 0.27.0",
"anyhow",
"proc-macro2 1.0.59",
"quote 1.0.28",
"syn 1.0.109",
]
[[package]]
name = "anchor-attribute-interface"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6700a6f5c888a9c33fe8afc0c64fd8575fa28d05446037306d0f96102ae4480"
dependencies = [
"anchor-syn 0.26.0",
"anyhow",
"heck",
"proc-macro2 1.0.59",
"quote 1.0.28",
"syn 1.0.109",
]
[[package]]
name = "anchor-attribute-program"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ad769993b5266714e8939e47fbdede90e5c030333c7522d99a4d4748cf26712"
dependencies = [
"anchor-syn 0.26.0",
"anchor-syn",
"anyhow",
"proc-macro2 1.0.59",
"quote 1.0.28",
@ -248,54 +156,11 @@ dependencies = [
[[package]]
name = "anchor-attribute-program"
version = "0.27.0"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b22ad0445115dbea5869b1d062da49ae125abed9132fc20c33227f25e42dfa6b"
checksum = "4eebd21543606ab61e2d83d9da37d24d3886a49f390f9c43a1964735e8c0f0d5"
dependencies = [
"anchor-syn 0.27.0",
"anyhow",
"proc-macro2 1.0.59",
"quote 1.0.28",
"syn 1.0.109",
]
[[package]]
name = "anchor-attribute-state"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e677fae4a016a554acdd0e3b7f178d3acafaa7e7ffac6b8690cf4e171f1c116"
dependencies = [
"anchor-syn 0.26.0",
"anyhow",
"proc-macro2 1.0.59",
"quote 1.0.28",
"syn 1.0.109",
]
[[package]]
name = "anchor-client"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04c06e06497b5b4f392845e0d04dde8374fd244fa2832dd0e5c27bfd99cb0342"
dependencies = [
"anchor-lang 0.27.0",
"anyhow",
"regex",
"serde",
"solana-account-decoder",
"solana-client",
"solana-sdk",
"thiserror",
"url",
]
[[package]]
name = "anchor-derive-accounts"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "340beef6809d1c3fcc7ae219153d981e95a8a277ff31985bd7050e32645dc9a8"
dependencies = [
"anchor-syn 0.26.0",
"anchor-syn",
"anyhow",
"proc-macro2 1.0.59",
"quote 1.0.28",
@ -304,11 +169,11 @@ dependencies = [
[[package]]
name = "anchor-derive-accounts"
version = "0.27.0"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48daeff6781ba2f02961b0ad211feb9a2de75af345d42c62b1a252fd4dfb0724"
checksum = "ec4720d899b3686396cced9508f23dab420f1308344456ec78ef76f98fda42af"
dependencies = [
"anchor-syn 0.27.0",
"anchor-syn",
"anyhow",
"proc-macro2 1.0.59",
"quote 1.0.28",
@ -317,9 +182,9 @@ dependencies = [
[[package]]
name = "anchor-derive-space"
version = "0.27.0"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4fe2886f92c4f33ec1b2b8b2b43ca1b9070cf4929e63c7eaaa09a9f2c0d5123"
checksum = "f495e85480bd96ddeb77b71d499247c7d4e8b501e75ecb234e9ef7ae7bd6552a"
dependencies = [
"proc-macro2 1.0.59",
"quote 1.0.28",
@ -328,96 +193,55 @@ dependencies = [
[[package]]
name = "anchor-lang"
version = "0.26.0"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "662ceafe667448ee4199a4be2ee83b6bb76da28566eee5cea05f96ab38255af8"
checksum = "0d2d4b20100f1310a774aba3471ef268e5c4ba4d5c28c0bbe663c2658acbc414"
dependencies = [
"anchor-attribute-access-control 0.26.0",
"anchor-attribute-account 0.26.0",
"anchor-attribute-constant 0.26.0",
"anchor-attribute-error 0.26.0",
"anchor-attribute-event 0.26.0",
"anchor-attribute-interface",
"anchor-attribute-program 0.26.0",
"anchor-attribute-state",
"anchor-derive-accounts 0.26.0",
"arrayref",
"base64 0.13.1",
"bincode",
"borsh",
"bytemuck",
"solana-program",
"thiserror",
]
[[package]]
name = "anchor-lang"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbbe5d1c7c057c6d63b4f2f538a320e4a22111126c9966340c3d9490e2f15ed1"
dependencies = [
"anchor-attribute-access-control 0.27.0",
"anchor-attribute-account 0.27.0",
"anchor-attribute-constant 0.27.0",
"anchor-attribute-error 0.27.0",
"anchor-attribute-event 0.27.0",
"anchor-attribute-program 0.27.0",
"anchor-derive-accounts 0.27.0",
"anchor-attribute-access-control",
"anchor-attribute-account",
"anchor-attribute-constant",
"anchor-attribute-error",
"anchor-attribute-event",
"anchor-attribute-program",
"anchor-derive-accounts",
"anchor-derive-space",
"arrayref",
"base64 0.13.1",
"bincode",
"borsh",
"bytemuck",
"getrandom 0.2.9",
"solana-program",
"thiserror",
]
[[package]]
name = "anchor-spl"
version = "0.26.0"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f32390ce8356f54c0f0245ea156f8190717e37285b8bf4f406a613dc4b954cde"
checksum = "78f860599da1c2354e7234c768783049eb42e2f54509ecfc942d2e0076a2da7b"
dependencies = [
"anchor-lang 0.26.0",
"anchor-lang",
"solana-program",
"spl-associated-token-account",
"spl-token",
"spl-token-2022",
]
[[package]]
name = "anchor-syn"
version = "0.26.0"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0418bcb5daac3b8cb1b60d8fdb1d468ca36f5509f31fb51179326fae1028fdcc"
checksum = "a125e4b0cc046cfec58f5aa25038e34cf440151d58f0db3afc55308251fe936d"
dependencies = [
"anyhow",
"bs58 0.3.1",
"heck",
"proc-macro2 1.0.59",
"proc-macro2-diagnostics",
"quote 1.0.28",
"serde",
"serde_json",
"sha2 0.9.9",
"syn 1.0.109",
"thiserror",
]
[[package]]
name = "anchor-syn"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11cb31fe143aedb36fc41409ea072aa0b840cbea727e62eb2ff6e7b6cea036ff"
dependencies = [
"anyhow",
"bs58 0.3.1",
"bs58 0.5.0",
"heck",
"proc-macro2 1.0.59",
"quote 1.0.28",
"serde",
"serde_json",
"sha2 0.9.9",
"sha2 0.10.6",
"syn 1.0.109",
"thiserror",
]
@ -719,18 +543,21 @@ dependencies = [
"alloc-stdlib",
]
[[package]]
name = "bs58"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "476e9cd489f9e121e02ffa6014a8ef220ecb15c05ed23fc34cca13925dc283fb"
[[package]]
name = "bs58"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3"
[[package]]
name = "bs58"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5353f36341f7451062466f0b755b96ac3a9547e4d7f6b70d603fc721a7d7896"
dependencies = [
"tinyvec",
]
[[package]]
name = "bumpalo"
version = "3.13.0"
@ -2396,19 +2223,6 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "proc-macro2-diagnostics"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bf29726d67464d49fa6224a1d07936a8c08bb3fba727c7493f6cf1616fdaada"
dependencies = [
"proc-macro2 1.0.59",
"quote 1.0.28",
"syn 1.0.109",
"version_check",
"yansi",
]
[[package]]
name = "qstring"
version = "0.7.2"
@ -3785,9 +3599,9 @@ checksum = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f"
[[package]]
name = "switchboard-common"
version = "0.0.1"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3432650dcf9ba9f8512ecd2d2424dba1accd21a2f57019964f193087fda7b4"
checksum = "4e684527505239852153ac6b4b27789815441a2b840564466cb6e47b25f543b3"
dependencies = [
"getrandom 0.2.9",
"hex",
@ -3799,10 +3613,9 @@ dependencies = [
[[package]]
name = "switchboard-solana"
version = "0.0.1"
version = "0.3.1"
dependencies = [
"anchor-client",
"anchor-lang 0.26.0",
"anchor-lang",
"anchor-spl",
"bincode",
"bytemuck",
@ -3810,12 +3623,11 @@ dependencies = [
"cron",
"rust_decimal",
"sgx-quote",
"solana-client",
"solana-program",
"solana-sdk",
"superslice",
"switchboard-common",
"toml_datetime",
"toml_edit",
"winnow",
]
[[package]]
@ -4637,12 +4449,6 @@ dependencies = [
"linked-hash-map",
]
[[package]]
name = "yansi"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
[[package]]
name = "yasna"
version = "0.5.2"

View File

@ -1,6 +1,6 @@
[package]
name = "switchboard-solana"
version = "0.0.1"
version = "0.3.1"
edition = "2021"
description = "A Rust library to interact with Switchboard accounts."
readme = "README.md"
@ -21,7 +21,7 @@ no-entrypoint = []
cpi = ["no-entrypoint"]
client = [
"switchboard-common/sgx",
"dep:anchor-client",
"dep:solana-client",
"dep:bincode",
"dep:sgx-quote",
"dep:cron",
@ -29,19 +29,17 @@ client = [
]
[dependencies]
switchboard-common = { version = "0.0.1" }
rust_decimal = "1"
bytemuck = "1.13.1"
switchboard-common = { version = "0.1.1" }
rust_decimal = "^1"
bytemuck = "^1"
superslice = "1"
anchor-lang = "0.26.0"
anchor-spl = "0.26.0"
solana-program = ">= 1.13.5, < 1.15"
# These may not be needed, anchor27 keeps complaining
winnow = "=0.4.1"
toml_edit = "=0.19.8"
toml_datetime = "=0.6.1"
anchor-client = { version = "0.27.0", optional = true }
bincode = { version = "1.3.3", optional = true }
anchor-lang = "0.28.0"
anchor-spl = "0.28.0"
solana-program = ">= 1.14, < 1.17"
solana-sdk = ">= 1.14, < 1.17"
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 }

View File

@ -11,7 +11,7 @@ pub enum SwitchboardAttestationPermission {
PermitQueueUsage = 1 << 1,
}
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
#[derive(Debug)]
pub struct AttestationPermissionAccountData {
@ -108,13 +108,11 @@ impl AttestationPermissionAccountData {
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub async fn fetch(
client: &anchor_client::Client<
std::sync::Arc<anchor_client::solana_sdk::signer::keypair::Keypair>,
>,
client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await
}
}

View File

@ -5,7 +5,7 @@ use std::cell::Ref;
use crate::SWITCHBOARD_ATTESTATION_PROGRAM_ID;
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
#[derive(Debug)]
pub struct AttestationQueueAccountData {
@ -115,10 +115,9 @@ impl AttestationQueueAccountData {
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub async fn fetch(
client: &anchor_client::Client<
std::sync::Arc<anchor_client::solana_sdk::signer::keypair::Keypair>,
>,
client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await

View File

@ -4,7 +4,7 @@ use bytemuck::{Pod, Zeroable};
use crate::SWITCHBOARD_ATTESTATION_PROGRAM_ID;
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
#[derive(Debug)]
pub struct AttestationState {

View File

@ -15,18 +15,16 @@ pub enum FunctionStatus {
InvalidPermissions = 1 << 4,
}
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
#[derive(Debug, PartialEq)]
pub struct FunctionAccountData {
pub name: [u8; 64],
pub metadata: [u8; 256],
pub authority: Pubkey,
///
pub container_registry: [u8; 64],
pub container: [u8; 64],
pub version: [u8; 32],
///
pub attestation_queue: Pubkey,
pub queue_idx: u32,
pub last_execution_timestamp: i64,
@ -164,6 +162,7 @@ impl FunctionAccountData {
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub fn get_schedule(&self) -> Option<cron::Schedule> {
if self.schedule[0] == 0 {
return None;
@ -177,6 +176,7 @@ impl FunctionAccountData {
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub fn get_last_execution_datetime(&self) -> chrono::DateTime<chrono::Utc> {
chrono::DateTime::from_utc(
chrono::NaiveDateTime::from_timestamp_opt(self.last_execution_timestamp, 0).unwrap(),
@ -185,6 +185,7 @@ impl FunctionAccountData {
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub fn should_execute(&self, now: chrono::DateTime<chrono::Utc>) -> bool {
let schedule = self.get_schedule();
if schedule.is_none() {
@ -203,6 +204,7 @@ impl FunctionAccountData {
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub fn next_execution_timestamp(&self) -> Option<chrono::DateTime<chrono::Utc>> {
let schedule = self.get_schedule();
if schedule.is_none() {
@ -213,10 +215,9 @@ impl FunctionAccountData {
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub async fn fetch(
client: &anchor_client::Client<
std::sync::Arc<anchor_client::solana_sdk::signer::keypair::Keypair>,
>,
client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await

View File

@ -3,7 +3,7 @@ use anchor_lang::{Discriminator, Owner, ZeroCopy};
use bytemuck::{Pod, Zeroable};
use std::cell::Ref;
use crate::{SwitchboardError, QUOTE_SEED, SWITCHBOARD_ATTESTATION_PROGRAM_ID};
use crate::{QUOTE_SEED, SWITCHBOARD_ATTESTATION_PROGRAM_ID};
#[repr(u8)]
#[derive(Copy, Clone, Eq, PartialEq)]
@ -15,7 +15,7 @@ pub enum VerificationStatus {
VerificationOverride = 1 << 3,
}
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
#[derive(Debug)]
pub struct QuoteAccountData {
@ -147,10 +147,9 @@ impl QuoteAccountData {
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub async fn fetch(
client: &anchor_client::Client<
std::sync::Arc<anchor_client::solana_sdk::signer::keypair::Keypair>,
>,
client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await

View File

@ -3,7 +3,6 @@ use anchor_lang::solana_program::entrypoint::ProgramResult;
use anchor_lang::solana_program::instruction::Instruction;
use anchor_lang::solana_program::program::{invoke, invoke_signed};
use anchor_lang::{Discriminator, InstructionData};
use anchor_spl::token::TokenAccount;
#[derive(Accounts)]
#[instruction(params: FunctionTriggerParams)] // rpc parameters hint

View File

@ -202,11 +202,10 @@ impl<'info> FunctionVerify<'info> {
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub async fn build(
client: &anchor_client::Client<
std::sync::Arc<anchor_client::solana_sdk::signer::keypair::Keypair>,
>,
fn_signer: std::sync::Arc<anchor_client::solana_sdk::signer::keypair::Keypair>,
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> {
@ -285,6 +284,7 @@ impl<'info> FunctionVerify<'info> {
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
fn build_ix(
accounts: FunctionVerifyAccounts,
observed_time: i64,
@ -307,6 +307,7 @@ impl<'info> FunctionVerify<'info> {
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub struct FunctionVerifyAccounts {
pub function: Pubkey,
pub fn_signer: Pubkey,
@ -324,6 +325,7 @@ pub struct FunctionVerifyAccounts {
pub system_program: Pubkey,
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
impl ToAccountMetas for FunctionVerifyAccounts {
fn to_account_metas(&self, _: Option<bool>) -> Vec<AccountMeta> {
vec![

View File

@ -1,6 +1,5 @@
use crate::SWITCHBOARD_ATTESTATION_PROGRAM_ID;
use anchor_client::solana_sdk::signer::keypair::Keypair;
use anchor_lang::prelude::*;
use solana_sdk::signer::keypair::Keypair;
use std::result::Result;
use std::str::FromStr;
use std::sync::Arc;
@ -13,14 +12,11 @@ pub fn to_pubkey(signer: Arc<Keypair>) -> std::result::Result<Pubkey, switchboar
}
pub async fn load_account<T: bytemuck::Pod>(
client: &anchor_client::Client<Arc<Keypair>>,
client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey,
) -> Result<T, switchboard_common::Error> {
let data = client
.program(SWITCHBOARD_ATTESTATION_PROGRAM_ID)
.async_rpc()
.get_account_data(&pubkey)
.await
.map_err(|_| switchboard_common::Error::CustomMessage("AnchorParseError".to_string()))?;
Ok(*bytemuck::try_from_bytes::<T>(&data[8..])
.map_err(|_| switchboard_common::Error::CustomMessage("AnchorParseError".to_string()))?)

View File

@ -1,5 +1,4 @@
#![allow(clippy::result_large_err)]
use anchor_lang::prelude::*;
use anchor_lang::solana_program::pubkey;
@ -9,14 +8,30 @@ 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;
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
#[cfg(not(target_os = "solana"))]
pub mod client;
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
#[cfg(not(target_os = "solana"))]
pub use client::*;
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
#[cfg(not(target_os = "solana"))]
pub mod sgx;
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
#[cfg(not(target_os = "solana"))]
pub use sgx::*;
/// Seed used to derive the SbState PDA.

View File

@ -0,0 +1,30 @@
macro_rules! cfg_solana {
($($item:item)*) => {
$(
#[cfg(target_os = "solana")]
$item
)*
}
}
macro_rules! cfg_not_solana {
($($item:item)*) => {
$( #[cfg(not(target_os = "solana"))] $item )*
}
}
macro_rules! cfg_client {
($($item:item)*) => {
$(
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
$item
)*
}
}
macro_rules! cfg_not_client {
($($item:item)*) => {
$( #[cfg(not(feature = "client"))] $item )*
}
}

View File

@ -3,7 +3,7 @@ use anchor_lang::Discriminator;
use rust_decimal::Decimal;
use std::cell::Ref;
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
#[derive(Default, Debug, PartialEq, Eq)]
pub struct Hash {
@ -11,7 +11,7 @@ pub struct Hash {
pub data: [u8; 32],
}
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
#[derive(Default, Debug, PartialEq, Eq)]
pub struct AggregatorRound {
@ -53,8 +53,8 @@ pub enum AggregatorResolutionMode {
ModeSlidingResolution = 1,
}
// #[zero_copy]
#[account(zero_copy)]
// #[zero_copy(unsafe)]
#[account(zero_copy(unsafe))]
#[repr(packed)]
#[derive(Debug, PartialEq)]
pub struct AggregatorAccountData {
@ -280,10 +280,9 @@ impl AggregatorAccountData {
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub async fn fetch(
client: &anchor_client::Client<
std::sync::Arc<anchor_client::solana_sdk::signer::keypair::Keypair>,
>,
client: &solana_client::rpc_client::RpcClient,
pubkey: Pubkey,
) -> std::result::Result<Self, switchboard_common::Error> {
crate::client::load_account(client, pubkey).await

View File

@ -1,3 +1,4 @@
#![allow(unaligned_references)]
use crate::*;
use anchor_lang::{Discriminator, Owner};
@ -27,7 +28,7 @@ pub struct BufferRelayerAccountData {
pub result: Vec<u8>,
}
#[zero_copy]
#[zero_copy(unsafe)]
#[derive(Default, Debug, AnchorSerialize, AnchorDeserialize)]
pub struct BufferRelayerRound {
/// Number of successful responses.

View File

@ -1,7 +1,7 @@
use anchor_lang::prelude::*;
use bytemuck::{Pod, Zeroable};
#[zero_copy]
#[zero_copy(unsafe)]
#[derive(Default)]
#[repr(packed)]
pub struct CrankRow {
@ -13,7 +13,7 @@ pub struct CrankRow {
unsafe impl Pod for CrankRow {}
unsafe impl Zeroable for CrankRow {}
#[account(zero_copy)]
#[account(zero_copy(unsafe))]
#[repr(packed)]
pub struct CrankAccountData {
/// Name of the crank to store on-chain.

View File

@ -5,7 +5,7 @@ use rust_decimal::prelude::{FromPrimitive, ToPrimitive};
use rust_decimal::Decimal;
use std::convert::{From, TryInto};
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
#[derive(Default, Debug, Eq, PartialEq)]
pub struct SwitchboardDecimal {

View File

@ -2,7 +2,7 @@
use anchor_lang::prelude::*;
use bytemuck::{Pod, Zeroable};
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct AccountMetaZC {
pub pubkey: Pubkey,
@ -10,7 +10,7 @@ pub struct AccountMetaZC {
pub is_writable: bool,
}
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
#[derive(AnchorSerialize, AnchorDeserialize)]
pub struct AccountMetaBorsh {
@ -19,7 +19,7 @@ pub struct AccountMetaBorsh {
pub is_writable: bool,
}
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct CallbackZC {
/// The program ID of the callback program being invoked.
@ -49,7 +49,7 @@ pub struct Callback {
pub ix_data: Vec<u8>,
}
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct VrfRound {
/// The alpha bytes used to calculate the VRF proof.
@ -101,7 +101,7 @@ impl std::fmt::Display for VrfStatus {
}
}
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct EcvrfProofZC {
pub Gamma: EdwardsPointZC, // RistrettoPoint
@ -117,7 +117,7 @@ impl Default for EcvrfProofZC {
/// The `Scalar` struct holds an integer \\(s < 2\^{255} \\) which
/// represents an element of \\(\mathbb Z / \ell\\).
#[allow(dead_code)]
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct Scalar {
/// `bytes` is a little-endian byte encoding of an integer representing a scalar modulo the
@ -158,7 +158,7 @@ pub struct FieldElement51(pub(crate) [u64; 5]);
unsafe impl Pod for FieldElement51 {}
unsafe impl Zeroable for FieldElement51 {}
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct FieldElementZC {
pub(crate) bytes: [u64; 5],
@ -197,7 +197,7 @@ pub struct CompletedPoint {
pub Z: FieldElement51,
pub T: FieldElement51,
}
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct CompletedPointZC {
pub X: FieldElementZC,
@ -243,7 +243,7 @@ pub struct EdwardsPoint {
pub(crate) T: FieldElement51,
}
#[allow(dead_code)]
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct EdwardsPointZC {
pub(crate) X: FieldElementZC,
@ -271,7 +271,7 @@ pub struct ProjectivePoint {
pub Y: FieldElement51,
pub Z: FieldElement51,
}
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct ProjectivePointZC {
pub(crate) X: FieldElementZC,
@ -304,7 +304,7 @@ impl Into<ProjectivePoint> for ProjectivePointZC {
}
}
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct EcvrfIntermediate {
pub r: FieldElementZC,
@ -317,7 +317,7 @@ unsafe impl Pod for EcvrfIntermediate {}
unsafe impl Zeroable for EcvrfIntermediate {}
#[allow(non_snake_case)]
#[zero_copy]
#[zero_copy(unsafe)]
#[repr(packed)]
pub struct VrfBuilder {
/// The OracleAccountData that is producing the randomness.

View File

@ -6,7 +6,7 @@ use bytemuck::{Pod, Zeroable};
use std::cell::Ref;
use superslice::*;
#[zero_copy]
#[zero_copy(unsafe)]
#[derive(Default)]
#[repr(packed)]
pub struct AggregatorHistoryRow {

View File

@ -1,6 +1,6 @@
use anchor_lang::prelude::*;
#[account(zero_copy)]
#[account(zero_copy(unsafe))]
#[repr(packed)]
pub struct LeaseAccountData {
/// Public key of the token account holding the lease contract funds until rewarded to oracles for successfully processing updates

View File

@ -1,4 +1,6 @@
use anchor_lang::prelude::*;
use crate::*;
use anchor_lang::Discriminator;
use std::cell::Ref;
#[derive(Copy, Clone, AnchorSerialize, AnchorDeserialize)]
pub enum OracleResponseType {
@ -7,7 +9,8 @@ pub enum OracleResponseType {
TypeDisagreement,
TypeNoResponse,
}
#[zero_copy]
#[zero_copy(unsafe)]
#[derive(Default)]
#[repr(packed)]
pub struct OracleMetrics {
@ -31,7 +34,7 @@ pub struct OracleMetrics {
pub total_late_response: u128,
}
#[account(zero_copy)]
#[account(zero_copy(unsafe))]
#[repr(packed)]
pub struct OracleAccountData {
/// Name of the oracle to store on-chain.
@ -57,4 +60,74 @@ pub struct OracleAccountData {
pub _ebuf: [u8; 255],
}
impl OracleAccountData {}
impl OracleAccountData {
/// Returns the deserialized Switchboard Oracle account
///
/// # Arguments
///
/// * `account_info` - A Solana AccountInfo referencing an existing Switchboard Oracle
///
/// # Examples
///
/// ```ignore
/// use switchboard_solana::OracleAccountData;
///
/// let oracle = OracleAccountData::new(oracle_account_info)?;
/// ```
pub fn new<'info>(
account_info: &'info AccountInfo<'info>,
) -> anchor_lang::Result<Ref<'info, Self>> {
let data = account_info.try_borrow_data()?;
if data.len() < OracleAccountData::discriminator().len() {
return Err(ErrorCode::AccountDiscriminatorNotFound.into());
}
let mut disc_bytes = [0u8; 8];
disc_bytes.copy_from_slice(&data[..8]);
if disc_bytes != OracleAccountData::discriminator() {
return Err(ErrorCode::AccountDiscriminatorMismatch.into());
}
Ok(Ref::map(data, |data| {
bytemuck::from_bytes(&data[8..std::mem::size_of::<OracleAccountData>() + 8])
}))
}
/// Returns the deserialized Switchboard Oracle account
///
/// # Arguments
///
/// * `data` - A Solana AccountInfo's data buffer
///
/// # Examples
///
/// ```ignore
/// use switchboard_solana::OracleAccountData;
///
/// let oracle = OracleAccountData::new(oracle_account_info.try_borrow_data()?)?;
/// ```
pub fn new_from_bytes(data: &[u8]) -> anchor_lang::Result<&OracleAccountData> {
if data.len() < OracleAccountData::discriminator().len() {
return Err(ErrorCode::AccountDiscriminatorNotFound.into());
}
let mut disc_bytes = [0u8; 8];
disc_bytes.copy_from_slice(&data[..8]);
if disc_bytes != OracleAccountData::discriminator() {
return Err(ErrorCode::AccountDiscriminatorMismatch.into());
}
Ok(bytemuck::from_bytes(
&data[8..std::mem::size_of::<OracleAccountData>() + 8],
))
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, 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
}
}

View File

@ -10,7 +10,7 @@ pub enum SwitchboardPermission {
PermitVrfRequests = 1 << 2,
}
#[account(zero_copy)]
#[account(zero_copy(unsafe))]
#[repr(packed)]
pub struct PermissionAccountData {
/// The authority that is allowed to set permissions for this account.

View File

@ -1,8 +1,9 @@
use super::decimal::SwitchboardDecimal;
use anchor_lang::prelude::*;
use crate::*;
use anchor_lang::Discriminator;
use bytemuck::try_cast_slice_mut;
use std::cell::Ref;
#[account(zero_copy)]
#[account(zero_copy(unsafe))]
#[repr(packed)]
pub struct OracleQueueAccountData {
/// Name of the queue to store on-chain.
@ -57,6 +58,12 @@ pub struct OracleQueueAccountData {
pub data_buffer: Pubkey,
}
impl Default for OracleQueueAccountData {
fn default() -> Self {
unsafe { std::mem::zeroed() }
}
}
impl OracleQueueAccountData {
pub fn size() -> usize {
std::mem::size_of::<OracleQueueAccountData>() + 8
@ -86,9 +93,74 @@ impl OracleQueueAccountData {
.checked_mul(batch_size.checked_add(1).unwrap().into())
.unwrap()
}
}
impl Default for OracleQueueAccountData {
fn default() -> Self {
unsafe { std::mem::zeroed() }
/// Returns the deserialized Switchboard OracleQueue account
///
/// # Arguments
///
/// * `account_info` - A Solana AccountInfo referencing an existing Switchboard OracleQueue
///
/// # Examples
///
/// ```ignore
/// use switchboard_solana::OracleQueueAccountData;
///
/// let oracle_queue = OracleQueueAccountData::new(queue_account_info)?;
/// ```
pub fn new<'info>(
account_info: &'info AccountInfo<'info>,
) -> anchor_lang::Result<Ref<'info, Self>> {
let data = account_info.try_borrow_data()?;
if data.len() < OracleQueueAccountData::discriminator().len() {
return Err(ErrorCode::AccountDiscriminatorNotFound.into());
}
let mut disc_bytes = [0u8; 8];
disc_bytes.copy_from_slice(&data[..8]);
if disc_bytes != OracleQueueAccountData::discriminator() {
return Err(ErrorCode::AccountDiscriminatorMismatch.into());
}
Ok(Ref::map(data, |data| {
bytemuck::from_bytes(&data[8..std::mem::size_of::<OracleQueueAccountData>() + 8])
}))
}
/// Returns the deserialized Switchboard OracleQueue account
///
/// # Arguments
///
/// * `data` - A Solana AccountInfo's data buffer
///
/// # Examples
///
/// ```ignore
/// use switchboard_solana::OracleQueueAccountData;
///
/// let oracle_queue = OracleQueueAccountData::new(oracle_account_info.try_borrow_data()?)?;
/// ```
pub fn new_from_bytes(data: &[u8]) -> anchor_lang::Result<&OracleQueueAccountData> {
if data.len() < OracleQueueAccountData::discriminator().len() {
return Err(ErrorCode::AccountDiscriminatorNotFound.into());
}
let mut disc_bytes = [0u8; 8];
disc_bytes.copy_from_slice(&data[..8]);
if disc_bytes != OracleQueueAccountData::discriminator() {
return Err(ErrorCode::AccountDiscriminatorMismatch.into());
}
Ok(bytemuck::from_bytes(
&data[8..std::mem::size_of::<OracleQueueAccountData>() + 8],
))
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, 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
}
}

View File

@ -1,6 +1,6 @@
use anchor_lang::prelude::*;
#[account(zero_copy)]
#[account(zero_copy(unsafe))]
#[repr(packed)]
pub struct SbState {
/// The account authority permitted to make account changes.

View File

@ -1,6 +1,6 @@
use crate::*;
#[zero_copy]
#[zero_copy(unsafe)]
#[derive(Default)]
#[repr(packed)]
pub struct SlidingWindowElement {
@ -10,7 +10,7 @@ pub struct SlidingWindowElement {
pub timestamp: i64,
}
#[account(zero_copy)]
#[account(zero_copy(unsafe))]
#[repr(packed)]
pub struct SlidingResultAccountData {
pub data: [SlidingWindowElement; 16],

View File

@ -8,7 +8,7 @@ use std::cell::Ref;
// VrfSetCallback
// VrfClose
#[account(zero_copy)]
#[account(zero_copy(unsafe))]
#[repr(packed)]
pub struct VrfAccountData {
/// The current status of the VRF account.
@ -122,4 +122,13 @@ impl VrfAccountData {
}
Ok(self.current_round.result)
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, 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
}
}

View File

@ -3,7 +3,7 @@ use crate::*;
use anchor_lang::Discriminator;
use std::cell::Ref;
#[account(zero_copy)]
#[account(zero_copy(unsafe))]
#[repr(packed)]
pub struct VrfLiteAccountData {
/// The bump used to derive the SbState account.
@ -132,4 +132,13 @@ impl VrfLiteAccountData {
}
Ok(self.result)
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, 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
}
}

View File

@ -14,7 +14,7 @@ pub struct VrfPoolRow {
}
#[repr(packed)]
#[account(zero_copy)]
#[account(zero_copy(unsafe))]
pub struct VrfPoolAccountData {
/// ACCOUNTS
pub authority: Pubkey, // authority can never be changed or else vrf accounts are useless
@ -95,6 +95,15 @@ impl VrfPoolAccountData {
&data[8..std::mem::size_of::<VrfPoolAccountData>() + 8],
))
}
#[cfg(feature = "client")]
#[cfg_attr(docsrs, 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
}
}
// impl Discriminator for VrfPoolAccountData {

View File

@ -1,21 +1,14 @@
pub use anchor_client;
use anchor_client::solana_sdk::commitment_config::CommitmentConfig;
use anchor_client::solana_sdk::signer::keypair::{keypair_from_seed, Keypair};
use anchor_client::solana_sdk::transaction::Transaction;
use anchor_client::Cluster;
use anchor_lang::solana_program::instruction::Instruction;
use anchor_lang::solana_program::message::Message;
use anchor_lang::solana_program::pubkey::Pubkey;
use sgx_quote::Quote;
use solana_sdk::signer::keypair::{keypair_from_seed, Keypair};
use std::env;
use std::result::Result;
use std::str::FromStr;
use std::sync::Arc;
use switchboard_common::{Error, FunctionResult, Gramine};
// use crate::{FunctionVerify, SWITCHBOARD_ATTESTATION_PROGRAM_ID};
use crate::attestation_program::FunctionVerify;
use crate::{QUOTE_SEED, SWITCHBOARD_ATTESTATION_PROGRAM_ID};
@ -26,15 +19,15 @@ pub fn generate_signer() -> Arc<Keypair> {
}
pub async fn function_verify(
url: String,
fn_signer: Arc<Keypair>,
mut ixs: Vec<Instruction>,
) -> Result<FunctionResult, Error> {
let fn_signer_pubkey = crate::client::to_pubkey(fn_signer.clone())?;
let client = anchor_client::Client::new_with_options(
Cluster::Devnet,
fn_signer.to_owned(),
CommitmentConfig::processed(),
let client = solana_client::rpc_client::RpcClient::new_with_commitment(
url,
solana_sdk::commitment_config::CommitmentConfig::processed(),
);
let quote_raw = Gramine::generate_quote(&fn_signer_pubkey.to_bytes()).unwrap();
@ -54,13 +47,9 @@ pub async fn function_verify(
let message = Message::new(&ixs, Some(&pubkeys.payer));
let blockhash = client
.program(SWITCHBOARD_ATTESTATION_PROGRAM_ID)
.rpc()
.get_latest_blockhash()
.unwrap();
let blockhash = client.get_latest_blockhash().unwrap();
let mut tx = Transaction::new_unsigned(message);
let mut tx = solana_sdk::transaction::Transaction::new_unsigned(message);
tx.partial_sign(&[fn_signer.as_ref()], blockhash);
Ok(FunctionResult {