mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-25 04:47:56 +00:00
* 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>
This commit is contained in:
@@ -1,22 +1,80 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Call from the root of the repo as:
|
||||
# ./scripts/generate_genesis_value.sh <chain-id> [rpc endpoint]
|
||||
usage() {
|
||||
echo Usage:
|
||||
echo "$0 <chain-id>"
|
||||
echo "$0 <chain-id> [rpc endpoint]"
|
||||
exit 1
|
||||
}
|
||||
|
||||
chain_spec_summary() {
|
||||
if [ -f $chain_spec ]; then
|
||||
echo -e "ℹ️ Using chain specs from" $chain_spec
|
||||
echo -e " - name :" $(jq -r .name $chain_spec)
|
||||
echo -e " - id :" $(jq -r .id $chain_spec)
|
||||
echo -e " - type :" $(jq -r .chainType $chain_spec)
|
||||
echo -e " - decimals :" $(jq -r .properties.tokenDecimals $chain_spec)
|
||||
echo -e " - symbol :" $(jq -r .properties.tokenSymbol $chain_spec)
|
||||
echo -e " - relay_chain :" $(jq -r .relay_chain $chain_spec)
|
||||
echo -e " - para_id :" $(jq -r .para_id $chain_spec)
|
||||
echo -e " - bootNodes :" $(jq '.bootNodes | length' $chain_spec)
|
||||
echo
|
||||
else
|
||||
echo "❌ Chain specs not found from" $chain_spec
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_collator() {
|
||||
BIN=target/release/polkadot-collator
|
||||
if [ -f $BIN ]; then
|
||||
echo "✅ Collator binary found:"
|
||||
$BIN --version
|
||||
else
|
||||
echo "❌ Collator binary not found, exiting"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
set -e
|
||||
|
||||
chain_id=$1
|
||||
rpc_endpoint=$2
|
||||
work_dir="polkadot-parachains/res"
|
||||
chain_spec=$work_dir/$chain_id.json
|
||||
chain_values=$work_dir/${chain_id}_values.json
|
||||
chain_values_scale=$work_dir/${chain_id}_values.scale
|
||||
|
||||
[ -z "$chain_id" ] && usage
|
||||
chain_spec_summary
|
||||
|
||||
pushd generate_genesis_values
|
||||
if [ "$rpc_endpoint" == "" ]; then
|
||||
# default connecting to the official rpc
|
||||
rpc_endpoint='wss://statemint-shell.polkadot.io'
|
||||
fi
|
||||
|
||||
if [[ "$rpc_endpoint" =~ "localhost" ]]; then
|
||||
check_collator
|
||||
echo -e "Make sure you have a collator running with the correct version at $rpc_endpoint."
|
||||
echo -e "If you don't, NOW is the time to start it with:"
|
||||
echo -e "target/release/polkadot-collator --chain polkadot-parachains/res/shell-statemint.json --tmp\n"
|
||||
read -p "You can abort with CTRL+C if this is not correct, otherwise press ENTER "
|
||||
fi
|
||||
|
||||
echo "Generating genesis values..."
|
||||
pushd scripts/generate_genesis_values
|
||||
yarn
|
||||
popd
|
||||
|
||||
node generate_genesis_values ../polkadot-parachains/res/$chain_id.json ../polkadot-parachains/res/${chain_id}_genesis_values.json
|
||||
node scripts/generate_genesis_values $chain_spec $chain_values
|
||||
|
||||
pushd scale_encode_genesis
|
||||
echo "Scale encoding..."
|
||||
pushd scripts/scale_encode_genesis
|
||||
yarn
|
||||
popd
|
||||
node scale_encode_genesis ../polkadot-parachains/res/${chain_id}_genesis_values.json ${chain_id}_genesis_values.txt
|
||||
|
||||
node scripts/scale_encode_genesis $chain_values $chain_values_scale $rpc_endpoint
|
||||
|
||||
|
||||
ls -al polkadot-parachains/res/${chain_id}_value*.*
|
||||
|
||||
@@ -2,6 +2,10 @@ const fs = require("fs");
|
||||
const { exit } = require("process");
|
||||
const { xxhashAsHex } = require("@polkadot/util-crypto");
|
||||
|
||||
// Utility script scraping a chain spec for the genesis keys and values and writing them out as a
|
||||
// json array of pairs. Filters the keys for anything already present in a shell runtime and sorts
|
||||
// the output for reproducibility.
|
||||
|
||||
if (!process.argv[2] || !process.argv[3]) {
|
||||
console.log("usage: node generate_keys <input chainspec> <output json>");
|
||||
exit();
|
||||
@@ -49,6 +53,7 @@ fs.readFile(input, "utf8", (err, data) => {
|
||||
Object.entries(spec.genesis.raw.top).filter(
|
||||
([key, value]) => !startsWith(key, filter_prefixes)
|
||||
);
|
||||
genesis.sort();
|
||||
|
||||
fs.writeFileSync(output, JSON.stringify(genesis));
|
||||
});
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
const fs = require("fs");
|
||||
const { exit } = require("process");
|
||||
const {WsProvider, ApiPromise} = require("@polkadot/api");
|
||||
const { WsProvider, ApiPromise } = require("@polkadot/api");
|
||||
const util = require("@polkadot/util");
|
||||
|
||||
async function connect(port, types) {
|
||||
const provider = new WsProvider("ws://127.0.0.1:" + port);
|
||||
// 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,
|
||||
@@ -14,28 +19,37 @@ async function connect(port, types) {
|
||||
}
|
||||
|
||||
if (!process.argv[2] || !process.argv[3]) {
|
||||
console.log("usage: node generate_keys <input json> <scale output file>");
|
||||
exit();
|
||||
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);
|
||||
}
|
||||
if (err) {
|
||||
console.log(`Error reading file from disk: ${err}`);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const genesis = JSON.parse(data);
|
||||
const genesis = JSON.parse(data);
|
||||
|
||||
connect(9944, {}).then(api => {
|
||||
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)
|
||||
});
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user