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

accounts is borrowed for 'info #3415

Open
cxp-13 opened this issue Dec 8, 2024 · 2 comments
Open

accounts is borrowed for 'info #3415

cxp-13 opened this issue Dec 8, 2024 · 2 comments
Labels

Comments

@cxp-13
Copy link

cxp-13 commented Dec 8, 2024

12 | #[program]
   | ^^^^^^^^^-
   | |        |
   | |        `__accounts` dropped here while still borrowed
   | borrowed value does not live long enough
   | lifetime `'info` defined here
   | argument requires that `__accounts` is borrowed for `'info`

I don't why life time error happen when I add 'b on lib.rs

pub fn battle_log<'b: 'info, 'c: 'info, 'info>(
        ctx: Context<'_, 'b, 'c, 'info, BattleLog<'info>>,
        battle_info: BattleInfo,
        warrior_card_collect_mints: Vec<Pubkey>
    ) -> Result<()> {
        battle_log_process(ctx, battle_info, warrior_card_collect_mints)
    }

I want to extract the logic of creating an account into a function, and then it will report an error, asking me to add the relationship between b and info.

fbc83ba68919fab094857cdbc31588a

The result is written in this way, but it cannot pass the limit of the problem I posted.

@acheroncrypto
Copy link
Collaborator

This is due to how internal codegen works. However, there is a draft PR (#3340) to make all lifetimes of Context the same to make it easier for people to work with it.

@cxp-13
Copy link
Author

cxp-13 commented Dec 17, 2024

Solution:
If you function involved in some params of context.accounts
don't add 'info in the front of params with context. like payer: &'info Signer<'info> .
Right example:

fn process_warrior_cards_usage<'info>(
    warrior_card_usage_data_len: usize,
    warrior_card_usage_ai: &'info AccountInfo<'info>,
    collect_mint: Pubkey,
    attacker: Pubkey,
    program_id: &Pubkey,
    payer: &Signer<'info>,
    rent_lamports: u64,
    system_program: &Program<'info, System>
) -> Result<()> {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants