Skip to content

Commit

Permalink
sdk updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gallynaut committed Jul 5, 2023
1 parent 5149b1d commit 672acf6
Show file tree
Hide file tree
Showing 13 changed files with 300 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface FunctionRequestAccountDataFields {
function: PublicKey;
/** The tokenAccount escrow */
escrow: PublicKey;
/** The Attestation Queue for this request. */
attestationQueue: PublicKey;
/** The current active request. */
activeRequest: types.FunctionRequestTriggerRoundFields;
/** The previous request. */
Expand Down Expand Up @@ -52,6 +54,8 @@ export interface FunctionRequestAccountDataJSON {
function: string;
/** The tokenAccount escrow */
escrow: string;
/** The Attestation Queue for this request. */
attestationQueue: string;
/** The current active request. */
activeRequest: types.FunctionRequestTriggerRoundJSON;
/** The previous request. */
Expand Down Expand Up @@ -86,6 +90,8 @@ export class FunctionRequestAccountData {
readonly function: PublicKey;
/** The tokenAccount escrow */
readonly escrow: PublicKey;
/** The Attestation Queue for this request. */
readonly attestationQueue: PublicKey;
/** The current active request. */
readonly activeRequest: types.FunctionRequestTriggerRound;
/** The previous request. */
Expand Down Expand Up @@ -117,6 +123,7 @@ export class FunctionRequestAccountData {
borsh.publicKey("payer"),
borsh.publicKey("function"),
borsh.publicKey("escrow"),
borsh.publicKey("attestationQueue"),
types.FunctionRequestTriggerRound.layout("activeRequest"),
types.FunctionRequestTriggerRound.layout("previousRequest"),
borsh.u32("maxContainerParamsLen"),
Expand All @@ -134,6 +141,7 @@ export class FunctionRequestAccountData {
this.payer = fields.payer;
this.function = fields.function;
this.escrow = fields.escrow;
this.attestationQueue = fields.attestationQueue;
this.activeRequest = new types.FunctionRequestTriggerRound({
...fields.activeRequest,
});
Expand Down Expand Up @@ -196,6 +204,7 @@ export class FunctionRequestAccountData {
payer: dec.payer,
function: dec.function,
escrow: dec.escrow,
attestationQueue: dec.attestationQueue,
activeRequest: types.FunctionRequestTriggerRound.fromDecoded(
dec.activeRequest
),
Expand Down Expand Up @@ -223,6 +232,7 @@ export class FunctionRequestAccountData {
payer: this.payer.toString(),
function: this.function.toString(),
escrow: this.escrow.toString(),
attestationQueue: this.attestationQueue.toString(),
activeRequest: this.activeRequest.toJSON(),
previousRequest: this.previousRequest.toJSON(),
maxContainerParamsLen: this.maxContainerParamsLen,
Expand All @@ -246,6 +256,7 @@ export class FunctionRequestAccountData {
payer: new PublicKey(obj.payer),
function: new PublicKey(obj.function),
escrow: new PublicKey(obj.escrow),
attestationQueue: new PublicKey(obj.attestationQueue),
activeRequest: types.FunctionRequestTriggerRound.fromJSON(
obj.activeRequest
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { PublicKey } from "@solana/web3.js";

// Program ID defined in the provided IDL. Do not edit, it will get overwritten.
export const PROGRAM_ID_IDL = new PublicKey(
"sbattyXrzedoNATfc4L31wC9Mhxsi1BmFhTiN8gDshx"
);

// Program ID passed with the cli --program-id flag when running the code generator. Do not edit, it will get overwritten.
export const PROGRAM_ID_CLI = new PublicKey(
"sbattyXrzedoNATfc4L31wC9Mhxsi1BmFhTiN8gDshx"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { PublicKey } from "@solana/web3.js";

// Program ID defined in the provided IDL. Do not edit, it will get overwritten.
export const PROGRAM_ID_IDL = new PublicKey(
"SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"
);

// Program ID passed with the cli --program-id flag when running the code generator. Do not edit, it will get overwritten.
export const PROGRAM_ID_CLI = new PublicKey(
"SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"
Expand Down
2 changes: 1 addition & 1 deletion rust/switchboard-solana/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/switchboard-solana/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "switchboard-solana"
version = "0.7.0"
version = "0.8.1"
edition = "2021"
description = "A Rust library to interact with Switchboard accounts."
readme = "README.md"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl From<u32> for SwitchboardAttestationPermission {

#[zero_copy(unsafe)]
#[repr(packed)]
#[derive(Debug)]
#[derive(Debug, AnchorDeserialize)]
pub struct AttestationPermissionAccountData {
pub authority: Pubkey,
pub permissions: u32,
Expand All @@ -44,6 +44,40 @@ pub struct AttestationPermissionAccountData {
pub _ebuf: [u8; 256],
}

impl anchor_lang::AccountDeserialize for AttestationPermissionAccountData {
fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
if buf.len() < AttestationPermissionAccountData::discriminator().len() {
return Err(anchor_lang::error::ErrorCode::AccountDiscriminatorNotFound.into());
}
let given_disc = &buf[..8];
if AttestationPermissionAccountData::discriminator() != given_disc {
return Err(
anchor_lang::error::Error::from(anchor_lang::error::AnchorError {
error_name: anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch.name(),
error_code_number: anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
.into(),
error_msg: anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
.to_string(),
error_origin: Some(anchor_lang::error::ErrorOrigin::Source(
anchor_lang::error::Source {
filename: "programs/attestation_program/src/lib.rs",
line: 1u32,
},
)),
compared_values: None,
})
.with_account_name("AttestationPermissionAccountData"),
);
}
Self::try_deserialize_unchecked(buf)
}
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let mut data: &[u8] = &buf[8..];
AnchorDeserialize::deserialize(&mut data)
.map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotDeserialize.into())
}
}

unsafe impl Pod for AttestationPermissionAccountData {}
unsafe impl Zeroable for AttestationPermissionAccountData {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::SWITCHBOARD_ATTESTATION_PROGRAM_ID;

#[zero_copy(unsafe)]
#[repr(packed)]
#[derive(Debug, AnchorDeserialize)]
pub struct AttestationQueueAccountData {
/// The address of the authority which is permitted to add/remove allowed enclave measurements.
pub authority: Pubkey,
Expand Down Expand Up @@ -47,6 +48,40 @@ pub struct AttestationQueueAccountData {
pub _ebuf: [u8; 1008],
}

impl anchor_lang::AccountDeserialize for AttestationQueueAccountData {
fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
if buf.len() < AttestationQueueAccountData::discriminator().len() {
return Err(anchor_lang::error::ErrorCode::AccountDiscriminatorNotFound.into());
}
let given_disc = &buf[..8];
if AttestationQueueAccountData::discriminator() != given_disc {
return Err(
anchor_lang::error::Error::from(anchor_lang::error::AnchorError {
error_name: anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch.name(),
error_code_number: anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
.into(),
error_msg: anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
.to_string(),
error_origin: Some(anchor_lang::error::ErrorOrigin::Source(
anchor_lang::error::Source {
filename: "programs/attestation_program/src/lib.rs",
line: 1u32,
},
)),
compared_values: None,
})
.with_account_name("AttestationQueueAccountData"),
);
}
Self::try_deserialize_unchecked(buf)
}
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let mut data: &[u8] = &buf[8..];
AnchorDeserialize::deserialize(&mut data)
.map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotDeserialize.into())
}
}

unsafe impl Pod for AttestationQueueAccountData {}
unsafe impl Zeroable for AttestationQueueAccountData {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,46 @@ use crate::SWITCHBOARD_ATTESTATION_PROGRAM_ID;

#[zero_copy(unsafe)]
#[repr(packed)]
#[derive(Debug)]
#[derive(Debug, AnchorDeserialize)]
pub struct AttestationProgramState {
pub bump: u8,
pub _ebuf: [u8; 2048],
}

impl anchor_lang::AccountDeserialize for AttestationProgramState {
fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
if buf.len() < AttestationProgramState::discriminator().len() {
return Err(anchor_lang::error::ErrorCode::AccountDiscriminatorNotFound.into());
}
let given_disc = &buf[..8];
if AttestationProgramState::discriminator() != given_disc {
return Err(
anchor_lang::error::Error::from(anchor_lang::error::AnchorError {
error_name: anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch.name(),
error_code_number: anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
.into(),
error_msg: anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
.to_string(),
error_origin: Some(anchor_lang::error::ErrorOrigin::Source(
anchor_lang::error::Source {
filename: "programs/attestation_program/src/lib.rs",
line: 1u32,
},
)),
compared_values: None,
})
.with_account_name("AttestationProgramState"),
);
}
Self::try_deserialize_unchecked(buf)
}
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let mut data: &[u8] = &buf[8..];
AnchorDeserialize::deserialize(&mut data)
.map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotDeserialize.into())
}
}

unsafe impl Pod for AttestationProgramState {}
unsafe impl Zeroable for AttestationProgramState {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl From<u8> for VerificationStatus {

#[zero_copy(unsafe)]
#[repr(packed)]
#[derive(Debug)]
#[derive(Debug, AnchorDeserialize)]
pub struct EnclaveAccountData {
/// The address of the signer generated within an enclave.
pub enclave_signer: Pubkey,
Expand Down Expand Up @@ -87,6 +87,40 @@ pub struct EnclaveAccountData {
pub _ebuf: [u8; 928],
}

impl anchor_lang::AccountDeserialize for EnclaveAccountData {
fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
if buf.len() < EnclaveAccountData::discriminator().len() {
return Err(anchor_lang::error::ErrorCode::AccountDiscriminatorNotFound.into());
}
let given_disc = &buf[..8];
if EnclaveAccountData::discriminator() != given_disc {
return Err(
anchor_lang::error::Error::from(anchor_lang::error::AnchorError {
error_name: anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch.name(),
error_code_number: anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
.into(),
error_msg: anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
.to_string(),
error_origin: Some(anchor_lang::error::ErrorOrigin::Source(
anchor_lang::error::Source {
filename: "programs/attestation_program/src/lib.rs",
line: 1u32,
},
)),
compared_values: None,
})
.with_account_name("EnclaveAccountData"),
);
}
Self::try_deserialize_unchecked(buf)
}
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let mut data: &[u8] = &buf[8..];
AnchorDeserialize::deserialize(&mut data)
.map_err(|_| anchor_lang::error::ErrorCode::AccountDidNotDeserialize.into())
}
}

unsafe impl Pod for EnclaveAccountData {}
unsafe impl Zeroable for EnclaveAccountData {}

Expand Down
Loading

0 comments on commit 672acf6

Please sign in to comment.