Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 1552c02

Browse files
committed
linter fix
1 parent 511bbb2 commit 1552c02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1389
-384
lines changed

api/jsonapi.go

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
"github.com/btcsuite/btcutil/base58"
4646
"github.com/golang/protobuf/proto"
4747
"github.com/golang/protobuf/ptypes"
48+
ipfscore "github.com/ipfs/go-ipfs/core"
4849
"github.com/ipfs/go-ipfs/core/coreapi"
4950
"github.com/ipfs/go-ipfs/namesys"
5051
"github.com/ipfs/go-ipfs/repo/fsrepo"
@@ -916,7 +917,11 @@ func (i *jsonAPIHandler) POSTSettings(w http.ResponseWriter, r *http.Request) {
916917
}
917918
if settings.StoreModerators != nil {
918919
modsToAdd, modsToDelete := extractModeratorChanges(*settings.StoreModerators, nil)
919-
go i.node.NotifyModerators(modsToAdd, modsToDelete)
920+
go func(modsToAdd, modsToDelete []string) {
921+
if err := i.node.NotifyModerators(modsToAdd, modsToDelete); err != nil {
922+
log.Error(err)
923+
}
924+
}(modsToAdd, modsToDelete)
920925
if err := i.node.SetModeratorsOnListings(*settings.StoreModerators); err != nil {
921926
ErrorResponse(w, http.StatusInternalServerError, err.Error())
922927
}
@@ -973,7 +978,11 @@ func (i *jsonAPIHandler) PUTSettings(w http.ResponseWriter, r *http.Request) {
973978
}
974979
if settings.StoreModerators != nil {
975980
modsToAdd, modsToDelete := extractModeratorChanges(*settings.StoreModerators, currentSettings.StoreModerators)
976-
go i.node.NotifyModerators(modsToAdd, modsToDelete)
981+
go func(modsToAdd, modsToDelete []string) {
982+
if err := i.node.NotifyModerators(modsToAdd, modsToDelete); err != nil {
983+
log.Error(err)
984+
}
985+
}(modsToAdd, modsToDelete)
977986
if err := i.node.SetModeratorsOnListings(*settings.StoreModerators); err != nil {
978987
ErrorResponse(w, http.StatusInternalServerError, err.Error())
979988
}
@@ -1033,7 +1042,11 @@ func (i *jsonAPIHandler) PATCHSettings(w http.ResponseWriter, r *http.Request) {
10331042
}
10341043
if settings.StoreModerators != nil {
10351044
modsToAdd, modsToDelete := extractModeratorChanges(*settings.StoreModerators, currentSettings.StoreModerators)
1036-
go i.node.NotifyModerators(modsToAdd, modsToDelete)
1045+
go func(modsToAdd, modsToDelete []string) {
1046+
if err := i.node.NotifyModerators(modsToAdd, modsToDelete); err != nil {
1047+
log.Error(err)
1048+
}
1049+
}(modsToAdd, modsToDelete)
10371050
if err := i.node.SetModeratorsOnListings(*settings.StoreModerators); err != nil {
10381051
ErrorResponse(w, http.StatusInternalServerError, err.Error())
10391052
}
@@ -1847,7 +1860,12 @@ func (i *jsonAPIHandler) GETModerators(w http.ResponseWriter, r *http.Request) {
18471860
id := r.URL.Query().Get("asyncID")
18481861
if id == "" {
18491862
idBytes := make([]byte, 16)
1850-
rand.Read(idBytes)
1863+
_, err := rand.Read(idBytes)
1864+
if err != nil {
1865+
// TODO: if this happens, len(idBytes) != 16
1866+
// how to handle this
1867+
log.Error(err)
1868+
}
18511869
id = base58.Encode(idBytes)
18521870
}
18531871

@@ -2175,7 +2193,10 @@ func (i *jsonAPIHandler) GETCase(w http.ResponseWriter, r *http.Request) {
21752193
return
21762194
}
21772195

2178-
i.node.Datastore.Cases().MarkAsRead(orderID)
2196+
err = i.node.Datastore.Cases().MarkAsRead(orderID)
2197+
if err != nil {
2198+
log.Error(err)
2199+
}
21792200
SanitizedResponseM(w, out, new(pb.CaseRespApi))
21802201
}
21812202

@@ -2566,11 +2587,20 @@ func (i *jsonAPIHandler) POSTMarkChatAsRead(w http.ResponseWriter, r *http.Reque
25662587
}
25672588
}
25682589
if subject != "" {
2569-
go func() {
2570-
i.node.Datastore.Purchases().MarkAsRead(subject)
2571-
i.node.Datastore.Sales().MarkAsRead(subject)
2572-
i.node.Datastore.Cases().MarkAsRead(subject)
2573-
}()
2590+
go func(subject string) {
2591+
err := i.node.Datastore.Purchases().MarkAsRead(subject)
2592+
if err != nil {
2593+
log.Error(err)
2594+
}
2595+
err = i.node.Datastore.Sales().MarkAsRead(subject)
2596+
if err != nil {
2597+
log.Error(err)
2598+
}
2599+
err = i.node.Datastore.Cases().MarkAsRead(subject)
2600+
if err != nil {
2601+
log.Error(err)
2602+
}
2603+
}(subject)
25742604
}
25752605
SanitizedResponse(w, `{}`)
25762606
}
@@ -2809,7 +2839,12 @@ func (i *jsonAPIHandler) POSTFetchProfiles(w http.ResponseWriter, r *http.Reques
28092839
id := r.URL.Query().Get("asyncID")
28102840
if id == "" {
28112841
idBytes := make([]byte, 16)
2812-
rand.Read(idBytes)
2842+
_, err := rand.Read(idBytes)
2843+
if err != nil {
2844+
// TODO: if this happens, len(idBytes) != 16
2845+
// how to handle this
2846+
log.Error(err)
2847+
}
28132848
id = base58.Encode(idBytes)
28142849
}
28152850

@@ -3184,7 +3219,12 @@ func (i *jsonAPIHandler) POSTBlockNode(w http.ResponseWriter, r *http.Request) {
31843219
nodes = append(nodes, pid)
31853220
}
31863221
}
3187-
go ipfs.RemoveAll(i.node.IpfsNode, peerID, i.node.IPNSQuorumSize)
3222+
go func(nd *ipfscore.IpfsNode, peerID string, quorum uint) {
3223+
err := ipfs.RemoveAll(nd, peerID, quorum)
3224+
if err != nil {
3225+
log.Error(err)
3226+
}
3227+
}(i.node.IpfsNode, peerID, i.node.IPNSQuorumSize)
31883228
nodes = append(nodes, peerID)
31893229
settings.BlockedNodes = &nodes
31903230
if err := i.node.Datastore.Settings().Put(settings); err != nil {
@@ -3625,7 +3665,12 @@ func (i *jsonAPIHandler) POSTFetchRatings(w http.ResponseWriter, r *http.Request
36253665
id := r.URL.Query().Get("asyncID")
36263666
if id == "" {
36273667
idBytes := make([]byte, 16)
3628-
rand.Read(idBytes)
3668+
_, err := rand.Read(idBytes)
3669+
if err != nil {
3670+
// TODO: if this happens, len(idBytes) != 16
3671+
// how to handle this
3672+
log.Error(err)
3673+
}
36293674
id = base58.Encode(idBytes)
36303675
}
36313676

@@ -3853,7 +3898,12 @@ func (i *jsonAPIHandler) GETIPNS(w http.ResponseWriter, r *http.Request) {
38533898
ErrorResponse(w, http.StatusInternalServerError, err.Error())
38543899
return
38553900
}
3856-
go ipfs.Resolve(i.node.IpfsNode, pid, time.Minute, i.node.IPNSQuorumSize, false)
3901+
go func(nd *ipfscore.IpfsNode, pid peer.ID, timeout time.Duration, quorum uint, useCache bool) {
3902+
_, err := ipfs.Resolve(nd, pid, timeout, quorum, useCache)
3903+
if err != nil {
3904+
log.Error(err)
3905+
}
3906+
}(i.node.IpfsNode, pid, time.Minute, i.node.IPNSQuorumSize, false)
38573907
fmt.Fprint(w, string(retBytes))
38583908
}
38593909

cmd/convert.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ func (x *Convert) Execute(args []string) error {
112112
}
113113
if x.Password != "" {
114114
p := "pragma key='" + x.Password + "';"
115-
sqlitedb.Exec(p)
115+
_, err = sqlitedb.Exec(p)
116+
if err != nil {
117+
return err
118+
}
116119
}
117120

118121
_, err = sqlitedb.Exec("DELETE FROM txns;")
@@ -138,7 +141,10 @@ func (x *Convert) Execute(args []string) error {
138141
return err
139142
}
140143
var cfgIface interface{}
141-
json.Unmarshal(cf, &cfgIface)
144+
err = json.Unmarshal(cf, &cfgIface)
145+
if err != nil {
146+
return err
147+
}
142148
cfgObj, ok := cfgIface.(map[string]interface{})
143149
if !ok {
144150
return errors.New("invalid config file")
@@ -360,7 +366,10 @@ func (x *Convert) Execute(args []string) error {
360366
settings, err := sqliteDB.Settings().Get()
361367
if err == nil {
362368
settings.StoreModerators = &[]string{}
363-
sqliteDB.Settings().Put(settings)
369+
err = sqliteDB.Settings().Put(settings)
370+
if err != nil {
371+
log.Error(err)
372+
}
364373
}
365374

366375
// Remove headers.bin

cmd/decrypt.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ func (x *DecryptDatabase) Execute(args []string) error {
9090
fmt.Println(err)
9191
return err
9292
}
93-
tmpDB.InitTables("")
93+
err = tmpDB.InitTables("")
94+
if err != nil {
95+
fmt.Println(err)
96+
return err
97+
}
9498
if err := sqlliteDB.Copy(path.Join(repoPath, "tmp", "datastore", filename), ""); err != nil {
9599
fmt.Println(err)
96100
return err

cmd/encrypt.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ func (x *EncryptDatabase) Execute(args []string) error {
118118
return err
119119
}
120120

121-
tmpDB.InitTables(pw)
121+
err = tmpDB.InitTables(pw)
122+
if err != nil {
123+
fmt.Println(err)
124+
return err
125+
}
122126
if err := sqlliteDB.Copy(path.Join(tmpPath, "datastore", filename), pw); err != nil {
123127
fmt.Println(err)
124128
return err

cmd/gencerts.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ func (x *GenerateCertificates) Execute(args []string) error {
110110
if err != nil {
111111
log.Fatalf("failed to open cert.pem for writing: %s", err)
112112
}
113-
pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
113+
err = pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
114+
if err != nil {
115+
log.Fatalf("failed to write pem encoding: %s", err)
116+
}
114117
certOut.Close()
115118
log.Noticef("wrote cert.pem\n")
116119

@@ -120,7 +123,10 @@ func (x *GenerateCertificates) Execute(args []string) error {
120123
log.Noticef("failed to open key.pem for writing:", err)
121124
return err
122125
}
123-
pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv.(*rsa.PrivateKey))})
126+
err = pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv.(*rsa.PrivateKey))})
127+
if err != nil {
128+
log.Fatalf("failed to write pem encoding: %s", err)
129+
}
124130
keyOut.Close()
125131
log.Noticef("wrote key.pem\n")
126132

cmd/start.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,12 +433,18 @@ func (x *Start) Execute(args []string) error {
433433
err = proto.Unmarshal(ival, ourIpnsRecord)
434434
if err != nil {
435435
log.Error("unmarshal record value", err)
436-
nd.Repo.Datastore().Delete(ipnskey)
436+
err = nd.Repo.Datastore().Delete(ipnskey)
437+
if err != nil {
438+
log.Error(err)
439+
}
437440
}
438441

439442
if x.ForceKeyCachePurge {
440443
log.Infof("forcing key purge from namesys cache...")
441-
nd.Repo.Datastore().Delete(ipnskey)
444+
err = nd.Repo.Datastore().Delete(ipnskey)
445+
if err != nil {
446+
log.Error(err)
447+
}
442448
}
443449

444450
// Wallet

core/core.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ func (n *OpenBazaarNode) RegressionNetworkEnabled() bool { return n.RegressionTe
132132
// SeedNode - publish to IPNS
133133
func (n *OpenBazaarNode) SeedNode() error {
134134
n.seedLock.Lock()
135-
ipfs.UnPinDir(n.IpfsNode, n.RootHash)
135+
err := ipfs.UnPinDir(n.IpfsNode, n.RootHash)
136+
if err != nil {
137+
log.Error(err)
138+
}
136139
var aerr error
137140
var rootHash string
138141
// There's an IPFS bug on Windows that might be related to the Windows indexer that could cause this to fail
@@ -256,8 +259,14 @@ func (n *OpenBazaarNode) SetUpRepublisher(interval time.Duration) {
256259
ticker := time.NewTicker(interval)
257260
go func() {
258261
for range ticker.C {
259-
n.UpdateFollow()
260-
n.SeedNode()
262+
err := n.UpdateFollow()
263+
if err != nil {
264+
log.Error(err)
265+
}
266+
err = n.SeedNode()
267+
if err != nil {
268+
log.Error(err)
269+
}
261270
}
262271
}()
263272
}

core/disputes.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,15 @@ func (n *OpenBazaarNode) OpenDispute(orderID string, contract *pb.RicardianContr
139139

140140
// Update database
141141
if isPurchase {
142-
n.Datastore.Purchases().Put(orderID, *contract, pb.OrderState_DISPUTED, true)
142+
err = n.Datastore.Purchases().Put(orderID, *contract, pb.OrderState_DISPUTED, true)
143+
if err != nil {
144+
log.Error(err)
145+
}
143146
} else {
144-
n.Datastore.Sales().Put(orderID, *contract, pb.OrderState_DISPUTED, true)
147+
err = n.Datastore.Sales().Put(orderID, *contract, pb.OrderState_DISPUTED, true)
148+
if err != nil {
149+
log.Error(err)
150+
}
145151
}
146152
return nil
147153
}
@@ -446,7 +452,10 @@ func (n *OpenBazaarNode) ProcessDisputeOpen(rc *pb.RicardianContract, peerID str
446452
Buyer: buyer,
447453
}
448454
n.Broadcast <- notif
449-
n.Datastore.Notifications().PutRecord(repo.NewNotification(notif, time.Now(), false))
455+
err = n.Datastore.Notifications().PutRecord(repo.NewNotification(notif, time.Now(), false))
456+
if err != nil {
457+
log.Error(err)
458+
}
450459
return nil
451460
}
452461

@@ -560,14 +569,13 @@ func (n *OpenBazaarNode) CloseDispute(orderID string, buyerPercentage, vendorPer
560569
}
561570

562571
var buyerAddr btcutil.Address
563-
buyerValue := big.NewInt(0)
564572
effectiveVal := new(big.Int).Sub(totalOut, &modValue)
565573
if payDivision.BuyerAny() {
566574
buyerAddr, err = wal.DecodeAddress(dispute.BuyerPayoutAddress)
567575
if err != nil {
568576
return err
569577
}
570-
buyerValue = new(big.Int).Mul(effectiveVal, big.NewInt(int64(buyerPercentage)))
578+
buyerValue := new(big.Int).Mul(effectiveVal, big.NewInt(int64(buyerPercentage)))
571579
buyerValue = buyerValue.Div(buyerValue, big.NewInt(100))
572580
out := wallet.TransactionOutput{
573581
Address: buyerAddr,
@@ -577,13 +585,12 @@ func (n *OpenBazaarNode) CloseDispute(orderID string, buyerPercentage, vendorPer
577585
outMap["buyer"] = out
578586
}
579587
var vendorAddr btcutil.Address
580-
vendorValue := big.NewInt(0)
581588
if payDivision.VendorAny() {
582589
vendorAddr, err = wal.DecodeAddress(dispute.VendorPayoutAddress)
583590
if err != nil {
584591
return err
585592
}
586-
vendorValue = new(big.Int).Mul(effectiveVal, big.NewInt(int64(vendorPercentage)))
593+
vendorValue := new(big.Int).Mul(effectiveVal, big.NewInt(int64(vendorPercentage)))
587594
vendorValue = vendorValue.Div(vendorValue, big.NewInt(100))
588595
out := wallet.TransactionOutput{
589596
Address: vendorAddr,

core/fulfillment.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,15 @@ func (n *OpenBazaarNode) FulfillOrder(fulfillment *pb.OrderFulfillment, contract
164164
}
165165
}
166166
if n.IsFulfilled(rc) {
167-
n.Datastore.Sales().Put(contract.VendorOrderConfirmation.OrderID, *contract, pb.OrderState_FULFILLED, false)
167+
err = n.Datastore.Sales().Put(contract.VendorOrderConfirmation.OrderID, *contract, pb.OrderState_FULFILLED, false)
168+
if err != nil {
169+
log.Error(err)
170+
}
168171
} else {
169-
n.Datastore.Sales().Put(contract.VendorOrderConfirmation.OrderID, *contract, pb.OrderState_PARTIALLY_FULFILLED, false)
172+
err = n.Datastore.Sales().Put(contract.VendorOrderConfirmation.OrderID, *contract, pb.OrderState_PARTIALLY_FULFILLED, false)
173+
if err != nil {
174+
log.Error(err)
175+
}
170176
}
171177
return nil
172178
}

core/images.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ func (n *OpenBazaarNode) addImage(img image.Image, imgPath string) (string, erro
108108
if err != nil {
109109
return "", err
110110
}
111-
jpeg.Encode(out, img, nil)
111+
err = jpeg.Encode(out, img, nil)
112+
if err != nil {
113+
return "", err
114+
}
112115
out.Close()
113116
return ipfs.AddFile(n.IpfsNode, imgPath)
114117
}

0 commit comments

Comments
 (0)