parser

package
v0.0.0-...-aac2901 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package parser is used to parse some stuff

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgBool

type ArgBool bool

ArgBool is a type alias to capture bool values correctly

func (*ArgBool) Capture

func (b *ArgBool) Capture(values []string) error

type ArgEnsDomain

type ArgEnsDomain common.Address

ArgEnsDomain is a type alias to capture ENS domains

func (*ArgEnsDomain) Capture

func (b *ArgEnsDomain) Capture(values []string) error

type ArgHex

type ArgHex struct {
	Address *base.Address
	String  *string
}

ArgHex represents anything that starts with 0x. If the value is a valid address, then it's capture into `base.Address` type, `string` otherwise.

func (*ArgHex) Capture

func (h *ArgHex) Capture(values []string) error

type ArgNumber

type ArgNumber struct {
	Int  *int64
	Uint *uint64
	Big  *base.Wei
}

ArgNumber represents a number

func (*ArgNumber) Capture

func (n *ArgNumber) Capture(values []string) error

func (*ArgNumber) Convert

func (n *ArgNumber) Convert(abiType *abi.Type) (any, error)

func (*ArgNumber) Interface

func (n *ArgNumber) Interface() any

Interface returns Number value as any

type ArgString

type ArgString string

ArgString is a type alias to capture strings correctly

func (*ArgString) Capture

func (b *ArgString) Capture(values []string) error

type ContractArgument

type ContractArgument struct {
	Tokens  []lexer.Token // the token that was parsed for this argument
	String  *ArgString    `parser:"@String"`             // the value if it's a string
	Number  *ArgNumber    `parser:"| @Decimal"`          // the value if it's a number
	Boolean *ArgBool      `parser:"| @('true'|'false')"` // the value if it's a boolean
	Hex     *ArgHex       `parser:"| @Hex"`              // the value if it's a hex string
	EnsAddr *ArgEnsDomain `parser:"| @EnsDomain"`        // the value if it's an ENS domain
}

ContractArgument represents input to the smart contract method call, e.g. `true` in `setSomething(true)`

func (*ContractArgument) AbiType

func (a *ContractArgument) AbiType(abiType *abi.Type) (any, error)

func (*ContractArgument) Interface

func (a *ContractArgument) Interface() any

Interface returns the value as interface{} (any)

type ContractCall

type ContractCall struct {
	// Four byte selector, e.g.
	// 0xcdba2fd4(105)
	SelectorCall *SelectorContractCall `parser:"@@"`

	// Everything encoded, e.g.
	// 0xcdba2fd40000000000000000000000000000000000000000000000000000000000007a69
	Encoded string `parser:" | @Hex"`

	// Function name, e.g.
	// someName(105)
	FunctionNameCall *FunctionContractCall `parser:" | @@"`
}

ContractCall is a call to a smart contract in any of the 3 supported forms (see Input syntax above)

func ParseCall

func ParseCall(source string) (*ContractCall, error)

ParseCall turns smart contract method call string and parses it into a nice structures, from which we can easily extract the data to make the call.

type FunctionContractCall

type FunctionContractCall struct {
	Name      string              `parser:"@SolidityIdent '('"`
	Arguments []*ContractArgument `parser:" (@@ (',' @@)*)? ')'"`
}

type Selector

type Selector struct {
	Value string
}

Selector captures four byte function selector (e.g. 0xcdba2fd4) It's capture method makes sure that the hex value is a valid selector.

func (*Selector) Capture

func (s *Selector) Capture(values []string) error

type SelectorContractCall

type SelectorContractCall struct {
	Selector  Selector            `parser:"@Hex '('"`
	Arguments []*ContractArgument `parser:" (@@ (',' @@)*)? ')'"`
}

Jump to

Keyboard shortcuts

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