add command line options

This commit is contained in:
Iuri Matias 2019-05-22 15:21:02 -04:00
parent f33c450fcb
commit ce4870dcae
7 changed files with 67 additions and 39 deletions

View File

@ -7,20 +7,20 @@ module.exports = {
"LiquidPledgingACLHelpers": require('./LiquidPledgingACLHelpers').default,
"ILPVault": require('./ILPVault').default,
"LiquidPledgingStorage": require('./LiquidPledgingStorage').default,
"ACLOracle": require('./ACLOracle').default,
"ACLHelpers": require('./ACLHelpers').default,
"ACLSyntaxSugar": require('./ACLSyntaxSugar').default,
"ACLOracle": require('./ACLOracle').default,
"IACL": require('./IACL').default,
"AppStorage": require('./AppStorage').default,
"ERCProxy": require('./ERCProxy').default,
"DelegateProxy": require('./DelegateProxy').default,
"DepositableDelegateProxy": require('./DepositableDelegateProxy').default,
"DelegateProxy": require('./DelegateProxy').default,
"AppStorage": require('./AppStorage').default,
"EtherTokenConstant": require('./EtherTokenConstant').default,
"IVaultRecoverable": require('./IVaultRecoverable').default,
"IsContract": require('./IsContract').default,
"VaultRecoverable": require('./VaultRecoverable').default,
"Initializable": require('./Initializable').default,
"IEVMScriptExecutor": require('./IEVMScriptExecutor').default,
"Initializable": require('./Initializable').default,
"EVMScriptRegistryConstants": require('./EVMScriptRegistryConstants').default,
"IEVMScriptRegistry": require('./IEVMScriptRegistry').default,
"DelegateScriptTarget": require('./DelegateScriptTarget').default,
@ -28,26 +28,26 @@ module.exports = {
"TestSimpleDelegatePluginFactory": require('./TestSimpleDelegatePluginFactory').default,
"AppProxyBase": require('./AppProxyBase').default,
"EVMScriptRunner": require('./EVMScriptRunner').default,
"ScriptHelpers": require('./ScriptHelpers').default,
"DeployDelegateScript": require('./DeployDelegateScript').default,
"ScriptHelpers": require('./ScriptHelpers').default,
"CallsScript": require('./CallsScript').default,
"DelegateScript": require('./DelegateScript').default,
"KernelConstants": require('./KernelConstants').default,
"LPConstants": require('./LPConstants').default,
"TestSimpleDelegatePlugin": require('./TestSimpleDelegatePlugin').default,
"TestSimpleProjectPlugin": require('./TestSimpleProjectPlugin').default,
"KernelStorage": require('./KernelStorage').default,
"AppProxyUpgradeable": require('./AppProxyUpgradeable').default,
"StandardToken": require('./StandardToken').default,
"KernelStorage": require('./KernelStorage').default,
"AragonApp": require('./AragonApp').default,
"SNT": require('./SNT').default,
"TestSimpleProjectPluginFactory": require('./TestSimpleProjectPluginFactory').default,
"AppProxyPinned": require('./AppProxyPinned').default,
"AragonApp": require('./AragonApp').default,
"KernelProxy": require('./KernelProxy').default,
"AppProxyPinned": require('./AppProxyPinned').default,
"Pledges": require('./Pledges').default,
"LiquidPledgingPlugins": require('./LiquidPledgingPlugins').default,
"EVMScriptRegistry": require('./EVMScriptRegistry').default,
"DAOFactory": require('./DAOFactory').default,
"EVMScriptRegistry": require('./EVMScriptRegistry').default,
"AppProxyFactory": require('./AppProxyFactory').default,
"LPVault": require('./LPVault').default,
"ACL": require('./ACL').default,
@ -56,7 +56,7 @@ module.exports = {
"PledgeAdmins": require('./PledgeAdmins').default,
"LPFactory": require('./LPFactory').default,
"LiquidPledgingBase": require('./LiquidPledgingBase').default,
"LiquidPledgingMock": require('./LiquidPledgingMock').default,
"LiquidPledging": require('./LiquidPledging').default,
"LiquidPledgingMock": require('./LiquidPledgingMock').default,
};

View File

@ -45,6 +45,7 @@
"dependencies": {
"@aragon/os": "3.1.9",
"colors": "^1.3.3",
"commander": "^2.20.0",
"embark": "^4.1.0-beta.0",
"embarkjs-connector-web3": "^4.0.0",
"inquirer": "^6.3.1"

View File

@ -1,14 +1,10 @@
var inquirer = require('inquirer');
const Web3 = require("web3");
const Contracts = require("./contracts.js");
const web3 = new Web3();
const LiquidPledgingJSONConfig = require("../dist/contracts/LiquidPledging.json");
let LiquidPledging;
const StandardTokenJSONConfig = require("../dist/contracts/StandardToken.json");
let StandardToken;
function doAction(actionText, action) {
console.dir(actionText)
const confirmation = inquirer
@ -32,11 +28,14 @@ function doAction(actionText, action) {
class Actions {
constructor() {
constructor(chain) {
this.chain = chain || "development";
}
connect(cb) {
web3.setProvider("ws://localhost:8556");
connect(url, cb) {
console.dir("chain: " + url);
console.dir("connecting to: " + url);
web3.setProvider(url);
setTimeout(async () => {
let accounts = await web3.eth.getAccounts();
@ -44,8 +43,9 @@ class Actions {
console.dir(accounts);
web3.eth.defaultAccount = accounts[0]
LiquidPledging = new web3.eth.Contract(LiquidPledgingJSONConfig.abiDefinition, LiquidPledgingJSONConfig.address);
StandardToken = new web3.eth.Contract(StandardTokenJSONConfig.abiDefinition, StandardTokenJSONConfig.address);
let contracts = new Contracts(this.chain, web3);
contracts.loadContracts();
this.contracts = contracts.contracts;
cb();
}, 1000);
@ -58,7 +58,7 @@ class Actions {
addProject(params) {
let text = `await LiquidPledging.methods.addProject(\"${params.name}\", \"${params.url}\", \"${params.account}\", ${params.parentProject}, ${params.commitTime}, \"${params.plugin}\").send({from: \"${web3.eth.defaultAccount}\", gas: 2000000})`
doAction(text, async () => {
let projectReceipt = await LiquidPledging.methods.addProject(params.name, params.url, params.account, params.parentProject, params.commitTime, params.plugin).send({from: web3.eth.defaultAccount, gas: 2000000});
let projectReceipt = await this.contracts.LiquidPledging.methods.addProject(params.name, params.url, params.account, params.parentProject, params.commitTime, params.plugin).send({from: web3.eth.defaultAccount, gas: 2000000});
console.dir("txHash: " + projectReceipt.transactionHash)
var projectId = projectReceipt.events.ProjectAdded.returnValues.idProject;
@ -69,7 +69,7 @@ class Actions {
addGiver(params) {
let text = `await LiquidPledging.methods.addGiver(\"${params.name}\", \"${params.url}\", ${params.commitTime}, \"${params.plugin}\").send({from: \"${web3.eth.defaultAccount}\", gas: 2000000})`
doAction(text, async () => {
let funderReceipt = await LiquidPledging.methods.addGiver(params.name, params.url, params.commitTime, params.plugin).send({from: web3.eth.defaultAccount, gas: 2000000})
let funderReceipt = await this.contracts.LiquidPledging.methods.addGiver(params.name, params.url, params.commitTime, params.plugin).send({from: web3.eth.defaultAccount, gas: 2000000})
console.dir("txHash: " + funderReceipt.transactionHash)
var funderId = funderReceipt.events.GiverAdded.returnValues.idGiver;
console.log(funderId);
@ -79,23 +79,23 @@ class Actions {
mintToken(params) {
let text = `await StandardToken.methods.mint(\"${params.account}\", web3.utils.toWei(\"${params.amount}\", \"ether\")).send({gas: 2000000})`
doAction(text, async () => {
let mintReceipt = await StandardToken.methods.mint(params.account, web3.utils.toWei(params.amount, "ether")).send({gas: 2000000})
let mintReceipt = await this.contracts.StandardToken.methods.mint(params.account, web3.utils.toWei(params.amount, "ether")).send({gas: 2000000})
console.dir("txHash: " + mintReceipt.transactionHash)
});
}
approveToken(params) {
let text = `await StandardToken.methods.approve(\"${LiquidPledging.options.address}\", web3.utils.toWei(\"${params.amount}\", \"ether\")).send({gas: 2000000})`
let text = `await StandardToken.methods.approve(\"${this.contracts.LiquidPledging.options.address}\", web3.utils.toWei(\"${params.amount}\", \"ether\")).send({gas: 2000000})`
doAction(text, async () => {
let mintReceipt = await StandardToken.methods.approve(LiquidPledging.options.address, web3.utils.toWei(params.amount, "ether")).send({gas: 2000000})
let mintReceipt = await this.contracts.StandardToken.methods.approve(this.contracts.LiquidPledging.options.address, web3.utils.toWei(params.amount, "ether")).send({gas: 2000000})
console.dir("txHash: " + mintReceipt.transactionHash)
});
}
donate(params) {
let text = `await LiquidPledging.methods.donate(${params.funderId}, ${params.projectId}, \"${LiquidPledging.options.address}\", web3.utils.toWei(\"${params.amount}\", \"ether\")).send({gas: 2000000});`
let text = `await LiquidPledging.methods.donate(${params.funderId}, ${params.projectId}, \"${this.contracts.LiquidPledging.options.address}\", web3.utils.toWei(\"${params.amount}\", \"ether\")).send({gas: 2000000});`
doAction(text, async () => {
let donateReceipt = await LiquidPledging.methods.donate(params.funderId, params.projectId, LiquidPledging.options.address, web3.utils.toWei(params.amount, "ether")).send({gas: 2000000});
let donateReceipt = await this.contracts.LiquidPledging.methods.donate(params.funderId, params.projectId, this.contracts.LiquidPledging.options.address, web3.utils.toWei(params.amount, "ether")).send({gas: 2000000});
console.dir("txHash: " + donateReceipt.transactionHash)
});
}

View File

@ -1,6 +1,5 @@
var inquirer = require('inquirer');
const menus = require('./menus.js');
const Actions = require('./actions.js');
async function app(actions) {
console.dir("### Liquid Funding Console")
@ -44,9 +43,4 @@ async function app(actions) {
}
}
const actions = new Actions();
actions.connect(async () => {
app(actions)
});
module.exports = app;

22
src/contracts.js Normal file
View File

@ -0,0 +1,22 @@
class Contracts {
constructor(chain, web3) {
this.chain = chain;
this.web3 = web3;
this.contracts = {};
}
loadContracts() {
const LiquidPledgingJSONConfig = require("../dist/contracts/LiquidPledging.json");
const LiquidPledging = new this.web3.eth.Contract(LiquidPledgingJSONConfig.abiDefinition, LiquidPledgingJSONConfig.address);
this.contracts.LiquidPledging = LiquidPledging;
const StandardTokenJSONConfig = require("../dist/contracts/StandardToken.json");
const StandardToken = new this.web3.eth.Contract(StandardTokenJSONConfig.abiDefinition, StandardTokenJSONConfig.address);
this.contracts.StandardToken = StandardToken;
}
}
module.exports = Contracts;

View File

@ -1,5 +1,16 @@
const UI = require("./ui");
var program = require('commander');
var cmd = require('./cmd.js');
const Actions = require('./actions.js');
const ui = new UI({});
program
.version('0.1.0')
.option('-u, --url [url]', "host to connect to (default: ws://localhost:8556)")
.option('-c, --chain [chain]', "environment to run, can be mainnet, ropsten, development (default: development)")
.parse(process.argv);
const actions = new Actions(program.chain || "development");
actions.connect(program.url || "ws://localhost:8556", async () => {
cmd(actions)
});

View File

@ -2831,7 +2831,7 @@ commander@2.9.0:
dependencies:
graceful-readlink ">= 1.0.0"
commander@^2.13.0, commander@^2.19.0, commander@^2.8.1, commander@~2.20.0:
commander@^2.13.0, commander@^2.19.0, commander@^2.20.0, commander@^2.8.1, commander@~2.20.0:
version "2.20.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
integrity sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==
@ -7424,7 +7424,7 @@ neo-async@^2.5.0, neo-async@^2.6.0:
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.0.tgz#b9d15e4d71c6762908654b5183ed38b753340835"
integrity sha512-MFh0d/Wa7vkKO3Y3LlacqAEeHK0mckVqzDieUKTT+KGxi+zIpeVsFxymkIiRpbpDziHc290Xr9A1O4Om7otoRA==
neo-blessed@0.2.0, neo-blessed@^0.2.0:
neo-blessed@0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/neo-blessed/-/neo-blessed-0.2.0.tgz#30f9495fdd104494402b62c6273a9c9b82de4f2b"
integrity sha512-C2kC4K+G2QnNQFXUIxTQvqmrdSIzGTX1ZRKeDW6ChmvPRw8rTkTEJzbEQHiHy06d36PCl/yMOCjquCRV8SpSQw==