5

I am facing an error on adding line Vec<String>, type or String type.
Error: error pic

#[derive(Accounts)]
pub struct ModifyLedger<'info> {
    #[account(mut)]
    pub ledger_account: Account<'info, Ledger>,
    #[account(mut)]
    pub wallet: Signer<'info>,
}

program function:

   pub fn add_limited_list(
        ctx: Context<ModifyLedger>,
        limited_pk_list: Vec<String>,
    ) -> Result<()> {
        for each_limited_pk in limited_pk_list.iter() {
            if ctx
                .accounts
                .ledger_account
                .limited_stage_list
                .iter()
                .find(|&pk | pk == each_limited_pk)
                == None
            {
                ctx.accounts
                    .ledger_account
                    .limited_stage_list
                    .push(each_limited_pk.to_string());
            }
        }

        Ok(())
    }

Account:

#[account]
pub struct Ledger {
    pub limited_stage_list: Vec<String>,
    pub timebound_stage_list: Vec<String>,
    pub public_stage_list: Vec<String>,
    //pub uri: String,
}

3
  • it would help so see how you are initializing the account that is failing. this is most likely an error with allocated space for the account and not properly handling dynamic data types on accounts
    – m_callens
    Commented Nov 1, 2022 at 3:00
  • You can view my entire smart contract here. Commented Nov 1, 2022 at 4:47
  • I have assigned space = 82 to the account. The code breaks down if I changes this number. Code works for all types u8, u32, u64, i64 but not for String and vec<String> Code Snippet: #[account( init_if_needed, payer = wallet, space = 82, seeds = [ b"new_seed", ], bump )] pub ledger_account: Account<'info, Ledger> Commented Nov 1, 2022 at 4:58

1 Answer 1

1

I increased the space that didn't worked initially. What worked for me is that after I increased the space (i.e space = 1024) and then deleted target folder, fetch new keys using anchor keys list, replaced it in declare_id and in anchor.toml, and then redeployed the the program using anchor build and anchor deploy. That worked for me.

#[account(init_if_needed,payer = wallet,space = 1024,seeds = [b"new_seed",],bump)]    
 pub ledger_account: Account<'info, Ledger>

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.