mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 13:47:19 +00:00
remove github.com/pkg/errors from dependencies
It's not needed any more with Go 1.13 as we have wrapping/unwrapping in base packages. All errors.Wrap calls are replaced with fmt.Errorf, some strings are improved along the way.
This commit is contained in:
parent
6e5920cc09
commit
5ef08f60ae
30 changed files with 90 additions and 95 deletions
|
@ -15,7 +15,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/network"
|
||||
"github.com/nspcc-dev/neo-go/pkg/network/metrics"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpc/server"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
@ -367,13 +366,13 @@ Main:
|
|||
for {
|
||||
select {
|
||||
case err := <-errChan:
|
||||
shutdownErr = errors.Wrap(err, "Error encountered by server")
|
||||
shutdownErr = fmt.Errorf("server error: %w", err)
|
||||
cancel()
|
||||
|
||||
case <-grace.Done():
|
||||
serv.Shutdown()
|
||||
if serverErr := rpcServer.Shutdown(); serverErr != nil {
|
||||
shutdownErr = errors.Wrap(serverErr, "Error encountered whilst shutting down server")
|
||||
shutdownErr = fmt.Errorf("error on shutdown: %w", serverErr)
|
||||
}
|
||||
prometheus.ShutDown()
|
||||
pprof.ShutDown()
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -25,7 +26,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
)
|
||||
|
@ -499,7 +499,7 @@ func testInvokeScript(ctx *cli.Context) error {
|
|||
}
|
||||
nefFile, err := nef.FileFromBytes(b)
|
||||
if err != nil {
|
||||
return cli.NewExitError(errors.Wrapf(err, "failed to restore .nef file"), 1)
|
||||
return cli.NewExitError(fmt.Errorf("failed to restore .nef file: %w", err), 1)
|
||||
}
|
||||
|
||||
args := ctx.Args()
|
||||
|
@ -570,12 +570,12 @@ func inspect(ctx *cli.Context) error {
|
|||
if compile {
|
||||
b, err = compiler.Compile(bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return cli.NewExitError(errors.Wrap(err, "failed to compile"), 1)
|
||||
return cli.NewExitError(fmt.Errorf("failed to compile: %w", err), 1)
|
||||
}
|
||||
} else {
|
||||
nefFile, err := nef.FileFromBytes(b)
|
||||
if err != nil {
|
||||
return cli.NewExitError(errors.Wrapf(err, "failed to restore .nef file"), 1)
|
||||
return cli.NewExitError(fmt.Errorf("failed to restore .nef file: %w", err), 1)
|
||||
}
|
||||
b = nefFile.Script
|
||||
}
|
||||
|
@ -645,17 +645,17 @@ func contractDeploy(ctx *cli.Context) error {
|
|||
}
|
||||
nefFile, err := nef.FileFromBytes(f)
|
||||
if err != nil {
|
||||
return cli.NewExitError(errors.Wrapf(err, "failed to restore .nef file"), 1)
|
||||
return cli.NewExitError(fmt.Errorf("failed to restore .nef file: %w", err), 1)
|
||||
}
|
||||
|
||||
manifestBytes, err := ioutil.ReadFile(manifestFile)
|
||||
if err != nil {
|
||||
return cli.NewExitError(errors.Wrapf(err, "failed to read manifest file"), 1)
|
||||
return cli.NewExitError(fmt.Errorf("failed to read manifest file: %w", err), 1)
|
||||
}
|
||||
m := &manifest.Manifest{}
|
||||
err = json.Unmarshal(manifestBytes, m)
|
||||
if err != nil {
|
||||
return cli.NewExitError(errors.Wrapf(err, "failed to restore manifest file"), 1)
|
||||
return cli.NewExitError(fmt.Errorf("failed to restore manifest file: %w", err), 1)
|
||||
}
|
||||
|
||||
gctx, cancel := options.GetTimeoutContext(ctx)
|
||||
|
|
1
go.mod
1
go.mod
|
@ -13,7 +13,6 @@ require (
|
|||
github.com/nspcc-dev/dbft v0.0.0-20200711144034-c526ccc6f570
|
||||
github.com/nspcc-dev/rfc6979 v0.2.0
|
||||
github.com/pierrec/lz4 v2.5.2+incompatible
|
||||
github.com/pkg/errors v0.8.1
|
||||
github.com/prometheus/client_golang v1.2.1
|
||||
github.com/stretchr/testify v1.4.0
|
||||
github.com/syndtr/goleveldb v0.0.0-20180307113352-169b1b37be73
|
||||
|
|
|
@ -15,7 +15,6 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/tools/go/loader"
|
||||
)
|
||||
|
||||
|
@ -179,11 +178,11 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
|
|||
if o.ManifestFile != "" {
|
||||
m, err := di.ConvertToManifest(o.ContractFeatures, o.ContractSupportedStandards...)
|
||||
if err != nil {
|
||||
return b, errors.Wrap(err, "failed to convert debug info to manifest")
|
||||
return b, fmt.Errorf("failed to convert debug info to manifest: %w", err)
|
||||
}
|
||||
mData, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return b, errors.Wrap(err, "failed to marshal manifest")
|
||||
return b, fmt.Errorf("failed to marshal manifest to JSON: %w", err)
|
||||
}
|
||||
return b, ioutil.WriteFile(o.ManifestFile, mData, os.ModePerm)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
"github.com/go-yaml/yaml"
|
||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const userAgentFormat = "/NEO-GO:%s/"
|
||||
|
@ -37,12 +36,12 @@ func Load(path string, netMode netmode.Magic) (Config, error) {
|
|||
// LoadFile loads config from the provided path.
|
||||
func LoadFile(configPath string) (Config, error) {
|
||||
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
||||
return Config{}, errors.Wrap(err, "Unable to load config")
|
||||
return Config{}, fmt.Errorf("config '%s' doesn't exist", configPath)
|
||||
}
|
||||
|
||||
configData, err := ioutil.ReadFile(configPath)
|
||||
if err != nil {
|
||||
return Config{}, errors.Wrap(err, "Unable to read config")
|
||||
return Config{}, fmt.Errorf("unable to read config: %w", err)
|
||||
}
|
||||
|
||||
config := Config{
|
||||
|
@ -54,7 +53,7 @@ func LoadFile(configPath string) (Config, error) {
|
|||
|
||||
err = yaml.Unmarshal(configData, &config)
|
||||
if err != nil {
|
||||
return Config{}, errors.Wrap(err, "Problem unmarshaling config json data")
|
||||
return Config{}, fmt.Errorf("failed to unmarshal config YAML: %w", err)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package consensus
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/dbft/payload"
|
||||
|
@ -14,7 +15,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type (
|
||||
|
@ -306,7 +306,7 @@ func (m *message) DecodeBinary(r *io.BinReader) {
|
|||
case recoveryMessageType:
|
||||
m.payload = new(recoveryMessage)
|
||||
default:
|
||||
r.Err = errors.Errorf("invalid type: 0x%02x", byte(m.Type))
|
||||
r.Err = fmt.Errorf("invalid type: 0x%02x", byte(m.Type))
|
||||
return
|
||||
}
|
||||
m.payload.DecodeBinary(r)
|
||||
|
@ -338,7 +338,7 @@ func (p *Payload) decodeData() error {
|
|||
br := io.NewBinReaderFromBuf(p.data)
|
||||
m.DecodeBinary(br)
|
||||
if br.Err != nil {
|
||||
return errors.Wrap(br.Err, "cannot decode data into message")
|
||||
return fmt.Errorf("can't decode message: %w", br.Err)
|
||||
}
|
||||
p.message = m
|
||||
return nil
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package consensus
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/nspcc-dev/dbft/crypto"
|
||||
"github.com/nspcc-dev/dbft/payload"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type (
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"sort"
|
||||
|
@ -27,7 +28,6 @@ import (
|
|||
"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/stackitem"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -223,7 +223,7 @@ func (bc *Blockchain) init() error {
|
|||
bc.blockHeight = bHeight
|
||||
bc.persistedHeight = bHeight
|
||||
if err = bc.dao.InitMPT(bHeight); err != nil {
|
||||
return errors.Wrapf(err, "can't init MPT at height %d", bHeight)
|
||||
return fmt.Errorf("can't init MPT at height %d: %w", bHeight, err)
|
||||
}
|
||||
|
||||
hashes, err := bc.dao.GetHeaderHashes()
|
||||
|
@ -579,9 +579,9 @@ func (bc *Blockchain) storeBlock(block *block.Block) error {
|
|||
v.LoadScriptWithFlags(bc.contracts.GetPersistScript(), smartcontract.AllowModifyStates|smartcontract.AllowCall)
|
||||
v.SetPriceGetter(getPrice)
|
||||
if err := v.Run(); err != nil {
|
||||
return errors.Wrap(err, "can't persist native contracts")
|
||||
return fmt.Errorf("onPersist run failed: %w", err)
|
||||
} else if _, err := systemInterop.DAO.Persist(); err != nil {
|
||||
return errors.Wrap(err, "can't persist `onPersist` changes")
|
||||
return fmt.Errorf("can't save onPersist changes: %w", err)
|
||||
}
|
||||
for i := range systemInterop.Notifications {
|
||||
bc.handleNotification(&systemInterop.Notifications[i], cache, block, block.Hash())
|
||||
|
@ -597,7 +597,7 @@ func (bc *Blockchain) storeBlock(block *block.Block) error {
|
|||
appExecResults = append(appExecResults, aer)
|
||||
err := cache.PutAppExecResult(aer)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to Store notifications")
|
||||
return fmt.Errorf("failed to store onPersist exec result: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -616,7 +616,7 @@ func (bc *Blockchain) storeBlock(block *block.Block) error {
|
|||
if !v.HasFailed() {
|
||||
_, err := systemInterop.DAO.Persist()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to persist invocation results")
|
||||
return fmt.Errorf("failed to persist invocation results: %w", err)
|
||||
}
|
||||
for i := range systemInterop.Notifications {
|
||||
bc.handleNotification(&systemInterop.Notifications[i], cache, block, tx.Hash())
|
||||
|
@ -638,7 +638,7 @@ func (bc *Blockchain) storeBlock(block *block.Block) error {
|
|||
appExecResults = append(appExecResults, aer)
|
||||
err = cache.PutAppExecResult(aer)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to Store notifications")
|
||||
return fmt.Errorf("failed to store tx exec result: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -647,7 +647,7 @@ func (bc *Blockchain) storeBlock(block *block.Block) error {
|
|||
if block.Index > 0 {
|
||||
prev, err := bc.dao.GetStateRoot(block.Index - 1)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "can't get previous state root")
|
||||
return fmt.Errorf("can't get previous state root: %w", err)
|
||||
}
|
||||
prevHash = hash.DoubleSha256(prev.GetSignedPart())
|
||||
}
|
||||
|
@ -1204,7 +1204,7 @@ func (bc *Blockchain) verifyHeader(currHeader, prevHeader *block.Header) error {
|
|||
func (bc *Blockchain) verifyTx(t *transaction.Transaction, block *block.Block) error {
|
||||
height := bc.BlockHeight()
|
||||
if t.ValidUntilBlock <= height || t.ValidUntilBlock > height+transaction.MaxValidUntilBlockIncrement {
|
||||
return errors.Errorf("transaction has expired. ValidUntilBlock = %d, current height = %d", t.ValidUntilBlock, height)
|
||||
return fmt.Errorf("transaction has expired. ValidUntilBlock = %d, current height = %d", t.ValidUntilBlock, height)
|
||||
}
|
||||
hashes, err := bc.GetScriptHashesForVerifying(t)
|
||||
if err != nil {
|
||||
|
@ -1219,26 +1219,26 @@ func (bc *Blockchain) verifyTx(t *transaction.Transaction, block *block.Block) e
|
|||
return !blockedAccounts[i].Less(h)
|
||||
})
|
||||
if i != len(blockedAccounts) && blockedAccounts[i].Equals(h) {
|
||||
return errors.Errorf("policy check failed: account %s is blocked", h.StringLE())
|
||||
return fmt.Errorf("policy check failed: account %s is blocked", h.StringLE())
|
||||
}
|
||||
}
|
||||
maxBlockSystemFee := bc.contracts.Policy.GetMaxBlockSystemFeeInternal(bc.dao)
|
||||
if maxBlockSystemFee < t.SystemFee {
|
||||
return errors.Errorf("policy check failed: transaction's fee shouldn't exceed maximum block system fee %d", maxBlockSystemFee)
|
||||
return fmt.Errorf("policy check failed: transaction's fee shouldn't exceed maximum block system fee %d", maxBlockSystemFee)
|
||||
}
|
||||
balance := bc.GetUtilityTokenBalance(t.Sender())
|
||||
need := t.SystemFee + t.NetworkFee
|
||||
if balance.Cmp(big.NewInt(need)) < 0 {
|
||||
return errors.Errorf("insufficient funds: balance is %v, need: %v", balance, need)
|
||||
return fmt.Errorf("insufficient funds: balance is %v, need: %v", balance, need)
|
||||
}
|
||||
size := io.GetVarSize(t)
|
||||
if size > transaction.MaxTransactionSize {
|
||||
return errors.Errorf("invalid transaction size = %d. It shoud be less then MaxTransactionSize = %d", io.GetVarSize(t), transaction.MaxTransactionSize)
|
||||
return fmt.Errorf("too big transaction (%d > MaxTransactionSize %d)", size, transaction.MaxTransactionSize)
|
||||
}
|
||||
needNetworkFee := int64(size) * bc.FeePerByte()
|
||||
netFee := t.NetworkFee - needNetworkFee
|
||||
if netFee < 0 {
|
||||
return errors.Errorf("insufficient funds: net fee is %v, need %v", t.NetworkFee, needNetworkFee)
|
||||
return fmt.Errorf("insufficient funds: net fee is %v, need %v", t.NetworkFee, needNetworkFee)
|
||||
}
|
||||
if block == nil {
|
||||
if ok := bc.memPool.Verify(t, bc); !ok {
|
||||
|
@ -1286,7 +1286,7 @@ func (bc *Blockchain) AddStateRoot(r *state.MPTRoot) error {
|
|||
}
|
||||
}
|
||||
if err := bc.verifyStateRoot(r); err != nil {
|
||||
return errors.WithMessage(err, "invalid state root")
|
||||
return fmt.Errorf("invalid state root: %w", err)
|
||||
}
|
||||
if r.Index > bc.BlockHeight() { // just put it into the store for future checks
|
||||
return bc.dao.PutStateRoot(&state.MPTRootState{
|
||||
|
@ -1298,7 +1298,7 @@ func (bc *Blockchain) AddStateRoot(r *state.MPTRoot) error {
|
|||
flag := state.Unverified
|
||||
if r.Witness != nil {
|
||||
if err := bc.verifyStateRootWitness(r); err != nil {
|
||||
return errors.WithMessage(err, "can't verify signature")
|
||||
return fmt.Errorf("can't verify signature: %w", err)
|
||||
}
|
||||
flag = state.Verified
|
||||
}
|
||||
|
@ -1315,7 +1315,7 @@ func (bc *Blockchain) AddStateRoot(r *state.MPTRoot) error {
|
|||
func (bc *Blockchain) updateStateHeight(newHeight uint32) error {
|
||||
h, err := bc.dao.GetCurrentStateRootHeight()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "can't get current state root height")
|
||||
return fmt.Errorf("can't get current state root height: %w", err)
|
||||
} else if newHeight == h+1 {
|
||||
updateStateHeightMetric(newHeight)
|
||||
return bc.dao.PutCurrentStateRootHeight(h + 1)
|
||||
|
@ -1474,12 +1474,12 @@ func (bc *Blockchain) verifyHashAgainstScript(hash util.Uint160, witness *transa
|
|||
}
|
||||
err = vm.Run()
|
||||
if vm.HasFailed() {
|
||||
return errors.Errorf("vm failed to execute the script with error: %s", err)
|
||||
return fmt.Errorf("vm failed to execute the script with error: %s", err)
|
||||
}
|
||||
resEl := vm.Estack().Pop()
|
||||
if resEl != nil {
|
||||
if !resEl.Bool() {
|
||||
return errors.Errorf("signature check failed")
|
||||
return fmt.Errorf("signature check failed")
|
||||
}
|
||||
if useKeys {
|
||||
bc.keyCacheLock.RLock()
|
||||
|
@ -1492,7 +1492,7 @@ func (bc *Blockchain) verifyHashAgainstScript(hash util.Uint160, witness *transa
|
|||
}
|
||||
}
|
||||
} else {
|
||||
return errors.Errorf("no result returned from the script")
|
||||
return fmt.Errorf("no result returned from the script")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -1511,7 +1511,7 @@ func (bc *Blockchain) verifyTxWitnesses(t *transaction.Transaction, block *block
|
|||
|
||||
witnesses := t.Scripts
|
||||
if len(hashes) != len(witnesses) {
|
||||
return errors.Errorf("expected len(hashes) == len(witnesses). got: %d != %d", len(hashes), len(witnesses))
|
||||
return fmt.Errorf("expected len(hashes) == len(witnesses). got: %d != %d", len(hashes), len(witnesses))
|
||||
}
|
||||
sort.Slice(hashes, func(i, j int) bool { return hashes[i].Less(hashes[j]) })
|
||||
sort.Slice(witnesses, func(i, j int) bool { return witnesses[i].ScriptHash().Less(witnesses[j].ScriptHash()) })
|
||||
|
@ -1519,8 +1519,7 @@ func (bc *Blockchain) verifyTxWitnesses(t *transaction.Transaction, block *block
|
|||
for i := 0; i < len(hashes); i++ {
|
||||
err := bc.verifyHashAgainstScript(hashes[i], &witnesses[i], interopCtx, false, t.NetworkFee)
|
||||
if err != nil {
|
||||
numStr := fmt.Sprintf("witness #%d", i)
|
||||
return errors.Wrap(err, numStr)
|
||||
return fmt.Errorf("witness #%d: %w", i, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap/zaptest"
|
||||
)
|
||||
|
@ -396,7 +395,7 @@ func signTx(bc *Blockchain, txs ...*transaction.Transaction) error {
|
|||
validators := bc.GetStandByValidators()
|
||||
rawScript, err := smartcontract.CreateMultiSigRedeemScript(len(bc.config.StandbyValidators)/2+1, validators)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "fail to sign tx")
|
||||
return fmt.Errorf("failed to sign tx: %w", err)
|
||||
}
|
||||
for _, tx := range txs {
|
||||
size := io.GetVarSize(tx)
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package runtime
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// GasLeft returns remaining amount of GAS.
|
||||
|
|
|
@ -2,6 +2,8 @@ package runtime
|
|||
|
||||
import (
|
||||
"crypto/elliptic"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||
|
@ -9,7 +11,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// CheckHashedWitness checks given hash against current list of script hashes
|
||||
|
@ -91,7 +92,7 @@ func CheckWitness(ic *interop.Context, v *vm.VM) error {
|
|||
res, err = CheckHashedWitness(ic, hash)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to check")
|
||||
return fmt.Errorf("failed to check witness: %w", err)
|
||||
}
|
||||
v.Estack().PushVal(res)
|
||||
return nil
|
||||
|
|
|
@ -2,6 +2,7 @@ package native
|
|||
|
||||
import (
|
||||
"crypto/elliptic"
|
||||
"errors"
|
||||
"math/big"
|
||||
"sort"
|
||||
"strings"
|
||||
|
@ -18,7 +19,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// NEO represents NEO native contract.
|
||||
|
|
|
@ -2,6 +2,7 @@ package native
|
|||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"math/big"
|
||||
"sort"
|
||||
"sync"
|
||||
|
@ -15,7 +16,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"crypto/x509"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
|
@ -16,7 +17,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// coordLen is the number of bytes in serialized X or Y coordinate.
|
||||
|
@ -267,7 +267,7 @@ func (p *PublicKey) DecodeBinary(r *io.BinReader) {
|
|||
return
|
||||
}
|
||||
default:
|
||||
r.Err = errors.Errorf("invalid prefix %d", prefix)
|
||||
r.Err = fmt.Errorf("invalid prefix %d", prefix)
|
||||
return
|
||||
}
|
||||
if x.Cmp(curveParams.P) >= 0 || y.Cmp(curveParams.P) >= 0 {
|
||||
|
|
|
@ -2,10 +2,10 @@ package base58
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
|
||||
"github.com/mr-tron/base58"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// CheckDecode implements a base58-encoded string decoding with hash-based
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package payload
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Headers payload.
|
||||
|
@ -19,7 +20,7 @@ const (
|
|||
)
|
||||
|
||||
// ErrTooManyHeaders is an error returned when too many headers were received.
|
||||
var ErrTooManyHeaders = errors.Errorf("too many headers were received (max: %d)", MaxHeadersAllowed)
|
||||
var ErrTooManyHeaders = fmt.Errorf("too many headers were received (max: %d)", MaxHeadersAllowed)
|
||||
|
||||
// DecodeBinary implements Serializable interface.
|
||||
func (p *Headers) DecodeBinary(br *io.BinReader) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
|
@ -15,7 +16,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -123,7 +123,7 @@ func (c *Client) SetWIF(wif string) error {
|
|||
defer c.wifMu.Unlock()
|
||||
decodedWif, err := keys.WIFDecode(wif, 0x00)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Failed to decode WIF; failed to add WIF to client ")
|
||||
return fmt.Errorf("failed to decode WIF: %w", err)
|
||||
}
|
||||
c.wif = decodedWif
|
||||
return nil
|
||||
|
@ -176,7 +176,7 @@ func (c *Client) makeHTTPRequest(r *request.Raw) (*response.Raw, error) {
|
|||
if resp.StatusCode != http.StatusOK {
|
||||
err = fmt.Errorf("HTTP %d/%s", resp.StatusCode, http.StatusText(resp.StatusCode))
|
||||
} else {
|
||||
err = errors.Wrap(err, "JSON decoding")
|
||||
err = fmt.Errorf("JSON decoding: %w", err)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// PolicyContractHash represents a hash of native Policy contract.
|
||||
|
|
|
@ -2,6 +2,7 @@ package client
|
|||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
||||
|
@ -16,7 +17,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// GetApplicationLog returns the contract log based on the specified txid.
|
||||
|
@ -428,28 +428,28 @@ func (c *Client) SignAndPushInvocationTx(script []byte, acc *wallet.Account, sys
|
|||
|
||||
addr, err := address.StringToUint160(acc.Address)
|
||||
if err != nil {
|
||||
return txHash, errors.Wrap(err, "failed to get address")
|
||||
return txHash, fmt.Errorf("failed to get address: %w", err)
|
||||
}
|
||||
tx.Signers = getSigners(addr, cosigners)
|
||||
|
||||
validUntilBlock, err := c.CalculateValidUntilBlock()
|
||||
if err != nil {
|
||||
return txHash, errors.Wrap(err, "failed to add validUntilBlock to transaction")
|
||||
return txHash, fmt.Errorf("failed to add validUntilBlock to transaction: %w", err)
|
||||
}
|
||||
tx.ValidUntilBlock = validUntilBlock
|
||||
|
||||
err = c.AddNetworkFee(tx, int64(netfee), acc)
|
||||
if err != nil {
|
||||
return txHash, errors.Wrapf(err, "failed to add network fee")
|
||||
return txHash, fmt.Errorf("failed to add network fee: %w", err)
|
||||
}
|
||||
|
||||
if err = acc.SignTx(tx); err != nil {
|
||||
return txHash, errors.Wrap(err, "failed to sign tx")
|
||||
return txHash, fmt.Errorf("failed to sign tx: %w", err)
|
||||
}
|
||||
txHash = tx.Hash()
|
||||
actualHash, err := c.SendRawTransaction(tx)
|
||||
if err != nil {
|
||||
return txHash, errors.Wrap(err, "failed sendning tx")
|
||||
return txHash, fmt.Errorf("failed to send tx: %w", err)
|
||||
}
|
||||
if !actualHash.Equals(txHash) {
|
||||
return actualHash, fmt.Errorf("sent and actual tx hashes mismatch:\n\tsent: %v\n\tactual: %v", txHash.StringLE(), actualHash.StringLE())
|
||||
|
@ -505,7 +505,7 @@ func (c *Client) CalculateValidUntilBlock() (uint32, error) {
|
|||
)
|
||||
blockCount, err := c.GetBlockCount()
|
||||
if err != nil {
|
||||
return result, errors.Wrapf(err, "cannot get block count")
|
||||
return result, fmt.Errorf("can't get block count: %w", err)
|
||||
}
|
||||
|
||||
if c.cache.calculateValidUntilBlock.expiresAt > blockCount {
|
||||
|
@ -513,7 +513,7 @@ func (c *Client) CalculateValidUntilBlock() (uint32, error) {
|
|||
} else {
|
||||
validators, err := c.GetValidators()
|
||||
if err != nil {
|
||||
return result, errors.Wrapf(err, "cannot get validators")
|
||||
return result, fmt.Errorf("can't get validators: %w", err)
|
||||
}
|
||||
validatorsCount = uint32(len(validators))
|
||||
c.cache.calculateValidUntilBlock = calculateValidUntilBlockCache{
|
||||
|
|
|
@ -28,7 +28,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -577,7 +576,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
|||
result: func(c *Client) interface{} {
|
||||
addr, err := address.StringToUint160("NMipL5VsNoLUBUJKPKLhxaEbPQVCZnyJyB")
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "failed to parse UnclaimedGas address"))
|
||||
panic(fmt.Errorf("failed to parse UnclaimedGas address: %w", err))
|
||||
}
|
||||
return result.UnclaimedGas{
|
||||
Address: addr,
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
|
@ -12,7 +13,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type (
|
||||
|
|
|
@ -2,9 +2,8 @@ package request
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -60,11 +59,11 @@ func (r *In) DecodeData(data io.ReadCloser) error {
|
|||
|
||||
err := json.NewDecoder(data).Decode(r)
|
||||
if err != nil {
|
||||
return errors.Errorf("error parsing JSON payload: %s", err)
|
||||
return fmt.Errorf("error parsing JSON payload: %s", err)
|
||||
}
|
||||
|
||||
if r.JSONRPC != JSONRPCVersion {
|
||||
return errors.Errorf("invalid version, expected 2.0 got: '%s'", r.JSONRPC)
|
||||
return fmt.Errorf("invalid version, expected 2.0 got: '%s'", r.JSONRPC)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -77,7 +76,7 @@ func (r *In) Params() (*Params, error) {
|
|||
|
||||
err := json.Unmarshal(r.RawParams, ¶ms)
|
||||
if err != nil {
|
||||
return nil, errors.Errorf("error parsing params field in payload: %s", err)
|
||||
return nil, fmt.Errorf("error parsing params field in payload: %s", err)
|
||||
}
|
||||
|
||||
return ¶ms, nil
|
||||
|
|
|
@ -2,8 +2,7 @@ package response
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type (
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
|
@ -30,7 +31,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -692,7 +692,7 @@ func (s *Server) getrawtransaction(reqParams request.Params) (interface{}, *resp
|
|||
if txHash, err := reqParams.Value(0).GetUint256(); err != nil {
|
||||
resultsErr = response.ErrInvalidParams
|
||||
} else if tx, height, err := s.chain.GetTransaction(txHash); err != nil {
|
||||
err = errors.Wrapf(err, "Invalid transaction hash: %s", txHash)
|
||||
err = fmt.Errorf("invalid transaction %s: %w", txHash, err)
|
||||
return nil, response.NewRPCError("Unknown transaction", err.Error(), err)
|
||||
} else if reqParams.Value(1).GetBoolean() {
|
||||
_header := s.chain.GetHeaderHash(int(height))
|
||||
|
|
|
@ -3,6 +3,8 @@ package smartcontract
|
|||
import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -10,7 +12,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// ParamType represents the Type of the smart contract parameter.
|
||||
|
@ -160,7 +161,7 @@ func ParseParamType(typ string) (ParamType, error) {
|
|||
case "any":
|
||||
return AnyType, nil
|
||||
default:
|
||||
return UnknownType, errors.Errorf("Unknown contract parameter type: %s", typ)
|
||||
return UnknownType, fmt.Errorf("bad parameter type: %s", typ)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/bits"
|
||||
|
@ -14,7 +15,6 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// PropertyState represents contract properties (flags).
|
||||
|
@ -94,7 +94,7 @@ func (p Parameter) MarshalJSON() ([]byte, error) {
|
|||
case InteropInterfaceType, AnyType:
|
||||
resultRawValue = nil
|
||||
default:
|
||||
resultErr = errors.Errorf("Marshaller for type %s not implemented", p.Type)
|
||||
resultErr = fmt.Errorf("can't marshal %s", p.Type)
|
||||
}
|
||||
if resultErr != nil {
|
||||
return nil, resultErr
|
||||
|
@ -183,7 +183,7 @@ func (p *Parameter) UnmarshalJSON(data []byte) (err error) {
|
|||
// stub, ignore value, it can only be null
|
||||
p.Value = nil
|
||||
default:
|
||||
return errors.Errorf("Unmarshaller for type %s not implemented", p.Type)
|
||||
return fmt.Errorf("can't unmarshal %s", p.Type)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ func (p Parameter) TryParse(dest interface{}) error {
|
|||
switch p.Type {
|
||||
case ByteArrayType:
|
||||
if data, ok = p.Value.([]byte); !ok {
|
||||
return errors.Errorf("failed to cast %s to []byte", p.Value)
|
||||
return fmt.Errorf("failed to cast %s to []byte", p.Value)
|
||||
}
|
||||
switch dest := dest.(type) {
|
||||
case *util.Uint160:
|
||||
|
@ -362,7 +362,7 @@ func (p Parameter) TryParse(dest interface{}) error {
|
|||
*dest = string(data)
|
||||
return nil
|
||||
default:
|
||||
return errors.Errorf("cannot cast param of type %s to type %s", p.Type, dest)
|
||||
return fmt.Errorf("cannot cast param of type %s to type %s", p.Type, dest)
|
||||
}
|
||||
default:
|
||||
return errors.New("cannot define param type")
|
||||
|
@ -373,7 +373,7 @@ func (p Parameter) TryParse(dest interface{}) error {
|
|||
func bytesToUint64(b []byte, size int) (uint64, error) {
|
||||
var length = size / 8
|
||||
if len(b) > length {
|
||||
return 0, errors.Errorf("input doesn't fit into %d bits", size)
|
||||
return 0, fmt.Errorf("input doesn't fit into %d bits", size)
|
||||
}
|
||||
if len(b) < length {
|
||||
data := make([]byte, length)
|
||||
|
@ -412,7 +412,7 @@ func NewParameterFromString(in string) (*Parameter, error) {
|
|||
}
|
||||
// We currently do not support following types:
|
||||
if res.Type == ArrayType || res.Type == MapType || res.Type == InteropInterfaceType || res.Type == VoidType {
|
||||
return nil, errors.Errorf("Unsupported contract parameter type: %s", res.Type)
|
||||
return nil, fmt.Errorf("unsupported parameter type %s", res.Type)
|
||||
}
|
||||
buf.Reset()
|
||||
hadType = true
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
|
@ -19,7 +20,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package vm
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// State of the VM.
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"crypto/elliptic"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
|
@ -20,7 +21,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type errorAtInstruct struct {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"crypto/elliptic"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
|
@ -17,7 +18,6 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue