Add Mut layer to accounts in bridge program.

Change-Id: I78dfb4568eaec4f597a6d0e1ac10a0f698bb5a61
This commit is contained in:
Reisen 2021-07-06 12:03:43 +00:00
parent 76066c8cc6
commit 387fcc48c0
8 changed files with 41 additions and 33 deletions

View File

@ -74,10 +74,10 @@ pub fn upgrade_contract(
#[derive(FromAccounts)]
pub struct UpgradeGuardianSet<'b> {
/// Payer for account creation (vaa-claim)
pub payer: Signer<Info<'b>>,
pub payer: Mut<Signer<Info<'b>>>,
/// Bridge config
pub bridge: Bridge<'b, { AccountState::Initialized }>,
pub bridge: Mut<Bridge<'b, { AccountState::Initialized }>>,
/// GuardianSet change VAA
pub vaa: ClaimableVAA<'b, GovernancePayloadGuardianSetChange>,
@ -86,7 +86,7 @@ pub struct UpgradeGuardianSet<'b> {
pub guardian_set_old: GuardianSet<'b, { AccountState::Initialized }>,
/// New guardian set
pub guardian_set_new: GuardianSet<'b, { AccountState::Uninitialized }>,
pub guardian_set_new: Mut<GuardianSet<'b, { AccountState::Uninitialized }>>,
}
impl<'b> InstructionContext<'b> for UpgradeGuardianSet<'b> {
@ -152,10 +152,10 @@ pub fn upgrade_guardian_set(
#[derive(FromAccounts)]
pub struct SetFees<'b> {
/// Payer for account creation (vaa-claim)
pub payer: Signer<Info<'b>>,
pub payer: Mut<Signer<Info<'b>>>,
/// Bridge config
pub bridge: Bridge<'b, { AccountState::Initialized }>,
pub bridge: Mut<Bridge<'b, { AccountState::Initialized }>>,
/// Governance VAA
pub vaa: ClaimableVAA<'b, GovernancePayloadSetMessageFee>,
@ -179,7 +179,7 @@ pub fn set_fees(ctx: &ExecutionContext, accs: &mut SetFees, _data: SetFeesData)
#[derive(FromAccounts)]
pub struct TransferFees<'b> {
/// Payer for account creation (vaa-claim)
pub payer: Signer<Info<'b>>,
pub payer: Mut<Signer<Info<'b>>>,
/// Bridge config
pub bridge: Bridge<'b, { AccountState::Initialized }>,
@ -188,10 +188,10 @@ pub struct TransferFees<'b> {
pub vaa: ClaimableVAA<'b, GovernancePayloadTransferFees>,
/// Account collecting tx fees
pub fee_collector: Derive<Info<'b>, "fee_collector">,
pub fee_collector: Mut<Derive<Info<'b>, "fee_collector">>,
/// Fee recipient
pub recipient: Info<'b>,
pub recipient: Mut<Info<'b>>,
}
impl<'b> InstructionContext<'b> for TransferFees<'b> {

View File

@ -18,10 +18,17 @@ type Payer<'a> = Signer<Info<'a>>;
#[derive(FromAccounts, ToInstruction)]
pub struct Initialize<'b> {
pub bridge: Bridge<'b, { AccountState::Uninitialized }>,
pub guardian_set: GuardianSet<'b, { AccountState::Uninitialized }>,
pub fee_collector: FeeCollector<'b>,
pub payer: Payer<'b>,
/// Bridge config.
pub bridge: Mut<Bridge<'b, { AccountState::Uninitialized }>>,
/// Location the new guardian set will be allocated at.
pub guardian_set: Mut<GuardianSet<'b, { AccountState::Uninitialized }>>,
/// Location of the fee collector that users will need to pay.
pub fee_collector: Mut<FeeCollector<'b>>,
/// Payer for account creation.
pub payer: Mut<Payer<'b>>,
}
impl<'b> InstructionContext<'b> for Initialize<'b> {

View File

@ -37,22 +37,23 @@ impl<'a> From<&PostMessage<'a>> for SequenceDerivationData<'a> {
#[derive(FromAccounts)]
pub struct PostMessage<'b> {
pub bridge: Bridge<'b, { AccountState::Initialized }>,
/// Bridge config needed for fee calculation.
pub bridge: Mut<Bridge<'b, { AccountState::Initialized }>>,
/// Account to store the posted message
pub message: UninitializedMessage<'b>,
pub message: Mut<UninitializedMessage<'b>>,
/// Emitter of the VAA
pub emitter: Signer<Info<'b>>,
/// Tracker for the emitter sequence
pub sequence: Sequence<'b>,
pub sequence: Mut<Sequence<'b>>,
/// Payer for account creation
pub payer: Signer<Info<'b>>,
pub payer: Mut<Signer<Info<'b>>>,
/// Account to collect tx fee
pub fee_collector: FeeCollector<'b>,
pub fee_collector: Mut<FeeCollector<'b>>,
pub clock: Sysvar<'b, Clock>,
}

