utils

package
v0.0.0-...-537fcec Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2018 License: MIT Imports: 18 Imported by: 0

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

View Source
const (
	HUMAN_TIME_FORMAT = "2006-01-02 15:04:05 MST"
)

Variables

View Source
var ZeroAddress = common.Address{}

ZeroAddress is an empty address, otherwise in Ethereum as 0x0000000000000000000000000000000000000000

Functions

func AddHexPrefix

func AddHexPrefix(str string) string

func BasicAuthGet

func BasicAuthGet(username, password, url string) (*http.Response, error)

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 EthToWei

func EthToWei(numEth float64) *big.Int

EthToWei converts ether amounts to wei.

func FormatJSON

func FormatJSON(v interface{}) ([]byte, error)

FormatJSON applies indent to format a JSON response.

func GetStringKeys

func GetStringKeys(v map[string]interface{}) []string

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 HexConcat

func HexConcat(strs ...string) string

HexConcat concatenates a given array of strings to return a single string.

func HexToBytes

func HexToBytes(strs ...string) ([]byte, error)

HexToBytes converts the given array of strings and returns bytes.

func HexToString

func HexToString(hex string) (string, error)

HexToString decodes a hex encoded string.

func HexToUint64

func HexToUint64(hex string) (uint64, error)

func ISO8601UTC

func ISO8601UTC(t time.Time) string

func IsEmptyAddress

func IsEmptyAddress(addr common.Address) bool

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 NullISO8601UTC(t null.Time) string

func RemoveHexPrefix

func RemoveHexPrefix(str string) string

func StringToHex

func StringToHex(in string) string

StringToHex converts a standard string to a hex encoded string.

func ToFilterQueryFor

func ToFilterQueryFor(fromBlock *big.Int, addresses []common.Address) ethereum.FilterQuery

Returns a struct that encapsulates desired arguments used to filter event logs.

func Uint64ToHex

func Uint64ToHex(i uint64) string

Uint64ToHex converts the given uint64 value to a hex-value string.

func WeiToEth

func WeiToEth(numWei *big.Int) float64

WeiToEth converts wei amounts to ether.

func WithoutZeroAddresses

func WithoutZeroAddresses(addresses []common.Address) []common.Address

Types

type BackoffSleeper

type BackoffSleeper struct {
	*backoff.Backoff
}

func NewBackoffSleeper

func NewBackoffSleeper() BackoffSleeper

func (BackoffSleeper) Duration

func (bs BackoffSleeper) Duration() time.Duration

func (BackoffSleeper) Sleep

func (bs BackoffSleeper) Sleep()

type Sleeper

type Sleeper interface {
	Reset()
	Sleep()
	Duration() time.Duration
}

Jump to

Keyboard shortcuts

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