add -a option to specify accounts file

This commit is contained in:
Iuri Matias 2019-05-23 15:05:28 -04:00
parent daf41954da
commit ec76b585b5
2 changed files with 30 additions and 11 deletions

View File

@ -4,6 +4,7 @@ const PledgeUtils = require('./pledge-utils');
const TrxUtils = require('./trx-utils');
const Contracts = require("./contracts.js");
const Provider = require("./provider.js");
const Web3 = require('web3');
function doAction(actionText, action) {
console.dir(actionText)
@ -32,22 +33,30 @@ function doAction(actionText, action) {
class Actions {
constructor(chain) {
constructor(chain, accounts) {
this.chain = chain || "development";
this.accounts = accounts || [];
}
connect(url, cb) {
connect(options, cb) {
const url = options.url;
const infura = options.infura;
console.dir("connecting to: " + url);
this.provider = new Provider();
const accounts = [{mnemonic: ""}]
this.provider.initAccounts(accounts);
this.provider.startWeb3Provider("ws", url)
//web3.setProvider(url);
if (this.accounts.length > 0) {
this.provider = new Provider();
this.provider.initAccounts(this.accounts);
this.provider.startWeb3Provider("ws", url)
} else {
this.web3 = new Web3();
this.web3.setProvider(url);
}
setTimeout(async () => {
this.web3 = this.provider.web3;
if (this.accounts.length > 0) {
this.web3 = this.provider.web3;
}
let accounts = await this.web3.eth.getAccounts();
console.dir("== accounts");

View File

@ -5,12 +5,22 @@ const Actions = require('./actions.js');
program
.version('0.1.0')
.option('-u, --url [url]', "host to connect to (default: ws://localhost:8556)")
.option('-a, --accounts [accounts]', "accounts file, if not defined uses accounts in the connecting node")
.option('-c, --chain [chain]', "environment to run, can be mainnet, ropsten, development (default: development)")
.option('-i, --infura [infuraKey]', "infuraKey (default: undefined)")
.parse(process.argv);
const actions = new Actions(program.chain || "development");
let accounts = [];
if (program.accounts) {
accounts = require(process.cwd() + "/" + program.accounts).accounts;
}
actions.connect(program.url || "ws://localhost:8556", async () => {
const actions = new Actions(program.chain || "development", accounts || []);
actions.connect({
url: (program.url || "ws://localhost:8556"),
infura: program.infura
}, async () => {
cmd(actions)
});