Skip to content

Commit

Permalink
Support moonsama
Browse files Browse the repository at this point in the history
  • Loading branch information
crystalin committed Feb 14, 2024
1 parent 7cf5a90 commit 01fff4c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
76 changes: 38 additions & 38 deletions src/libs/helpers/state-manipulator/state-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ export const STORAGE_NAMES: { [name in NetworkName]: string } = {
};

export interface StateInfo {
"file": string,
"cleanFile"?: string,
"name": string,
"chainId": string,
"blockHash": string,
"blockNumber": number,
"runtime": {
"specName": string,
"implName": string,
"authoringVersion": number,
"specVersion": number,
"implVersion": number,
"apis": [string, number][],
"transactionVersion": 2,
"stateVersion": 0
},
file: string;
cleanFile?: string;
name: string;
chainId: string;
blockHash: string;
blockNumber: number;
runtime: {
specName: string;
implName: string;
authoringVersion: number;
specVersion: number;
implVersion: number;
apis: [string, number][];
transactionVersion: 2;
stateVersion: 0;
};
}

export interface DownloadOptions {
Expand All @@ -75,9 +75,7 @@ export async function downloadExportedState(
const { network, outPath, checkLatest, useCleanState } = options;

if (!STORAGE_NAMES[network]) {
throw new Error(
`Invalid network ${network}, expecting ${Object.keys(STORAGE_NAMES).join(", ")}`
);
console.warn(`Invalid network ${network}, expecting ${Object.keys(STORAGE_NAMES).join(", ")}`);
}

const stateInfoFileName = `${network}-state.info.json`;
Expand All @@ -99,7 +97,8 @@ export async function downloadExportedState(

// No check for latest, skip if files already exists
if (stateInfoExists && !checkLatest) {
const stateFileName = (useCleanState && stateInfo.cleanFile) ? stateInfo.cleanFile : stateInfo.file;
const stateFileName =
useCleanState && stateInfo.cleanFile ? stateInfo.cleanFile : stateInfo.file;
const stateFile = path.join(outPath, stateFileName);

const stateExist = await fs
Expand All @@ -114,16 +113,15 @@ export async function downloadExportedState(
const client = new Client(`https://states.kaki.dev`);
const downloadedStateInfo: StateInfo = await (
await client.request({
path:
`/${network}-state.info.json`,
path: `/${network}-state.info.json`,
method: "GET",
})
).body.json();

// Already latest version
if (stateInfo && stateInfo.blockHash == downloadedStateInfo.blockHash) {

const stateFileName = (useCleanState && stateInfo.cleanFile) ? stateInfo.cleanFile : stateInfo.file;
const stateFileName =
useCleanState && stateInfo.cleanFile ? stateInfo.cleanFile : stateInfo.file;
const stateFile = path.join(outPath, stateFileName);

const stateExist = await fs
Expand All @@ -137,7 +135,10 @@ export async function downloadExportedState(
}
}

const stateFileName = (useCleanState && downloadedStateInfo.cleanFile) ? downloadedStateInfo.cleanFile : downloadedStateInfo.file;
const stateFileName =
useCleanState && downloadedStateInfo.cleanFile
? downloadedStateInfo.cleanFile
: downloadedStateInfo.file;
const stateFile = path.join(outPath, stateFileName);

const fileStream = (await fs.open(stateFile, "w")).createWriteStream();
Expand All @@ -150,12 +151,11 @@ export async function downloadExportedState(
await new Promise<void>((resolve, reject) => {
client.dispatch(
{
path:
`/${stateFileName}`,
path: `/${stateFileName}`,
method: "GET",
},
{
onConnect: () => { },
onConnect: () => {},
onError: (error) => {
reject(error);
},
Expand Down Expand Up @@ -214,17 +214,17 @@ export async function neutralizeExportedState(
new HRMPManipulator(),
dev
? new SpecManipulator({
name: `Forked Dev Network`,
chainType: `Development`,
relayChain: `dev-service`,
devService: true,
paraId: 0,
protocolId: "",
})
name: `Forked Dev Network`,
chainType: `Development`,
relayChain: `dev-service`,
devService: true,
paraId: 0,
protocolId: "",
})
: new SpecManipulator({
name: `Fork Network`,
relayChain: `rococo-local`,
}),
name: `Fork Network`,
relayChain: `rococo-local`,
}),
new CollectiveManipulator("TechCommitteeCollective", [ALITH_ADDRESS]),
new CollectiveManipulator("CouncilCollective", [ALITH_ADDRESS]),
new ValidationManipulator(),
Expand Down
6 changes: 3 additions & 3 deletions src/tools/run-moonbeam-fork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,11 @@ const main = async () => {
],
],
];
if ("patch" in relayChainSpec.genesis?.runtimeGenesis) {
if (relayChainSpec.genesis?.runtimeGenesis && "patch" in relayChainSpec.genesis?.runtimeGenesis) {
relayChainSpec.genesis.runtimeGenesis.patch.paras = paras;
} else if ("runtime_genesis_config" in relayChainSpec.genesis?.runtime) {
} else if (relayChainSpec.genesis?.runtime && "runtime_genesis_config" in relayChainSpec.genesis?.runtime) {
relayChainSpec.genesis.runtime.runtime_genesis_config.paras = paras;
} else if ("paras" in relayChainSpec.genesis?.runtime) {
} else if (relayChainSpec.genesis?.runtime && "paras" in relayChainSpec.genesis?.runtime) {
relayChainSpec.genesis.runtime.paras = paras;
} else {
process.stdout.write(` X - Could not find parachain format in relay genesis file.\n`);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const NETWORK_WS_URLS: { [name in NETWORK_NAME]: string } = {
polkadot: "wss://rpc.polkadot.io",
};
export const NETWORK_HTTP_URLS: { [name in NETWORK_NAME]: string } = {
stagenet: "https://frag-stagenet-relay-rpc-ws.g.moondev.network",
stagenet: "https://deo-moon-moondev-1-stagenet-relay-rpc-1.rv.moondev.network",
alphanet: "https://rpc.api.moonbase.moonbeam.network",
moonsama: "https://rpc.moonsama.gcp.purestake.run",
moonsilver: "https://rpc.moonsilver.moonbeam.network",
Expand Down

0 comments on commit 01fff4c

Please sign in to comment.