polkadot.js: Unable to create Enum

1.8k views Asked by At

types.json:

{
  "WorkerId": {
    "_enum": {
      "Single": "Single",
      "Double": "Double"
    }
  },
  "Single": "u8",
  "Double": "(u8, u8)",
}

substrate code:

#[pallet::storage]
#[pallet::getter(fn worker_infos)]
pub type WorkerInfos<T: Config> = StorageMap<_, Twox64Concat, WorkerId, WorkerInfo, ValueQuery>;


pub enum WorkerId {
    Single(u8),
    Double(u8, u8),
}

I want to query worker_infos by WorkerId in polkadot.js:

    workerIds = [1,2]
    api.query[wrpc][wcallable]
      .multi(workerIds, (results) => {
        ...
      })
      .then((unsub) => {
        ...
      })
      .catch(console.error);

Error info:

REGISTRY: Error: Unable to create Enum via index 2, in Single, Double

Any ideas on this? How to pass workerIds(enum type) in polkadot.js?

1

There are 1 answers

0
dev-for-fun On

{ Single: 1 } or { Double: [2, 3] }