From 0a0282c53b621df5945af615862eb3dc3b6f5525 Mon Sep 17 00:00:00 2001 From: chengenguan <2630109260@qq.com> Date: Mon, 14 Jan 2019 15:23:13 +0800 Subject: [PATCH] feat(transaction):add feetype and netused for transaction and transfer --- src/contract/basic.js | 2 +- src/interface/transactions.js | 11 +++++------ src/interface/transfers.js | 7 +++++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/contract/basic.js b/src/contract/basic.js index 4016ef7..951b2d2 100644 --- a/src/contract/basic.js +++ b/src/contract/basic.js @@ -491,7 +491,7 @@ module.exports = { if (netAmount < 0 || energyAmount < 0) return 'Amount should be positive number' const sender = this.sender const pledgeAccount = await app.sdb.load('AccountPledge', sender.address) - if (!pledgeAccount) return `No pledege for account ${sender.address}` + if (!pledgeAccount) return `No pledge for account ${sender.address}` const totalPledges = await app.sdb.loadMany('AccountTotalPledge', { }) if (totalPledges.length === 0) return 'Total pledge is not set' if (totalPledges[0].totalPledgeForNet < netAmount || totalPledges[0].totalPledgeForEnergy < energyAmount) return 'Insufficient balance in AccountTotalPledges' diff --git a/src/interface/transactions.js b/src/interface/transactions.js index 639ba88..b6a2823 100644 --- a/src/interface/transactions.js +++ b/src/interface/transactions.js @@ -3,13 +3,12 @@ function defined(obj) { } async function handleTransaction(trs) { - if (trs.fee < 0) { - const gasConsume = await app.sdb.findOne('Gasconsumption', { condition: { tid: trs.id } }) - trs.gasUsed = gasConsume.gasUsed - trs.gasCurrency = gasConsume.money + const netconsumption = await app.sdb.findOne('Netenergyconsumption', { condition: { tid: trs.id } }) + if (netconsumption) { + trs.feeType = 'NET' + trs.netUsed = netconsumption.netUsed } else { - trs.gasUsed = trs.fee - trs.gasCurrency = 'XAS' + trs.feeType = 'XAS' } } diff --git a/src/interface/transfers.js b/src/interface/transfers.js index 3a31eeb..adb5907 100644 --- a/src/interface/transfers.js +++ b/src/interface/transfers.js @@ -94,6 +94,13 @@ module.exports = (router) => { t.amount = t.amount.slice(0, pos) } } + const netconsumption = await app.sdb.findOne('Netenergyconsumption', { condition: { tid: t.tid } }) + if (netconsumption) { + t.feeType = 'NET' + t.netUsed = netconsumption.netUsed + } else { + t.feeType = 'XAS' + } } return { count, transfers } })