abi

package
v0.0.0-...-9345ff8 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FunctionType    = "function"
	L1HandlerType   = "l1_handler"
	ConstructorType = "constructor"
	EventType       = "event"
	StructType      = "struct"
)

abi types

View Source
const (
	EntrypointTypeExternal    = "EXTERNAL"
	EntrypointTypeConstructor = "CONSTRUCTOR"
	EntrypointTypeL1Handler   = "L1_HANDLER"
)

entrypoint types

Variables

View Source
var (
	ErrTooShortCallData = errors.New("calldata is too short")
	ErrInvalidTupleType = errors.New("invalid tuple type")
	ErrNoLenField       = errors.New("can't find array length field")
)

errors

View Source
var (
	ExecuteFunction = FunctionItem{
		Type: Type{
			Type: FunctionType,
			Name: encoding.ExecuteEntrypoint,
		},

		Inputs: []Type{
			{
				Name: "call_array_len",
				Type: "felt",
			}, {
				Name: "call_array",
				Type: "CallArray*",
			}, {
				Name: "calldata_len",
				Type: "felt",
			}, {
				Name: "calldata",
				Type: "felt*",
			},
		},
		Outputs: []Type{
			{
				Name: "response_len",
				Type: "felt",
			}, {
				Name: "response",
				Type: "felt*",
			},
		},
	}

	CallArray = StructItem{
		Type: Type{
			Type: StructType,
			Name: "CallArray",
		},
		Size: 4,
		Members: []Member{
			{
				Type: Type{
					Type: "felt",
					Name: "to",
				},
				Offset: 0,
			}, {
				Type: Type{
					Type: "felt",
					Name: "selector",
				},
				Offset: 1,
			}, {
				Type: Type{
					Type: "felt",
					Name: "data_offset",
				},
				Offset: 2,
			}, {
				Type: Type{
					Type: "felt",
					Name: "data_len",
				},
				Offset: 3,
			},
		},
	}

	ChangeModules = FunctionItem{
		Type: Type{
			Type: FunctionType,
			Name: encoding.ChangeModulesEntrypoint,
		},

		Inputs: []Type{
			{
				Name: "actions_len",
				Type: "felt",
			}, {
				Name: "actions",
				Type: "ModuleFunctionAction*",
			}, {
				Name: "address",
				Type: "felt",
			}, {
				Name: "calldata_len",
				Type: "felt",
			}, {
				Name: "calldata",
				Type: "felt*",
			},
		},
		Outputs: []Type{
			{
				Name: "response_len",
				Type: "felt",
			}, {
				Name: "response",
				Type: "felt*",
			},
		},
	}

	ModuleFunctionAction = StructItem{
		Type: Type{
			Type: StructType,
			Name: "ModuleFunctionAction",
		},
		Size: 3,
		Members: []Member{
			{
				Type: Type{
					Type: "felt",
					Name: "module_address",
				},
				Offset: 0,
			}, {
				Type: Type{
					Type: "felt",
					Name: "action",
				},
				Offset: 1,
			}, {
				Type: Type{
					Type: "felt",
					Name: "selector",
				},
				Offset: 2,
			},
		},
	}
)

default types

Functions

func DecodeChangeModulesCallData

func DecodeChangeModulesCallData(calldata []string) (map[string]any, error)

DecodeChangeModulesCallData -

func DecodeEventData

func DecodeEventData(data []string, typ EventItem, structs map[string]*StructItem) (map[string]any, error)

DecodeEventData -

func DecodeExecuteCallData

func DecodeExecuteCallData(calldata []string) (map[string]any, error)

DecodeExecuteCallData -

func DecodeFunctionCallData

func DecodeFunctionCallData(calldata []string, typ FunctionItem, structs map[string]*StructItem) (map[string]any, error)

DecodeFunctionCallData -

Types

type Abi

type Abi struct {
	Functions   map[string]*FunctionItem `json:"-"`
	L1Handlers  map[string]*FunctionItem `json:"-"`
	Constructor map[string]*FunctionItem `json:"-"`
	Events      map[string]*EventItem    `json:"-"`
	Structs     map[string]*StructItem   `json:"-"`

	FunctionsBySelector   map[string]*FunctionItem `json:"-"`
	L1HandlersBySelector  map[string]*FunctionItem `json:"-"`
	ConstructorBySelector map[string]*FunctionItem `json:"-"`
	EventsBySelector      map[string]*EventItem    `json:"-"`
	StructsBySelector     map[string]*StructItem   `json:"-"`

	Names map[string]string `json:"-"`
}

Abi -

func (*Abi) GetByTypeAndSelector

func (a *Abi) GetByTypeAndSelector(typ string, selector string) (any, bool)

GetByTypeAndSelector - receives abi type by entrypoint type and selector

func (*Abi) GetConstructorBySelector

func (a *Abi) GetConstructorBySelector(selector string) (*FunctionItem, bool)

GetConstructorBySelector - receives constructor's ABI by selector. Selector may has prefix 0x and left-padding zeroes.

func (*Abi) GetEventBySelector

func (a *Abi) GetEventBySelector(selector string) (*EventItem, bool)

GetEventBySelector - receives event's ABI by selector. Selector may has prefix 0x and left-padding zeroes.

func (*Abi) GetFunctionBySelector

func (a *Abi) GetFunctionBySelector(selector string) (*FunctionItem, bool)

GetFunctionBySelector - receives function's ABI by selector. Selector may has prefix 0x and left-padding zeroes.

func (*Abi) GetL1HandlerBySelector

func (a *Abi) GetL1HandlerBySelector(selector string) (*FunctionItem, bool)

GetL1HandlerBySelector - receives l1 handler's ABI by selector. Selector may has prefix 0x and left-padding zeroes.

func (*Abi) GetStructBySelector

func (a *Abi) GetStructBySelector(selector string) (*StructItem, bool)

GetStructBySelector - receives struct's ABI by selector. Selector may has prefix 0x and left-padding zeroes.

func (*Abi) UnmarshalJSON

func (a *Abi) UnmarshalJSON(raw []byte) error

UnmarshalJSON -

type EventItem

type EventItem struct {
	Type

	Data []Type `json:"data"`
	Keys []Type `json:"keys"`
}

EventItem -

type FunctionItem

type FunctionItem struct {
	Type

	Inputs  []Type `json:"inputs"`
	Outputs []Type `json:"outputs"`
}

FunctionItem -

type Member

type Member struct {
	Type

	Offset uint64 `json:"offset"`
}

Member -

type StructItem

type StructItem struct {
	Type

	Size    uint64   `json:"size"`
	Members []Member `json:"members"`
}

StructItem -

type Type

type Type struct {
	Type string `json:"type"`
	Name string `json:"name"`
}

Type -

Jump to

Keyboard shortcuts

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