Using vectors on predicate configurable

I currently have a predicate with some configurable ones, and one of them is an array of type [b256;10].


This is a problem if I want to have this array with non-zero lengths.

How could I use a vector in these configurables?

Remembering that configurables cannot receive values that have not yet been instantiated, such as (ref):

SIGNERS: Vec<b256> = Vec::new()

You can instantiate an empty vec with Sway by Example
SIGNERS_VEC: StorageVec<u64> = StorageVec {}


use std::{storage::storage_vec::*};

configurable {
    SIGNERS: [Address; 3] = [
    SIGNERS_VEC: StorageVec<u64> = StorageVec {},

fn main() -> bool {
1 Like

Hmmm, StorageVec is meant to be used only in the storage. Having it as a configurable just puts an empty struct in the configurable and that struct cannot be changed any more.
In general, configurables must have a size known at the compile time. That’s why we cannot store dynamic structures there.
What is your exact use case? Do you know the upper bound of the signers? E.g. knowing there will be no more then 10. Then you can have a configurable tuple where the first element would be the actual count e.g. SIGNERS: (u8, [b256;10]) = [ all zeros ]. In the SDK you can then set the SIGNERS.0 to e.g. 3 and fill the first three elements of the array and left others to be zero.

Just heard back from the sway team and according to them, at the moment, we do not support “dynamic types” on configurable. It is something we are aiming for in the “near future”. Especially because it seems necessary in some cases. But using two configurable: (len, array) is the best workaround we have at the moment.

1 Like

Great suggestion, seems to work well for me
thanks :slight_smile:

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.