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 { StorageFunction } from '@polkadot/types/StorageKey';
|
||||
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';
|
||||
|
||||
@@ -410,9 +410,8 @@ export default abstract class ApiBase<OnCall> implements ApiBaseInterface<OnCall
|
||||
method: StorageFunction,
|
||||
onCall: (method: OnCallFunction<Observable<Codec | undefined | null>>, params: Array<any>, isSubscription?: boolean) => T
|
||||
): QueryableStorageFunction<T> {
|
||||
const decorated: any = (...args: any): T => {
|
||||
|
||||
return onCall(
|
||||
const decorated: any = (...args: any): T =>
|
||||
onCall(
|
||||
(...args: any) => this._rpcRx.state
|
||||
.subscribeStorage([[method, args[0]]])
|
||||
.pipe(
|
||||
@@ -426,7 +425,6 @@ export default abstract class ApiBase<OnCall> implements ApiBaseInterface<OnCall
|
||||
),
|
||||
args
|
||||
);
|
||||
};
|
||||
|
||||
decorated.at = (hash: Hash, arg?: any): T =>
|
||||
onCall(
|
||||
@@ -439,6 +437,9 @@ export default abstract class ApiBase<OnCall> implements ApiBaseInterface<OnCall
|
||||
[arg]
|
||||
);
|
||||
|
||||
decorated.key = (arg?: any): string =>
|
||||
u8aToHex(compactStripLength(method(arg))[1]);
|
||||
|
||||
return this.decorateFunctionMeta(method, decorated) as QueryableStorageFunction<T>;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ export interface DecoratedRpc<OnCall> {
|
||||
export interface QueryableStorageFunction<OnCall> extends StorageFunction {
|
||||
(arg?: any): OnCall;
|
||||
at: (hash: Uint8Array | string, arg?: any) => OnCall;
|
||||
key: (arg?: any) => string;
|
||||
}
|
||||
|
||||
export interface QueryableModuleStorage<OnCall> {
|
||||
|
||||
Reference in New Issue
Block a user