1

How can we reload the lamport balance of a Signer to compare before/after a CPI?

If we have:

pub struct SomeIX<'info> {
    #[account(mut)]
    pub payer: Signer<'info>,
//etc...

and in our handler:

    let lamports_before = ctx.accounts.payer.lamports();
    //Some CPI where payer pays...
    //RELOAD?
    let lamports_after = ctx.accounts.payer.lamports();

For Token accounts, we can simply do: ctx.accounts.some_acc.reload()?;

But Signer has no reload function.

2 Answers 2

3

Have you tried accessing the account_info using ctx.accounts.payer.to_account_info().lamports() and seeing if that contains the updated value?

1
  • It's entirely possible this doesn't work but I presume there's a reason anchor doesn't have a reload function for regular account types
    – Henry E
    Commented Oct 13, 2022 at 19:26
1

The answer is actually that the lamport balance updates automatically. For example when using the system program to transfer funds, the lamport balance will be updated after the CPI.

Lamports should be borrowed as mut.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.