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";
export default class DevTxs {
private embark: Embark;
private blockchainConfig: any;
private events: Events;
private logger: Logger;
private web3?: Web3;
private regularTxsInt?: NodeJS.Timeout;
constructor(embark: Embark) {
this.embark = embark;
this.blockchainConfig = this.embark.config.blockchainConfig;
this.logger = embark.logger;
this.events = embark.events;
}
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);
const accounts = await this.web3.eth.getAccounts();
@ -23,6 +29,10 @@ export default class DevTxs {
this.registerConsoleCommands();
}
private shouldStartDevTxs() {
return (this.blockchainConfig.enabled && this.blockchainConfig.clientConfig && this.blockchainConfig.clientConfig.miningMode === 'dev');
}
private registerConsoleCommands() {
this.embark.registerConsoleCommand({
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() {
if (this.regularTxsInt) {
throw new Error("Regular txs already started.");
if (!this.shouldStartDevTxs()) {
return;
}
if (!this.web3) {
return;
}
if (this.regularTxsInt) {
throw new Error("Regular txs already started.");
}
const networkId = await this.web3.eth.net.getId();
if (networkId !== constants.blockchain.networkIds.development) {
return;

View File

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