removed await from liquidPledging.js

This commit is contained in:
perissology 2017-09-21 17:48:56 -04:00
parent ebf53f885a
commit bb14e679f0
2 changed files with 90 additions and 71 deletions

View File

@ -72,7 +72,7 @@ module.exports = (abi, bytecode) => {
this[key] = (...args) => methodWrapper(web3, this.$contract.methods[key], ...args); this[key] = (...args) => methodWrapper(web3, this.$contract.methods[key], ...args);
}); });
// set default from address // set default from address
web3.eth.getAccounts() web3.eth.getAccounts()
.then((accounts) => { .then((accounts) => {
this.$contract.options.from = (accounts.length > 0) ? accounts[0] : undefined; this.$contract.options.from = (accounts.length > 0) ? accounts[0] : undefined;

View File

@ -1,4 +1,3 @@
/* eslint-disable no-await-in-loop */
const LiquidPledgingAbi = require('../build/LiquidPledging.sol').LiquidPledgingAbi; const LiquidPledgingAbi = require('../build/LiquidPledging.sol').LiquidPledgingAbi;
const LiquidPledgingCode = require('../build/LiquidPledging.sol').LiquidPledgingByteCode; const LiquidPledgingCode = require('../build/LiquidPledging.sol').LiquidPledgingByteCode;
const LiquidPledgingMockAbi = require('../build/LiquidPledgingMock.sol').LiquidPledgingMockAbi; const LiquidPledgingMockAbi = require('../build/LiquidPledgingMock.sol').LiquidPledgingMockAbi;
@ -11,87 +10,107 @@ module.exports = (test) => {
const LiquidPledging = generateClass($abi, $byteCode); const LiquidPledging = generateClass($abi, $byteCode);
async function $getNote(idNote) { LiquidPledging.prototype.$toDecimal = function (val) { return this.$web3.utils.toDecimal(val); };
LiquidPledging.prototype.$toNumber = function (val) { this.$web3.utils.toBN(val); };
LiquidPledging.prototype.$getNote = function (idNote) {
const note = { const note = {
delegates: [], delegates: [],
}; };
const res = await this.getNote(idNote);
note.amount = this.$toNumber(res.amount);
note.owner = res.owner;
for (let i = 1; i <= this.$toDecimal(res.nDelegates); i += 1) {
const delegate = {};
const resd = await this.getNoteDelegate(idNote, i);
delegate.id = this.$toDecimal(resd.idDelegate);
delegate.addr = resd.addr;
delegate.name = resd.name;
note.delegates.push(delegate);
}
if (res.proposedProject) {
note.proposedProject = this.$toDecimal(res.proposedProject);
note.commmitTime = this.$toDecimal(res.commitTime);
}
if (res.oldNote) {
note.oldProject = this.$toDecimal(res.oldNote);
}
if (res.paymentState === '0') {
note.paymentState = 'NotPaid';
} else if (res.paymentState === '1') {
note.paymentState = 'Paying';
} else if (res.paymentState === '2') {
note.paymentState = 'Paid';
} else {
note.paymentState = 'Unknown';
}
return note;
}
LiquidPledging.prototype.$getNote = $getNote; return this.getNote(idNote)
.then((res) => {
note.amount = this.$toNumber(res.amount);
note.owner = res.owner;
async function $getManager(idManager) { if (res.proposedProject) {
note.proposedProject = this.$toDecimal(res.proposedProject);
note.commmitTime = this.$toDecimal(res.commitTime);
}
if (res.oldNote) {
note.oldProject = this.$toDecimal(res.oldNote);
}
if (res.paymentState === '0') {
note.paymentState = 'NotPaid';
} else if (res.paymentState === '1') {
note.paymentState = 'Paying';
} else if (res.paymentState === '2') {
note.paymentState = 'Paid';
} else {
note.paymentState = 'Unknown';
}
const promises = [];
for (let i = 1; i <= this.$toDecimal(res.nDelegates); i += 1) {
promises.push(
this.getNoteDelegate(idNote, i)
.then(r => ({
id: this.$toDecimal(r.idDelegate),
addr: r.addr,
name: r.name,
})),
);
}
return Promise.all(promises);
})
.then((delegates) => {
note.delegates = delegates;
return note;
});
};
LiquidPledging.prototype.$getManager = function (idManager) {
const manager = {}; const manager = {};
const res = await this.getNoteManager(idManager); return this.getNoteManager(idManager)
if (res.managerType === '0') { .then((res) => {
manager.type = 'Donor'; if (res.managerType === '0') {
} else if (res.managerType === '1') { manager.type = 'Donor';
manager.type = 'Delegate'; } else if (res.managerType === '1') {
} else if (res.managerType === '2') { manager.type = 'Delegate';
manager.type = 'Project'; } else if (res.managerType === '2') {
} else { manager.type = 'Project';
manager.type = 'Unknown'; } else {
} manager.type = 'Unknown';
manager.addr = res.addr; }
manager.name = res.name; manager.addr = res.addr;
manager.commitTime = this.$toDecimal(res.commitTime); manager.name = res.name;
if (manager.paymentState === 'Project') { manager.commitTime = this.$toDecimal(res.commitTime);
manager.parentProject = res.parentProject; if (manager.paymentState === 'Project') {
manager.canceled = res.canceled; manager.parentProject = res.parentProject;
} manager.canceled = res.canceled;
return manager; }
return manager;
});
}; };
LiquidPledging.prototype.$getManager = $getManager; LiquidPledging.prototype.getState = function () {
const getNotes = () => this.numberOfNotes()
.then((nNotes) => {
const promises = [];
for (let i = 1; i <= nNotes; i += 1) {
promises.push(this.$getNote(i));
}
return Promise.all(promises);
});
async function getState() { const getManagers = () => this.numberOfNoteManagers()
const st = { .then((nManagers) => {
notes: [null], const promises = [];
managers: [null], for (let i = 1; i <= nManagers; i += 1) {
}; promises.push(this.$getManager(i));
const nNotes = await this.numberOfNotes(); }
for (let i = 1; i <= nNotes; i += 1) {
const note = await this.$getNote(i);
st.notes.push(note);
}
const nManagers = await this.numberOfNoteManagers(); return Promise.all(promises);
for (let i = 1; i <= nManagers; i += 1) { });
const manager = await this.$getManager(i);
st.managers.push(manager); return Promise.all([getNotes(), getManagers()])
} .then(([notes, managers]) => ({
return st; notes: [null, ...notes],
managers: [null, ...managers],
}));
}; };
LiquidPledging.prototype.getState = getState;
LiquidPledging.prototype.generateDonorsState = function () { LiquidPledging.prototype.generateDonorsState = function () {
const donorsState = []; const donorsState = [];