Add anchor accounts for PostMessage instruction.

Change-Id: I26d054479b95d9e33c8da4f8b6fca630240ffb3f
This commit is contained in:
Reisen 2021-04-30 02:49:37 +00:00
parent ab20f15904
commit c1c778d65a
3 changed files with 42 additions and 16 deletions

View File

@ -13,4 +13,3 @@ pub fn publish_message(
) -> ProgramResult {
Ok(())
}

View File

@ -22,6 +22,21 @@ struct SecpInstructionPart<'a> {
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(
bridge: &mut Bridge,
ctx: Context<VerifySig>,
@ -29,20 +44,7 @@ pub fn verify_signatures(
signers: [i8; MAX_LEN_GUARDIAN_KEYS],
initial_creation: bool,
) -> ProgramResult {
let sig_infos: Vec<SigInfo> = 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();
let sig_infos = filter_empty_signatures(&signers);
// We check this manually because the type-level checks are
// not available for Instructions yet. See the VerifySig

View File

@ -70,7 +70,32 @@ pub struct InitializeData {
}
#[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)]
pub struct PublishMessageData {}