Skip to content

Commit

Permalink
Merge pull request #40 from mosaicnetworks/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
danukumanan authored Sep 23, 2019
2 parents 52ce985 + e429160 commit 14ebcdb
Show file tree
Hide file tree
Showing 15 changed files with 341 additions and 371 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v1.2.0

### Added

- `TxCommand` class hold transactional command abstractions

### Changed

- All transaction commands now use `TxCommand` class
- `gasPrice` has been removed from all commands due to it being redundant

## v1.1.1

- core: `Command` class now has `.startSprinner(text: string)` and `.stopSpinner`
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "evm-lite-cli",
"version": "1.1.1",
"version": "1.2.0",
"main": "dist/index.js",
"typings": "dist/typings/index.d.ts",
"license": "MIT",
Expand All @@ -14,20 +14,20 @@
"dev": "yarn install --registry http://192.168.1.4:4873",
"publish:dev": "yarn publish --registry http://192.168.1.4:4873",
"add:dev": "yarn add --registry http://192.168.1.4:4873",
"i": "ts-node src/evmlc i",
"e": "ts-node src/evmlc",
"i": "ts-node src/evmlc --datadir ~/Library/MONET i",
"e": "ts-node src/evmlc --datadir ~/Library/MONET",
"linkalldev": "yarn link evm-lite-core evm-lite-consensus evm-lite-keystore evm-lite-datadir evm-lite-client evm-lite-utils",
"pkg": "yarn run build && rm -rf bin && pkg . --out-path ./bin"
},
"dependencies": {
"chalk": "^2.4.2",
"cli-table": "^0.3.1",
"evm-lite-client": "^1.3.2",
"evm-lite-consensus": "^1.3.2",
"evm-lite-core": "^1.3.2",
"evm-lite-datadir": "^1.3.3",
"evm-lite-keystore": "^1.3.2",
"evm-lite-utils": "^1.3.3",
"evm-lite-client": "^1.3.7",
"evm-lite-consensus": "^1.3.7",
"evm-lite-core": "^1.3.7",
"evm-lite-datadir": "^1.3.7",
"evm-lite-keystore": "^1.3.7",
"evm-lite-utils": "^1.3.7",
"figlet": "^1.2.4",
"inquirer": "^7.0.0",
"mkdirp": "^0.5.1",
Expand Down
Empty file removed scripts/generate-command-help.ts
Empty file.
31 changes: 5 additions & 26 deletions src/commands/poa-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import utils from 'evm-lite-utils';

import Session from '../core/Session';

import Command, { IArgs, IOptions } from '../core/Command';
import Command, { IArgs, ITxOptions } from '../core/TxCommand';

interface Opts extends IOptions {
interface Opts extends ITxOptions {
interactive?: boolean;
host: string;
port: number;
gas: number;
gasprice: number;
}

interface Args extends IArgs<Opts> {
Expand All @@ -22,8 +21,6 @@ interface Args extends IArgs<Opts> {

interface Answers {
address: string;
gas: number;
gasPrice: number;
}

export default (evmlc: Vorpal, session: Session) => {
Expand All @@ -36,7 +33,6 @@ export default (evmlc: Vorpal, session: Session) => {
.option('-i, --interactive', 'enter interactive')
.option('-d, --debug', 'show debug output')
.option('-g, --gas <g>', 'override config gas value')
.option('-gp, --gasprice <gp>', 'override config gasprice value')
.option('-h, --host <ip>', 'override config host value')
.option('-p, --port <port>', 'override config port value')
.types({
Expand All @@ -50,6 +46,8 @@ export default (evmlc: Vorpal, session: Session) => {

class POACheckCommand extends Command<Args> {
protected async init(): Promise<boolean> {
this.constant = true;

this.args.options.interactive =
this.args.options.interactive || this.session.interactive;

Expand All @@ -62,10 +60,6 @@ class POACheckCommand extends Command<Args> {
this.args.options.gas = this.config.defaults.gas;
}

if (!this.args.options.gasprice && this.args.options.gasprice !== 0) {
this.args.options.gasprice = this.config.defaults.gasPrice;
}

this.node = new Node(this.args.options.host, this.args.options.port);

return this.args.options.interactive;
Expand All @@ -77,27 +71,12 @@ class POACheckCommand extends Command<Args> {
message: 'Nominee address: ',
name: 'address',
type: 'input'
},
{
default: this.args.options.gas || 100000,
message: 'Gas: ',
name: 'gas',
type: 'number'
},
{
default: this.args.options.gasprice || 0,
message: 'Gas Price: ',
name: 'gasPrice',
type: 'number'
}
];

const answers = await Inquirer.prompt<Answers>(questions);

this.args.address = answers.address;

this.args.options.gas = answers.gas;
this.args.options.gasprice = answers.gasPrice;
}

protected async check(): Promise<void> {
Expand All @@ -121,7 +100,7 @@ class POACheckCommand extends Command<Args> {
const tx = contract.methods.checkAuthorised(
{
gas: this.args.options.gas,
gasPrice: this.args.options.gasprice
gasPrice: Number(this.args.options.gasPrice)
},
utils.cleanAddress(this.args.address)
);
Expand Down
43 changes: 7 additions & 36 deletions src/commands/poa-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,19 @@ import utils from 'evm-lite-utils';

import Session from '../core/Session';

import Command, { IArgs, IOptions } from '../core/Command';
import Command, { IArgs, ITxOptions } from '../core/TxCommand';

interface Opts extends IOptions {
interface Opts extends ITxOptions {
interactive?: boolean;
from: string;
pwd: string;
host: string;
port: number;
gas: number;
gasprice: number;
}

interface Args extends IArgs<Opts> {}

interface Answers {
gas: number;
gasPrice: number;
}

export default (evmlc: Vorpal, session: Session) => {
const description = 'Initialize PoA contract';

Expand All @@ -41,7 +35,6 @@ export default (evmlc: Vorpal, session: Session) => {
.option('-h, --host <ip>', 'override config host value')
.option('-p, --port <port>', 'override config port value')
.option('-g, --gas <g>', 'override config gas value')
.option('-gp, --gasprice <gp>', 'override config gasprice value')
.types({
string: ['_', 'f', 'from', 'host', 'pwd']
})
Expand All @@ -53,6 +46,8 @@ export default (evmlc: Vorpal, session: Session) => {

class POAInitCommand extends Command<Args> {
protected async init(): Promise<boolean> {
this.payable = true;

this.args.options.interactive =
this.args.options.interactive || this.session.interactive;

Expand All @@ -65,10 +60,6 @@ class POAInitCommand extends Command<Args> {
this.args.options.gas = this.config.defaults.gas;
}

if (!this.args.options.gasprice && this.args.options.gasprice !== 0) {
this.args.options.gasprice = this.config.defaults.gasPrice;
}

this.args.options.from =
this.args.options.from || this.config.defaults.from;

Expand All @@ -78,27 +69,7 @@ class POAInitCommand extends Command<Args> {
}

protected async prompt(): Promise<void> {
await this.decryptPrompt();

const questions: Inquirer.QuestionCollection<Answers> = [
{
default: this.args.options.gas || 100000,
message: 'Gas: ',
name: 'gas',
type: 'number'
},
{
default: this.args.options.gasprice || 0,
message: 'Gas Price: ',
name: 'gasPrice',
type: 'number'
}
];

const answers = await Inquirer.prompt<Answers>(questions);

this.args.options.gas = answers.gas;
this.args.options.gasprice = answers.gasPrice;
return;
}

protected async check(): Promise<void> {
Expand Down Expand Up @@ -154,8 +125,8 @@ class POAInitCommand extends Command<Args> {

const tx = contract.methods.init({
from: this.account.address,
gas: this.config.defaults.gas,
gasPrice: this.config.defaults.gasPrice
gas: this.args.options.gas,
gasPrice: Number(this.args.options.gasPrice)
});

this.startSpinner('Sending Transaction');
Expand Down
38 changes: 9 additions & 29 deletions src/commands/poa-nominate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ import utils from 'evm-lite-utils';

import Session from '../core/Session';

import Command, { IArgs, IOptions } from '../core/Command';
import Command, { IArgs, ITxOptions } from '../core/TxCommand';

interface Opts extends IOptions {
interface Opts extends ITxOptions {
interactive?: boolean;
moniker: string;
from: string;
pwd?: string;
host: string;
port: number;
gas: number;
gasprice: number;
}

interface Args extends IArgs<Opts> {
Expand All @@ -29,8 +28,6 @@ interface Args extends IArgs<Opts> {
interface Answers {
address: string;
nomineeMoniker: string;
gas: number;
gasPrice: number;
}

export default (evmlc: Vorpal, session: Session) => {
Expand All @@ -47,7 +44,6 @@ export default (evmlc: Vorpal, session: Session) => {
.option('-h, --host <ip>', 'override config host value')
.option('-p, --port <port>', 'override config port value')
.option('-g, --gas <g>', 'override config gas value')
.option('-gp, --gasprice <gp>', 'override config gasprice value')
.types({
string: ['_', 'pwd', 'moniker', 'from', 'h', 'host']
})
Expand All @@ -59,6 +55,8 @@ export default (evmlc: Vorpal, session: Session) => {

class POANominateCommand extends Command<Args> {
protected async init(): Promise<boolean> {
this.payable = true;

this.args.options.interactive =
this.args.options.interactive || this.session.interactive;

Expand All @@ -71,10 +69,6 @@ class POANominateCommand extends Command<Args> {
this.args.options.gas = this.config.defaults.gas;
}

if (!this.args.options.gasprice && this.args.options.gasprice !== 0) {
this.args.options.gasprice = this.config.defaults.gasPrice;
}

this.args.options.from =
this.args.options.from || this.config.defaults.from;

Expand All @@ -84,12 +78,13 @@ class POANominateCommand extends Command<Args> {
}

protected async prompt(): Promise<void> {
await this.decryptPrompt();

const keystore = await this.datadir.listKeyfiles();
const questions: Inquirer.QuestionCollection<Answers> = [
{
default: keystore[this.args.options.from].address || '',
default:
(this.args.options.from &&
keystore[this.args.options.from].address) ||
'',
message: 'Nominee: ',
name: 'address',
type: 'input'
Expand All @@ -99,18 +94,6 @@ class POANominateCommand extends Command<Args> {
message: 'Nominee Moniker: ',
name: 'nomineeMoniker',
type: 'input'
},
{
default: this.args.options.gas || 100000,
message: 'Gas: ',
name: 'gas',
type: 'number'
},
{
default: this.args.options.gasprice || 0,
message: 'Gas Price: ',
name: 'gasPrice',
type: 'number'
}
];

Expand All @@ -119,8 +102,6 @@ class POANominateCommand extends Command<Args> {
this.args.address = utils.trimHex(answers.address);

this.args.options.moniker = answers.nomineeMoniker;
this.args.options.gas = answers.gas;
this.args.options.gasprice = answers.gasPrice;
}

protected async check(): Promise<void> {
Expand Down Expand Up @@ -172,7 +153,6 @@ class POANominateCommand extends Command<Args> {
);

const poa = await this.node!.getPOA();

this.log.info('POA', poa.address);

const contract = Contract.load(JSON.parse(poa.abi), poa.address);
Expand All @@ -190,7 +170,7 @@ class POANominateCommand extends Command<Args> {
{
from: this.account.address,
gas: this.args.options.gas,
gasPrice: this.args.options.gasprice
gasPrice: Number(this.args.options.gasPrice)
},
utils.cleanAddress(this.args.address),
this.args.options.moniker
Expand Down
Loading

0 comments on commit 14ebcdb

Please sign in to comment.