webapi: Fix revoked % calculation.
This commit is contained in:
parent
1dbcb785df
commit
fc1f7f2955
@ -108,16 +108,13 @@ func (c *cache) update(db *database.VspDatabase, dcrd rpc.DcrdConnect,
|
|||||||
c.data.BlockHeight = bestBlock.Height
|
c.data.BlockHeight = bestBlock.Height
|
||||||
c.data.NetworkProportion = float32(voting) / float32(bestBlock.PoolSize)
|
c.data.NetworkProportion = float32(voting) / float32(bestBlock.PoolSize)
|
||||||
|
|
||||||
// Prevent dividing by zero when pool has no voted tickets.
|
total := voted + revoked
|
||||||
switch voted {
|
|
||||||
case 0:
|
// Prevent dividing by zero when pool has no voted/revoked tickets.
|
||||||
if revoked == 0 {
|
if total == 0 {
|
||||||
c.data.RevokedProportion = 0
|
c.data.RevokedProportion = 0
|
||||||
} else {
|
} else {
|
||||||
c.data.RevokedProportion = 1
|
c.data.RevokedProportion = float32(revoked) / float32(total)
|
||||||
}
|
|
||||||
default:
|
|
||||||
c.data.RevokedProportion = float32(revoked) / float32(voted)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user