Generate, sign, and populate message fields.
Change-Id: Ia03b080f17fc27e34178dda0a946d46a6cb6877c
This commit is contained in:
parent
edfbfc93db
commit
baf9614998
|
@ -16,7 +16,7 @@ const VAA_TX_FEE: u64 = 18 * 10000;
|
|||
/// Maximum size of a posted VAA
|
||||
pub const MAX_PAYLOAD_SIZE: usize = 400;
|
||||
|
||||
pub fn publish_message(bridge: &mut Bridge, ctx: Context<PublishMessage>) -> Result<()> {
|
||||
pub fn publish_message(bridge: &mut Bridge, ctx: Context<PublishMessage>, nonce: u8) -> Result<()> {
|
||||
// Manually create message account, as Anchor can't do it.
|
||||
let mut message: ProgramAccount<PostedMessage> = {
|
||||
// First create the message account. 8 Bytes additional for the discriminator.
|
||||
|
@ -30,26 +30,33 @@ pub fn publish_message(bridge: &mut Bridge, ctx: Context<PublishMessage>) -> Res
|
|||
ctx.program_id,
|
||||
);
|
||||
|
||||
// let seeds = [
|
||||
// ctx.accounts.poll.to_account_info().key.as_ref(),
|
||||
// ctx.accounts.stake.member.to_account_info().key.as_ref(),
|
||||
// &[nonce],
|
||||
// ];
|
||||
// let signer = &[&seeds[..]];
|
||||
// solana_program::program::invoke_signed(
|
||||
// &ix,
|
||||
// &[
|
||||
// ctx.accounts.stake.beneficiary.clone(),
|
||||
// ctx.accounts.vote.clone(),
|
||||
// ctx.accounts.system_program.clone(),
|
||||
// ],
|
||||
// signer,
|
||||
// )?;
|
||||
// Derived seeds for a message account.
|
||||
let seeds = [
|
||||
ctx.program_id.as_ref(),
|
||||
ctx.accounts.emitter.key.as_ref(),
|
||||
&[nonce],
|
||||
];
|
||||
|
||||
// Wrap seeds in a signer list.
|
||||
let signer = &[&seeds[..]];
|
||||
|
||||
// Create account using generated data.
|
||||
solana_program::program::invoke_signed(
|
||||
&ix,
|
||||
&[
|
||||
ctx.accounts.emitter.clone(),
|
||||
ctx.accounts.system_program.clone(),
|
||||
],
|
||||
signer,
|
||||
)?;
|
||||
// Deserialize the newly created account into an object.
|
||||
ProgramAccount::try_from_init(&ctx.accounts.message)?
|
||||
};
|
||||
|
||||
// Do any initialization here.
|
||||
// Initialize Message data.
|
||||
message.submission_time = ctx.accounts.clock.unix_timestamp as u32;
|
||||
message.emitter_chain = Chain::Solana;
|
||||
message.emitter_address = ctx.accounts.emitter.key.to_bytes();
|
||||
|
||||
// Manually persist changes since we manually created the account.
|
||||
message.exit(ctx.program_id)?;
|
||||
|
|
|
@ -122,7 +122,7 @@ pub mod anchor_bridge {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn publish_message(&mut self, ctx: Context<PublishMessage>, data: PublishMessageData) -> Result<()> {
|
||||
pub fn publish_message(&mut self, ctx: Context<PublishMessage>, data: PublishMessageData, nonce: u8) -> Result<()> {
|
||||
// Sysvar trait not implemented for Instructions by sdk, so manual check required. See
|
||||
// the VerifySig struct for more info.
|
||||
if *ctx.accounts.instructions.key != solana_program::sysvar::instructions::id() {
|
||||
|
@ -132,6 +132,7 @@ pub mod anchor_bridge {
|
|||
api::publish_message(
|
||||
self,
|
||||
ctx,
|
||||
nonce,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue