Merge pull request #3336 from nspcc-dev/go-upd
Add Go 1.22 support, drop Go 1.19 support
This commit is contained in:
commit
49edf9e498
60 changed files with 148 additions and 167 deletions
10
.github/workflows/build.yml
vendored
10
.github/workflows/build.yml
vendored
|
@ -37,7 +37,7 @@ jobs:
|
|||
runs-on: ${{matrix.os.name}}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [{ name: ubuntu-20.04, bin-name: linux }, { name: windows-2022, bin-name: windows }, { name: macos-12, bin-name: darwin }]
|
||||
os: [{ name: ubuntu-22.04, bin-name: linux }, { name: windows-2022, bin-name: windows }, { name: macos-12, bin-name: darwin }]
|
||||
arch: [amd64, arm64]
|
||||
exclude:
|
||||
- os: { name: windows-2022, bin-name: windows }
|
||||
|
@ -53,8 +53,7 @@ jobs:
|
|||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.21'
|
||||
cache: true
|
||||
go-version: '1.22'
|
||||
|
||||
- name: Build CLI
|
||||
run: make build
|
||||
|
@ -80,7 +79,7 @@ jobs:
|
|||
build_image:
|
||||
needs: build_cli
|
||||
name: Build and push docker image
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
@ -136,8 +135,7 @@ jobs:
|
|||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.21'
|
||||
cache: true
|
||||
go-version: '1.22'
|
||||
|
||||
- name: Login to DockerHub
|
||||
if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true') }}
|
||||
|
|
33
.github/workflows/tests.yml
vendored
33
.github/workflows/tests.yml
vendored
|
@ -86,7 +86,7 @@ jobs:
|
|||
|
||||
test_cover:
|
||||
name: Coverage
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
env:
|
||||
CGO_ENABLED: 0
|
||||
|
@ -99,7 +99,7 @@ jobs:
|
|||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.21'
|
||||
go-version: '1.22'
|
||||
cache: true
|
||||
|
||||
- name: Write coverage profile
|
||||
|
@ -117,25 +117,25 @@ jobs:
|
|||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-20.04, windows-2022, macos-12, macos-14]
|
||||
go_versions: [ '1.19', '1.20', '1.21' ]
|
||||
os: [ubuntu-22.04, windows-2022, macos-12, macos-14]
|
||||
go_versions: [ '1.20', '1.21', '1.22' ]
|
||||
exclude:
|
||||
# Only latest Go version for Windows and MacOS.
|
||||
- os: windows-2022
|
||||
go_versions: '1.19'
|
||||
go_versions: '1.20'
|
||||
- os: windows-2022
|
||||
go_versions: '1.20'
|
||||
- os: macos-12
|
||||
go_versions: '1.19'
|
||||
- os: macos-12
|
||||
go_versions: '1.20'
|
||||
- os: macos-14
|
||||
go_versions: '1.19'
|
||||
- os: macos-14
|
||||
go_versions: '1.20'
|
||||
# Exclude latest Go version for Ubuntu as Coverage uses it.
|
||||
- os: ubuntu-20.04
|
||||
go_versions: '1.21'
|
||||
- os: macos-12
|
||||
go_versions: '1.20'
|
||||
- os: macos-12
|
||||
go_versions: '1.21'
|
||||
- os: macos-14
|
||||
go_versions: '1.20'
|
||||
- os: macos-14
|
||||
go_versions: '1.21'
|
||||
# Exclude latest Go version for Ubuntu as Coverage uses it.
|
||||
- os: ubuntu-22.04
|
||||
go_versions: '1.22'
|
||||
fail-fast: false
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
@ -147,7 +147,6 @@ jobs:
|
|||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '${{ matrix.go_versions }}'
|
||||
cache: true
|
||||
|
||||
- name: Run tests
|
||||
run: go test -v -race ./...
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Builder image
|
||||
# Keep go version in sync with Build GA job.
|
||||
FROM golang:1.21-alpine as builder
|
||||
FROM golang:1.22-alpine as builder
|
||||
|
||||
# Display go version for information purposes.
|
||||
RUN go version
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Builder image
|
||||
# Keep go version in sync with Build GA job.
|
||||
FROM golang:1.21.3-windowsservercore-ltsc2022 as builder
|
||||
FROM golang:1.22.0-windowsservercore-ltsc2022 as builder
|
||||
|
||||
COPY . /neo-go
|
||||
|
||||
|
|
2
Makefile
2
Makefile
|
@ -3,7 +3,7 @@ REPONAME = "neo-go"
|
|||
NETMODE ?= "privnet"
|
||||
BINARY=neo-go
|
||||
BINARY_PATH=./bin/$(BINARY)$(shell go env GOEXE)
|
||||
GO_VERSION ?= 1.19
|
||||
GO_VERSION ?= 1.20
|
||||
DESTDIR = ""
|
||||
SYSCONFIGDIR = "/etc"
|
||||
BINDIR = "/usr/bin"
|
||||
|
|
|
@ -51,7 +51,7 @@ NeoGo, `:latest` points to the latest release) or build yourself.
|
|||
|
||||
### Building
|
||||
|
||||
Building NeoGo requires Go 1.19+ and `make`:
|
||||
Building NeoGo requires Go 1.20+ and `make`:
|
||||
|
||||
```
|
||||
make
|
||||
|
|
|
@ -375,7 +375,7 @@ func initSmartContract(ctx *cli.Context) error {
|
|||
|
||||
gm := []byte("module " + contractName + `
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/nspcc-dev/neo-go/pkg/interop ` + ver + `
|
||||
|
|
|
@ -616,7 +616,7 @@ func getInstructionParameter(c *cli.Context) (int, error) {
|
|||
}
|
||||
n, err := strconv.Atoi(args[0])
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("%w: %s", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return 0, fmt.Errorf("%w: %w", ErrInvalidParameter, err)
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
@ -736,7 +736,7 @@ func handleLoadNEF(c *cli.Context) error {
|
|||
if signersStartOffset != 0 && len(args) > signersStartOffset {
|
||||
signers, err = cmdargs.ParseSigners(c.Args()[signersStartOffset:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: failed to parse signers: %v", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: failed to parse signers: %w", ErrInvalidParameter, err)
|
||||
}
|
||||
}
|
||||
err = prepareVM(c, createFakeTransaction(nef.Script, signers))
|
||||
|
@ -767,7 +767,7 @@ func handleLoadBase64(c *cli.Context) error {
|
|||
}
|
||||
b, err := base64.StdEncoding.DecodeString(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: %w", ErrInvalidParameter, err)
|
||||
}
|
||||
var signers []transaction.Signer
|
||||
if len(args) > 1 {
|
||||
|
@ -779,7 +779,7 @@ func handleLoadBase64(c *cli.Context) error {
|
|||
}
|
||||
signers, err = cmdargs.ParseSigners(args[2:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %v", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: %w", ErrInvalidParameter, err)
|
||||
}
|
||||
}
|
||||
err = prepareVM(c, createFakeTransaction(b, signers))
|
||||
|
@ -807,7 +807,7 @@ func handleLoadHex(c *cli.Context) error {
|
|||
}
|
||||
b, err := hex.DecodeString(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: %w", ErrInvalidParameter, err)
|
||||
}
|
||||
var signers []transaction.Signer
|
||||
if len(args) > 1 {
|
||||
|
@ -819,7 +819,7 @@ func handleLoadHex(c *cli.Context) error {
|
|||
}
|
||||
signers, err = cmdargs.ParseSigners(args[2:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %v", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: %w", ErrInvalidParameter, err)
|
||||
}
|
||||
}
|
||||
err = prepareVM(c, createFakeTransaction(b, signers))
|
||||
|
@ -859,7 +859,7 @@ func handleLoadGo(c *cli.Context) error {
|
|||
}
|
||||
signers, err = cmdargs.ParseSigners(args[2:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %v", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: %w", ErrInvalidParameter, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -962,7 +962,7 @@ func handleLoadDeployed(c *cli.Context) error {
|
|||
}
|
||||
signers, err = cmdargs.ParseSigners(args[2:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %v", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: %w", ErrInvalidParameter, err)
|
||||
}
|
||||
}
|
||||
err = prepareVM(c, createFakeTransaction(cs.NEF.Script, signers)) // prepare VM one more time for proper IC initialization.
|
||||
|
@ -1074,7 +1074,7 @@ func handleRun(c *cli.Context) error {
|
|||
|
||||
_, scParams, err := cmdargs.ParseParams(args[1:], true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %v", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: %w", ErrInvalidParameter, err)
|
||||
}
|
||||
params = make([]stackitem.Item, len(scParams))
|
||||
for i := range scParams {
|
||||
|
@ -1185,7 +1185,7 @@ func handleStep(c *cli.Context) error {
|
|||
if len(args) > 0 {
|
||||
n, err = strconv.Atoi(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrInvalidParameter, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: %w", ErrInvalidParameter, err)
|
||||
}
|
||||
}
|
||||
v.AddBreakPointRel(n)
|
||||
|
|
|
@ -347,7 +347,7 @@ require (
|
|||
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0
|
||||
)
|
||||
replace github.com/nspcc-dev/neo-go/pkg/interop => ` + filepath.Join(wd, "../../pkg/interop") + `
|
||||
go 1.19`)
|
||||
go 1.20`)
|
||||
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "go.mod"), goMod, os.ModePerm))
|
||||
return filename
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package wallet
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/elliptic"
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -36,27 +36,27 @@ func TestParseMultisigContract(t *testing.T) {
|
|||
testParseMultisigContract(t, s, 1, pub)
|
||||
})
|
||||
t.Run("bad, no check multisig", func(t *testing.T) {
|
||||
sBad := slice.Copy(s)
|
||||
sBad := bytes.Clone(s)
|
||||
sBad[len(sBad)-1] ^= 0xFF
|
||||
testParseMultisigContract(t, sBad, 0)
|
||||
})
|
||||
t.Run("bad, invalid number of keys", func(t *testing.T) {
|
||||
sBad := slice.Copy(s)
|
||||
sBad := bytes.Clone(s)
|
||||
sBad[len(sBad)-2] = opPush1 + 1
|
||||
testParseMultisigContract(t, sBad, 0)
|
||||
})
|
||||
t.Run("bad, invalid first instruction", func(t *testing.T) {
|
||||
sBad := slice.Copy(s)
|
||||
sBad := bytes.Clone(s)
|
||||
sBad[0] = 0xFF
|
||||
testParseMultisigContract(t, sBad, 0)
|
||||
})
|
||||
t.Run("bad, invalid public key", func(t *testing.T) {
|
||||
sBad := slice.Copy(s)
|
||||
sBad := bytes.Clone(s)
|
||||
sBad[2] = 0xFF
|
||||
testParseMultisigContract(t, sBad, 0)
|
||||
})
|
||||
t.Run("bad, many sigs", func(t *testing.T) {
|
||||
sBad := slice.Copy(s)
|
||||
sBad := bytes.Clone(s)
|
||||
sBad[0] = opPush1 + 1
|
||||
testParseMultisigContract(t, sBad, 0)
|
||||
})
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module github.com/nspcc-dev/neo-go/examples/engine
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module github.com/nspcc-dev/neo-go/examples/events
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module github.com/nspcc-dev/neo-go/examples/iterator
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module github.com/nspcc-dev/neo-go/examples/nft
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module github.com/nspcc-dev/neo-go/examples/nft-nd-nns
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/nspcc-dev/neo-go v0.102.1-0.20231020181554-d89c8801d689
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module github.com/nspcc-dev/neo-go/examples/nft-nd
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module github.com/nspcc-dev/neo-go/examples/oracle
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module github.com/nspcc-dev/neo-go/examples/runtime
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module github.com/nspcc-dev/neo-go/examples/storage
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module github.com/nspcc-dev/neo-go/examples/timer
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module github.com/nspcc-dev/neo-go/examples/token
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module github.com/nspcc-dev/neo-go/examples/zkp/cubic
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/consensys/gnark v0.9.1
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module github.com/nspcc-dev/neo-go/examples/zkp/xor
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0
|
||||
|
|
2
go.mod
2
go.mod
|
@ -1,6 +1,6 @@
|
|||
module github.com/nspcc-dev/neo-go
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/chzyer/readline v1.5.1
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module github.com/nspcc-dev/neo-go/internal/examples/oracle
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0
|
||||
|
|
|
@ -50,5 +50,6 @@ func Uint160() util.Uint160 {
|
|||
}
|
||||
|
||||
func init() {
|
||||
//nolint:staticcheck
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
||||
|
@ -1172,7 +1171,7 @@ func (bc *Blockchain) resetTransfers(cache *dao.Simple, height uint32) error {
|
|||
trInfo = nil
|
||||
removeFollowing = false
|
||||
} else if removeFollowing {
|
||||
cache.Store.Delete(slice.Copy(k))
|
||||
cache.Store.Delete(bytes.Clone(k))
|
||||
return seekErr == nil
|
||||
}
|
||||
|
||||
|
@ -2511,7 +2510,7 @@ func (bc *Blockchain) verifyAndPoolTx(t *transaction.Transaction, pool *mempool.
|
|||
// really require a chain lock.
|
||||
err := vm.IsScriptCorrect(t.Script, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %v", ErrInvalidScript, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: %w", ErrInvalidScript, err)
|
||||
}
|
||||
|
||||
height := bc.BlockHeight()
|
||||
|
@ -2522,7 +2521,7 @@ func (bc *Blockchain) verifyAndPoolTx(t *transaction.Transaction, pool *mempool.
|
|||
// Policying.
|
||||
if err := bc.contracts.Policy.CheckPolicy(bc.dao, t); err != nil {
|
||||
// Only one %w can be used.
|
||||
return fmt.Errorf("%w: %v", ErrPolicy, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: %w", ErrPolicy, err)
|
||||
}
|
||||
if t.SystemFee > bc.config.MaxBlockSystemFee {
|
||||
return fmt.Errorf("%w: too big system fee (%d > MaxBlockSystemFee %d)", ErrPolicy, t.SystemFee, bc.config.MaxBlockSystemFee)
|
||||
|
@ -2566,7 +2565,7 @@ func (bc *Blockchain) verifyAndPoolTx(t *transaction.Transaction, pool *mempool.
|
|||
case errors.Is(err, mempool.ErrOOM):
|
||||
return ErrOOM
|
||||
case errors.Is(err, mempool.ErrConflictsAttribute):
|
||||
return fmt.Errorf("mempool: %w: %s", ErrHasConflicts, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("mempool: %w: %w", ErrHasConflicts, err)
|
||||
default:
|
||||
return err
|
||||
}
|
||||
|
@ -2607,7 +2606,7 @@ func (bc *Blockchain) verifyTxAttributes(d *dao.Simple, tx *transaction.Transact
|
|||
case transaction.OracleResponseT:
|
||||
h, err := bc.contracts.Oracle.GetScriptHash(bc.dao)
|
||||
if err != nil || h.Equals(util.Uint160{}) {
|
||||
return fmt.Errorf("%w: %v", ErrInvalidAttribute, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: %w", ErrInvalidAttribute, err)
|
||||
}
|
||||
hasOracle := false
|
||||
for i := range tx.Signers {
|
||||
|
@ -2627,7 +2626,7 @@ func (bc *Blockchain) verifyTxAttributes(d *dao.Simple, tx *transaction.Transact
|
|||
resp := tx.Attributes[i].Value.(*transaction.OracleResponse)
|
||||
req, err := bc.contracts.Oracle.GetRequestInternal(bc.dao, resp.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: oracle tx points to invalid request: %v", ErrInvalidAttribute, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: oracle tx points to invalid request: %w", ErrInvalidAttribute, err)
|
||||
}
|
||||
if uint64(tx.NetworkFee+tx.SystemFee) < req.GasForResponse {
|
||||
return fmt.Errorf("%w: oracle tx has insufficient gas", ErrInvalidAttribute)
|
||||
|
@ -2638,7 +2637,7 @@ func (bc *Blockchain) verifyTxAttributes(d *dao.Simple, tx *transaction.Transact
|
|||
if isPartialTx {
|
||||
maxNVBDelta, err := bc.GetMaxNotValidBeforeDelta()
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: failed to retrieve MaxNotValidBeforeDelta value from native Notary contract: %v", ErrInvalidAttribute, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: failed to retrieve MaxNotValidBeforeDelta value from native Notary contract: %w", ErrInvalidAttribute, err)
|
||||
}
|
||||
if curHeight+maxNVBDelta < nvb {
|
||||
return fmt.Errorf("%w: NotValidBefore (%d) bigger than MaxNVBDelta (%d) allows at height %d", ErrInvalidAttribute, nvb, maxNVBDelta, curHeight)
|
||||
|
@ -2873,7 +2872,7 @@ func (bc *Blockchain) InitVerificationContext(ic *interop.Context, hash util.Uin
|
|||
}
|
||||
err := vm.IsScriptCorrect(witness.VerificationScript, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %v", ErrInvalidVerificationScript, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: %w", ErrInvalidVerificationScript, err)
|
||||
}
|
||||
ic.VM.LoadScriptWithHash(witness.VerificationScript, hash, callflag.ReadOnly)
|
||||
} else {
|
||||
|
@ -2898,7 +2897,7 @@ func (bc *Blockchain) InitVerificationContext(ic *interop.Context, hash util.Uin
|
|||
if len(witness.InvocationScript) != 0 {
|
||||
err := vm.IsScriptCorrect(witness.InvocationScript, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %v", ErrInvalidInvocationScript, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: %w", ErrInvalidInvocationScript, err)
|
||||
}
|
||||
ic.VM.LoadScript(witness.InvocationScript)
|
||||
}
|
||||
|
@ -2930,7 +2929,7 @@ func (bc *Blockchain) verifyHashAgainstScript(hash util.Uint160, witness *transa
|
|||
}
|
||||
err := interopCtx.Exec()
|
||||
if vm.HasFailed() {
|
||||
return 0, fmt.Errorf("%w: vm execution has failed: %v", ErrVerificationFailed, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return 0, fmt.Errorf("%w: vm execution has failed: %w", ErrVerificationFailed, err)
|
||||
}
|
||||
estack := vm.Estack()
|
||||
if estack.Len() > 0 {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
@ -17,7 +18,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -175,9 +175,9 @@ func TestBlockchain_InitWithIncompleteStateJump(t *testing.T) {
|
|||
bPrefix := make([]byte, 1)
|
||||
bPrefix[0] = byte(bcSpout.dao.Version.StoragePrefix)
|
||||
bcSpout.dao.Store.Seek(storage.SeekRange{Prefix: bPrefix}, func(k, v []byte) bool {
|
||||
key := slice.Copy(k)
|
||||
key := bytes.Clone(k)
|
||||
key[0] = byte(tempPrefix)
|
||||
value := slice.Copy(v)
|
||||
value := bytes.Clone(v)
|
||||
batch.Put(key, value)
|
||||
return true
|
||||
})
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package dao
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
|
@ -19,7 +20,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
)
|
||||
|
||||
|
@ -383,7 +383,7 @@ func (dao *Simple) DeleteStorageItem(id int32, key []byte) {
|
|||
// may not be copied. Seek continues iterating until false is returned from f. A requested prefix
|
||||
// (if any non-empty) is trimmed before passing to f.
|
||||
func (dao *Simple) Seek(id int32, rng storage.SeekRange, f func(k, v []byte) bool) {
|
||||
rng.Prefix = slice.Copy(dao.makeStorageItemKey(id, rng.Prefix)) // f() can use dao too.
|
||||
rng.Prefix = bytes.Clone(dao.makeStorageItemKey(id, rng.Prefix)) // f() can use dao too.
|
||||
dao.Store.Seek(rng, func(k, v []byte) bool {
|
||||
return f(k[len(rng.Prefix):], v)
|
||||
})
|
||||
|
@ -393,7 +393,7 @@ func (dao *Simple) Seek(id int32, rng storage.SeekRange, f func(k, v []byte) boo
|
|||
// starting from the point specified) to a channel and returns the channel.
|
||||
// Resulting keys and values may not be copied.
|
||||
func (dao *Simple) SeekAsync(ctx context.Context, id int32, rng storage.SeekRange) chan storage.KeyValue {
|
||||
rng.Prefix = slice.Copy(dao.makeStorageItemKey(id, rng.Prefix))
|
||||
rng.Prefix = bytes.Clone(dao.makeStorageItemKey(id, rng.Prefix))
|
||||
return dao.Store.SeekAsync(ctx, rng, true)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package contract_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"math"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
@ -15,7 +16,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -136,13 +136,13 @@ func TestCreateAccount_HFAspidochelone(t *testing.T) {
|
|||
emit.Int(w.BinWriter, int64(2))
|
||||
emit.Syscall(w.BinWriter, interopnames.SystemContractCreateMultisigAccount)
|
||||
require.NoError(t, w.Err)
|
||||
multisigScript := slice.Copy(w.Bytes())
|
||||
multisigScript := bytes.Clone(w.Bytes())
|
||||
|
||||
w.Reset()
|
||||
emit.Bytes(w.BinWriter, pub.Bytes())
|
||||
emit.Syscall(w.BinWriter, interopnames.SystemContractCreateStandardAccount)
|
||||
require.NoError(t, w.Err)
|
||||
standardScript := slice.Copy(w.Bytes())
|
||||
standardScript := bytes.Clone(w.Bytes())
|
||||
|
||||
createAccTx := func(t *testing.T, script []byte) *transaction.Transaction {
|
||||
tx := e.PrepareInvocation(t, script, []neotest.Signer{e.Committee}, bc.BlockHeight()+1)
|
||||
|
|
|
@ -165,7 +165,7 @@ func CallFromNative(ic *interop.Context, caller util.Uint160, cs *state.Contract
|
|||
|
||||
for !ic.VM.HasStopped() && len(ic.VM.Istack()) > startSize {
|
||||
if err := ic.VM.Step(); err != nil {
|
||||
return fmt.Errorf("%w: %v", ErrNativeCall, err) //nolint:errorlint // non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: %w", ErrNativeCall, err)
|
||||
}
|
||||
}
|
||||
if ic.VM.HasFailed() {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
)
|
||||
|
||||
|
@ -31,6 +31,9 @@ type Iterator struct {
|
|||
curr storage.KeyValue
|
||||
next bool
|
||||
opts int64
|
||||
// prefix is the storage item key prefix Find is performed with. It must be
|
||||
// copied if no FindRemovePrefix option specified since it's shared between all
|
||||
// iterator items.
|
||||
prefix []byte
|
||||
}
|
||||
|
||||
|
@ -39,7 +42,7 @@ func NewIterator(seekCh chan storage.KeyValue, prefix []byte, opts int64) *Itera
|
|||
return &Iterator{
|
||||
seekCh: seekCh,
|
||||
opts: opts,
|
||||
prefix: slice.Copy(prefix),
|
||||
prefix: bytes.Clone(prefix),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +61,7 @@ func (s *Iterator) Value() stackitem.Item {
|
|||
}
|
||||
key := s.curr.Key
|
||||
if s.opts&FindRemovePrefix == 0 {
|
||||
key = append(s.prefix, key...)
|
||||
key = append(bytes.Clone(s.prefix), key...)
|
||||
}
|
||||
if s.opts&FindKeysOnly != 0 {
|
||||
return stackitem.NewByteArray(key)
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -230,7 +229,7 @@ func (b *Billet) traverse(curr Node, path, from []byte, process func(pathToNode
|
|||
return b.traverse(r, path, from, process, ignoreStorageErr, backwards)
|
||||
}
|
||||
if len(from) == 0 {
|
||||
bytes := slice.Copy(curr.Bytes())
|
||||
bytes := bytes.Clone(curr.Bytes())
|
||||
if process(fromNibbles(path), curr, bytes) {
|
||||
return curr, errStop
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
)
|
||||
|
||||
// GetProof returns a proof that the key belongs to t.
|
||||
|
@ -30,11 +29,11 @@ func (t *Trie) getProof(curr Node, path []byte, proofs *[][]byte) (Node, error)
|
|||
switch n := curr.(type) {
|
||||
case *LeafNode:
|
||||
if len(path) == 0 {
|
||||
*proofs = append(*proofs, slice.Copy(n.Bytes()))
|
||||
*proofs = append(*proofs, bytes.Clone(n.Bytes()))
|
||||
return n, nil
|
||||
}
|
||||
case *BranchNode:
|
||||
*proofs = append(*proofs, slice.Copy(n.Bytes()))
|
||||
*proofs = append(*proofs, bytes.Clone(n.Bytes()))
|
||||
i, path := splitPath(path)
|
||||
r, err := t.getProof(n.Children[i], path, proofs)
|
||||
if err != nil {
|
||||
|
@ -44,7 +43,7 @@ func (t *Trie) getProof(curr Node, path []byte, proofs *[][]byte) (Node, error)
|
|||
return n, nil
|
||||
case *ExtensionNode:
|
||||
if bytes.HasPrefix(path, n.key) {
|
||||
*proofs = append(*proofs, slice.Copy(n.Bytes()))
|
||||
*proofs = append(*proofs, bytes.Clone(n.Bytes()))
|
||||
r, err := t.getProof(n.next, path[len(n.key):], proofs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -75,5 +74,5 @@ func VerifyProof(rh util.Uint256, key []byte, proofs [][]byte) ([]byte, bool) {
|
|||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
return slice.Copy(leaf.(*LeafNode).value), true
|
||||
return bytes.Clone(leaf.(*LeafNode).value), true
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
)
|
||||
|
||||
// TrieMode is the storage mode of a trie, it affects the DB scheme.
|
||||
|
@ -84,7 +83,7 @@ func (t *Trie) Get(key []byte) ([]byte, error) {
|
|||
return nil, err
|
||||
}
|
||||
t.root = r
|
||||
return slice.Copy(leaf.(*LeafNode).value), nil
|
||||
return bytes.Clone(leaf.(*LeafNode).value), nil
|
||||
}
|
||||
|
||||
// getWithPath returns the current node with all hash nodes along the path replaced
|
||||
|
@ -221,7 +220,7 @@ func (t *Trie) putIntoExtension(curr *ExtensionNode, path []byte, val Node) (Nod
|
|||
|
||||
t.addRef(b.Hash(), b.bytes)
|
||||
if lp > 0 {
|
||||
e := NewExtensionNode(slice.Copy(pref), b)
|
||||
e := NewExtensionNode(bytes.Clone(pref), b)
|
||||
t.addRef(e.Hash(), e.bytes)
|
||||
return e, nil
|
||||
}
|
||||
|
@ -617,8 +616,8 @@ func (t *Trie) Find(prefix, from []byte, max int) ([]storage.KeyValue, error) {
|
|||
if leaf, ok := node.(*LeafNode); ok {
|
||||
if from == nil || !bytes.Equal(pathToNode, from) { // (*Billet).traverse includes `from` path into result if so. Need to filter out manually.
|
||||
res = append(res, storage.KeyValue{
|
||||
Key: append(slice.Copy(prefix), pathToNode...),
|
||||
Value: slice.Copy(leaf.value),
|
||||
Key: append(bytes.Clone(prefix), pathToNode...),
|
||||
Value: bytes.Clone(leaf.value),
|
||||
})
|
||||
count++
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
)
|
||||
|
||||
// TrieStore is an MPT-based storage implementation for storing and retrieving
|
||||
|
@ -101,8 +100,8 @@ func (m *TrieStore) Seek(rng storage.SeekRange, f func(k, v []byte) bool) {
|
|||
if leaf, ok := node.(*LeafNode); ok {
|
||||
// (*Billet).traverse includes `from` path into the result if so. It's OK for Seek, so shouldn't be filtered out.
|
||||
kv := storage.KeyValue{
|
||||
Key: append(slice.Copy(rng.Prefix), pathToNode...), // Do not cut prefix.
|
||||
Value: slice.Copy(leaf.value),
|
||||
Key: append(bytes.Clone(rng.Prefix), pathToNode...), // Do not cut prefix.
|
||||
Value: bytes.Clone(leaf.value),
|
||||
}
|
||||
return !f(kv.Key, kv.Value) // Should return whether to stop.
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package native
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -25,7 +26,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
)
|
||||
|
||||
|
@ -160,7 +160,7 @@ func newOracle() *Oracle {
|
|||
|
||||
// GetOracleResponseScript returns a script for the transaction with an oracle response.
|
||||
func (o *Oracle) GetOracleResponseScript() []byte {
|
||||
return slice.Copy(o.oracleScript)
|
||||
return bytes.Clone(o.oracleScript)
|
||||
}
|
||||
|
||||
// OnPersist implements the Contract interface.
|
||||
|
@ -395,7 +395,7 @@ func (o *Oracle) RequestInternal(ic *interop.Context, url string, filter *string
|
|||
if len(data) > maxUserDataLength {
|
||||
return ErrBigArgument
|
||||
}
|
||||
data = slice.Copy(data) // Serialization context will be used in PutRequestInternal again.
|
||||
data = bytes.Clone(data) // Serialization context will be used in PutRequestInternal again.
|
||||
|
||||
var filterNotif stackitem.Item
|
||||
if filter != nil {
|
||||
|
|
|
@ -177,7 +177,7 @@ func (s *Std) serialize(ic *interop.Context, args []stackitem.Item) stackitem.It
|
|||
panic(errors.New("too big item"))
|
||||
}
|
||||
|
||||
return stackitem.NewByteArray(slice.Copy(data)) // Serialization context can be reused.
|
||||
return stackitem.NewByteArray(bytes.Clone(data)) // Serialization context can be reused.
|
||||
}
|
||||
|
||||
func (s *Std) deserialize(_ *interop.Context, args []stackitem.Item) stackitem.Item {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package statesync
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
|
@ -8,7 +9,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/core/mpt"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap/zaptest"
|
||||
)
|
||||
|
@ -33,8 +33,8 @@ func TestModule_PR2019_discussion_r689629704(t *testing.T) {
|
|||
expectedItems []storage.KeyValue
|
||||
)
|
||||
expectedStorage.Seek(storage.SeekRange{Prefix: []byte{byte(storage.DataMPT)}}, func(k, v []byte) bool {
|
||||
key := slice.Copy(k)
|
||||
value := slice.Copy(v)
|
||||
key := bytes.Clone(k)
|
||||
value := bytes.Clone(v)
|
||||
expectedItems = append(expectedItems, storage.KeyValue{
|
||||
Key: key,
|
||||
Value: value,
|
||||
|
@ -97,8 +97,8 @@ func TestModule_PR2019_discussion_r689629704(t *testing.T) {
|
|||
// Compare resulting storage items and refcounts.
|
||||
var actualItems []storage.KeyValue
|
||||
expectedStorage.Seek(storage.SeekRange{Prefix: []byte{byte(storage.DataMPT)}}, func(k, v []byte) bool {
|
||||
key := slice.Copy(k)
|
||||
value := slice.Copy(v)
|
||||
key := bytes.Clone(k)
|
||||
value := bytes.Clone(v)
|
||||
actualItems = append(actualItems, storage.KeyValue{
|
||||
Key: key,
|
||||
Value: value,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package statesync_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/internal/basicchain"
|
||||
|
@ -11,7 +12,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
||||
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -230,7 +230,7 @@ func TestStateSyncModule_Init(t *testing.T) {
|
|||
alreadyRequested[unknownHashes[0]] = struct{}{}
|
||||
var callbackCalled bool
|
||||
err := bcSpout.GetStateSyncModule().Traverse(unknownHashes[0], func(node mpt.Node, nodeBytes []byte) bool {
|
||||
require.NoError(t, module.AddMPTNodes([][]byte{slice.Copy(nodeBytes)}))
|
||||
require.NoError(t, module.AddMPTNodes([][]byte{bytes.Clone(nodeBytes)}))
|
||||
callbackCalled = true
|
||||
return true // add nodes one-by-one
|
||||
})
|
||||
|
@ -435,8 +435,8 @@ func TestStateSyncModule_RestoreBasicChain(t *testing.T) {
|
|||
fetchStorage := func(ps storage.Store, storagePrefix byte) []storage.KeyValue {
|
||||
var kv []storage.KeyValue
|
||||
ps.Seek(storage.SeekRange{Prefix: []byte{storagePrefix}}, func(k, v []byte) bool {
|
||||
key := slice.Copy(k)
|
||||
value := slice.Copy(v)
|
||||
key := bytes.Clone(k)
|
||||
value := bytes.Clone(v)
|
||||
if key[0] == byte(storage.STTempStorage) {
|
||||
key[0] = byte(storage.STStorage)
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
|
@ -66,7 +65,7 @@ func NewBoltDBStore(cfg dbconfig.BoltDBOptions) (*BoltDBStore, error) {
|
|||
closeErr := db.Close()
|
||||
err = fmt.Errorf("failed to initialize BoltDB instance: %w", err)
|
||||
if closeErr != nil {
|
||||
err = fmt.Errorf("%w, failed to close BoltDB instance: %v", err, closeErr) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
err = fmt.Errorf("%w, failed to close BoltDB instance: %w", err, closeErr)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
@ -81,7 +80,7 @@ func (s *BoltDBStore) Get(key []byte) (val []byte, err error) {
|
|||
val = b.Get(key)
|
||||
// Value from Get is only valid for the lifetime of transaction, #1482
|
||||
if val != nil {
|
||||
val = slice.Copy(val)
|
||||
val = bytes.Clone(val)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
|
|
@ -6,8 +6,6 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
)
|
||||
|
||||
// MemCachedStore is a wrapper around persistent store that caches all changes
|
||||
|
@ -107,7 +105,7 @@ func (s *MemCachedStore) Get(key []byte) ([]byte, error) {
|
|||
// Put puts new KV pair into the store.
|
||||
func (s *MemCachedStore) Put(key, value []byte) {
|
||||
newKey := string(key)
|
||||
vcopy := slice.Copy(value)
|
||||
vcopy := bytes.Clone(value)
|
||||
s.lock()
|
||||
put(s.chooseMap(key), newKey, vcopy)
|
||||
s.unlock()
|
||||
|
@ -259,8 +257,8 @@ func performSeek(ctx context.Context, ps Store, memRes []KeyValueExists, rng See
|
|||
return false
|
||||
}
|
||||
kvPs := KeyValue{
|
||||
Key: slice.Copy(k),
|
||||
Value: slice.Copy(v),
|
||||
Key: bytes.Clone(k),
|
||||
Value: bytes.Clone(v),
|
||||
}
|
||||
for {
|
||||
select {
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/internal/random"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -420,7 +419,7 @@ func TestCachedSeekSorting(t *testing.T) {
|
|||
}
|
||||
var foundKVs []KeyValue
|
||||
ts.Seek(SeekRange{Prefix: goodPrefix}, func(k, v []byte) bool {
|
||||
foundKVs = append(foundKVs, KeyValue{Key: slice.Copy(k), Value: slice.Copy(v)})
|
||||
foundKVs = append(foundKVs, KeyValue{Key: bytes.Clone(k), Value: bytes.Clone(v)})
|
||||
return true
|
||||
})
|
||||
assert.Equal(t, len(foundKVs), len(lowerKVs)+len(updatedKVs))
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -70,8 +69,8 @@ func testStoreSeek(t *testing.T, s Store) {
|
|||
actual := make([]KeyValue, 0, len(goodkvs))
|
||||
s.Seek(rng, func(k, v []byte) bool {
|
||||
actual = append(actual, KeyValue{
|
||||
Key: slice.Copy(k),
|
||||
Value: slice.Copy(v),
|
||||
Key: bytes.Clone(k),
|
||||
Value: bytes.Clone(v),
|
||||
})
|
||||
if cont == nil {
|
||||
return true
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module github.com/nspcc-dev/neo-go/pkg/interop
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
func FuzzMessageDecode(f *testing.F) {
|
||||
for i := 0; i < 100; i++ {
|
||||
seed := make([]byte, rand.Uint32()%1000)
|
||||
//nolint:staticcheck
|
||||
rand.Read(seed)
|
||||
f.Add(seed)
|
||||
}
|
||||
|
|
|
@ -201,9 +201,9 @@ func (w *PollingBased) WaitAny(ctx context.Context, vub uint32, hashes ...util.U
|
|||
return nil, ErrTxNotAccepted
|
||||
}
|
||||
case <-w.polling.Context().Done():
|
||||
return nil, fmt.Errorf("%w: %v", ErrContextDone, w.polling.Context().Err()) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return nil, fmt.Errorf("%w: %w", ErrContextDone, w.polling.Context().Err())
|
||||
case <-ctx.Done():
|
||||
return nil, fmt.Errorf("%w: %v", ErrContextDone, ctx.Err()) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return nil, fmt.Errorf("%w: %w", ErrContextDone, ctx.Err())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -329,9 +329,9 @@ func (w *EventBased) WaitAny(ctx context.Context, vub uint32, hashes ...util.Uin
|
|||
}
|
||||
res = aer
|
||||
case <-w.ws.Context().Done():
|
||||
waitErr = fmt.Errorf("%w: %v", ErrContextDone, w.ws.Context().Err()) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
waitErr = fmt.Errorf("%w: %w", ErrContextDone, w.ws.Context().Err())
|
||||
case <-ctx.Done():
|
||||
waitErr = fmt.Errorf("%w: %v", ErrContextDone, ctx.Err()) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
waitErr = fmt.Errorf("%w: %w", ErrContextDone, ctx.Err())
|
||||
}
|
||||
}
|
||||
close(exit)
|
||||
|
@ -361,7 +361,7 @@ func (w *EventBased) WaitAny(ctx context.Context, vub uint32, hashes ...util.Uin
|
|||
}
|
||||
case unsubErr := <-unsubErrs:
|
||||
if unsubErr != nil {
|
||||
errFmt := "unsubscription error: %v"
|
||||
errFmt := "unsubscription error: %w"
|
||||
errArgs := []any{unsubErr}
|
||||
if waitErr != nil {
|
||||
errFmt = "%w; " + errFmt
|
||||
|
@ -393,7 +393,7 @@ func (w *EventBased) WaitAny(ctx context.Context, vub uint32, hashes ...util.Uin
|
|||
res, waitErr = w.polling.WaitAny(ctx, vub, hashes...)
|
||||
if waitErr != nil {
|
||||
// Wrap the poll-based error, it's more important.
|
||||
waitErr = fmt.Errorf("event-based error: %v; poll-based waiter error: %w", wsWaitErr, waitErr) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
waitErr = fmt.Errorf("event-based error: %w; poll-based waiter error: %w", wsWaitErr, waitErr)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
|
@ -943,7 +943,7 @@ func (c *WSClient) UnsubscribeAll() error {
|
|||
for _, id := range subs {
|
||||
err := c.performUnsubscription(id)
|
||||
if err != nil {
|
||||
errFmt := "failed to unsubscribe from feed %d: %v"
|
||||
errFmt := "failed to unsubscribe from feed %d: %w"
|
||||
errArgs := []any{err}
|
||||
if resErr != nil {
|
||||
errFmt = "%w; " + errFmt
|
||||
|
|
|
@ -20,7 +20,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||
|
@ -354,8 +353,8 @@ func safeCopy(tx *transaction.Transaction) *transaction.Transaction {
|
|||
cp.Scripts = make([]transaction.Witness, len(tx.Scripts))
|
||||
for i := range cp.Scripts {
|
||||
cp.Scripts[i] = transaction.Witness{
|
||||
InvocationScript: slice.Copy(tx.Scripts[i].InvocationScript),
|
||||
VerificationScript: slice.Copy(tx.Scripts[i].VerificationScript),
|
||||
InvocationScript: bytes.Clone(tx.Scripts[i].InvocationScript),
|
||||
VerificationScript: bytes.Clone(tx.Scripts[i].VerificationScript),
|
||||
}
|
||||
}
|
||||
return &cp
|
||||
|
|
|
@ -109,12 +109,12 @@ func parseNeoFSURL(u *url.URL) (*oid.Address, []string, error) {
|
|||
|
||||
var containerID cid.ID
|
||||
if err := containerID.DecodeString(ps[0]); err != nil {
|
||||
return nil, nil, fmt.Errorf("%w: %v", ErrInvalidContainer, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return nil, nil, fmt.Errorf("%w: %w", ErrInvalidContainer, err)
|
||||
}
|
||||
|
||||
var objectID oid.ID
|
||||
if err := objectID.DecodeString(ps[1]); err != nil {
|
||||
return nil, nil, fmt.Errorf("%w: %v", ErrInvalidObject, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return nil, nil, fmt.Errorf("%w: %w", ErrInvalidObject, err)
|
||||
}
|
||||
var objAddr = new(oid.Address)
|
||||
objAddr.SetContainer(containerID)
|
||||
|
|
|
@ -65,7 +65,7 @@ func getDefaultClient(cfg config.OracleConfiguration) *http.Client {
|
|||
d.Control = func(network, address string, c syscall.RawConn) error {
|
||||
host, _, err := net.SplitHostPort(address)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: failed to split address %s: %s", ErrRestrictedRedirect, address, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: failed to split address %s: %w", ErrRestrictedRedirect, address, err)
|
||||
}
|
||||
ip := net.ParseIP(host)
|
||||
if ip == nil {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package oracle
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
@ -16,7 +17,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/services/oracle/broadcaster"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
@ -277,8 +277,8 @@ drain:
|
|||
|
||||
// UpdateNativeContract updates native oracle contract info for tx verification.
|
||||
func (o *Oracle) UpdateNativeContract(script, resp []byte, h util.Uint160, verifyOffset int) {
|
||||
o.oracleScript = slice.Copy(script)
|
||||
o.oracleResponse = slice.Copy(resp)
|
||||
o.oracleScript = bytes.Clone(script)
|
||||
o.oracleResponse = bytes.Clone(resp)
|
||||
|
||||
o.oracleHash = h
|
||||
o.verifyOffset = verifyOffset
|
||||
|
|
|
@ -30,7 +30,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/services/oracle"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -163,8 +162,8 @@ func TestOracle(t *testing.T) {
|
|||
md := nativeOracleState.Manifest.ABI.GetMethod(manifest.MethodVerify, -1)
|
||||
require.NotNil(t, md)
|
||||
oracleRespScript := native.CreateOracleResponseScript(nativeOracleH)
|
||||
orc1.UpdateNativeContract(nativeOracleState.NEF.Script, slice.Copy(oracleRespScript), nativeOracleH, md.Offset)
|
||||
orc2.UpdateNativeContract(nativeOracleState.NEF.Script, slice.Copy(oracleRespScript), nativeOracleH, md.Offset)
|
||||
orc1.UpdateNativeContract(nativeOracleState.NEF.Script, bytes.Clone(oracleRespScript), nativeOracleH, md.Offset)
|
||||
orc2.UpdateNativeContract(nativeOracleState.NEF.Script, bytes.Clone(oracleRespScript), nativeOracleH, md.Offset)
|
||||
|
||||
cs := contracts.GetOracleContractState(t, pathToInternalContracts, validator.ScriptHash(), 0)
|
||||
rawManifest, err := json.Marshal(cs.Manifest)
|
||||
|
|
|
@ -52,7 +52,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest/standard"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
|
@ -1760,7 +1759,7 @@ func (s *Server) findStorageInternal(id int32, prefix []byte, start, take int, s
|
|||
}
|
||||
if i < end {
|
||||
res.Results = append(res.Results, result.KeyValue{
|
||||
Key: slice.Copy(append(prefix, k...)), // Don't strip prefix, as it is done in C#.
|
||||
Key: bytes.Clone(append(prefix, k...)), // Don't strip prefix, as it is done in C#.
|
||||
Value: v,
|
||||
})
|
||||
i++
|
||||
|
|
|
@ -165,7 +165,7 @@ supportedstandards: []`
|
|||
// and dependency packages version needed for smart contract compilation.
|
||||
verifyGomod = `module verify
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231004150345-8849ccde2524
|
||||
`
|
||||
|
|
|
@ -22,13 +22,6 @@ func reverse(dst []byte, src []byte) {
|
|||
}
|
||||
}
|
||||
|
||||
// Copy copies the byte slice into new slice (make/copy).
|
||||
func Copy(b []byte) []byte {
|
||||
d := make([]byte, len(b))
|
||||
copy(d, b)
|
||||
return d
|
||||
}
|
||||
|
||||
// Clean wipes the data in b by filling it with zeros.
|
||||
func Clean(b []byte) {
|
||||
for i := range b {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package slice
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -30,7 +31,7 @@ var testCases = []struct {
|
|||
|
||||
func TestCopyReverse(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
arg := Copy(tc.arr)
|
||||
arg := bytes.Clone(tc.arr)
|
||||
require.Equal(t, tc.arr, arg)
|
||||
|
||||
have := CopyReverse(arg)
|
||||
|
@ -52,7 +53,7 @@ func TestCopyReverse(t *testing.T) {
|
|||
|
||||
func TestClean(t *testing.T) {
|
||||
for _, tc := range testCases[1:] { // Empty one will be equal.
|
||||
cp := Copy(tc.arr)
|
||||
cp := bytes.Clone(tc.arr)
|
||||
Clean(cp)
|
||||
require.NotEqual(t, tc.arr, cp)
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/bigint"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util/slice"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -197,7 +196,7 @@ func convertPrimitive(item Item, typ Type) (Item, error) {
|
|||
return nil, err
|
||||
}
|
||||
if typ == BufferT {
|
||||
return NewBuffer(slice.Copy(b)), nil
|
||||
return NewBuffer(bytes.Clone(b)), nil
|
||||
}
|
||||
// ByteArray can't really be changed, so it's OK to reuse `b`.
|
||||
return NewByteArray(b), nil
|
||||
|
@ -687,7 +686,7 @@ func (i *ByteArray) equalsLimited(s Item, limit *int) bool {
|
|||
|
||||
// Dup implements the Item interface.
|
||||
func (i *ByteArray) Dup() Item {
|
||||
ba := slice.Copy(*i)
|
||||
ba := bytes.Clone(*i)
|
||||
return (*ByteArray)(&ba)
|
||||
}
|
||||
|
||||
|
@ -1186,7 +1185,7 @@ func (i *Buffer) Convert(typ Type) (Item, error) {
|
|||
case BufferT:
|
||||
return i, nil
|
||||
case ByteArrayT:
|
||||
return NewByteArray(slice.Copy(*i)), nil
|
||||
return NewByteArray(bytes.Clone(*i)), nil
|
||||
case IntegerT:
|
||||
if len(*i) > MaxBigIntegerSizeBits/8 {
|
||||
return nil, errTooBigInteger
|
||||
|
@ -1248,12 +1247,12 @@ func deepCopy(item Item, seen map[Item]Item, asImmutable bool) Item {
|
|||
bi := new(big.Int).Set(it.Big())
|
||||
return (*BigInteger)(bi)
|
||||
case *ByteArray:
|
||||
return NewByteArray(slice.Copy(*it))
|
||||
return NewByteArray(bytes.Clone(*it))
|
||||
case *Buffer:
|
||||
if asImmutable {
|
||||
return NewByteArray(slice.Copy(*it))
|
||||
return NewByteArray(bytes.Clone(*it))
|
||||
}
|
||||
return NewBuffer(slice.Copy(*it))
|
||||
return NewBuffer(bytes.Clone(*it))
|
||||
case Bool:
|
||||
return it
|
||||
case *Pointer:
|
||||
|
|
|
@ -449,7 +449,7 @@ type (
|
|||
)
|
||||
|
||||
func mkErrValue(err error) error {
|
||||
return fmt.Errorf("%w: %v", ErrInvalidValue, err) //nolint:errorlint // errorlint: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors
|
||||
return fmt.Errorf("%w: %w", ErrInvalidValue, err)
|
||||
}
|
||||
|
||||
// FromJSONWithTypes deserializes an item from typed-json representation.
|
||||
|
|
|
@ -3,7 +3,6 @@ package vm
|
|||
import (
|
||||
"crypto/elliptic"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -223,7 +222,7 @@ func (v *VM) PrintOps(out io.Writer) {
|
|||
// if the parameter is a 20-byte value.
|
||||
u, err := util.Uint160DecodeBytesBE(parameter)
|
||||
if err == nil {
|
||||
desc = fmt.Sprintf("%x (%q, %q)", parameter, address.Uint160ToString(u), "0x"+hex.EncodeToString(slice.CopyReverse(parameter)))
|
||||
desc = fmt.Sprintf("%x (%q, %q)", parameter, address.Uint160ToString(u), "0x"+u.StringLE())
|
||||
} else {
|
||||
desc = fmt.Sprintf("%x", parameter)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue