Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Update linter to 1.53.2 #384

Merged
merged 3 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion cmd/v3tool/dcrwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions cmd/vspd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion database/helpers.go → database/encoding.go
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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))
Expand Down
File renamed without changes.
21 changes: 3 additions & 18 deletions database/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package database

import (
"encoding/json"
"fmt"
"time"

Expand Down Expand Up @@ -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) {
Expand Down
65 changes: 33 additions & 32 deletions webapi/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

// 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
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
}
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.
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions webapi/setaltsignaddr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down