Documentation ¶
Index ¶
- Variables
- func B(input string) []byte
- func CanonicalHex(input string) string
- func ConcatHex(with0x bool, in ...string) (out string)
- func DecimalsInBigInt(decimal uint32) *big.Int
- func DeclarationTypeNames() []string
- func Has0xPrefix(input string) bool
- func Keccak256(data ...[]byte) []byte
- func MustDecodeString(hexStr string) []byte
- func PrefixedHex(input string) string
- func PrettifyBigIntWithDecimals(in *big.Int, precision, truncateDecimalCount uint) string
- func SanitizeHex(input string) string
- func StateMutabilityNames() []string
- type ABI
- type Address
- func (a Address) Bytes() []byte
- func (a Address) ID() uint64
- func (a Address) MarshalJSON() ([]byte, error)
- func (a Address) MarshalJSONRPC() ([]byte, error)
- func (a Address) MarshalText() ([]byte, error)
- func (a Address) Pretty() string
- func (a Address) String() string
- func (a *Address) UnmarshalJSON(data []byte) error
- type AddressArray
- type BigIntArray
- type BoolArray
- type Bytes
- func (h Bytes) Bytes() []byte
- func (h Bytes) ID() uint64
- func (h Bytes) MarshalJSON() ([]byte, error)
- func (h Bytes) MarshalJSONRPC() ([]byte, error)
- func (h Bytes) MarshalText() ([]byte, error)
- func (h Bytes) Pretty() string
- func (h Bytes) String() string
- func (h *Bytes) UnmarshalJSON(data []byte) error
- type DeclarationType
- type Decoder
- func (d *Decoder) Read(typeName string) (interface{}, error)
- func (d *Decoder) ReadAddress() (out Address, err error)
- func (d *Decoder) ReadBigInt() (out *big.Int, err error)
- func (d *Decoder) ReadBool() (out bool, err error)
- func (d *Decoder) ReadBuffer(byteCount uint64) ([]byte, error)
- func (d *Decoder) ReadBytes() ([]byte, error)
- func (d *Decoder) ReadFixedBytes() ([]byte, error)
- func (d *Decoder) ReadMethod() (out string, err error)
- func (d *Decoder) ReadMethodCall() (*MethodCall, error)
- func (d *Decoder) ReadOutput(parameters []*MethodParameter) (out []interface{}, err error)
- func (d *Decoder) ReadString() (out string, err error)
- func (d *Decoder) ReadUint64() (out uint64, err error)
- func (d *Decoder) SetBytes(input []byte) *Decoder
- func (d *Decoder) String() string
- type Encoder
- type ErrDecoding
- type Hash
- type Hex
- type Int16
- type Int32
- type Int64
- type Int8
- type InvertedSignature
- func (s InvertedSignature) R() *big.Int
- func (s InvertedSignature) Recover(messageHash Hash) (Address, error)
- func (s InvertedSignature) RecoverPersonal(signingData Hex) (Address, error)
- func (s InvertedSignature) S() *big.Int
- func (s InvertedSignature) String() string
- func (s InvertedSignature) ToSignature() (out Signature)
- func (s InvertedSignature) V() byte
- type KeyBag
- type Log
- type LogDecoder
- type LogEvent
- type LogEventDef
- type LogParameter
- type MethodCall
- type MethodDef
- func (f *MethodDef) DecodeOutput(data []byte) ([]interface{}, error)
- func (f *MethodDef) DecodeOutputFromString(data string) ([]interface{}, error)
- func (f *MethodDef) DecodeToObjectFromBytes(data []byte) (out map[string]interface{}, err error)
- func (f *MethodDef) DecodeToObjectFromDecoder(decoder *Decoder) (out map[string]interface{}, err error)
- func (f *MethodDef) DecodeToObjectFromString(data string) (out map[string]interface{}, err error)
- func (f *MethodDef) MethodID() []byte
- func (f *MethodDef) NewCall(args ...interface{}) *MethodCall
- func (f *MethodDef) NewCallFromString(args ...string) *MethodCall
- func (f *MethodDef) Signature() string
- func (f *MethodDef) String() string
- type MethodParameter
- type PrivateKey
- func (p *PrivateKey) Bytes() (out []byte)
- func (p *PrivateKey) MarshalJSON() ([]byte, error)
- func (p *PrivateKey) PublicKey() *PublicKey
- func (p *PrivateKey) Sign(messageHash Hash) (out Signature, err error)
- func (p *PrivateKey) SignPersonal(signingData Hex) (out Signature, err error)
- func (p *PrivateKey) String() string
- func (p *PrivateKey) UnmarshalJSON(v []byte) (err error)
- type PublicKey
- type Signature
- func (s Signature) R() *big.Int
- func (s Signature) Recover(messageHash Hash) (Address, error)
- func (s Signature) RecoverPersonal(signingData Hex) (Address, error)
- func (s Signature) S() *big.Int
- func (s Signature) String() string
- func (s Signature) ToInverted() (out InvertedSignature)
- func (s Signature) V() byte
- type StateMutability
- type StringArray
- type StructComponent
- type Timestamp
- type Token
- type TokenAmount
- type Topic
- type Uint16
- type Uint16Array
- type Uint32
- type Uint32Array
- type Uint64
- type Uint64Array
- type Uint8
- type Uint8Array
Constants ¶
This section is empty.
Variables ¶
var ETHToken = &Token{ Name: "Ethereum", Symbol: "ETH", Address: nil, Decimals: 18, }
var KnownSignatures = map[string]string{}/* 149637 elements not displayed */
Functions ¶
func CanonicalHex ¶
CanonicalHex receives an input and return it's canonical form, i.e. the single unique well-formed which in our case is an all-lower case version with even number of characters.
The only differences with `SanitizeHexInput` here is an additional call to `strings.ToLower` before returning the result.
func DecimalsInBigInt ¶
func DeclarationTypeNames ¶
func DeclarationTypeNames() []string
DeclarationTypeNames returns a list of possible string values of DeclarationType.
func Has0xPrefix ¶
func MustDecodeString ¶
func PrefixedHex ¶
PrefixedHex is CanonicalHex but with 0x prefix
func SanitizeHex ¶
SanitizeHex removes the prefix `0x` if it exists and ensures there is an even number of characters in the string, padding on the left of the string is it's not the case.
func StateMutabilityNames ¶
func StateMutabilityNames() []string
StateMutabilityNames returns a list of possible string values of StateMutability.
Types ¶
type ABI ¶
type ABI struct { LogEventsMap map[string]*LogEventDef FunctionsMap map[string]*MethodDef ConstructorsMap map[string]*MethodDef LogEventsByNameMap map[string]*LogEventDef FunctionsByNameMap map[string]*MethodDef ConstructorsByNameMap map[string]*MethodDef }
ABI is our custom internal definition of a contract's ABI that bridges the information between the two ABI like formats for contract's, i.e. `.abi` file and AST file as output by `solc` compiler.
func ParseABIFromBytes ¶
func (*ABI) FindFunction ¶
func (*ABI) FindFunctionByName ¶
func (*ABI) FindLog ¶
func (a *ABI) FindLog(topic []byte) *LogEventDef
type Address ¶
type Address []byte
func MustNewAddress ¶
func NewAddress ¶
func (Address) MarshalJSON ¶
func (Address) MarshalJSONRPC ¶
func (Address) MarshalText ¶
func (*Address) UnmarshalJSON ¶
type AddressArray ¶
type AddressArray []Address
func (AddressArray) At ¶
func (a AddressArray) At(index uint64, value interface{})
type BigIntArray ¶
func (BigIntArray) At ¶
func (a BigIntArray) At(index uint64, value interface{})
type Bytes ¶
type Bytes []byte
func MustNewBytes ¶
func (Bytes) MarshalJSON ¶
func (Bytes) MarshalJSONRPC ¶
func (Bytes) MarshalText ¶
func (*Bytes) UnmarshalJSON ¶
type DeclarationType ¶
type DeclarationType int
ENUM(
Function Constructor Receive Fallback Event Error
)
const ( // DeclarationTypeFunction is a DeclarationType of type Function. DeclarationTypeFunction DeclarationType = iota // DeclarationTypeConstructor is a DeclarationType of type Constructor. DeclarationTypeConstructor // DeclarationTypeReceive is a DeclarationType of type Receive. DeclarationTypeReceive // DeclarationTypeFallback is a DeclarationType of type Fallback. DeclarationTypeFallback // DeclarationTypeEvent is a DeclarationType of type Event. DeclarationTypeEvent // DeclarationTypeError is a DeclarationType of type Error. DeclarationTypeError )
func ParseDeclarationType ¶
func ParseDeclarationType(name string) (DeclarationType, error)
ParseDeclarationType attempts to convert a string to a DeclarationType
func (DeclarationType) MarshalText ¶
func (x DeclarationType) MarshalText() ([]byte, error)
MarshalText implements the text marshaller method
func (DeclarationType) String ¶
func (x DeclarationType) String() string
String implements the Stringer interface.
func (*DeclarationType) UnmarshalText ¶
func (x *DeclarationType) UnmarshalText(text []byte) error
UnmarshalText implements the text unmarshaller method
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
func NewDecoder ¶
func NewDecoderFromString ¶
func (*Decoder) ReadAddress ¶
func (*Decoder) ReadFixedBytes ¶
func (*Decoder) ReadMethod ¶
func (*Decoder) ReadMethodCall ¶
func (d *Decoder) ReadMethodCall() (*MethodCall, error)
func (*Decoder) ReadOutput ¶
func (d *Decoder) ReadOutput(parameters []*MethodParameter) (out []interface{}, err error)
func (*Decoder) ReadString ¶
func (*Decoder) ReadUint64 ¶
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
func NewEncoder ¶
func NewEncoder() *Encoder
func (*Encoder) Write ¶
func (e *Encoder) Write(parameter *MethodParameter, in interface{}) error
func (*Encoder) WriteMethodCall ¶
func (e *Encoder) WriteMethodCall(method *MethodCall) error
func (*Encoder) WriteParameters ¶
func (e *Encoder) WriteParameters(parameters []*MethodParameter, data []interface{}) error
type ErrDecoding ¶
type ErrDecoding struct {
// contains filtered or unexported fields
}
func NewErrDecoding ¶
func NewErrDecoding(message string, args ...interface{}) *ErrDecoding
func (*ErrDecoding) Error ¶
func (e *ErrDecoding) Error() string
type Hash ¶
type Hash []byte
func MustNewHash ¶
func (Hash) MarshalJSON ¶
func (Hash) MarshalJSONRPC ¶
func (Hash) MarshalText ¶
func (*Hash) UnmarshalJSON ¶
type Hex ¶
type Hex []byte
func MustNewHex ¶
func (Hex) MarshalJSON ¶
func (Hex) MarshalJSONRPC ¶
func (Hex) MarshalText ¶
func (*Hex) UnmarshalJSON ¶
type InvertedSignature ¶
type InvertedSignature [65]byte
InvertedSignature represents a standard Signature but the order of component `V` is inverted, being the last byte of the bytes (where it's the first byte in the standard `btcec` Signature).
The InverteSignature is in packed form of 65 bytes and order of the components is R (32 bytes) + S (32 bytes) + V (1 byte).
The components can be retrieved with `R()`, `S()` and `V()`.
This form is used on certain Ethereum construct like when doing a personal signing where the `V` component must be the last component of the signature for correct recovery.
func NewInvertedSignatureFromBytes ¶
func NewInvertedSignatureFromBytes(in []byte) (out InvertedSignature, err error)
func (InvertedSignature) R ¶
func (s InvertedSignature) R() *big.Int
R returns the R component of signature.
func (InvertedSignature) Recover ¶
func (s InvertedSignature) Recover(messageHash Hash) (Address, error)
RecoverPersonal is a shortcut method for `signature.ToSignature().Recover(messageHash)`.
func (InvertedSignature) RecoverPersonal ¶
func (s InvertedSignature) RecoverPersonal(signingData Hex) (Address, error)
RecoverPersonal is a shortcut method for `signature.ToSignature().RecoverPersonal(signingData)`.
func (InvertedSignature) S ¶
func (s InvertedSignature) S() *big.Int
S returns the R component of signature.
func (InvertedSignature) String ¶
func (s InvertedSignature) String() string
func (InvertedSignature) ToSignature ¶
func (s InvertedSignature) ToSignature() (out Signature)
func (InvertedSignature) V ¶
func (s InvertedSignature) V() byte
V returns the recovery ID according to Bitcoin rules for the signature recovery. Ethereum augmented recovery ID to protect agaisnt replay attacks is **not** applied here.
See https://bitcoin.stackexchange.com/a/38909 for extra details
type KeyBag ¶
type KeyBag struct {
Keys []*PrivateKey `json:"keys"`
}
KeyBag holds private keys in memory, for signing transactions.
type LogDecoder ¶
type LogDecoder struct { DataDecoder *Decoder // contains filtered or unexported fields }
func NewLogDecoder ¶
func NewLogDecoder(logEvent *Log) *LogDecoder
func (*LogDecoder) ReadData ¶
func (d *LogDecoder) ReadData(typeName string) (out interface{}, err error)
func (*LogDecoder) ReadTopic ¶
func (d *LogDecoder) ReadTopic() ([]byte, error)
func (*LogDecoder) ReadTypedTopic ¶
func (d *LogDecoder) ReadTypedTopic(typeName string) (out interface{}, err error)
type LogEvent ¶
type LogEvent struct { Def *LogEventDef Data interface{} }
type LogEventDef ¶
type LogEventDef struct { Name string Parameters []*LogParameter }
func (*LogEventDef) Signature ¶
func (l *LogEventDef) Signature() string
func (*LogEventDef) String ¶
func (l *LogEventDef) String() string
type LogParameter ¶
func (*LogParameter) GetName ¶
func (p *LogParameter) GetName(index int) string
type MethodCall ¶
type MethodCall struct { MethodDef *MethodDef Data []interface{} // contains filtered or unexported fields }
func (*MethodCall) AppendArg ¶
func (f *MethodCall) AppendArg(v interface{})
func (*MethodCall) AppendArgFromString ¶
func (f *MethodCall) AppendArgFromString(v string)
func (*MethodCall) Encode ¶
func (f *MethodCall) Encode() ([]byte, error)
func (*MethodCall) MarshalJSONRPC ¶
func (f *MethodCall) MarshalJSONRPC() ([]byte, error)
func (*MethodCall) MustEncode ¶
func (f *MethodCall) MustEncode() []byte
type MethodDef ¶
type MethodDef struct { Name string Parameters []*MethodParameter ReturnParameters []*MethodParameter StateMutability StateMutability }
func MustNewMethodDef ¶
func NewMethodDef ¶
func (*MethodDef) DecodeOutput ¶
func (*MethodDef) DecodeOutputFromString ¶
func (*MethodDef) DecodeToObjectFromBytes ¶
func (*MethodDef) DecodeToObjectFromDecoder ¶
func (*MethodDef) DecodeToObjectFromString ¶
func (*MethodDef) NewCall ¶
func (f *MethodDef) NewCall(args ...interface{}) *MethodCall
NewCall instantiate a new call from the method definition and uses the received arguments as elements used to resolve the parameters values.
A call is a particular instance of a Method where ultimately the parameters's value will be resolved. A method call in opposition to a method definition can be encoded according to Ethereum rules or decode data returned for this call against the definition.
func (*MethodDef) NewCallFromString ¶
func (f *MethodDef) NewCallFromString(args ...string) *MethodCall
NewCallFromString works exactly like `NewCall“ except that it actually assumes all arguments are string version of the actual Ethereum types defined by the method and append them to the Data slice by calling `AppendArgFromString` which converts the string representation to the correct type.
type MethodParameter ¶
type MethodParameter struct { // Name represents the name of the parameter as defined by the // developer in the Solidity code of the contract. Name string // TypeName represents the type of the parameter, this is standard // types known to Solidity. Array have a suffix `[]` (can be nested) // and struct type is always `tuple` with an filled up `Components` // defining the struct. TypeName string // TypeMutability is unclear, requires more investigation, I don't recall // to which Solidity concept it refers to. TypeMutability string // Payable determines if the parameter is a payable value so an // Ether value. Payable bool // InternalType is the internal type to the contract, usually equal // to `TypeName` but can be different for example if a type `uint` // was defined, in this case `TypeName` will be `uint256` and internal // type will be `uint`. Tuple which have `TypeName` `tuple` but internal // type is `struct <Contract>.<Struct>` is another exceptions. InternalType string // Components represents that struct fields of a particular tuple. Only // filled up when `TypeName` is equal to `tuple` (or array of tuples). Components []*StructComponent }
func (*MethodParameter) Signature ¶
func (p *MethodParameter) Signature() string
type PrivateKey ¶
type PrivateKey struct {
// contains filtered or unexported fields
}
func NewPrivateKey ¶
func NewPrivateKey(rawPrivateKey string) (*PrivateKey, error)
func NewRandomPrivateKey ¶
func NewRandomPrivateKey() (*PrivateKey, error)
func (*PrivateKey) Bytes ¶
func (p *PrivateKey) Bytes() (out []byte)
func (*PrivateKey) MarshalJSON ¶
func (p *PrivateKey) MarshalJSON() ([]byte, error)
func (*PrivateKey) PublicKey ¶
func (p *PrivateKey) PublicKey() *PublicKey
func (*PrivateKey) Sign ¶
func (p *PrivateKey) Sign(messageHash Hash) (out Signature, err error)
Sign generates the signature for the according message hash based on this private key using ECDSA signature rules.
See Signature documentation for more info about return signature format.
func (*PrivateKey) SignPersonal ¶
func (p *PrivateKey) SignPersonal(signingData Hex) (out Signature, err error)
SignPersonal computes the correct message from `signingData` according to [ERC-712](https://eips.ethereum.org/EIPS/eip-712) which is briefly `keccak256(bytesOf("\x19Ethereum Signed Message:\n") + bytesOf(toString(len(signingData))) + signingData)`.
This computed generated hash is then pass directly to `privateKey.Sign(personalMessageHash)`.
See Sign for more details.
func (*PrivateKey) String ¶
func (p *PrivateKey) String() string
func (*PrivateKey) UnmarshalJSON ¶
func (p *PrivateKey) UnmarshalJSON(v []byte) (err error)
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
func NewPublicKeyFromECDSA ¶
func NewPublicKeyFromECDSA(key *secp256k1.PublicKey) *PublicKey
type Signature ¶
type Signature [65]byte
Signature represents a btcec Signature as computed from ecdsa.SignCompact(), this signature is in packed form of 65 bytes with ordered V (1 byte) + R (32 bytes) + S (32 bytes).
The components can be retrieved with `R()`, `S()` and `V()`.
func NewSignatureFromBytes ¶
func (Signature) RecoverPersonal ¶
func (Signature) ToInverted ¶
func (s Signature) ToInverted() (out InvertedSignature)
ToInverted returns the InvertedSignature version of this Signature, this is that the components are ordered as `R`, `S` then `V` in the inverted version.
This form is used on certain Ethereum construct like when doing a personal signing where the `V` component must be the last component of the signature for correct recovery.
func (Signature) V ¶
V returns the recovery ID according to Bitcoin rules for the signature recovery. Ethereum augmented recovery ID to protect agaisnt replay attacks is **not** applied here.
See https://bitcoin.stackexchange.com/a/38909 for extra details
type StateMutability ¶
type StateMutability int
ENUM(
Pure View NonPayable Payable
)
const ( // StateMutabilityPure is a StateMutability of type Pure. StateMutabilityPure StateMutability = iota // StateMutabilityView is a StateMutability of type View. StateMutabilityView // StateMutabilityNonPayable is a StateMutability of type NonPayable. StateMutabilityNonPayable // StateMutabilityPayable is a StateMutability of type Payable. StateMutabilityPayable )
func ParseStateMutability ¶
func ParseStateMutability(name string) (StateMutability, error)
ParseStateMutability attempts to convert a string to a StateMutability
func (StateMutability) MarshalText ¶
func (x StateMutability) MarshalText() ([]byte, error)
MarshalText implements the text marshaller method
func (StateMutability) String ¶
func (x StateMutability) String() string
String implements the Stringer interface.
func (*StateMutability) UnmarshalText ¶
func (x *StateMutability) UnmarshalText(text []byte) error
UnmarshalText implements the text unmarshaller method
type StringArray ¶
type StringArray []string
func (StringArray) At ¶
func (a StringArray) At(index uint64, value interface{})
type StructComponent ¶
type StructComponent struct { InternalType string `json:"internalType"` Name string `json:"name"` Type string `json:"type"` }
func (*StructComponent) String ¶
func (c *StructComponent) String() string
type Timestamp ¶
Timestamp represents a timestamp value on the Ethereum chain always in UTC time zone.
func (Timestamp) MarshalText ¶
func (*Timestamp) UnmarshalText ¶
type Token ¶
type Token struct { Name string `json:"name"` Symbol string `json:"symbol"` Address Address `json:"address"` Decimals uint `json:"decimals"` TotalSupply *big.Int `json:"total_supply"` }
func (*Token) Amount ¶
func (t *Token) Amount(value int64) TokenAmount
type TokenAmount ¶
func (TokenAmount) Bytes ¶
func (t TokenAmount) Bytes() []byte
func (TokenAmount) Format ¶
func (t TokenAmount) Format(truncateDecimalCount uint) string
func (TokenAmount) String ¶
func (t TokenAmount) String() string
type Uint16Array ¶
type Uint16Array []uint16
func (Uint16Array) At ¶
func (a Uint16Array) At(index uint64, value interface{})
type Uint32Array ¶
type Uint32Array []uint32
func (Uint32Array) At ¶
func (a Uint32Array) At(index uint64, value interface{})
type Uint64Array ¶
type Uint64Array []uint64
func (Uint64Array) At ¶
func (a Uint64Array) At(index uint64, value interface{})
type Uint8Array ¶
type Uint8Array []uint8
func (Uint8Array) At ¶
func (a Uint8Array) At(index uint64, value interface{})