Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

170 Call Gitlab CI job to Automate Runtime Release #430

Merged
merged 27 commits into from
Jun 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update js code
  • Loading branch information
b-yap committed May 16, 2024
commit 4d61a1ab245ed335f6b7fe2634a949f4cead8f80
61 changes: 40 additions & 21 deletions .github/workflows/scripts/js/parachain_authorize_upgrade.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
// This code will submit a transaction to propose an `authorizeUpgrade`
// for Pendulum:
// * save to env var PENDULUM_SEED the account seed of Pendulum
// * save to env var PENDULUM_WASM_FILE the compressed wasm file of Pendulum
//
// for Amplitude:
// * save to env var AMPLITUDE_SEED the account seed of Amplitude
// * save to env var AMPLITUDE_WASM_FILE the compressed wasm file of Amplitude
//
// steps:
// 1. npm init -y
// 2. npm install
// 3. node parachain_authorize_upgrade.js <chain> <compressed.wasm>

const { ApiPromise, WsProvider, Keyring } = require("@polkadot/api");
const { blake2AsHex } = require("@polkadot/util-crypto");
const readline = require("node:readline/promises");
const { stdin, stdout } = require("node:process");
const fs = require('fs');

const rl = readline.createInterface({ input: stdin, output: stdout });
const amplitudeDefinition = {
websocketUrl: "wss://rpc-amplitude.pendulumchain.tech",
accountSeed: process.env.AMPLITUDE_SEED,
wasmFile: process.env.AMPLITUDE_WASM_FILE
}

const pendulumDefinition = {
websocketUrl: "wss://rpc-pendulum.prd.pendulumchain.tech",
accountSeed: process.env.PENDULUM_SEED,
wasmFile: process.env.PENDULUM_WASM_FILE
}

// if keypair is undefined, then dryRun must be true
async function submitExtrinsic(transaction, keypair) {
Expand Down Expand Up @@ -46,54 +62,57 @@ async function submitExtrinsic(transaction, keypair) {
});
}

async function submitTransaction(call, api) {
const keyring = new Keyring({ type: "sr25519" });
// todo: need an account
let submitterKeypair = keyring.addFromUri("//Alice");

async function democracyProposal(call, { api, submitterKeypair }) {
console.log("Preimage data", call.inner.toHex());
console.log("Preimage hash", `0x${Buffer.from(call.inner.hash).toString("hex")}`);

const submitPreimageTransaction = api.tx.preimage.notePreimage(call.inner.toHex());
// todo: uncomment if ready
// uncomment if ready
// await submitExtrinsic(submitPreimageTransaction, submitterKeypair);
}

async function submitTransaction(accountSeed, call, api) {
const keyring = new Keyring({ type: "sr25519" });
let submitterKeypair = keyring.addFromUri(accountSeed);
console.log("account: ", submitterKeypair.address);

await democracyProposal(call, {
api,
submitterKeypair
});
};

function getUrl (network) {
function getDefinitions (network) {
switch (network) {
case "amplitude":
return "wss://rpc-amplitude.pendulumchain.tech";

return amplitudeDefinition;
case "pendulum":
return "wss://rpc-pendulum.prd.pendulumchain.tech";
return pendulumDefinition;
}
};


async function main() {
const args = process.argv;

if (args.length < 4 ) {
console.error('Expecting two arguments!');
if (args.length < 3 ) {
console.error('Please provide the chain to upgrade');
process.exit(1);
}

console.log("the argument: ", args[2]);
const websocketUrl = getUrl(args[2]);

let { accountSeed, websocketUrl, wasmFile } = getDefinitions(args[2]);
console.log("the url: ", websocketUrl);

const wsProvider = new WsProvider(websocketUrl);

const api = await ApiPromise.create({ provider: wsProvider });

const wasmFileBytes = fs.readFileSync(args[3]);
const wasmFileBytes = fs.readFileSync(wasmFile);
const wasmFileHash = blake2AsHex(wasmFileBytes, 256);
console.log('wasmfile: ', wasmFileHash);

const authorizeUpgrade = api.tx.parachainSystem.authorizeUpgrade(wasmFileHash, true);

await submitTransaction(authorizeUpgrade, api);
await submitTransaction(accountSeed,authorizeUpgrade, api);

process.exit();
}
Expand Down
Loading