Parachain light clients (#8050)
* feat: Added parachain light clients * fix: Add resolve json compiler option * chore: Fix lints * refactor: Better organized light client specs * chore: Added sort lint and some doc strings
This commit is contained in:
parent
949a9fc615
commit
0266224a69
@ -130,7 +130,8 @@ export const prodParasKusama: EndpointOption[] = [
|
||||
providers: {
|
||||
GMorDieDAO: 'wss://kusama.gmordie.com',
|
||||
'bLd Nodes': 'wss://ws.gm.bldnodes.org',
|
||||
TerraBioDAO: 'wss://ws-node-gm.terrabiodao.org'
|
||||
TerraBioDAO: 'wss://ws-node-gm.terrabiodao.org',
|
||||
'light client': 'light://substrate-connect/kusama/gm'
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -158,7 +159,8 @@ export const prodParasKusama: EndpointOption[] = [
|
||||
paraId: 2125,
|
||||
text: 'InvArch Tinkernet',
|
||||
providers: {
|
||||
'InvArch Team': 'wss://tinker.invarch.network'
|
||||
'InvArch Team': 'wss://tinker.invarch.network',
|
||||
'light client': 'light://substrate-connect/kusama/tinkernet'
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -26,6 +26,7 @@ import { formatBalance, isNumber, isTestChain, objectSpread, stringify } from '@
|
||||
import { defaults as addressDefaults } from '@polkadot/util-crypto/address/defaults';
|
||||
|
||||
import ApiContext from './ApiContext';
|
||||
import { lightSpecs } from './light-client-specs';
|
||||
import registry from './typeRegistry';
|
||||
import { decodeUrlTypes } from './urlTypes';
|
||||
|
||||
@ -234,19 +235,29 @@ async function loadOnReady (api: ApiPromise, endpoint: LinkOption | null, inject
|
||||
};
|
||||
}
|
||||
|
||||
function getWellKnownChain (chain = 'polkadot') {
|
||||
switch (chain) {
|
||||
case 'kusama':
|
||||
return WellKnownChain.ksmcc3;
|
||||
case 'polkadot':
|
||||
return WellKnownChain.polkadot;
|
||||
case 'rococo':
|
||||
return WellKnownChain.rococo_v2_2;
|
||||
case 'westend':
|
||||
return WellKnownChain.westend2;
|
||||
default:
|
||||
throw new Error(`Unable to construct light chain ${chain}`);
|
||||
}
|
||||
function getLightProvider (chain = 'polkadot') {
|
||||
const [relayArg, paraArg] = chain.split('/');
|
||||
|
||||
const wellKnown = () => {
|
||||
switch (relayArg) {
|
||||
case 'kusama':
|
||||
return WellKnownChain.ksmcc3;
|
||||
case 'polkadot':
|
||||
return WellKnownChain.polkadot;
|
||||
case 'rococo':
|
||||
return WellKnownChain.rococo_v2_2;
|
||||
case 'westend':
|
||||
return WellKnownChain.westend2;
|
||||
default:
|
||||
throw new Error(`Unable to construct light chain ${chain}`);
|
||||
}
|
||||
};
|
||||
|
||||
const relay = new ScProvider(wellKnown());
|
||||
|
||||
return paraArg && lightSpecs[paraArg]
|
||||
? new ScProvider(JSON.stringify(lightSpecs[paraArg]), relay)
|
||||
: relay;
|
||||
}
|
||||
|
||||
async function createApi (apiUrl: string, signer: ApiSigner, onError: (error: unknown) => void): Promise<Record<string, Record<string, string>>> {
|
||||
@ -256,7 +267,7 @@ async function createApi (apiUrl: string, signer: ApiSigner, onError: (error: un
|
||||
try {
|
||||
const providers = [0].map((): ProviderInterface =>
|
||||
isLight
|
||||
? new ScProvider(getWellKnownChain(apiUrl.replace('light://substrate-connect/', '')))
|
||||
? getLightProvider(apiUrl.replace('light://substrate-connect/', ''))
|
||||
: new WsProvider(apiUrl)
|
||||
);
|
||||
|
||||
|
||||
77
packages/react-api/src/light-client-specs/gm.json
Normal file
77
packages/react-api/src/light-client-specs/gm.json
Normal file
File diff suppressed because one or more lines are too long
15
packages/react-api/src/light-client-specs/index.ts
Normal file
15
packages/react-api/src/light-client-specs/index.ts
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2017-2022 @polkadot/react-api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint sort-keys: ["error", "asc", { caseSensitive: false }] */
|
||||
|
||||
import gmSpec from './gm.json';
|
||||
import tinkernetSpec from './tinkernet.json';
|
||||
|
||||
// Add your imported spec here in alphabetical order.
|
||||
// The key here reflects the URL of the light client endpoint.
|
||||
// e.g. light://substrate-connect/kusama/gm
|
||||
export const lightSpecs: Record<string, unknown> = {
|
||||
gm: gmSpec,
|
||||
tinkernet: tinkernetSpec
|
||||
};
|
||||
85
packages/react-api/src/light-client-specs/tinkernet.json
Normal file
85
packages/react-api/src/light-client-specs/tinkernet.json
Normal file
File diff suppressed because one or more lines are too long
@ -2,7 +2,8 @@
|
||||
"extends": "./tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./packages",
|
||||
"outDir": "./build"
|
||||
"outDir": "./build",
|
||||
"resolveJsonModule": true,
|
||||
},
|
||||
"exclude": [
|
||||
"build/**/*",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user