2

BoundedVec is a vector where the length of the queue is always bounded, which is better than Vec for storage because it has a defined a maximum length. I recommend this StackExchange questions to learn the difference between BoundedVec and Vec: When to use BoundedVec vs. WeakBoundedVec vs. Vec?

Vec is okay to use in the runtime, but never to put into storage, since it is unbounded by definition.

In my Smart Contract I want to store a struct that contains a Vec.

What is the best practice here?

1 Answer 1

3

You can store Vec in contract's storage which can grow over time. storage_deposit_limit specifies the max amount of storage your contract can use.

If you want to explicitly limit the size of the Vec, you can store either a constant or another storage item max_size where you specify the max number of elements your list can have. Then in the message, you can add the check whenever new element is to be pushed and if the limit is reached, you can return an error with sensible message.

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.