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
run: go build ./...
- 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
run: ./run_tests.sh

View File

@ -97,7 +97,7 @@ func (w *dcrwallet) createFeeTx(feeAddress string, fee int64) (string, error) {
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
err := w.Call(context.TODO(), "signmessage", &signature, commitmentAddr.String(), msg)
if err != nil {

View File

@ -445,12 +445,12 @@ func loadConfig() (*config, error) {
// Exit with success
os.Exit(0)
} else {
// If database does not exist, return error.
if !fileExists(cfg.dbPath) {
return nil, fmt.Errorf("no database exists in %s. Run vspd with the"+
" --feexpub option to initialize one", dataDir)
}
}
// If database does not exist, return error.
if !fileExists(cfg.dbPath) {
return nil, fmt.Errorf("no database exists in %s. Run vspd with the"+
" --feexpub option to initialize one", dataDir)
}
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
// license that can be found in the LICENSE file.
@ -28,6 +28,16 @@ func bytesToStringMap(bytes []byte) (map[string]string, error) {
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 {
bytes := make([]byte, 8)
binary.LittleEndian.PutUint64(bytes, uint64(i))

View File

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

View File

@ -227,44 +227,44 @@ func (s *Server) broadcastTicket(c *gin.Context) {
}
_, err = dcrdClient.GetRawTransaction(parentHash.String())
var e *wsrpc.Error
if err == nil {
// 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
// the hex, so we can broadcast it here.
if err != nil {
var e *wsrpc.Error
if errors.As(err, &e) && e.Code == rpc.ErrNoTxInfo {
// ErrNoTxInfo means local dcrd is not aware of the parent. We have
// the hex, so we can broadcast it here.
// Before broadcasting, check that the provided parent hex is
// actually the parent of the ticket.
var found bool
for _, txIn := range msgTx.TxIn {
if !txIn.PreviousOutPoint.Hash.IsEqual(&parentHash) {
continue
// Before broadcasting, check that the provided parent hex is
// actually the parent of the ticket.
var found bool
for _, txIn := range msgTx.TxIn {
if !txIn.PreviousOutPoint.Hash.IsEqual(&parentHash) {
continue
}
found = true
break
}
found = true
break
}
if !found {
s.log.Errorf("%s: Invalid ticket parent (ticketHash=%s)", funcName, request.TicketHash)
s.sendErrorWithMsg("invalid ticket parent", types.ErrBadRequest, c)
return
}
if !found {
s.log.Errorf("%s: Invalid ticket parent (ticketHash=%s)", funcName, request.TicketHash)
s.sendErrorWithMsg("invalid ticket parent", types.ErrBadRequest, c)
return
}
s.log.Debugf("%s: Broadcasting parent tx %s (ticketHash=%s)", funcName, parentHash, request.TicketHash)
err = dcrdClient.SendRawTransaction(request.ParentHex)
if err != nil {
s.log.Errorf("%s: dcrd.SendRawTransaction for parent tx failed (ticketHash=%s): %v",
s.log.Debugf("%s: Broadcasting parent tx %s (ticketHash=%s)", funcName, parentHash, request.TicketHash)
err = dcrdClient.SendRawTransaction(request.ParentHex)
if err != nil {
s.log.Errorf("%s: dcrd.SendRawTransaction for parent tx failed (ticketHash=%s): %v",
funcName, request.TicketHash, err)
s.sendError(types.ErrCannotBroadcastTicket, c)
return
}
} else {
s.log.Errorf("%s: dcrd.GetRawTransaction for ticket parent failed (ticketHash=%s): %v",
funcName, request.TicketHash, err)
s.sendError(types.ErrCannotBroadcastTicket, c)
s.sendError(types.ErrInternalError, c)
return
}
} else {
s.log.Errorf("%s: dcrd.GetRawTransaction for ticket parent failed (ticketHash=%s): %v",
funcName, request.TicketHash, err)
s.sendError(types.ErrInternalError, c)
return
}
// Check if local dcrd already knows the ticket.
@ -276,6 +276,7 @@ func (s *Server) broadcastTicket(c *gin.Context) {
// ErrNoTxInfo means local dcrd is not aware of the ticket. We have the
// hex, so we can broadcast it here.
var e *wsrpc.Error
if errors.As(err, &e) && e.Code == rpc.ErrNoTxInfo {
s.log.Debugf("%s: Broadcasting ticket (ticketHash=%s)", funcName, request.TicketHash)
err = dcrdClient.SendRawTransaction(request.TicketHex)

View File

@ -121,11 +121,11 @@ type testNode struct {
existsLiveTicketErr error
}
func (n *testNode) ExistsLiveTicket(ticketHash string) (bool, error) {
func (n *testNode) ExistsLiveTicket(_ string) (bool, error) {
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
}