Skip to content

Commit

Permalink
Add accumulated vest to circulation
Browse files Browse the repository at this point in the history
  • Loading branch information
kacpersaw committed Jul 16, 2024
1 parent f205ebb commit 47c9278
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 101 deletions.
18 changes: 14 additions & 4 deletions dash-backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"github.com/spacemeshos/dash-backend/utils"
"github.com/spacemeshos/economics/vesting"
"io"
"math/rand"
"net/http"
Expand Down Expand Up @@ -107,11 +108,20 @@ func main() {
})

http.HandleFunc("/circulating", func(w http.ResponseWriter, r *http.Request) {
stats := history.GetStats()
var circulation int64 = 0
for _, val := range stats.Circulation {
circulation += val.Amt
networkInfo, err := history.GetStorage().GetNetworkInfo(context.Background())
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}

accumulatedVest := vesting.AccumulatedVestAtLayer(networkInfo.TopLayer)
sum, err := history.GetStorage().GetRewardsTotalSum(context.Background())
if err != nil {
log.Warning("GetRewardsTotalSum error: %v", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
var circulation = int64(accumulatedVest) + sum
c := utils.ParseSmidge(float64(circulation))

w.WriteHeader(http.StatusOK)
Expand Down
64 changes: 33 additions & 31 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module github.com/spacemeshos/dash-backend

go 1.21.7
go 1.22.5

require (
github.com/gorilla/websocket v1.5.0
github.com/spacemeshos/explorer-backend v1.5.1
github.com/spacemeshos/go-spacemesh v1.4.0-alpha.1.0.20240222125138-5e7397f4e057
github.com/urfave/cli/v2 v2.23.7
github.com/gorilla/websocket v1.5.1
github.com/spacemeshos/economics v0.1.3
github.com/spacemeshos/explorer-backend v1.7.3
github.com/spacemeshos/go-spacemesh v1.6.2
github.com/urfave/cli/v2 v2.27.2
go.mongodb.org/mongo-driver v1.11.1
)

Expand All @@ -17,51 +18,52 @@ require (
github.com/anacrolix/sync v0.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/c0mm4nd/go-ripemd v0.0.0-20200326052756-bd1759ad7d10 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/go-llsqlite/crawshaw v0.5.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/go-llsqlite/crawshaw v0.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/huandu/xstrings v1.2.0 // indirect
github.com/klauspost/compress v1.17.3 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.47.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spacemeshos/address v0.0.0-20220829090052-44ab32617871 // indirect
github.com/spacemeshos/api/release/go v1.30.0 // indirect
github.com/spacemeshos/go-scale v1.1.12 // indirect
github.com/spacemeshos/api/release/go v1.50.0 // indirect
github.com/spacemeshos/go-scale v1.2.0 // indirect
github.com/spacemeshos/merkle-tree v0.2.3 // indirect
github.com/spacemeshos/poet v0.10.2 // indirect
github.com/spacemeshos/post v0.11.0 // indirect
github.com/spacemeshos/poet v0.10.3 // indirect
github.com/spacemeshos/post v0.12.7 // indirect
github.com/spacemeshos/sha256-simd v0.1.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
github.com/zeebo/assert v1.3.0 // indirect
github.com/zeebo/blake3 v0.2.3 // indirect
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/grpc v1.62.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
Loading

0 comments on commit 47c9278

Please sign in to comment.