Skip to content

Commit

Permalink
Nobids/gnosis follow up minor (#2612)
Browse files Browse the repository at this point in the history
* (NOBIDS) Fix help for comman parameter for misc tool

* (NOBIDS) Remove unused function FormatBlockReward

* (NOBIDS) Remove commented-out code

* (NOBIDS) Improve possible early exit

* (NOBIDS) Fix index page for empty IndexPageData

* (NOBIDS) Remove GetEthRoundPrice

* (NOBIDS) Make more use of MainCurrency

* (NOBIDS) Use %w for err

* (NOBIDS) Add log entry when retrieving token metadata
  • Loading branch information
D13ce authored Oct 18, 2023
1 parent dc2f7a6 commit 8d0e559
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 74 deletions.
2 changes: 1 addition & 1 deletion cmd/misc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var opts = struct {

func main() {
configPath := flag.String("config", "config/default.config.yml", "Path to the config file")
flag.StringVar(&opts.Command, "command", "", "command to run, available: updateAPIKey, applyDbSchema, initBigtableSchema, epoch-export, debug-rewards, clear-bigtable, index-old-eth1-blocks, update-aggregation-bits, historic-prices-export, index-missing-blocks, export-epoch-missed-slots, migrate-last-attestation-slot-bigtable, generate-config-from-testnet-stub, export-genesis-validators")
flag.StringVar(&opts.Command, "command", "", "command to run, available: updateAPIKey, applyDbSchema, initBigtableSchema, epoch-export, debug-rewards, debug-blocks, clear-bigtable, index-old-eth1-blocks, update-aggregation-bits, historic-prices-export, index-missing-blocks, export-epoch-missed-slots, migrate-last-attestation-slot-bigtable, export-genesis-validators, update-block-finalization-sequentially, nameValidatorsByRanges")
flag.Uint64Var(&opts.StartEpoch, "start-epoch", 0, "start epoch")
flag.Uint64Var(&opts.EndEpoch, "end-epoch", 0, "end epoch")
flag.Uint64Var(&opts.User, "user", 0, "user id")
Expand Down
2 changes: 2 additions & 0 deletions db/bigtable_eth1.go
Original file line number Diff line number Diff line change
Expand Up @@ -3425,6 +3425,8 @@ func (bigtable *Bigtable) GetERC20MetadataForAddress(address []byte) (*types.ERC
// }

if row == nil { // Retrieve token metadata from Ethplorer and store it for later usage
logger.Infof("retrieving metadata for token %x via rpc", address)

metadata, err := rpc.CurrentGethClient.GetERC20TokenMetadata(address)
if err != nil {
logger.Warnf("error retrieving metadata for token %x: %v", address, err)
Expand Down
4 changes: 2 additions & 2 deletions db/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -1712,8 +1712,8 @@ func WriteExecutionChartSeriesForDay(day int64) error {
switch utils.Config.Chain.ClConfig.DepositChainID {
case 1:
crowdSale := 72009990.50
logger.Infof("Exporting MARKET_CAP: %v", newEmission.Div(decimal.NewFromInt(1e18)).Add(decimal.NewFromFloat(crowdSale)).Mul(decimal.NewFromFloat(price.GetPrice("ETH", "USD"))).String())
err = SaveChartSeriesPoint(dateTrunc, "MARKET_CAP", newEmission.Div(decimal.NewFromInt(1e18)).Add(decimal.NewFromFloat(crowdSale)).Mul(decimal.NewFromFloat(price.GetPrice("ETH", "USD"))).String())
logger.Infof("Exporting MARKET_CAP: %v", newEmission.Div(decimal.NewFromInt(1e18)).Add(decimal.NewFromFloat(crowdSale)).Mul(decimal.NewFromFloat(price.GetPrice(utils.Config.Frontend.MainCurrency, "USD"))).String())
err = SaveChartSeriesPoint(dateTrunc, "MARKET_CAP", newEmission.Div(decimal.NewFromInt(1e18)).Add(decimal.NewFromFloat(crowdSale)).Mul(decimal.NewFromFloat(price.GetPrice(utils.Config.Frontend.MainCurrency, "USD"))).String())
if err != nil {
return fmt.Errorf("error calculating MARKET_CAP chart_series: %w", err)
}
Expand Down
7 changes: 1 addition & 6 deletions price/price.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func getPriceFromFeed(feed *chainlink_feed.Feed) (float64, error) {
decimals := decimal.NewFromInt(1e8) // 8 decimal places for the Chainlink feeds
res, err := feed.LatestRoundData(&bind.CallOpts{})
if err != nil {
return 0, fmt.Errorf("failed to fetch latest chainlink eth/usd price feed data: %v", err)
return 0, fmt.Errorf("failed to fetch latest chainlink eth/usd price feed data: %w", err)
}
return decimal.NewFromBigInt(res.Answer, 0).Div(decimals).InexactFloat64(), nil
}
Expand Down Expand Up @@ -276,8 +276,3 @@ func GetCurrencySymbol(currency string) string {
}
return x.Symbol
}

func GetEthRoundPrice(currency float64) uint64 {
ethRoundPrice := uint64(currency)
return ethRoundPrice
}
38 changes: 2 additions & 36 deletions services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -1065,42 +1065,8 @@ func LatestIndexPageData() *types.IndexPageData {
} else {
logger.Errorf("error retrieving indexPageData from cache: %v", err)
}
return &types.IndexPageData{
NetworkName: "",
DepositContract: "",
ShowSyncingMessage: false,
CurrentEpoch: 0,
CurrentFinalizedEpoch: 0,
CurrentSlot: 0,
ScheduledCount: 0,
FinalityDelay: 0,
ActiveValidators: 0,
EnteringValidators: 0,
ExitingValidators: 0,
StakedEther: "",
AverageBalance: "",
DepositedTotal: 0,
DepositThreshold: 0,
ValidatorsRemaining: 0,
NetworkStartTs: 0,
MinGenesisTime: 0,
Blocks: []*types.IndexPageDataBlocks{},
Epochs: []*types.IndexPageDataEpochs{},
StakedEtherChartData: [][]float64{},
ActiveValidatorsChartData: [][]float64{},
Title: "",
Subtitle: "",
Genesis: false,
GenesisPeriod: false,
Mainnet: false,
DepositChart: &types.ChartsPageDataChart{},
DepositDistribution: &types.ChartsPageDataChart{},
Countdown: nil,
SlotVizData: nil,
ValidatorsPerEpoch: 0,
ValidatorsPerDay: 0,
NewDepositProcessAfter: "",
}

return &types.IndexPageData{}
}

// LatestPoolsPageData returns the latest pools page data
Expand Down
2 changes: 1 addition & 1 deletion templates/index/depositDistribution.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
</div>
</figure>
<script>
{{if .DepositDistribution}}
{{if and .DepositDistribution .DepositDistribution.Data}}
var drill = {{.DepositDistribution.Data.Drilldown}}
for (let i=0; i<drill.series.length; i++){
for (let j=0; j<drill.series[i].data.length; j++){
Expand Down
32 changes: 4 additions & 28 deletions utils/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ func FormatBalanceChangeFormated(balance *int64, currencyName string, details *i
currencyFunc = ClToCurrency
}

if balance == nil || *balance == 0 {
return template.HTML(fmt.Sprintf("<span class=\"float-right\">0 %s</span>", currencySymbol))
}

maxDigits := uint(6)

income := ""
Expand Down Expand Up @@ -308,9 +312,6 @@ func FormatBalanceChangeFormated(balance *int64, currencyName string, details *i
income += fmt.Sprintf("Total: %s %s", FormatAddCommasFormated(currencyFunc(details.TotalClRewards(), currencyName).InexactFloat64(), maxDigits), currencySymbol)
}

if balance == nil || *balance == 0 {
return template.HTML(fmt.Sprintf("<span class=\"float-right\">0 %s</span>", currencySymbol))
}
if *balance < 0 {
return template.HTML(fmt.Sprintf("<span title='%s' data-html=\"true\" data-toggle=\"tooltip\" class=\"text-danger float-right\">%s %s</span>", income, FormatAddCommasFormated(currencyFunc(*balance, currencyName).InexactFloat64(), maxDigits), currencySymbol))
}
Expand Down Expand Up @@ -504,17 +505,6 @@ func FormatTransactionType(txnType uint8) string {
// FormatCurrentBalance will return the current balance formated as string with 9 digits after the comma (1 gwei = 1e9 eth)
func FormatCurrentBalance(balanceInt uint64, currency string) template.HTML {
return template.HTML(fmt.Sprintf(`%s %v`, exchangeAndTrim(Config.Frontend.ClCurrency, currency, float64(balanceInt), false), currency))
/*
if currency == Config.Frontend.ClCurrency {
exchangeRate := price.GetPrice(Config.Frontend.ClCurrency, currency)
balance := float64(balanceInt) / float64(Config.Frontend.ClCurrencyDivisor)
return template.HTML(fmt.Sprintf("%.5f %v", balance*exchangeRate, currency))
} else {
exchangeRate := price.GetPrice(Config.Frontend.ClCurrency, currency)
balance := FormatFloat((float64(balanceInt)/float64(Config.Frontend.ClCurrencyDivisor))*float64(exchangeRate), 2)
return template.HTML(fmt.Sprintf(`%s %v`, balance, currency))
}
*/
}

// FormatDepositAmount will return the deposit amount formated as string
Expand Down Expand Up @@ -1193,20 +1183,6 @@ func FormatNotificationChannel(ch types.NotificationChannel) template.HTML {
return label
}

func FormatBlockReward(blockNumber int64) template.HTML {
var reward *big.Int

if blockNumber < 4370000 {
reward = big.NewInt(5e+18)
} else if blockNumber < 7280000 {
reward = big.NewInt(3e+18)
} else {
reward = big.NewInt(2e+18)
}

return FormatAmount(reward, Config.Frontend.ElCurrency, 5)
}

func FormatTokenBalance(balance *types.Eth1AddressBalance) template.HTML {
p := message.NewPrinter(language.English)

Expand Down

0 comments on commit 8d0e559

Please sign in to comment.