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

View File

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

View File

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

View File

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

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: dependencies:
graceful-readlink ">= 1.0.0" 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" version "2.20.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422" resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
integrity sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ== 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" resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.0.tgz#b9d15e4d71c6762908654b5183ed38b753340835"
integrity sha512-MFh0d/Wa7vkKO3Y3LlacqAEeHK0mckVqzDieUKTT+KGxi+zIpeVsFxymkIiRpbpDziHc290Xr9A1O4Om7otoRA== 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" version "0.2.0"
resolved "https://registry.yarnpkg.com/neo-blessed/-/neo-blessed-0.2.0.tgz#30f9495fdd104494402b62c6273a9c9b82de4f2b" resolved "https://registry.yarnpkg.com/neo-blessed/-/neo-blessed-0.2.0.tgz#30f9495fdd104494402b62c6273a9c9b82de4f2b"
integrity sha512-C2kC4K+G2QnNQFXUIxTQvqmrdSIzGTX1ZRKeDW6ChmvPRw8rTkTEJzbEQHiHy06d36PCl/yMOCjquCRV8SpSQw== integrity sha512-C2kC4K+G2QnNQFXUIxTQvqmrdSIzGTX1ZRKeDW6ChmvPRw8rTkTEJzbEQHiHy06d36PCl/yMOCjquCRV8SpSQw==