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 anchor_lang::{prelude::*, solana_program};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
accounts,
|
||||||
|
anchor_bridge::Bridge,
|
||||||
|
types::{BridgeConfig, Version},
|
||||||
|
Initialize, InitializeData, MAX_LEN_GUARDIAN_KEYS,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn initialize(
|
pub fn initialize(
|
||||||
ctx: Context<Initialize>,
|
ctx: Context<Initialize>,
|
||||||
len_guardians: u8,
|
len_guardians: u8,
|
||||||
initial_guardian_key: [[u8; 20]; MAX_LEN_GUARDIAN_KEYS],
|
initial_guardian_key: [[u8; 20]; MAX_LEN_GUARDIAN_KEYS],
|
||||||
config: BridgeConfig,
|
config: BridgeConfig,
|
||||||
) -> ProgramResult {
|
) -> Result<Bridge, ProgramError> {
|
||||||
Ok(())
|
Ok(Bridge {
|
||||||
|
guardian_set_version: Version(0),
|
||||||
|
config,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::{accounts, VerifySig, VerifySigsData};
|
|
||||||
use anchor_lang::{prelude::*, solana_program};
|
use anchor_lang::{prelude::*, solana_program};
|
||||||
|
|
||||||
|
use crate::{accounts, VerifySig, VerifySigsData};
|
||||||
use byteorder::ByteOrder;
|
use byteorder::ByteOrder;
|
||||||
use sha3::Digest;
|
use sha3::Digest;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
|
@ -41,7 +41,23 @@ pub struct VerifySigsData {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Accounts)]
|
#[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)]
|
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug)]
|
||||||
pub struct InitializeData {
|
pub struct InitializeData {
|
||||||
|
@ -63,13 +79,15 @@ pub mod anchor_bridge {
|
||||||
pub config: types::BridgeConfig,
|
pub config: types::BridgeConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initialize(ctx: Context<Initialize>, data: InitializeData) -> ProgramResult {
|
impl Bridge {
|
||||||
api::initialize(
|
pub fn new(ctx: Context<Initialize>, data: InitializeData) -> Result<Self, ProgramError> {
|
||||||
ctx,
|
api::initialize(
|
||||||
data.len_guardians,
|
ctx,
|
||||||
data.initial_guardian_keys,
|
data.len_guardians,
|
||||||
data.config,
|
data.initial_guardian_keys,
|
||||||
)
|
data.config,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn verify_signatures(ctx: Context<VerifySig>, data: VerifySigsData) -> ProgramResult {
|
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.
|
// Distinguishes a Version number from a standard u32.
|
||||||
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug)]
|
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug)]
|
||||||
pub struct Version(u32);
|
pub struct Version(pub u32);
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug)]
|
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug)]
|
||||||
|
|
Loading…
Reference in New Issue