Skip to content

Commit

Permalink
stats: use decimal.Decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Oct 30, 2023
1 parent bd1e269 commit e5d0dc1
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package stats
import (
"time"

"github.com/shopspring/decimal"
"go.sia.tech/core/types"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -30,10 +31,10 @@ type (
}

Values struct {
SC types.Currency `json:"sc"`
USD float64 `json:"usd"`
EUR float64 `json:"eur"`
BTC float64 `json:"btc"`
SC types.Currency `json:"sc"`
USD decimal.Decimal `json:"usd"`
EUR decimal.Decimal `json:"eur"`
BTC decimal.Decimal `json:"btc"`
}

ContractState struct {
Expand All @@ -58,6 +59,15 @@ type (
}
)

func (v Values) Add(b Values) Values {
return Values{
SC: v.SC.Add(b.SC),
USD: v.USD.Add(b.USD),
EUR: v.EUR.Add(b.EUR),
BTC: v.BTC.Add(b.BTC),
}
}

func (p *Provider) Metrics(timestamp time.Time) (ContractState, error) {
return p.store.Metrics(timestamp)
}
Expand Down

0 comments on commit e5d0dc1

Please sign in to comment.