Closed jnaviask closed 4 years ago
Never mind -- I found the typesBundle
feature and was able to fix this with something like this:
const api = new ApiPromise({
provider: new WsProvider(url),
registry,
types: spec.types,
typesAlias: spec.typesAlias,
typesBundle: {
spec: {
'edgeware': {
types: [
{
minmax: [0, 50],
types: spec.types || {},
},
]
}
}
}
});
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.
Consider the following code example, given that
spec
contains some custom types which are required for the events call, andblockNumber
is an arbitrary old block:This will give the following failure on Edgeware at the
api.query.system.events.at
call:Why? Calling a
.at()
method from an old version of the chain invokesgetBlockRegistry
inpackages/api/src/base/Init.ts
, which overwrites the internal TypeRegistry when a new version is detected:There is currently no way to specify custom type registries for different spec versions. How can we handle this?
A simple proposal would be to add
typesSpecVersion?: Record<number, RegistryTypes>;
to theRegisteredTypes
interface (whichApiOptions
extends), and add the specified versions tothis.#registries
on construction. However, we cannot fetch historical metadata until the archival connection is made, so we would have to store an incompleteVersionedRegistry
. To avoid this, we could also maintain a separate object just for historicalRegistryTypes
and wait to populatethis.#registries
until the requisite connection occurs.This implementation wouldn't fully solve the problem of supplying historical types, as we would also want to specify a historical
typesAlias
, but it would be a big step toward proper archival access.