Skip to content

Commit 2510b34

Browse files
committed
chore(script): set client versions
1 parent aacb3d8 commit 2510b34

1 file changed

Lines changed: 37 additions & 6 deletions

File tree

scripts/init-testnet.ts

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { SubmittableExtrinsic } from "@polkadot/api/types";
99
import { assert } from "console";
1010
import { isForeignAsset } from "../src";
1111
import { BN } from "bn.js";
12+
import fetch from "cross-fetch";
1213

1314
const readline = require("readline");
1415
const yargs = require("yargs/yargs");
@@ -23,10 +24,10 @@ const args = yargs(hideBin(process.argv))
2324
description: "Which default values to use",
2425
choices: ['testnet-kintsugi'],
2526
})
26-
// .option("clients-url", {
27-
// description: "Url of the clients, without the client-name. E.g. https://github.com/interlay/interbtc-clients/releases/download/1.17.6/",
28-
// demandOption: true,
29-
// })
27+
.option("clients-url", {
28+
description: "Url of the clients, without the client-name. E.g. https://github.com/interlay/interbtc-clients/releases/download/1.17.6/",
29+
demandOption: true,
30+
})
3031
.argv;
3132

3233
main().catch((err) => {
@@ -392,8 +393,33 @@ function constructForeignAssetSetup(api: ApiPromise) {
392393
];
393394
}
394395

395-
// function constructClientsInfoSetup(api: ApiPromise) {
396-
// }
396+
async function constructClientsInfoSetup(api: ApiPromise, baseUrl: String) {
397+
const checksumFile = await fetch(baseUrl + 'sha256sums.txt')
398+
.then(res => {
399+
if (res.status >= 400) {
400+
throw new Error("Bad response from server");
401+
}
402+
return res.text();
403+
});
404+
405+
const re = /([a-f0-9]+)\s*[.]\/(([a-z]+)-parachain-metadata-kintsugi-testnet)/g;
406+
let matches = []
407+
let match;
408+
while ((match = re.exec(checksumFile)) !== null) {
409+
matches.push([match[1], match[2], match[3]]);
410+
}
411+
412+
return matches.map(([checksum, fullFileName, clientName]) => {
413+
return api.tx.clientsInfo.setCurrentClientRelease(
414+
clientName,
415+
{
416+
uri: baseUrl + fullFileName,
417+
checksum: "0x" + checksum,
418+
}
419+
)
420+
});
421+
}
422+
397423
function toUrl(extrinsic: SubmittableExtrinsic<"promise">, endpoint: string) {
398424
return "https://polkadot.js.org/apps/?rpc=" +
399425
encodeURIComponent(endpoint) +
@@ -405,6 +431,7 @@ async function setupParachain() {
405431
const paraApi = await createSubstrateAPI(args['parachain-endpoint']);
406432

407433
let calls = [
434+
await constructClientsInfoSetup(paraApi, args["clients-url"]),
408435
constructFundingSetup(paraApi),
409436
constructForeignAssetSetup(paraApi),
410437
constructLendingSetup(paraApi),
@@ -422,6 +449,10 @@ async function setupParachain() {
422449
}
423450

424451
async function main(): Promise<void> {
452+
if (!args["clients-url"].endsWith("/")) {
453+
throw new Error("clients-url needs to end with `/`, e.g. https://github.com/interlay/interbtc-clients/releases/download/1.19.2/");
454+
}
455+
425456
await cryptoWaitReady();
426457

427458
switch (args['with-defaults-of']) {

0 commit comments

Comments
 (0)