diff --git a/scripts/runtime-upgrade.js b/scripts/runtime-upgrade.js index 9a32a97..ac180fc 100644 --- a/scripts/runtime-upgrade.js +++ b/scripts/runtime-upgrade.js @@ -2,11 +2,26 @@ // Usage: // ./bin/cennz-cli script ./scripts/runtime-upgrade.js // -import fs from 'fs'; -var myArgs = process.argv.slice(3); +const myArgs = process.argv.slice(3); -// <<< Change this sudo key to match you network >>> -keyring.Keyring({type: 'sr25519'}).addFromUri(myargs[1]); -const wasm = fs.readFileSync(myargs[2]); +console.log(myArgs) + +const sudo = (new keyring.Keyring({ type: 'sr25519' })).addFromUri(myArgs[0]); +const wasm = fs.readFileSync(myArgs[1]); const wasmHex = `0x${wasm.toString('hex')}`; -await api.tx.sudo.sudo(api.tx.system.setCode(wasmHex)).signAndSend(sudo); +const setCode = api.tx.system.setCode(wasmHex); +const scheduler = api.tx.sudo.sudo(api.tx.scheduler.scheduleAfter(10, null, 0, setCode)); +await scheduler.signAndSend(sudo, ({ status, events }) => { + if (status.isInBlock) { + events.forEach(({ event: { data, method } }) => { + console.log('method::', method.toString()); + console.log('data::', data.toString()); + }); + } + + if (status.isFinalized) { + process.exit() + } +}); + + diff --git a/src/index.js b/src/index.js index 8a57fb6..9a4b6b1 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,5 @@ import minimist from 'minimist'; -import {Api, WsProvider } from '@cennznet/api'; +import { Api, WsProvider } from '@cennznet/api'; import repl from 'repl'; import fs from 'fs'; import keyring from '../node_modules/@polkadot/keyring/index.js'; @@ -9,70 +9,71 @@ import * as utils from '../node_modules/@polkadot/util/index.js'; const args = minimist(process.argv.slice(2)); async function setup() { - let endpoint = 'ws://localhost:9944'; - if (args.endpoint) { - if(args.endpoint === 'mainnet') { - args.endpoint = 'wss://cennznet.unfrastructure.io/public/ws'; - } else if(args.endpoint === 'nikau') { - args.endpoint = 'wss://nikau.centrality.me/public/ws'; - } - endpoint = args.endpoint; - } + let endpoint = 'ws://localhost:9944'; + if (args.endpoint) { + if (args.endpoint === 'mainnet') { + args.endpoint = 'wss://cennznet.unfrastructure.io/public/ws'; + } else if (args.endpoint === 'nikau') { + args.endpoint = 'wss://nikau.centrality.me/public/ws'; + } + endpoint = args.endpoint; + } - let types = {}; - if (args.types) { - console.log(`loading custom types from: '${args.types}'...`); - try { - types = JSON.parse(fs.readFileSync(args.types)); - } catch (err) { - throw `Failed loading custom types from: '${args.types}' with: ${err}`; - } - console.log(`using custom types: ${JSON.stringify(types)} ✅`); - } + let types = {}; + if (args.types) { + console.log(`loading custom types from: '${args.types}'...`); + try { + types = JSON.parse(fs.readFileSync(args.types)); + } catch (err) { + throw `Failed loading custom types from: '${args.types}' with: ${err}`; + } + console.log(`using custom types: ${JSON.stringify(types)} ✅`); + } - // Setup API session - let provider = new WsProvider(endpoint, 10); - console.log(`connecting to: ${endpoint}...`); - global.api = await Api.create({ provider: endpoint, types }) - console.log(`connected ✅`); + // Setup API session + let provider = new WsProvider(endpoint, 10); + console.log(`connecting to: ${endpoint}...`); + global.api = await Api.create({ provider: endpoint, types }) + console.log(`connected ✅`); - // Setup injected helper libs / functions - // Note: we vendor the @cennznet/api.js compatible versions - global.utilCrypto = utilCrypto; - global.utils = utils; - global.keyring = keyring; + // Setup injected helper libs / functions + // Note: we vendor the @cennznet/api.js compatible versions + global.utilCrypto = utilCrypto; + global.utils = utils; + global.keyring = keyring; + global.fs = fs; - // A simple keyring with pre-populated test accounts - let toyKeyring = new keyring.Keyring({ type: 'sr25519' }); - toyKeyring.alice = toyKeyring.addFromUri("//Alice"); - toyKeyring.bob = toyKeyring.addFromUri("//Bob"); - toyKeyring.charlie = toyKeyring.addFromUri("//Charlie"); - toyKeyring.dave = toyKeyring.addFromUri("//Dave"); - toyKeyring.eve = toyKeyring.addFromUri("//Eve"); - global.toyKeyring = toyKeyring; + // A simple keyring with pre-populated test accounts + let toyKeyring = new keyring.Keyring({ type: 'sr25519' }); + toyKeyring.alice = toyKeyring.addFromUri("//Alice"); + toyKeyring.bob = toyKeyring.addFromUri("//Bob"); + toyKeyring.charlie = toyKeyring.addFromUri("//Charlie"); + toyKeyring.dave = toyKeyring.addFromUri("//Dave"); + toyKeyring.eve = toyKeyring.addFromUri("//Eve"); + global.toyKeyring = toyKeyring; } async function main() { - if (args.run) { - console.log(`Running user script: '${args.run}' with: api, utilCrypto, keyring, utils`); - let script = fs.readFileSync(args.run).toString(); - eval(`(async () => {${script}})()`); - } else { - console.log("Launching session with: api, keyring, utilCrypto, utils"); - console.log("Test accounts are available via: toyKeyring"); - repl.start('> '); - } + if (args.run) { + console.log(`Running user script: '${args.run}' with: api, utilCrypto, keyring, utils`); + let script = fs.readFileSync(args.run).toString(); + eval(`(async () => {${script}})()`); + } else { + console.log("Launching session with: api, keyring, utilCrypto, utils"); + console.log("Test accounts are available via: toyKeyring"); + repl.start('> '); + } } setup() - .then(() => { - main() - .catch(err => { - console.log(`error during execution: ${err}`) - process.exit(1); - }); - }) - .catch(err => { - console.log(`error during setup: ${err}`) - process.exit(1); - }); + .then(() => { + main() + .catch(err => { + console.log(`error during execution: ${err}`) + process.exit(1); + }); + }) + .catch(err => { + console.log(`error during setup: ${err}`) + process.exit(1); + });