commit
9c6b9dcc15
|
@ -97,6 +97,17 @@ class Actions {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async withdraw(params) {
|
||||||
|
let text = `await LiquidPledging.methods.withdraw(\"${params.id}\", web3.utils.toWei(\"${params.amount}\", "ether")).send({gas: 2000000})`;
|
||||||
|
return doAction(text, async () => {
|
||||||
|
const toSend = this.contracts.LiquidPledging.methods.withdraw(params.id.toString(), web3.utils.toWei(params.amount.toString(), "ether"));
|
||||||
|
const receipt = await TrxUtils.executeAndWait(toSend, web3.eth.defaultAccount);
|
||||||
|
console.dir("txHash: " + receipt.transactionHash);
|
||||||
|
const paymentId = receipt.events.AuthorizePayment.returnValues.idPayment;
|
||||||
|
console.log("Payment ID: " , paymentId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async viewPledges(params) {
|
async viewPledges(params) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -33,6 +33,11 @@ function mainMenu(actions) {
|
||||||
if (subAction === 'View Pledges') {
|
if (subAction === 'View Pledges') {
|
||||||
await actions.viewPledges();
|
await actions.viewPledges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (subAction === 'Withdraw') {
|
||||||
|
let params = (await menus.withdraw())
|
||||||
|
await actions.withdraw(params);
|
||||||
|
}
|
||||||
} else if (action === 'Funders') {
|
} else if (action === 'Funders') {
|
||||||
subAction = (await menus.funders()).action
|
subAction = (await menus.funders()).action
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,19 @@ class Contracts {
|
||||||
|
|
||||||
loadContracts() {
|
loadContracts() {
|
||||||
console.dir("loading contracts for " + this.chain);
|
console.dir("loading contracts for " + this.chain);
|
||||||
|
const LPVaultJSONConfig = require(`../chains/${this.chain}/contracts/LPVault.json`);
|
||||||
|
const LPVault = new this.web3.eth.Contract(LPVaultJSONConfig.abiDefinition, LPVaultJSONConfig.address);
|
||||||
|
|
||||||
const LiquidPledgingJSONConfig = require(`../chains/${this.chain}/contracts/LiquidPledging.json`);
|
const LiquidPledgingJSONConfig = require(`../chains/${this.chain}/contracts/LiquidPledging.json`);
|
||||||
const LiquidPledging = new this.web3.eth.Contract(LiquidPledgingJSONConfig.abiDefinition, LiquidPledgingJSONConfig.address);
|
const LiquidPledging = new this.web3.eth.Contract(LiquidPledgingJSONConfig.abiDefinition, LiquidPledgingJSONConfig.address);
|
||||||
this.contracts.LiquidPledging = LiquidPledging;
|
|
||||||
|
|
||||||
const StandardTokenJSONConfig = require(`../chains/${this.chain}/contracts/StandardToken.json`);
|
const StandardTokenJSONConfig = require(`../chains/${this.chain}/contracts/StandardToken.json`);
|
||||||
const StandardToken = new this.web3.eth.Contract(StandardTokenJSONConfig.abiDefinition, StandardTokenJSONConfig.address);
|
const StandardToken = new this.web3.eth.Contract(StandardTokenJSONConfig.abiDefinition, StandardTokenJSONConfig.address);
|
||||||
|
|
||||||
|
LiquidPledging.options.jsonInterface.push(LPVault.options.jsonInterface.find(x => x.type === 'event' && x.name ==='AuthorizePayment'));
|
||||||
|
|
||||||
|
this.contracts.LiquidPledging = LiquidPledging;
|
||||||
|
this.contracts.LPVault = LPVault;
|
||||||
this.contracts.StandardToken = StandardToken;
|
this.contracts.StandardToken = StandardToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
23
src/menus.js
23
src/menus.js
|
@ -33,7 +33,7 @@ const menus = {
|
||||||
'List Projects',
|
'List Projects',
|
||||||
'Create Project',
|
'Create Project',
|
||||||
'View Project',
|
'View Project',
|
||||||
'Donate to Project',
|
'Fund a Project',
|
||||||
new inquirer.Separator(),
|
new inquirer.Separator(),
|
||||||
'Back',
|
'Back',
|
||||||
// new inquirer.Separator(),
|
// new inquirer.Separator(),
|
||||||
|
@ -71,6 +71,7 @@ const menus = {
|
||||||
message: 'Pledges> ',
|
message: 'Pledges> ',
|
||||||
choices: [
|
choices: [
|
||||||
'View Pledges',
|
'View Pledges',
|
||||||
|
'Withdraw',
|
||||||
new inquirer.Separator(),
|
new inquirer.Separator(),
|
||||||
'Back',
|
'Back',
|
||||||
// new inquirer.Separator(),
|
// new inquirer.Separator(),
|
||||||
|
@ -182,6 +183,26 @@ const menus = {
|
||||||
])
|
])
|
||||||
},
|
},
|
||||||
|
|
||||||
|
withdraw: async function() {
|
||||||
|
return inquirer.prompt([
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
name: 'id',
|
||||||
|
message: 'What is the Pledge ID?',
|
||||||
|
filter: Number,
|
||||||
|
default: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
name: 'amount',
|
||||||
|
message: 'amount (in ether units)',
|
||||||
|
default: 2,
|
||||||
|
filter: Number
|
||||||
|
}
|
||||||
|
])
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
createFunder: async function() {
|
createFunder: async function() {
|
||||||
return inquirer.prompt([
|
return inquirer.prompt([
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,11 +30,11 @@ const PledgeState = {
|
||||||
|
|
||||||
const printTable = (pledges, web3) => {
|
const printTable = (pledges, web3) => {
|
||||||
const table = new Table({
|
const table = new Table({
|
||||||
head: ['Id', 'Owner', 'Token', 'Amount', 'nDelegates', 'IntededProject (?)', 'Commit Time (?)', 'Old Pledge Id', 'Pledge State']
|
head: ['Id', 'Owner', 'Token', 'Amount', 'nDelegates', 'IntededProject (?)', 'Commit Time', 'Old Pledge Id', 'Pledge State']
|
||||||
});
|
});
|
||||||
for(let i = pledges.length - 1; i >= 0; i--){
|
for(let i = pledges.length - 1; i >= 0; i--){
|
||||||
table.push(
|
table.push(
|
||||||
[pledges[i].id, `${pledges[i].owner} (${pledges[i].ownerData.name})`, pledges[i].token, web3.utils.fromWei(pledges[i].amount, "ether"), pledges[i].nDelegates, pledges[i].intendedProject, pledges[i].commitTime, pledges[i].oldPledge, PledgeState[pledges[i].pledgeState]]
|
[pledges[i].id, `${pledges[i].owner} (${pledges[i].ownerData.name}, ${pledges[i].ownerData.commitTime})`, pledges[i].token, web3.utils.fromWei(pledges[i].amount, "ether"), pledges[i].nDelegates, pledges[i].intendedProject,`${pledges[i].commitTime}`, pledges[i].oldPledge, PledgeState[pledges[i].pledgeState]]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
console.log(table.toString());
|
console.log(table.toString());
|
||||||
|
|
Loading…
Reference in New Issue