Fix range & entries with Option decoding (#2023)
This commit is contained in:
@@ -344,7 +344,11 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
|||||||
}
|
}
|
||||||
|
|
||||||
private decorateStorageRange<ApiType extends ApiTypes> (decorated: QueryableStorageEntry<ApiType>, args: [Arg?, Arg?], range: [Hash, Hash?]): Observable<[Hash, Codec][]> {
|
private decorateStorageRange<ApiType extends ApiTypes> (decorated: QueryableStorageEntry<ApiType>, args: [Arg?, Arg?], range: [Hash, Hash?]): Observable<[Hash, Codec][]> {
|
||||||
const outputType = unwrapStorageType(decorated.creator.meta.type);
|
let outputType: any = unwrapStorageType(decorated.creator.meta.type);
|
||||||
|
|
||||||
|
if (decorated.creator.meta.modifier.isOptional) {
|
||||||
|
outputType = `Option<${outputType}>`;
|
||||||
|
}
|
||||||
|
|
||||||
return this._rpcCore.state
|
return this._rpcCore.state
|
||||||
.queryStorage([decorated.key(...args)], ...range)
|
.queryStorage([decorated.key(...args)], ...range)
|
||||||
@@ -353,7 +357,7 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
|||||||
.filter((change): change is StorageChangeSet => !!change.changes.length)
|
.filter((change): change is StorageChangeSet => !!change.changes.length)
|
||||||
.map(({ block, changes: [[, value]] }): [Hash, Codec] => [
|
.map(({ block, changes: [[, value]] }): [Hash, Codec] => [
|
||||||
block,
|
block,
|
||||||
this.createType(outputType, value.unwrapOrDefault())
|
this.createType(outputType, value.isSome ? value.unwrap().toHex() : undefined)
|
||||||
])
|
])
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -464,7 +468,7 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
|||||||
map(([keys, values]): [StorageKey, Codec][] =>
|
map(([keys, values]): [StorageKey, Codec][] =>
|
||||||
keys.map((key, index): [StorageKey, Codec] => [
|
keys.map((key, index): [StorageKey, Codec] => [
|
||||||
key,
|
key,
|
||||||
this.createType(outputType, values[index].unwrapOr(undefined))
|
this.createType(outputType, values[index].isSome ? values[index].unwrap().toHex() : undefined)
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -17,6 +17,15 @@ describe.skip('misc quick tests', (): void => {
|
|||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.skip('handles map entries', async (): Promise<void> => {
|
||||||
|
const provider = new WsProvider('wss://kusama-rpc.polkadot.io');
|
||||||
|
const api = await new ApiPromise({ provider }).isReady;
|
||||||
|
|
||||||
|
console.error(JSON.stringify(
|
||||||
|
await api.query.indices.accounts.entries()
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
it.skip('handles doublemap entries', async (): Promise<void> => {
|
it.skip('handles doublemap entries', async (): Promise<void> => {
|
||||||
const api = await new ApiPromise().isReady;
|
const api = await new ApiPromise().isReady;
|
||||||
const activeEra = await api.query.staking.activeEra();
|
const activeEra = await api.query.staking.activeEra();
|
||||||
|
|||||||
Reference in New Issue
Block a user