forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fee_stats.go
68 lines (59 loc) · 2 KB
/
fee_stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package actions
import (
"net/http"
"strconv"
"github.com/pownieh/stellar_go/protocols/horizon"
"github.com/pownieh/stellar_go/services/horizon/internal/operationfeestats"
)
// FeeStatsHandler is the action handler for the /fee_stats endpoint
type FeeStatsHandler struct {
}
// GetResource fee stats resource
func (handler FeeStatsHandler) GetResource(w HeaderWriter, r *http.Request) (interface{}, error) {
feeStats := horizon.FeeStats{}
cur, ok := operationfeestats.CurrentState()
feeStats.LastLedgerBaseFee = cur.LastBaseFee
feeStats.LastLedger = cur.LastLedger
// LedgerCapacityUsage is the empty string when operationfeestats has not had its state set
if ok {
capacity, err := strconv.ParseFloat(
cur.LedgerCapacityUsage,
64,
)
if err != nil {
return nil, err
}
feeStats.LedgerCapacityUsage = capacity
}
// FeeCharged
feeStats.FeeCharged.Max = cur.FeeChargedMax
feeStats.FeeCharged.Min = cur.FeeChargedMin
feeStats.FeeCharged.Mode = cur.FeeChargedMode
feeStats.FeeCharged.P10 = cur.FeeChargedP10
feeStats.FeeCharged.P20 = cur.FeeChargedP20
feeStats.FeeCharged.P30 = cur.FeeChargedP30
feeStats.FeeCharged.P40 = cur.FeeChargedP40
feeStats.FeeCharged.P50 = cur.FeeChargedP50
feeStats.FeeCharged.P60 = cur.FeeChargedP60
feeStats.FeeCharged.P70 = cur.FeeChargedP70
feeStats.FeeCharged.P80 = cur.FeeChargedP80
feeStats.FeeCharged.P90 = cur.FeeChargedP90
feeStats.FeeCharged.P95 = cur.FeeChargedP95
feeStats.FeeCharged.P99 = cur.FeeChargedP99
// MaxFee
feeStats.MaxFee.Max = cur.MaxFeeMax
feeStats.MaxFee.Min = cur.MaxFeeMin
feeStats.MaxFee.Mode = cur.MaxFeeMode
feeStats.MaxFee.P10 = cur.MaxFeeP10
feeStats.MaxFee.P20 = cur.MaxFeeP20
feeStats.MaxFee.P30 = cur.MaxFeeP30
feeStats.MaxFee.P40 = cur.MaxFeeP40
feeStats.MaxFee.P50 = cur.MaxFeeP50
feeStats.MaxFee.P60 = cur.MaxFeeP60
feeStats.MaxFee.P70 = cur.MaxFeeP70
feeStats.MaxFee.P80 = cur.MaxFeeP80
feeStats.MaxFee.P90 = cur.MaxFeeP90
feeStats.MaxFee.P95 = cur.MaxFeeP95
feeStats.MaxFee.P99 = cur.MaxFeeP99
return feeStats, nil
}