util

package
v0.0.0-...-65a0283 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package hexutil implements hex encoding with 0x prefix. This encoding is used by the Ubiq RPC API to transport binary data in JSON payloads.

Encoding Rules

All hex data must have prefix "0x".

For byte slices, the hex data must be of even length. An empty byte slice encodes as "0x".

Integers are encoded using the least amount of digits (no leading zero digits). Their encoding may be of uneven length. The number zero encodes as "0x0".

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyString   = &decError{"empty hex string"}
	ErrSyntax        = &decError{"invalid hex string"}
	ErrMissingPrefix = &decError{"hex string without 0x prefix"}
	ErrOddLength     = &decError{"hex string of odd length"}
	ErrEmptyNumber   = &decError{"hex string \"0x\""}
	ErrLeadingZero   = &decError{"hex number with leading zero digits"}
	ErrUint64Range   = &decError{"hex number > 64 bits"}
	ErrUintRange     = &decError{fmt.Sprintf("hex number > %d bits", uintBits)}
	ErrBig256Range   = &decError{"hex number > 256 bits"}
)

Errors

Functions

func BigFloatToString

func BigFloatToString(f *big.Float, prec int) string

func CaculateBlockReward

func CaculateBlockReward(height uint64, uncleNo int) *big.Int

func CaculateUncleReward

func CaculateUncleReward(height uint64, uncleHeight uint64) *big.Int

func Decode

func Decode(input string) ([]byte, error)

Decode decodes a hex string with 0x prefix.

func DecodeBig

func DecodeBig(input string) (*big.Int, error)

DecodeBig decodes a hex string with 0x prefix as a quantity. Numbers larger than 256 bits are not accepted.

func DecodeHex

func DecodeHex(str string) uint64

func DecodeUint64

func DecodeUint64(input string) (uint64, error)

DecodeUint64 decodes a hex string with 0x prefix as a quantity.

func DecodeValueHex

func DecodeValueHex(val string) string

func Encode

func Encode(b []byte) string

Encode encodes b as a hex string with 0x prefix.

func EncodeBig

func EncodeBig(bigint *big.Int) string

EncodeBig encodes bigint as a hex string with 0x prefix. The sign of the integer is ignored.

func EncodeUint64

func EncodeUint64(i uint64) string

EncodeUint64 encodes i as a hex string with 0x prefix.

func FloatToString

func FloatToString(f float64) string

func FormatQwark

func FormatQwark(str string) string

func FromWei

func FromWei(str string) string

func FromWeiToGwei

func FromWeiToGwei(str string) string

func GetJson

func GetJson(client *http.Client, url string, target interface{}) error

func InputParamsToAddress

func InputParamsToAddress(str string) string

func MakeTimestamp

func MakeTimestamp() int64

func MustDecode

func MustDecode(input string) []byte

MustDecode decodes a hex string with 0x prefix. It panics for invalid input.

func MustDecodeBig

func MustDecodeBig(input string) *big.Int

MustDecodeBig decodes a hex string with 0x prefix as a quantity. It panics for invalid input.

func MustDecodeUint64

func MustDecodeUint64(input string) uint64

MustDecodeUint64 decodes a hex string with 0x prefix as a quantity. It panics for invalid input.

Types

type DateValuesSlice

type DateValuesSlice struct {
	Values []uint
	Dates  []string
}

func (DateValuesSlice) Len

func (sbo DateValuesSlice) Len() int

func (DateValuesSlice) Less

func (sbo DateValuesSlice) Less(i, j int) bool

func (DateValuesSlice) Swap

func (sbo DateValuesSlice) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL