2021-11-23 16:44:46 +00:00
|
|
|
package requests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2022-03-14 13:59:51 +00:00
|
|
|
"strconv"
|
2021-11-23 16:44:46 +00:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2022-03-17 20:16:02 +00:00
|
|
|
// HexToInt converts a hex string to a type uint64
|
2022-03-14 13:59:51 +00:00
|
|
|
func HexToInt(hexStr string) uint64 {
|
|
|
|
// Remove the 0x prefix
|
|
|
|
cleaned := strings.ReplaceAll(hexStr, "0x", "")
|
|
|
|
|
|
|
|
result, _ := strconv.ParseUint(cleaned, 16, 64)
|
|
|
|
return result
|
|
|
|
}
|
2022-03-17 20:16:02 +00:00
|
|
|
|
|
|
|
// parseResponse converts any of the rpctest interfaces to a string for readability
|
|
|
|
func parseResponse(resp interface{}) (string, error) {
|
|
|
|
result, err := json.Marshal(resp)
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("error trying to marshal response: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(result), nil
|
|
|
|
}
|
2022-03-31 12:40:09 +00:00
|
|
|
|
|
|
|
// NamespaceAndSubMethodFromMethod splits a parent method into namespace and the actual method
|
|
|
|
func NamespaceAndSubMethodFromMethod(method string) (string, string, error) {
|
|
|
|
parts := strings.SplitN(method, "_", 2)
|
|
|
|
if len(parts) != 2 {
|
|
|
|
return "", "", fmt.Errorf("invalid string to split")
|
|
|
|
}
|
|
|
|
return parts[0], parts[1], nil
|
|
|
|
}
|