0

How to store enumeration in smart contract with ink! I have a field in smart contract with type Mapping<AccountId, Enum>, I tried to use guide https://ink.substrate.io/datastructures/custom-datastructure, but I don't understand how I should pull, push and clear Enum values in storage by pointers.

2 Answers 2

0

With the current version of the ink! you need to implement SpreadLayout, PackedLayout, and StorageLayout. You can derive implementation of those traits like here or implement it manually.

But after resolving issue maybe you need to derive other traits or use a macro. More details about the new version you can find with linked pull requests=)

1

Just derive this trait to Enum or use this code:

  impl SpreadLayout for Enum {
    const FOOTPRINT: u64 = 2;

    fn pull_spread(ptr: &mut KeyPtr) -> Self {
        Self::from(SpreadLayout::pull_spread(ptr))
    }

    fn push_spread(&self, ptr: &mut KeyPtr) {
        SpreadLayout::push_spread(self, ptr);
    }

    fn clear_spread(&self, ptr: &mut KeyPtr) {
        SpreadLayout::clear_spread(self, ptr);
    }
}

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.