Fix range & entries with Option decoding (#2023)

This commit is contained in:
Jaco Greeff
2020-03-10 19:44:50 +01:00
committed by GitHub
parent cacafab912
commit 60c982ed95
2 changed files with 16 additions and 3 deletions
+7 -3
View File
@@ -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)
]) ])
) )
); );
+9
View File
@@ -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();