Merge pull request #1281 from nspcc-dev/drop-go-1.12-and-fix-some-things
Drop go 1.12 and fix some things
This commit is contained in:
commit
c3c88a57cd
54 changed files with 235 additions and 280 deletions
|
@ -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 {
|
||||
|
|
|
@ -123,7 +123,7 @@ func (c *Client) CreateNEP5TransferTx(acc *wallet.Account, to util.Uint160, toke
|
|||
func (c *Client) CreateNEP5MultiTransferTx(acc *wallet.Account, gas int64, recepients ...TransferTarget) (*transaction.Transaction, error) {
|
||||
from, err := address.StringToUint160(acc.Address)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("bad account address: %v", err)
|
||||
return nil, fmt.Errorf("bad account address: %w", err)
|
||||
}
|
||||
w := io.NewBufBinWriter()
|
||||
for i := range recepients {
|
||||
|
@ -147,7 +147,7 @@ func (c *Client) CreateTxFromScript(script []byte, acc *wallet.Account, gas int6
|
|||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't add system fee to transaction: %v", err)
|
||||
return nil, fmt.Errorf("can't add system fee to transaction: %w", err)
|
||||
}
|
||||
tx := transaction.New(c.opts.Network, script, result.GasConsumed)
|
||||
tx.Signers = []transaction.Signer{
|
||||
|
@ -158,12 +158,12 @@ func (c *Client) CreateTxFromScript(script []byte, acc *wallet.Account, gas int6
|
|||
}
|
||||
tx.ValidUntilBlock, err = c.CalculateValidUntilBlock()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't calculate validUntilBlock: %v", err)
|
||||
return nil, fmt.Errorf("can't calculate validUntilBlock: %w", err)
|
||||
}
|
||||
|
||||
err = c.AddNetworkFee(tx, gas, acc)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't add network fee to transaction: %v", err)
|
||||
return nil, fmt.Errorf("can't add network fee to transaction: %w", err)
|
||||
}
|
||||
|
||||
return tx, nil
|
||||
|
@ -180,7 +180,7 @@ func (c *Client) TransferNEP5(acc *wallet.Account, to util.Uint160, token util.U
|
|||
}
|
||||
|
||||
if err := acc.SignTx(tx); err != nil {
|
||||
return util.Uint256{}, fmt.Errorf("can't sign tx: %v", err)
|
||||
return util.Uint256{}, fmt.Errorf("can't sign tx: %w", err)
|
||||
}
|
||||
|
||||
return c.SendRawTransaction(tx)
|
||||
|
@ -194,7 +194,7 @@ func (c *Client) MultiTransferNEP5(acc *wallet.Account, gas int64, recepients ..
|
|||
}
|
||||
|
||||
if err := acc.SignTx(tx); err != nil {
|
||||
return util.Uint256{}, fmt.Errorf("can't sign tx: %v", err)
|
||||
return util.Uint256{}, fmt.Errorf("can't sign tx: %w", err)
|
||||
}
|
||||
|
||||
return c.SendRawTransaction(tx)
|
||||
|
|
|
@ -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,
|
||||
|
@ -691,7 +690,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
|||
result: func(c *Client) interface{} {
|
||||
h, err := util.Uint256DecodeStringLE("72159b0cf1221110daad6e1df6ef4ff03012173b63c86910bd7134deb659c875")
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("can't decode `sendrawtransaction` result hash: %v", err))
|
||||
panic(fmt.Errorf("can't decode `sendrawtransaction` result hash: %w", err))
|
||||
}
|
||||
return h
|
||||
},
|
||||
|
@ -711,7 +710,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
|||
result: func(c *Client) interface{} {
|
||||
h, err := util.Uint256DecodeStringLE("1bdea8f80eb5bd97fade38d5e7fb93b02c9d3e01394e9f4324218132293f7ea6")
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("can't decode `submitblock` result hash: %v", err))
|
||||
panic(fmt.Errorf("can't decode `submitblock` result hash: %w", err))
|
||||
}
|
||||
return h
|
||||
},
|
||||
|
|
|
@ -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: %w", 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: %w", 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"
|
||||
)
|
||||
|
||||
|
@ -614,7 +614,7 @@ func (s *Server) getDecimals(contractID int32, cache map[int32]decimals) (decima
|
|||
},
|
||||
})
|
||||
if err != nil {
|
||||
return decimals{}, fmt.Errorf("can't create script: %v", err)
|
||||
return decimals{}, fmt.Errorf("can't create script: %w", err)
|
||||
}
|
||||
res := s.runScriptInVM(script, nil)
|
||||
if res == nil || res.State != "HALT" || len(res.Stack) == 0 {
|
||||
|
@ -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))
|
||||
|
@ -917,8 +917,8 @@ func (s *Server) submitBlock(reqParams request.Params) (interface{}, *response.E
|
|||
}
|
||||
err = s.chain.AddBlock(b)
|
||||
if err != nil {
|
||||
switch err {
|
||||
case core.ErrInvalidBlockIndex, core.ErrAlreadyExists:
|
||||
switch {
|
||||
case errors.Is(err, core.ErrInvalidBlockIndex) || errors.Is(err, core.ErrAlreadyExists):
|
||||
return nil, response.ErrAlreadyExists
|
||||
default:
|
||||
return nil, response.ErrValidationFailed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue