From 04371fee97e84f29e7af1af0313444aef1d40e6d Mon Sep 17 00:00:00 2001 From: sandy <18382255942@163.com> Date: Thu, 30 Nov 2023 11:18:14 +0800 Subject: [PATCH 01/14] feat(): upgrade go-everpay --- go.mod | 2 +- jobs.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 3c0640d..f598955 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( require ( github.com/Khan/genqlient v0.6.0 github.com/allegro/bigcache/v3 v3.1.0 - github.com/everFinance/go-everpay v0.0.8 + github.com/everFinance/go-everpay v0.2.0 github.com/everFinance/goarns v0.0.3 github.com/segmentio/kafka-go v0.4.40 go.mongodb.org/mongo-driver v1.11.4 diff --git a/jobs.go b/jobs.go index d32e09a..c81c58d 100644 --- a/jobs.go +++ b/jobs.go @@ -71,7 +71,7 @@ func (s *Arseeding) runJobs(bundleInterval int) { // delete tmp file, one may be repeat request same data,tmp file can be reserve with short time s.scheduler.Every(2).Minute().SingletonMode().Do(s.deleteTmpFile) - //statistic + // statistic s.scheduler.Every(1).Minute().SingletonMode().Do(s.UpdateRealTime) go s.ProduceDailyStatistic() s.scheduler.Every(1).Day().At("00:01").SingletonMode().Do(s.ProduceDailyStatistic) @@ -1144,7 +1144,7 @@ func (s *Arseeding) ProduceDailyStatistic() { var firstOrder schema.Order var osc schema.OrderStatistic err := s.wdb.Db.Model(&schema.Order{}).First(&firstOrder).Error - //Not found + // Not found if err != nil { return } @@ -1156,7 +1156,7 @@ func (s *Arseeding) ProduceDailyStatistic() { } end := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) - //If yesterday's record already exists, return + // If yesterday's record already exists, return if !s.wdb.WhetherExec(schema.TimeRange{Start: end.Add(-24 * time.Hour), End: end}) { return } From 87ad52cde5ddd86353eef691f2c21f54784df65f Mon Sep 17 00:00:00 2001 From: Panda Date: Mon, 15 Jan 2024 18:58:51 +0800 Subject: [PATCH 02/14] feat: add sign data api --- api.go | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/api.go b/api.go index 089fea9..701e1ec 100644 --- a/api.go +++ b/api.go @@ -84,6 +84,7 @@ func (s *Arseeding) runAPI(port string) { // ANS-104 bundle Data api v1.GET("/bundle/bundler", s.getBundler) v1.POST("/bundle/tx/:currency", s.submitItem) + v1.POST("/bundle/tx/signData", s.getSignData) v1.GET("/bundle/tx/:itemId", s.getItemMeta) // get item meta, without data v1.GET("/bundle/tx/:itemId/:field", s.getItemField) @@ -543,6 +544,7 @@ func (s *Arseeding) processApikeySpendBal(currency, apikey string, dataSize int6 return nil } +// @todo 增加 eid 签名类型支持 func (s *Arseeding) submitItem(c *gin.Context) { if c.GetHeader("Content-Type") != "application/octet-stream" { errorResponse(c, "Wrong body type") @@ -633,6 +635,78 @@ func (s *Arseeding) submitItem(c *gin.Context) { }) } +func (s *Arseeding) getSignData(c *gin.Context) { + + // get all query and assemble tags + queryMap := c.Request.URL.Query() + // query key must include "Content-Type" + if _, ok := queryMap["Content-Type"]; !ok { + errorResponse(c, "Query params must include Content-Type") + return + } + tags := make([]types.Tag, 0, len(queryMap)) + for k, values := range queryMap { + for _, val := range values { + tags = append(tags, types.Tag{ + Name: k, + Value: val, + }) + } + } + + if c.Request.Body == nil { + errorResponse(c, "can not submit null native data") + return + } + + dataFile, err := os.CreateTemp(schema.TmpFileDir, "arseed-") + if err != nil { + c.Request.Body.Close() + errorResponse(c, err.Error()) + return + } + defer func() { + c.Request.Body.Close() + dataFile.Close() + os.Remove(dataFile.Name()) + }() + var dataBuf bytes.Buffer + var item types.BundleItem + // write up to schema.AllowMaxNativeDataSize to memory + size, err := setItemData(c, dataFile, &dataBuf) + if err != nil && err != io.EOF { + errorResponse(c, err.Error()) + return + } + if size > schema.SubmitMaxSize { + errorResponse(c, schema.ErrDataTooBig.Error()) + return + } + + if size > schema.AllowStreamMinItemSize { // the body size > schema.AllowStreamMinItemSize, need write to tmp file + item, err = s.bundlerItemSigner.CreateItemStream(dataFile, "", "", tags) + + } else { + item, err = s.bundlerItemSigner.CreateItem(dataBuf.Bytes(), "", "", tags) + } + + if err != nil { + errorResponse(c, "assemble bundle item failed") + log.Error("s.bundlerItemSigner.CreateAndSignItem", "err", err) + return + } + + signData, err := utils.BundleItemSignData(item) + if err != nil { + errorResponse(c, "BundleItemSignData failed") + log.Error("BundleItemSignData", "err", err) + return + } + + c.JSON(http.StatusOK, string(signData)) + +} + func (s *Arseeding) submitNativeData(c *gin.Context) { apiKey := c.GetHeader("X-API-KEY") if len(apiKey) == 0 { @@ -846,6 +920,7 @@ func (s *Arseeding) bundleFee(c *gin.Context) { c.JSON(http.StatusOK, respFee) } +// @todo 支持用 eid 类型查询订单 func (s *Arseeding) getOrders(c *gin.Context) { signer := c.Param("signer") _, signerAddr, err := account.IDCheck(signer) diff --git a/go.mod b/go.mod index f58b93f..37f7c0c 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/aliyun/aliyun-oss-go-sdk v2.2.6+incompatible github.com/aws/aws-sdk-go v1.27.0 github.com/ethereum/go-ethereum v1.10.20 - github.com/everFinance/goar v1.5.7 + github.com/everFinance/goar v1.5.8-0.20240115095401-1323f0ff38f9 github.com/everFinance/goether v1.1.9 github.com/gin-gonic/gin v1.7.7 github.com/go-co-op/gocron v1.11.0 From 2804cbd7299845504a8088f9e3fa63e9ab165cda Mon Sep 17 00:00:00 2001 From: Panda Date: Mon, 22 Jan 2024 11:10:21 +0800 Subject: [PATCH 03/14] update goar --- go.mod | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 37f7c0c..06e1b7b 100644 --- a/go.mod +++ b/go.mod @@ -1,22 +1,24 @@ module github.com/everFinance/arseeding -go 1.17 +go 1.21 + +toolchain go1.21.6 require ( github.com/aliyun/aliyun-oss-go-sdk v2.2.6+incompatible github.com/aws/aws-sdk-go v1.27.0 github.com/ethereum/go-ethereum v1.10.20 - github.com/everFinance/goar v1.5.8-0.20240115095401-1323f0ff38f9 + github.com/everFinance/goar v1.5.8-0.20240119103750-4bb69454cd14 github.com/everFinance/goether v1.1.9 github.com/gin-gonic/gin v1.7.7 github.com/go-co-op/gocron v1.11.0 - github.com/google/uuid v1.3.0 + github.com/google/uuid v1.5.0 github.com/gorilla/handlers v1.4.2 github.com/mkevac/debugcharts v0.0.0-20191222103121-ae1c48aa8615 github.com/panjf2000/ants/v2 v2.6.0 github.com/prometheus/client_golang v1.12.2 github.com/shopspring/decimal v1.2.0 - github.com/stretchr/testify v1.8.2 + github.com/stretchr/testify v1.8.4 github.com/tidwall/gjson v1.14.4 github.com/ulule/limiter/v3 v3.10.0 github.com/urfave/cli/v2 v2.24.4 @@ -49,6 +51,7 @@ require ( github.com/everFinance/ethrpc v1.0.4 // indirect github.com/everFinance/gojwk v1.0.0 // indirect github.com/everFinance/ttcrsa v1.1.3 // indirect + github.com/fxamacker/cbor/v2 v2.5.0 // indirect github.com/getsentry/sentry-go v0.11.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-ole/go-ole v1.2.6 // indirect @@ -57,9 +60,13 @@ require ( github.com/go-playground/validator/v10 v10.4.1 // indirect github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/go-stack/stack v1.8.1 // indirect + github.com/go-webauthn/webauthn v0.10.0 // indirect + github.com/go-webauthn/x v0.1.6 // indirect + github.com/golang-jwt/jwt/v5 v5.2.0 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/golang/snappy v0.0.4 // indirect - github.com/google/go-cmp v0.5.6 // indirect + github.com/google/go-cmp v0.5.9 // indirect + github.com/google/go-tpm v0.9.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/hamba/avro v1.5.6 // indirect github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac // indirect @@ -73,6 +80,7 @@ require ( github.com/mattn/go-isatty v0.0.17 // indirect github.com/mattn/go-sqlite3 v1.14.5 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect @@ -92,16 +100,17 @@ require ( github.com/tklauser/numcpus v0.6.0 // indirect github.com/ugorji/go/codec v1.1.7 // indirect github.com/vektah/gqlparser/v2 v2.5.1 // indirect + github.com/x448/float16 v0.8.4 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/scram v1.1.2 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect - golang.org/x/crypto v0.3.0 // indirect - golang.org/x/net v0.9.0 // indirect + golang.org/x/crypto v0.17.0 // indirect + golang.org/x/net v0.10.0 // indirect golang.org/x/sync v0.1.0 // indirect - golang.org/x/sys v0.8.0 // indirect - golang.org/x/text v0.9.0 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect google.golang.org/protobuf v1.28.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect From d99e6f2f3d49113f238b002a56041acfa979ae58 Mon Sep 17 00:00:00 2001 From: Panda Date: Mon, 22 Jan 2024 11:14:19 +0800 Subject: [PATCH 04/14] feat: fix go mod --- go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/go.mod b/go.mod index 06e1b7b..2322192 100644 --- a/go.mod +++ b/go.mod @@ -65,7 +65,6 @@ require ( github.com/golang-jwt/jwt/v5 v5.2.0 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/golang/snappy v0.0.4 // indirect - github.com/google/go-cmp v0.5.9 // indirect github.com/google/go-tpm v0.9.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/hamba/avro v1.5.6 // indirect From 3cce291c3de4d3f22bdffcd0718ba455a23de237 Mon Sep 17 00:00:00 2001 From: Panda Date: Mon, 22 Jan 2024 11:18:31 +0800 Subject: [PATCH 05/14] feat: update go.mod --- go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/go.mod b/go.mod index b3e1fd2..7483224 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,6 @@ module github.com/everFinance/arseeding go 1.21 -toolchain go1.21.6 require ( github.com/aliyun/aliyun-oss-go-sdk v2.2.6+incompatible From 96ececfc147daa3b8dfdef0918252db5e4c4dc51 Mon Sep 17 00:00:00 2001 From: Panda Date: Mon, 22 Jan 2024 11:21:38 +0800 Subject: [PATCH 06/14] feat: drone update go version --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index e7b5531..9002c6f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -10,7 +10,7 @@ platform: steps: - name: build - image: golang:1.17-buster + image: golang:1.21-buster environment: SSH_KEY: from_secret: ssh_key_github From d52d8272259c59ab189c4477a3e2373b01789afa Mon Sep 17 00:00:00 2001 From: Panda Date: Mon, 22 Jan 2024 11:31:02 +0800 Subject: [PATCH 07/14] feat: update image --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 9002c6f..8beaf13 100644 --- a/.drone.yml +++ b/.drone.yml @@ -10,7 +10,7 @@ platform: steps: - name: build - image: golang:1.21-buster + image: golang:1.21.6-bullseye environment: SSH_KEY: from_secret: ssh_key_github From beec34e1f45f5e9df31bfd0cd6e5c5f683a22938 Mon Sep 17 00:00:00 2001 From: Panda Date: Mon, 22 Jan 2024 15:33:20 +0800 Subject: [PATCH 08/14] feat: update goar --- go.mod | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 7483224..a6abdd8 100644 --- a/go.mod +++ b/go.mod @@ -2,12 +2,11 @@ module github.com/everFinance/arseeding go 1.21 - require ( github.com/aliyun/aliyun-oss-go-sdk v2.2.6+incompatible github.com/aws/aws-sdk-go v1.27.0 github.com/ethereum/go-ethereum v1.10.20 - github.com/everFinance/goar v1.5.8-0.20240119103750-4bb69454cd14 + github.com/everFinance/goar v1.5.8-0.20240122072959-fc10cad2b702 github.com/everFinance/goether v1.1.9 github.com/gin-gonic/gin v1.7.7 github.com/go-co-op/gocron v1.11.0 From 2aec0971938ebf770d4f47df99c9761343cdd0ec Mon Sep 17 00:00:00 2001 From: Panda Date: Tue, 23 Jan 2024 16:33:21 +0800 Subject: [PATCH 09/14] feat: update goar --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index a6abdd8..98486b6 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/aliyun/aliyun-oss-go-sdk v2.2.6+incompatible github.com/aws/aws-sdk-go v1.27.0 github.com/ethereum/go-ethereum v1.10.20 - github.com/everFinance/goar v1.5.8-0.20240122072959-fc10cad2b702 + github.com/everFinance/goar v1.5.8-0.20240123083210-7c84eab0aad8 github.com/everFinance/goether v1.1.9 github.com/gin-gonic/gin v1.7.7 github.com/go-co-op/gocron v1.11.0 From ad2f4cca525bf1a714b4c90096f61df2c9b07d2e Mon Sep 17 00:00:00 2001 From: Panda Date: Tue, 23 Jan 2024 17:01:36 +0800 Subject: [PATCH 10/14] feat: update goar --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 98486b6..6dddfbd 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/aliyun/aliyun-oss-go-sdk v2.2.6+incompatible github.com/aws/aws-sdk-go v1.27.0 github.com/ethereum/go-ethereum v1.10.20 - github.com/everFinance/goar v1.5.8-0.20240123083210-7c84eab0aad8 + github.com/everFinance/goar v1.5.8-0.20240123085808-62661ba6ed60 github.com/everFinance/goether v1.1.9 github.com/gin-gonic/gin v1.7.7 github.com/go-co-op/gocron v1.11.0 From 9e6dc1010d99b02c9fc6e92b24337c6c8e54f972 Mon Sep 17 00:00:00 2001 From: sandy <18382255942@163.com> Date: Thu, 1 Feb 2024 17:19:36 +0800 Subject: [PATCH 11/14] feat(): add bundle everTx payment --- go.mod | 10 ++-------- jobs.go | 15 ++++++++++++--- schema/bundle.go | 6 ++++++ sdk/sdk.go | 16 +++++++++++----- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 6dddfbd..95f25aa 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/aliyun/aliyun-oss-go-sdk v2.2.6+incompatible github.com/aws/aws-sdk-go v1.27.0 github.com/ethereum/go-ethereum v1.10.20 - github.com/everFinance/goar v1.5.8-0.20240123085808-62661ba6ed60 + github.com/everFinance/goar v1.5.8 github.com/everFinance/goether v1.1.9 github.com/gin-gonic/gin v1.7.7 github.com/go-co-op/gocron v1.11.0 @@ -49,7 +49,6 @@ require ( github.com/everFinance/ethrpc v1.0.4 // indirect github.com/everFinance/gojwk v1.0.0 // indirect github.com/everFinance/ttcrsa v1.1.3 // indirect - github.com/fxamacker/cbor/v2 v2.5.0 // indirect github.com/getsentry/sentry-go v0.11.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-ole/go-ole v1.2.6 // indirect @@ -58,12 +57,9 @@ require ( github.com/go-playground/validator/v10 v10.4.1 // indirect github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/go-stack/stack v1.8.1 // indirect - github.com/go-webauthn/webauthn v0.10.0 // indirect - github.com/go-webauthn/x v0.1.6 // indirect - github.com/golang-jwt/jwt/v5 v5.2.0 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/golang/snappy v0.0.4 // indirect - github.com/google/go-tpm v0.9.0 // indirect + github.com/google/go-cmp v0.5.9 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/hamba/avro v1.5.6 // indirect github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac // indirect @@ -77,7 +73,6 @@ require ( github.com/mattn/go-isatty v0.0.17 // indirect github.com/mattn/go-sqlite3 v1.14.5 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect - github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect @@ -97,7 +92,6 @@ require ( github.com/tklauser/numcpus v0.6.0 // indirect github.com/ugorji/go/codec v1.1.7 // indirect github.com/vektah/gqlparser/v2 v2.5.1 // indirect - github.com/x448/float16 v0.8.4 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/scram v1.1.2 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect diff --git a/jobs.go b/jobs.go index c81c58d..cce7436 100644 --- a/jobs.go +++ b/jobs.go @@ -15,7 +15,6 @@ import ( "github.com/everFinance/go-everpay/account" "github.com/everFinance/go-everpay/config" sdkSchema "github.com/everFinance/go-everpay/sdk/schema" - paySchema "github.com/everFinance/go-everpay/token/schema" tokUtils "github.com/everFinance/go-everpay/token/utils" "github.com/everFinance/goar" "github.com/everFinance/goar/types" @@ -204,7 +203,6 @@ func (s *Arseeding) watchEverReceiptTxs() { subTx := s.everpaySdk.Cli.SubscribeTxs(sdkSchema.FilterQuery{ StartCursor: int64(startCursor), Address: s.bundler.Signer.Address, - Action: paySchema.TxActionTransfer, }) defer subTx.Unsubscribe() @@ -219,6 +217,17 @@ func (s *Arseeding) watchEverReceiptTxs() { log.Error("account.IDCheck(tt.From)", "err", err, "from", tt.From) continue } + // decode payment meta + paymentMeta := schema.PaymentMeta{} + if err = json.Unmarshal([]byte(tt.Data), &paymentMeta); err != nil { + log.Error("json.Unmarshal([]byte(tt.Data), &paymentMeta)", "err", err, "everTx", tt.EverHash) + continue + } + newData, err := json.Marshal(paymentMeta) + if err != nil { + log.Error("json.Marshal(paymentMeta)", "err", err, "paymentMeta", paymentMeta) + continue + } res := schema.ReceiptEverTx{ RawId: uint64(tt.RawId), @@ -228,7 +237,7 @@ func (s *Arseeding) watchEverReceiptTxs() { TokenTag: tokUtils.Tag(tt.ChainType, tt.TokenSymbol, tt.TokenID), From: from, Amount: tt.Amount, - Data: tt.Data, + Data: string(newData), Sig: tt.Sig, Status: schema.UnSpent, } diff --git a/schema/bundle.go b/schema/bundle.go index 01cf352..b74b3ca 100644 --- a/schema/bundle.go +++ b/schema/bundle.go @@ -4,3 +4,9 @@ const ( DefaultPaymentExpiredRange = int64(2592000) // 30 days DefaultExpectedRange = 50 // block height range ) + +type PaymentMeta struct { + AppName string `json:"appName"` + Action string `json:"action"` + ItemIds []string `json:"itemIds"` +} diff --git a/sdk/sdk.go b/sdk/sdk.go index b51b25b..861072b 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -156,11 +156,17 @@ func (s *SDK) PayOrders(orders []*arseedSchema.RespOrder) (everTx *paySchema.Tra itemIds = append(itemIds, ord.ItemId) } - payTxData := struct { - AppName string `json:"appName"` - Action string `json:"action"` - ItemIds []string `json:"itemIds"` - }{ + // payTxData := struct { + // AppName string `json:"appName"` + // Action string `json:"action"` + // ItemIds []string `json:"itemIds"` + // }{ + // AppName: "arseeding", + // Action: "payment", + // ItemIds: itemIds, + // } + + payTxData := arseedSchema.PaymentMeta{ AppName: "arseeding", Action: "payment", ItemIds: itemIds, From 483b8169675b589788b11d9acf146e4230d4448c Mon Sep 17 00:00:00 2001 From: sandy <18382255942@163.com> Date: Thu, 1 Feb 2024 17:24:59 +0800 Subject: [PATCH 12/14] feat(): fix bug --- api.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api.go b/api.go index 701e1ec..c75126d 100644 --- a/api.go +++ b/api.go @@ -684,10 +684,10 @@ func (s *Arseeding) getSignData(c *gin.Context) { } if size > schema.AllowStreamMinItemSize { // the body size > schema.AllowStreamMinItemSize, need write to tmp file - item, err = s.bundlerItemSigner.CreateItemStream(dataFile, "", "", tags) + item, err = s.bundlerItemSigner.CreateAndSignItemStream(dataFile, "", "", tags) } else { - item, err = s.bundlerItemSigner.CreateItem(dataBuf.Bytes(), "", "", tags) + item, err = s.bundlerItemSigner.CreateAndSignItem(dataBuf.Bytes(), "", "", tags) } if err != nil { From 670f2da326465f100a43893bd5a48e8f98b4d2e3 Mon Sep 17 00:00:00 2001 From: sandy <18382255942@163.com> Date: Thu, 1 Feb 2024 22:43:56 +0800 Subject: [PATCH 13/14] feat(): add bundle pay sdk and everpay-kits --- arseeding.go | 2 +- go.mod | 71 ++++++++++++++++++++++++++++---------------- jobs.go | 2 +- sdk/manifest.go | 4 +-- sdk/manifest_test.go | 2 +- sdk/schema/sdk.go | 6 ++++ sdk/sdk.go | 62 +++++++++++++++++++++++++------------- 7 files changed, 98 insertions(+), 51 deletions(-) diff --git a/arseeding.go b/arseeding.go index a319034..2283b82 100644 --- a/arseeding.go +++ b/arseeding.go @@ -8,9 +8,9 @@ import ( "github.com/everFinance/arseeding/schema" "github.com/everFinance/arseeding/sdk" "github.com/everFinance/go-everpay/common" - paySdk "github.com/everFinance/go-everpay/sdk" "github.com/everFinance/goar" "github.com/everFinance/goar/types" + paySdk "github.com/everVision/everpay-kits/sdk" "github.com/gin-gonic/gin" "github.com/go-co-op/gocron" "os" diff --git a/go.mod b/go.mod index 95f25aa..36e81cc 100644 --- a/go.mod +++ b/go.mod @@ -1,14 +1,16 @@ module github.com/everFinance/arseeding -go 1.21 +go 1.21.1 + +toolchain go1.21.5 require ( github.com/aliyun/aliyun-oss-go-sdk v2.2.6+incompatible github.com/aws/aws-sdk-go v1.27.0 - github.com/ethereum/go-ethereum v1.10.20 + github.com/ethereum/go-ethereum v1.13.5 github.com/everFinance/goar v1.5.8 github.com/everFinance/goether v1.1.9 - github.com/gin-gonic/gin v1.7.7 + github.com/gin-gonic/gin v1.8.1 github.com/go-co-op/gocron v1.11.0 github.com/google/uuid v1.5.0 github.com/gorilla/handlers v1.4.2 @@ -19,7 +21,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/tidwall/gjson v1.14.4 github.com/ulule/limiter/v3 v3.10.0 - github.com/urfave/cli/v2 v2.24.4 + github.com/urfave/cli/v2 v2.25.7 go.etcd.io/bbolt v1.3.6 gopkg.in/h2non/gentleman.v2 v2.0.5 gorm.io/datatypes v1.0.1 @@ -33,6 +35,7 @@ require ( github.com/allegro/bigcache/v3 v3.1.0 github.com/everFinance/go-everpay v0.2.0 github.com/everFinance/goarns v0.0.3 + github.com/everVision/everpay-kits v0.0.6-0.20240201142725-21cc7715d94d github.com/segmentio/kafka-go v0.4.40 go.mongodb.org/mongo-driver v1.11.4 ) @@ -40,70 +43,88 @@ require ( require ( github.com/StackExchange/wmi v1.2.1 // indirect github.com/beorn7/perks v1.0.1 // indirect + github.com/bits-and-blooms/bitset v1.7.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/btcsuite/btcd/btcutil v1.1.3 // indirect - github.com/cespare/xxhash/v2 v2.1.2 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/consensys/bavard v0.1.13 // indirect + github.com/consensys/gnark-crypto v0.12.1 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect + github.com/ethereum/c-kzg-4844 v0.4.0 // indirect github.com/everFinance/ethrpc v1.0.4 // indirect github.com/everFinance/gojwk v1.0.0 // indirect github.com/everFinance/ttcrsa v1.1.3 // indirect - github.com/getsentry/sentry-go v0.11.0 // indirect + github.com/fxamacker/cbor/v2 v2.5.0 // indirect + github.com/getsentry/sentry-go v0.25.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-ole/go-ole v1.2.6 // indirect - github.com/go-playground/locales v0.13.0 // indirect - github.com/go-playground/universal-translator v0.17.0 // indirect - github.com/go-playground/validator/v10 v10.4.1 // indirect + github.com/go-playground/locales v0.14.0 // indirect + github.com/go-playground/universal-translator v0.18.0 // indirect + github.com/go-playground/validator/v10 v10.11.1 // indirect github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/go-stack/stack v1.8.1 // indirect - github.com/golang/protobuf v1.5.2 // indirect - github.com/golang/snappy v0.0.4 // indirect - github.com/google/go-cmp v0.5.9 // indirect + github.com/go-webauthn/webauthn v0.8.3 // indirect + github.com/go-webauthn/x v0.1.2 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/golang-jwt/jwt/v4 v4.5.0 // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect + github.com/google/go-tpm v0.9.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/hamba/avro v1.5.6 // indirect - github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac // indirect + github.com/holiman/uint256 v1.2.3 // indirect + github.com/inconshreveable/log15 v2.16.0+incompatible // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.4 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/compress v1.15.9 // indirect - github.com/leodido/go-urn v1.2.0 // indirect + github.com/klauspost/compress v1.16.0 // indirect + github.com/leodido/go-urn v1.2.1 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.17 // indirect github.com/mattn/go-sqlite3 v1.14.5 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect + github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect + github.com/pelletier/go-toml/v2 v2.0.5 // indirect github.com/pierrec/lz4/v4 v4.1.15 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/client_model v0.2.0 // indirect + github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a // indirect github.com/prometheus/common v0.32.1 // indirect github.com/prometheus/procfs v0.7.3 // indirect github.com/robfig/cron/v3 v3.0.1 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect + github.com/supranational/blst v0.3.11 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect - github.com/tidwall/sjson v1.2.4 // indirect - github.com/tklauser/go-sysconf v0.3.11 // indirect - github.com/tklauser/numcpus v0.6.0 // indirect - github.com/ugorji/go/codec v1.1.7 // indirect + github.com/tidwall/sjson v1.2.5 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect + github.com/ugorji/go/codec v1.2.7 // indirect github.com/vektah/gqlparser/v2 v2.5.1 // indirect + github.com/x448/float16 v0.8.4 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/scram v1.1.2 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect golang.org/x/crypto v0.17.0 // indirect - golang.org/x/net v0.10.0 // indirect - golang.org/x/sync v0.1.0 // indirect + golang.org/x/net v0.19.0 // indirect + golang.org/x/sync v0.3.0 // indirect golang.org/x/sys v0.15.0 // indirect + golang.org/x/term v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect - golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect - google.golang.org/protobuf v1.28.1 // indirect + golang.org/x/time v0.3.0 // indirect + google.golang.org/protobuf v1.29.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + rsc.io/tmplfunc v0.0.3 // indirect ) diff --git a/jobs.go b/jobs.go index cce7436..0aaf8e0 100644 --- a/jobs.go +++ b/jobs.go @@ -14,11 +14,11 @@ import ( "github.com/everFinance/arseeding/schema" "github.com/everFinance/go-everpay/account" "github.com/everFinance/go-everpay/config" - sdkSchema "github.com/everFinance/go-everpay/sdk/schema" tokUtils "github.com/everFinance/go-everpay/token/utils" "github.com/everFinance/goar" "github.com/everFinance/goar/types" "github.com/everFinance/goar/utils" + sdkSchema "github.com/everVision/everpay-kits/schema" "github.com/google/uuid" "github.com/panjf2000/ants/v2" "github.com/shopspring/decimal" diff --git a/sdk/manifest.go b/sdk/manifest.go index 6a3b5f9..777eafb 100644 --- a/sdk/manifest.go +++ b/sdk/manifest.go @@ -4,8 +4,8 @@ import ( "encoding/json" seedSchema "github.com/everFinance/arseeding/schema" "github.com/everFinance/arseeding/sdk/schema" - paySchema "github.com/everFinance/go-everpay/pay/schema" "github.com/everFinance/goar/types" + paySchema "github.com/everVision/everpay-kits/schema" "github.com/panjf2000/ants/v2" "io/ioutil" "mime" @@ -26,7 +26,7 @@ func (s *SDK) UploadFolderAndPay(rootPath string, batchSize int, indexFile strin if err != nil { return } - everTxs, err = s.BatchPayOrders(orders) + everTxs, err = s.BatchPayOrders(orders, nil) return } diff --git a/sdk/manifest_test.go b/sdk/manifest_test.go index ae92205..7f9dc33 100644 --- a/sdk/manifest_test.go +++ b/sdk/manifest_test.go @@ -38,7 +38,7 @@ func TestSDK_UploadFolder(t *testing.T) { t.Log(len(orders)) t.Log("manifestId:", manifestId) // pay fee - everTxs, err := sdk.BatchPayOrders(orders) + everTxs, err := sdk.BatchPayOrders(orders, nil) t.Log("everTx:", everTxs[0].HexHash()) } diff --git a/sdk/schema/sdk.go b/sdk/schema/sdk.go index b02b8ef..7c2ddf3 100644 --- a/sdk/schema/sdk.go +++ b/sdk/schema/sdk.go @@ -7,3 +7,9 @@ type OptionItem struct { Anchor string Tags []types.Tag } + +type Reward struct { + Tag string // token tag + Recipient string + Amount string +} diff --git a/sdk/sdk.go b/sdk/sdk.go index 861072b..3dbb487 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -6,13 +6,14 @@ import ( "fmt" arseedSchema "github.com/everFinance/arseeding/schema" "github.com/everFinance/arseeding/sdk/schema" - paySchema "github.com/everFinance/go-everpay/pay/schema" - paySdk "github.com/everFinance/go-everpay/sdk" "github.com/everFinance/goar" "github.com/everFinance/goar/types" "github.com/everFinance/goar/utils" + paySchema "github.com/everVision/everpay-kits/schema" + paySdk "github.com/everVision/everpay-kits/sdk" "math/big" "os" + "time" ) type SDK struct { @@ -38,23 +39,23 @@ func NewSDK(arseedUrl, payUrl string, signer interface{}) (*SDK, error) { }, nil } -func (s *SDK) SendDataAndPay(data []byte, currency string, option *schema.OptionItem, needSequence bool) (everTx *paySchema.Transaction, itemId string, err error) { +func (s *SDK) SendDataAndPay(data []byte, currency string, option *schema.OptionItem, needSequence bool, rewards []schema.Reward) (everTx *paySchema.Transaction, itemId string, err error) { order, err := s.SendData(data, currency, "", option, needSequence) if err != nil { return } itemId = order.ItemId - everTx, err = s.PayOrders([]*arseedSchema.RespOrder{order}) + everTx, err = s.PayOrders([]*arseedSchema.RespOrder{order}, rewards) return } -func (s *SDK) SendDataStreamAndPay(data *os.File, currency string, option *schema.OptionItem, needSequence bool) (everTx *paySchema.Transaction, itemId string, err error) { +func (s *SDK) SendDataStreamAndPay(data *os.File, currency string, option *schema.OptionItem, needSequence bool, rewards []schema.Reward) (everTx *paySchema.Transaction, itemId string, err error) { order, err := s.SendDataStream(data, currency, "", option, needSequence) if err != nil { return } itemId = order.ItemId - everTx, err = s.PayOrders([]*arseedSchema.RespOrder{order}) + everTx, err = s.PayOrders([]*arseedSchema.RespOrder{order}, rewards) return } @@ -90,9 +91,9 @@ func (s *SDK) SendDataStream(data *os.File, currency string, apikey string, opti return } -func (s *SDK) BatchPayOrders(orders []*arseedSchema.RespOrder) (everTxs []*paySchema.Transaction, err error) { +func (s *SDK) BatchPayOrders(orders []*arseedSchema.RespOrder, rewards []schema.Reward) (everTxs []*paySchema.Transaction, err error) { if len(orders) <= 500 { - everTx, err := s.PayOrders(orders) + everTx, err := s.PayOrders(orders, rewards) if err != nil { return nil, err } @@ -104,7 +105,7 @@ func (s *SDK) BatchPayOrders(orders []*arseedSchema.RespOrder) (everTxs []*paySc end := 500 for { subOrders := orders[start:end] - everTx, err := s.PayOrders(subOrders) + everTx, err := s.PayOrders(subOrders, rewards) if err != nil { return nil, err } @@ -122,7 +123,7 @@ func (s *SDK) BatchPayOrders(orders []*arseedSchema.RespOrder) (everTxs []*paySc return } -func (s *SDK) PayOrders(orders []*arseedSchema.RespOrder) (everTx *paySchema.Transaction, err error) { +func (s *SDK) PayOrders(orders []*arseedSchema.RespOrder, rewards []schema.Reward) (everTx *paySchema.Transaction, err error) { if len(orders) == 0 { return nil, errors.New("order is null") } @@ -156,16 +157,6 @@ func (s *SDK) PayOrders(orders []*arseedSchema.RespOrder) (everTx *paySchema.Tra itemIds = append(itemIds, ord.ItemId) } - // payTxData := struct { - // AppName string `json:"appName"` - // Action string `json:"action"` - // ItemIds []string `json:"itemIds"` - // }{ - // AppName: "arseeding", - // Action: "payment", - // ItemIds: itemIds, - // } - payTxData := arseedSchema.PaymentMeta{ AppName: "arseeding", Action: "payment", @@ -204,7 +195,16 @@ func (s *SDK) PayOrders(orders []*arseedSchema.RespOrder) (everTx *paySchema.Tra return } - everTx, err = s.Pay.Transfer(useTag, totalFee, orders[0].Bundler, string(dataJs)) + if len(rewards) > 0 { + var bundleSigs paySchema.BundleWithSigs + bundleSigs, err = s.assembleEverBundleItems(rewards) + if err != nil { + return + } + everTx, err = s.Pay.BundleWithData(useTag, orders[0].Bundler, totalFee, bundleSigs, string(dataJs)) + } else { + everTx, err = s.Pay.Transfer(useTag, totalFee, orders[0].Bundler, string(dataJs)) + } return } @@ -235,3 +235,23 @@ func (s *SDK) PayApikey(tokenTag string, amount *big.Int) (everHash string, err everHash = everTx.HexHash() return } + +func (s *SDK) assembleEverBundleItems(rewards []schema.Reward) (paySchema.BundleWithSigs, error) { + items := make([]paySchema.BundleItem, 0, len(rewards)) + tokens := s.Pay.GetTokens() + for _, rd := range rewards { + tok, ok := tokens[rd.Tag] + if !ok { + return paySchema.BundleWithSigs{}, errors.New("token tag not exist") + } + items = append(items, paySchema.BundleItem{ + Tag: rd.Tag, + ChainID: tok.ChainID, + From: s.Pay.AccId, + To: rd.Recipient, + Amount: rd.Amount, + }) + } + bundleWithoutSig := paySdk.GenBundle(items, time.Now().Unix()+100) + return s.Pay.SignBundleData(bundleWithoutSig) +} From 4a3b5d0779c230945ac13758149cb4eb6f9b2d95 Mon Sep 17 00:00:00 2001 From: sandy <18382255942@163.com> Date: Thu, 1 Feb 2024 23:00:46 +0800 Subject: [PATCH 14/14] feat(): test --- sdk/sdk_test.go | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/sdk/sdk_test.go b/sdk/sdk_test.go index 12ed3bb..57798a2 100644 --- a/sdk/sdk_test.go +++ b/sdk/sdk_test.go @@ -45,7 +45,7 @@ func TestSDK_SendDataAndPay_RsaSigner(t *testing.T) { tags := []types.Tag{ {"Content-Type", "text"}, } - tx, itemId, err := sdk.SendDataAndPay(data, "usdt", &schema.OptionItem{Tags: tags}, false) // your account must have enough balance in everpay + tx, itemId, err := sdk.SendDataAndPay(data, "usdt", &schema.OptionItem{Tags: tags}, false, nil) // your account must have enough balance in everpay assert.NoError(t, err) t.Log("itemId:", itemId) t.Log(tx.HexHash()) @@ -156,7 +156,41 @@ func TestSDK_SendDataStreamAndPay(t *testing.T) { tags := []types.Tag{ {"Content-Type", "text"}, } - tx, itemId, err := sdk.SendDataStreamAndPay(data, "usdt", &schema.OptionItem{Tags: tags}, false) // your account must have enough balance in everpay + tx, itemId, err := sdk.SendDataStreamAndPay(data, "usdt", &schema.OptionItem{Tags: tags}, false, nil) // your account must have enough balance in everpay + assert.NoError(t, err) + t.Log("itemId:", itemId) + t.Log(tx.HexHash()) +} + +func TestSDK_PayOrders_BundlePay(t *testing.T) { + payUrl := "https://api.everpay.io" + seedUrl := "https://seed-dev.everpay.io" + + eccSigner, err := goether.NewSigner("") + if err != nil { + panic(err) + } + sdk, err := NewSDK(seedUrl, payUrl, eccSigner) + if err != nil { + panic(err) + } + data := []byte("sandy test bundle pay") + tags := []types.Tag{ + {"Content-Type", "text"}, + } + rewards := []schema.Reward{ + { + Tag: "conflux-cfx-0x0000000000000000000000000000000000000000", + Recipient: "cSYOy8-p1QFenktkDBFyRM3cwZSTrQ_J4EsELLho_UE", + Amount: "55024587325649", + }, + { + Tag: "moonbeam-glmr-0x0000000000000000000000000000000000000000", + Recipient: "0xa2026731B31E4DFBa78314bDBfBFDC8cF5F761F8", + Amount: "3417200978720", + }, + } + tx, itemId, err := sdk.SendDataAndPay(data, "usdt", &schema.OptionItem{Tags: tags}, false, rewards) // your account must have enough balance in everpay assert.NoError(t, err) t.Log("itemId:", itemId) t.Log(tx.HexHash())