Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 21 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require("dotenv").config();
const { ApiPromise } = require('@polkadot/api');
const { HttpProvider } = require('@polkadot/rpc-provider');
const { xxhashAsHex } = require('@polkadot/util-crypto');
const bjson = require('big-json');
const execFileSync = require('child_process').execFileSync;
const execSync = require('child_process').execSync;
const binaryPath = path.join(__dirname, 'data', 'binary');
Expand Down Expand Up @@ -48,7 +49,7 @@ const skippedModulesPrefix = ['System', 'Session', 'Babe', 'Grandpa', 'GrandpaFi

async function fixParachinStates (api, forkedSpec) {
const skippedKeys = [
api.query.parasScheduler.sessionStartBlock.key()
api.query.paraScheduler.sessionStartBlock.key()
];
for (const k of skippedKeys) {
delete forkedSpec.genesis.raw.top[k];
Expand Down Expand Up @@ -120,7 +121,17 @@ async function main() {
execSync(binaryPath + ` build-spec --chain ${forkChain} --raw > ` + forkedSpecPath);
}

let storage = JSON.parse(fs.readFileSync(storagePath, 'utf8'));
console.log(chalk.green('Parsing storage'));
let storage = await new Promise((resolve, reject) => {
fs.createReadStream(storagePath, 'utf8')
.pipe(bjson.createParseStream()
.on('data', function(data) {
resolve(data);
})
.on('error', function() {
reject();
}));
});
let originalSpec = JSON.parse(fs.readFileSync(originalSpecPath, 'utf8'));
let forkedSpec = JSON.parse(fs.readFileSync(forkedSpecPath, 'utf8'));

Expand Down Expand Up @@ -150,7 +161,14 @@ async function main() {
forkedSpec.genesis.raw.top['0x5c0d1176a568c1f92944340dbfed9e9c530ebca703c85910e7164cb7d1c9e47b'] = '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d';
}

fs.writeFileSync(forkedSpecPath, JSON.stringify(forkedSpec, null, 4));
console.log(chalk.green('Writing forked spec (this may take a while)'));
await new Promise((resolve, reject) => {
bjson.createStringifyStream({ body: forkedSpec })
.pipe(fs.createWriteStream(forkedSpecPath)
.on('end', function() {
resolve();
}));
});

console.log('Forked genesis generated successfully. Find it at ./data/fork.json');
process.exit();
Expand Down
131 changes: 131 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"homepage": "https://github.com/maxsam4/fork-off-substrate#readme",
"dependencies": {
"@polkadot/api": "^6.8.1",
"big-json": "^3.2.0",
"chalk": "^4.1.2",
"cli-progress": "^3.9.1",
"dotenv": "^10.0.0"
Expand Down