Skip to content

Commit

Permalink
[Rewards] Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
peak3d committed Jul 6, 2023
1 parent 8dea1cf commit bd84aba
Show file tree
Hide file tree
Showing 14 changed files with 386 additions and 1,055 deletions.
47 changes: 46 additions & 1 deletion api/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ func AddV2Routes(ctx *Context, router *web.Router, path string, indexBytes []byt
Get("/cacheassets", (*V2Context).CacheAssets).
Get("/cacheassetaggregates", (*V2Context).CacheAssetAggregates).
Get("/cacheaggregates/:id", (*V2Context).CacheAggregates).
Get("/multisigalias/:owners", (*V2Context).GetMultisigAlias)
Get("/multisigalias/:owners", (*V2Context).GetMultisigAlias).
Post("/rewards", (*V2Context).GetRewardPost)
}

// AVAX
Expand Down Expand Up @@ -546,6 +547,50 @@ func (c *V2Context) GetMultisigAlias(w web.ResponseWriter, r *web.Request) {
})
}

func (c *V2Context) GetRewardPost(w web.ResponseWriter, r *web.Request) {
collectors := utils.NewCollectors(
utils.NewCounterObserveMillisCollect(MetricMillis),
utils.NewCounterIncCollect(MetricCount),
utils.NewCounterObserveMillisCollect(MetricAggregateMillis),
utils.NewCounterIncCollect(MetricAggregateCount),
)
defer func() {
_ = collectors.Collect()
}()

p := &params.ListTransactionsParams{}
q, err := ParseGetJSON(r, cfg.RequestGetMaxSize)
if err != nil {
c.WriteErr(w, 400, err)
return
}
if err := p.ForValues(c.version, q); err != nil {
c.WriteErr(w, 400, err)
return
}

addrsParam := q["addresses"]
addresses := []string{}
for _, addrParam := range addrsParam {
// convert owner address from bech32 to be used internally
addr, err := address.ParseToID(addrParam)
if err != nil {
c.WriteErr(w, 400, err)
return
}
addresses = append(addresses, addr.String())
}
// calculate cache key from addresses
cacheKey := fmt.Sprintf("%x", sha256.Sum256([]byte(strings.Join(addrsParam, ""))))
c.WriteCacheable(w, caching.Cacheable{
TTL: 5 * time.Second,
Key: c.cacheKeyForID("reward", cacheKey),
CacheableFn: func(ctx context.Context) (interface{}, error) {
return c.avaxReader.GetReward(ctx, addresses)
},
})
}

func (c *V2Context) ListTransactions(w web.ResponseWriter, r *web.Request) {
collectors := utils.NewCollectors(
utils.NewCounterObserveMillisCollect(MetricMillis),
Expand Down
11 changes: 0 additions & 11 deletions cmds/magelland/magelland.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/chain4travel/magellan/cfg"
"github.com/chain4travel/magellan/db"
"github.com/chain4travel/magellan/models"
"github.com/chain4travel/magellan/services/rewards"
"github.com/chain4travel/magellan/servicesctrl"
"github.com/chain4travel/magellan/stream"
"github.com/chain4travel/magellan/stream/consumers"
Expand Down Expand Up @@ -358,16 +357,6 @@ func runStreamProcessorManagers(
bm.Close()
}()

rh := &rewards.Handler{}
err = rh.Start(sc)
if err != nil {
*runError = err
return
}
defer func() {
rh.Close()
}()

err = consumers.Bootstrap(sc, config.NetworkID, config, consumerFactories)
if err != nil {
*runError = err
Expand Down
Loading

0 comments on commit bd84aba

Please sign in to comment.