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:
parent
a5003c046b
commit
203bf7d2e6
2
.github/workflows/go.yml
vendored
2
.github/workflows/go.yml
vendored
@ -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
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -445,13 +445,13 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
@ -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))
|
||||
@ -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) {
|
||||
|
||||
@ -227,10 +227,9 @@ func (s *Server) broadcastTicket(c *gin.Context) {
|
||||
}
|
||||
|
||||
_, err = dcrdClient.GetRawTransaction(parentHash.String())
|
||||
if err != nil {
|
||||
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 {
|
||||
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.
|
||||
|
||||
@ -266,6 +265,7 @@ func (s *Server) broadcastTicket(c *gin.Context) {
|
||||
s.sendError(types.ErrInternalError, c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Check if local dcrd already knows the ticket.
|
||||
_, 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
|
||||
// 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)
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user