From 095a06b051ded47d65353d48ecf38384999477b8 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Mon, 9 Oct 2023 14:24:58 +0530 Subject: [PATCH] generics --- params/config.go | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/params/config.go b/params/config.go index ccadd953ca..5f311f8e0f 100644 --- a/params/config.go +++ b/params/config.go @@ -766,7 +766,7 @@ func (c *BorConfig) calculateBorConfigHelper(field map[string]uint64, number uin return field[keys[len(keys)-1]] } -func borKeyValueConfigHelper(field map[string]uint64, number uint64) uint64 { +func borKeyValueConfigHelper[T uint64 | string](field map[string]T, number uint64) T { keys := make([]string, 0, len(field)) for k := range field { keys = append(keys, k) @@ -787,23 +787,7 @@ func borKeyValueConfigHelper(field map[string]uint64, number uint64) uint64 { } func (c *BorConfig) CalculateBurntContract(number uint64) string { - keys := make([]string, 0, len(c.BurntContract)) - for k := range c.BurntContract { - keys = append(keys, k) - } - - sort.Strings(keys) - - for i := 0; i < len(keys)-1; i++ { - valUint, _ := strconv.ParseUint(keys[i], 10, 64) - valUintNext, _ := strconv.ParseUint(keys[i+1], 10, 64) - - if number >= valUint && number < valUintNext { - return c.BurntContract[keys[i]] - } - } - - return c.BurntContract[keys[len(keys)-1]] + return borKeyValueConfigHelper(c.BurntContract, number) } // Description returns a human-readable description of ChainConfig.