-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from Yuripetusko/master
Don't use commander for cli tools as it doesn't work through package.json bin
- Loading branch information
Showing
8 changed files
with
199 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,29 @@ | ||
#! /usr/bin/env node | ||
import commander from "commander"; | ||
import { Options } from "../src/tools/types"; | ||
import fs from "fs"; | ||
import JsonAdapter from "../src/tools/consolidator/adapters/json"; | ||
import { Consolidator } from "../src/tools/consolidator/consolidator"; | ||
import arg from "arg"; | ||
|
||
export const addTo = (program: commander.CommanderStatic | typeof commander) => | ||
program | ||
.command("consolidate") | ||
.option("--json <json>", "The JSON file from which to consolidate") | ||
.action(async (opts: Options) => { | ||
const file = opts.json; | ||
if (!file) { | ||
console.error("File path must be provided"); | ||
process.exit(1); | ||
} | ||
// Check the JSON file exists and is reachable | ||
try { | ||
fs.accessSync(file, fs.constants.R_OK); | ||
} catch (e) { | ||
console.error( | ||
"File is not readable. Are you providing the right path?" | ||
); | ||
process.exit(1); | ||
} | ||
const ja = new JsonAdapter(file); | ||
const con = new Consolidator(ja); | ||
con.consolidate(); | ||
}); | ||
const consolidate = async () => { | ||
const args = arg({ | ||
"--json": String, // The JSON file from which to consolidate | ||
}); | ||
|
||
const file = args["--json"]; | ||
if (!file) { | ||
console.error("File path must be provided"); | ||
process.exit(1); | ||
} | ||
// Check the JSON file exists and is reachable | ||
try { | ||
fs.accessSync(file, fs.constants.R_OK); | ||
} catch (e) { | ||
console.error("File is not readable. Are you providing the right path?"); | ||
process.exit(1); | ||
} | ||
const ja = new JsonAdapter(file); | ||
const con = new Consolidator(ja); | ||
con.consolidate(); | ||
}; | ||
|
||
consolidate(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,47 @@ | ||
#! /usr/bin/env node | ||
import commander from "commander"; | ||
import { Options } from "../src/tools/types"; | ||
import { deeplog, getApi } from "../src/tools/utils"; | ||
import arg from "arg"; | ||
|
||
export const addTo = (program: commander.CommanderStatic | typeof commander) => | ||
program | ||
.command("getevents") | ||
.option("--ws <ws>", "The websocket URL", "ws://127.0.0.1:9944") | ||
.option( | ||
"--blocks <blocks>", | ||
"Blocks to extract events from, comma separated" | ||
) | ||
.action(async (opts: Options) => { | ||
const api = await getApi(opts.ws); | ||
console.log("Connecting to " + opts.ws); | ||
const blocks = opts.blocks.split(",").map(parseInt); | ||
console.log(`Processing blocks: ` + blocks.toString()); | ||
for (const blockNum of blocks) { | ||
console.log(`========== Block ${blockNum} =============`); | ||
const blockHash = await api.rpc.chain.getBlockHash(blockNum); | ||
const events = await api.query.system.events.at(blockHash); | ||
const block = await api.rpc.chain.getBlock(blockHash); | ||
if (block.block === undefined) { | ||
console.error("Block is undefined for block " + blockHash); | ||
continue; | ||
} | ||
console.log(`Found ${events.length} events`); | ||
console.log(`Found ${block.block.extrinsics.length} extrincics`); | ||
for (const e of events) { | ||
console.log(`~~~~ Event ${e.event.method.toString()} ~~~~`); | ||
deeplog(e.toHuman()); | ||
deeplog(e.event.meta.toHuman()); | ||
console.log(e.event.section.toString()); | ||
console.log(e.event.method.toString()); | ||
console.log(`~~~~ Event ${e.event.method.toString()} END ~~~~`); | ||
} | ||
let index = 0; | ||
for (const ex of block.block.extrinsics) { | ||
console.log(`=== Extrinsic ${blockNum}-${index} =============`); | ||
deeplog(ex.toHuman()); | ||
console.log(`=== Extrinsic ${blockNum}-${index} END =============`); | ||
index++; | ||
} | ||
console.log(`========== Block ${blockNum} END =============`); | ||
} | ||
process.exit(0); | ||
}); | ||
const getEvents = async () => { | ||
const args = arg({ | ||
// Types | ||
"--ws": String, // The websocket URL | ||
"--blocks": String, // Blocks to extract events from, comma separated | ||
}); | ||
|
||
const api = await getApi(args["--ws"] || "ws://127.0.0.1:9944"); | ||
console.log("Connecting to " + args["--ws"]); | ||
const blocks = (args["--blocks"] || "").split(",").map(parseInt); | ||
console.log(`Processing blocks: ` + blocks.toString()); | ||
for (const blockNum of blocks) { | ||
console.log(`========== Block ${blockNum} =============`); | ||
const blockHash = await api.rpc.chain.getBlockHash(blockNum); | ||
const events = await api.query.system.events.at(blockHash); | ||
const block = await api.rpc.chain.getBlock(blockHash); | ||
if (block.block === undefined) { | ||
console.error("Block is undefined for block " + blockHash); | ||
continue; | ||
} | ||
console.log(`Found ${events.length} events`); | ||
console.log(`Found ${block.block.extrinsics.length} extrincics`); | ||
for (const e of events) { | ||
console.log(`~~~~ Event ${e.event.method.toString()} ~~~~`); | ||
deeplog(e.toHuman()); | ||
deeplog(e.event.meta.toHuman()); | ||
console.log(e.event.section.toString()); | ||
console.log(e.event.method.toString()); | ||
console.log(`~~~~ Event ${e.event.method.toString()} END ~~~~`); | ||
} | ||
let index = 0; | ||
for (const ex of block.block.extrinsics) { | ||
console.log(`=== Extrinsic ${blockNum}-${index} =============`); | ||
deeplog(ex.toHuman()); | ||
console.log(`=== Extrinsic ${blockNum}-${index} END =============`); | ||
index++; | ||
} | ||
console.log(`========== Block ${blockNum} END =============`); | ||
} | ||
process.exit(0); | ||
}; | ||
|
||
getEvents(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,23 @@ | ||
#! /usr/bin/env node | ||
import commander from "commander"; | ||
import { Options } from "../src/tools/types"; | ||
import { getApi } from "../src/tools/utils"; | ||
import { Seeder } from "../test/seed/seeder"; | ||
import arg from "arg"; | ||
|
||
export const addTo = (program: commander.CommanderStatic | typeof commander) => | ||
program | ||
.command("seed") | ||
.option( | ||
"--folder <folder>", | ||
"The folder from which to read seeds", | ||
"default" | ||
) | ||
.action(async (opts: Options) => { | ||
let folder = opts.folder; | ||
if (!folder.startsWith("test/seed")) folder = "test/seed/" + folder; | ||
console.log("Connecting to local chain..."); | ||
const api = await getApi("ws://127.0.0.1:9944"); | ||
console.log("Connected."); | ||
console.log("Looking for seed files inside " + folder); | ||
const s = new Seeder(api); | ||
await s.seedFromFolder(folder); | ||
process.exit(0); | ||
}); | ||
const seed = async () => { | ||
const args = arg({ | ||
// Types | ||
"--folder": String, // The folder from which to read seeds | ||
}); | ||
|
||
let folder = args["--folder"] || "default"; | ||
if (!folder.startsWith("test/seed")) folder = "test/seed/" + folder; | ||
console.log("Connecting to local chain..."); | ||
const api = await getApi("ws://127.0.0.1:9944"); | ||
console.log("Connected."); | ||
console.log("Looking for seed files inside " + folder); | ||
const s = new Seeder(api); | ||
await s.seedFromFolder(folder); | ||
process.exit(0); | ||
}; | ||
|
||
seed(); |
Oops, something went wrong.