Skip to content

Commit

Permalink
feat(transaction):add feetype and netused for transaction and transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
chengenguan committed Jan 14, 2019
1 parent 29466c7 commit 0a0282c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/contract/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
11 changes: 5 additions & 6 deletions src/interface/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/interface/transfers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
})
Expand Down

0 comments on commit 0a0282c

Please sign in to comment.