Add anchor accounts for PostMessage instruction.
Change-Id: I26d054479b95d9e33c8da4f8b6fca630240ffb3f
This commit is contained in:
parent
ab20f15904
commit
c1c778d65a
|
@ -13,4 +13,3 @@ pub fn publish_message(
|
||||||
) -> ProgramResult {
|
) -> ProgramResult {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,21 @@ struct SecpInstructionPart<'a> {
|
||||||
msg_size: u16,
|
msg_size: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn filter_empty_signatures(signers: &[i8; MAX_LEN_GUARDIAN_KEYS]) -> Vec<SigInfo> {
|
||||||
|
signers
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter_map(|(i, p)| match *p {
|
||||||
|
-1 => None,
|
||||||
|
ix => Some(SigInfo {
|
||||||
|
sig_index: ix as u8,
|
||||||
|
signer_index: i as u8,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn verify_signatures(
|
pub fn verify_signatures(
|
||||||
bridge: &mut Bridge,
|
bridge: &mut Bridge,
|
||||||
ctx: Context<VerifySig>,
|
ctx: Context<VerifySig>,
|
||||||
|
@ -29,20 +44,7 @@ pub fn verify_signatures(
|
||||||
signers: [i8; MAX_LEN_GUARDIAN_KEYS],
|
signers: [i8; MAX_LEN_GUARDIAN_KEYS],
|
||||||
initial_creation: bool,
|
initial_creation: bool,
|
||||||
) -> ProgramResult {
|
) -> ProgramResult {
|
||||||
let sig_infos: Vec<SigInfo> = signers
|
let sig_infos = filter_empty_signatures(&signers);
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.filter_map(|(i, p)| {
|
|
||||||
if *p == -1 {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Some(SigInfo {
|
|
||||||
sig_index: *p as u8,
|
|
||||||
signer_index: i as u8,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// We check this manually because the type-level checks are
|
// We check this manually because the type-level checks are
|
||||||
// not available for Instructions yet. See the VerifySig
|
// not available for Instructions yet. See the VerifySig
|
||||||
|
|
|
@ -70,7 +70,32 @@ pub struct InitializeData {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Accounts)]
|
#[derive(Accounts)]
|
||||||
pub struct PublishMessage {}
|
pub struct PublishMessage<'info> {
|
||||||
|
/// Clock used for timestamping.
|
||||||
|
pub clock: Sysvar<'info, Clock>,
|
||||||
|
|
||||||
|
/// Instructions used for transaction reflection.
|
||||||
|
pub instructions: AccountInfo<'info>,
|
||||||
|
|
||||||
|
/// Derived account verified to match the expected pubkey via Bridge::check_and_create_account.
|
||||||
|
#[account(init)]
|
||||||
|
pub message: AccountInfo<'info>,
|
||||||
|
|
||||||
|
/// No need to verify - only used as the fee payer for account creation.
|
||||||
|
#[account(signer)]
|
||||||
|
pub payer: AccountInfo<'info>,
|
||||||
|
|
||||||
|
/// The emitter, only used as metadata. We verify that the account is a signer to prevent
|
||||||
|
/// messages from being spoofed.
|
||||||
|
#[account(signer)]
|
||||||
|
pub emitter: AccountInfo<'info>,
|
||||||
|
|
||||||
|
/// 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 PublishMessageData {}
|
pub struct PublishMessageData {}
|
||||||
|
|
Loading…
Reference in New Issue