Add state_queryStorageAt RPC (#2082)
* Add state_queryStorageAt RPC * Add queryStorageAt rpc * Clanup merge
This commit is contained in:
@@ -201,6 +201,10 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
|
||||
* Query historical storage entries (by key) starting from a start block
|
||||
**/
|
||||
queryStorage: AugmentedRpc<<T = Codec[]>(keys: Vec<StorageKey> | (StorageKey | string | Uint8Array | any)[], fromBlock?: Hash | Uint8Array | string, toBlock?: Hash | Uint8Array | string) => Observable<[Hash, T][]>>;
|
||||
/**
|
||||
* Query storage entries (by key) starting at block hash given as the second parameter
|
||||
**/
|
||||
queryStorageAt: AugmentedRpc<<T = Codec[]>(keys: Vec<StorageKey> | (StorageKey | string | Uint8Array | any)[], at?: Hash | Uint8Array | string) => Observable<T>>;
|
||||
/**
|
||||
* Retrieves the runtime version via subscription
|
||||
**/
|
||||
|
||||
@@ -188,7 +188,7 @@ export default class Rpc implements RpcInterface {
|
||||
map(([params, result]): any =>
|
||||
isRaw
|
||||
? this.registry.createType('Raw', result)
|
||||
: this.formatOutput(def, params, result)
|
||||
: this.formatOutput(method, def, params, result)
|
||||
),
|
||||
catchError((error): any => {
|
||||
logErrorMessage(method, def, error);
|
||||
@@ -247,7 +247,7 @@ export default class Rpc implements RpcInterface {
|
||||
observer.next(
|
||||
isRaw
|
||||
? this.registry.createType('Raw', result)
|
||||
: this.formatOutput(def, params, result)
|
||||
: this.formatOutput(method, def, params, result)
|
||||
);
|
||||
} catch (error) {
|
||||
observer.error(error);
|
||||
@@ -317,7 +317,7 @@ export default class Rpc implements RpcInterface {
|
||||
return ['0x3a636f6465'].includes(key.toHex());
|
||||
}
|
||||
|
||||
private formatOutput (rpc: DefinitionRpc, params: Codec[], result?: any): Codec | Codec[] {
|
||||
private formatOutput (method: string, rpc: DefinitionRpc, params: Codec[], result?: any): Codec | Codec[] {
|
||||
if (rpc.type === 'StorageData') {
|
||||
const key = params[0] as StorageKey;
|
||||
|
||||
@@ -331,10 +331,15 @@ export default class Rpc implements RpcInterface {
|
||||
} else if (rpc.type === 'StorageChangeSet') {
|
||||
return this.formatStorageSet(params[0] as Vec<StorageKey>, result.changes);
|
||||
} else if (rpc.type === 'Vec<StorageChangeSet>') {
|
||||
return result.map(({ block, changes }: { block: string; changes: [string, string | null][] }): [Hash, Codec[]] => [
|
||||
const mapped = result.map(({ block, changes }: { block: string; changes: [string, string | null][] }): [Hash, Codec[]] => [
|
||||
this.registry.createType('Hash', block),
|
||||
this.formatStorageSet(params[0] as Vec<StorageKey>, changes)
|
||||
]);
|
||||
|
||||
// we only query at a specific block, not a range - flatten
|
||||
return method === 'queryStorageAt'
|
||||
? mapped[0][1]
|
||||
: mapped;
|
||||
}
|
||||
|
||||
return createTypeUnsafe(this.registry, rpc.type, [result]);
|
||||
|
||||
@@ -34,6 +34,8 @@ export default function generateRpcTypes (dest = 'packages/api/src/augment/rpc.t
|
||||
return createDocComments(6, [def.description]) + indent(6)(`getStorage: AugmentedRpc<<T = Codec>(key: ${StorageKeyTye}, block?: Hash | Uint8Array | string) => Observable<T>>;`);
|
||||
} else if (methodName === 'queryStorage') {
|
||||
return createDocComments(6, [def.description]) + indent(6)(`queryStorage: AugmentedRpc<<T = Codec[]>(keys: Vec<StorageKey> | (${StorageKeyTye})[], fromBlock?: Hash | Uint8Array | string, toBlock?: Hash | Uint8Array | string) => Observable<[Hash, T][]>>;`);
|
||||
} else if (methodName === 'queryStorageAt') {
|
||||
return createDocComments(6, [def.description]) + indent(6)(`queryStorageAt: AugmentedRpc<<T = Codec[]>(keys: Vec<StorageKey> | (${StorageKeyTye})[], at?: Hash | Uint8Array | string) => Observable<T>>;`);
|
||||
} else if (methodName === 'subscribeStorage') {
|
||||
return createDocComments(6, [def.description]) + indent(6)(`subscribeStorage: AugmentedRpc<<T = Codec[]>(keys: Vec<StorageKey> | (${StorageKeyTye})[]) => Observable<T>>;`);
|
||||
}
|
||||
|
||||
@@ -268,9 +268,24 @@ export default {
|
||||
type: 'Vec<StorageKey>'
|
||||
},
|
||||
{
|
||||
name: 'startBlock',
|
||||
name: 'fromBlock',
|
||||
type: 'Hash'
|
||||
},
|
||||
{
|
||||
name: 'toBlock',
|
||||
type: 'BlockHash',
|
||||
isOptional: true
|
||||
}
|
||||
],
|
||||
type: 'Vec<StorageChangeSet>'
|
||||
},
|
||||
queryStorageAt: {
|
||||
description: 'Query storage entries (by key) starting at block hash given as the second parameter',
|
||||
params: [
|
||||
{
|
||||
name: 'keys',
|
||||
type: 'Vec<StorageKey>'
|
||||
},
|
||||
{
|
||||
name: 'at',
|
||||
type: 'BlockHash',
|
||||
|
||||
Reference in New Issue
Block a user