types

package
v0.0.0-...-c17f0e7 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

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 ParseInt

func ParseInt(bytes []byte) *big.Int

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

func ParseUint

func ParseUint(bytes []byte) *big.Int

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 AccountState struct {
	Root    Hash            `json:"root"`
	Storage map[Hash]string `json:"storage,omitempty"`
}

type Address

type Address string

func NewAddress

func NewAddress(hexString string) Address

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) Hex

func (addr *Address) Hex() string

func (*Address) IsEmpty

func (addr *Address) IsEmpty() bool

func (Address) MarshalJSON

func (addr Address) MarshalJSON() ([]byte, error)

func (*Address) String

func (addr *Address) String() string

func (*Address) UnmarshalJSON

func (addr *Address) UnmarshalJSON(input []byte) error

func (*Address) UnmarshalTOML

func (addr *Address) UnmarshalTOML(input []byte) error

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

type EIP165Call struct {
	To   Address `json:"to"`
	Data HexData `json:"data"`
}

Call args for checking a contract for EIP165 interfaces

type ERC721Token

type ERC721Token struct {
	Contract  Address `json:"contract"`
	Holder    Address `json:"holder"`
	Token     string  `json:"token"`
	HeldFrom  uint64  `json:"heldFrom"`
	HeldUntil *uint64 `json:"heldUntil"`
}

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

func NewHash(hexString string) Hash

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) Hex

func (hsh *Hash) Hex() string

func (*Hash) IsEmpty

func (hsh *Hash) IsEmpty() bool

func (Hash) MarshalJSON

func (hsh Hash) MarshalJSON() ([]byte, error)

func (*Hash) String

func (hsh *Hash) String() string

func (*Hash) UnmarshalJSON

func (hsh *Hash) UnmarshalJSON(input []byte) error

func (*Hash) UnmarshalTOML

func (hsh *Hash) UnmarshalTOML(input []byte) error

type HeadItem

type HeadItem struct {
	StartOffset uint64
	EndOffset   uint64
	Arg         ContractABIArgument
}

type HexData

type HexData string

func NewHexData

func NewHexData(input string) HexData

func (*HexData) AsBytes

func (data *HexData) AsBytes() []byte

func (*HexData) IsEmpty

func (data *HexData) IsEmpty() bool

func (HexData) MarshalJSON

func (data HexData) MarshalJSON() ([]byte, error)

func (*HexData) String

func (data *HexData) String() string

func (*HexData) UnmarshalJSON

func (data *HexData) UnmarshalJSON(input []byte) error

type HexNumber

type HexNumber uint64

func (HexNumber) MarshalJSON

func (num HexNumber) MarshalJSON() ([]byte, error)

func (*HexNumber) ToUint64

func (num *HexNumber) ToUint64() uint64

func (*HexNumber) UnmarshalJSON

func (num *HexNumber) UnmarshalJSON(input []byte) error

type InternalCall

type InternalCall struct {
	From    Address `json:"from"`
	To      Address `json:"to"`
	Gas     uint64  `json:"gas"`
	GasUsed uint64  `json:"gasUsed"`
	Value   uint64  `json:"value"`
	Input   HexData `json:"input"`
	Output  HexData `json:"output"`
	Type    string  `json:"type"`
}

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 RangeResult struct {
	Start       uint64 `json:"start"`
	End         uint64 `json:"end"`
	ResultCount int    `json:"resultCount"`
}

type RawAccountState

type RawAccountState struct {
	Root    Hash              `json:"root"`
	Storage map[string]string `json:"storage,omitempty"`
}

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 RawHeader

type RawHeader struct {
	Hash   Hash      `json:"hash"`
	Number HexNumber `json:"number"`
}

type RawInnerCall

type RawInnerCall struct {
	Type    string
	To      Address
	Input   HexData
	From    Address
	Value   HexNumber
	Gas     HexNumber
	GasUsed HexNumber
	Output  HexData
	Calls   []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 StorageItem struct {
	VarName  string      `json:"name"`
	VarIndex uint64      `json:"index"`
	VarType  string      `json:"type"`
	Value    interface{} `json:"value,omitempty"`
}

type StorageResult

type StorageResult struct {
	Storage     map[Hash]string
	StorageRoot Hash
	BlockNumber uint64
}

type Template

type Template struct {
	TemplateName  string `json:"templateName"`
	ABI           string `json:"abi"`
	StorageLayout string `json:"storageLayout"`
}

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"`
}

Jump to

Keyboard shortcuts

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