Skip to content

Commit

Permalink
Add accounts count and vested amount to epoch stats
Browse files Browse the repository at this point in the history
  • Loading branch information
kacpersaw committed Sep 12, 2024
1 parent e70b235 commit cdd743e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions api/storage/epoch.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package storage

import (

Check failure on line 3 in api/storage/epoch.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)
"github.com/spacemeshos/economics/constants"

Check failure on line 4 in api/storage/epoch.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/spacemeshos/go-spacemesh) (gci)
"math"

Check failure on line 5 in api/storage/epoch.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)

Check failure on line 6 in api/storage/epoch.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/spacemeshos/go-spacemesh) (gci)
"github.com/spacemeshos/explorer-backend/utils"
Expand All @@ -20,6 +21,8 @@ type EpochStats struct {
NumUnits uint64 `json:"num_units,omitempty"`
SmeshersCount uint64 `json:"smeshers_count,omitempty"`
Decentral uint64 `json:"decentral,omitempty"`
VestedAmount uint64 `json:"vested_amount,omitempty"`
AccountsCount uint64 `json:"accounts_count,omitempty"`
}

func (c *Client) GetEpochStats(db *sql.Database, epoch, layersPerEpoch int64) (*EpochStats, error) {
Expand All @@ -32,6 +35,15 @@ func (c *Client) GetEpochStats(db *sql.Database, epoch, layersPerEpoch int64) (*

start := epoch * layersPerEpoch
end := start + layersPerEpoch - 1
currentEpoch := c.NodeClock.CurrentLayer().Uint32() / uint32(layersPerEpoch)

if !c.Testnet && start >= constants.VestStart && start <= constants.VestEnd {
if epoch == int64(currentEpoch) {
stats.VestedAmount = (uint64(c.NodeClock.CurrentLayer().Uint32()) - uint64(start-1)) * constants.VestPerLayer

Check failure on line 42 in api/storage/epoch.go

View workflow job for this annotation

GitHub Actions / lint

the line is 121 characters long, which exceeds the maximum of 120 characters. (lll)
} else {
stats.VestedAmount = uint64(layersPerEpoch) * constants.VestPerLayer
}
}

_, err := db.Exec(`SELECT COUNT(*)
FROM (
Expand Down Expand Up @@ -104,6 +116,19 @@ FROM (
return true
})

_, err = db.Exec(`SELECT COUNT(DISTINCT address)
FROM transactions_results_addresses
WHERE tid IN (
SELECT id FROM transactions WHERE layer >= ?1 AND layer <= ?2)`,
func(statement *sql.Statement) {
statement.BindInt64(1, start)
statement.BindInt64(2, end)
},
func(statement *sql.Statement) bool {
stats.AccountsCount = uint64(statement.ColumnInt64(0))
return true
})

return stats, err
}

Expand Down

0 comments on commit cdd743e

Please sign in to comment.