build: Update linter to 1.53.2 (#384)

* build: Update linter to 1.53.2

* database: Rename helpers.go to encoding.go

* database: Ignore json.Marshal errors.
This commit is contained in:
Jamie Holdstock 2023-06-05 15:39:01 +01:00 committed by GitHub
parent a5003c046b
commit 203bf7d2e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 56 additions and 60 deletions

View File

@ -17,6 +17,6 @@ jobs:
- name: Build - name: Build
run: go build ./... run: go build ./...
- name: Install Linters - name: Install Linters
run: "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.51.1" run: "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.53.2"
- name: Test and Lint - name: Test and Lint
run: ./run_tests.sh run: ./run_tests.sh

View File

@ -97,7 +97,7 @@ func (w *dcrwallet) createFeeTx(feeAddress string, fee int64) (string, error) {
return signedTx.Hex, nil return signedTx.Hex, nil
} }
func (w *dcrwallet) SignMessage(ctx context.Context, msg string, commitmentAddr stdaddr.Address) ([]byte, error) { func (w *dcrwallet) SignMessage(_ context.Context, msg string, commitmentAddr stdaddr.Address) ([]byte, error) {
var signature string var signature string
err := w.Call(context.TODO(), "signmessage", &signature, commitmentAddr.String(), msg) err := w.Call(context.TODO(), "signmessage", &signature, commitmentAddr.String(), msg)
if err != nil { if err != nil {

View File

@ -445,13 +445,13 @@ func loadConfig() (*config, error) {
// Exit with success // Exit with success
os.Exit(0) os.Exit(0)
} else { }
// If database does not exist, return error. // If database does not exist, return error.
if !fileExists(cfg.dbPath) { if !fileExists(cfg.dbPath) {
return nil, fmt.Errorf("no database exists in %s. Run vspd with the"+ return nil, fmt.Errorf("no database exists in %s. Run vspd with the"+
" --feexpub option to initialize one", dataDir) " --feexpub option to initialize one", dataDir)
} }
}
return &cfg, nil return &cfg, nil
} }

View File

@ -1,4 +1,4 @@
// Copyright (c) 2022 The Decred developers // Copyright (c) 2022-2023 The Decred developers
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@ -28,6 +28,16 @@ func bytesToStringMap(bytes []byte) (map[string]string, error) {
return stringMap, nil return stringMap, nil
} }
func stringMapToBytes(stringMap map[string]string) []byte {
// json.Marshal will only return an error if passed an invalid struct.
// Structs are all known and hard-coded, so errors are never expected here.
bytes, err := json.Marshal(stringMap)
if err != nil {
panic(err)
}
return bytes
}
func int64ToBytes(i int64) []byte { func int64ToBytes(i int64) []byte {
bytes := make([]byte, 8) bytes := make([]byte, 8)
binary.LittleEndian.PutUint64(bytes, uint64(i)) binary.LittleEndian.PutUint64(bytes, uint64(i))

View File

@ -5,7 +5,6 @@
package database package database
import ( import (
"encoding/json"
"fmt" "fmt"
"time" "time"
@ -165,28 +164,14 @@ func putTicketInBucket(bkt *bolt.Bucket, ticket Ticket) error {
if err = bkt.Put(confirmedK, boolToBytes(ticket.Confirmed)); err != nil { if err = bkt.Put(confirmedK, boolToBytes(ticket.Confirmed)); err != nil {
return err return err
} }
if err = bkt.Put(tSpendPolicyK, stringMapToBytes(ticket.TSpendPolicy)); err != nil {
jsonTSpend, err := json.Marshal(ticket.TSpendPolicy)
if err != nil {
return err return err
} }
if err = bkt.Put(tSpendPolicyK, jsonTSpend); err != nil { if err = bkt.Put(treasuryPolicyK, stringMapToBytes(ticket.TreasuryPolicy)); err != nil {
return err return err
} }
jsonTreasury, err := json.Marshal(ticket.TreasuryPolicy) return bkt.Put(voteChoicesK, stringMapToBytes(ticket.VoteChoices))
if err != nil {
return err
}
if err = bkt.Put(treasuryPolicyK, jsonTreasury); err != nil {
return err
}
jsonVoteChoices, err := json.Marshal(ticket.VoteChoices)
if err != nil {
return err
}
return bkt.Put(voteChoicesK, jsonVoteChoices)
} }
func getTicketFromBkt(bkt *bolt.Bucket) (Ticket, error) { func getTicketFromBkt(bkt *bolt.Bucket) (Ticket, error) {

View File

@ -227,10 +227,9 @@ func (s *Server) broadcastTicket(c *gin.Context) {
} }
_, err = dcrdClient.GetRawTransaction(parentHash.String()) _, err = dcrdClient.GetRawTransaction(parentHash.String())
if err != nil {
var e *wsrpc.Error var e *wsrpc.Error
if err == nil { if errors.As(err, &e) && e.Code == rpc.ErrNoTxInfo {
// No error means dcrd already knows the parent tx, nothing to do.
} else if errors.As(err, &e) && e.Code == rpc.ErrNoTxInfo {
// ErrNoTxInfo means local dcrd is not aware of the parent. We have // ErrNoTxInfo means local dcrd is not aware of the parent. We have
// the hex, so we can broadcast it here. // the hex, so we can broadcast it here.
@ -266,6 +265,7 @@ func (s *Server) broadcastTicket(c *gin.Context) {
s.sendError(types.ErrInternalError, c) s.sendError(types.ErrInternalError, c)
return return
} }
}
// Check if local dcrd already knows the ticket. // Check if local dcrd already knows the ticket.
_, err = dcrdClient.GetRawTransaction(request.TicketHash) _, err = dcrdClient.GetRawTransaction(request.TicketHash)
@ -276,6 +276,7 @@ func (s *Server) broadcastTicket(c *gin.Context) {
// ErrNoTxInfo means local dcrd is not aware of the ticket. We have the // ErrNoTxInfo means local dcrd is not aware of the ticket. We have the
// hex, so we can broadcast it here. // hex, so we can broadcast it here.
var e *wsrpc.Error
if errors.As(err, &e) && e.Code == rpc.ErrNoTxInfo { if errors.As(err, &e) && e.Code == rpc.ErrNoTxInfo {
s.log.Debugf("%s: Broadcasting ticket (ticketHash=%s)", funcName, request.TicketHash) s.log.Debugf("%s: Broadcasting ticket (ticketHash=%s)", funcName, request.TicketHash)
err = dcrdClient.SendRawTransaction(request.TicketHex) err = dcrdClient.SendRawTransaction(request.TicketHex)

View File

@ -121,11 +121,11 @@ type testNode struct {
existsLiveTicketErr error existsLiveTicketErr error
} }
func (n *testNode) ExistsLiveTicket(ticketHash string) (bool, error) { func (n *testNode) ExistsLiveTicket(_ string) (bool, error) {
return n.existsLiveTicket, n.existsLiveTicketErr return n.existsLiveTicket, n.existsLiveTicketErr
} }
func (n *testNode) GetRawTransaction(txHash string) (*dcrdtypes.TxRawResult, error) { func (n *testNode) GetRawTransaction(_ string) (*dcrdtypes.TxRawResult, error) {
return n.getRawTransaction, n.getRawTransactionErr return n.getRawTransaction, n.getRawTransactionErr
} }