starknet

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EnumTemplate string = `` /* 821-byte string literal not displayed */

This is the Go template which is used to generate the function corresponding to an Enum. This template should be applied to a GeneratedEnum struct.

View Source
var EventParserTemplate string = `` /* 1000-byte string literal not displayed */

This aggregates all event information to generate an event parser for the given ABI. This template should be applied to a []GeneratedEvent list.

View Source
var EventTemplate string = `` /* 1212-byte string literal not displayed */

This is the Go template which is used to generate the Go bindings to a Starknet ABI event. This template should be applied to a GeneratedEvent struct.

View Source
var EventsCommonCode string = `` /* 3905-byte string literal not displayed */

Common code used in the code generated for events.

View Source
var HeaderTemplate string = `` /* 577-byte string literal not displayed */

This is the Go template used to create header information at the top of the generated code. At a bare minimum, the header specifies the version of seer that was used to generate the code. This template should be applied to a HeaderParameters struct.

View Source
var StructCommonCode string = `` /* 1368-byte string literal not displayed */
View Source
var StructTemplate string = `` /* 928-byte string literal not displayed */

This is the Go template which is used to generate the Go definition of a Starknet ABI struct. This template should be applied to a GeneratedStruct struct.

Functions

func Generate

func Generate(parsed *ParsedABI) (string, error)

Generates a single string consisting of the Go code for all the artifacts in a parsed Starknet ABI.

func GenerateGoNameForType

func GenerateGoNameForType(qualifiedName string) string

Generates a Go name for a Starknet ABI item given its fully qualified ABI name. Qualified names for Starknet ABI items are of the form: `core::starknet::contract_address::ContractAddress`

func GenerateHeader

func GenerateHeader(packageName string) (string, error)

Generates the header for the output code.

func GenerateSnippets

func GenerateSnippets(parsed *ParsedABI) (map[string]string, error)

Generate generates Go code for each of the items in a Starknet contract ABI. Returns a mapping of the go name of each object to a specification of the generated artifact. Currently supports: - Enums - Structs - Events

ABI names are used to depuplicate code snippets. The assumption is that the Starknet fully qualified name for a type uniquely determines that type across the entire ABI. This way even if the ABI passed into the code generator contains duplicate instances of an ABI item, the Go code will only contain one definition of that item.

func HashFromName

func HashFromName(name string) (string, error)

Calculates the Starknet hash corresponding to the name of a Starknet ABI event. This hash is how the event is represented in Starknet event logs.

func ParserFunction

func ParserFunction(goType string) string

Returns the name of the function that parses the given Go type.

func ShouldGenerateStructType

func ShouldGenerateStructType(goName string) bool

Types

type ABIItemType

type ABIItemType struct {
	Type string `json:"type,omitempty"`
	Kind string `json:"kind,omitempty"`
}

Represents a single item in a Starknet ABI.

type Enum

type Enum struct {
	Type     string         `json:"type"`
	Name     string         `json:"name"`
	Variants []*EnumVariant `json:"variants"`
}

Represents an enum in a Starknet ABI.

type EnumVariant

type EnumVariant struct {
	Name  string `json:"name"`
	Index int    `json:"index"`
}

Represents a particular value in a Starknet ABI enum.

type EventStruct

type EventStruct struct {
	Type    string          `json:"type"`
	Name    string          `json:"name"`
	Kind    string          `json:"kind"`
	Members []*StructMember `json:"members"`
}

Represents a struct in a Starknet ABI which is used as an event.

type GeneratedEnum

type GeneratedEnum struct {
	GenerationParameters
	ParserName    string
	EvaluatorName string
	Definition    *Enum
	Code          string
}

The output of the code generation process for enum items in a Starknet ABI.

type GeneratedEvent

type GeneratedEvent struct {
	GenerationParameters
	ParserName   string
	Definition   *EventStruct
	EventNameVar string
	EventHashVar string
	EventHash    string
	Code         string
}

type GeneratedStruct

type GeneratedStruct struct {
	GenerationParameters
	ParserName string
	Definition *Struct
	Code       string
}

The output of the code generation process for struct items in a Starknet ABI.

type GenerationParameters

type GenerationParameters struct {
	OriginalName string
	GoName       string
}

Common parameters required for the generation of all types of artifacts.

type HeaderParameters

type HeaderParameters struct {
	Version     string
	PackageName string
}

Defines the parameters used to create the header information for the generated code.

type IntermediateABI

type IntermediateABI struct {
	Types    []ABIItemType
	Messages []json.RawMessage
}

Internal representation of a Starknet ABI used while parsing the ABI into its Go representation as a ParsedABI.

type ParsedABI

type ParsedABI struct {
	Enums   []*Enum        `json:"enums"`
	Structs []*Struct      `json:"structs"`
	Events  []*EventStruct `json:"events"`
}

Represents a parsed Starknet ABI.

func ParseABI

func ParseABI(rawABI []byte) (*ParsedABI, error)

Parses a Starknet ABI from a JSON byte array.

type Struct

type Struct struct {
	Type    string          `json:"type"`
	Name    string          `json:"name"`
	Members []*StructMember `json:"members"`
}

Represents a struct in a Starknet ABI.

type StructMember

type StructMember struct {
	Name string `json:"name"`
	Type string `json:"type"`
	Kind string `json:"kind,omitempty"`
}

Represents a member of a Starknet ABI struct.

Jump to

Keyboard shortcuts

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