From 86054875a4f0296ed38858553448dfe92c14da9c Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 11 Aug 2022 10:27:25 -0400 Subject: [PATCH] fix: add mode build param and change ipfs gateway accordingly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- Makefile | 5 ++++- VERSION | 2 +- api/geth_backend.go | 2 +- ipfs/ipfs.go | 7 +++---- params/version.go | 3 +++ services/ens/api.go | 6 +++++- services/ens/api_test.go | 2 +- services/stickers/api.go | 1 + 8 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index a398d8554..b22b2c505 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ RELEASE_DIR := /tmp/release-$(RELEASE_TAG) PRE_RELEASE := "1" RELEASE_TYPE := $(shell if [ $(PRE_RELEASE) = "0" ] ; then echo release; else echo pre-release ; fi) GOLANGCI_BINARY=golangci-lint +IPFS_GATEWAY_URL ?= https://ipfs.status.im/ ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10... detected_OS := Windows @@ -42,10 +43,12 @@ ENABLE_METRICS ?= true BUILD_FLAGS ?= $(shell echo "-ldflags='\ -X github.com/status-im/status-go/params.Version=$(RELEASE_TAG:v%=%) \ -X github.com/status-im/status-go/params.GitCommit=$(GIT_COMMIT) \ + -X github.com/status-im/status-go/params.IpfsGatewayURL=$(IPFS_GATEWAY_URL) \ -X github.com/status-im/status-go/vendor/github.com/ethereum/go-ethereum/metrics.EnabledStr=$(ENABLE_METRICS)'") BUILD_FLAGS_MOBILE ?= $(shell echo "-ldflags='\ -X github.com/status-im/status-go/params.Version=$(RELEASE_TAG:v%=%) \ - -X github.com/status-im/status-go/params.GitCommit=$(GIT_COMMIT)'") + -X github.com/status-im/status-go/params.GitCommit=$(GIT_COMMIT) \ + -X github.com/status-im/status-go/params.IPFS_GATEWAY_URL=$(IPFS_GATEWAY_URL)'") networkid ?= StatusChain gotest_extraflags = diff --git a/VERSION b/VERSION index 82da8f5b6..a9a7f3fec 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.106.3 +0.107.0 diff --git a/api/geth_backend.go b/api/geth_backend.go index 0220bb994..8ec52c645 100644 --- a/api/geth_backend.go +++ b/api/geth_backend.go @@ -83,7 +83,7 @@ type GethStatusBackend struct { // NewGethStatusBackend create a new GethStatusBackend instance func NewGethStatusBackend() *GethStatusBackend { - defer log.Info("Status backend initialized", "backend", "geth", "version", params.Version, "commit", params.GitCommit) + defer log.Info("Status backend initialized", "backend", "geth", "version", params.Version, "commit", params.GitCommit, "IpfsGatewayURL", params.IpfsGatewayURL) backend := &GethStatusBackend{} backend.initialize() diff --git a/ipfs/ipfs.go b/ipfs/ipfs.go index 94936eabd..a8d45c6df 100644 --- a/ipfs/ipfs.go +++ b/ipfs/ipfs.go @@ -11,14 +11,13 @@ import ( "time" "github.com/ipfs/go-cid" - "github.com/multiformats/go-multibase" "github.com/wealdtech/go-multicodec" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/log" + "github.com/status-im/status-go/params" ) -const infuraAPIURL = "https://ipfs.infura.io:5001/api/v0/cat?arg=" const maxRequestsPerSecond = 3 type taskResponse struct { @@ -133,7 +132,7 @@ func hashToCid(hash []byte) (string, error) { return "", err } - return thisCID.StringOfBase(multibase.Base32) + return thisCID.Hash().B58String(), nil } func decodeStringHash(input string) (string, error) { @@ -198,7 +197,7 @@ func (d *Downloader) exists(cid string) (bool, []byte, error) { func (d *Downloader) download(cid string, download bool) ([]byte, error) { path := filepath.Join(d.ipfsDir, cid) - req, err := http.NewRequest(http.MethodPost, infuraAPIURL+cid, nil) + req, err := http.NewRequest(http.MethodGet, params.IpfsGatewayURL+cid, nil) if err != nil { return nil, err } diff --git a/params/version.go b/params/version.go index b468d4afd..b66bed35d 100644 --- a/params/version.go +++ b/params/version.go @@ -6,3 +6,6 @@ var Version string // GitCommit is a commit hash. var GitCommit string + +// IpfsGatewayURL is the Gateway URL to use for IPFS +var IpfsGatewayURL string diff --git a/services/ens/api.go b/services/ens/api.go index ab0b22138..e1ecd908f 100644 --- a/services/ens/api.go +++ b/services/ens/api.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "fmt" "math/big" + "net/url" "strings" "sync" @@ -568,7 +569,10 @@ func (api *API) ResourceURL(ctx context.Context, chainID uint64, username string if err != nil { return nil, errors.Wrap(err, "failed to obtain base36 representation") } - host := str + ".ipfs.infura-ipfs.io/" + + parsedURL, _ := url.Parse(params.IpfsGatewayURL) + // Remove scheme from the url + host := parsedURL.Hostname() + parsedURL.Path + str return &URI{scheme, host, ""}, nil case "ipns-ns": id, offset := binary.Uvarint(data) diff --git a/services/ens/api_test.go b/services/ens/api_test.go index 54945c922..62860d7b4 100644 --- a/services/ens/api_test.go +++ b/services/ens/api_test.go @@ -131,7 +131,7 @@ func TestResourceURL(t *testing.T) { uri, err := api.ResourceURL(context.Background(), 1, "simpledapp.eth") require.NoError(t, err) require.Equal(t, "https", uri.Scheme) - require.Equal(t, "bafybeidzlqpkbtvpjtxnzgew6ffxhozq5f4ojbk64iq3tjl7lkjue2biby.ipfs.infura-ipfs.io/", uri.Host) + require.Equal(t, "bafybeidzlqpkbtvpjtxnzgew6ffxhozq5f4ojbk64iq3tjl7lkjue2biby", uri.Host) require.Equal(t, "", uri.Path) uri, err = api.ResourceURL(context.Background(), 1, "swarm.eth") diff --git a/services/stickers/api.go b/services/stickers/api.go index 759495bd7..db879d167 100644 --- a/services/stickers/api.go +++ b/services/stickers/api.go @@ -285,6 +285,7 @@ func (api *API) fetchStickerPacks(chainID uint64, resultChan chan<- *StickerPack stickerPack, err := api.fetchPackData(stickerType, packID, true) if err != nil { log.Warn("Could not retrieve stickerpack data", "packID", packID, "error", err) + errChan <- err return }