Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6378fc1
chore: update linters
rodrigo-pino Oct 7, 2025
09ace65
chore: fix lll linter errors in the typeddata pkg
thiagodeev Oct 7, 2025
4715507
fix: fix lll linter errors in the utils pkg
thiagodeev Oct 7, 2025
2f245f0
fix: fix lll linter errors in the internal pkg
thiagodeev Oct 7, 2025
1605139
fix: new lll linter errors in the rpc pkg
thiagodeev Oct 8, 2025
bf5ab8b
fix: new lll linter errors in the account pkg
thiagodeev Oct 8, 2025
1571a85
fix: new lll linter errors in all other small pkgs
thiagodeev Oct 8, 2025
202b754
feat: apply new nolintlint lint rules and implement them in the code
thiagodeev Oct 9, 2025
ae336b9
feat: add new staticcheck linter rule and update part of the code wit…
thiagodeev Oct 9, 2025
90763a6
refactor: update interface assertions to use nil pointers
thiagodeev Oct 10, 2025
1e9c489
refactor: rename typedData package to typedata and update related ref…
thiagodeev Oct 10, 2025
74071c2
refactor: more changes related to the ST1003 staticcheck linter
thiagodeev Oct 10, 2025
aa4bc98
refactor: more changes related to the ST1003 staticcheck linter 2
thiagodeev Oct 10, 2025
067f380
refactor: more changes related to the ST1003 staticcheck linter 3
thiagodeev Oct 10, 2025
bde05e8
refactor: more changes related to the ST1003 staticcheck linter 4
thiagodeev Oct 10, 2025
1170c6d
refactor: fixing other staticcheck linter errors
thiagodeev Oct 10, 2025
a39f149
refactor: enable all gocritic linters
thiagodeev Oct 10, 2025
804bf7b
refactor: allow gosec linter and change code to support it
thiagodeev Oct 10, 2025
d35a8fd
ci: enable all govet linters except fieldalignment
thiagodeev Oct 10, 2025
547e61a
ci: remove more exclusions from the linter file
thiagodeev Oct 10, 2025
983590e
Merge branch 'main' into rdr/update-linters
thiagodeev Oct 10, 2025
df82a05
ci: remove golangci_diff.yaml and update linter workflow to use speci…
thiagodeev Oct 13, 2025
6eda08a
chore: update golangci-lint version to v2.5.0 and fix linter
thiagodeev Oct 13, 2025
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
8 changes: 4 additions & 4 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4.1.0
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 #v5
with:
go-version-file: go.mod
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 #v8
with:
version: v2.4.0
version: v2.5.0
47 changes: 19 additions & 28 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,16 @@ linters:
min-len: 2
min-occurrences: 3
gocritic:
disabled-checks:
- sloppyReassign
- dupImport
- ifElseChain
- octalLiteral
- whyNoLint
- unnamedResult
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
enable-all: true
gocyclo:
min-complexity: 15
gosec:
excludes:
- G115
govet:
enable:
- nilness
- shadow
enable-all: true
disable:
# Since we are a library, we need to also take into account the UX when aligning fields.
- fieldalignment
lll:
line-length: 140
line-length: 100
misspell:
locale: UK
mnd:
Expand All @@ -85,21 +71,20 @@ linters:
- "1"
- "2"
- "3"
ignored-functions:
- strings.SplitN
nolintlint:
require-explanation: false
require-specific: false
allow-unused: false
require-explanation: true
require-specific: true
staticcheck:
checks:
- "all"
exclusions:
paths:
- client/ # it comes from go-ethereum, let's refactor it another time
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- exhaustruct
Expand Down Expand Up @@ -133,6 +118,9 @@ linters:
- linters:
- lll
source: '^//go:generate '
- linters:
- staticcheck
path: rpc/mock_test.go
formatters:
enable:
- gci
Expand All @@ -142,7 +130,10 @@ formatters:
- golines
settings:
golines:
max-len: 140
max-len: 100
goimports:
local-prefixes:
- github.com/golangci/golangci-lint
- github.com/golangci/golangci-lint
issues:
max-issues-per-linter: 0
max-same-issues: 0
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New `curve.SignFelts` function for signing messages with felt.Felt parameters.

