Make metadata available on registry swap (#2556)

* Make metadata available on registry swap

* Return full VersionedRegistry
This commit is contained in:
Jaco Greeff
2020-08-31 22:52:33 +02:00
committed by GitHub
parent 15c35900ac
commit 0e9a50e020
2 changed files with 18 additions and 20 deletions
+4 -4
View File
@@ -68,7 +68,7 @@ function logErrorMessage (method: string, { params, type }: DefinitionRpc, error
export default class Rpc implements RpcInterface {
#registryDefault: Registry;
#getBlockRegistry?: (blockHash?: string | Uint8Array | null) => Promise<Registry>;
#getBlockRegistry?: (blockHash: string | Uint8Array) => Promise<{ registry: Registry }>;
readonly #storageCache = new Map<string, string | null>();
@@ -136,7 +136,7 @@ export default class Rpc implements RpcInterface {
/**
* @description Sets a registry swap (typically from Api)
*/
public setRegistrySwap (registrySwap: (blockHash?: string | Uint8Array | null) => Promise<Registry>): void {
public setRegistrySwap (registrySwap: (blockHash: string | Uint8Array) => Promise<{ registry: Registry }>): void {
this.#getBlockRegistry = registrySwap;
}
@@ -210,9 +210,9 @@ export default class Rpc implements RpcInterface {
const hash = hashIndex === -1
? undefined
: values[hashIndex] as Uint8Array;
const registry = hash && this.#getBlockRegistry
const { registry } = hash && this.#getBlockRegistry
? await this.#getBlockRegistry(hash)
: this.#registryDefault;
: { registry: this.#registryDefault };
const params = this._formatInputs(registry, def, values);
const data = await this.provider.send(rpcName, params.map((param): AnyJson => param.toJSON())) as AnyJson;