Documentation ¶
Overview ¶
Package utils is used for the common functions for dealing with conversion to and from hex, bytes, and strings, formatting time, and basic HTTP authentication.
Index ¶
- Constants
- Variables
- func AddHexPrefix(str string) string
- func BasicAuthGet(username, password, url string) (*http.Response, error)
- func BasicAuthPatch(username, password, url string, contentType string, body io.Reader) (*http.Response, error)
- func BasicAuthPost(username, password, url string, contentType string, body io.Reader) (*http.Response, error)
- func DecodeEthereumTx(hex string) (types.Transaction, error)
- func EncodeTxToHex(tx *types.Transaction) (string, error)
- func EthToWei(numEth float64) *big.Int
- func FormatJSON(v interface{}) ([]byte, error)
- func GetStringKeys(v map[string]interface{}) []string
- func HexConcat(strs ...string) string
- func HexToBytes(strs ...string) ([]byte, error)
- func HexToString(hex string) (string, error)
- func HexToUint64(hex string) (uint64, error)
- func ISO8601UTC(t time.Time) string
- func IsEmptyAddress(addr common.Address) bool
- func NewBytes32ID() string
- func NullISO8601UTC(t null.Time) string
- func RemoveHexPrefix(str string) string
- func StringToHex(in string) string
- func ToFilterArg(q ethereum.FilterQuery) interface{}
- func ToFilterQueryFor(fromBlock *big.Int, addresses []common.Address) ethereum.FilterQuery
- func Uint64ToHex(i uint64) string
- func WeiToEth(numWei *big.Int) float64
- func WithoutZeroAddresses(addresses []common.Address) []common.Address
- type BackoffSleeper
- type Sleeper
Constants ¶
const (
HUMAN_TIME_FORMAT = "2006-01-02 15:04:05 MST"
)
Variables ¶
var ZeroAddress = common.Address{}
ZeroAddress is an empty address, otherwise in Ethereum as 0x0000000000000000000000000000000000000000
Functions ¶
func AddHexPrefix ¶
func BasicAuthGet ¶
BasicAuthGet uses the given username and password to send a GET request at the given URL and returns a response.
func BasicAuthPatch ¶
func BasicAuthPatch(username, password, url string, contentType string, body io.Reader) (*http.Response, error)
BasicAuthPatch sends a PATCH request to the HTTP client with the given username and password to authenticate at the url with contentType and returns a response.
func BasicAuthPost ¶
func BasicAuthPost(username, password, url string, contentType string, body io.Reader) (*http.Response, error)
BasicAuthPost sends a POST request to the HTTP client with the given username and password to authenticate at the url with contentType and returns a response.
func DecodeEthereumTx ¶
func DecodeEthereumTx(hex string) (types.Transaction, error)
DecodeEthereumTx takes an RLP hex encoded Ethereum transaction and returns a Transaction struct with all the fields accessible.
func EncodeTxToHex ¶
func EncodeTxToHex(tx *types.Transaction) (string, error)
EncodeTxToHex converts the given Ethereum Transaction type and returns its hex-value string.
func FormatJSON ¶
FormatJSON applies indent to format a JSON response.
func GetStringKeys ¶
GetStringKeys returns an array of strings from the keys of Unmarshalled JSON given as input. For example, if `j` were our JSON:
var value map[string]interface{} err = json.Unmarshal(j, &value) keys := utils.GetStringKeys(value)
func HexToBytes ¶
HexToBytes converts the given array of strings and returns bytes.
func HexToString ¶
HexToString decodes a hex encoded string.
func HexToUint64 ¶
func ISO8601UTC ¶
func IsEmptyAddress ¶
IsEmptyAddress checks that the address is empty, synonymous with the zero account/address. No logs can come from this address, as there is no contract present there.
See https://stackoverflow.com/questions/48219716/what-is-address0-in-solidity for the more info on the zero address.
func NewBytes32ID ¶
func NewBytes32ID() string
NewBytes32ID returns a randomly generated UUID that conforms to Ethereum bytes32.
func NullISO8601UTC ¶
func RemoveHexPrefix ¶
func StringToHex ¶
StringToHex converts a standard string to a hex encoded string.
func ToFilterArg ¶
func ToFilterArg(q ethereum.FilterQuery) interface{}
func ToFilterQueryFor ¶
Returns a struct that encapsulates desired arguments used to filter event logs.
func Uint64ToHex ¶
Uint64ToHex converts the given uint64 value to a hex-value string.
Types ¶
type BackoffSleeper ¶
func NewBackoffSleeper ¶
func NewBackoffSleeper() BackoffSleeper
func (BackoffSleeper) Duration ¶
func (bs BackoffSleeper) Duration() time.Duration
func (BackoffSleeper) Sleep ¶
func (bs BackoffSleeper) Sleep()