### Changed
- Major refactoring in the codebase to match Golang conventions.
- Renaming:
- All type/function names that contained `_` have been renamed to remove the underscore.
- The `typedData` pkg was renamed to `typedata`.
- The `rpc.Provider.GetStorageProof` method was renamed to `rpc.Provider.StorageProof`.
- The `rpc.Provider.GetTransactionStatus` method was renamed to `rpc.Provider.TransactionStatus`.
- The `rpc.Provider.GetMessagesStatus` method was renamed to `rpc.Provider.MessagesStatus`.
- The `rpc.Provider.TransactionByBlockIdAndIndex` method was renamed to `rpc.Provider.TransactionByBlockIDAndIndex` (see the 'ID').
- The `rpc.RpcProvider` interface was renamed to `rpc.RPCProvider`.
- Other renames in exported types/fields/variables:
- `typedData.Domain.ChainId` -> `typedData.Domain.ChainID`
- `rpc.SKIP_FEE_CHARGE` -> `rpc.SkipFeeCharge`
- `rpc.SKIP_VALIDATE` -> `rpc.SkipValidate`
- `account.Account.ChainId` -> `account.Account.ChainID`
- Variables `hash.PREFIX_TRANSACTION`, `hash.PREFIX_DECLARE`, and `hash.PREFIX_DEPLOY_ACCOUNT` were renamed and
are no longer exported.
- Variable `contracts.PREFIX_CONTRACT_ADDRESS` was renamed and is no longer exported.
- Changed types:
- `contracts.SierraEntryPoint.FunctionIdx` is now of type `uint`
- `contracts.CasmEntryPoint.Offset` is now of type `uint`
- The `rpc.RPCError` type and logic was refactored and moved to the new `client/rpcerr` package.
There are some changes in the new package:
- The internal `tryUnwrapToRPCErr` func of the `rpc` pkg was renamed to `UnwrapToRPCErr` and moved to the new package.
Expand All @@ -37,6 +57,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
old `rpc/spy_test.go` file was removed.
- New `mocks/mock_client.go` file containing a mock of the `client.Client` type (`client.ClientI` interface).
- New benchmarks and tests for the `typedData` pkg.
- New linter rules in the `.golangci.yaml` file, thus, a lot of changes in the codebase to fix the new rules.
- Updated `golangci-lint` to v2.5.0.

## [0.15.0](https://github.com/NethermindEth/starknet.go/releases/tag/v0.15.0) - 2025-09-03
### Changed
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GOLANGCI_LINT_VERSION := v2.4.0
GOLANGCI_LINT_VERSION := v2.5.0
MOCKGEN_VERSION := v0.6.0
.PHONY: test lint format

