Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
.tool-versions
starknet.go
.idea/
.vscode/
vendor/

.tool-versions
.env*
!.env.template
rpc*/.env.mainnet
rpc*/.env.testnet

*.txt

tmp/

examples/**/*.sum

*/**/*abi.json

.idea/

.vscode/settings.json
50 changes: 50 additions & 0 deletions cmd/starkgen/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"fmt"
"time"

"github.com/spf13/cobra"
)

var (
// Used for flags.
abiPath string
pkgName string
typeName string
outPath string

// main CLI command
rootCmd = &cobra.Command{}

Check failure on line 18 in cmd/starkgen/main.go

View workflow job for this annotation

GitHub Actions / lint

cobra.Command is missing fields Use, Aliases, SuggestFor, Short, GroupID, Long, Example, ValidArgs, ValidArgsFunction, Args, ArgAliases, BashCompletionFunction, Deprecated, Annotations, Version, PersistentPreRun, PersistentPreRunE, PreRun, PreRunE, Run, RunE, PostRun, PostRunE, PersistentPostRun, PersistentPostRunE, FParseErrWhitelist, CompletionOptions, TraverseChildren, Hidden, SilenceErrors, SilenceUsage, DisableFlagParsing, DisableAutoGenTag, DisableFlagsInUseLine, DisableSuggestions, SuggestionsMinimumDistance (exhaustruct)
)

func init() {

Check failure on line 21 in cmd/starkgen/main.go

View workflow job for this annotation

GitHub Actions / lint

don't use `init` function (gochecknoinits)
// set flags
rootCmd.PersistentFlags().StringVar(&abiPath, "abi", "", "path to the Cairo contract ABI")
rootCmd.MarkPersistentFlagRequired("abi")

Check failure on line 24 in cmd/starkgen/main.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `rootCmd.MarkPersistentFlagRequired` is not checked (errcheck)
// @todo at the end, validate default values correctness
rootCmd.PersistentFlags().StringVar(&pkgName, "pkg", "", "package name for the generated Go code (default is the lower case contract name)")

Check failure on line 26 in cmd/starkgen/main.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (golines)
rootCmd.PersistentFlags().StringVar(&typeName, "type", "", "type name for the generated Go code (default is the upper case contract name)")
rootCmd.PersistentFlags().StringVar(&outPath, "out", "", "output directory for the generated Go code (default is the current directory)")
}

func main() {
rootCmd.Use = "starkgen --abi --pkg [--type] [--out]"
rootCmd.Short = "Generate Go bindings for Cairo contracts"
rootCmd.Long = `Generate Go bindings for Cairo contracts
Creating now random content just to test
how this text will be displayed in the termina.`

rootCmd.Run = func(cmd *cobra.Command, args []string) {
ticker := time.NewTicker(1 * time.Second)
go func() {
for {
time := <-ticker.C
fmt.Printf("%s\n", time)
}
}()
select {}
}

rootCmd.Execute()

Check failure on line 49 in cmd/starkgen/main.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `rootCmd.Execute` is not checked (errcheck)
}
10 changes: 8 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ require (
github.com/joho/godotenv v1.4.0
github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.9.1
github.com/stretchr/testify v1.10.0
go.uber.org/mock v0.5.0
golang.org/x/crypto v0.36.0
golang.org/x/net v0.38.0
)

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.6 // indirect
golang.org/x/text v0.26.0 // indirect
)

