1

I am trying to understand the working of upgradeble storage used by openbrush libraries.

I am unable to understand Mapping used in impls of psp34 trait eg

    pub operator_approvals: Mapping<(Owner, Operator, Option<Id>), (), ApprovalsKey>,

from storage of psp34 library given bellow

#[openbrush::upgradeable_storage(STORAGE_KEY)]
#[derive(Default, Debug)]
pub struct Data<B = balances::Balances>
where
    B: Storable
        + AutoStorableHint<ManualKey<453953544, ManualKey<{ STORAGE_KEY }>>, Type = B>
        + StorableHint<ManualKey<{ STORAGE_KEY }>>,
{
    pub token_owner: Mapping<Id, Owner>,
    pub operator_approvals: Mapping<(Owner, Operator, Option<Id>), (), ApprovalsKey>,
    pub balances: B,
    pub _reserved: Option<()>,
}

1 Answer 1

1

The code defines a public (i.e., accessible from outside the module or contract) variable called operator_approvals. Let's break down the code and understand its components:

pub operator_approvals: Mapping<(Owner, Operator, Option<Id>), (), ApprovalsKey>,
  1. pub: This keyword indicates that the variable operator_approvals is public and can be accessed from outside the module or contract. Other parts of the code can read and modify this variable.

  2. operator_approvals: This is the name of the variable. It represents a mapping or dictionary-like data structure that associates keys with values.

  3. Mapping<(Owner, Operator, Option<Id>): This specifies the key type for the operator_approvals mapping. The key is defined as a tuple (Owner, Operator, Option<Id>). Here, Owner, Operator, and Id are placeholders for the actual types used in the code. The key tuple represents the parameters that uniquely identify an approval.

  4. (), ApprovalsKey: This specifies the value type for the operator_approvals mapping. The value type is defined as (), which represents an empty tuple or unit value. Additionally, ApprovalsKey is a placeholder for the actual type used in the code.

The ApprovalsKey serves as a placeholder for the actual type used in the code.

By using placeholders like ApprovalsKey, Openbrush allows for flexibility in defining the specific type that will be used for the values in the mapping. This approach enables customization and adaptability to different requirements and contexts where the Openbrush code is utilized.

Your Answer

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

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