Remove explicit RpcCore interface (apply in API itself) (#3284)
* Remove explicit RpcCore interface (apply in API itself) * Simplify * Adjust test linting * casting * Remove stray eslint * Re-add enable
This commit is contained in:
@@ -79,7 +79,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
|
||||
protected _rpc?: DecoratedRpc<ApiType, RpcInterface>;
|
||||
|
||||
protected _rpcCore: RpcCore;
|
||||
protected _rpcCore: RpcCore & RpcInterface;
|
||||
|
||||
protected _runtimeChain?: Text;
|
||||
|
||||
@@ -136,6 +136,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
|
||||
this.#instanceId = `${++instanceCounter}`;
|
||||
this.#registry = options.source?.registry || options.registry || new TypeRegistry();
|
||||
this._rx.registry = this.#registry;
|
||||
|
||||
const thisProvider = options.source
|
||||
? options.source._rpcCore.provider.clone()
|
||||
@@ -144,10 +145,11 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
this._decorateMethod = decorateMethod;
|
||||
this._options = options;
|
||||
this._type = type;
|
||||
this._rpcCore = new RpcCore(this.#instanceId, this.#registry, thisProvider, this._options.rpc);
|
||||
|
||||
// The RPC interface decorates the known interfaces on init
|
||||
this._rpcCore = new RpcCore(this.#instanceId, this.#registry, thisProvider, this._options.rpc) as (RpcCore & RpcInterface);
|
||||
this._isConnected = new BehaviorSubject(this._rpcCore.provider.isConnected);
|
||||
this._rx.hasSubscriptions = this._rpcCore.provider.hasSubscriptions;
|
||||
this._rx.registry = this.#registry;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -281,7 +283,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
});
|
||||
}
|
||||
|
||||
protected _decorateRpc<ApiType extends ApiTypes> (rpc: RpcCore, decorateMethod: DecorateMethod<ApiType>, input: Partial<DecoratedRpc<ApiType, RpcInterface>> = {}): DecoratedRpc<ApiType, RpcInterface> {
|
||||
protected _decorateRpc<ApiType extends ApiTypes> (rpc: RpcCore & RpcInterface, decorateMethod: DecorateMethod<ApiType>, input: Partial<DecoratedRpc<ApiType, RpcInterface>> = {}): DecoratedRpc<ApiType, RpcInterface> {
|
||||
return rpc.sections.reduce((out, _sectionName): DecoratedRpc<ApiType, RpcInterface> => {
|
||||
const sectionName = _sectionName as keyof DecoratedRpc<ApiType, RpcInterface>;
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/rpc-core authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { RpcInterface } from '@polkadot/rpc-core/types.jsonrpc';
|
||||
|
||||
import { createTestPairs } from '@polkadot/keyring/testingPairs';
|
||||
import { MockProvider } from '@polkadot/rpc-provider/mock';
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
@@ -9,11 +11,11 @@ import { RpcCore } from '.';
|
||||
|
||||
describe('Cached Observables', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
let rpc: RpcCore;
|
||||
let rpc: RpcCore & RpcInterface;
|
||||
const keyring = createTestPairs();
|
||||
|
||||
beforeEach((): void => {
|
||||
rpc = new RpcCore('123', registry, new MockProvider(registry));
|
||||
rpc = new RpcCore('123', registry, new MockProvider(registry)) as (RpcCore & RpcInterface);
|
||||
});
|
||||
|
||||
it('creates a single observable for subscriptions (multiple calls)', (): void => {
|
||||
|
||||
@@ -79,7 +79,7 @@ function isTreatAsHex (key: StorageKey): boolean {
|
||||
* const rpc = new Rpc(provider);
|
||||
* ```
|
||||
*/
|
||||
export class RpcCore implements RpcInterface {
|
||||
export class RpcCore {
|
||||
#instanceId: string;
|
||||
|
||||
#registryDefault: Registry;
|
||||
@@ -94,42 +94,6 @@ export class RpcCore implements RpcInterface {
|
||||
|
||||
public readonly sections: string[] = [];
|
||||
|
||||
// Ok, this is quite horrible - we really should not be using the ! here, but we are actually assigning
|
||||
// these via the createInterfaces inside the constructor. However... this is not quite visible. The reason
|
||||
// why we don't do for individual assignments is to allow user-defined RPCs to also be defined
|
||||
|
||||
public readonly author!: RpcInterface['author'];
|
||||
|
||||
public readonly babe!: RpcInterface['babe'];
|
||||
|
||||
public readonly chain!: RpcInterface['chain'];
|
||||
|
||||
public readonly childstate!: RpcInterface['childstate'];
|
||||
|
||||
public readonly contracts!: RpcInterface['contracts'];
|
||||
|
||||
public readonly engine!: RpcInterface['engine'];
|
||||
|
||||
public readonly eth!: RpcInterface['eth'];
|
||||
|
||||
public readonly grandpa!: RpcInterface['grandpa'];
|
||||
|
||||
public readonly net!: RpcInterface['net'];
|
||||
|
||||
public readonly offchain!: RpcInterface['offchain'];
|
||||
|
||||
public readonly payment!: RpcInterface['payment'];
|
||||
|
||||
public readonly rpc!: RpcInterface['rpc'];
|
||||
|
||||
public readonly state!: RpcInterface['state'];
|
||||
|
||||
public readonly syncstate!: RpcInterface['syncstate'];
|
||||
|
||||
public readonly system!: RpcInterface['system'];
|
||||
|
||||
public readonly web3!: RpcInterface['web3'];
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* Default constructor for the Api Object
|
||||
@@ -148,6 +112,7 @@ export class RpcCore implements RpcInterface {
|
||||
// these are the base keys (i.e. part of jsonrpc)
|
||||
this.sections.push(...sectionNames);
|
||||
|
||||
// decorate all interfaces, defined and user on this instance
|
||||
this.addUserInterfaces(userRpc);
|
||||
}
|
||||
|
||||
@@ -187,7 +152,7 @@ export class RpcCore implements RpcInterface {
|
||||
this.sections.forEach((sectionName): void => {
|
||||
(this as Record<string, unknown>)[sectionName as Section] ||= {};
|
||||
|
||||
const section = this[sectionName as Section] as Record<string, unknown>;
|
||||
const section = (this as Record<string, unknown>)[sectionName as Section] as Record<string, unknown>;
|
||||
|
||||
Object
|
||||
.entries({
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/rpc-core authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { RpcInterface } from '@polkadot/rpc-core/types.jsonrpc';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
|
||||
import { MockProvider } from '@polkadot/rpc-provider/mock';
|
||||
@@ -11,10 +12,10 @@ import { RpcCore } from '.';
|
||||
|
||||
describe('replay', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
let rpc: RpcCore;
|
||||
let rpc: RpcCore & RpcInterface;
|
||||
|
||||
beforeEach((): void => {
|
||||
rpc = new RpcCore('653', registry, new MockProvider(registry));
|
||||
rpc = new RpcCore('653', registry, new MockProvider(registry)) as (RpcCore & RpcInterface);
|
||||
});
|
||||
|
||||
it('subscribes via the rpc section', (done): void => {
|
||||
|
||||
Reference in New Issue
Block a user