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

Commit afdde88

Browse files
committed
Merge branch 'master' into compatibilitytest
2 parents c7f3a87 + 0b1cd2e commit afdde88

38 files changed

+1394
-117
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ env:
88
- "PATH=/home/travis/gopath/bin:$PATH"
99
before_install:
1010
- go get -u github.com/axw/gocov/gocov github.com/mattn/goveralls github.com/tcnksm/ghr
11-
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.15.0
11+
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.23.3
1212
install:
1313
- echo "No external dependencies required. Skipping travis default library dependency setup to use vendors..."
1414
script:
15-
- $GOPATH/bin/golangci-lint run --deadline 10m --new-from-rev=24dc0f64
15+
- $GOPATH/bin/golangci-lint run --deadline 10m --new-from-rev=
1616
- cd $TRAVIS_BUILD_DIR && go test -i && ./test_compile.sh
1717
- goveralls -coverprofile=coverage.out -service travis-ci -repotoken $COVERALLS_TOKEN
1818
after_success:

Godeps/Godeps.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/jsonapi.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3696,7 +3696,10 @@ func (i *jsonAPIHandler) POSTFetchRatings(w http.ResponseWriter, r *http.Request
36963696
id := r.URL.Query().Get("asyncID")
36973697
if id == "" {
36983698
idBytes := make([]byte, 16)
3699-
rand.Read(idBytes)
3699+
_, err := rand.Read(idBytes)
3700+
if err != nil {
3701+
return
3702+
}
37003703
id = base58.Encode(idBytes)
37013704
}
37023705

core/core.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131

3232
const (
3333
// VERSION - current version
34-
VERSION = "0.13.8"
34+
VERSION = "0.14.0"
3535
// USERAGENT - user-agent header string
3636
USERAGENT = "/openbazaar-go:" + VERSION + "/"
3737
)

core/disputes.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (n *OpenBazaarNode) OpenDispute(orderID string, contract *pb.RicardianContr
110110
contract.Signatures = append(contract.Signatures, rc.Signatures[0])
111111

112112
// Send to moderator
113-
err = n.SendDisputeOpen(order.Payment.Moderator, nil, rc)
113+
err = n.SendDisputeOpen(order.Payment.Moderator, nil, rc, orderID)
114114
if err != nil {
115115
return err
116116
}
@@ -131,7 +131,7 @@ func (n *OpenBazaarNode) OpenDispute(orderID string, contract *pb.RicardianContr
131131
return nil
132132
}
133133
}
134-
err = n.SendDisputeOpen(counterparty, &counterkey, rc)
134+
err = n.SendDisputeOpen(counterparty, &counterkey, rc, orderID)
135135
if err != nil {
136136
return err
137137
}
@@ -172,6 +172,10 @@ func (n *OpenBazaarNode) verifyEscrowFundsAreDisputeable(contract *pb.RicardianC
172172
log.Errorf("Failed NewHashFromStr(%s): %s", r.Txid, err.Error())
173173
return false
174174
}
175+
if hash == nil {
176+
log.Errorf("Nil NewHashFromStr(%s)", r.Txid)
177+
return false
178+
}
175179
actualConfirmations, _, err := wal.GetConfirmations(*hash)
176180
if err != nil {
177181
log.Errorf("Failed GetConfirmations(%s): %s", hash.String(), err.Error())
@@ -764,11 +768,11 @@ func (n *OpenBazaarNode) CloseDispute(orderID string, buyerPercentage, vendorPer
764768
return err
765769
}
766770

767-
err = n.SendDisputeClose(buyerID, &buyerKey, rc)
771+
err = n.SendDisputeClose(buyerID, &buyerKey, rc, orderID)
768772
if err != nil {
769773
return err
770774
}
771-
err = n.SendDisputeClose(vendorID, &vendorKey, rc)
775+
err = n.SendDisputeClose(vendorID, &vendorKey, rc, orderID)
772776
if err != nil {
773777
return err
774778
}

core/net.go

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,26 @@ func (n *OpenBazaarNode) SendRefund(peerID string, refundMessage *pb.RicardianCo
443443
log.Errorf("failed to marshal the contract: %v", err)
444444
return err
445445
}
446+
// Create the REFUND message
446447
m := pb.Message{
447448
MessageType: pb.Message_REFUND,
448449
Payload: a,
449450
}
451+
452+
// Save REFUND message to the database for this order for resending if necessary
453+
orderID0 := refundMessage.Refund.OrderID
454+
if orderID0 == "" {
455+
log.Errorf("failed fetching orderID")
456+
} else {
457+
err = n.Datastore.Messages().Put(
458+
fmt.Sprintf("%s-%d", orderID0, int(pb.Message_REFUND)),
459+
orderID0, pb.Message_REFUND, peerID, repo.Message{Msg: m},
460+
"", 0, []byte{})
461+
if err != nil {
462+
log.Errorf("failed putting message (%s-%d): %v", orderID0, int(pb.Message_REFUND), err)
463+
}
464+
}
465+
450466
k, err := libp2p.UnmarshalPublicKey(refundMessage.GetBuyerOrder().GetBuyerID().GetPubkeys().Identity)
451467
if err != nil {
452468
log.Errorf("failed to unmarshal publicKey: %v", err)
@@ -508,16 +524,33 @@ func (n *OpenBazaarNode) SendOrderCompletion(peerID string, k *libp2p.PubKey, co
508524
}
509525

510526
// SendDisputeOpen - send open dispute msg to peer
511-
func (n *OpenBazaarNode) SendDisputeOpen(peerID string, k *libp2p.PubKey, disputeMessage *pb.RicardianContract) error {
527+
func (n *OpenBazaarNode) SendDisputeOpen(peerID string, k *libp2p.PubKey, disputeMessage *pb.RicardianContract, orderID string) error {
512528
a, err := ptypes.MarshalAny(disputeMessage)
513529
if err != nil {
514530
log.Errorf("failed to marshal the contract: %v", err)
515531
return err
516532
}
533+
534+
// Create the DISPUTE_OPEN message
517535
m := pb.Message{
518536
MessageType: pb.Message_DISPUTE_OPEN,
519537
Payload: a,
520538
}
539+
540+
// Save DISPUTE_OPEN message to the database for this order for resending if necessary
541+
orderID0 := orderID
542+
if orderID0 == "" {
543+
log.Errorf("failed fetching orderID")
544+
} else {
545+
err = n.Datastore.Messages().Put(
546+
fmt.Sprintf("%s-%d", orderID0, int(pb.Message_DISPUTE_OPEN)),
547+
orderID0, pb.Message_DISPUTE_OPEN, peerID, repo.Message{Msg: m},
548+
"", 0, []byte{})
549+
if err != nil {
550+
log.Errorf("failed putting message (%s-%d): %v", orderID0, int(pb.Message_DISPUTE_OPEN), err)
551+
}
552+
}
553+
521554
return n.sendMessage(peerID, k, m)
522555
}
523556

@@ -528,24 +561,58 @@ func (n *OpenBazaarNode) SendDisputeUpdate(peerID string, updateMessage *pb.Disp
528561
log.Errorf("failed to marshal the contract: %v", err)
529562
return err
530563
}
564+
565+
// Create the DISPUTE_UPDATE message
531566
m := pb.Message{
532567
MessageType: pb.Message_DISPUTE_UPDATE,
533568
Payload: a,
534569
}
570+
571+
// Save DISPUTE_UPDATE message to the database for this order for resending if necessary
572+
orderID0 := updateMessage.OrderId
573+
if orderID0 == "" {
574+
log.Errorf("failed fetching orderID")
575+
} else {
576+
err = n.Datastore.Messages().Put(
577+
fmt.Sprintf("%s-%d", orderID0, int(pb.Message_DISPUTE_UPDATE)),
578+
orderID0, pb.Message_DISPUTE_UPDATE, peerID, repo.Message{Msg: m},
579+
"", 0, []byte{})
580+
if err != nil {
581+
log.Errorf("failed putting message (%s-%d): %v", orderID0, int(pb.Message_DISPUTE_UPDATE), err)
582+
}
583+
}
584+
535585
return n.sendMessage(peerID, nil, m)
536586
}
537587

538588
// SendDisputeClose - send dispute closed msg to peer
539-
func (n *OpenBazaarNode) SendDisputeClose(peerID string, k *libp2p.PubKey, resolutionMessage *pb.RicardianContract) error {
589+
func (n *OpenBazaarNode) SendDisputeClose(peerID string, k *libp2p.PubKey, resolutionMessage *pb.RicardianContract, orderID string) error {
540590
a, err := ptypes.MarshalAny(resolutionMessage)
541591
if err != nil {
542592
log.Errorf("failed to marshal the contract: %v", err)
543593
return err
544594
}
595+
596+
// Create the DISPUTE_CLOSE message
545597
m := pb.Message{
546598
MessageType: pb.Message_DISPUTE_CLOSE,
547599
Payload: a,
548600
}
601+
602+
// Save DISPUTE_CLOSE message to the database for this order for resending if necessary
603+
orderID0 := orderID
604+
if orderID0 == "" {
605+
log.Errorf("failed fetching orderID")
606+
} else {
607+
err = n.Datastore.Messages().Put(
608+
fmt.Sprintf("%s-%d", orderID0, int(pb.Message_DISPUTE_CLOSE)),
609+
orderID0, pb.Message_DISPUTE_CLOSE, peerID, repo.Message{Msg: m},
610+
"", 0, []byte{})
611+
if err != nil {
612+
log.Errorf("failed putting message (%s-%d): %v", orderID0, int(pb.Message_DISPUTE_CLOSE), err)
613+
}
614+
}
615+
549616
return n.sendMessage(peerID, k, m)
550617
}
551618

@@ -804,6 +871,8 @@ func (n *OpenBazaarNode) SendOrderPayment(spend *SpendResponse) error {
804871
if err != nil {
805872
return err
806873
}
874+
875+
// Create the ORDER_PAYMENT message
807876
m := pb.Message{
808877
MessageType: pb.Message_ORDER_PAYMENT,
809878
Payload: a,
@@ -813,6 +882,21 @@ func (n *OpenBazaarNode) SendOrderPayment(spend *SpendResponse) error {
813882
if err != nil {
814883
return err
815884
}
885+
886+
// Save ORDER_PAYMENT message to the database for this order for resending if necessary
887+
orderID0 := msg.OrderID
888+
if orderID0 == "" {
889+
log.Errorf("failed fetching orderID")
890+
} else {
891+
err = n.Datastore.Messages().Put(
892+
fmt.Sprintf("%s-%d", orderID0, int(pb.Message_ORDER_PAYMENT)),
893+
orderID0, pb.Message_ORDER_PAYMENT, spend.PeerID, repo.Message{Msg: m},
894+
"", 0, []byte{})
895+
if err != nil {
896+
log.Errorf("failed putting message (%s-%d): %v", orderID0, int(pb.Message_ORDER_PAYMENT), err)
897+
}
898+
}
899+
816900
ctx, cancel := context.WithTimeout(context.Background(), n.OfflineMessageFailoverTimeout)
817901
err = n.Service.SendMessage(ctx, p, &m)
818902
cancel()

core/order.go

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,28 +1707,39 @@ func quantityForItem(version uint32, item *pb.Order_Item) *big.Int {
17071707
// ReserveCurrencyConverter will attempt to build a CurrencyConverter based on
17081708
// the reserve currency, or will panic if unsuccessful
17091709
func (n *OpenBazaarNode) ReserveCurrencyConverter() (*repo.CurrencyConverter, error) {
1710-
var reserveCode = "BTC"
1711-
if n.RegressionTestEnable || n.TestnetEnable {
1712-
reserveCode = "TBTC"
1713-
}
1714-
1715-
wal, err := n.Multiwallet.WalletForCurrencyCode(reserveCode)
1716-
if err != nil {
1717-
return nil, fmt.Errorf("unable to find reserve (%s) wallet", reserveCode)
1718-
}
1710+
// reserve currency whitelist
1711+
// TODO: later when the wallet can express whether it can
1712+
// provide reliable reserve currency rates, they can be
1713+
// reflected upon instead of using an explicit whitelist
1714+
var preferredReserveWalletCodes = []string{"BTC"}
1715+
for _, code := range preferredReserveWalletCodes {
1716+
var reserveCode = code
1717+
if n.RegressionTestEnable || n.TestnetEnable {
1718+
reserveCode = "T" + code
1719+
}
1720+
1721+
wal, err := n.Multiwallet.WalletForCurrencyCode(reserveCode)
1722+
if err != nil {
1723+
continue
1724+
}
17191725

1720-
if wal.ExchangeRates() == nil {
1721-
return nil, fmt.Errorf("reserve wallet has exchange rates disabled or unavailable")
1722-
}
1726+
if wal.ExchangeRates() == nil {
1727+
log.Warningf("%s reserve wallet has exchange rates disabled or unavailable", reserveCode)
1728+
continue
1729+
}
17231730

1724-
// priming the exchange rate cache
1725-
if _, err := wal.ExchangeRates().GetAllRates(false); err != nil {
1726-
log.Warningf("priming exchange rate cache: %s", err.Error())
1727-
}
1731+
if _, err := wal.ExchangeRates().GetAllRates(false); err != nil {
1732+
log.Warningf("%s reserve wallet priming exchange rate cache: %s", reserveCode, err.Error())
1733+
continue
1734+
}
17281735

1729-
cc, err := repo.NewCurrencyConverter(reserveCode, wal.ExchangeRates())
1730-
if err != nil {
1731-
return nil, fmt.Errorf("creating reserve currency converter: %s", err.Error())
1736+
cc, err := repo.NewCurrencyConverter(reserveCode, wal.ExchangeRates())
1737+
if err != nil {
1738+
log.Warningf("creating %s reserve currency converter: %s", reserveCode, err.Error())
1739+
continue
1740+
}
1741+
log.Infof("reserve exchange rates provided by %s wallet", reserveCode)
1742+
return cc, nil
17321743
}
1733-
return cc, nil
1744+
return nil, errors.New("unable to find reserve wallet with exchange rates")
17341745
}

core/profile.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ func (n *OpenBazaarNode) PatchProfile(patch map[string]interface{}) error {
195195

196196
repoProfile.NormalizeDataForAllSchemas()
197197

198+
if repoProfile.GetProtobuf().ModeratorInfo != nil &&
199+
repoProfile.GetProtobuf().ModeratorInfo.Fee != nil &&
200+
repoProfile.GetProtobuf().ModeratorInfo.Fee.FeeType == pb.Moderator_Fee_PERCENTAGE {
201+
202+
repoProfile.GetProtobuf().ModeratorInfo.Fee.FixedFee = nil
203+
}
204+
198205
if err := repoProfile.Valid(); err != nil {
199206
return fmt.Errorf("invalid profile: %s", err.Error())
200207
}

ipfs/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/ipfs/go-ipfs/repo"
1616
)
1717

18-
var routerCacheURI string
18+
//var routerCacheURI string
1919

2020
// UpdateIPFSGlobalProtocolVars is a hack to manage custom protocol strings
2121
// which do not yet have an API to manage their configuration
@@ -34,7 +34,7 @@ func UpdateIPFSGlobalProtocolVars(testnetEnable bool) {
3434
// PrepareIPFSConfig builds the configuration options for the internal
3535
// IPFS node.
3636
func PrepareIPFSConfig(r repo.Repo, routerAPIEndpoint string, testEnable, regtestEnable bool) *ipfscore.BuildCfg {
37-
routerCacheURI = routerAPIEndpoint
37+
//routerCacheURI = routerAPIEndpoint
3838
ncfg := &ipfscore.BuildCfg{
3939
Repo: r,
4040
Online: true,

0 commit comments

Comments
 (0)