@@ -9,6 +9,7 @@ import { SubmittableExtrinsic } from "@polkadot/api/types";
99import { assert } from "console" ;
1010import { isForeignAsset } from "../src" ;
1111import { BN } from "bn.js" ;
12+ import fetch from "cross-fetch" ;
1213
1314const readline = require ( "readline" ) ;
1415const 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
3233main ( ) . 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 - f 0 - 9 ] + ) \s * [ . ] \/ ( ( [ a - z ] + ) - p a r a c h a i n - m e t a d a t a - k i n t s u g i - t e s t n e t ) / 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+
397423function 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
424451async 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