Skip to content

Commit

Permalink
Fix: contract calls stats
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored and m-kus committed Oct 12, 2020
1 parent 85732cc commit c7558c6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cmd/api/handlers/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ func getHistogramOptions(name, network string, addresses ...string) ([]elastic.H
Kind: elastic.HistogramFilterKindExists,
})

filters = append(filters, elastic.HistogramFilter{
Field: "status",
Value: "applied",
Kind: elastic.HistogramFilterKindMatch,
})

if len(addresses) > 0 {
filters = append(filters, elastic.HistogramFilter{
Kind: elastic.HistogramFilterKindAddresses,
Expand Down
3 changes: 2 additions & 1 deletion internal/elastic/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func (e *Elastic) GetDAppStats(network string, addresses []string, period string

matches := []qItem{
matchQ("network", network),
exists("entrypoint"),
boolQ(
should(addressMatches...),
minimumShouldMatch(1),
Expand All @@ -300,7 +301,7 @@ func (e *Elastic) GetDAppStats(network string, addresses []string, period string
).Add(
aggs(
aggItem{"users", cardinality("source.keyword")},
aggItem{"tx", count("indexed_time")},
aggItem{"calls", count("indexed_time")},
aggItem{"volume", sum("amount")},
),
).Zero()
Expand Down
4 changes: 2 additions & 2 deletions internal/elastic/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,13 @@ type TokenUsageStats map[string]TokenMethodUsageStats
// DAppStats -
type DAppStats struct {
Users int64 `json:"users"`
Txs int64 `json:"txs"`
Calls int64 `json:"txs"`
Volume int64 `json:"volume"`
}

// ParseElasticJSON -
func (stats *DAppStats) ParseElasticJSON(hit gjson.Result) {
stats.Txs = hit.Get("tx.value").Int()
stats.Calls = hit.Get("calls.value").Int()
stats.Users = hit.Get("users.value").Int()
stats.Volume = hit.Get("volume.value").Int()
}
Expand Down

0 comments on commit c7558c6

Please sign in to comment.