-
Notifications
You must be signed in to change notification settings - Fork 457
Fixed fees calculations in getForgedByAccount endpoint #384
Changes from 9 commits
a58288f
47ecf23
ddffa97
0817002
65e3cdb
539b4ba
0e6064d
9a38a92
c6022f3
24cac3d
0f8cc6f
0dca3d2
858ea7d
f08ee65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -761,8 +761,11 @@ shared.getForgedByAccount = function (req, cb) { | |
return setImmediate(cb, err[0].message); | ||
} | ||
|
||
if (req.body.start && req.body.end) { | ||
if (req.body.start !== undefined || req.body.end !== undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why changed condition here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should allow |
||
modules.blocks.aggregateBlocksReward({generatorPublicKey: req.body.generatorPublicKey, start: req.body.start, end: req.body.end}, function (err, reward) { | ||
if (err) { | ||
return setImmediate(cb, err); | ||
} | ||
var forged = bignum(reward.fees).plus(bignum(reward.rewards)).toString(); | ||
return setImmediate(cb, null, {fees: reward.fees, rewards: reward.rewards, forged: forged, count: reward.count}); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,9 +26,51 @@ var BlocksSql = { | |
|
||
aggregateBlocksReward: function (params) { | ||
return [ | ||
'SELECT SUM("b_totalFee") AS fees, SUM("b_reward") AS rewards, COUNT(1) AS count', | ||
'FROM blocks_list', | ||
(params.where.length ? 'WHERE ' + params.where.join(' AND ') : '') | ||
'WITH', | ||
'delegate as (SELECT', | ||
'1 FROM mem_accounts m WHERE m."isDelegate" = 1 AND m."publicKey" = DECODE (${generatorPublicKey}, \'hex\') LIMIT 1),', | ||
'borders as (SELECT', | ||
'(SELECT (CAST(b.height / ${delegates} AS INTEGER) + (CASE WHEN b.height % ${delegates} > 0 THEN 1 ELSE 0 END)) FROM blocks b ORDER BY b.height DESC LIMIT 1) as current,', | ||
'(SELECT (CAST(b.height / ${delegates} AS INTEGER) + (CASE WHEN b.height % ${delegates} > 0 THEN 1 ELSE 0 END)) FROM blocks b', | ||
(params.start !== undefined ? ' WHERE b.timestamp >= ${start}' : ''), | ||
'ORDER BY b.height ASC LIMIT 1) as min,', | ||
'(SELECT (CAST(b.height / ${delegates} AS INTEGER) + (CASE WHEN b.height % ${delegates} > 0 THEN 1 ELSE 0 END)) FROM blocks b', | ||
(params.end !== undefined ? ' WHERE b.timestamp <= ${end}' : ''), | ||
'ORDER BY b.height DESC LIMIT 1) as max', | ||
'),', | ||
'r as (SELECT DISTINCT ', | ||
'(CAST(b.height / ${delegates} AS INTEGER) + (CASE WHEN b.height % ${delegates} > 0 THEN 1 ELSE 0 END)) AS round', | ||
'FROM blocks b WHERE b."generatorPublicKey" = DECODE (${generatorPublicKey}, \'hex\')),', | ||
're as (SELECT r.round as round, ((r.round-1)*${delegates})+1 as min, r.round*${delegates} as max', | ||
'FROM r WHERE r.round >= (SELECT min FROM borders) AND round <= (SELECT max FROM borders)),', | ||
'sum_min as (SELECT', | ||
'sum(CASE WHEN b."generatorPublicKey" = DECODE (${generatorPublicKey}, \'hex\') THEN b.reward ELSE 0 END) AS rewards,', | ||
'sum(CASE WHEN b."generatorPublicKey" = DECODE (${generatorPublicKey}, \'hex\') THEN 1 ELSE 0 END) AS blocks', | ||
'FROM blocks b WHERE b.height BETWEEN (SELECT min FROM re ORDER BY round ASC LIMIT 1) AND (SELECT max FROM re ORDER BY round ASC LIMIT 1)', | ||
(params.start !== undefined ? 'AND b.timestamp >= ${start}' : ''), | ||
'),', | ||
'sum_max as (SELECT', | ||
'sum(CASE WHEN b."generatorPublicKey" = DECODE (${generatorPublicKey}, \'hex\') THEN b.reward ELSE 0 END) AS rewards,', | ||
'sum(CASE WHEN b."generatorPublicKey" = DECODE (${generatorPublicKey}, \'hex\') THEN 1 ELSE 0 END) AS blocks', | ||
'FROM blocks b WHERE b.height BETWEEN (SELECT min FROM re ORDER BY round DESC LIMIT 1) AND (SELECT max FROM re ORDER BY round DESC LIMIT 1)', | ||
(params.end !== undefined ? 'AND b.timestamp <= ${end}' : ''), | ||
'),', | ||
'rs as (SELECT re.*, SUM(b."totalFee") AS fees,', | ||
'sum(CASE WHEN b."generatorPublicKey" = DECODE (${generatorPublicKey}, \'hex\') THEN b.reward ELSE 0 END) AS rewards,', | ||
'sum(CASE WHEN b."generatorPublicKey" = DECODE (${generatorPublicKey}, \'hex\') THEN 1 ELSE 0 END) AS blocks', | ||
'FROM re, blocks b WHERE b.height BETWEEN re.min AND re.max GROUP BY re.round, re.min, re.max),', | ||
'rsc as (SELECT', | ||
'(CASE WHEN round = borders.current THEN 0 ELSE fees END), round,', | ||
'(CASE WHEN round = borders.min THEN (SELECT blocks FROM sum_min) ELSE (CASE WHEN round = borders.max THEN (SELECT blocks FROM sum_max) ELSE blocks END) END) as blocks,', | ||
'(CASE WHEN round = borders.min THEN (SELECT rewards FROM sum_min) ELSE (CASE WHEN round = borders.max THEN (SELECT rewards FROM sum_max) ELSE rewards END) END) as rewards,', | ||
'(SELECT 1 FROM blocks b WHERE b.height = rs.max AND b."generatorPublicKey" = DECODE (${generatorPublicKey}, \'hex\') LIMIT 1) AS last', | ||
'FROM rs, borders)', | ||
'SELECT', | ||
'(SELECT * FROM delegate) as delegate,', | ||
'sum (rsc.blocks) as count,', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @4miners Please capitalize postgres syntax such as |
||
'sum(floor(rsc.fees/${delegates})*rsc.blocks + (CASE WHEN rsc.last = 1 THEN (rsc.fees-floor(rsc.fees/${delegates})*${delegates}) ELSE 0 END)) as fees,', | ||
'sum(rsc.rewards) as rewards', | ||
'FROM rsc' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wow There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @4miners: Would it be possible to move this query to a postgres view? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll check that. |
||
].filter(Boolean).join(' '); | ||
}, | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@4miners
Account not found or is not a delegate
.