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

Commit

Permalink
Merge master and fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacia committed Feb 25, 2019
1 parent 4f30cff commit f662c7a
Show file tree
Hide file tree
Showing 73 changed files with 503 additions and 439 deletions.
7 changes: 5 additions & 2 deletions api/jsonapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import (
"encoding/hex"
"encoding/json"
"fmt"

"gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
routing "gx/ipfs/QmPpYHPRGVpSJTkQDQDwTYZ1cYUR2NM4HS6M3iAXi8aoUa/go-libp2p-kad-dht"
"gx/ipfs/QmTRhk7cgjUf2gfQ3p2M9KPECNZEW9XUrmHcFCgog4cPgB/go-libp2p-peer"
ps "gx/ipfs/QmTTJcDL3gsnGDALjh2fDGg1onGRUdVgNL2hU2WEZcVrMX/go-libp2p-peerstore"
"gx/ipfs/QmaRb5yNXKonhbkpNxNawoydk4N6es6b4fPj19sjEKsh5D/go-datastore"

"io/ioutil"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -45,6 +47,7 @@ import (
"github.com/btcsuite/btcutil/base58"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"

"github.com/ipfs/go-ipfs/repo/fsrepo"
)

Expand Down Expand Up @@ -1156,7 +1159,7 @@ func (i *jsonAPIHandler) GETInventory(w http.ResponseWriter, r *http.Request) {
}

// If we want our own inventory get it from the local database and return
getPersonalInventory := (peerIDString == "" || peerIDString == i.node.IPFSIdentityString())
getPersonalInventory := peerIDString == "" || peerIDString == i.node.IPFSIdentityString()
if getPersonalInventory {
var (
err error
Expand Down Expand Up @@ -3243,7 +3246,7 @@ func (i *jsonAPIHandler) GETEstimateFee(w http.ResponseWriter, r *http.Request)
return
}
}
fmt.Fprintf(w, `{"estimatedFee": %d}`, (fee))
fmt.Fprintf(w, `{"estimatedFee": %d}`, fee)
}

