From 27fcf024b2b02cab0721c13d1a1f1e53367246ce Mon Sep 17 00:00:00 2001 From: sandy <18382255942@163.com> Date: Fri, 26 Aug 2022 18:12:48 +0800 Subject: [PATCH 1/3] feat(): fix 4everland get bundle parse bug --- jobs.go | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/jobs.go b/jobs.go index 0c14c67..f777938 100644 --- a/jobs.go +++ b/jobs.go @@ -3,6 +3,7 @@ package arseeding import ( "encoding/json" "errors" + "fmt" "github.com/everFinance/arseeding/schema" "github.com/everFinance/everpay-go/account" "github.com/everFinance/everpay-go/config" @@ -492,7 +493,6 @@ func (s *Arseeding) retryOnChainArTx() { func (s *Arseeding) onChainBundleTx(itemIds []string) (arTx types.Transaction, onChainItemIds []string, err error) { onChainItems := make([]types.BundleItem, 0, len(itemIds)) - onChainItemIds = make([]string, 0, len(itemIds)) for _, itemId := range itemIds { itemBinary, err := s.store.LoadItemBinary(itemId) if err != nil { @@ -505,19 +505,50 @@ func (s *Arseeding) onChainBundleTx(itemIds []string) (arTx types.Transaction, o continue } onChainItems = append(onChainItems, *item) - onChainItemIds = append(onChainItemIds, item.Id) } if len(onChainItems) == 0 { err = errors.New("onChainItems is null") return } + // the end off item.Data not be "", because when the case viewblock decode failed. // todo viewblock used stream function decode item, so this is a bug for them + endItem := onChainItems[len(onChainItems)-1] + if endItem.Data == "" { + // find a data != "" item and push to end off + idx := -1 + for i, item := range onChainItems { + if item.Data != "" { + idx = i + break + } + } + if idx == -1 { + err = errors.New("all bundle items data are null") + return + } + newEndItem := onChainItems[idx] + onChainItems = append(onChainItems[:idx], onChainItems[idx+1:]...) + onChainItems = append(onChainItems, newEndItem) + } + + // get onChainItemIds + for _, item := range onChainItems { + onChainItemIds = append(onChainItemIds, item.Id) + } + // assemble and send to arweave bundle, err := utils.NewBundle(onChainItems...) if err != nil { log.Error("utils.NewBundle(onChainItems...)", "err", err) return } + + // verify bundle, ensure that the bundle is exactly right before sending + if _, err = utils.DecodeBundle(bundle.BundleBinary); err != nil { + err = errors.New(fmt.Sprintf("Verify bundle failed; err:%v", err)) + return + } + arTxtags := []types.Tag{ {Name: "App-Name", Value: "arseeding"}, {Name: "App-Version", Value: "1.0.0"}, @@ -591,7 +622,6 @@ func (s *Arseeding) parseAndSaveBundleTx() { } if err := s.ParseAndSaveBundleItems(arId, data); err != nil { log.Error("ParseAndSaveBundleItems", "err", err, "arId", arId) - continue } // del wait db if err = s.store.DelParsedBundleArId(arId); err != nil { From d049a41e235139fe21e722067f74e75317ff1b29 Mon Sep 17 00:00:00 2001 From: sandy <18382255942@163.com> Date: Fri, 26 Aug 2022 18:25:25 +0800 Subject: [PATCH 2/3] feat(): fix api --- api.go | 2 +- sdk/manifest_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api.go b/api.go index 280ad56..1eaaba7 100644 --- a/api.go +++ b/api.go @@ -25,7 +25,7 @@ func (s *Arseeding) runAPI(port string) { } if !s.NoFee { - r.Use(LimiterMiddleware(3000, "M", s.config.GetIPWhiteList())) + r.Use(LimiterMiddleware(30000, "M", s.config.GetIPWhiteList())) } v1 := r.Group("/") { diff --git a/sdk/manifest_test.go b/sdk/manifest_test.go index 6a388aa..a3fd99d 100644 --- a/sdk/manifest_test.go +++ b/sdk/manifest_test.go @@ -46,13 +46,13 @@ func TestSDK_UploadFolderWithNoFee(t *testing.T) { priKey := "1d8bdd0d2f1e73dffe1111111118325b7e195669541f76559760ef615a588be3" eccSigner, err := goether.NewSigner(priKey) assert.NoError(t, err) - seedUrl := "https://arseed-dev.web3infra.dev" + seedUrl := "https://arseed.web3infra.dev" payUrl := "https://api.everpay.io" sdk, err := NewSDK(seedUrl, payUrl, eccSigner) assert.NoError(t, err) apikey := "xxxxxxxxxx" - rootPath := "./dist" + rootPath := "./build" orders, manifestId, err := sdk.UploadFolderWithNoFee(rootPath, 20, "index.html", apikey) assert.NoError(t, err) t.Log(len(orders)) From af439d91e7d4b2cc04548c9ee0b563e06e1ab0b0 Mon Sep 17 00:00:00 2001 From: sandy <18382255942@163.com> Date: Fri, 26 Aug 2022 19:44:11 +0800 Subject: [PATCH 3/3] feat(): fix api --- api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api.go b/api.go index 1eaaba7..237ba95 100644 --- a/api.go +++ b/api.go @@ -91,7 +91,7 @@ func (s *Arseeding) runAPI(port string) { func (s *Arseeding) arseedInfo(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ "Name": "Arseeding", - "Version": "v1.0.13", + "Version": "v1.0.16", "Documentation": "https://web3infra.dev", }) }