Add isClonable getter on providers (#5317)

* Add isClonable getter on providers

* Use isClonable in API constructor

* mock clonable
This commit is contained in:
Jaco
2022-11-04 10:52:51 +02:00
committed by GitHub
parent 8883d355ff
commit d9aa61c786
7 changed files with 31 additions and 1 deletions
+1
View File
@@ -10,6 +10,7 @@ Contributed:
Changes:
- Align `ScProvider` code structure with other providers
- Add `isClonable` getter on providers (some, e.g. sc doesn't support this)
- Update to latest Substrate metadata
+3 -1
View File
@@ -167,7 +167,9 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
this._rx.registry = this.#registry;
const thisProvider = options.source
? options.source._rpcCore.provider.clone()
? options.source._rpcCore.provider.isClonable
? options.source._rpcCore.provider.clone()
: options.source._rpcCore.provider
: (options.provider || new WsProvider());
this._decorateMethod = decorateMethod;
+7
View File
@@ -97,6 +97,13 @@ export class HttpProvider implements ProviderInterface {
return this.#stats;
}
/**
* @summary `true` when this provider supports clone()
*/
public get isClonable (): boolean {
return true;
}
/**
* @summary Whether the node is connected or not.
* @return {boolean} true if connected
+4
View File
@@ -114,6 +114,10 @@ export class MockProvider implements ProviderInterface {
}
}
public get isClonable (): boolean {
return false;
}
public get isConnected (): boolean {
return true;
}
@@ -69,6 +69,10 @@ export class ScProvider implements ProviderInterface {
return true;
}
public get isClonable (): boolean {
return false;
}
public get isConnected (): boolean {
return !!this.#chain && this.#isChainReady;
}
+5
View File
@@ -49,8 +49,13 @@ export type ProviderInterfaceEmitted = 'connected' | 'disconnected' | 'error';
export type ProviderInterfaceEmitCb = (value?: any) => any;
export interface ProviderInterface {
/** true if the provider supports subscriptions (not available for HTTP) */
readonly hasSubscriptions: boolean;
/** true if the clone() functionality is available on the provider */
readonly isClonable: boolean;
/** true if the provider is currently connected (ws/sc has connection logic) */
readonly isConnected: boolean;
/** (optional) stats for the provider with connections/bytes */
readonly stats?: ProviderStats;
clone (): ProviderInterface;
+7
View File
@@ -165,6 +165,13 @@ export class WsProvider implements ProviderInterface {
return true;
}
/**
* @summary `true` when this provider supports clone()
*/
public get isClonable (): boolean {
return true;
}
/**
* @summary Whether the node is connected or not.
* @return {boolean} true if connected