Skip to content

Commit

Permalink
Reuse org-wide linter (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-khimov authored Sep 10, 2024
2 parents 8e5cf96 + b169956 commit db6dbb9
Show file tree
Hide file tree
Showing 35 changed files with 52 additions and 73 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/config/.golangci.yml

This file was deleted.

13 changes: 1 addition & 12 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,7 @@ on:
jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: latest
args: --config=.github/workflows/config/.golangci.yml
uses: nspcc-dev/.github/.github/workflows/go-linter.yml@master

tests:
name: Tests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ bindings_config.yml
/vendor/
.idea
/bin/
.golangci.yml

# debhelpers
**/.debhelper
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,10 @@ debclean:

fmt:
@gofmt -l -w -s $$(find . -type f -name '*.go'| grep -v "/vendor/")

.golangci.yml:
wget -O $@ https://github.com/nspcc-dev/.github/raw/master/.golangci.yml

# Lint Go code
lint: .golangci.yml
golangci-lint run
2 changes: 1 addition & 1 deletion cmd/dump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {

err := os.MkdirAll(rootDir, 0700)
if err != nil {
log.Fatal(fmt.Errorf("create root dir: %v", err))
log.Fatal(fmt.Errorf("create root dir: %w", err))
}

err = _dump(*neoRPCEndpoint, rootDir, *chainLabel)
Expand Down
3 changes: 1 addition & 2 deletions common/ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ const irListMethod = "innerRingList"
// InnerRingInvoker returns the public key of the inner ring node that has invoked the contract.
// Work around for environments without notary support.
func InnerRingInvoker(ir []interop.PublicKey) interop.PublicKey {
for i := 0; i < len(ir); i++ {
node := ir[i]
for _, node := range ir {
if runtime.CheckWitness(node) {
return node
}
Expand Down
2 changes: 1 addition & 1 deletion common/nns.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func ResolveFSContractWithNNS(nns interop.Hash160, contractName string) interop.
}
if len(records[0]) == 2*interop.Hash160Len {
var h = make([]byte, interop.Hash160Len)
for i := 0; i < interop.Hash160Len; i++ {
for i := 0; i < interop.Hash160Len; i++ { //nolint:intrange // Not supported by NeoGo
ii := (interop.Hash160Len - i - 1) * 2
h[i] = byte(std.Atoi(records[0][ii:ii+2], 16))
}
Expand Down
11 changes: 3 additions & 8 deletions common/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ func Vote(ctx storage.Context, id, from []byte) int {
blockHeight = ledger.CurrentIndex()
)

for i := 0; i < len(candidates); i++ {
cnd := candidates[i]

for _, cnd := range candidates {
if blockHeight-cnd.Height > blockDiff {
continue
}
Expand Down Expand Up @@ -84,8 +82,7 @@ func RemoveVotes(ctx storage.Context, id []byte) {
index int
)

for i := 0; i < len(candidates); i++ {
cnd := candidates[i]
for i, cnd := range candidates {
if bytesEqual(cnd.ID, id) {
index = i
break
Expand All @@ -103,9 +100,7 @@ func TryPurgeVotes(ctx storage.Context) bool {
candidates = getBallots(ctx)
blockHeight = ledger.CurrentIndex()
)
for i := 0; i < len(candidates); i++ {
cnd := candidates[i]

for _, cnd := range candidates {
if blockHeight-cnd.Height <= blockDiff {
return false
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/alphabet/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func switchToNotary(ctx storage.Context, args []any) {
ledger.CurrentIndex() + lockInterval, // till
}

for i := 0; i < len(innerRingNodes); i++ {
for i := range innerRingNodes {
addr := contract.CreateStandardAccount(innerRingNodes[i])
if !gas.Transfer(currentContract, addr, perNodeGASSimple, nil) {
panic("failed to transfer part of GAS to the Inner Ring node")
Expand All @@ -175,7 +175,7 @@ func switchToNotary(ctx storage.Context, args []any) {
}
}

for i := 0; i < len(storageNodes); i++ {
for i := range storageNodes {
publicKey := storageNodes[i].blob[2:35] // hardcoded because there was no other way
addr := contract.CreateStandardAccount(publicKey)
if !gas.Transfer(currentContract, addr, perNodeGASSimple, nil) {
Expand Down
Binary file modified contracts/alphabet/contract.nef
Binary file not shown.
2 changes: 1 addition & 1 deletion contracts/alphabet/manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"NeoFS Alphabet","abi":{"methods":[{"name":"_initialize","offset":0,"parameters":[],"returntype":"Void","safe":false},{"name":"_deploy","offset":35,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"emit","offset":2846,"parameters":[],"returntype":"Void","safe":false},{"name":"gas","offset":2667,"parameters":[],"returntype":"Integer","safe":true},{"name":"name","offset":3477,"parameters":[],"returntype":"String","safe":true},{"name":"neo","offset":2681,"parameters":[],"returntype":"Integer","safe":true},{"name":"onNEP17Payment","offset":1163,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"update","offset":2535,"parameters":[{"name":"script","type":"ByteArray"},{"name":"manifest","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"verify","offset":3497,"parameters":[],"returntype":"Boolean","safe":true},{"name":"version","offset":3493,"parameters":[],"returntype":"Integer","safe":true},{"name":"vote","offset":3305,"parameters":[{"name":"epoch","type":"Integer"},{"name":"candidates","type":"Array"}],"returntype":"Void","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":["update","transfer","vote"]}],"supportedstandards":[],"trusts":[],"extra":null}
{"name":"NeoFS Alphabet","abi":{"methods":[{"name":"_initialize","offset":0,"parameters":[],"returntype":"Void","safe":false},{"name":"_deploy","offset":35,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"emit","offset":2827,"parameters":[],"returntype":"Void","safe":false},{"name":"gas","offset":2648,"parameters":[],"returntype":"Integer","safe":true},{"name":"name","offset":3458,"parameters":[],"returntype":"String","safe":true},{"name":"neo","offset":2662,"parameters":[],"returntype":"Integer","safe":true},{"name":"onNEP17Payment","offset":1160,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"update","offset":2516,"parameters":[{"name":"script","type":"ByteArray"},{"name":"manifest","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"verify","offset":3478,"parameters":[],"returntype":"Boolean","safe":true},{"name":"version","offset":3474,"parameters":[],"returntype":"Integer","safe":true},{"name":"vote","offset":3286,"parameters":[{"name":"epoch","type":"Integer"},{"name":"candidates","type":"Array"}],"returntype":"Void","safe":false}],"events":[]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":["update","transfer","vote"]}],"supportedstandards":[],"trusts":[],"extra":null}
2 changes: 1 addition & 1 deletion contracts/audit/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type (
// epoch and container ID since we iterate over these values. But we can shrink
// public key by using first bytes of the hashed value.

// V2 format
// V2 format.
const maxKeySize = 24 // 24 + 32 (container ID length) + 8 (epoch length) = 64

func (a AuditHeader) ID() []byte {
Expand Down
Binary file modified contracts/balance/contract.nef
Binary file not shown.
2 changes: 1 addition & 1 deletion contracts/balance/manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"NeoFS Balance","abi":{"methods":[{"name":"_initialize","offset":0,"parameters":[],"returntype":"Void","safe":false},{"name":"_deploy","offset":93,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"balanceOf","offset":1549,"parameters":[{"name":"account","type":"Hash160"}],"returntype":"Integer","safe":true},{"name":"burn","offset":2101,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"txDetails","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"decimals","offset":1527,"parameters":[],"returntype":"Integer","safe":true},{"name":"lock","offset":1695,"parameters":[{"name":"txDetails","type":"ByteArray"},{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"until","type":"Integer"}],"returntype":"Void","safe":false},{"name":"mint","offset":1980,"parameters":[{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"txDetails","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"newEpoch","offset":1850,"parameters":[{"name":"epochNum","type":"Integer"}],"returntype":"Void","safe":false},{"name":"symbol","offset":1523,"parameters":[],"returntype":"String","safe":true},{"name":"totalSupply","offset":1531,"parameters":[],"returntype":"Integer","safe":true},{"name":"transfer","offset":1568,"parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Boolean","safe":false},{"name":"transferX","offset":1592,"parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"details","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"update","offset":1392,"parameters":[{"name":"script","type":"ByteArray"},{"name":"manifest","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"version","offset":2252,"parameters":[],"returntype":"Integer","safe":true}],"events":[{"name":"Lock","parameters":[{"name":"txID","type":"ByteArray"},{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"until","type":"Integer"}]},{"name":"Transfer","parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"}]},{"name":"TransferX","parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"details","type":"ByteArray"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":["update","subscribeForNewEpoch"]}],"supportedstandards":["NEP-17"],"trusts":[],"extra":null}
{"name":"NeoFS Balance","abi":{"methods":[{"name":"_initialize","offset":0,"parameters":[],"returntype":"Void","safe":false},{"name":"_deploy","offset":93,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"balanceOf","offset":1546,"parameters":[{"name":"account","type":"Hash160"}],"returntype":"Integer","safe":true},{"name":"burn","offset":2098,"parameters":[{"name":"from","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"txDetails","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"decimals","offset":1524,"parameters":[],"returntype":"Integer","safe":true},{"name":"lock","offset":1692,"parameters":[{"name":"txDetails","type":"ByteArray"},{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"until","type":"Integer"}],"returntype":"Void","safe":false},{"name":"mint","offset":1977,"parameters":[{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"txDetails","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"newEpoch","offset":1847,"parameters":[{"name":"epochNum","type":"Integer"}],"returntype":"Void","safe":false},{"name":"symbol","offset":1520,"parameters":[],"returntype":"String","safe":true},{"name":"totalSupply","offset":1528,"parameters":[],"returntype":"Integer","safe":true},{"name":"transfer","offset":1565,"parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Boolean","safe":false},{"name":"transferX","offset":1589,"parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"details","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"update","offset":1389,"parameters":[{"name":"script","type":"ByteArray"},{"name":"manifest","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"version","offset":2249,"parameters":[],"returntype":"Integer","safe":true}],"events":[{"name":"Lock","parameters":[{"name":"txID","type":"ByteArray"},{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"until","type":"Integer"}]},{"name":"Transfer","parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"}]},{"name":"TransferX","parameters":[{"name":"from","type":"Hash160"},{"name":"to","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"details","type":"ByteArray"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":["update","subscribeForNewEpoch"]}],"supportedstandards":["NEP-17"],"trusts":[],"extra":null}
7 changes: 3 additions & 4 deletions contracts/container/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const (
// nolint:deadcode,unused
nnsDefaultTLD = "container"

// V2 format
// V2 format.
containerIDSize = interop.Hash256Len // SHA256 size

singleEstimatePrefix = "est"
Expand All @@ -68,7 +68,7 @@ const (
deletedKeyPrefix = 'd'
estimatePostfixSize = 10

// default SOA record field values
// default SOA record field values.
defaultRefresh = 3600 // 1 hour
defaultRetry = 600 // 10 min
defaultExpire = 3600 * 24 * 365 * 10 // 10 years
Expand Down Expand Up @@ -301,8 +301,7 @@ func PutNamed(container []byte, signature interop.Signature,

details := common.ContainerFeeTransferDetails(containerID)

for i := 0; i < len(alphabet); i++ {
node := alphabet[i]
for _, node := range alphabet {
to := contract.CreateStandardAccount(node)

contract.Call(balanceContractAddr, "transferX",
Expand Down
Binary file modified contracts/container/contract.nef
Binary file not shown.
Loading

0 comments on commit db6dbb9

Please sign in to comment.