update dependencies: packages ioutil, errors

No functional changes.

As pointed out in lightwalletd/pull/469, the errors package we're using
has been deprecated, so this commit updates the code to use "errors"
instead of "github.com/pkg/errors". Same with "io/ioutil", which has
been superceded by "os".
This commit is contained in:
Larry Ruane 2024-01-23 12:07:55 -07:00 committed by Larry Ruane
parent 5c534c6142
commit e8453e62f6
11 changed files with 31 additions and 39 deletions

View File

@ -10,7 +10,6 @@ import (
"encoding/binary"
"hash/fnv"
"io"
"io/ioutil"
"os"
"path/filepath"
"sync"
@ -209,7 +208,7 @@ func NewBlockCache(dbPath string, chainName string, startHeight int, syncFromHei
if err != nil {
Log.Fatal("open ", c.lengthsName, " failed: ", err)
}
lengths, err := ioutil.ReadFile(c.lengthsName)
lengths, err := os.ReadFile(c.lengthsName)
if err != nil {
Log.Fatal("read ", c.lengthsName, " failed: ", err)
}

View File

@ -6,7 +6,6 @@ package common
import (
"encoding/hex"
"encoding/json"
"io/ioutil"
"os"
"testing"
@ -32,7 +31,7 @@ func TestCache(t *testing.T) {
}
var compactTests []compactTest
blockJSON, err := ioutil.ReadFile("../testdata/compact_blocks.json")
blockJSON, err := os.ReadFile("../testdata/compact_blocks.json")
if err != nil {
t.Fatal(err)
}

View File

@ -7,11 +7,12 @@ package common
import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
"time"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/zcash/lightwalletd/parser"
"github.com/zcash/lightwalletd/walletrpc"
@ -323,7 +324,7 @@ func getBlockFromRPC(height int) (*walletrpc.CompactBlock, error) {
if (strings.Split(rpcErr.Error(), ":"))[0] == "-8" {
return nil, nil
}
return nil, errors.Wrap(rpcErr, "error requesting verbose block")
return nil, fmt.Errorf("error requesting verbose block: %w", rpcErr)
}
var block1 ZcashRpcReplyGetblock1
err = json.Unmarshal(result, &block1)
@ -340,24 +341,24 @@ func getBlockFromRPC(height int) (*walletrpc.CompactBlock, error) {
// For some reason, the error responses are not JSON
if rpcErr != nil {
return nil, errors.Wrap(rpcErr, "error requesting block")
return nil, fmt.Errorf("error requesting block: %w", rpcErr)
}
var blockDataHex string
err = json.Unmarshal(result, &blockDataHex)
if err != nil {
return nil, errors.Wrap(err, "error reading JSON response")
return nil, fmt.Errorf("error reading JSON response: %w", err)
}
blockData, err := hex.DecodeString(blockDataHex)
if err != nil {
return nil, errors.Wrap(err, "error decoding getblock output")
return nil, fmt.Errorf("error decoding getblock output: %w", err)
}
block := parser.NewBlock()
rest, err := block.ParseFromSlice(blockData)
if err != nil {
return nil, errors.Wrap(err, "error parsing block")
return nil, fmt.Errorf("error parsing block: %w", err)
}
if len(rest) != 0 {
return nil, errors.New("received overlong message")
@ -368,7 +369,7 @@ func getBlockFromRPC(height int) (*walletrpc.CompactBlock, error) {
for i, t := range block.Transactions() {
txid, err := hex.DecodeString(block1.Tx[i])
if err != nil {
return nil, errors.Wrap(err, "error decoding getblock txid")
return nil, fmt.Errorf("error decoding getblock txid: %w", err)
}
// convert from big-endian
t.SetTxID(parser.Reverse(txid))

View File

@ -7,14 +7,13 @@ import (
"bufio"
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
"time"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/zcash/lightwalletd/walletrpc"
)
@ -117,7 +116,7 @@ func TestGetLightdInfo(t *testing.T) {
FirstRPC()
// Ensure the retry happened as expected
logFile, err := ioutil.ReadFile("test-log")
logFile, err := os.ReadFile("test-log")
if err != nil {
t.Fatal("Cannot read test-log", err)
}

View File

@ -5,10 +5,11 @@
package frontend
import (
"errors"
"fmt"
"net"
"github.com/btcsuite/btcd/rpcclient"
"github.com/pkg/errors"
"github.com/zcash/lightwalletd/common"
ini "gopkg.in/ini.v1"
)
@ -40,7 +41,7 @@ func NewZRPCFromFlags(opts *common.Options) (*rpcclient.Client, error) {
func connFromConf(confPath interface{}) (*rpcclient.ConnConfig, error) {
cfg, err := ini.Load(confPath)
if err != nil {
return nil, errors.Wrap(err, "failed to read config file")
return nil, fmt.Errorf("failed to read config file: %w", err)
}
rpcaddr := cfg.Section("").Key("rpcbind").String()

1
go.mod
View File

@ -7,7 +7,6 @@ require (
github.com/golang/protobuf v1.5.3
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.2
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.4.0

4
go.sum
View File

@ -982,10 +982,6 @@ github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk
github.com/phpdave11/gofpdi v1.0.13/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
github.com/pierrec/lz4/v4 v4.1.15/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

View File

@ -7,8 +7,8 @@ package parser
import (
"fmt"
"errors"
"github.com/pkg/errors"
"github.com/zcash/lightwalletd/parser/internal/bytestring"
"github.com/zcash/lightwalletd/walletrpc"
)
@ -134,7 +134,7 @@ func (b *Block) ParseFromSlice(data []byte) (rest []byte, err error) {
hdr := NewBlockHeader()
data, err = hdr.ParseFromSlice(data)
if err != nil {
return nil, errors.Wrap(err, "parsing block header")
return nil, fmt.Errorf("parsing block header: %w", err)
}
s := bytestring.String(data)
@ -150,7 +150,7 @@ func (b *Block) ParseFromSlice(data []byte) (rest []byte, err error) {
tx := NewTransaction()
data, err = tx.ParseFromSlice(data)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("parsing transaction %d", i))
return nil, fmt.Errorf("error parsing transaction %d: %w", i, err)
}
vtx = append(vtx, tx)
}

View File

@ -9,9 +9,9 @@ import (
"bytes"
"crypto/sha256"
"encoding/binary"
"errors"
"math/big"
"github.com/pkg/errors"
"github.com/zcash/lightwalletd/parser/internal/bytestring"
)

View File

@ -8,11 +8,9 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"testing"
"github.com/pkg/errors"
protobuf "github.com/golang/protobuf/proto"
)
@ -26,7 +24,7 @@ func TestCompactBlocks(t *testing.T) {
}
var compactTests []compactTest
blockJSON, err := ioutil.ReadFile("../testdata/compact_blocks.json")
blockJSON, err := os.ReadFile("../testdata/compact_blocks.json")
if err != nil {
t.Fatal(err)
}
@ -41,7 +39,7 @@ func TestCompactBlocks(t *testing.T) {
block := NewBlock()
blockData, err = block.ParseFromSlice(blockData)
if err != nil {
t.Error(errors.Wrap(err, fmt.Sprintf("parsing testnet block %d", test.BlockHeight)))
t.Error(fmt.Errorf("error parsing testnet block %d: %w", test.BlockHeight, err))
continue
}
if len(blockData) > 0 {

View File

@ -6,9 +6,9 @@
package parser
import (
"errors"
"fmt"
"github.com/pkg/errors"
"github.com/zcash/lightwalletd/parser/internal/bytestring"
"github.com/zcash/lightwalletd/walletrpc"
)
@ -105,7 +105,7 @@ func (tx *Transaction) ParseTransparent(data []byte) ([]byte, error) {
ti := &tx.transparentInputs[i]
s, err = ti.ParseFromSlice([]byte(s))
if err != nil {
return nil, errors.Wrap(err, "while parsing transparent input")
return nil, fmt.Errorf("error parsing transparent input: %w", err)
}
}
@ -118,7 +118,7 @@ func (tx *Transaction) ParseTransparent(data []byte) ([]byte, error) {
to := &tx.transparentOutputs[i]
s, err = to.ParseFromSlice([]byte(s))
if err != nil {
return nil, errors.Wrap(err, "while parsing transparent output")
return nil, fmt.Errorf("error parsing transparent output: %w", err)
}
}
return []byte(s), nil
@ -433,7 +433,7 @@ func (tx *Transaction) parseV4(data []byte) ([]byte, error) {
newSpend := &tx.shieldedSpends[i]
s, err = newSpend.ParseFromSlice([]byte(s), 4)
if err != nil {
return nil, errors.Wrap(err, "while parsing shielded Spend")
return nil, fmt.Errorf("error parsing shielded Spend: %w", err)
}
}
if !s.ReadCompactSize(&outputCount) {
@ -444,7 +444,7 @@ func (tx *Transaction) parseV4(data []byte) ([]byte, error) {
newOutput := &tx.shieldedOutputs[i]
s, err = newOutput.ParseFromSlice([]byte(s), 4)
if err != nil {
return nil, errors.Wrap(err, "while parsing shielded Output")
return nil, fmt.Errorf("error parsing shielded Output: %w", err)
}
}
var joinSplitCount int
@ -458,7 +458,7 @@ func (tx *Transaction) parseV4(data []byte) ([]byte, error) {
js := &tx.joinSplits[i]
s, err = js.ParseFromSlice([]byte(s))
if err != nil {
return nil, errors.Wrap(err, "while parsing JoinSplit")
return nil, fmt.Errorf("error parsing JoinSplit: %w", err)
}
}
@ -509,7 +509,7 @@ func (tx *Transaction) parseV5(data []byte) ([]byte, error) {
newSpend := &tx.shieldedSpends[i]
s, err = newSpend.ParseFromSlice([]byte(s), tx.version)
if err != nil {
return nil, errors.Wrap(err, "while parsing shielded Spend")
return nil, fmt.Errorf("error parsing shielded Spend: %w", err)
}
}
if !s.ReadCompactSize(&outputCount) {
@ -523,7 +523,7 @@ func (tx *Transaction) parseV5(data []byte) ([]byte, error) {
newOutput := &tx.shieldedOutputs[i]
s, err = newOutput.ParseFromSlice([]byte(s), tx.version)
if err != nil {
return nil, errors.Wrap(err, "while parsing shielded Output")
return nil, fmt.Errorf("error parsing shielded Output: %w", err)
}
}
if spendCount+outputCount > 0 && !s.Skip(8) {
@ -556,7 +556,7 @@ func (tx *Transaction) parseV5(data []byte) ([]byte, error) {
a := &tx.orchardActions[i]
s, err = a.ParseFromSlice([]byte(s))
if err != nil {
return nil, errors.Wrap(err, "while parsing orchard action")
return nil, fmt.Errorf("error parsing orchard action: %w", err)
}
}
if actionsCount > 0 {