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

Commit afd01e8

Browse files
committed
Merge branch 'ethereum-master' of https://github.com/OpenBazaar/openbazaar-go into compatibilitytest
2 parents 6556f74 + c110900 commit afd01e8

File tree

168 files changed

+5817
-8989
lines changed

Some content is hidden

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

168 files changed

+5817
-8989
lines changed

Godeps/Godeps.json

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

api/jsonapi.go

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ import (
2525
ipnspath "gx/ipfs/QmQAgv6Gaoe2tQpcabqwKXKChp2MZ7i3UXv9DqTTaxCaTR/go-path"
2626
files "gx/ipfs/QmQmhotPUzVrMEWNK3x1R5jQ5ZHWyL7tVUrmRPjrBrvyCb/go-ipfs-files"
2727
cid "gx/ipfs/QmTbxNB1NwDesLmKTscr4udL2tVP7MaxvXnD1D9yX7g3PN/go-cid"
28-
datastore "gx/ipfs/QmUadX5EcvrBmxAV9sE7wUWtWSqxns5K84qKJBixmcT1w9/go-datastore"
2928
ipns "gx/ipfs/QmUwMnKKjH3JwGKNVZ3TcP37W93xzqNA4ECFFiMo6sXkkc/go-ipns"
3029
iface "gx/ipfs/QmXLwxifxwfc2bAwq6rdjbYqAsGzWsDE9RM5TWMGtykyj6/interface-go-ipfs-core"
3130
peer "gx/ipfs/QmYVXrKrKHDC9FobgmcmshCDyWwdrfwfanNQN4oxJ9Fk3h/go-libp2p-peer"
3231
routing "gx/ipfs/QmYxUdYY9S6yg5tSPVin5GFTvtfsLauVcr7reHDD3dM8xf/go-libp2p-routing"
3332
ps "gx/ipfs/QmaCTz9RkrU13bm9kMB54f7atgqM4qkjDZpRwRoJiWXEqs/go-libp2p-peerstore"
33+
ggproto "gx/ipfs/QmddjPSGZb3ieihSseFeCfVRpZzcqczPNsD2DvarSwnjJB/gogo-protobuf/proto"
3434
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
3535

3636
"github.com/OpenBazaar/jsonpb"
@@ -47,7 +47,6 @@ import (
4747
"github.com/golang/protobuf/ptypes"
4848
ipfscore "github.com/ipfs/go-ipfs/core"
4949
"github.com/ipfs/go-ipfs/core/coreapi"
50-
"github.com/ipfs/go-ipfs/namesys"
5150
"github.com/ipfs/go-ipfs/repo/fsrepo"
5251
)
5352

@@ -1045,19 +1044,10 @@ func (i *jsonAPIHandler) PATCHSettings(w http.ResponseWriter, r *http.Request) {
10451044
ErrorResponse(w, http.StatusBadRequest, err.Error())
10461045
return
10471046
}
1048-
if settings.StoreModerators != nil {
1049-
modsToAdd, modsToDelete := extractModeratorChanges(*settings.StoreModerators, currentSettings.StoreModerators)
1050-
go func(modsToAdd, modsToDelete []string) {
1051-
if err := i.node.NotifyModerators(modsToAdd, modsToDelete); err != nil {
1052-
log.Error(err)
1053-
}
1054-
}(modsToAdd, modsToDelete)
1055-
if err := i.node.SetModeratorsOnListings(*settings.StoreModerators); err != nil {
1056-
ErrorResponse(w, http.StatusInternalServerError, err.Error())
1057-
}
1058-
if err := i.node.SeedNode(); err != nil {
1059-
ErrorResponse(w, http.StatusInternalServerError, err.Error())
1060-
}
1047+
err = i.node.Datastore.Settings().Update(settings)
1048+
if err != nil {
1049+
ErrorResponse(w, http.StatusInternalServerError, err.Error())
1050+
return
10611051
}
10621052
if settings.BlockedNodes != nil {
10631053
var blockedIds []peer.ID
@@ -1071,10 +1061,21 @@ func (i *jsonAPIHandler) PATCHSettings(w http.ResponseWriter, r *http.Request) {
10711061
}
10721062
i.node.BanManager.SetBlockedIds(blockedIds)
10731063
}
1074-
err = i.node.Datastore.Settings().Update(settings)
1075-
if err != nil {
1076-
ErrorResponse(w, http.StatusInternalServerError, err.Error())
1077-
return
1064+
if settings.StoreModerators != nil {
1065+
modsToAdd, modsToDelete := extractModeratorChanges(*settings.StoreModerators, currentSettings.StoreModerators)
1066+
if err := i.node.SetModeratorsOnListings(*settings.StoreModerators); err != nil {
1067+
ErrorResponse(w, http.StatusInternalServerError, err.Error())
1068+
return
1069+
}
1070+
if err := i.node.SeedNode(); err != nil {
1071+
ErrorResponse(w, http.StatusInternalServerError, err.Error())
1072+
return
1073+
}
1074+
go func(modsToAdd, modsToDelete []string) {
1075+
if err := i.node.NotifyModerators(modsToAdd, modsToDelete); err != nil {
1076+
log.Error(err)
1077+
}
1078+
}(modsToAdd, modsToDelete)
10781079
}
10791080
SanitizedResponse(w, `{}`)
10801081
}
@@ -3422,7 +3423,7 @@ func (i *jsonAPIHandler) GETEstimateFee(w http.ResponseWriter, r *http.Request)
34223423
fee, err := wal.EstimateSpendFee(*amount, feeLevel)
34233424
if err != nil {
34243425
switch {
3425-
case err == wallet.ErrorInsuffientFunds:
3426+
case err == wallet.ErrInsufficientFunds:
34263427
ErrorResponse(w, http.StatusBadRequest, `ERROR_INSUFFICIENT_FUNDS`)
34273428
return
34283429
case err == wallet.ErrorDustAmount:
@@ -3875,6 +3876,7 @@ func (i *jsonAPIHandler) GETWalletStatus(w http.ResponseWriter, r *http.Request)
38753876
}
38763877

38773878
func (i *jsonAPIHandler) GETIPNS(w http.ResponseWriter, r *http.Request) {
3879+
ipfsStore := i.node.IpfsNode.Repo.Datastore()
38783880
_, peerID := path.Split(r.URL.Path)
38793881

38803882
pid, err := peer.IDB58Decode(peerID)
@@ -3883,7 +3885,7 @@ func (i *jsonAPIHandler) GETIPNS(w http.ResponseWriter, r *http.Request) {
38833885
return
38843886
}
38853887

3886-
val, err := i.node.IpfsNode.Repo.Datastore().Get(namesys.IpnsDsKey(pid))
3888+
peerIPNSRecord, err := ipfs.GetCachedIPNSRecord(ipfsStore, pid)
38873889
if err != nil { // No record in datastore
38883890
ErrorResponse(w, http.StatusNotFound, err.Error())
38893891
return
@@ -3892,7 +3894,7 @@ func (i *jsonAPIHandler) GETIPNS(w http.ResponseWriter, r *http.Request) {
38923894
var keyBytes []byte
38933895
pubkey := i.node.IpfsNode.Peerstore.PubKey(pid)
38943896
if pubkey == nil || !pid.MatchesPublicKey(pubkey) {
3895-
keyval, err := i.node.IpfsNode.Repo.Datastore().Get(datastore.NewKey(core.KeyCachePrefix + peerID))
3897+
keyval, err := ipfs.GetCachedPubkey(ipfsStore, peerID)
38963898
if err != nil {
38973899
ErrorResponse(w, http.StatusNotFound, err.Error())
38983900
return
@@ -3910,8 +3912,13 @@ func (i *jsonAPIHandler) GETIPNS(w http.ResponseWriter, r *http.Request) {
39103912
Pubkey string `json:"pubkey"`
39113913
Record string `json:"record"`
39123914
}
3915+
peerIPNSBytes, err := ggproto.Marshal(peerIPNSRecord)
3916+
if err != nil {
3917+
ErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("marshaling IPNS record: %s", err.Error()))
3918+
return
3919+
}
39133920

3914-
ret := KeyAndRecord{hex.EncodeToString(keyBytes), string(val)}
3921+
ret := KeyAndRecord{hex.EncodeToString(keyBytes), string(peerIPNSBytes)}
39153922
retBytes, err := json.MarshalIndent(ret, "", " ")
39163923
if err != nil {
39173924
ErrorResponse(w, http.StatusInternalServerError, err.Error())
@@ -3941,9 +3948,14 @@ func (i *jsonAPIHandler) GETResolveIPNS(w http.ResponseWriter, r *http.Request)
39413948
var response = respType{PeerID: peerID}
39423949

39433950
if i.node.IpfsNode.Identity.Pretty() == peerID {
3944-
ipnsBytes, err := i.node.IpfsNode.Repo.Datastore().Get(namesys.IpnsDsKey(i.node.IpfsNode.Identity))
3951+
rec, err := ipfs.GetCachedIPNSRecord(i.node.IpfsNode.Repo.Datastore(), i.node.IpfsNode.Identity)
3952+
if err != nil {
3953+
ErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("retrieving self: %s", err))
3954+
return
3955+
}
3956+
ipnsBytes, err := proto.Marshal(rec)
39453957
if err != nil {
3946-
ErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("retrieving self from datastore: %s", err))
3958+
ErrorResponse(w, http.StatusInternalServerError, fmt.Sprintf("marshaling self: %s", err))
39473959
return
39483960
}
39493961
response.Record.Hex = hex.EncodeToString(ipnsBytes)

api/jsonapi_data_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ const walletBalanceJSONResponse = `{
333333
"TBCH": {
334334
"confirmed": "0",
335335
"currency": {
336-
"code": "TBCH",
336+
"code": "TBCH",
337337
"currencyType": "crypto",
338338
"divisibility": 8,
339339
"name": "Testnet Bitcoin Cash"
@@ -344,7 +344,7 @@ const walletBalanceJSONResponse = `{
344344
"TBTC": {
345345
"confirmed": "0",
346346
"currency": {
347-
"code": "TBTC",
347+
"code": "TBTC",
348348
"currencyType": "crypto",
349349
"divisibility": 8,
350350
"name": "Testnet Bitcoin"
@@ -355,7 +355,7 @@ const walletBalanceJSONResponse = `{
355355
"TLTC": {
356356
"confirmed": "0",
357357
"currency": {
358-
"code": "TLTC",
358+
"code": "TLTC",
359359
"currencyType": "crypto",
360360
"divisibility": 8,
361361
"name": "Testnet Litecoin"
@@ -366,7 +366,7 @@ const walletBalanceJSONResponse = `{
366366
"TZEC": {
367367
"confirmed": "0",
368368
"currency": {
369-
"code": "TZEC",
369+
"code": "TZEC",
370370
"currencyType": "crypto",
371371
"divisibility": 8,
372372
"name": "Testnet Zcash"

api/jsonapi_helpers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ func executeAPITest(t *testing.T, test apiTest) {
177177
}
178178

179179
if !reflect.DeepEqual(responseJSON, expectedJSON) {
180+
t.Error("Error: incorrect response")
180181
t.Logf("expected:\n%s", expectedResp)
181182
t.Logf("actual:\n%s", string(respBody))
182-
t.Error("Incorrect response")
183183
}
184184
}
185185
}

0 commit comments

Comments
 (0)