Skip to content

Commit

Permalink
Merge pull request #46 from everFinance/feature/fix-4everland-bug
Browse files Browse the repository at this point in the history
Feature/fix 4everland bug
  • Loading branch information
zyjblockchain authored Aug 26, 2022
2 parents 1f69c71 + af439d9 commit 1510a75
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
4 changes: 2 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")
{
Expand Down Expand Up @@ -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",
})
}
Expand Down
36 changes: 33 additions & 3 deletions jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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"},
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions sdk/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 1510a75

Please sign in to comment.