require (
github.com/bits-and-blooms/bitset v1.21.0 // indirect
github.com/consensys/bavard v0.1.27 // indirect
Expand All @@ -25,8 +32,7 @@ require (
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/sys v0.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

require golang.org/x/sys v0.31.0 // indirect
14 changes: 10 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ github.com/consensys/bavard v0.1.27 h1:j6hKUrGAy/H+gpNrpLU3I26n1yc+VMGmd6ID5+gAh
github.com/consensys/bavard v0.1.27/go.mod h1:k/zVjHHC4B+PQy1Pg7fgvG3ALicQw540Crag8qx+dZs=
github.com/consensys/gnark-crypto v0.16.0 h1:8Dl4eYmUWK9WmlP1Bj6je688gBRJCJbT8Mw4KoTAawo=
github.com/consensys/gnark-crypto v0.16.0/go.mod h1:Ke3j06ndtPTVvo++PhGNgvm+lgpLvzbcE2MqljY7diU=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80NsVHagjM=
Expand All @@ -43,6 +44,8 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/holiman/uint256 v1.3.2 h1:a9EgMPSC1AAaj1SZL5zIQD3WbwTuHrMGOerLjGmM/TA=
github.com/holiman/uint256 v1.3.2/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
Expand Down Expand Up @@ -74,6 +77,9 @@ github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0leargg
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
Expand All @@ -92,10 +98,10 @@ golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa h1:t2QcU6V556bFjYgu4L6C+6VrC
golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa/go.mod h1:BHOTPb3L19zxehTsLoJXVaTktb06DFgmdW6Wb9s8jqk=
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
134 changes: 134 additions & 0 deletions starkgen/abi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package starkgen

// Item represents a contract item ABI
// @todo make it a any type and use a switch statement to handle the different types
type Item struct {
Type string `json:"type"`
// The actual content is one of the following types based on the Type field
Function *Function `json:"function,omitempty"`
Constructor *Constructor `json:"constructor,omitempty"`
L1Handler *L1Handler `json:"l1_handler,omitempty"`
Event *Event `json:"event,omitempty"`
Struct *Struct `json:"struct,omitempty"`
Enum *Enum `json:"enum,omitempty"`
Interface *Interface `json:"interface,omitempty"`
Impl *Imp `json:"impl,omitempty"`
}

// Imp represents a contract implementation ABI
type Imp struct {
Type string `json:"type"`
Name string `json:"name"`
InterfaceName string `json:"interface_name"`
}

// Interface represents a contract interface ABI
type Interface struct {
Type string `json:"type"`
Name string `json:"name"`
Items []Item `json:"items"`
}

// StateMutability represents the state mutability of a function
type StateMutability string

const (
External StateMutability = "external"
View StateMutability = "view"
)

// Function represents a contract function ABI
type Function struct {
Type string `json:"type"`
Name string `json:"name"`
Inputs []Input `json:"inputs"`
Outputs []Output `json:"outputs"`
StateMutability StateMutability `json:"state_mutability"`
}

// Constructor represents a contract constructor ABI
type Constructor struct {
Type string `json:"type"`
Name string `json:"name"`
Inputs []Input `json:"inputs"`
}

// L1Handler represents a contract L1 handler ABI
type L1Handler struct {
Type string `json:"type"`
Name string `json:"name"`
Inputs []Input `json:"inputs"`
Outputs []Output `json:"outputs"`
StateMutability StateMutability `json:"state_mutability"`
}

// Event represents a contract event ABI
type Event struct {
Type string `json:"type"`
Name string `json:"name"`
Kind EventKind `json:"kind"`
Members []EventField `json:"members,omitempty"`
Variants []EventField `json:"variants,omitempty"`
}

// EventKind is a string enum representing the kind of an event
type EventKind string

const (
EventKindStruct EventKind = "struct"
EventKindEnum EventKind = "enum"
)

// EventField represents a field in an event
type EventField struct {
Name string `json:"name"`
Type string `json:"type"`
Kind EventFieldKind `json:"kind"`
}

// EventFieldKind represents how to serialize the event's field

Check failure on line 89 in starkgen/abi.go

View workflow job for this annotation

GitHub Actions / lint

`serialize` is a misspelling of `serialise` (misspell)
type EventFieldKind string

const (
KeySerde EventFieldKind = "key"
DataSerde EventFieldKind = "data"
Nested EventFieldKind = "nested"
Flat EventFieldKind = "flat"
)

// Input represents a function input ABI
type Input struct {
Name string `json:"name"`
Type string `json:"type"`
}

// Output represents a function output ABI
type Output struct {
Type string `json:"type"`
}

// Struct represents a struct ABI
type Struct struct {
Type string `json:"type"`
Name string `json:"name"`
Members []StructMember `json:"members"`
}

// StructMember represents a struct member
type StructMember struct {
Name string `json:"name"`
Type string `json:"type"`
}

// Enum represents an enum ABI
type Enum struct {
Type string `json:"type"`
Name string `json:"name"`
Variants []EnumVariant `json:"variants"`
}

// EnumVariant represents an enum variant
type EnumVariant struct {
Name string `json:"name"`
Type string `json:"type"`
}
6 changes: 6 additions & 0 deletions starkgen/decode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package starkgen

func GetABIFromFile(abiPath string) ([]byte, error) {
// TODO: implement
return nil, nil
}
Loading
Loading