Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to drop tx after execution #41

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions programs/multisig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub mod serum_multisig {
pid: Pubkey,
accs: Vec<TransactionAccount>,
data: Vec<u8>,
successor: Option<Pubkey>,
) -> Result<()> {
let owner_index = ctx
.accounts
Expand All @@ -75,6 +76,7 @@ pub mod serum_multisig {
tx.multisig = *ctx.accounts.multisig.to_account_info().key;
tx.did_execute = false;
tx.owner_set_seqno = ctx.accounts.multisig.owner_set_seqno;
tx.successor = successor;

Ok(())
}
Expand Down Expand Up @@ -183,6 +185,17 @@ pub mod serum_multisig {

Ok(())
}

// Move transaction rent exemption SOL
pub fn drop_transaction(ctx: Context<DropTransaction>) -> Result<()> {
let tx = ctx.accounts.transaction.to_account_info();
let mut tx_balance = tx.try_borrow_mut_lamports()?;
let successor = ctx.accounts.successor.to_account_info();
let mut successor_balance = successor.try_borrow_mut_lamports()?;
**successor_balance = (**successor_balance).checked_add(**tx_balance).unwrap();
**tx_balance = 0;
Ok(())
}
}

#[derive(Accounts)]
Expand Down Expand Up @@ -239,6 +252,20 @@ pub struct ExecuteTransaction<'info> {
transaction: ProgramAccount<'info, Transaction>,
}

#[derive(Accounts)]
pub struct DropTransaction<'info> {
fanatid marked this conversation as resolved.
Show resolved Hide resolved
multisig: ProgramAccount<'info, Multisig>,
fanatid marked this conversation as resolved.
Show resolved Hide resolved
#[account(
mut,
has_one = multisig,
constraint = transaction.did_execute == true,
fanatid marked this conversation as resolved.
Show resolved Hide resolved
constraint = transaction.successor == Some(*successor.key),
)]
transaction: ProgramAccount<'info, Transaction>,
#[account(mut)]
successor: AccountInfo<'info>,
fanatid marked this conversation as resolved.
Show resolved Hide resolved
}

#[account]
pub struct Multisig {
pub owners: Vec<Pubkey>,
Expand All @@ -263,6 +290,8 @@ pub struct Transaction {
pub did_execute: bool,
// Owner set sequence number.
pub owner_set_seqno: u32,
// Account which receive rent exemption SOL after transaction executing.
pub successor: Option<Pubkey>,
}

impl From<&Transaction> for Instruction {
Expand Down Expand Up @@ -329,4 +358,6 @@ pub enum ErrorCode {
InvalidThreshold,
#[msg("Owners must be unique")]
UniqueOwners,
#[msg("Invalid successor account.")]
InvalidSuccessor,
}
3 changes: 2 additions & 1 deletion tests/multisig.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe("multisig", () => {

const transaction = anchor.web3.Keypair.generate();
const txSize = 1000; // Big enough, cuz I'm lazy.
await program.rpc.createTransaction(pid, accounts, data, {
await program.rpc.createTransaction(pid, accounts, data, null, {
accounts: {
multisig: multisig.publicKey,
transaction: transaction.publicKey,
Expand All @@ -89,6 +89,7 @@ describe("multisig", () => {
assert.ok(txAccount.multisig.equals(multisig.publicKey));
assert.deepStrictEqual(txAccount.didExecute, false);
assert.ok(txAccount.ownerSetSeqno === 0);
assert.deepStrictEqual(txAccount.successor, null);

// Other owner approves transactoin.
await program.rpc.approve({
Expand Down