View File

@ -70,10 +70,10 @@ pub struct PostVAA<'b> {
pub signature_set: SignatureSet<'b, { AccountState::Initialized }>,
/// Message the VAA is associated with.
pub message: Message<'b, { AccountState::MaybeInitialized }>,
pub message: Mut<Message<'b, { AccountState::MaybeInitialized }>>,
/// Account used to pay for auxillary instructions.
pub payer: Info<'b>,
pub payer: Mut<Signer<Info<'b>>>,
/// Clock used for timestamping.
pub clock: Sysvar<'b, Clock>,

View File

@ -27,13 +27,13 @@ use std::io::Write;
#[derive(FromAccounts)]
pub struct VerifySignatures<'b> {
/// Payer for account creation
pub payer: Signer<Info<'b>>,
pub payer: Mut<Signer<Info<'b>>>,
/// Guardian set of the signatures
pub guardian_set: GuardianSet<'b, { AccountState::Initialized }>,
/// Signature Account
pub signature_set: SignatureSet<'b, { AccountState::MaybeInitialized }>,
pub signature_set: Mut<SignatureSet<'b, { AccountState::MaybeInitialized }>>,
/// Instruction reflection account (special sysvar)
pub instruction_acc: Info<'b>,

View File

@ -110,7 +110,7 @@ pub fn post_message(
accounts: vec![
AccountMeta::new(bridge, false),
AccountMeta::new(message, false),
AccountMeta::new(emitter, true),
AccountMeta::new_readonly(emitter, true),
AccountMeta::new(sequence, false),
AccountMeta::new(payer, true),
AccountMeta::new(fee_collector, false),
@ -152,7 +152,7 @@ pub fn verify_signatures(
accounts: vec![
AccountMeta::new(payer, true),
AccountMeta::new(guardian_set, false),
AccountMeta::new_readonly(guardian_set, false),
AccountMeta::new(signature_set, false),
AccountMeta::new_readonly(sysvar::instructions::id(), false),
AccountMeta::new_readonly(sysvar::rent::id(), false),
@ -197,9 +197,9 @@ pub fn post_vaa(program_id: Pubkey, payer: Pubkey, vaa: PostVAAData) -> Instruct
program_id,
accounts: vec![
AccountMeta::new(guardian_set, false),
AccountMeta::new(bridge, false),
AccountMeta::new(signature_set, false),
AccountMeta::new_readonly(guardian_set, false),
AccountMeta::new_readonly(bridge, false),
AccountMeta::new_readonly(signature_set, false),
AccountMeta::new(message, false),
AccountMeta::new(payer, true),
AccountMeta::new_readonly(sysvar::clock::id(), false),
@ -283,9 +283,9 @@ pub fn upgrade_guardian_set(
accounts: vec![
AccountMeta::new(payer, true),
AccountMeta::new(bridge, false),
AccountMeta::new(payload_message, false),
AccountMeta::new_readonly(payload_message, false),
AccountMeta::new(claim, false),
AccountMeta::new(guardian_set_old, false),
AccountMeta::new_readonly(guardian_set_old, false),
AccountMeta::new(guardian_set_new, false),
AccountMeta::new_readonly(solana_program::system_program::id(), false),
],
@ -319,7 +319,7 @@ pub fn set_fees(
accounts: vec![
AccountMeta::new(payer, true),
AccountMeta::new(bridge, false),
AccountMeta::new(message, false),
AccountMeta::new_readonly(message, false),
AccountMeta::new(claim, false),
AccountMeta::new_readonly(solana_program::system_program::id(), false),
],
@ -355,8 +355,8 @@ pub fn transfer_fees(
accounts: vec![
AccountMeta::new(payer, true),
AccountMeta::new(bridge, false),
AccountMeta::new(message, false),
AccountMeta::new_readonly(bridge, false),
AccountMeta::new_readonly(message, false),
AccountMeta::new(claim, false),
AccountMeta::new(fee_collector, false),
AccountMeta::new(recipient, false),

View File

@ -123,7 +123,7 @@ pub struct ClaimableVAA<'b, T: DeserializePayload> {
pub message: PayloadMessage<'b, T>,
// Claim account to prevent double spending
pub claim: Claim<'b, { AccountState::Uninitialized }>,
pub claim: Mut<Claim<'b, { AccountState::Uninitialized }>>,
}
impl<'b, T: DeserializePayload> Deref for ClaimableVAA<'b, T> {

View File

@ -230,7 +230,7 @@ impl<
// It is also a malformed program to attempt to write to a non-writeable account.
if !self.0.is_writable {
return Err(SolitaireError::NonWriteableAccount(*self.0.key));
return Ok(());
}
self.1.serialize(&mut *self.0.data.borrow_mut())?;