Skip to content

Commit

Permalink
[PVM, Dependencies] DAC txs and proposals (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
evlekht authored Jan 22, 2024
1 parent fadf074 commit 4467dc4
Show file tree
Hide file tree
Showing 15 changed files with 1,662 additions and 49 deletions.
49 changes: 47 additions & 2 deletions api/v2.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2022, Chain4Travel AG. All rights reserved.
// Copyright (C) 2022-2023, Chain4Travel AG. All rights reserved.
//
// This file is a derived work, based on ava-labs code whose
// original notices appear below.
Expand Down Expand Up @@ -153,7 +153,9 @@ func AddV2Routes(ctx *Context, router *web.Router, path string, indexBytes []byt
Get("/cacheassetaggregates", (*V2Context).CacheAssetAggregates).
Get("/cacheaggregates/:id", (*V2Context).CacheAggregates).
Get("/multisigalias/:owners", (*V2Context).GetMultisigAlias).
Post("/rewards", (*V2Context).GetRewardPost)
Post("/rewards", (*V2Context).GetRewardPost).
Get("/proposals", (*V2Context).ListDACProposals).
Get("/proposals/:id", (*V2Context).GetDACProposalWithVotes)
}

// AVAX
Expand Down Expand Up @@ -1145,3 +1147,46 @@ func (c *V2Context) CacheAggregates(w web.ResponseWriter, r *web.Request) {

WriteJSON(w, b)
}

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

params := &params.ListDACProposalsParams{}
if err := params.ForValues(c.version, r.URL.Query()); err != nil {
c.WriteErr(w, 400, err)
return
}

c.WriteCacheable(w, caching.Cacheable{
TTL: 5 * time.Second,
Key: c.cacheKeyForParams("list_dac_proposals", params),
CacheableFn: func(ctx context.Context) (interface{}, error) {
return c.avaxReader.ListDACProposals(ctx, params)
},
})
}

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

proposalID := r.PathParams["id"]
c.WriteCacheable(w, caching.Cacheable{
TTL: 5 * time.Second,
Key: c.cacheKeyForID("get_dac_proposal", proposalID),
CacheableFn: func(ctx context.Context) (interface{}, error) {
return c.avaxReader.GetDACProposalWithVotes(ctx, proposalID)
},
})
}
Loading

0 comments on commit 4467dc4

Please sign in to comment.