Skip to content

Commit

Permalink
added types bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
timbrinded committed Jun 9, 2023
1 parent c7f0b52 commit 7085c51
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .changeset/kind-crabs-compare.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
---

Fix GrepTest for Running networks
- [#144](https://github.com/Moonsong-Labs/moonwall/issues/144)
- [#144](https://github.com/Moonsong-Labs/moonwall/issues/144)
7 changes: 7 additions & 0 deletions .changeset/red-rice-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@moonwall/types": patch
"@moonwall/cli": patch
---

Tansii Changes
- [#145](https://github.com/Moonsong-Labs/moonwall/issues/145)
25 changes: 14 additions & 11 deletions packages/cli/src/internal/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { deriveViemChain } from "@moonwall/util";
import { ApiOptions } from "@polkadot/api/types/index.js";
import { OverrideBundleType } from "@polkadot/types/types/registry";
const debug = Debug("global:providers");

//TODO: Make Generic /w function overloads
export function prepareProviders(providerConfigs: ProviderConfig[]): MoonwallProvider[] {
return providerConfigs.map(({ name, endpoints, type, rpc }) => {
return providerConfigs.map(({ name, endpoints, type, rpc, additionalTypes }) => {
const url = endpoints.includes("ENV_VAR") ? process.env.WSS_URL! : endpoints[0];
const privateKey = process.env.MOON_PRIV_KEY || ALITH_PRIVATE_KEY;

Expand All @@ -32,17 +33,23 @@ export function prepareProviders(providerConfigs: ProviderConfig[]): MoonwallPro
name,
type,
connect: async () => {
const options = {
const options: ApiOptions = {
provider: new WsProvider(url),
initWasm: false,
noInitWarn: true,
rpc: !!rpc ? { ...rpcDefinitions, ...rpc } : rpcDefinitions,
typesBundle: !!additionalTypes ? additionalTypes : undefined,
};

if (!!rpc) {
options["rpc"] = rpc;
}

const api = await ApiPromise.create(options as ApiOptions);
if (!!additionalTypes) {
options["typesBundle"] = { ...additionalTypes };
}

const api = await ApiPromise.create(options);
await api.isReady;
return api;
},
Expand All @@ -55,20 +62,16 @@ export function prepareProviders(providerConfigs: ProviderConfig[]): MoonwallPro
name,
type,
connect: async () => {
const options = {
const options: ApiOptions = {
provider: new WsProvider(url),
initWasm: false,
isPedantic: false,
rpc: rpcDefinitions,
typesBundle: types,
rpc: !!rpc ? { ...rpcDefinitions, ...rpc } : rpcDefinitions,
typesBundle: types as OverrideBundleType,
noInitWarn: true,
};

if (!!rpc) {
options["rpc"] = { ...rpc };
}

const moonApi = await ApiPromise.create(options as ApiOptions);
const moonApi = await ApiPromise.create(options);
await moonApi.isReady;
return moonApi;
},
Expand Down
10 changes: 10 additions & 0 deletions packages/types/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@
"ProviderConfig": {
"description": "The configuration object for a provider.",
"properties": {
"additionalTypes": {
"additionalProperties": {
"additionalProperties": {
"type": "string"
},
"type": "object"
},
"description": "Represents a collection of GenericData.\nIt's an object where each key is a string and the corresponding value is a GenericData object.",
"type": "object"
},
"endpoints": {
"items": {
"type": "string"
Expand Down
22 changes: 22 additions & 0 deletions packages/types/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export interface ProviderConfig {
type: ProviderType;
endpoints: string[];
rpc?: IRpcBundle;
additionalTypes?: TypesBundle;
}

// TODO: Make Provider Sub-types (for viem and polkadot.js)
Expand Down Expand Up @@ -226,3 +227,24 @@ export interface IRpcModule {
export interface IRpcBundle {
[moduleName: string]: IRpcModule;
}

/**
* Represents a collection of GenericData.
* It's an object where each key is a string and the corresponding value is a GenericData object.
*
* @example
* ```typescript
* const example: TypesBundle = {
* ContainerChainGenesisData: {
* id: "Vec<u8>"
* }
* };
* ```
*/
export type TypesBundle = {
[key: string]: GenericData;
};

export type GenericData = {
[key: string]: string;
};

0 comments on commit 7085c51

Please sign in to comment.