add -a option to specify accounts file
This commit is contained in:
parent
daf41954da
commit
ec76b585b5
|
@ -4,6 +4,7 @@ const PledgeUtils = require('./pledge-utils');
|
||||||
const TrxUtils = require('./trx-utils');
|
const TrxUtils = require('./trx-utils');
|
||||||
const Contracts = require("./contracts.js");
|
const Contracts = require("./contracts.js");
|
||||||
const Provider = require("./provider.js");
|
const Provider = require("./provider.js");
|
||||||
|
const Web3 = require('web3');
|
||||||
|
|
||||||
function doAction(actionText, action) {
|
function doAction(actionText, action) {
|
||||||
console.dir(actionText)
|
console.dir(actionText)
|
||||||
|
@ -32,22 +33,30 @@ function doAction(actionText, action) {
|
||||||
|
|
||||||
class Actions {
|
class Actions {
|
||||||
|
|
||||||
constructor(chain) {
|
constructor(chain, accounts) {
|
||||||
this.chain = chain || "development";
|
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);
|
console.dir("connecting to: " + url);
|
||||||
|
|
||||||
this.provider = new Provider();
|
if (this.accounts.length > 0) {
|
||||||
const accounts = [{mnemonic: ""}]
|
this.provider = new Provider();
|
||||||
this.provider.initAccounts(accounts);
|
this.provider.initAccounts(this.accounts);
|
||||||
this.provider.startWeb3Provider("ws", url)
|
this.provider.startWeb3Provider("ws", url)
|
||||||
|
} else {
|
||||||
//web3.setProvider(url);
|
this.web3 = new Web3();
|
||||||
|
this.web3.setProvider(url);
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
this.web3 = this.provider.web3;
|
if (this.accounts.length > 0) {
|
||||||
|
this.web3 = this.provider.web3;
|
||||||
|
}
|
||||||
|
|
||||||
let accounts = await this.web3.eth.getAccounts();
|
let accounts = await this.web3.eth.getAccounts();
|
||||||
console.dir("== accounts");
|
console.dir("== accounts");
|
||||||
|
|
14
src/index.js
14
src/index.js
|
@ -5,12 +5,22 @@ const Actions = require('./actions.js');
|
||||||
program
|
program
|
||||||
.version('0.1.0')
|
.version('0.1.0')
|
||||||
.option('-u, --url [url]', "host to connect to (default: ws://localhost:8556)")
|
.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('-c, --chain [chain]', "environment to run, can be mainnet, ropsten, development (default: development)")
|
||||||
|
.option('-i, --infura [infuraKey]', "infuraKey (default: undefined)")
|
||||||
.parse(process.argv);
|
.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)
|
cmd(actions)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue