2

Is there a way to store reference to a zero copy account in a regular account? Something like

#[account]
pub struct HoldingAccount {
  [account(zero)]
  pub myReferenceToAZeroCopyAccount: Box<ZeroCopyAccount>
}

Or does it need to always be passed in through context?

Also, extra points if myReferenceToAZeroCopyAccount becomes owned by HoldingAccount.

1 Answer 1

1

Not 100% sure i understand what you mean, but an account can not own another account execpt its a program afaik.

What you can do though is save an authority in the zero copy account and check in the owning program if the signer is the authority and only then allow to change the data.

#[account]
#[derive(InitSpace)]
pub struct RegularAccount {
    refToZeroCopy: Pubkey,
}

#[account(zero_copy)]
#[repr(C)]
#[derive(InitSpace)]
pub struct ZeroCopyAccount {
    authority: Pubkey,
    data: u64,
}

But you would still always need to pass in the zero copy account because all accounts you want to read from need to be passed into the transaction.

If you want zeroCopy serialized data in your regular account you could maybe save a byte array in the account and then deserialize it yourself.

2

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.