Skip to content

Commit

Permalink
Beautify output
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Nov 23, 2023
1 parent f07bb5b commit 200fcb7
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions cmd/api/handler/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package handler

import (
"context"
"fmt"
"net/http"
"sort"
"strconv"
Expand Down Expand Up @@ -72,7 +73,7 @@ func (handler GasHandler) EstimateForPfb(c echo.Context) error {
}

const (
estimationGasPriceBlocksCount = 100
estimationGasPriceBlocksCount = 10
)

// EstimatePrice godoc
Expand Down Expand Up @@ -147,19 +148,19 @@ func (handler GasHandler) EstimatePrice(c echo.Context) error {
Height: uint64(gp.stats.Height),
GasWanted: uint64(gp.stats.GasLimit),
GasUsed: uint64(gp.stats.GasUsed),
Fee: gp.stats.Fee.String(),
Fee: gp.stats.Fee.StringFixed(0),
GasPrice: "0",
GasUsedRatio: "0",
TxCount: uint64(gp.stats.TxCount),
Percentiles: []string{
gp.percentiles[0].String(),
gp.percentiles[1].String(),
gp.percentiles[2].String(),
gp.percentiles[0].StringFixed(8),
gp.percentiles[1].StringFixed(8),
gp.percentiles[2].StringFixed(8),
},
}
if gp.stats.GasLimit > 0 {
block.GasUsedRatio = decimal.NewFromInt(gp.stats.GasUsed).Div(decimal.NewFromInt(gp.stats.GasLimit)).String()
block.GasPrice = gp.stats.Fee.Div(decimal.NewFromInt(gp.stats.GasLimit)).String()
block.GasUsedRatio = fmt.Sprintf("%.8f", float64(gp.stats.GasUsed)/float64(gp.stats.GasLimit))
block.GasPrice = fmt.Sprintf("%.8f", gp.stats.Fee.InexactFloat64()/float64(gp.stats.GasLimit))
}

gas.blocks = append(gas.blocks, block)
Expand Down Expand Up @@ -195,9 +196,9 @@ func newGasPrice() gasPrice {

func (gp gasPrice) toResponse() responses.GasPrice {
return responses.GasPrice{
Slow: gp.percentiles[0].String(),
Median: gp.percentiles[1].String(),
Fast: gp.percentiles[2].String(),
Slow: gp.percentiles[0].StringFixed(8),
Median: gp.percentiles[1].StringFixed(8),
Fast: gp.percentiles[2].StringFixed(8),
ComputedBlocks: gp.blocks,
}
}
Expand Down Expand Up @@ -240,7 +241,7 @@ func (handler GasHandler) computeGasPriceEstimationForBlock(ctx context.Context,
if txs[txIndex].GasPrice.LessThan(minGasPrice) {
gp.percentiles[txIndex] = minGasPrice.Copy()
} else {
gp.percentiles[i] = txs[txIndex].GasPrice
gp.percentiles[i] = txs[txIndex].GasPrice.Copy()
}
}

Expand Down

0 comments on commit 200fcb7

Please sign in to comment.