Align jsonrpc augmentation with others (#1796)
This commit is contained in:
@@ -3,9 +3,9 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ApiTypes, DecorateMethod, DecoratedRpc, SubmittableModuleExtrinsics } from '@polkadot/api/types';
|
||||
import { ApiObject, ContractABIMessage, ContractABIPre, ContractBase, ContractMessage } from '../types';
|
||||
import { RpcInterface } from '@polkadot/rpc-core/jsonrpc.types';
|
||||
import { RpcInterface } from '@polkadot/rpc-core/types';
|
||||
import { Registry } from '@polkadot/types/types';
|
||||
import { ApiObject, ContractABIMessage, ContractABIPre, ContractBase, ContractMessage } from '../types';
|
||||
|
||||
import { assert, isFunction, stringCamelCase } from '@polkadot/util';
|
||||
import Abi from '../Abi';
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Constants, Storage } from '@polkadot/metadata/Decorated/types';
|
||||
import { RpcInterface } from '@polkadot/rpc-core/jsonrpc.types';
|
||||
import { RpcInterface } from '@polkadot/rpc-core/types';
|
||||
import { InterfaceRegistry } from '@polkadot/types/interfaceRegistry';
|
||||
import { Call, Hash, RuntimeVersion } from '@polkadot/types/interfaces';
|
||||
import { AnyFunction, CallFunction, Codec, CodecArg as Arg, ITuple, InterfaceTypes, ModulesWithCalls, Registry, RegistryTypes } from '@polkadot/types/types';
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Constants } from '@polkadot/metadata/Decorated/types';
|
||||
import { RpcInterface } from '@polkadot/rpc-core/jsonrpc.types';
|
||||
import { RpcInterface } from '@polkadot/rpc-core/types';
|
||||
import { Hash, RuntimeVersion } from '@polkadot/types/interfaces';
|
||||
import { InterfaceRegistry } from '@polkadot/types/interfaceRegistry';
|
||||
import { CallFunction, InterfaceTypes, RegistryError, RegistryTypes, SignerPayloadRawBase } from '@polkadot/types/types';
|
||||
|
||||
@@ -4,4 +4,5 @@
|
||||
|
||||
import './consts';
|
||||
import './query';
|
||||
import './rpc';
|
||||
import './tx';
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { Option, Vec } from '@polkadot/types/codec';
|
||||
import { Bytes, H256, Metadata, StorageData, StorageKey, Text, u32, 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 { BlockHash, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, NetworkState, PeerInfo, RpcMethods, RuntimeDispatchInfo, RuntimeVersion, StorageChangeSet } from '@polkadot/types/interfaces/rpc';
|
||||
import { AnyNumber, Codec, IExtrinsic } from '@polkadot/types/types';
|
||||
|
||||
declare module '@polkadot/rpc-core/types.jsonrpc' {
|
||||
export interface RpcInterface {
|
||||
account: {
|
||||
/**
|
||||
* Retrieves the next accountIndex as available on the node
|
||||
**/
|
||||
nextIndex(accountId: AccountId | string | Uint8Array): Observable<Index>;
|
||||
};
|
||||
author: {
|
||||
/**
|
||||
* Insert a key into the keystore.
|
||||
**/
|
||||
insertKey(keyType: Text | string, suri: Text | string, publicKey: Bytes | string | Uint8Array): Observable<Bytes>;
|
||||
/**
|
||||
* Returns all pending extrinsics, potentially grouped by sender
|
||||
**/
|
||||
pendingExtrinsics(): Observable<Vec<Extrinsic>>;
|
||||
/**
|
||||
* Remove given extrinsic from the pool and temporarily ban it to prevent reimporting
|
||||
**/
|
||||
removeExtrinsic(bytesOrHash: Vec<ExtrinsicOrHash> | (ExtrinsicOrHash | object | number | Uint8Array | string)[]): Observable<Vec<Hash>>;
|
||||
/**
|
||||
* Generate new session keys and returns the corresponding public keys
|
||||
**/
|
||||
rotateKeys(): Observable<Bytes>;
|
||||
/**
|
||||
* Submit and subscribe to watch an extrinsic until unsubscribed
|
||||
**/
|
||||
submitAndWatchExtrinsic(extrinsic: IExtrinsic): Observable<ExtrinsicStatus>;
|
||||
/**
|
||||
* Submit a fully formatted extrinsic for block inclusion
|
||||
**/
|
||||
submitExtrinsic(extrinsic: IExtrinsic): Observable<Hash>;
|
||||
};
|
||||
chain: {
|
||||
/**
|
||||
* Get header and body of a relay chain block
|
||||
**/
|
||||
getBlock(hash?: BlockHash | string | Uint8Array): Observable<SignedBlock>;
|
||||
/**
|
||||
* Get the block hash for a specific block
|
||||
**/
|
||||
getBlockHash(blockNumber?: BlockNumber | AnyNumber | Uint8Array): Observable<BlockHash>;
|
||||
/**
|
||||
* Get hash of the last finalized block in the canon chain
|
||||
**/
|
||||
getFinalizedHead(): Observable<BlockHash>;
|
||||
/**
|
||||
* Retrieves the header for a specific block
|
||||
**/
|
||||
getHeader(hash?: BlockHash | string | Uint8Array): Observable<Header>;
|
||||
/**
|
||||
* Retrieves the best finalized header via subscription
|
||||
**/
|
||||
subscribeFinalizedHeads(): Observable<Header>;
|
||||
/**
|
||||
* Retrieves the best header via subscription
|
||||
**/
|
||||
subscribeNewHeads(): Observable<Header>;
|
||||
};
|
||||
contracts: {
|
||||
/**
|
||||
* Executes a call to a contract
|
||||
**/
|
||||
call(callRequest: ContractCallRequest | object | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<ContractExecResult>;
|
||||
/**
|
||||
* Returns the value under a specified storage key in a contract
|
||||
**/
|
||||
getStorage(address: AccountId | string | Uint8Array, key: H256 | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<Option<Bytes>>;
|
||||
};
|
||||
payment: {
|
||||
/**
|
||||
* Retrieves the fee information for an encoded extrinsic
|
||||
**/
|
||||
queryInfo(extrinsic: Bytes | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<RuntimeDispatchInfo>;
|
||||
};
|
||||
rpc: {
|
||||
/**
|
||||
* Retrieves the list of RPC methods that are exposed by the node
|
||||
**/
|
||||
methods(): Observable<RpcMethods>;
|
||||
};
|
||||
state: {
|
||||
/**
|
||||
* Perform a call to a builtin on the chain
|
||||
**/
|
||||
call(method: Text | string, data: Bytes | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<Bytes>;
|
||||
/**
|
||||
* Retrieves the keys with prefix of a specific child storage
|
||||
**/
|
||||
getChildKeys(childStorageKey: StorageKey | string | Uint8Array | any, childDefinition: StorageKey | string | Uint8Array | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<Vec<StorageKey>>;
|
||||
/**
|
||||
* Retrieves the child storage for a key
|
||||
**/
|
||||
getChildStorage(childStorageKey: StorageKey | string | Uint8Array | any, childDefinition: StorageKey | string | Uint8Array | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<StorageData>;
|
||||
/**
|
||||
* Retrieves the child storage hash
|
||||
**/
|
||||
getChildStorageHash(childStorageKey: StorageKey | string | Uint8Array | any, childDefinition: StorageKey | string | Uint8Array | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<Hash>;
|
||||
/**
|
||||
* Retrieves the child storage size
|
||||
**/
|
||||
getChildStorageSize(childStorageKey: StorageKey | string | Uint8Array | any, childDefinition: StorageKey | string | Uint8Array | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<u64>;
|
||||
/**
|
||||
* Retrieves the keys with a certain prefix
|
||||
**/
|
||||
getKeys(key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<Vec<StorageKey>>;
|
||||
/**
|
||||
* Returns the runtime metadata
|
||||
**/
|
||||
getMetadata(at?: BlockHash | string | Uint8Array): Observable<Metadata>;
|
||||
/**
|
||||
* Get the runtime version
|
||||
**/
|
||||
getRuntimeVersion(at?: BlockHash | string | Uint8Array): Observable<RuntimeVersion>;
|
||||
getStorage<T = Codec>(key: any, block?: Hash | Uint8Array | string): Observable<T>;
|
||||
/**
|
||||
* Retrieves the storage hash
|
||||
**/
|
||||
getStorageHash(key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<Hash>;
|
||||
/**
|
||||
* Retrieves the storage size
|
||||
**/
|
||||
getStorageSize(key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<u64>;
|
||||
/**
|
||||
* Query historical storage entries (by key) starting from a start block
|
||||
**/
|
||||
queryStorage(keys: Vec<StorageKey> | (StorageKey | string | Uint8Array | any)[], startBlock: Hash | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<Vec<StorageChangeSet>>;
|
||||
/**
|
||||
* Retrieves the runtime version via subscription
|
||||
**/
|
||||
subscribeRuntimeVersion(): Observable<RuntimeVersion>;
|
||||
subscribeStorage<T = Codec[]>(keys: any[]): Observable<T>;
|
||||
};
|
||||
system: {
|
||||
/**
|
||||
* Retrieves the chain
|
||||
**/
|
||||
chain(): Observable<Text>;
|
||||
/**
|
||||
* Return health status of the node
|
||||
**/
|
||||
health(): Observable<Health>;
|
||||
/**
|
||||
* Retrieves the node name
|
||||
**/
|
||||
name(): Observable<Text>;
|
||||
/**
|
||||
* Returns current state of the network
|
||||
**/
|
||||
networkState(): Observable<NetworkState>;
|
||||
/**
|
||||
* Returns the currently connected peers
|
||||
**/
|
||||
peers(): Observable<Vec<PeerInfo>>;
|
||||
/**
|
||||
* Get a custom set of properties as a JSON object, defined in the chain spec
|
||||
**/
|
||||
properties(): Observable<ChainProperties>;
|
||||
/**
|
||||
* Retrieves the version of the node
|
||||
**/
|
||||
version(): Observable<Text>;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,13 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
// Module augmentation so that `api.{consts,query,tx}.*.*` work
|
||||
// Module augmentation so that `api.{consts,query,rpc,tx}.*.*` work
|
||||
import './augment';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { DeriveCustom, ExactDerive } from '@polkadot/api-derive';
|
||||
import { Constants } from '@polkadot/metadata/Decorated/types';
|
||||
import { RpcInterface } from '@polkadot/rpc-core/jsonrpc.types';
|
||||
import { UserRpc } from '@polkadot/rpc-core/types';
|
||||
import { RpcInterface, UserRpc } from '@polkadot/rpc-core/types';
|
||||
import { Metadata } from '@polkadot/types';
|
||||
import { Hash, RuntimeVersion } from '@polkadot/types/interfaces';
|
||||
import { RegistryTypes, SignatureOptions, SignerPayloadJSON, SignerPayloadRaw, Registry } from '@polkadot/types/types';
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
import { ProviderInterface } from '@polkadot/rpc-provider/types';
|
||||
import { RpcMethod, RpcSection, RpcParam } from '@polkadot/jsonrpc/types';
|
||||
import { AnyJson, Codec, Registry } from '@polkadot/types/types';
|
||||
import { RpcInterface } from './jsonrpc.types';
|
||||
import { RpcInterfaceMethod, UserRpc } from './types';
|
||||
import { RpcInterface, RpcInterfaceMethod, UserRpc } from './types';
|
||||
|
||||
import memoizee from 'memoizee';
|
||||
import { combineLatest, from, Observable, Observer, of, throwError } from 'rxjs';
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { Option, Vec } from '@polkadot/types/codec';
|
||||
import { Bytes, H256, Metadata, StorageData, StorageKey, Text, u32, 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 { BlockHash, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, NetworkState, PeerInfo, RpcMethods, RuntimeDispatchInfo, RuntimeVersion, StorageChangeSet } from '@polkadot/types/interfaces/rpc';
|
||||
import { AnyNumber, Codec, IExtrinsic } from '@polkadot/types/types';
|
||||
|
||||
export interface RpcInterface {
|
||||
account: {
|
||||
nextIndex(accountId: AccountId | string | Uint8Array): Observable<Index>;
|
||||
};
|
||||
author: {
|
||||
insertKey(keyType: Text | string, suri: Text | string, publicKey: Bytes | string | Uint8Array): Observable<Bytes>;
|
||||
pendingExtrinsics(): Observable<Vec<Extrinsic>>;
|
||||
removeExtrinsic(bytesOrHash: Vec<ExtrinsicOrHash> | (ExtrinsicOrHash | object | number | Uint8Array | string)[]): Observable<Vec<Hash>>;
|
||||
rotateKeys(): Observable<Bytes>;
|
||||
submitAndWatchExtrinsic(extrinsic: IExtrinsic): Observable<ExtrinsicStatus>;
|
||||
submitExtrinsic(extrinsic: IExtrinsic): Observable<Hash>;
|
||||
};
|
||||
chain: {
|
||||
getBlock(hash?: BlockHash | string | Uint8Array): Observable<SignedBlock>;
|
||||
getBlockHash(blockNumber?: BlockNumber | AnyNumber | Uint8Array): Observable<BlockHash>;
|
||||
getFinalizedHead(): Observable<BlockHash>;
|
||||
getHeader(hash?: BlockHash | string | Uint8Array): Observable<Header>;
|
||||
subscribeFinalizedHeads(): Observable<Header>;
|
||||
subscribeNewHeads(): Observable<Header>;
|
||||
};
|
||||
contracts: {
|
||||
call(callRequest: ContractCallRequest | object | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<ContractExecResult>;
|
||||
getStorage(address: AccountId | string | Uint8Array, key: H256 | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<Option<Bytes>>;
|
||||
};
|
||||
payment: {
|
||||
queryInfo(extrinsic: Bytes | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<RuntimeDispatchInfo>;
|
||||
};
|
||||
rpc: {
|
||||
methods(): Observable<RpcMethods>;
|
||||
};
|
||||
state: {
|
||||
call(method: Text | string, data: Bytes | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<Bytes>;
|
||||
getChildKeys(childStorageKey: StorageKey | string | Uint8Array | any, childDefinition: StorageKey | string | Uint8Array | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<Vec<StorageKey>>;
|
||||
getChildStorage(childStorageKey: StorageKey | string | Uint8Array | any, childDefinition: StorageKey | string | Uint8Array | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<StorageData>;
|
||||
getChildStorageHash(childStorageKey: StorageKey | string | Uint8Array | any, childDefinition: StorageKey | string | Uint8Array | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<Hash>;
|
||||
getChildStorageSize(childStorageKey: StorageKey | string | Uint8Array | any, childDefinition: StorageKey | string | Uint8Array | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<u64>;
|
||||
getKeys(key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<Vec<StorageKey>>;
|
||||
getMetadata(at?: BlockHash | string | Uint8Array): Observable<Metadata>;
|
||||
getRuntimeVersion(at?: BlockHash | string | Uint8Array): Observable<RuntimeVersion>;
|
||||
getStorage<T = Codec>(key: any, block?: Hash | Uint8Array | string): Observable<T>;
|
||||
getStorageHash(key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<Hash>;
|
||||
getStorageSize(key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<u64>;
|
||||
queryStorage(keys: Vec<StorageKey> | (StorageKey | string | Uint8Array | any)[], startBlock: Hash | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<Vec<StorageChangeSet>>;
|
||||
subscribeRuntimeVersion(): Observable<RuntimeVersion>;
|
||||
subscribeStorage<T = Codec[]>(keys: any[]): Observable<T>;
|
||||
};
|
||||
system: {
|
||||
chain(): Observable<Text>;
|
||||
health(): Observable<Health>;
|
||||
name(): Observable<Text>;
|
||||
networkState(): Observable<NetworkState>;
|
||||
peers(): Observable<Vec<PeerInfo>>;
|
||||
properties(): Observable<ChainProperties>;
|
||||
version(): Observable<Text>;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2020 @polkadot/rpc-core authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface RpcInterface {}
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
export * from './types.jsonrpc';
|
||||
|
||||
export interface RpcInterfaceMethod {
|
||||
(...params: any[]): Observable<any>;
|
||||
}
|
||||
|
||||
@@ -10,12 +10,11 @@ import { TypeRegistry } from '../../codec/create';
|
||||
import { createImportCode, createImports, FOOTER, getSimilarTypes, HEADER, setImports } from '../util';
|
||||
|
||||
/** @internal */
|
||||
export default function generateRpcTypes (dest = 'packages/rpc-core/src/jsonrpc.types.ts'): void {
|
||||
export default function generateRpcTypes (dest = 'packages/api/src/types/augment/rpc.ts'): void {
|
||||
console.log(`${dest}\n\tGenerating`);
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
const imports = createImports({ '@polkadot/types/interfaces': definitions });
|
||||
|
||||
const body = Object.keys(interfaces).sort().reduce<string[]>((allSections, section): string[] => {
|
||||
const allMethods = Object.keys(interfaces[section].methods).sort().map((key): string => {
|
||||
const method = interfaces[section].methods[key];
|
||||
@@ -26,9 +25,9 @@ export default function generateRpcTypes (dest = 'packages/rpc-core/src/jsonrpc.
|
||||
if (section === 'state') {
|
||||
if (method.method === 'getStorage') {
|
||||
setImports(definitions, imports, ['Codec']);
|
||||
return ' getStorage<T = Codec>(key: any, block?: Hash | Uint8Array | string): Observable<T>;';
|
||||
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>;';
|
||||
return ' subscribeStorage<T = Codec[]>(keys: any[]): Observable<T>;';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,14 +38,14 @@ export default function generateRpcTypes (dest = 'packages/rpc-core/src/jsonrpc.
|
||||
return `${param.name}${param.isOptional ? '?' : ''}: ${similarTypes.join(' | ')}`;
|
||||
});
|
||||
|
||||
return ` ${method.method}(${args.join(', ')}): Observable<${method.type}>;`;
|
||||
return ` /**\n * ${method.description}\n **/\n ${method.method}(${args.join(', ')}): Observable<${method.type}>;`;
|
||||
});
|
||||
|
||||
return allSections.concat(
|
||||
[
|
||||
` ${section}: {`,
|
||||
` ${section}: {`,
|
||||
...allMethods,
|
||||
' };'
|
||||
' };'
|
||||
].join('\n')
|
||||
);
|
||||
}, []).join('\n');
|
||||
@@ -73,8 +72,8 @@ export default function generateRpcTypes (dest = 'packages/rpc-core/src/jsonrpc.
|
||||
types: Object.keys(imports.typesTypes)
|
||||
}
|
||||
]);
|
||||
const interfaceStart = 'export interface RpcInterface {\n';
|
||||
const interfaceEnd = '\n}';
|
||||
const interfaceStart = "declare module '@polkadot/rpc-core/types.jsonrpc' {\n export interface RpcInterface {\n";
|
||||
const interfaceEnd = '\n }\n}';
|
||||
|
||||
console.log('\tWriting');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user