-
Notifications
You must be signed in to change notification settings - Fork 161
feat: add metadata versions endpoints #1424
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
Conversation
… for versions 14 and 15 - transaction material with metadata returns metadata regardless of the 'metadata' query param - updated docs
bee344
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks amazing
docs/src/openapi-v1.yaml
Outdated
| - transaction | ||
| summary: Get all the network information needed to construct a transaction offline and | ||
| the version of metadata specified in `metadataVersion`. | ||
| description: Returns the material that is universal to constructing any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Returns all the materials necessary to constructing any signed transactions offline."
I don't think we need any other details, and we can also get rid of the mention to /tx/artifacts.
docs/src/openapi-v1.yaml
Outdated
| description: The version of metadata. The input is expected in a `vX` format, where `X` | ||
| represents the version number (e.g. `v14`, `v15`). By default, metadata is outputted | ||
| in 'JSON' format, unless the `metadata` query parameter is provided, in which case it can be | ||
| either in 'JSON' or 'SCALE' format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think JSON, and SCALE should be lower case here to be consistent
| ): Promise<void> => { | ||
| const hash = await this.getHashFromAt(at); | ||
|
|
||
| let api; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const api = at
? await this.api.at(hash)
: this.api| ); | ||
| } | ||
|
|
||
| const availableVersions = (await api.call.metadata.metadataVersions()).toHuman() as string[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think toJSON() might be more fitting here. Generally speaking I think toHuman is good for user facing data that is meant to be displayed, such as UI's.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's awesome! Thank you so much for this one!
Changed it and added the as unknown as Vec<u32> since this reflects the actual type which is returned from await api.call.metadata.metadataVersions(). If inspected with .toRawType(), it is a Vec<u32>.
| } | ||
|
|
||
| const availableVersions = (await api.call.metadata.metadataVersions()).toHuman() as string[]; | ||
| if (version && availableVersions?.includes(version.toString()) === false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (version && availableVersions?.includes(version.toString()) === false) { | |
| if (version && !availableVersions?.includes(version.toString())) { |
| throw new Error(`Version ${version} of Metadata is not available.`); | ||
| } | ||
|
|
||
| const registry = api ? api.registry : this.api.registry; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
api will always be true here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ofc! 😱 Changing this!
| } | ||
|
|
||
| const availableVersions = (await api.call.metadata.metadataVersions()).toHuman() as string[]; | ||
| if (version && availableVersions?.includes(version.toString()) === false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (version && availableVersions?.includes(version.toString()) === false) { | |
| if (version && !availableVersions?.includes(version.toString())) { |
| */ | ||
| async fetchMetadataVersioned(hash: BlockHash, metadataVersion: number): Promise<Metadata> { | ||
| const { api } = this; | ||
| const apiAt = await api.at(hash); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were potentially calling api.at twice, I would just pass the api from the controller down to the service and call it apiAt or something.
| */ | ||
| async fetchMetadataVersions(hash: BlockHash): Promise<string[]> { | ||
| const { api } = this; | ||
| const apiAt = await api.at(hash); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with this api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the previous one but for this one, in the RuntimeMetadataController > getMetadataAvailableVersions I don't call api.at. I just get the hash.
TarikGul
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really amazing job! Just a few talking points and nits.
- throw an error if newer call is not available for older blocks - removed some comments left in node transaction spec file
Co-authored-by: Tarik Gul <[email protected]>
Closes #1410
Description
The current implementation differs from the initial idea outlined in the #1410 issue. We did not add a query param in the existing endpoints in order to maintain the current functionality unchanged. Instead, the following new endpoints were added:
/runtime/metadata/{metadataVersion}jsonformat./runtime/metadata/versions["14", "15"]when connected to Kusama/Polkadot chain.transaction/material/{metadataVersion}metadatais defined then the output will be in the requested format (scaleorjson).jsonformat.The input for path parameter
metadataVersionis expected in avXformat, whereXrepresents the version number of the metadata. Examples:v14,v15.Notes-Thoughts on Code Implementation
metadataVersionpath parameter is repeated in bothgetMetadataVersionedfunction andgetTransactionMaterialwithVersionedMetadata. Maybe I could add these validation checks in amiddlewareand call it from there 🤔transaction/material/{metadataVersion}whenmetadatais set toscale, I returnmetadata.toString()(before I was returningmetadata.toHex()). I replaced that so that the output is the same as in p-js apps when calling metadata.metadataAtVersion() for a specific version).Tests
metadataVersionparam:v25,v11vJDHSorabcf14or15. the input should be of formatv14/v15orV14/V15.runtime/metadata/v14?at=225911transaction/material/v14?metadata=scale&at=225911both these cases will return an error message
Function 'api.call.metadata.metadataVersions()' is not available at this block height.since for these new endpoints we make use of the new callmetadataVersions()which not available in older blocks.scaleorjsonformat intransaction/materialendpoint.Todos
v14orv15but the generic path parammetadataVersion