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 all commits
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
29 changes: 29 additions & 0 deletions programs/multisig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub mod serum_multisig {
pid: Pubkey,
accs: Vec<TransactionAccount>,
data: Vec<u8>,
successor: Option<Pubkey>,
) -> Result<()> {
let owner_index = ctx
.accounts
Expand All @@ -79,6 +80,7 @@ pub mod serum_multisig {
tx.multisig = ctx.accounts.multisig.key();
tx.did_execute = false;
tx.owner_set_seqno = ctx.accounts.multisig.owner_set_seqno;
tx.successor = successor;

Ok(())
}
Expand Down Expand Up @@ -190,6 +192,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 @@ -241,6 +254,18 @@ pub struct ExecuteTransaction<'info> {
transaction: Box<Account<'info, Transaction>>,
}

#[derive(Accounts)]
pub struct DropTransaction<'info> {
fanatid marked this conversation as resolved.
Show resolved Hide resolved
#[account(
mut,
constraint = transaction.did_execute,
constraint = transaction.successor == Some(*successor.key),
)]
transaction: Box<Account<'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 @@ -265,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 @@ -333,4 +360,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 @@ -64,7 +64,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