@@ -25,12 +25,12 @@ import (
25
25
ipnspath "gx/ipfs/QmQAgv6Gaoe2tQpcabqwKXKChp2MZ7i3UXv9DqTTaxCaTR/go-path"
26
26
files "gx/ipfs/QmQmhotPUzVrMEWNK3x1R5jQ5ZHWyL7tVUrmRPjrBrvyCb/go-ipfs-files"
27
27
cid "gx/ipfs/QmTbxNB1NwDesLmKTscr4udL2tVP7MaxvXnD1D9yX7g3PN/go-cid"
28
- datastore "gx/ipfs/QmUadX5EcvrBmxAV9sE7wUWtWSqxns5K84qKJBixmcT1w9/go-datastore"
29
28
ipns "gx/ipfs/QmUwMnKKjH3JwGKNVZ3TcP37W93xzqNA4ECFFiMo6sXkkc/go-ipns"
30
29
iface "gx/ipfs/QmXLwxifxwfc2bAwq6rdjbYqAsGzWsDE9RM5TWMGtykyj6/interface-go-ipfs-core"
31
30
peer "gx/ipfs/QmYVXrKrKHDC9FobgmcmshCDyWwdrfwfanNQN4oxJ9Fk3h/go-libp2p-peer"
32
31
routing "gx/ipfs/QmYxUdYY9S6yg5tSPVin5GFTvtfsLauVcr7reHDD3dM8xf/go-libp2p-routing"
33
32
ps "gx/ipfs/QmaCTz9RkrU13bm9kMB54f7atgqM4qkjDZpRwRoJiWXEqs/go-libp2p-peerstore"
33
+ ggproto "gx/ipfs/QmddjPSGZb3ieihSseFeCfVRpZzcqczPNsD2DvarSwnjJB/gogo-protobuf/proto"
34
34
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
35
35
36
36
"github.com/OpenBazaar/jsonpb"
@@ -47,7 +47,6 @@ import (
47
47
"github.com/golang/protobuf/ptypes"
48
48
ipfscore "github.com/ipfs/go-ipfs/core"
49
49
"github.com/ipfs/go-ipfs/core/coreapi"
50
- "github.com/ipfs/go-ipfs/namesys"
51
50
"github.com/ipfs/go-ipfs/repo/fsrepo"
52
51
)
53
52
@@ -1045,19 +1044,10 @@ func (i *jsonAPIHandler) PATCHSettings(w http.ResponseWriter, r *http.Request) {
1045
1044
ErrorResponse (w , http .StatusBadRequest , err .Error ())
1046
1045
return
1047
1046
}
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
1061
1051
}
1062
1052
if settings .BlockedNodes != nil {
1063
1053
var blockedIds []peer.ID
@@ -1071,10 +1061,21 @@ func (i *jsonAPIHandler) PATCHSettings(w http.ResponseWriter, r *http.Request) {
1071
1061
}
1072
1062
i .node .BanManager .SetBlockedIds (blockedIds )
1073
1063
}
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 )
1078
1079
}
1079
1080
SanitizedResponse (w , `{}` )
1080
1081
}
@@ -3422,7 +3423,7 @@ func (i *jsonAPIHandler) GETEstimateFee(w http.ResponseWriter, r *http.Request)
3422
3423
fee , err := wal .EstimateSpendFee (* amount , feeLevel )
3423
3424
if err != nil {
3424
3425
switch {
3425
- case err == wallet .ErrorInsuffientFunds :
3426
+ case err == wallet .ErrInsufficientFunds :
3426
3427
ErrorResponse (w , http .StatusBadRequest , `ERROR_INSUFFICIENT_FUNDS` )
3427
3428
return
3428
3429
case err == wallet .ErrorDustAmount :
@@ -3875,6 +3876,7 @@ func (i *jsonAPIHandler) GETWalletStatus(w http.ResponseWriter, r *http.Request)
3875
3876
}
3876
3877
3877
3878
func (i * jsonAPIHandler ) GETIPNS (w http.ResponseWriter , r * http.Request ) {
3879
+ ipfsStore := i .node .IpfsNode .Repo .Datastore ()
3878
3880
_ , peerID := path .Split (r .URL .Path )
3879
3881
3880
3882
pid , err := peer .IDB58Decode (peerID )
@@ -3883,7 +3885,7 @@ func (i *jsonAPIHandler) GETIPNS(w http.ResponseWriter, r *http.Request) {
3883
3885
return
3884
3886
}
3885
3887
3886
- val , err := i . node . IpfsNode . Repo . Datastore (). Get ( namesys . IpnsDsKey ( pid ) )
3888
+ peerIPNSRecord , err := ipfs . GetCachedIPNSRecord ( ipfsStore , pid )
3887
3889
if err != nil { // No record in datastore
3888
3890
ErrorResponse (w , http .StatusNotFound , err .Error ())
3889
3891
return
@@ -3892,7 +3894,7 @@ func (i *jsonAPIHandler) GETIPNS(w http.ResponseWriter, r *http.Request) {
3892
3894
var keyBytes []byte
3893
3895
pubkey := i .node .IpfsNode .Peerstore .PubKey (pid )
3894
3896
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 )
3896
3898
if err != nil {
3897
3899
ErrorResponse (w , http .StatusNotFound , err .Error ())
3898
3900
return
@@ -3910,8 +3912,13 @@ func (i *jsonAPIHandler) GETIPNS(w http.ResponseWriter, r *http.Request) {
3910
3912
Pubkey string `json:"pubkey"`
3911
3913
Record string `json:"record"`
3912
3914
}
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
+ }
3913
3920
3914
- ret := KeyAndRecord {hex .EncodeToString (keyBytes ), string (val )}
3921
+ ret := KeyAndRecord {hex .EncodeToString (keyBytes ), string (peerIPNSBytes )}
3915
3922
retBytes , err := json .MarshalIndent (ret , "" , " " )
3916
3923
if err != nil {
3917
3924
ErrorResponse (w , http .StatusInternalServerError , err .Error ())
@@ -3941,9 +3948,14 @@ func (i *jsonAPIHandler) GETResolveIPNS(w http.ResponseWriter, r *http.Request)
3941
3948
var response = respType {PeerID : peerID }
3942
3949
3943
3950
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 )
3945
3957
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 ))
3947
3959
return
3948
3960
}
3949
3961
response .Record .Hex = hex .EncodeToString (ipnsBytes )
0 commit comments