Move minimum amount of types to skeleton initialize

Change-Id: Ibfc5767de20802035a9403cd937005bdb7ab96cc
This commit is contained in:
Reisen 2021-04-27 14:34:10 +00:00
parent 888c461d73
commit a05091897f
4 changed files with 49 additions and 12 deletions

View File

@ -1,4 +1,6 @@
pub mod initialize;
pub mod verify_signatures; pub mod verify_signatures;
// Re-expose underlying module functions and data, for consuming APIs to use. // Re-expose underlying module functions and data, for consuming APIs to use.
pub use initialize::*;
pub use verify_signatures::*; pub use verify_signatures::*;

View File

@ -0,0 +1,6 @@
use crate::{accounts, Initialize, InitializeData};
use anchor_lang::{prelude::*, solana_program};
pub fn initialize(ctx: Context<Initialize>, data: InitializeData) -> ProgramResult {
Ok(())
}

View File

@ -2,9 +2,10 @@ use anchor_lang::{prelude::*, solana_program};
mod account; mod account;
mod api; mod api;
mod types;
use account::BridgeInfo; use account::{BridgeInfo, GuardianSetInfo};
use account::GuardianSetInfo; use types::BridgeConfig;
/// An enum with labeled network identifiers. These must be consistent accross all wormhole /// An enum with labeled network identifiers. These must be consistent accross all wormhole
/// contracts deployed on each chain. /// contracts deployed on each chain.
@ -18,16 +19,6 @@ pub const CHAIN_ID_SOLANA: u8 = Chain::Solana as u8;
/// maximum number of guardians /// maximum number of guardians
pub const MAX_LEN_GUARDIAN_KEYS: usize = 20; pub const MAX_LEN_GUARDIAN_KEYS: usize = 20;
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug)]
pub struct VerifySigsData {
/// hash of the VAA
pub hash: [u8; 32],
/// instruction indices of signers (-1 for missing)
pub signers: [i8; MAX_LEN_GUARDIAN_KEYS],
/// indicates whether this verification should only succeed if the sig account does not exist
pub initial_creation: bool,
}
#[derive(Accounts)] #[derive(Accounts)]
pub struct VerifySig<'info> { pub struct VerifySig<'info> {
pub bridge: AccountInfo<'info>, pub bridge: AccountInfo<'info>,
@ -39,10 +30,37 @@ pub struct VerifySig<'info> {
pub payer_info: AccountInfo<'info>, pub payer_info: AccountInfo<'info>,
} }
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug)]
pub struct VerifySigsData {
/// hash of the VAA
pub hash: [u8; 32],
/// instruction indices of signers (-1 for missing)
pub signers: [i8; MAX_LEN_GUARDIAN_KEYS],
/// indicates whether this verification should only succeed if the sig account does not exist
pub initial_creation: bool,
}
#[derive(Accounts)]
pub struct Initialize {}
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug)]
pub struct InitializeData {
/// number of initial guardians
pub len_guardians: u8,
/// guardians that are allowed to sign mints
pub initial_guardian: [[u8; 20]; MAX_LEN_GUARDIAN_KEYS],
/// config for the bridge
pub config: BridgeConfig,
}
#[program] #[program]
pub mod anchor_bridge { pub mod anchor_bridge {
use super::*; use super::*;
pub fn initialize(ctx: Context<Initialize>, data: InitializeData) -> ProgramResult {
api::initialize(ctx, data)
}
pub fn verify_signatures(ctx: Context<VerifySig>, data: VerifySigsData) -> ProgramResult { pub fn verify_signatures(ctx: Context<VerifySig>, data: VerifySigsData) -> ProgramResult {
api::verify_signatures(ctx, data) api::verify_signatures(ctx, data)
} }

View File

@ -0,0 +1,11 @@
use anchor_lang::prelude::*;
#[repr(C)]
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug)]
pub struct BridgeConfig {
/// Period for how long a guardian set is valid after it has been replaced by a new one. This
/// guarantees that VAAs issued by that set can still be submitted for a certain period. In
/// this period we still trust the old guardian set.
pub guardian_set_expiration_time: u32,
}