-
Notifications
You must be signed in to change notification settings - Fork 0
Api metadata #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Api metadata #1
Changes from 2 commits
2e07647
2ac9959
b17612f
5c19a15
69f1c40
ee85f9b
cd73b2d
5a9cee7
fece0c6
08df1b2
a5e1ddb
be78057
348043b
2b81019
d135da0
53e8fe1
bcba1c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,7 +107,7 @@ export default abstract class ApiBase<CodecResult, SubscriptionResult> implement | |
| const thisProvider = options.source | ||
| ? options.source._rpcBase._provider.clone() | ||
| : options.provider; | ||
|
|
||
| const genesisSpecToMetaDataMap = options.GenesisSpecToMetaDataMap ? options.GenesisSpecToMetaDataMap : {}; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use deconstructing to assign a default value.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GenesisSpecToMetaDataMap first G should be lowercase
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need a better name, something like prebundles |
||
| this._options = options; | ||
| this._type = type; | ||
| this._eventemitter = new EventEmitter(); | ||
|
|
@@ -125,7 +125,7 @@ export default abstract class ApiBase<CodecResult, SubscriptionResult> implement | |
| this.registerTypes(options.types); | ||
| } | ||
|
|
||
| this.init(); | ||
| this.init(genesisSpecToMetaDataMap); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -331,7 +331,7 @@ export default abstract class ApiBase<CodecResult, SubscriptionResult> implement | |
| this._eventemitter.emit(type, ...args); | ||
| } | ||
|
|
||
| private init (): void { | ||
| private init (genesisSpecToMetaDataMap: {[key: string]: string}): void { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to change signature of init(), you can use this.options to get visit the value
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same for loadMeta() |
||
| let healthTimer: NodeJS.Timeout | null = null; | ||
|
|
||
| this._rpcBase._provider.on('disconnected', () => { | ||
|
|
@@ -352,7 +352,7 @@ export default abstract class ApiBase<CodecResult, SubscriptionResult> implement | |
|
|
||
| try { | ||
| const [hasMeta, cryptoReady] = await Promise.all([ | ||
| this.loadMeta(), | ||
| this.loadMeta(genesisSpecToMetaDataMap), | ||
| cryptoWaitReady() | ||
| ]); | ||
|
|
||
|
|
@@ -361,7 +361,6 @@ export default abstract class ApiBase<CodecResult, SubscriptionResult> implement | |
|
|
||
| this.emit('ready', this); | ||
| } | ||
|
|
||
| healthTimer = setInterval(() => { | ||
| this._rpcRx.system.health().toPromise().catch(() => { | ||
| // ignore | ||
|
|
@@ -373,15 +372,30 @@ export default abstract class ApiBase<CodecResult, SubscriptionResult> implement | |
| }); | ||
| } | ||
|
|
||
| private async loadMeta (): Promise<boolean> { | ||
| private async loadMeta (genesisSpecToMetaDataMap: {[key: string]: string}): Promise<boolean> { | ||
| // 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() | ||
| ]); | ||
| let key = ''; | ||
|
KarishmaBothara marked this conversation as resolved.
Outdated
|
||
| if (this._runtimeVersion) { | ||
| key = `${this._genesisHash}${this._runtimeVersion.specVersion}`; | ||
| } | ||
| if (key in genesisSpecToMetaDataMap) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why use a for loop? i think you have a key already, so either it exists or not
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no for loop used |
||
| try { | ||
| const rpcData = genesisSpecToMetaDataMap[key]; | ||
| 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; | ||
|
|
||
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.