Use Anchor state for Initialize
Change-Id: I4f61c3e74e037e873f669f240ebbc8fe26567103
This commit is contained in:
parent
17bda088f1
commit
1c9facbb75
|
@ -1,11 +1,20 @@
|
|||
use crate::{accounts, types::BridgeConfig, Initialize, InitializeData, MAX_LEN_GUARDIAN_KEYS};
|
||||
use anchor_lang::{prelude::*, solana_program};
|
||||
|
||||
use crate::{
|
||||
accounts,
|
||||
anchor_bridge::Bridge,
|
||||
types::{BridgeConfig, Version},
|
||||
Initialize, InitializeData, MAX_LEN_GUARDIAN_KEYS,
|
||||
};
|
||||
|
||||
pub fn initialize(
|
||||
ctx: Context<Initialize>,
|
||||
len_guardians: u8,
|
||||
initial_guardian_key: [[u8; 20]; MAX_LEN_GUARDIAN_KEYS],
|
||||
config: BridgeConfig,
|
||||
) -> ProgramResult {
|
||||
Ok(())
|
||||
) -> Result<Bridge, ProgramError> {
|
||||
Ok(Bridge {
|
||||
guardian_set_version: Version(0),
|
||||
config,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::{accounts, VerifySig, VerifySigsData};
|
||||
use anchor_lang::{prelude::*, solana_program};
|
||||
|
||||
use crate::{accounts, VerifySig, VerifySigsData};
|
||||
use byteorder::ByteOrder;
|
||||
use sha3::Digest;
|
||||
use std::io::Write;
|
||||
|
|
|
@ -41,7 +41,23 @@ pub struct VerifySigsData {
|
|||
}
|
||||
|
||||
#[derive(Accounts)]
|
||||
pub struct Initialize {}
|
||||
pub struct Initialize<'info> {
|
||||
/// Account used to pay for auxillary instructions.
|
||||
#[account(signer)]
|
||||
pub payer: AccountInfo<'info>,
|
||||
|
||||
/// Used for timestamping actions.
|
||||
pub clock: Sysvar<'info, Clock>,
|
||||
|
||||
/// Information about the current guardian set.
|
||||
pub guardian_set: ProgramState<'info, GuardianSetInfo>,
|
||||
|
||||
/// Required by Anchor for associated accounts.
|
||||
pub rent: Sysvar<'info, Rent>,
|
||||
|
||||
/// Required by Anchor for associated accounts.
|
||||
pub system_program: AccountInfo<'info>,
|
||||
}
|
||||
|
||||
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug)]
|
||||
pub struct InitializeData {
|
||||
|
@ -63,13 +79,15 @@ pub mod anchor_bridge {
|
|||
pub config: types::BridgeConfig,
|
||||
}
|
||||
|
||||
pub fn initialize(ctx: Context<Initialize>, data: InitializeData) -> ProgramResult {
|
||||
api::initialize(
|
||||
ctx,
|
||||
data.len_guardians,
|
||||
data.initial_guardian_keys,
|
||||
data.config,
|
||||
)
|
||||
impl Bridge {
|
||||
pub fn new(ctx: Context<Initialize>, data: InitializeData) -> Result<Self, ProgramError> {
|
||||
api::initialize(
|
||||
ctx,
|
||||
data.len_guardians,
|
||||
data.initial_guardian_keys,
|
||||
data.config,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn verify_signatures(ctx: Context<VerifySig>, data: VerifySigsData) -> ProgramResult {
|
||||
|
|
|
@ -2,7 +2,7 @@ use anchor_lang::prelude::*;
|
|||
|
||||
// Distinguishes a Version number from a standard u32.
|
||||
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug)]
|
||||
pub struct Version(u32);
|
||||
pub struct Version(pub u32);
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug)]
|
||||
|
|
Loading…
Reference in New Issue