Expand Down
71 changes: 50 additions & 21 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (
var (
ErrTxnTypeUnSupported = errors.New("unsupported transaction type")
ErrTxnVersionUnSupported = errors.New("unsupported transaction version")
BRAAVOS_WARNING_MESSAGE = `WARNING: Currently, Braavos accounts are incompatible with transactions sent via
RPC 0.8.0. Ref: https://community.starknet.io/t/starknet-devtools-for-0-13-5/115495#p-2359168-braavos-compatibility-issues-3`

//nolint:lll // The line break would be outputted in the warning message
BraavosWarningMessage = `WARNING: Currently, Braavos accounts are incompatible with transactions sent via RPC 0.8.0. Ref: https://community.starknet.io/t/starknet-devtools-for-0-13-5/115495#p-2359168-braavos-compatibility-issues-3`
)

//go:generate mockgen -destination=../mocks/mock_account.go -package=mocks -source=account.go AccountInterface
Expand Down Expand Up @@ -50,10 +51,17 @@ type AccountInterface interface {
SendTransaction(ctx context.Context, txn rpc.BroadcastTxn) (rpc.TransactionResponse, error)
Sign(ctx context.Context, msg *felt.Felt) ([]*felt.Felt, error)
SignInvokeTransaction(ctx context.Context, tx rpc.InvokeTxnType) error
SignDeployAccountTransaction(ctx context.Context, tx rpc.DeployAccountType, precomputeAddress *felt.Felt) error
SignDeployAccountTransaction(
ctx context.Context,
tx rpc.DeployAccountType,
precomputeAddress *felt.Felt,
) error
SignDeclareTransaction(ctx context.Context, tx rpc.DeclareTxnType) error
TransactionHashInvoke(invokeTxn rpc.InvokeTxnType) (*felt.Felt, error)
TransactionHashDeployAccount(tx rpc.DeployAccountType, contractAddress *felt.Felt) (*felt.Felt, error)
TransactionHashDeployAccount(
tx rpc.DeployAccountType,
contractAddress *felt.Felt,
) (*felt.Felt, error)
TransactionHashDeclare(tx rpc.DeclareTxnType) (*felt.Felt, error)
Verify(msgHash *felt.Felt, signature []*felt.Felt) (bool, error)
WaitForTransactionReceipt(
Expand All @@ -63,11 +71,11 @@ type AccountInterface interface {
) (*rpc.TransactionReceiptWithBlockInfo, error)
}

var _ AccountInterface = &Account{} //nolint:exhaustruct
var _ AccountInterface = (*Account)(nil)

type Account struct {
Provider rpc.RpcProvider
ChainId *felt.Felt
Provider rpc.RPCProvider
ChainID *felt.Felt
Address *felt.Felt
publicKey string
CairoVersion CairoVersion
Expand Down Expand Up @@ -98,19 +106,26 @@ const (
// - *Account: a pointer to newly created Account
// - error: an error if any
func NewAccount(
provider rpc.RpcProvider,
provider rpc.RPCProvider,
accountAddress *felt.Felt,
publicKey string,
keystore Keystore,
cairoVersion CairoVersion,
) (*Account, error) {
// TODO: Remove this temporary check once solved (starknet v0.14.0 should do it)
// This temporary check is to warn the user that Braavos account restricts transactions to have exactly two resource fields.
// This temporary check is to warn the user that Braavos account restricts
// transactions to have exactly two resource fields.
// This makes them incompatible with transactions sent via RPC 0.8.0
accClassHash, err := provider.ClassHashAt(context.Background(), rpc.WithBlockTag("latest"), accountAddress)
// ignoring the error to not break mock tests (if the provider is not working, it will return an error in the next ChainID call anyway)
accClassHash, err := provider.ClassHashAt(
context.Background(),
rpc.WithBlockTag("latest"),
accountAddress,
)
// ignoring the error to not break mock tests (if the provider is not
// working, it will return an error in the next ChainID call anyway)
if err == nil {
// Since felt.Felt.String() returns a string without leading zeros, we need to remove them from the
// Since felt.Felt.String() returns a string without leading zeros, we
// need to remove them from the class hashes for the comparison
// class hashes for the comparison
braavosClassHashes := []string{
// Original class hash: 0x02c8c7e6fbcfb3e8e15a46648e8914c6aa1fc506fc1e7fb3d1e19630716174bc
Expand All @@ -121,7 +136,7 @@ func NewAccount(
"0x41bf1e71792aecb9df3e9d04e1540091c5e13122a731e02bec588f71dc1a5c3",
}
if slices.Contains(braavosClassHashes, accClassHash.String()) {
fmt.Print(BRAAVOS_WARNING_MESSAGE + "\n\n")
fmt.Print(BraavosWarningMessage + "\n\n")
}
}

Expand All @@ -136,7 +151,7 @@ func NewAccount(
publicKey: publicKey,
ks: keystore,
CairoVersion: cairoVersion,
ChainId: new(felt.Felt).SetBytes([]byte(chainID)),
ChainID: new(felt.Felt).SetBytes([]byte(chainID)),
}

return account, nil
Expand All @@ -158,7 +173,10 @@ func (account *Account) Nonce(ctx context.Context) (*felt.Felt, error) {
// Returns:
// - *felt.Felt: the precomputed address as a *felt.Felt
// - error: an error if any
func PrecomputeAccountAddress(salt, classHash *felt.Felt, constructorCalldata []*felt.Felt) *felt.Felt {
func PrecomputeAccountAddress(
salt, classHash *felt.Felt,
constructorCalldata []*felt.Felt,
) *felt.Felt {
return contracts.PrecomputeAddress(&felt.Zero, salt, classHash, constructorCalldata)
}

Expand All @@ -181,7 +199,8 @@ func (account *Account) FmtCalldata(fnCalls []rpc.FunctionCall) ([]*felt.Felt, e
}
}

// FmtCallDataCairo0 generates a slice of *felt.Felt that represents the calldata for the given function calls in Cairo 0 format.
// FmtCallDataCairo0 generates a slice of *felt.Felt that represents the
// calldata for the given function calls in Cairo 0 format.
//
// Parameters:
// - fnCalls: a slice of rpc.FunctionCall containing the function calls.
Expand All @@ -190,15 +209,22 @@ func (account *Account) FmtCalldata(fnCalls []rpc.FunctionCall) ([]*felt.Felt, e
// - a slice of *felt.Felt representing the generated calldata.
//
// https://github.com/project3fusion/StarkSharp/blob/main/StarkSharp/StarkSharp.Rpc/Modules/Transactions/Hash/TransactionHash.cs#L27
//
//nolint:lll // The link would be unclickable if we break the line.
func FmtCallDataCairo0(callArray []rpc.FunctionCall) []*felt.Felt {
calldata := make([]*felt.Felt, 0, 10) //nolint:mnd
calls := make([]*felt.Felt, 0, 10) //nolint:mnd
calldata := make([]*felt.Felt, 0, 10) //nolint:mnd // Randomly chosen
calls := make([]*felt.Felt, 0, 10) //nolint:mnd // Randomly chosen

calldata = append(calldata, new(felt.Felt).SetUint64(uint64(len(callArray))))

offset := uint64(0)
for _, call := range callArray {
calldata = append(calldata, call.ContractAddress, call.EntryPointSelector, new(felt.Felt).SetUint64(offset))
calldata = append(
calldata,
call.ContractAddress,
call.EntryPointSelector,
new(felt.Felt).SetUint64(offset),
)
callDataLen := uint64(len(call.Calldata))
calldata = append(calldata, new(felt.Felt).SetUint64(callDataLen))
offset += callDataLen
Expand All @@ -212,7 +238,8 @@ func FmtCallDataCairo0(callArray []rpc.FunctionCall) []*felt.Felt {
return calldata
}

// FmtCallDataCairo2 generates the calldata for the given function calls for Cairo 2 contracts.
// FmtCallDataCairo2 generates the calldata for the given function calls for
// Cairo 2 contracts.
//
// Parameters:
// - fnCalls: a slice of rpc.FunctionCall containing the function calls.
Expand All @@ -221,8 +248,10 @@ func FmtCallDataCairo0(callArray []rpc.FunctionCall) []*felt.Felt {
// - a slice of *felt.Felt representing the generated calldata.
//
// https://github.com/project3fusion/StarkSharp/blob/main/StarkSharp/StarkSharp.Rpc/Modules/Transactions/Hash/TransactionHash.cs#L22
//
//nolint:lll // The link would be unclickable if we break the line.
func FmtCallDataCairo2(callArray []rpc.FunctionCall) []*felt.Felt {
result := make([]*felt.Felt, 0, 10) //nolint:mnd
result := make([]*felt.Felt, 0, 10) //nolint:mnd // Randomly chosen

result = append(result, new(felt.Felt).SetUint64(uint64(len(callArray))))

Expand Down
Loading
Loading