chore: fixes for staticcheck

This commit is contained in:
Andrej Zavgorodnij 2020-09-29 17:31:31 +03:00
parent e5bf59ff56
commit bc92227a75
7 changed files with 21 additions and 20 deletions

View File

@ -130,6 +130,9 @@ func (am *AirgappedMachine) handleStateDkgCommitsAwaitConfirmations(o *client.Op
marshaledCommits = append(marshaledCommits, commitBz)
}
commitsBz, err := json.Marshal(marshaledCommits)
if err != nil {
return fmt.Errorf("failed to marshal marshaledCommits: %w", err)
}
am.dkgInstances[o.DKGIdentifier] = dkgInstance

View File

@ -17,7 +17,6 @@ import (
"github.com/depools/dc4bc/fsm/types/requests"
"github.com/google/uuid"
"github.com/depools/dc4bc/fsm/state_machines/signature_proposal_fsm"
spf "github.com/depools/dc4bc/fsm/state_machines/signature_proposal_fsm"
"github.com/depools/dc4bc/fsm/state_machines"
@ -143,7 +142,7 @@ func (c *Client) ProcessMessage(message storage.Message) error {
}
// we can't verify a message at this moment, cause we don't have public keys of participantss
if fsm.Event(message.Event) != signature_proposal_fsm.EventInitProposal {
if fsm.Event(message.Event) != spf.EventInitProposal {
if err := c.verifyMessage(fsmInstance, message); err != nil {
return fmt.Errorf("failed to verifyMessage %+v: %w", message, err)
}

View File

@ -54,6 +54,7 @@ func TestClient_ProcessMessage(t *testing.T) {
t.Run("test_process_dkg_init", func(t *testing.T) {
fsm, err := state_machines.Create(dkgRoundID)
req.NoError(err)
state.EXPECT().LoadFSM(dkgRoundID).Times(1).Return(fsm, true, nil)
senderKeyPair := client.NewKeyPair()

View File

@ -117,7 +117,8 @@ func (n *node) run(t *testing.T) {
if err = pubKey.UnmarshalBinary(pubKeyReq.MasterKey); err != nil {
t.Fatalf("failed to unmarshal pubkey: %v", err)
}
if err = ioutil.WriteFile(fmt.Sprintf("/tmp/dc4bc_participant_%d.pubkey", pubKeyReq.ParticipantId), []byte(pubKey.String()), 666); err != nil {
if err = ioutil.WriteFile(fmt.Sprintf("/tmp/dc4bc_participant_%d.pubkey",
pubKeyReq.ParticipantId), []byte(pubKey.String()), 0666); err != nil {
t.Fatalf("failed to write pubkey to temp file: %v", err)
}
}

View File

@ -205,11 +205,8 @@ func (t *terminal) run() error {
func (t *terminal) dropSensitiveData(passExpiration time.Duration) {
ticker := time.NewTicker(passExpiration)
for {
select {
case <-ticker.C:
t.airgapped.DropSensitiveData()
}
for range ticker.C {
t.airgapped.DropSensitiveData()
}
}
@ -239,7 +236,7 @@ func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for _ = range c {
for range c {
fmt.Printf("Intercepting SIGINT, please type `exit` to stop the machine\n>>> ")
}
}()

View File

@ -7,16 +7,17 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/depools/dc4bc/fsm/fsm"
"github.com/depools/dc4bc/fsm/state_machines/signature_proposal_fsm"
"github.com/depools/dc4bc/fsm/state_machines/signing_proposal_fsm"
"github.com/depools/dc4bc/fsm/types/responses"
"io/ioutil"
"log"
"net/http"
"sort"
"time"
"github.com/depools/dc4bc/fsm/fsm"
"github.com/depools/dc4bc/fsm/state_machines/signature_proposal_fsm"
"github.com/depools/dc4bc/fsm/state_machines/signing_proposal_fsm"
"github.com/depools/dc4bc/fsm/types/responses"
"github.com/depools/dc4bc/client"
"github.com/depools/dc4bc/fsm/types/requests"
"github.com/depools/dc4bc/qr"
@ -296,7 +297,7 @@ func startDKGCommand() *cobra.Command {
messageData := req
messageDataBz, err := json.Marshal(messageData)
if err != nil {
return fmt.Errorf("failed to marshal SignatureProposalParticipantsListRequest: %v\n", err)
return fmt.Errorf("failed to marshal SignatureProposalParticipantsListRequest: %v", err)
}
resp, err := rawPostRequest(fmt.Sprintf("http://%s/startDKG", listenAddr),
"application/json", messageDataBz)
@ -380,13 +381,13 @@ func proposeSignMessageCommand() *cobra.Command {
}
messageDataSignBz, err := json.Marshal(messageDataSign)
if err != nil {
return fmt.Errorf("failed to marshal SigningProposalStartRequest: %v\n", err)
return fmt.Errorf("failed to marshal SigningProposalStartRequest: %v", err)
}
messageDataBz, err := json.Marshal(map[string][]byte{"data": messageDataSignBz,
"dkgID": dkgID})
if err != nil {
return fmt.Errorf("failed to marshal SigningProposalStartRequest: %v\n", err)
return fmt.Errorf("failed to marshal SigningProposalStartRequest: %v", err)
}
resp, err := rawPostRequest(fmt.Sprintf("http://%s/proposeSignMessage", listenAddr),

View File

@ -75,8 +75,6 @@ type FSM struct {
// stateMu guards access to the currentState state.
stateMu sync.RWMutex
// eventMu guards access to State() and Transition().
eventMu sync.Mutex
}
// Transition key source + dst
@ -299,7 +297,8 @@ func (f *FSM) MustCopyWithState(state State) *FSM {
func (f *FSM) DoInternal(event Event, args ...interface{}) (resp *Response, err error) {
trEvent, ok := f.transitions[trKey{f.currentState, event}]
if !ok {
return nil, errors.New(fmt.Sprintf("cannot execute internal event \"%s\" for state \"%s\"", event, f.currentState))
return nil, fmt.Errorf("cannot execute internal event \"%s\" for state \"%s\"",
event, f.currentState)
}
return f.do(trEvent, args...)
@ -308,7 +307,7 @@ func (f *FSM) DoInternal(event Event, args ...interface{}) (resp *Response, err
func (f *FSM) Do(event Event, args ...interface{}) (resp *Response, err error) {
trEvent, ok := f.transitions[trKey{f.currentState, event}]
if !ok {
return nil, errors.New(fmt.Sprintf("cannot execute event \"%s\" for state \"%s\"", event, f.currentState))
return nil, fmt.Errorf("cannot execute event \"%s\" for state \"%s\"", event, f.currentState)
}
if trEvent.isInternal {
return nil, errors.New("event is internal")