Add query.<sec>.<met>.{size, hash}(arg? any) (#630)

This commit is contained in:
Jaco Greeff
2019-01-25 11:33:53 +01:00
committed by GitHub
parent 32bd58ccc3
commit 98ea1f90a2
3 changed files with 18 additions and 8 deletions
+14 -6
View File
@@ -427,12 +427,20 @@ export default abstract class ApiBase<OnCall> implements ApiBaseInterface<OnCall
decorated.at = (hash: Hash, arg?: any): T =>
onCall(
arg => this._rpcRx.state
.getStorage([method, arg], hash)
.pipe(
// same as above (for single result), in the case of errors on creation, return `undefined`
catchError(() => of())
),
// same as above (for single result), in the case of errors on creation, return `undefined`
arg => this._rpcRx.state.getStorage([method, arg], hash).pipe(catchError(() => of())),
[arg]
);
decorated.hash = (arg?: any): T =>
onCall(
arg => this._rpcRx.state.getStorageSize([method, arg]).pipe(catchError(() => of())),
[arg]
);
decorated.size = (arg?: any): T =>
onCall(
arg => this._rpcRx.state.getStorageSize([method, arg]).pipe(catchError(() => of())),
[arg]
);
+2 -2
View File
@@ -8,10 +8,10 @@ import { QueryableStorageFunction as QueryableStorageFunctionBase, SubmittableEx
import ApiBase from '../Base';
import SubmittableExtrinsicBase from '../SubmittableExtrinsic';
export type OnCall = Promise<Codec | null | undefined> | PromiseSubscription;
export type PromiseSubscription = Promise<() => any>;
export type OnCall = Promise<Codec | null | undefined> | PromiseSubscription;
export interface ApiPromiseInterface extends ApiBase<OnCall> {
readonly isReady: Promise<ApiPromiseInterface>;
}
+2
View File
@@ -30,7 +30,9 @@ export interface DecoratedRpc<OnCall> {
interface QueryableStorageFunctionBase<OnCall> extends StorageFunction {
(arg?: any): OnCall;
at: (hash: Uint8Array | string, arg?: any) => OnCall;
hash: (arg?: any) => OnCall; // Observable<Hash>
key: (arg?: any) => string;
size: (arg?: any) => OnCall; // Observable<U64>
}
interface QueryableStorageFunctionPromise<OnCall> extends QueryableStorageFunctionBase<OnCall> {