use crate::*;
pub fn handler(ctx: Context<Approve>) -> Result<()> {
let owner_index = ctx
.accounts
.smart_wallet
.try_owner_index(ctx.accounts.owner.key())?;
ctx.accounts.transaction.signers[owner_index] = true;
emit!(TransactionApproveEvent {
smart_wallet: ctx.accounts.smart_wallet.key(),
transaction: ctx.accounts.transaction.key(),
owner: ctx.accounts.owner.key(),
timestamp: Clock::get()?.unix_timestamp
});
Ok(())
}
impl<'info> Validate<'info> for Approve<'info> {
fn validate(&self) -> Result<()> {
assert_keys_eq!(self.smart_wallet, self.transaction.smart_wallet);
invariant!(
self.smart_wallet.owner_set_seqno == self.transaction.owner_set_seqno,
OwnerSetChanged
);
invariant!(self.transaction.executed_at == -1, AlreadyExecuted);
Ok(())
}
}
#[derive(Accounts)]
pub struct Approve<'info> {
pub smart_wallet: Account<'info, SmartWallet>,
#[account(mut, has_one = smart_wallet)]
pub transaction: Account<'info, Transaction>,
pub owner: Signer<'info>,
}