Skip to content

Commit

Permalink
[worker] pass registry types into the constructor instead of the api
Browse files Browse the repository at this point in the history
  • Loading branch information
clangenb committed Apr 11, 2024
1 parent 0596e39 commit 278f389
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/worker-api/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import WebSocketAsPromised from 'websocket-as-promised';
import {Keyring} from "@polkadot/keyring";
import type {u8} from "@polkadot/types-codec";
import type {TypeRegistry, Vec} from "@polkadot/types";
import type {RegistryTypes} from "@polkadot/types/types";

export interface IWorker extends WebSocketAsPromised {
rsCount: number;
Expand Down Expand Up @@ -32,8 +33,7 @@ export function createJsonRpcRequest(method: string, params: any, id: number | s

export interface WorkerOptions {
keyring?: Keyring;
api: any;
types: any;
types?: RegistryTypes;
createWebSocket?: (url: string) => WebSocket;
}

Expand Down
9 changes: 1 addition & 8 deletions packages/worker-api/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,16 @@ export class Worker extends WebSocketAsPromised implements IWorker {
attachRequestId: (data: any): any => data,
extractRequestId: () => this.rsCount = ++this.rsCount
});
const {api, types} = options;
this.#keyring = (options.keyring || undefined);
this.#registry = new TypeRegistry();
this.rsCount = 0;
this.rqStack = [] as string[]

if (types) {
if (options.types != undefined) {
this.#registry.register(encointerOptions({types: options.types}).types as RegistryTypes);
} else {
this.#registry.register(encointerOptions().types as RegistryTypes);
}

if (api) {
// add the metadata derived types to the registry and overwrite
// existing definitions for types with the same name.
this.#registry.register(api.registry.types);
}
}

public encrypt(data: Uint8Array): Vec<u8> {
Expand Down

0 comments on commit 278f389

Please sign in to comment.