Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions .github/workflows/lint-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ jobs:
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v0.18.1 ./...

- name: golangci-lint
uses: golangci/golangci-lint-action@v6.4.1
uses: golangci/golangci-lint-action@v8
with:
version: v1.64.8
version: v2.2.1
# use the default if on main branch, otherwise use the pull request config
args: --timeout=30m --config=.golangci.yml
only-new-issues: false
Expand Down
99 changes: 50 additions & 49 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,63 @@
# Please refer to the official golangci-lint config documentation for more details:
# https://golangci-lint.run/usage/configuration/
# https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
version: "2"
run:
timeout: 10m
Comment thread
otherview marked this conversation as resolved.
tests: true
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
exclude-dirs-use-default: true

linters:
disable-all: true
default: none
enable:
- goimports
- gosimple
- bidichk
- copyloopvar
- durationcheck
- gosec
- govet
- ineffassign
- misspell
- revive
- staticcheck
Comment thread
otherview marked this conversation as resolved.
- unconvert
- typecheck
- unused
- staticcheck
- bidichk
- durationcheck
- copyloopvar
- whitespace
- gosec
- revive

# - structcheck # lots of false positives
# - errcheck #lot of false positives
# - contextcheck
# - errchkjson # lots of false positives
# - errorlint # this check crashes
# - exhaustive # silly check
# - makezero # false positives
# - nilerr # several intentional

linters-settings:
gofmt:
simplify: true
gosec:
excludes:
- G115
- G406 # ignore ripe160 deprecation
- G507 # ignore ripe160 deprecation
revive:
settings:
gosec:
excludes:
- G115
- G406
- G507
revive:
rules:
- name: var-naming
arguments:
- []
- []
- - upperCaseConst: true
severity: warning
disabled: false
exclude:
- ""
exclusions:
Comment thread
otherview marked this conversation as resolved.
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- name: var-naming
severity: warning
disabled: false
exclude: [""]
arguments:
- [] # AllowList
- [] # DenyList
- - upperCaseConst: true # Extra parameter (upperCaseConst|skipPackageNameChecks)

- path: vm/contracts.go
text: 'SA1019: "golang.org/x/crypto/ripemd160" is deprecated: RIPEMD-160 is a legacy hash and should not be used for new applications.'
paths:
- third_party$
- builtin$
- examples$
issues:
max-issues-per-linter: 1000
exclude-rules:
- path: vm/contracts.go
text: 'SA1019: "golang.org/x/crypto/ripemd160" is deprecated: RIPEMD-160 is a legacy hash and should not be used for new applications.'
formatters:
enable:
- goimports
settings:
gofmt:
simplify: true
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
90 changes: 45 additions & 45 deletions api/accounts/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/vechain/thor/v2/api"
"github.com/vechain/thor/v2/api/utils"
"github.com/vechain/thor/v2/api/restutil"
"github.com/vechain/thor/v2/bft"
"github.com/vechain/thor/v2/block"
"github.com/vechain/thor/v2/chain"
Expand Down Expand Up @@ -66,17 +66,17 @@ func (a *Accounts) handleGetCode(w http.ResponseWriter, req *http.Request) error
hexAddr := mux.Vars(req)["address"]
addr, err := thor.ParseAddress(hexAddr)
if err != nil {
return utils.BadRequest(errors.WithMessage(err, "address"))
return restutil.BadRequest(errors.WithMessage(err, "address"))
}
revision, err := utils.ParseRevision(req.URL.Query().Get("revision"), false)
revision, err := restutil.ParseRevision(req.URL.Query().Get("revision"), false)
if err != nil {
return utils.BadRequest(errors.WithMessage(err, "revision"))
return restutil.BadRequest(errors.WithMessage(err, "revision"))
}

