Do message payment within same instruction

Change-Id: Id1e3ac10bcdc7e91c649f5e75caf8a98e27be0c6
This commit is contained in:
Reisen 2021-07-01 07:20:03 +00:00
parent cdcf6f5d14
commit 62f5cb1986
2 changed files with 13 additions and 5 deletions

View File

@ -64,9 +64,10 @@ impl<'b> InstructionContext<'b> for PostMessage<'b> {
#[derive(BorshDeserialize, BorshSerialize, Default)] #[derive(BorshDeserialize, BorshSerialize, Default)]
pub struct PostMessageData { pub struct PostMessageData {
/// unique nonce for this message /// Unique nonce for this message
pub nonce: u32, pub nonce: u32,
/// message payload
/// Message payload
pub payload: Vec<u8>, pub payload: Vec<u8>,
} }
@ -84,7 +85,7 @@ pub fn post_message(
payload: data.payload.clone(), payload: data.payload.clone(),
}; };
trace!("Verifying Message: {}, {}", accs.emitter.key, data.nonce,); trace!("Verifying Message: {}, {}", accs.emitter.key, data.nonce);
accs.message accs.message
.verify_derivation(ctx.program_id, &msg_derivation)?; .verify_derivation(ctx.program_id, &msg_derivation)?;

View File

@ -152,14 +152,21 @@ mod helpers {
) -> Pubkey { ) -> Pubkey {
// Transfer money into the fee collector as it needs a balance/must exist. // Transfer money into the fee collector as it needs a balance/must exist.
let fee_collector = FeeCollector::<'_>::key(None, program); let fee_collector = FeeCollector::<'_>::key(None, program);
transfer(client, payer, &fee_collector, 10_000);
// Capture the resulting message, later functions will need this. // Capture the resulting message, later functions will need this.
let (message_key, instruction) = let (message_key, instruction) =
instructions::post_message(*program, payer.pubkey(), emitter.pubkey(), nonce, data) instructions::post_message(*program, payer.pubkey(), emitter.pubkey(), nonce, data)
.unwrap(); .unwrap();
execute(client, payer, &[payer, emitter], &[instruction]); execute(
client,
payer,
&[payer, emitter],
&[
system_instruction::transfer(&payer.pubkey(), &fee_collector, 10_000),
instruction,
],
);
message_key message_key
} }