3

1 the runtime storage order type as follow:

// Order storage
    #[pallet::storage]
    #[pallet::getter(fn order)]
    pub type Orders<T: Config<I>, I: 'static = ()> = StorageMap<
        _,
        Blake2_128Concat,
        (LaneId, MessageNonce),
        Order<T::AccountId, T::BlockNumber, RingBalance<T, I>>,
        OptionQuery,
    >;

the auto-generated querying JS api as follow:

      orders: AugmentedQuery<ApiType, (arg: ITuple<[LaneId, MessageNonce]> | [LaneId | string | Uint8Array, MessageNonce | AnyNumber | Uint8Array]) => Observable<Option<Order>>, [ITuple<[LaneId, MessageNonce]>]> & QueryableStorageEntry<ApiType, [ITuple<[LaneId, MessageNonce]>]>;

the client orders api can only query part of orders from parameters.

my question is that is there any way to query all orders from storage?

1 Answer 1

5

You should be able to use entries to get all the key value pairs from a map.

See the polkdot.js docs here: https://polkadot.js.org/docs/api/start/api.query.other#map-keys--entries

The below is taken from the above link:

When working maps and double-maps, it is possible to retrieve a list of all the keys and entries for the map. For this we can use the .entries(): [StorageKey, Type][] queries. For example we may want to know the current list of validator exposures at a current era in the staking module -

...
// Retrieve the active era
const activeEra = await api.query.staking.activeEra();

// retrieve all exposures for the active era
const exposures = await api.query.staking.erasStakers.entries(activeEra.index);

exposures.forEach(([key, exposure]) => {
  console.log('key arguments:', key.args.map((k) => k.toHuman()));
  console.log('     exposure:', exposure.toHuman());
});

To understand the usage of the key.args, you need to understand that map/doublemap keys are stored alongside their lookups. This means that the raw key has hashed parts as well as the raw data. The API will decode the keys and provide the raw key arguments in args. This would mean if we are querying api.query.staking.validators(validatorId: AccountId) via entries, the key.args would be [AccountId] if we are querying api.query.staking.erasStakers(era: EraIndex, validatorId: AccountId) via entries, the key.args would be [EraIndex, AccountId]

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.