Files
pezkuwi-subxt/scripts/scale_encode_genesis/index.js
T
Squirrel 7ce3fe4e0d Add Statemint Genesis Values (#817) (#905)
* Add Statemint Genesis Values (#817)

* add some docs to genesis scripts

* move statemint test chainspec

* add initial (draft) version of statemint chain spec

* adjust genesis value script

* add Statemint genesis Aura keys

* add bootnodes to statemint-genesis spec

* Add checks, debug and doc (#790)

* Add checks, debug and doc

* Update scripts/generate_genesis_value.sh

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Update scripts/generate_genesis_value.sh

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* default to official shell rpc endpoint for genesis values

* remove statemint test chain spec

* add Statemint chain spec and genesis values

* sort statemint genesis values

* some script docs adjustments

Co-authored-by: Chevdor <chevdor@users.noreply.github.com>

* cargo fmt

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
Co-authored-by: Chevdor <chevdor@users.noreply.github.com>
2022-01-19 10:43:46 +00:00

56 lines
1.6 KiB
JavaScript

const fs = require("fs");
const { exit } = require("process");
const { WsProvider, ApiPromise } = require("@polkadot/api");
const util = require("@polkadot/util");
// Utility script constructing a SCALE-encoded setStorage call from a key-value json array of
// genesis values by connecting to a running instance of the chain. (It is not required to be
// functional or synced.)
// connect to a substrate chain and return the api object
async function connect(endpoint, types = {}) {
const provider = new WsProvider(endpoint);
const api = await ApiPromise.create({
provider,
types,
throwOnConnect: false,
});
return api;
}
if (!process.argv[2] || !process.argv[3]) {
console.log("usage: node generate_keys <input json> <scale output file> [rpc enpoint]");
exit();
}
const input = process.argv[2];
const output = process.argv[3];
// default to localhost and the default Substrate port
const rpcEnpoint = process.argv[4] || "ws://localhost:9944";
console.log("Processing", input, output);
fs.readFile(input, "utf8", (err, data) => {
if (err) {
console.log(`Error reading file from disk: ${err}`);
exit(1);
}
const genesis = JSON.parse(data);
console.log("loaded genesis, length = ", genesis.length);
console.log(`Connecting to RPC endpoint: ${rpcEnpoint}`);
connect(rpcEnpoint)
.then((api) => {
console.log('Connected');
const setStorage = api.tx.system.setStorage(genesis);
const raw = setStorage.method.toU8a();
const hex = util.u8aToHex(raw);
fs.writeFileSync(output, hex);
exit(0);
})
.catch((e) => {
console.error(e);
exit(1);
});
});