2

I am developing a cross-chain NFT transfer pallet that involves transferring both item metadata and collection metadata. To accomplish this, I need to access the data field within the ItemMetadata struct provided by the FRAME NFT pallet. The challenge lies in the fact that the data field is marked as private within the NFT pallet's codebase. Here is the relevant portion of the NFT pallet's code:

#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
#[scale_info(skip_type_params(StringLimit))]
pub struct ItemMetadata<Deposit, StringLimit: Get<u32>> {
    /// The balance deposited for this metadata.
    ///
    /// This pays for the data stored in this struct.
    pub(super) deposit: Deposit,
    /// General information concerning this item. Limited in length by `StringLimit`. This will
    /// generally be either a JSON dump or the hash of some JSON which can be found on a
    /// hash-addressable global publication system such as IPFS.
    pub(super) data: BoundedVec<u8, StringLimit>,
}

I'm seeking a solution to access and utilize the data field in my cross-chain transfer functionality while respecting the privacy constraints set in the NFT pallet's design. Could anyone help me with this.

1
  • make a pull request asking nicely to provide a method to access it?
    – dadzerlaze
    Sep 11, 2023 at 15:31

1 Answer 1

2

There is no way to access private fields in Rust. It is a limitation of the language.

  1. You can fork the NFT pallet and make those fields public.
  2. If your context involves encoded bytes, you can copy and redefine this struct in your code and make those fields public. Decode the struct from the bytes and you can access those fields now.
2
  • The problem lies in the fact that i can't fork the NFT pallet. I need to work with the Existing FRAME NFT Pallet.
    – Ipsa Gupta
    Sep 11, 2023 at 8:00
  • And if 2 doesn't work for you either, you may need to ask the upstream to make that change.
    – AurevoirXavier
    Sep 11, 2023 at 8:05

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.