fix(@embark/geth): only register console command if in dev mode; use endpoint; use dev account for regular txs that fix geths stuck tx issue

fix(@embark/geth): only register console command if in dev mode; use endpoint; use dev account for regular txs that fix geths stuck tx issue

fix(@embark/geth): only do regular txs if miningMode is dev

fix(@embark/geth): only register console command if in dev mode; use endpoint

fix(@embark/geth): only register console command if in dev mode; use endpoint

fix(@embark/geth): only register console command if in dev mode; use endpoint

fix(@embark/geth): only register console command if in dev mode; use endpoint
This commit is contained in:
Iuri Matias 2019-12-11 17:53:52 -05:00
parent 9f2a5949c2
commit 5d53847c6f
2 changed files with 18 additions and 5 deletions

View File

@ -4,17 +4,23 @@ import Web3 from "web3";
import constants from "embark-core/constants.json"; import constants from "embark-core/constants.json";
export default class DevTxs { export default class DevTxs {
private embark: Embark; private embark: Embark;
private blockchainConfig: any;
private events: Events; private events: Events;
private logger: Logger; private logger: Logger;
private web3?: Web3; private web3?: Web3;
private regularTxsInt?: NodeJS.Timeout; private regularTxsInt?: NodeJS.Timeout;
constructor(embark: Embark) { constructor(embark: Embark) {
this.embark = embark; this.embark = embark;
this.blockchainConfig = this.embark.config.blockchainConfig;
this.logger = embark.logger; this.logger = embark.logger;
this.events = embark.events; this.events = embark.events;
} }
public async init() { public async init() {
const provider = await this.events.request2("blockchain:client:provider", "ethereum"); if (!this.shouldStartDevTxs()) {
return;
}
const provider = await this.events.request2("blockchain:client:provider", "ethereum", this.blockchainConfig.endpoint);
this.web3 = new Web3(provider); this.web3 = new Web3(provider);
const accounts = await this.web3.eth.getAccounts(); const accounts = await this.web3.eth.getAccounts();
@ -23,6 +29,10 @@ export default class DevTxs {
this.registerConsoleCommands(); this.registerConsoleCommands();
} }
private shouldStartDevTxs() {
return (this.blockchainConfig.enabled && this.blockchainConfig.clientConfig && this.blockchainConfig.clientConfig.miningMode === 'dev');
}
private registerConsoleCommands() { private registerConsoleCommands() {
this.embark.registerConsoleCommand({ this.embark.registerConsoleCommand({
description: __("Toggles regular transactions used to prevent transactions from getting stuck when using Geth and Metamask"), description: __("Toggles regular transactions used to prevent transactions from getting stuck when using Geth and Metamask"),
@ -68,12 +78,16 @@ export default class DevTxs {
} }
public async startRegularTxs() { public async startRegularTxs() {
if (this.regularTxsInt) { if (!this.shouldStartDevTxs()) {
throw new Error("Regular txs already started."); return;
} }
if (!this.web3) { if (!this.web3) {
return; return;
} }
if (this.regularTxsInt) {
throw new Error("Regular txs already started.");
}
const networkId = await this.web3.eth.net.getId(); const networkId = await this.web3.eth.net.getId();
if (networkId !== constants.blockchain.networkIds.development) { if (networkId !== constants.blockchain.networkIds.development) {
return; return;

View File

@ -42,6 +42,7 @@ class Geth {
if (err) { if (err) {
this.logger.error(`Error launching blockchain process: ${err.message || err}`); this.logger.error(`Error launching blockchain process: ${err.message || err}`);
} }
this.setupDevTxs();
readyCb(); readyCb();
}); });
this.registerServiceCheck(); this.registerServiceCheck();
@ -51,8 +52,6 @@ class Geth {
cb(); cb();
} }
}); });
this.setupDevTxs();
} }
async setupDevTxs() { async setupDevTxs() {