Skip to content

Commit

Permalink
allow start with custom block time. fixes #36
Browse files Browse the repository at this point in the history
  • Loading branch information
djnicholson committed Jan 21, 2021
1 parent 95074d0 commit bfe8258
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"onCommand:neo3-visual-devtracker.express.create",
"onCommand:neo3-visual-devtracker.express.reset",
"onCommand:neo3-visual-devtracker.express.run",
"onCommand:neo3-visual-devtracker.express.runAdvanced",
"onCommand:neo3-visual-devtracker.express.transfer",
"onCommand:neo3-visual-devtracker.express.walletCreate",
"onCommand:neo3-visual-devtracker.neo.contractDeploy",
Expand Down Expand Up @@ -93,6 +94,11 @@
"dark": "resources/dark/play.svg"
}
},
{
"command": "neo3-visual-devtracker.express.runAdvanced",
"title": "Start blockchain (with custom options)...",
"category": "Neo Express 3"
},
{
"command": "neo3-visual-devtracker.express.transfer",
"title": "Transfer assets",
Expand Down Expand Up @@ -171,6 +177,10 @@
"command": "neo3-visual-devtracker.express.run",
"when": "view == neo3-visual-devtracker.views.blockchains && viewItem == express"
},
{
"command": "neo3-visual-devtracker.express.runAdvanced",
"when": "view == neo3-visual-devtracker.views.blockchains && viewItem == express"
},
{
"command": "neo3-visual-devtracker.express.transfer",
"when": "view == neo3-visual-devtracker.views.blockchains && viewItem == express"
Expand Down
2 changes: 1 addition & 1 deletion src/extension/blockchainMonitor/blockchainState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as bitset from "bitset";
import * as neonTypes from "@cityofzion/neon-core/lib/types";
import * as neonTx from "@cityofzion/neon-core/lib/tx";

const MAX_REFRESH_INTERVAL_MS = 1000; // initially check every 1s but adapt according to observed block times
const MAX_REFRESH_INTERVAL_MS = 500;
const INITIAL_REFRESH_INTERVAL_MS = 3000;
const MIN_REFRESH_INTERVAL_MS = 1000 * 30;

Expand Down
8 changes: 8 additions & 0 deletions src/extension/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ export async function activate(context: vscode.ExtensionContext) {
(identifier) => neoExpressInstanceManager.run(identifier)
);

registerBlockchainInstanceCommand(
context,
"express",
blockchainsTreeDataProvider,
"neo3-visual-devtracker.express.runAdvanced",
(identifier) => neoExpressInstanceManager.runAdvanced(identifier)
);

registerBlockchainInstanceCommand(
context,
"express",
Expand Down
24 changes: 21 additions & 3 deletions src/extension/neoExpress/neoExpressInstanceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ActiveConnection from "../activeConnection";
import BlockchainIdentifier from "../blockchainIdentifier";
import Log from "../../shared/log";
import NeoExpress from "./neoExpress";
import IoHelpers from "../util/ioHelpers";

const LOG_PREFIX = "NeoExpressInstanceManager";
// VS Code does not offer an event-driven mechanism for detecting when a user closes a terminal, so polling is required:
Expand Down Expand Up @@ -38,7 +39,7 @@ export default class NeoExpressInstanceManager {
this.disposed = true;
}

async run(identifer: BlockchainIdentifier) {
async run(identifer: BlockchainIdentifier, secondsPerBlock: number = 15) {
if (identifer.blockchainType !== "express") {
return;
}
Expand All @@ -63,7 +64,7 @@ export default class NeoExpressInstanceManager {
"-i",
child.configPath,
"-s",
"15",
`${secondsPerBlock}`,
`${child.index}`
);
if (terminal) {
Expand All @@ -77,7 +78,7 @@ export default class NeoExpressInstanceManager {
"-i",
identifer.configPath,
"-s",
"15",
`${secondsPerBlock}`,
`${identifer.index}`
);
if (terminal) {
Expand All @@ -99,6 +100,23 @@ export default class NeoExpressInstanceManager {
this.onChangeEmitter.fire();
}

async runAdvanced(identifer: BlockchainIdentifier) {
if (identifer.blockchainType !== "express") {
return;
}

const secondsPerBlock = await IoHelpers.enterNumber(
"How often (in seconds) should new blocks be produced?",
15,
(n) =>
Math.round(n) === n && n > 0 && n <= 3600
? null
: "Enter a whole number between 1 and 3600"
);

await this.run(identifer, secondsPerBlock);
}

async stop() {
try {
for (const terminal of this.terminals) {
Expand Down
11 changes: 9 additions & 2 deletions src/extension/util/ioHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ export default class IoHelpers {
return await IoHelpers.choosePassword(prompt, acceptEmptyString);
}

static async enterNumber(prompt: string): Promise<number | undefined> {
static async enterNumber(
prompt: string,
defaultValue?: number,
additionalValidation: (n: number) => string | null = () => null
): Promise<number | undefined> {
const input = await vscode.window.showInputBox({
prompt,
validateInput: (_) =>
isNaN(parseFloat(_)) ? "Enter a numeric value" : null,
isNaN(parseFloat(_))
? "Enter a numeric value"
: additionalValidation(parseFloat(_)),
value: defaultValue ? `${defaultValue}` : undefined,
});
if (input) {
return parseFloat(input);
Expand Down

0 comments on commit bfe8258

Please sign in to comment.