Documentation ¶
Index ¶
- Constants
- Variables
- func ABIDecode(abiStr string, data []byte) ([]interface{}, error)
- func ABIEncode(abiStr string, values ...interface{}) ([]byte, error)
- func Bytes32FromString(s string) [32]byte
- func Bytes32ToSlice(a [32]byte) (r []byte)
- func Bytes4FromString(s string) [4]byte
- func CheckUint256(n *big.Int) error
- func ConcatBytes(bufs ...[]byte) []byte
- func EIP55CapitalizedAddress(possibleAddressString string) bool
- func EVMEncodeBytes(input []byte) []byte
- func EVMTranscodeBool(value gjson.Result) ([]byte, error)
- func EVMTranscodeInt256(value gjson.Result) ([]byte, error)
- func EVMTranscodeUint256(value gjson.Result) ([]byte, error)
- func EVMWordBigInt(val *big.Int) ([]byte, error)
- func EVMWordSignedBigInt(val *big.Int) ([]byte, error)
- func EVMWordUint128(val *big.Int) ([]byte, error)
- func EVMWordUint32(val uint32) []byte
- func EVMWordUint64(val uint64) []byte
- func HexToUint256(s string) (*big.Int, error)
- func IsEmptyAddress(addr common.Address) bool
- func Keccak256(in []byte) ([]byte, error)
- func Keccak256Fixed(in []byte) [32]byte
- func MustAbiType(ts string, components []abi.ArgumentMarshaling) abi.Type
- func MustHash(in string) common.Hash
- func NewHash() common.Hash
- func NewRedialBackoff() backoff.Backoff
- func PadByteToHash(b byte) common.Hash
- func ParseEthereumAddress(addressString string) (common.Address, error)
- func RandUint256() *big.Int
- func RandomAddress() common.Address
- func RandomBytes32() (r [32]byte)
- func RandomHash() common.Hash
- func RetryWithBackoff(ctx context.Context, fn func() (retry bool))
- func Uint256ToBytes(x *big.Int) (uint256 []byte, err error)
- func Uint256ToBytes32(n *big.Int) []byte
- type BackoffSleeper
Constants ¶
const ( // FormatBytes encodes the output as bytes FormatBytes = "bytes" // FormatPreformatted encodes the output, assumed to be hex, as bytes. FormatPreformatted = "preformatted" // FormatUint256 encodes the output as bytes containing a uint256 FormatUint256 = "uint256" // FormatInt256 encodes the output as bytes containing an int256 FormatInt256 = "int256" // FormatBool encodes the output as bytes containing a bool FormatBool = "bool" )
const EVMWordByteLen = 32
EVMWordByteLen the length of an EVM Word Byte
Variables ¶
var ( // MaxUint256 represents the largest number represented by an EVM word MaxUint256 = &big.Int{} // MaxInt256 represents the largest number represented by an EVM word using // signed encoding. MaxInt256 = &big.Int{} // MinInt256 represents the smallest number represented by an EVM word using // signed encoding. MinInt256 = &big.Int{} )
"Constants" used by EVM words
var EmptyHash = common.Hash{}
EmptyHash is a hash of all zeroes, otherwise in Ethereum as 0x0000000000000000000000000000000000000000000000000000000000000000
var ZeroAddress = common.Address{}
ZeroAddress is an address of all zeroes, otherwise in Ethereum as 0x0000000000000000000000000000000000000000
Functions ¶
func ABIDecode ¶
ABIEncode is the equivalent of abi.decode. See a full set of examples https://github.com/ethereum/go-ethereum/blob/420b78659bef661a83c5c442121b13f13288c09f/accounts/abi/packing_test.go#L31
func ABIEncode ¶
ABIEncode is the equivalent of abi.encode. See a full set of examples https://github.com/ethereum/go-ethereum/blob/420b78659bef661a83c5c442121b13f13288c09f/accounts/abi/packing_test.go#L31
func Bytes32FromString ¶
Bytes32FromString returns a 32 byte array filled from the given string, which may be of any length.
func Bytes32ToSlice ¶
func Bytes4FromString ¶
Bytes4FromString returns a 4 byte array filled from the given string, which may be of any length.
func CheckUint256 ¶
CheckUint256 returns an error if n is out of bounds for a uint256
func ConcatBytes ¶
ConcatBytes appends a bunch of byte arrays into a single byte array
func EIP55CapitalizedAddress ¶
EIP55CapitalizedAddress returns true iff possibleAddressString has the correct capitalization for an Ethereum address, per EIP 55
func EVMEncodeBytes ¶
EVMEncodeBytes encodes arbitrary bytes as bytes expected by the EVM
func EVMTranscodeBool ¶
EVMTranscodeBool converts a json input to an EVM bool
func EVMTranscodeInt256 ¶
EVMTranscodeInt256 converts a json input to an EVM int256
func EVMTranscodeUint256 ¶
EVMTranscodeUint256 converts a json input to an EVM uint256
func EVMWordBigInt ¶
EVMWordBigInt returns a big.Int as an EVM word byte array, with support for a signed representation. Returns error on overflow.
func EVMWordSignedBigInt ¶
EVMWordSignedBigInt returns a big.Int as an EVM word byte array, with support for a signed representation. Returns error on overflow.
func EVMWordUint128 ¶
EVMWordUint128 returns a uint128 as an EVM word byte array.
func EVMWordUint32 ¶
EVMWordUint32 returns a uint32 as an EVM word byte array.
func EVMWordUint64 ¶
EVMWordUint64 returns a uint64 as an EVM word byte array.
func HexToUint256 ¶
HexToUint256 returns the uint256 represented by s, or an error if it doesn't represent one.
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 Keccak256 ¶
Keccak256 is a simplified interface for the legacy SHA3 implementation that Ethereum uses.
func Keccak256Fixed ¶
func MustAbiType ¶
func MustAbiType(ts string, components []abi.ArgumentMarshaling) abi.Type
func NewRedialBackoff ¶
NewRedialBackoff is a standard backoff to use for redialling or reconnecting to unreachable network endpoints
func PadByteToHash ¶
PadByteToHash returns a hash with zeros padded on the left of the given byte.
func ParseEthereumAddress ¶
ParseEthereumAddress returns addressString as a go-ethereum Address, or an error if it's invalid, e.g. if EIP 55 capitalization check fails
func RandUint256 ¶
RandUint256 generates a random bigNum up to 2 ** 256 - 1
func RandomAddress ¶
func RandomBytes32 ¶
func RandomBytes32() (r [32]byte)
func RandomHash ¶
func RetryWithBackoff ¶
RetryWithBackoff retries the sleeper and backs off if not Done
func Uint256ToBytes ¶
Uint256ToBytes is x represented as the bytes of a uint256
func Uint256ToBytes32 ¶
Uint256ToBytes32 returns the bytes32 encoding of the big int provided
Types ¶
type BackoffSleeper ¶
BackoffSleeper is a sleeper that backs off on subsequent attempts.
func NewBackoffSleeper ¶
func NewBackoffSleeper() *BackoffSleeper
NewBackoffSleeper returns a BackoffSleeper that is configured to sleep for 0 seconds initially, then backs off from 1 second minimum to 10 seconds maximum.
func (*BackoffSleeper) After ¶
func (bs *BackoffSleeper) After() time.Duration
After returns the duration for the next stop, and increments the backoff.
func (*BackoffSleeper) Duration ¶
func (bs *BackoffSleeper) Duration() time.Duration
Duration returns the current duration value.
func (*BackoffSleeper) Reset ¶
func (bs *BackoffSleeper) Reset()
Reset resets the backoff intervals.
func (*BackoffSleeper) Sleep ¶
func (bs *BackoffSleeper) Sleep()
Sleep waits for the given duration, incrementing the back off.