add: hex2uint64 util

This commit is contained in:
Mohamed Sohail 2021-12-14 18:41:24 +03:00
parent b20ad7c443
commit 69202baadb
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D
3 changed files with 18 additions and 5 deletions

View File

@ -8,7 +8,7 @@ A tiny stateless service to return health status and useful metrics from OpenEth
#### Endpoints
- `/health` (Expect 200 for health with an additional JSON object with more info)
- `/metrics` (Expect 200 for health with an additional JSON object with more info)
- `/metrics` (Expect 200 with an additional JSON object with more info)
#### Development

View File

@ -2,6 +2,7 @@ package server
import (
"git.grassecon.org/grassrootseconomics/openethereum-node-status/pkg/rpc"
"git.grassecon.org/grassrootseconomics/openethereum-node-status/pkg/util"
"github.com/rs/zerolog/log"
"github.com/ybbus/jsonrpc/v2"
)
@ -17,8 +18,8 @@ type (
}
BatchMetricsResponse struct {
GasPrice string
BlockNumber string
GasPrice uint64
BlockNumber uint64
}
)
@ -85,7 +86,7 @@ func batchMetricsCall() (bool, BatchMetricsResponse) {
return false, batchResponse
}
// If sync is complete the rpc result is false, however this call dones't gurantee all blocks have been imported
batchResponse.GasPrice = val
batchResponse.GasPrice = util.Hex2Int(val)
}
if blockNumber, ok := rpcResponses[1]; ok {
@ -93,7 +94,7 @@ func batchMetricsCall() (bool, BatchMetricsResponse) {
if err != nil {
return false, batchResponse
}
batchResponse.BlockNumber = val
batchResponse.BlockNumber = util.Hex2Int(val)
}
return true, batchResponse

12
pkg/util/hex2int.go Normal file
View File

@ -0,0 +1,12 @@
package util
import (
"strconv"
"strings"
)
func Hex2Int(hexStr string) uint64 {
cleaned := strings.Replace(hexStr, "0x", "", -1)
result, _ := strconv.ParseUint(cleaned, 16, 64)
return uint64(result)
}