Documentation ¶
Index ¶
- func ParseAllData(inputs []ContractABIArgument, data []byte) (map[string]interface{}, error)
- func ParseDynamicType(arg ContractABIArgument, data []byte) (interface{}, error)
- func ParseInt(bytes []byte) *big.Int
- func ParseStaticType(arg ContractABIArgument, data []byte, startingPosition uint64) (interface{}, uint64, error)
- func ParseUint(bytes []byte) *big.Int
- type ABIStructure
- type ABIStructureArgument
- type ABIStructureEntry
- type AccountState
- type Address
- type Block
- type ContractABI
- type ContractABIArgument
- type ContractABIEvent
- type ContractABIEventArgument
- type ContractABIFunction
- type EIP165Call
- type ERC721Token
- type Event
- type Hash
- type HeadItem
- type HexData
- type HexNumber
- type InternalCall
- type PageOptions
- type ParsedEvent
- type ParsedState
- type ParsedTransaction
- type QueryOptions
- type RangeResult
- type RawAccountState
- type RawBlock
- type RawHeader
- type RawInnerCall
- type RawOuterCall
- type ReportingResponseTemplate
- type SolidityStorageDocument
- type SolidityStorageEntries
- type SolidityStorageEntry
- type SolidityTypeEntry
- type StorageItem
- type StorageResult
- type Template
- type TokenQueryOptions
- type Transaction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseAllData ¶
func ParseAllData(inputs []ContractABIArgument, data []byte) (map[string]interface{}, error)
Rules for parsing can be found at: https://solidity.readthedocs.io/en/develop/abi-spec.html#argument-encoding
ParseAllData parses a set of elements from the ABI, assuming they fill the provided data ¶
1) Check the "head" of the next element: 2) Check if the element is statically typed 2a) if statically typed, the "head" is the element itself, so it is parsed immediately, and the current pointer for where we are within the data
array is updated. Note there is no "tail" for a static element.
2b) if it is dynamically typed, make a note of its starting position (data[pointer:pointer+32] interpreted as a uint) and update the last dynamic
element with its ending position (which is the same value))
3) Once all the elements have been parsed, start processing the dynamic element tails, which may recursively call ParseData 4) Concatenate all the results into a map against their variable names and return
The "head" and "tail" concept of the encoding can be visualised as follows:
If we have elements: X1, X2, X3, X4, then the encoding of that will be: Head(X1) + Head(X2) + Head(X3) + Head(X4) + Tail(X1) + Tail(X2) + Tail(X3) + Tail(X4) - if Xn is static, then Tail(Xn) is omitted, and the encoding of the element is in Head(Xn) - if Xn is dynamic then:
- Head(Xn) is 32 bytes, representing a uint256 of the starting position of Tail(Xn) within the data array
- Tail(Xn) is the actual encoding of the element
Because we only get the starting position of dynamic elements, we have to infer the end position by taking the start position of the next dynamic element, leading to 2b) that we update the last dynamic element with the end point (as we now know this value)
func ParseDynamicType ¶
func ParseDynamicType(arg ContractABIArgument, data []byte) (interface{}, error)
func ParseStaticType ¶
func ParseStaticType(arg ContractABIArgument, data []byte, startingPosition uint64) (interface{}, uint64, error)
ParseStaticType will attempt to parse all the possible static types defined by the ABI encoding spec. It returns the result of parsing, as well as the next offset from which to parse the next element - i.e. the starting offset + how many bytes it read to parse this element
Types ¶
type ABIStructure ¶
type ABIStructure []ABIStructureEntry
func NewABIStructureFromJSON ¶
func NewABIStructureFromJSON(abi string) (ABIStructure, error)
func (ABIStructure) ToInternalABI ¶
func (abi ABIStructure) ToInternalABI() *ContractABI
type ABIStructureArgument ¶
type ABIStructureArgument struct { Name string `json:"name"` Type string `json:"type"` Components []ABIStructureArgument `json:"components"` Indexed bool `json:"indexed"` }
func (ABIStructureArgument) AsArgument ¶
func (arg ABIStructureArgument) AsArgument() ContractABIArgument
func (ABIStructureArgument) AsIndexedArgument ¶
func (arg ABIStructureArgument) AsIndexedArgument() ContractABIEventArgument
type ABIStructureEntry ¶
type ABIStructureEntry struct { Type string `json:"type"` Name string `json:"name"` Inputs []ABIStructureArgument `json:"inputs"` Outputs []ABIStructureArgument `json:"outputs"` Anonymous bool `json:"anonymous"` }
func (ABIStructureEntry) AsConstructor ¶
func (entry ABIStructureEntry) AsConstructor() ContractABIFunction
func (ABIStructureEntry) AsEvent ¶
func (entry ABIStructureEntry) AsEvent() ContractABIEvent
func (ABIStructureEntry) AsFunction ¶
func (entry ABIStructureEntry) AsFunction() ContractABIFunction
type AccountState ¶
type Address ¶
type Address string
func NewAddress ¶
NewAddressFromHex creates a new address from a given hex string It will left-pad to 20 bytes if the string is shorter than that, or truncate to 20 bytes if larger
func (Address) MarshalJSON ¶
func (*Address) UnmarshalJSON ¶
func (*Address) UnmarshalTOML ¶
type Block ¶
type Block struct { Hash Hash `json:"hash"` ParentHash Hash `json:"parentHash"` StateRoot Hash `json:"stateRoot"` TxRoot Hash `json:"txRoot"` ReceiptRoot Hash `json:"receiptRoot"` Number uint64 `json:"number"` GasLimit uint64 `json:"gasLimit"` GasUsed uint64 `json:"gasUsed"` Timestamp uint64 `json:"timestamp"` ExtraData string `json:"extraData"` Transactions []Hash `json:"transactions"` }
type ContractABI ¶
type ContractABI struct { Constructor ContractABIFunction Functions []ContractABIFunction Events []ContractABIEvent }
type ContractABIArgument ¶
type ContractABIArgument struct { Name string Type string Components []ContractABIArgument }
func (ContractABIArgument) IsDynamic ¶
func (arg ContractABIArgument) IsDynamic() bool
+-----------------+--------+---------+ | Type | Static | Dynamic | +-----------------+--------+---------+ | uint<x> | ✔ | | | int<x> | ✔ | | | address | ✔ | | | bool | ✔ | | | bytes<x> | ✔ | | | bytes | | ✔ | | string | | ✔ | | T[] | | ✔ | | T<static>[m] | ✔ | | | T<dynamic>[m] | | ✔ | | Tuple<static> | ✔ | | | Tuple<dynamic> | | ✔ | +-----------------+--------+---------+
Note: a tuple is dynamic if at least one element is dynamic
Note: fixed sized arrays are not explicitly handled because they only
depend on their type to determine if they're static or not
func (ContractABIArgument) String ¶
func (arg ContractABIArgument) String() string
func (ContractABIArgument) StringNoName ¶
func (arg ContractABIArgument) StringNoName() string
type ContractABIEvent ¶
type ContractABIEvent struct { Type string Name string Inputs []ContractABIEventArgument Anonymous bool }
func (ContractABIEvent) Parse ¶
func (event ContractABIEvent) Parse(data []byte) (map[string]interface{}, error)
func (ContractABIEvent) Signature ¶
func (event ContractABIEvent) Signature() string
func (ContractABIEvent) String ¶
func (event ContractABIEvent) String() string
func (ContractABIEvent) StringNoName ¶
func (event ContractABIEvent) StringNoName() string
type ContractABIEventArgument ¶
type ContractABIEventArgument struct { ContractABIArgument Indexed bool }
type ContractABIFunction ¶
type ContractABIFunction struct { Type string Name string Inputs []ContractABIArgument Outputs []ContractABIArgument }
func (ContractABIFunction) Parse ¶
func (function ContractABIFunction) Parse(data []byte) (map[string]interface{}, error)
func (ContractABIFunction) Signature ¶
func (function ContractABIFunction) Signature() string
func (ContractABIFunction) String ¶
func (function ContractABIFunction) String() string
func (ContractABIFunction) StringNoName ¶
func (function ContractABIFunction) StringNoName() string
type EIP165Call ¶
Call args for checking a contract for EIP165 interfaces
type ERC721Token ¶
type Event ¶
type Event struct { Index uint64 `json:"index"` Address Address `json:"address"` Topics []Hash `json:"topics"` Data HexData `json:"data"` BlockNumber uint64 `json:"blockNumber"` BlockHash Hash `json:"blockHash"` TransactionHash Hash `json:"transactionHash"` TransactionIndex uint64 `json:"transactionIndex"` Timestamp uint64 `json:"timestamp"` }
type Hash ¶
type Hash string
func NewHash ¶
NewHashFromHex creates a new hash from a given hex string It will left-pad to 32 bytes if the string is shorter than that, or truncate to 32 bytes if larger
func (Hash) MarshalJSON ¶
func (*Hash) UnmarshalJSON ¶
func (*Hash) UnmarshalTOML ¶
type HeadItem ¶
type HeadItem struct { StartOffset uint64 EndOffset uint64 Arg ContractABIArgument }
type HexData ¶
type HexData string
func NewHexData ¶
func (HexData) MarshalJSON ¶
func (*HexData) UnmarshalJSON ¶
type HexNumber ¶
type HexNumber uint64
func (HexNumber) MarshalJSON ¶
func (*HexNumber) UnmarshalJSON ¶
type InternalCall ¶
type PageOptions ¶
type PageOptions struct { BeginBlockNumber *big.Int `json:"beginBlockNumber"` EndBlockNumber *big.Int `json:"endBlockNumber"` PageSize int `json:"pageSize"` PageNumber int `json:"pageNumber"` }
func (*PageOptions) SetDefaults ¶
func (opts *PageOptions) SetDefaults()
type ParsedEvent ¶
type ParsedEvent struct { Sig string `json:"eventSig"` ParsedData map[string]interface{} `json:"parsedData"` RawEvent *Event `json:"rawEvent"` }
func (*ParsedEvent) ParseEvent ¶
func (pe *ParsedEvent) ParseEvent(rawABI string) error
type ParsedState ¶
type ParsedState struct { BlockNumber uint64 `json:"blockNumber"` HistoricStorage []*StorageItem `json:"historicStorage"` }
type ParsedTransaction ¶
type ParsedTransaction struct { Sig string `json:"txSig"` Func4Bytes HexData `json:"func4Bytes"` ParsedData map[string]interface{} `json:"parsedData"` ParsedEvents []*ParsedEvent `json:"parsedEvents"` RawTransaction *Transaction `json:"rawTransaction"` }
func (*ParsedTransaction) ParseTransaction ¶
func (ptx *ParsedTransaction) ParseTransaction(rawABI string) error
type QueryOptions ¶
type QueryOptions struct { BeginBlockNumber *big.Int `json:"beginBlockNumber"` EndBlockNumber *big.Int `json:"endBlockNumber"` BeginTimestamp *big.Int `json:"beginTimestamp"` EndTimestamp *big.Int `json:"endTimestamp"` PageSize int `json:"pageSize"` PageNumber int `json:"pageNumber"` }
func (*QueryOptions) SetDefaults ¶
func (opts *QueryOptions) SetDefaults()
type RangeResult ¶
type RawAccountState ¶
type RawBlock ¶
type RawBlock struct { Hash Hash `json:"hash"` ParentHash Hash `json:"parentHash"` StateRoot Hash `json:"stateRoot"` TxRoot Hash `json:"transactionsRoot"` ReceiptRoot Hash `json:"receiptsRoot"` Number HexNumber `json:"number"` GasLimit HexNumber `json:"gasLimit"` GasUsed HexNumber `json:"gasUsed"` Timestamp HexNumber `json:"timestamp"` ExtraData string `json:"extraData"` Transactions []Hash `json:"transactions"` }
received from eth_getBlockByNumber
type RawInnerCall ¶
type RawOuterCall ¶
type RawOuterCall struct {
Calls []RawInnerCall
}
type ReportingResponseTemplate ¶
type ReportingResponseTemplate struct { Address Address `json:"address"` HistoricState []*ParsedState `json:"historicState"` Total uint64 `json:"total"` Options *PageOptions `json:"options"` }
type SolidityStorageDocument ¶
type SolidityStorageDocument struct { Storage SolidityStorageEntries `json:"storage"` Types map[string]SolidityTypeEntry `json:"types"` }
type SolidityStorageEntries ¶
type SolidityStorageEntries []SolidityStorageEntry
func (SolidityStorageEntries) Len ¶
func (sse SolidityStorageEntries) Len() int
func (SolidityStorageEntries) Less ¶
func (sse SolidityStorageEntries) Less(i, j int) bool
func (SolidityStorageEntries) Swap ¶
func (sse SolidityStorageEntries) Swap(i, j int)
type SolidityStorageEntry ¶
type SolidityStorageEntry struct { Label string `json:"label"` Offset uint64 `json:"offset"` Slot uint64 `json:"slot"` Type string `json:"type"` }
func (*SolidityStorageEntry) UnmarshalJSON ¶
func (sse *SolidityStorageEntry) UnmarshalJSON(b []byte) error
type SolidityTypeEntry ¶
type SolidityTypeEntry struct { Encoding string `json:"encoding"` Key string `json:"key"` Label string `json:"label"` NumberOfBytes uint64 `json:"numberOfBytes"` Value string `json:"value"` Base string `json:"base"` Members SolidityStorageEntries `json:"members"` }
func (*SolidityTypeEntry) UnmarshalJSON ¶
func (sse *SolidityTypeEntry) UnmarshalJSON(b []byte) error
type StorageItem ¶
type StorageResult ¶
type TokenQueryOptions ¶
type TokenQueryOptions struct { BeginBlockNumber *big.Int `json:"beginBlockNumber"` EndBlockNumber *big.Int `json:"endBlockNumber"` After string `json:"after"` PageSize int `json:"pageSize"` PageNumber int `json:"pageNumber"` }
func (*TokenQueryOptions) SetDefaults ¶
func (opts *TokenQueryOptions) SetDefaults()
type Transaction ¶
type Transaction struct { Hash Hash `json:"hash"` Status bool `json:"status"` BlockNumber uint64 `json:"blockNumber"` BlockHash Hash `json:"blockHash"` Index uint64 `json:"index"` Nonce uint64 `json:"nonce"` From Address `json:"from"` To Address `json:"to"` Value uint64 `json:"value"` Gas uint64 `json:"gas"` GasPrice uint64 `json:"gasPrice"` GasUsed uint64 `json:"gasUsed"` CumulativeGasUsed uint64 `json:"cumulativeGasUsed"` CreatedContract Address `json:"createdContract"` Data HexData `json:"data"` PrivateData HexData `json:"privateData"` IsPrivate bool `json:"isPrivate"` Timestamp uint64 `json:"timestamp"` Events []*Event `json:"events"` InternalCalls []*InternalCall `json:"internalCalls"` }