Add api.query.<section>.<method>.key(...) => string (#615)
This commit is contained in:
@@ -26,7 +26,7 @@ import { Event, Hash, Metadata, Method, RuntimeVersion } from '@polkadot/types/i
|
|||||||
import { MethodFunction, ModulesWithMethods } from '@polkadot/types/Method';
|
import { MethodFunction, ModulesWithMethods } from '@polkadot/types/Method';
|
||||||
import { StorageFunction } from '@polkadot/types/StorageKey';
|
import { StorageFunction } from '@polkadot/types/StorageKey';
|
||||||
import { Codec } from '@polkadot/types/types';
|
import { Codec } from '@polkadot/types/types';
|
||||||
import { assert, isFunction, isObject, isUndefined, logger } from '@polkadot/util';
|
import { assert, compactStripLength, isFunction, isObject, isUndefined, logger, u8aToHex } from '@polkadot/util';
|
||||||
|
|
||||||
import SubmittableExtrinsic from './SubmittableExtrinsic';
|
import SubmittableExtrinsic from './SubmittableExtrinsic';
|
||||||
|
|
||||||
@@ -410,9 +410,8 @@ export default abstract class ApiBase<OnCall> implements ApiBaseInterface<OnCall
|
|||||||
method: StorageFunction,
|
method: StorageFunction,
|
||||||
onCall: (method: OnCallFunction<Observable<Codec | undefined | null>>, params: Array<any>, isSubscription?: boolean) => T
|
onCall: (method: OnCallFunction<Observable<Codec | undefined | null>>, params: Array<any>, isSubscription?: boolean) => T
|
||||||
): QueryableStorageFunction<T> {
|
): QueryableStorageFunction<T> {
|
||||||
const decorated: any = (...args: any): T => {
|
const decorated: any = (...args: any): T =>
|
||||||
|
onCall(
|
||||||
return onCall(
|
|
||||||
(...args: any) => this._rpcRx.state
|
(...args: any) => this._rpcRx.state
|
||||||
.subscribeStorage([[method, args[0]]])
|
.subscribeStorage([[method, args[0]]])
|
||||||
.pipe(
|
.pipe(
|
||||||
@@ -426,7 +425,6 @@ export default abstract class ApiBase<OnCall> implements ApiBaseInterface<OnCall
|
|||||||
),
|
),
|
||||||
args
|
args
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
decorated.at = (hash: Hash, arg?: any): T =>
|
decorated.at = (hash: Hash, arg?: any): T =>
|
||||||
onCall(
|
onCall(
|
||||||
@@ -439,6 +437,9 @@ export default abstract class ApiBase<OnCall> implements ApiBaseInterface<OnCall
|
|||||||
[arg]
|
[arg]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
decorated.key = (arg?: any): string =>
|
||||||
|
u8aToHex(compactStripLength(method(arg))[1]);
|
||||||
|
|
||||||
return this.decorateFunctionMeta(method, decorated) as QueryableStorageFunction<T>;
|
return this.decorateFunctionMeta(method, decorated) as QueryableStorageFunction<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export interface DecoratedRpc<OnCall> {
|
|||||||
export interface QueryableStorageFunction<OnCall> extends StorageFunction {
|
export interface QueryableStorageFunction<OnCall> extends StorageFunction {
|
||||||
(arg?: any): OnCall;
|
(arg?: any): OnCall;
|
||||||
at: (hash: Uint8Array | string, arg?: any) => OnCall;
|
at: (hash: Uint8Array | string, arg?: any) => OnCall;
|
||||||
|
key: (arg?: any) => string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface QueryableModuleStorage<OnCall> {
|
export interface QueryableModuleStorage<OnCall> {
|
||||||
|
|||||||
Reference in New Issue
Block a user