I need to extend the fields I have within a PDA. Some accounts are already live, so I want those to still be compatible with the new layout. As a simple illustrative example, consider this account structure:
#[account]
pub struct AccountA {
pub variableA: u32,
}
Now I modify it, so so the program pads PDAs as such:
#[account]
pub struct AccountA {
pub variableA: u32,
pub variableB: u32,
}
I'd like to know if it's possible to retain compatibility with accounts created using the original struct after this change. Specifically, will the following line still function properly?
let acc_a: &mut Account<'_, AccountA> = &mut ctx.accounts.acc_a;
And make it so it will work with both smaller accounts with only one field from before the upgrade, as well as the larger ones post upgrade with two fields.
In essence I want a function similar to this:
impl AccountA {
pub fn value(&self, value: u32) -> bool {
return value < self.variableA || value > self.variableB;
}
}
If caller provides PDA of AccountA
from before the change, it should still work on the first of the or statements.
There is a plan to implement a function to resize and extend the existing account, but I want the transition to be seamless. Ideally, existing users should only need to invoke the resizing function if they desire the new functionality.