Fix entries values decoding (#2011)
* Fix entries values decoding * Linting * Properly unwrap storage subs
This commit is contained in:
@@ -21,7 +21,7 @@ function queryClipped (api: ApiInterfaceRx, withActive?: boolean): Observable<[E
|
||||
// we could just do entries over the full set, however the set can be quite large - split it into
|
||||
// batches - may need to re-visit this, or alternatively use pages keys for exceptionally large sets
|
||||
allPoints.map(({ era }): Observable<[StorageKey, Exposure][]> =>
|
||||
api.query.staking.erasStakersClipped.entries(era)
|
||||
api.query.staking.erasStakers.entries(era)
|
||||
)
|
||||
)
|
||||
])
|
||||
|
||||
@@ -452,16 +452,16 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
))
|
||||
)
|
||||
.pipe(
|
||||
switchMap((keys): Observable<[StorageKey[], Codec[]]> =>
|
||||
switchMap((keys): Observable<[StorageKey[], Option<Codec>[]]> =>
|
||||
combineLatest([
|
||||
of(keys.map((key): StorageKey => key.decodeArgsFromMeta(meta))),
|
||||
this._rpcCore.state.subscribeStorage(keys)
|
||||
of(keys.map((key) => key.decodeArgsFromMeta(meta))),
|
||||
this._rpcCore.state.subscribeStorage<Option<Codec>[]>(keys)
|
||||
])
|
||||
),
|
||||
map(([keys, values]): [StorageKey, Codec][] =>
|
||||
keys.map((key, index): [StorageKey, Codec] => [
|
||||
key,
|
||||
this.createType(outputType, values[index])
|
||||
this.createType(outputType, values[index].unwrapOrDefault())
|
||||
])
|
||||
)
|
||||
);
|
||||
|
||||
@@ -5,12 +5,21 @@
|
||||
import { ApiPromise, WsProvider } from '@polkadot/api';
|
||||
|
||||
describe.skip('misc quick tests', (): void => {
|
||||
it.skip('handles doublemap entries', async (): Promise<void> => {
|
||||
const api = await new ApiPromise().isReady;
|
||||
const activeEra = await api.query.staking.activeEra();
|
||||
|
||||
console.log(JSON.stringify(
|
||||
await api.query.staking.erasStakers.entries(activeEra.unwrapOrDefault().index)
|
||||
));
|
||||
});
|
||||
|
||||
it.skip('does something in society', async (): Promise<void> => {
|
||||
const provider = new WsProvider('wss://kusama-rpc.polkadot.io');
|
||||
const api = await new ApiPromise({ provider }).isReady;
|
||||
|
||||
console.error(api.query.society.defenderVotes.creator.meta.toHuman());
|
||||
|
||||
await api.query.society.defenderVotes('Dab4bfYTZRUDMWjYAUQuFbDreQ9mt7nULWu3Dw7jodbzVe9');
|
||||
console.log(JSON.stringify(
|
||||
await api.query.society.defenderVotes('Dab4bfYTZRUDMWjYAUQuFbDreQ9mt7nULWu3Dw7jodbzVe9')
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -117,7 +117,7 @@ export default class Raw extends Uint8Array implements IU8a {
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
public toRawType (): string {
|
||||
return '&[u8]';
|
||||
return 'Raw';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
|
||||
describe('Exposure', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
it('properly decodes an Exposure', (): void => {
|
||||
expect(
|
||||
registry.createType('Exposure', '0x0fd2c5f6bc904d990f94373671da716d04fe65717dad0447d715f660a0a58411de509b42e6efb8375f562f58a554d5860e0f3e8ec04bb6db2b').toHuman()
|
||||
).toEqual({
|
||||
others: [{
|
||||
value: '12.344k Unit',
|
||||
who: '5HpG9w8EBLe5XCrbczpwq5TSXvedjrBGCwqxK1iQ7qUsSWFc'
|
||||
}],
|
||||
own: '30.805k Unit',
|
||||
total: '43.150k Unit'
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user