_, st, err := utils.GetSummaryAndState(revision, a.repo, a.bft, a.stater, a.forkConfig)
_, st, err := restutil.GetSummaryAndState(revision, a.repo, a.bft, a.stater, a.forkConfig)
if err != nil {
if a.repo.IsNotFound(err) {
return utils.BadRequest(errors.WithMessage(err, "revision"))
return restutil.BadRequest(errors.WithMessage(err, "revision"))
}
return err
}
Expand All @@ -85,7 +85,7 @@ func (a *Accounts) handleGetCode(w http.ResponseWriter, req *http.Request) error
return err
}

return utils.WriteJSON(w, &api.GetCodeResult{Code: hexutil.Encode(code)})
return restutil.WriteJSON(w, &api.GetCodeResult{Code: hexutil.Encode(code)})
}

func (a *Accounts) getAccount(addr thor.Address, header *block.Header, state *state.State) (*api.Account, error) {
Expand Down Expand Up @@ -120,17 +120,17 @@ func (a *Accounts) getStorage(addr thor.Address, key thor.Bytes32, state *state.
func (a *Accounts) handleGetAccount(w http.ResponseWriter, req *http.Request) error {
addr, err := thor.ParseAddress(mux.Vars(req)["address"])
if err != nil {
return utils.BadRequest(errors.WithMessage(err, "address"))
return restutil.BadRequest(errors.WithMessage(err, "address"))
}
revision, err := utils.ParseRevision(req.URL.Query().Get("revision"), false)
revision, err := restutil.ParseRevision(req.URL.Query().Get("revision"), false)
if err != nil {
return utils.BadRequest(errors.WithMessage(err, "revision"))
return restutil.BadRequest(errors.WithMessage(err, "revision"))
}

summary, st, err := utils.GetSummaryAndState(revision, a.repo, a.bft, a.stater, a.forkConfig)
summary, st, err := restutil.GetSummaryAndState(revision, a.repo, a.bft, a.stater, a.forkConfig)
if err != nil {
if a.repo.IsNotFound(err) {
return utils.BadRequest(errors.WithMessage(err, "revision"))
return restutil.BadRequest(errors.WithMessage(err, "revision"))
}
return err
}
Expand All @@ -139,27 +139,27 @@ func (a *Accounts) handleGetAccount(w http.ResponseWriter, req *http.Request) er
if err != nil {
return err
}
return utils.WriteJSON(w, acc)
return restutil.WriteJSON(w, acc)
}

func (a *Accounts) handleGetStorage(w http.ResponseWriter, req *http.Request) error {
addr, err := thor.ParseAddress(mux.Vars(req)["address"])
if err != nil {
return utils.BadRequest(errors.WithMessage(err, "address"))
return restutil.BadRequest(errors.WithMessage(err, "address"))
}
key, err := thor.ParseBytes32(mux.Vars(req)["key"])
if err != nil {
return utils.BadRequest(errors.WithMessage(err, "key"))
return restutil.BadRequest(errors.WithMessage(err, "key"))
}
revision, err := utils.ParseRevision(req.URL.Query().Get("revision"), false)
revision, err := restutil.ParseRevision(req.URL.Query().Get("revision"), false)
if err != nil {
return utils.BadRequest(errors.WithMessage(err, "revision"))
return restutil.BadRequest(errors.WithMessage(err, "revision"))
}

_, st, err := utils.GetSummaryAndState(revision, a.repo, a.bft, a.stater, a.forkConfig)
_, st, err := restutil.GetSummaryAndState(revision, a.repo, a.bft, a.stater, a.forkConfig)
if err != nil {
if a.repo.IsNotFound(err) {
return utils.BadRequest(errors.WithMessage(err, "revision"))
return restutil.BadRequest(errors.WithMessage(err, "revision"))
}
return err
}
Expand All @@ -168,30 +168,30 @@ func (a *Accounts) handleGetStorage(w http.ResponseWriter, req *http.Request) er
if err != nil {
return err
}
return utils.WriteJSON(w, &api.GetStorageResult{Value: storage.String()})
return restutil.WriteJSON(w, &api.GetStorageResult{Value: storage.String()})
}

func (a *Accounts) handleCallContract(w http.ResponseWriter, req *http.Request) error {
callData := &api.CallData{}
if err := utils.ParseJSON(req.Body, &callData); err != nil {
return utils.BadRequest(errors.WithMessage(err, "body"))
if err := restutil.ParseJSON(req.Body, &callData); err != nil {
return restutil.BadRequest(errors.WithMessage(err, "body"))
}
revision, err := utils.ParseRevision(req.URL.Query().Get("revision"), true)
revision, err := restutil.ParseRevision(req.URL.Query().Get("revision"), true)
if err != nil {
return utils.BadRequest(errors.WithMessage(err, "revision"))
return restutil.BadRequest(errors.WithMessage(err, "revision"))
}
summary, st, err := utils.GetSummaryAndState(revision, a.repo, a.bft, a.stater, a.forkConfig)
summary, st, err := restutil.GetSummaryAndState(revision, a.repo, a.bft, a.stater, a.forkConfig)
if err != nil {
if a.repo.IsNotFound(err) {
return utils.BadRequest(errors.WithMessage(err, "revision"))
return restutil.BadRequest(errors.WithMessage(err, "revision"))
}
return err
}
var addr *thor.Address
if mux.Vars(req)["address"] != "" {
address, err := thor.ParseAddress(mux.Vars(req)["address"])
if err != nil {
return utils.BadRequest(errors.WithMessage(err, "address"))
return restutil.BadRequest(errors.WithMessage(err, "address"))
}
addr = &address
}
Expand All @@ -211,36 +211,36 @@ func (a *Accounts) handleCallContract(w http.ResponseWriter, req *http.Request)
if err != nil {
return err
}
return utils.WriteJSON(w, results[0])
return restutil.WriteJSON(w, results[0])
}

func (a *Accounts) handleCallBatchCode(w http.ResponseWriter, req *http.Request) error {
var batchCallData api.BatchCallData
if err := utils.ParseJSON(req.Body, &batchCallData); err != nil {
return utils.BadRequest(errors.WithMessage(err, "body"))
if err := restutil.ParseJSON(req.Body, &batchCallData); err != nil {
return restutil.BadRequest(errors.WithMessage(err, "body"))
}
// reject null element in clauses, {} will be unmarshaled to default value and will be accepted/handled by the runtime
for i, clause := range batchCallData.Clauses {
if clause == nil {
return utils.BadRequest(fmt.Errorf("clauses[%d]: null not allowed", i))
return restutil.BadRequest(fmt.Errorf("clauses[%d]: null not allowed", i))
}
}
revision, err := utils.ParseRevision(req.URL.Query().Get("revision"), true)
revision, err := restutil.ParseRevision(req.URL.Query().Get("revision"), true)
if err != nil {
return utils.BadRequest(errors.WithMessage(err, "revision"))
return restutil.BadRequest(errors.WithMessage(err, "revision"))
}
summary, st, err := utils.GetSummaryAndState(revision, a.repo, a.bft, a.stater, a.forkConfig)
summary, st, err := restutil.GetSummaryAndState(revision, a.repo, a.bft, a.stater, a.forkConfig)
if err != nil {
if a.repo.IsNotFound(err) {
return utils.BadRequest(errors.WithMessage(err, "revision"))
return restutil.BadRequest(errors.WithMessage(err, "revision"))
}
return err
}
results, err := a.batchCall(req.Context(), &batchCallData, summary.Header, st)
if err != nil {
return err
}
return utils.WriteJSON(w, results)
return restutil.WriteJSON(w, results)
}

func (a *Accounts) batchCall(
Expand Down Expand Up @@ -299,7 +299,7 @@ func (a *Accounts) batchCall(

func (a *Accounts) handleBatchCallData(batchCallData *api.BatchCallData) (txCtx *xenv.TransactionContext, gas uint64, clauses []*tx.Clause, err error) {
if batchCallData.Gas > a.callGasLimit {
return nil, 0, nil, utils.Forbidden(errors.New("gas: exceeds limit"))
return nil, 0, nil, restutil.Forbidden(errors.New("gas: exceeds limit"))
} else if batchCallData.Gas == 0 {
gas = a.callGasLimit
} else {
Expand Down Expand Up @@ -357,7 +357,7 @@ func (a *Accounts) handleBatchCallData(batchCallData *api.BatchCallData) (txCtx
if c.Data != "" {
data, err = hexutil.Decode(c.Data)
if err != nil {
err = utils.BadRequest(errors.WithMessage(err, fmt.Sprintf("data[%d]", i)))
err = restutil.BadRequest(errors.WithMessage(err, fmt.Sprintf("data[%d]", i)))
return
}
}
Expand All @@ -372,31 +372,31 @@ func (a *Accounts) Mount(root *mux.Router, pathPrefix string) {
sub.Path("/*").
Methods(http.MethodPost).
Name("POST /accounts/*").
HandlerFunc(utils.WrapHandlerFunc(a.handleCallBatchCode))
HandlerFunc(restutil.WrapHandlerFunc(a.handleCallBatchCode))
sub.Path("/{address}").
Methods(http.MethodGet).
Name("GET /accounts/{address}").
HandlerFunc(utils.WrapHandlerFunc(a.handleGetAccount))
HandlerFunc(restutil.WrapHandlerFunc(a.handleGetAccount))
sub.Path("/{address}/code").
Methods(http.MethodGet).
Name("GET /accounts/{address}/code").
HandlerFunc(utils.WrapHandlerFunc(a.handleGetCode))
HandlerFunc(restutil.WrapHandlerFunc(a.handleGetCode))
sub.Path("/{address}/storage/{key}").
Methods("GET").
Name("GET /accounts/{address}/storage").
HandlerFunc(utils.WrapHandlerFunc(a.handleGetStorage))
HandlerFunc(restutil.WrapHandlerFunc(a.handleGetStorage))

// These two methods are currently deprecated
callContractHandler := utils.HandleGone
callContractHandler := restutil.HandleGone
if a.enabledDeprecated {
callContractHandler = a.handleCallContract
}
sub.Path("").
Methods(http.MethodPost).
Name("POST /accounts").
HandlerFunc(utils.WrapHandlerFunc(callContractHandler))
HandlerFunc(restutil.WrapHandlerFunc(callContractHandler))
sub.Path("/{address}").
Methods(http.MethodPost).
Name("POST /accounts/{address}").
HandlerFunc(utils.WrapHandlerFunc(callContractHandler))
HandlerFunc(restutil.WrapHandlerFunc(callContractHandler))
}
4 changes: 2 additions & 2 deletions api/accounts/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"github.com/vechain/thor/v2/test/testchain"
"github.com/vechain/thor/v2/thor"
"github.com/vechain/thor/v2/thorclient"
"github.com/vechain/thor/v2/thorclient/httpclient"
"github.com/vechain/thor/v2/tx"

ABI "github.com/vechain/thor/v2/abi"
tccommon "github.com/vechain/thor/v2/thorclient/common"
)

// pragma solidity ^0.4.18;
Expand Down Expand Up @@ -199,7 +199,7 @@ func getAccountWithFinalizedRevision(t *testing.T) {
genesisAccount, err := tclient.Account(&soloAddress, thorclient.Revision(genesisBlock.Header().ID().String()))
require.NoError(t, err)

finalizedAccount, err := tclient.Account(&soloAddress, thorclient.Revision(tccommon.FinalizedRevision))
finalizedAccount, err := tclient.Account(&soloAddress, thorclient.Revision(httpclient.FinalizedRevision))
require.NoError(t, err)

genesisEnergy := (*big.Int)(genesisAccount.Energy)
Expand Down
Loading
Loading