Acc contracts_getStorage (#1603)

This commit is contained in:
Jaco Greeff
2019-11-23 22:29:33 +01:00
committed by GitHub
parent 49b3104d04
commit db59fbff25
9 changed files with 62 additions and 39 deletions
+21 -20
View File
@@ -2,11 +2,11 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import { Observable } from 'rxjs';
import { Vec } from '@polkadot/types/codec';
import { Bytes, Metadata, StorageData, StorageKey, Text, u64 } from '@polkadot/types';
import { Option, Vec } from '@polkadot/types/codec';
import { Bytes, H256, Metadata, StorageData, StorageKey, Text, u64 } from '@polkadot/types';
import { AccountId, BlockNumber, Extrinsic, Hash, Header, Index, SignedBlock } from '@polkadot/types/interfaces/runtime';
import { ContractCallRequest, ContractExecResult } from '@polkadot/types/interfaces/contracts';
import { ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, NetworkState, PeerInfo, RpcMethods, RuntimeDispatchInfo, RuntimeVersion, StorageChangeSet } from '@polkadot/types/interfaces/rpc';
import { BlockHash, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, NetworkState, PeerInfo, RpcMethods, RuntimeDispatchInfo, RuntimeVersion, StorageChangeSet } from '@polkadot/types/interfaces/rpc';
import { Codec, IExtrinsic } from '@polkadot/types/types';
export interface RpcInterface {
@@ -22,35 +22,36 @@ export interface RpcInterface {
submitExtrinsic(extrinsic: IExtrinsic): Observable<Hash>;
};
chain: {
getBlock(hash?: Hash | Uint8Array | string): Observable<SignedBlock>;
getBlockHash(blockNumber?: BlockNumber | Uint8Array | number | string): Observable<Hash>;
getFinalizedHead(): Observable<Hash>;
getHeader(hash?: Hash | Uint8Array | string): Observable<Header>;
getBlock(hash?: BlockHash | Uint8Array | string): Observable<SignedBlock>;
getBlockHash(blockNumber?: BlockNumber | Uint8Array | number | string): Observable<BlockHash>;
getFinalizedHead(): Observable<BlockHash>;
getHeader(hash?: BlockHash | Uint8Array | string): Observable<Header>;
subscribeFinalizedHeads(): Observable<Header>;
subscribeNewHeads(): Observable<Header>;
};
contracts: {
call(callRequest: ContractCallRequest, at?: Hash | Uint8Array | string): Observable<ContractExecResult>;
call(callRequest: ContractCallRequest, at?: BlockHash | Uint8Array | string): Observable<ContractExecResult>;
getStorage(address: AccountId | Uint8Array | string, key: H256 | Uint8Array | string, at?: BlockHash | Uint8Array | string): Observable<Option<Bytes>>;
};
payment: {
queryInfo(extrinsic: Bytes | Uint8Array | string, hash?: Hash | Uint8Array | string): Observable<RuntimeDispatchInfo>;
queryInfo(extrinsic: Bytes | Uint8Array | string, at?: BlockHash | Uint8Array | string): Observable<RuntimeDispatchInfo>;
};
rpc: {
methods(): Observable<RpcMethods>;
};
state: {
call(method: Text | string, data: Bytes | Uint8Array | string, block?: Hash | Uint8Array | string): Observable<Bytes>;
getChildKeys(childStorageKey: any, key: any, block?: Hash | Uint8Array | string): Observable<Vec<StorageKey>>;
getChildStorage(childStorageKey: any, key: any, block?: Hash | Uint8Array | string): Observable<StorageData>;
getChildStorageHash(childStorageKey: any, key: any, block?: Hash | Uint8Array | string): Observable<Hash>;
getChildStorageSize(childStorageKey: any, key: any, block?: Hash | Uint8Array | string): Observable<u64>;
getKeys(key: any, block?: Hash | Uint8Array | string): Observable<Vec<StorageKey>>;
getMetadata(block?: Hash | Uint8Array | string): Observable<Metadata>;
getRuntimeVersion(hash?: Hash | Uint8Array | string): Observable<RuntimeVersion>;
call(method: Text | string, data: Bytes | Uint8Array | string, at?: BlockHash | Uint8Array | string): Observable<Bytes>;
getChildKeys(childStorageKey: any, key: any, at?: BlockHash | Uint8Array | string): Observable<Vec<StorageKey>>;
getChildStorage(childStorageKey: any, key: any, at?: BlockHash | Uint8Array | string): Observable<StorageData>;
getChildStorageHash(childStorageKey: any, key: any, at?: BlockHash | Uint8Array | string): Observable<Hash>;
getChildStorageSize(childStorageKey: any, key: any, at?: BlockHash | Uint8Array | string): Observable<u64>;
getKeys(key: any, at?: BlockHash | Uint8Array | string): Observable<Vec<StorageKey>>;
getMetadata(at?: BlockHash | Uint8Array | string): Observable<Metadata>;
getRuntimeVersion(at?: BlockHash | Uint8Array | string): Observable<RuntimeVersion>;
getStorage<T = Codec>(key: any, block?: Hash | Uint8Array | string): Observable<T>;
getStorageHash(key: any, block?: Hash | Uint8Array | string): Observable<Hash>;
getStorageSize(key: any, block?: Hash | Uint8Array | string): Observable<u64>;
queryStorage(keys: (any)[], startBlock: Hash | Uint8Array | string, block?: Hash | Uint8Array | string): Observable<Vec<StorageChangeSet>>;
getStorageHash(key: any, at?: BlockHash | Uint8Array | string): Observable<Hash>;
getStorageSize(key: any, at?: BlockHash | Uint8Array | string): Observable<u64>;
queryStorage(keys: (any)[], startBlock: Hash | Uint8Array | string, at?: BlockHash | Uint8Array | string): Observable<Vec<StorageChangeSet>>;
subscribeRuntimeVersion(): Observable<RuntimeVersion>;
subscribeStorage<T = Codec[]>(keys: any[]): Observable<T>;
};
+4 -4
View File
@@ -12,7 +12,7 @@ import createParam from './create/param';
const getHeader: RpcMethodOpt = {
description: 'Retrieves the header for a specific block',
params: [
createParam('hash', 'Hash', { isOptional: true })
createParam('hash', 'BlockHash', { isOptional: true })
],
type: 'Header'
};
@@ -20,7 +20,7 @@ const getHeader: RpcMethodOpt = {
const getBlock: RpcMethodOpt = {
description: 'Get header and body of a relay chain block',
params: [
createParam('hash', 'Hash', { isOptional: true })
createParam('hash', 'BlockHash', { isOptional: true })
],
type: 'SignedBlock'
};
@@ -30,13 +30,13 @@ const getBlockHash: RpcMethodOpt = {
params: [
createParam('blockNumber', 'BlockNumber', { isOptional: true })
],
type: 'Hash'
type: 'BlockHash'
};
const getFinalizedHead: RpcMethodOpt = {
description: 'Get hash of the last finalized block in the canon chain',
params: [],
type: 'Hash'
type: 'BlockHash'
};
const subscribeNewHeads: RpcMethodOpt = {
+14 -2
View File
@@ -14,11 +14,22 @@ const call: RpcMethodOpt = {
isOptional: true,
params: [
createParam('callRequest', 'ContractCallRequest'),
createParam('at', 'Hash', { isOptional: true })
createParam('at', 'BlockHash', { isOptional: true })
],
type: 'ContractExecResult'
};
const getStorage: RpcMethodOpt = {
description: 'Returns the value under a specified storage key in a contract',
isOptional: true,
params: [
createParam('address', 'AccountId'),
createParam('key', 'H256'),
createParam('at', 'BlockHash', { isOptional: true })
],
type: 'Option<Bytes>'
};
const section = 'contracts';
/**
@@ -30,6 +41,7 @@ export default {
description: '(Optional) Methods that performs actions on contracts',
section,
methods: {
call: createMethod(section, 'call', call)
call: createMethod(section, 'call', call),
getStorage: createMethod(section, 'getStorage', getStorage)
}
};
+2 -1
View File
@@ -11,9 +11,10 @@ import createParam from './create/param';
const queryInfo: RpcMethodOpt = {
description: 'Retrieves the fee information for an encoded extrinsic',
isOptional: true,
params: [
createParam('extrinsic', 'Bytes'),
createParam('hash', 'Hash', { isOptional: true })
createParam('at', 'BlockHash', { isOptional: true })
],
type: 'RuntimeDispatchInfo'
};
+6 -6
View File
@@ -14,14 +14,14 @@ const call: RpcMethodOpt = {
params: [
createParam('method', 'Text'),
createParam('data', 'Bytes'),
createParam('block', 'Hash', { isOptional: true })
createParam('at', 'BlockHash', { isOptional: true })
],
type: 'Bytes'
};
const KEY_QUERY_PARAMS = [
createParam('key', 'StorageKey'),
createParam('block', 'Hash', { isOptional: true })
createParam('at', 'BlockHash', { isOptional: true })
];
const getKeys: RpcMethodOpt = {
@@ -51,7 +51,7 @@ const getStorageSize: RpcMethodOpt = {
const CHILD_QUERY_PARAMS = [
createParam('childStorageKey', 'StorageKey'),
createParam('key', 'StorageKey'),
createParam('block', 'Hash', { isOptional: true })
createParam('at', 'BlockHash', { isOptional: true })
];
const getChildKeys: RpcMethodOpt = {
@@ -81,7 +81,7 @@ const getChildStorageSize: RpcMethodOpt = {
const getMetadata: RpcMethodOpt = {
description: 'Returns the runtime metadata',
params: [
createParam('block', 'Hash', { isOptional: true })
createParam('at', 'BlockHash', { isOptional: true })
],
// This is not part of InterfaceTypes
type: 'Metadata' as any
@@ -90,7 +90,7 @@ const getMetadata: RpcMethodOpt = {
const getRuntimeVersion: RpcMethodOpt = {
description: 'Get the runtime version',
params: [
createParam('hash', 'Hash', { isOptional: true })
createParam('at', 'BlockHash', { isOptional: true })
],
type: 'RuntimeVersion'
};
@@ -100,7 +100,7 @@ const queryStorage: RpcMethodOpt = {
params: [
createParam('keys', 'Vec<StorageKey>'),
createParam('startBlock', 'Hash'),
createParam('block', 'Hash', { isOptional: true })
createParam('at', 'BlockHash', { isOptional: true })
],
type: 'Vec<StorageChangeSet>'
};
+4 -1
View File
@@ -28,7 +28,7 @@ import { BlockAttestations, IncludedBlocks, MoreAttestations } from '@polkadot/t
import { EthereumAddress } from '@polkadot/types/interfaces/claims';
import { AttestedCandidate, AuctionIndex, BalanceUpload, Bidder, CandidateReceipt, CollatorId, CollatorSignature, EgressQueueRoot, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, NewBidder, ParaId, ParaIdOf, ParaInfo, ParaScheduling, ParachainDispatchOrigin, Retriable, SlotRange, SubId, UpwardMessage, ValidatorIndex, ValidityAttestation, ValidityVote, WinningData, WinningDataEntry } from '@polkadot/types/interfaces/parachains';
import { CallMetadataV0, DoubleMapTypeV3, DoubleMapTypeV4, DoubleMapTypeV5, DoubleMapTypeV6, DoubleMapTypeV7, DoubleMapTypeV8, ErrorMetadataV8, EventMetadataLatest, EventMetadataV0, EventMetadataV1, EventMetadataV2, EventMetadataV3, EventMetadataV4, EventMetadataV5, EventMetadataV6, EventMetadataV7, EventMetadataV8, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV0, FunctionArgumentMetadataV1, FunctionArgumentMetadataV2, FunctionArgumentMetadataV3, FunctionArgumentMetadataV4, FunctionArgumentMetadataV5, FunctionArgumentMetadataV6, FunctionArgumentMetadataV7, FunctionArgumentMetadataV8, FunctionMetadataLatest, FunctionMetadataV0, FunctionMetadataV1, FunctionMetadataV2, FunctionMetadataV3, FunctionMetadataV4, FunctionMetadataV5, FunctionMetadataV6, FunctionMetadataV7, FunctionMetadataV8, MapTypeV0, MapTypeV2, MapTypeV3, MapTypeV4, MapTypeV5, MapTypeV6, MapTypeV7, MapTypeV8, MetadataLatest, MetadataV0, MetadataV1, MetadataV2, MetadataV3, MetadataV4, MetadataV5, MetadataV6, MetadataV7, MetadataV8, ModuleConstantMetadataLatest, ModuleConstantMetadataV6, ModuleConstantMetadataV7, ModuleConstantMetadataV8, ModuleMetadataLatest, ModuleMetadataV0, ModuleMetadataV1, ModuleMetadataV2, ModuleMetadataV3, ModuleMetadataV4, ModuleMetadataV5, ModuleMetadataV6, ModuleMetadataV7, ModuleMetadataV8, OuterDispatchCallV0, OuterDispatchMetadataV0, OuterEventEventMetadataEventsV0, OuterEventEventMetadataV0, OuterEventMetadataV0, PlainTypeLatest, PlainTypeV0, PlainTypeV2, PlainTypeV3, PlainTypeV4, PlainTypeV5, PlainTypeV6, PlainTypeV7, PlainTypeV8, RuntimeModuleMetadataV0, StorageEntryMetadataLatest, StorageEntryMetadataV6, StorageEntryMetadataV7, StorageEntryMetadataV8, StorageEntryModifierLatest, StorageEntryModifierV6, StorageEntryModifierV7, StorageEntryModifierV8, StorageEntryTypeLatest, StorageEntryTypeV6, StorageEntryTypeV7, StorageEntryTypeV8, StorageFunctionMetadataV0, StorageFunctionMetadataV1, StorageFunctionMetadataV2, StorageFunctionMetadataV3, StorageFunctionMetadataV4, StorageFunctionMetadataV5, StorageFunctionModifierV0, StorageFunctionModifierV1, StorageFunctionModifierV2, StorageFunctionModifierV3, StorageFunctionModifierV4, StorageFunctionModifierV5, StorageFunctionTypeV0, StorageFunctionTypeV1, StorageFunctionTypeV2, StorageFunctionTypeV3, StorageFunctionTypeV4, StorageFunctionTypeV5, StorageMetadataV0, StorageMetadataV7, StorageMetadataV8 } from '@polkadot/types/interfaces/metadata';
import { ApiId, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, KeyValueOption, NetworkState, PeerInfo, RpcMethods, RuntimeDispatchInfo, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from '@polkadot/types/interfaces/rpc';
import { ApiId, BlockHash, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, KeyValueOption, NetworkState, PeerInfo, RpcMethods, RuntimeDispatchInfo, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from '@polkadot/types/interfaces/rpc';
export interface InterfaceRegistry {
bool: bool;
@@ -1162,6 +1162,9 @@ export interface InterfaceRegistry {
ApiId: ApiId;
'Option<ApiId>': Option<ApiId>;
'Vec<ApiId>': Vec<ApiId>;
BlockHash: BlockHash;
'Option<BlockHash>': Option<BlockHash>;
'Vec<BlockHash>': Vec<BlockHash>;
ChainProperties: ChainProperties;
'Option<ChainProperties>': Option<ChainProperties>;
'Vec<ChainProperties>': Vec<ChainProperties>;
@@ -5,6 +5,7 @@
export default {
types: {
ApiId: '[u8; 8]',
BlockHash: 'Hash',
ChainProperties: {
ss58Format: 'Option<u8>',
tokenDecimals: 'Option<u32>',
@@ -9,6 +9,9 @@ import { Balance, BlockNumber, DispatchClass, Hash, Weight } from '@polkadot/typ
/** Uint8Array, Codec */
export interface ApiId extends Uint8Array, Codec {}
/** Hash */
export interface BlockHash extends Hash {}
/** Struct */
export interface ChainProperties extends Struct {
/** Option<u8> */
@@ -22,11 +22,13 @@ export default function generateRpcTypes (): void {
setImports(imports, [method.type]);
// FIXME These 2 are too hard to type, I give up
if (method.method === 'getStorage') {
setImports(imports, ['Codec']);
return ' getStorage<T = Codec>(key: any, block?: Hash | Uint8Array | string): Observable<T>;';
} else if (method.method === 'subscribeStorage') {
return ' subscribeStorage<T = Codec[]>(keys: any[]): Observable<T>;';
if (section === 'state') {
if (method.method === 'getStorage') {
setImports(imports, ['Codec']);
return ' getStorage<T = Codec>(key: any, block?: Hash | Uint8Array | string): Observable<T>;';
} else if (method.method === 'subscribeStorage') {
return ' subscribeStorage<T = Codec[]>(keys: any[]): Observable<T>;';
}
}
const args = method.params.map((param): string => {