func (i *jsonAPIHandler) GETFees(w http.ResponseWriter, r *http.Request) {
Expand Down
6 changes: 4 additions & 2 deletions api/jsonapi_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"bytes"
"encoding/json"
"fmt"

ma "gx/ipfs/QmT4U94DnD8FRfqr21obWY32HLM5VExccPKMjQHofeYqr9/go-multiaddr"
manet "gx/ipfs/Qmaabb1tJZ2CX5cp6MuuiGgns71NYoxdgQP6Xdid1dVceC/go-multiaddr-net"

"io/ioutil"
"net/http"
"os"
Expand Down Expand Up @@ -202,9 +204,9 @@ func httpGet(endpoint string) ([]byte, error) {
func jsonFor(t *testing.T, fixture proto.Message) string {
m := jsonpb.Marshaler{}

json, err := m.MarshalToString(fixture)
jsonStr, err := m.MarshalToString(fixture)
if err != nil {
t.Fatal(err)
}
return json
return jsonStr
}
4 changes: 2 additions & 2 deletions api/jsonapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ func TestListingsAcceptedCurrencies(t *testing.T) {
}
resp.Body.Close()

respObj := []struct {
var respObj []struct {
AcceptedCurrencies []string `json:"acceptedCurrencies"`
}{}
}
err = json.Unmarshal(respBody, &respObj)
if err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion api/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (m *notificationManager) sendNotification(n repo.Notifier) {
// TODO: should be extended to include new notifiers in the list
func (m *notificationManager) getNotifiers() []notifier {
settings, err := m.node.Datastore.Settings().Get()
notifiers := []notifier{}
var notifiers []notifier
if err != nil {
return notifiers
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,16 @@ func (x *Convert) Execute(args []string) error {
json.Unmarshal(cf, &cfgIface)
cfgObj, ok := cfgIface.(map[string]interface{})
if !ok {
return errors.New("Invalid config file")
return errors.New("invalid config file")
}

walletIface, ok := cfgObj["Wallet"]
if !ok {
return errors.New("Config file missing wallet field")
return errors.New("config file missing wallet field")
}
walletCfg, ok := walletIface.(map[string]interface{})
if !ok {
return errors.New("Invalid config file")
return errors.New("invalid config file")
}
walletCfg["Type"] = cfgtype
if strings.ToLower(args[0]) == "zcash" {
Expand Down Expand Up @@ -304,7 +304,7 @@ func (x *Convert) Execute(args []string) error {
for i, l := range index {
h, ok := hashes[l.Slug]
if !ok {
return errors.New("Malformatted index file")
return errors.New("malformatted index file")
}
l.Hash = h
index[i] = l
Expand Down
4 changes: 2 additions & 2 deletions cmd/gencerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func (x *GenerateCertificates) Execute(args []string) error {
}

// Check if host ip or dns name and count their quantity
ipAddresses := []net.IP{}
dnsNames := []string{}
var ipAddresses []net.IP
var dnsNames []string
hosts := strings.Split(x.Host, ",")
for _, h := range hosts {
if ip := net.ParseIP(h); ip != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (x *Init) Execute(args []string) error {
if x.WalletCreationDate != "" {
creationDate, err = time.Parse(time.RFC3339, x.WalletCreationDate)
if err != nil {
return errors.New("Wallet creation date timestamp must be in RFC3339 format")
return errors.New("wallet creation date timestamp must be in RFC3339 format")
}
}

Expand Down
5 changes: 4 additions & 1 deletion cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"

bitswap "gx/ipfs/QmNkxFCmPtr2RQxjZNRCNryLud4L9wMEiBJsLgF14MqTHj/go-bitswap/network"
"gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
"gx/ipfs/QmPpYHPRGVpSJTkQDQDwTYZ1cYUR2NM4HS6M3iAXi8aoUa/go-libp2p-kad-dht/opts"
Expand All @@ -16,6 +17,7 @@ import (
oniontp "gx/ipfs/QmVSfWChGxC5AkUhM6ZyZxbcBmZoPrUmrPuW6BnHU3YDA9/go-onion-transport"
ws "gx/ipfs/QmY957dCFYVPKpj21xRs6KA3XAGA9tBt73UE5kfUGdNgD9/go-ws-transport"
"io"

"io/ioutil"
"os"
"path"
Expand Down Expand Up @@ -81,7 +83,7 @@ func (x *Restore) Execute(args []string) error {
if x.WalletCreationDate != "" {
creationDate, err = time.Parse(time.RFC3339, x.WalletCreationDate)
if err != nil {
return errors.New("Wallet creation date timestamp must be in RFC3339 format")
return errors.New("wallet creation date timestamp must be in RFC3339 format")
}
}
os.RemoveAll(repoPath)
Expand Down Expand Up @@ -209,6 +211,7 @@ func (x *Restore) Execute(args []string) error {
if x.TorPassword != "" {
torPw = x.TorPassword
}

transportOptions := libp2p.ChainOptions(libp2p.Transport(oniontp.NewOnionTransportC("tcp4", torControl, torPw, nil, repoPath, (usingTor && usingClearnet))))
if usingClearnet {
transportOptions = libp2p.ChainOptions(
Expand Down
20 changes: 11 additions & 9 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/rand"
"errors"
"fmt"

"gx/ipfs/QmPpYHPRGVpSJTkQDQDwTYZ1cYUR2NM4HS6M3iAXi8aoUa/go-libp2p-kad-dht"
"gx/ipfs/QmPpYHPRGVpSJTkQDQDwTYZ1cYUR2NM4HS6M3iAXi8aoUa/go-libp2p-kad-dht/opts"
ma "gx/ipfs/QmT4U94DnD8FRfqr21obWY32HLM5VExccPKMjQHofeYqr9/go-multiaddr"
Expand All @@ -22,6 +23,7 @@ import (
"gx/ipfs/QmcQ81jSyWCp1jpkQ8CMbtpXT3jK7Wg6ZtYmoyWFgBoF9c/go-libp2p-routing"
p2phost "gx/ipfs/QmdJfsSbKSZnMkfZ1kpopiyB9i3Hd6cp8VKWZmtWPa7Moc/go-libp2p-host"
"gx/ipfs/QmdxUuburamoF6zF9qjeQC4WYcWGbWuRmdLacMEsW8ioD8/gogo-protobuf/proto"

"io"
"io/ioutil"
"net"
Expand Down Expand Up @@ -79,7 +81,7 @@ var fileLogFormat = logging.MustStringFormatter(
)

var (
ErrNoGateways = errors.New("No gateway addresses configured")
ErrNoGateways = errors.New("no gateway addresses configured")
)

type Start struct {
Expand Down Expand Up @@ -109,19 +111,19 @@ func (x *Start) Execute(args []string) error {
printSplashScreen(x.Verbose)

if x.Testnet && x.Regtest {
return errors.New("Invalid combination of testnet and regtest modes")
return errors.New("invalid combination of testnet and regtest modes")
}

if x.Tor && x.DualStack {
return errors.New("Invalid combination of tor and dual stack modes")
return errors.New("invalid combination of tor and dual stack modes")
}

isTestnet := false
if x.Testnet || x.Regtest {
isTestnet = true
}
if x.BitcoinCash && x.ZCash != "" {
return errors.New("Bitcoin Cash and ZCash cannot be used at the same time")
return errors.New("bitcoin cash and zcash cannot be used at the same time")
}

// Set repo path
Expand Down Expand Up @@ -583,7 +585,7 @@ func (x *Start) Execute(args []string) error {
f.Close()
} else {
if string(cookie)[:len(cookiePrefix)] != cookiePrefix {
return errors.New("Invalid authentication cookie. Delete it to generate a new one")
return errors.New("invalid authentication cookie. Delete it to generate a new one")
}
split := strings.SplitAfter(string(cookie), cookiePrefix)
authCookie.Value = split[1]
Expand Down Expand Up @@ -646,12 +648,12 @@ func (x *Start) Execute(args []string) error {
storage = selfhosted.NewSelfHostedStorage(repoPath, core.Node.IpfsNode, pushNodes, core.Node.SendStore)
} else if x.Storage == "dropbox" {
if usingTor && !usingClearnet {
log.Error("Dropbox can not be used with Tor")
return errors.New("Dropbox can not be used with Tor")
log.Error("dropbox can not be used with tor")
return errors.New("dropbox can not be used with tor")
}

if dropboxToken == "" {
err = errors.New("Dropbox token not set in config file")
err = errors.New("dropbox token not set in config file")
log.Error(err)
return err
}
Expand All @@ -661,7 +663,7 @@ func (x *Start) Execute(args []string) error {
return err
}
} else {
err = errors.New("Invalid storage option")
err = errors.New("invalid storage option")
log.Error(err)
return err
}
Expand Down
12 changes: 6 additions & 6 deletions core/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (n *OpenBazaarNode) CompleteOrder(orderRatings *OrderRatings, contract *pb.
var rk []byte
if contract.DisputeResolution != nil {
if contract.VendorOrderConfirmation == nil {
return errors.New("Cannot leave review because the vendor never accepted this order")
return errors.New("cannot leave review because the vendor never accepted this order")
}
for _, sig := range contract.VendorOrderConfirmation.RatingSignatures {
if sig.Metadata.ListingSlug == r.Slug {
Expand All @@ -92,7 +92,7 @@ func (n *OpenBazaarNode) CompleteOrder(orderRatings *OrderRatings, contract *pb.
}
}
if len(contract.BuyerOrder.RatingKeys) < len(orderRatings.Ratings) {
return errors.New("Invalid number of rating keys in buyer order")
return errors.New("invalid number of rating keys in buyer order")
}
rk = contract.BuyerOrder.RatingKeys[z]

Expand Down Expand Up @@ -331,7 +331,7 @@ func (n *OpenBazaarNode) ReleaseFundsAfterTimeout(contract *pb.RicardianContract
}

if confirms < minConfirms {
EscrowTimeLockedError = fmt.Errorf("Tx %s needs %d more confirmations before it can be spent", r.Txid, int(minConfirms-confirms))
EscrowTimeLockedError = fmt.Errorf("tx %s needs %d more confirmations before it can be spent", r.Txid, int(minConfirms-confirms))
return EscrowTimeLockedError
}

Expand Down Expand Up @@ -577,11 +577,11 @@ func verifySignaturesOnOrderCompletion(contract *pb.RicardianContract) error {
); err != nil {
switch err.(type) {
case noSigError:
return errors.New("Contract does not contain a signature for the order completion")
return errors.New("contract does not contain a signature for the order completion")
case invalidSigError:
return errors.New("Buyer's guid signature on contact failed to verify")
return errors.New("buyer's guid signature on contact failed to verify")
case matchKeyError:
return errors.New("Public key in order does not match reported buyer ID")
return errors.New("public key in order does not match reported buyer ID")
default:
return err
}
Expand Down
19 changes: 10 additions & 9 deletions core/confirmation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"errors"
"fmt"

crypto "gx/ipfs/QmPvyPwuCgJ7pDmrKDxRtsScJgBaM5h4EpRL2qQJsmXf4n/go-libp2p-crypto"
"time"

Expand Down Expand Up @@ -128,7 +129,7 @@ func (n *OpenBazaarNode) ConfirmOfflineOrder(contract *pb.RicardianContract, rec
}

if len(txInputs) == 0 {
return errors.New("No unspent transactions found to fund order")
return errors.New("no unspent transactions found to fund order")
}

chaincode, err := hex.DecodeString(contract.BuyerOrder.Payment.Chaincode)
Expand Down Expand Up @@ -262,10 +263,10 @@ func (n *OpenBazaarNode) ValidateOrderConfirmation(contract *pb.RicardianContrac
return err
}
if contract.VendorOrderConfirmation.OrderID != orderID {
return errors.New("Vendor's response contained invalid order ID")
return errors.New("vendor's response contained invalid order ID")
}
if contract.VendorOrderConfirmation.RequestedAmount != contract.BuyerOrder.Payment.Amount {
return errors.New("Vendor requested an amount different from what we calculated")
return errors.New("vendor requested an amount different from what we calculated")
}
wal, err := n.Multiwallet.WalletForCurrencyCode(contract.BuyerOrder.Payment.Coin)
if err != nil {
Expand All @@ -281,23 +282,23 @@ func (n *OpenBazaarNode) ValidateOrderConfirmation(contract *pb.RicardianContrac
}
}
if !exists {
return errors.New("Rating signatures do not cover all purchased listings")
return errors.New("rating signatures do not cover all purchased listings")
}
pubkey, err := crypto.UnmarshalPublicKey(contract.VendorListings[0].VendorID.Pubkeys.Identity)
if err != nil {
return err
}

if !bytes.Equal(sig.Metadata.ModeratorKey, contract.BuyerOrder.Payment.ModeratorKey) {
return errors.New("Rating signature does not contain moderatory key")
return errors.New("rating signature does not contain moderatory key")
}
ser, err := proto.Marshal(sig.Metadata)
if err != nil {
return err
}
valid, err := pubkey.Verify(ser, sig.Signature)
if err != nil || !valid {
return errors.New("Failed to verify signature on rating keys")
return errors.New("failed to verify signature on rating keys")
}
}
}
Expand Down Expand Up @@ -344,11 +345,11 @@ func verifySignaturesOnOrderConfirmation(contract *pb.RicardianContract) error {
); err != nil {
switch err.(type) {
case noSigError:
return errors.New("Contract does not contain a signature for the order confirmation")
return errors.New("contract does not contain a signature for the order confirmation")
case invalidSigError:
return errors.New("Vendor's guid signature on contact failed to verify")
return errors.New("vendor's guid signature on contact failed to verify")
case matchKeyError:
return errors.New("Public key in order confirmation does not match reported vendor ID")
return errors.New("public key in order confirmation does not match reported vendor ID")
default:
return err
}
Expand Down
2 changes: 2 additions & 0 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package core

import (
"errors"

cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
"gx/ipfs/QmPpYHPRGVpSJTkQDQDwTYZ1cYUR2NM4HS6M3iAXi8aoUa/go-libp2p-kad-dht"
libp2p "gx/ipfs/QmPvyPwuCgJ7pDmrKDxRtsScJgBaM5h4EpRL2qQJsmXf4n/go-libp2p-crypto"
ma "gx/ipfs/QmT4U94DnD8FRfqr21obWY32HLM5VExccPKMjQHofeYqr9/go-multiaddr"
peer "gx/ipfs/QmTRhk7cgjUf2gfQ3p2M9KPECNZEW9XUrmHcFCgog4cPgB/go-libp2p-peer"
"gx/ipfs/QmaRb5yNXKonhbkpNxNawoydk4N6es6b4fPj19sjEKsh5D/go-datastore"
routing "gx/ipfs/QmcQ81jSyWCp1jpkQ8CMbtpXT3jK7Wg6ZtYmoyWFgBoF9c/go-libp2p-routing"

"path"
"sync"
"time"
Expand Down
Loading

0 comments on commit f662c7a

Please sign in to comment.