Basic same-type multi queries (#866)
* Basic same-type multi queries * Remove extra map, straight to switchMap
This commit is contained in:
@@ -548,16 +548,22 @@ export default abstract class ApiBase<CodecResult, SubscriptionResult> implement
|
||||
[arg]
|
||||
) as unknown as HashResult<C, S>;
|
||||
|
||||
// FIXME as above...
|
||||
decorated.key = (arg?: CodecArg): string =>
|
||||
u8aToHex(compactStripLength(method(arg))[1]);
|
||||
|
||||
decorated.multi = (args: Array<CodecArg>, callback?: CodecCallback): S =>
|
||||
onCall(
|
||||
() => this._rpcRx.state.subscribeStorage(args.map((arg) => [method, arg])),
|
||||
[],
|
||||
callback
|
||||
) as unknown as S;
|
||||
|
||||
decorated.size = (arg?: CodecArg): U64Result<C, S> =>
|
||||
onCall(
|
||||
(arg: CodecArg) => this._rpcRx.state.getStorageSize([method, arg]),
|
||||
[arg]
|
||||
) as unknown as U64Result<C, S>;
|
||||
|
||||
decorated.key = (arg?: CodecArg): string =>
|
||||
u8aToHex(compactStripLength(method(arg))[1]);
|
||||
|
||||
return this.decorateFunctionMeta(method, decorated) as QueryableStorageFunction<C, S>;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ export interface QueryableStorageFunctionBase<CodecResult, SubscriptionResult> e
|
||||
at: (hash: Hash | Uint8Array | string, arg?: CodecArg) => CodecResult;
|
||||
hash: (arg?: CodecArg) => HashResult<CodecResult, SubscriptionResult>;
|
||||
key: (arg?: CodecArg) => string;
|
||||
multi: (args: Array<CodecArg>, callback?: CodecCallback) => SubscriptionResult;
|
||||
size: (arg?: CodecArg) => U64Result<CodecResult, SubscriptionResult>;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,21 @@ describe.skip('e2e queries', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('subscribes to multiple results (freeBalance.multi)', (done) => {
|
||||
api.query.balances.freeBalance.multi([
|
||||
keyring.alice.address(),
|
||||
keyring.bob.address(),
|
||||
keyring.ferdie.address(),
|
||||
'5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE'
|
||||
], (balances) => {
|
||||
expect(balances).toHaveLength(4);
|
||||
|
||||
console.error(balances);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('makes a query at a specific block', async () => {
|
||||
const header = await api.rpc.chain.getHeader();
|
||||
const events = await api.query.system.events.at(header.hash);
|
||||
|
||||
Reference in New Issue
Block a user