Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions packages/api/src/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export default abstract class ApiBase<CodecResult, SubscriptionResult> implement
const thisProvider = options.source
? options.source._rpcBase._provider.clone()
: options.provider;

Comment thread
KarishmaBothara marked this conversation as resolved.
this._options = options;
this._type = type;
this._eventemitter = new EventEmitter();
Expand Down Expand Up @@ -361,7 +360,6 @@ export default abstract class ApiBase<CodecResult, SubscriptionResult> implement

this.emit('ready', this);
}

healthTimer = setInterval(() => {
this._rpcRx.system.health().toPromise().catch(() => {
// ignore
Expand All @@ -374,14 +372,26 @@ export default abstract class ApiBase<CodecResult, SubscriptionResult> implement
}

private async loadMeta (): Promise<boolean> {
const {prebundles = {}} = this._options;
// only load from on-chain if we are not a clone (default path), alternatively
// just use the values from the source instance provided
if (!this._options.source || !this._options.source._isReady) {
this._runtimeMetadata = await this._rpcBase.state.getMetadata();
this._runtimeVersion = await this._rpcBase.chain.getRuntimeVersion();
this._genesisHash = await this._rpcBase.chain.getBlockHash(0);

// get unique types & validate
[this._genesisHash, this._runtimeVersion] = await Promise.all([
this._rpcBase.chain.getBlockHash(0),
this._rpcBase.chain.getRuntimeVersion()
]);
if (`${this._genesisHash}${(this._runtimeVersion as RuntimeVersion).specVersion}` in prebundles) {
Comment thread
KarishmaBothara marked this conversation as resolved.
Outdated
try {
const rpcData = prebundles[`${this._genesisHash}${(this._runtimeVersion as RuntimeVersion).specVersion}`];
const metadata = new Metadata(rpcData);
this._runtimeMetadata = metadata;
this.runtimeMetadata.getUniqTypes(false);
} catch (e) {
this._runtimeMetadata = await this._rpcBase.state.getMetadata();
}
} else {
this._runtimeMetadata = await this._rpcBase.state.getMetadata();
}
this.runtimeMetadata.getUniqTypes(false);
} else {
this._runtimeMetadata = this._options.source.runtimeMetadata;
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ export interface ApiOptions {
* uses types not available in the base Substrate runtime.
*/
types?: RegistryTypes;

prebundles?: {
[key: string]: string
Comment thread
KarishmaBothara marked this conversation as resolved.
Outdated
};
}

export interface ApiInterface$Decorated<CodecResult, SubscriptionResult> {
Expand Down
71 changes: 71 additions & 0 deletions packages/api/test/e2e/promise-metadata.spec.js

Large diffs are not rendered by default.