Skip to content

Commit c543de2

Browse files
Merge pull request #90 from everFinance/develop
Develop
2 parents 89c8b15 + 320607d commit c543de2

File tree

11 files changed

+239
-62
lines changed

11 files changed

+239
-62
lines changed

.drone.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ platform:
1010

1111
steps:
1212
- name: build
13-
image: golang:1.17-buster
13+
image: golang:1.21.6-bullseye
1414
environment:
1515
SSH_KEY:
1616
from_secret: ssh_key_github

api.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func (s *Arseeding) runAPI(port string) {
8484
// ANS-104 bundle Data api
8585
v1.GET("/bundle/bundler", s.getBundler)
8686
v1.POST("/bundle/tx/:currency", s.submitItem)
87+
v1.POST("/bundle/tx/signData", s.getSignData)
8788

8889
v1.GET("/bundle/tx/:itemId", s.getItemMeta) // get item meta, without data
8990
v1.GET("/bundle/tx/:itemId/:field", s.getItemField)
@@ -543,6 +544,7 @@ func (s *Arseeding) processApikeySpendBal(currency, apikey string, dataSize int6
543544
return nil
544545
}
545546

547+
// @todo 增加 eid 签名类型支持
546548
func (s *Arseeding) submitItem(c *gin.Context) {
547549
if c.GetHeader("Content-Type") != "application/octet-stream" {
548550
errorResponse(c, "Wrong body type")
@@ -633,6 +635,78 @@ func (s *Arseeding) submitItem(c *gin.Context) {
633635
})
634636
}
635637

638+
func (s *Arseeding) getSignData(c *gin.Context) {
639+
640+
// get all query and assemble tags
641+
queryMap := c.Request.URL.Query()
642+
// query key must include "Content-Type"
643+
if _, ok := queryMap["Content-Type"]; !ok {
644+
errorResponse(c, "Query params must include Content-Type")
645+
return
646+
}
647+
tags := make([]types.Tag, 0, len(queryMap))
648+
for k, values := range queryMap {
649+
for _, val := range values {
650+
tags = append(tags, types.Tag{
651+
Name: k,
652+
Value: val,
653+
})
654+
}
655+
}
656+
657+
if c.Request.Body == nil {
658+
errorResponse(c, "can not submit null native data")
659+
return
660+
}
661+
662+
dataFile, err := os.CreateTemp(schema.TmpFileDir, "arseed-")
663+
if err != nil {
664+
c.Request.Body.Close()
665+
errorResponse(c, err.Error())
666+
return
667+
}
668+
defer func() {
669+
c.Request.Body.Close()
670+
dataFile.Close()
671+
os.Remove(dataFile.Name())
672+
}()
673+
var dataBuf bytes.Buffer
674+
var item types.BundleItem
675+
// write up to schema.AllowMaxNativeDataSize to memory
676+
size, err := setItemData(c, dataFile, &dataBuf)
677+
if err != nil && err != io.EOF {
678+
errorResponse(c, err.Error())
679+
return
680+
}
681+
if size > schema.SubmitMaxSize {
682+
errorResponse(c, schema.ErrDataTooBig.Error())
683+
return
684+
}
685+
686+
if size > schema.AllowStreamMinItemSize { // the body size > schema.AllowStreamMinItemSize, need write to tmp file
687+
item, err = s.bundlerItemSigner.CreateAndSignItemStream(dataFile, "", "", tags)
688+
689+
} else {
690+
item, err = s.bundlerItemSigner.CreateAndSignItem(dataBuf.Bytes(), "", "", tags)
691+
}
692+
693+
if err != nil {
694+
errorResponse(c, "assemble bundle item failed")
695+
log.Error("s.bundlerItemSigner.CreateAndSignItem", "err", err)
696+
return
697+
}
698+
699+
signData, err := utils.BundleItemSignData(item)
700+
if err != nil {
701+
errorResponse(c, "BundleItemSignData failed")
702+
log.Error("BundleItemSignData", "err", err)
703+
return
704+
}
705+
706+
c.JSON(http.StatusOK, string(signData))
707+
708+
}
709+
636710
func (s *Arseeding) submitNativeData(c *gin.Context) {
637711
apiKey := c.GetHeader("X-API-KEY")
638712
if len(apiKey) == 0 {
@@ -846,6 +920,7 @@ func (s *Arseeding) bundleFee(c *gin.Context) {
846920
c.JSON(http.StatusOK, respFee)
847921
}
848922

923+
// @todo 支持用 eid 类型查询订单
849924
func (s *Arseeding) getOrders(c *gin.Context) {
850925
signer := c.Param("signer")
851926
_, signerAddr, err := account.IDCheck(signer)

arseeding.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"github.com/everFinance/arseeding/schema"
99
"github.com/everFinance/arseeding/sdk"
1010
"github.com/everFinance/go-everpay/common"
11-
paySdk "github.com/everFinance/go-everpay/sdk"
1211
"github.com/everFinance/goar"
1312
"github.com/everFinance/goar/types"
13+
paySdk "github.com/everVision/everpay-kits/sdk"
1414
"github.com/gin-gonic/gin"
1515
"github.com/go-co-op/gocron"
1616
"os"

go.mod

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
module github.com/everFinance/arseeding
22

3-
go 1.17
3+
go 1.21.1
4+
5+
toolchain go1.21.5
46

57
require (
68
github.com/aliyun/aliyun-oss-go-sdk v2.2.6+incompatible
79
github.com/aws/aws-sdk-go v1.27.0
8-
github.com/ethereum/go-ethereum v1.10.20
9-
github.com/everFinance/goar v1.5.7
10+
github.com/ethereum/go-ethereum v1.13.5
11+
github.com/everFinance/goar v1.5.8
1012
github.com/everFinance/goether v1.1.9
11-
github.com/gin-gonic/gin v1.7.7
13+
github.com/gin-gonic/gin v1.8.1
1214
github.com/go-co-op/gocron v1.11.0
13-
github.com/google/uuid v1.3.0
15+
github.com/google/uuid v1.5.0
1416
github.com/gorilla/handlers v1.4.2
1517
github.com/mkevac/debugcharts v0.0.0-20191222103121-ae1c48aa8615
1618
github.com/panjf2000/ants/v2 v2.6.0
1719
github.com/prometheus/client_golang v1.12.2
1820
github.com/shopspring/decimal v1.2.0
19-
github.com/stretchr/testify v1.8.2
21+
github.com/stretchr/testify v1.8.4
2022
github.com/tidwall/gjson v1.14.4
2123
github.com/ulule/limiter/v3 v3.10.0
22-
github.com/urfave/cli/v2 v2.24.4
24+
github.com/urfave/cli/v2 v2.25.7
2325
go.etcd.io/bbolt v1.3.6
2426
gopkg.in/h2non/gentleman.v2 v2.0.5
2527
gorm.io/datatypes v1.0.1
@@ -31,79 +33,98 @@ require (
3133
require (
3234
github.com/Khan/genqlient v0.6.0
3335
github.com/allegro/bigcache/v3 v3.1.0
34-
github.com/everFinance/go-everpay v0.1.1
36+
github.com/everFinance/go-everpay v0.2.0
3537
github.com/everFinance/goarns v0.0.3
38+
github.com/everVision/everpay-kits v0.0.6-0.20240201142725-21cc7715d94d
3639
github.com/segmentio/kafka-go v0.4.40
3740
go.mongodb.org/mongo-driver v1.11.4
3841
)
3942

4043
require (
4144
github.com/StackExchange/wmi v1.2.1 // indirect
4245
github.com/beorn7/perks v1.0.1 // indirect
46+
github.com/bits-and-blooms/bitset v1.7.0 // indirect
4347
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
4448
github.com/btcsuite/btcd/btcutil v1.1.3 // indirect
45-
github.com/cespare/xxhash/v2 v2.1.2 // indirect
49+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
50+
github.com/consensys/bavard v0.1.13 // indirect
51+
github.com/consensys/gnark-crypto v0.12.1 // indirect
4652
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
53+
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
4754
github.com/davecgh/go-spew v1.1.1 // indirect
4855
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
56+
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
4957
github.com/everFinance/ethrpc v1.0.4 // indirect
5058
github.com/everFinance/gojwk v1.0.0 // indirect
5159
github.com/everFinance/ttcrsa v1.1.3 // indirect
52-
github.com/getsentry/sentry-go v0.11.0 // indirect
60+
github.com/fxamacker/cbor/v2 v2.5.0 // indirect
61+
github.com/getsentry/sentry-go v0.25.0 // indirect
5362
github.com/gin-contrib/sse v0.1.0 // indirect
5463
github.com/go-ole/go-ole v1.2.6 // indirect
55-
github.com/go-playground/locales v0.13.0 // indirect
56-
github.com/go-playground/universal-translator v0.17.0 // indirect
57-
github.com/go-playground/validator/v10 v10.4.1 // indirect
64+
github.com/go-playground/locales v0.14.0 // indirect
65+
github.com/go-playground/universal-translator v0.18.0 // indirect
66+
github.com/go-playground/validator/v10 v10.11.1 // indirect
5867
github.com/go-sql-driver/mysql v1.6.0 // indirect
5968
github.com/go-stack/stack v1.8.1 // indirect
60-
github.com/golang/protobuf v1.5.2 // indirect
61-
github.com/golang/snappy v0.0.4 // indirect
62-
github.com/google/go-cmp v0.5.6 // indirect
69+
github.com/go-webauthn/webauthn v0.8.3 // indirect
70+
github.com/go-webauthn/x v0.1.2 // indirect
71+
github.com/goccy/go-json v0.10.2 // indirect
72+
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
73+
github.com/golang/protobuf v1.5.3 // indirect
74+
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
75+
github.com/google/go-tpm v0.9.0 // indirect
6376
github.com/gorilla/websocket v1.5.0 // indirect
6477
github.com/hamba/avro v1.5.6 // indirect
65-
github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac // indirect
78+
github.com/holiman/uint256 v1.2.3 // indirect
79+
github.com/inconshreveable/log15 v2.16.0+incompatible // indirect
6680
github.com/jinzhu/inflection v1.0.0 // indirect
6781
github.com/jinzhu/now v1.1.4 // indirect
6882
github.com/jmespath/go-jmespath v0.4.0 // indirect
6983
github.com/json-iterator/go v1.1.12 // indirect
70-
github.com/klauspost/compress v1.15.9 // indirect
71-
github.com/leodido/go-urn v1.2.0 // indirect
84+
github.com/klauspost/compress v1.16.0 // indirect
85+
github.com/leodido/go-urn v1.2.1 // indirect
7286
github.com/mattn/go-colorable v0.1.13 // indirect
7387
github.com/mattn/go-isatty v0.0.17 // indirect
7488
github.com/mattn/go-sqlite3 v1.14.5 // indirect
75-
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
89+
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
90+
github.com/mitchellh/mapstructure v1.5.0 // indirect
91+
github.com/mmcloughlin/addchain v0.4.0 // indirect
7692
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
7793
github.com/modern-go/reflect2 v1.0.2 // indirect
7894
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
95+
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
7996
github.com/pierrec/lz4/v4 v4.1.15 // indirect
8097
github.com/pkg/errors v0.9.1 // indirect
8198
github.com/pmezard/go-difflib v1.0.0 // indirect
82-
github.com/prometheus/client_model v0.2.0 // indirect
99+
github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a // indirect
83100
github.com/prometheus/common v0.32.1 // indirect
84101
github.com/prometheus/procfs v0.7.3 // indirect
85102
github.com/robfig/cron/v3 v3.0.1 // indirect
86103
github.com/russross/blackfriday/v2 v2.1.0 // indirect
87104
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
105+
github.com/supranational/blst v0.3.11 // indirect
88106
github.com/tidwall/match v1.1.1 // indirect
89107
github.com/tidwall/pretty v1.2.1 // indirect
90-
github.com/tidwall/sjson v1.2.4 // indirect
91-
github.com/tklauser/go-sysconf v0.3.11 // indirect
92-
github.com/tklauser/numcpus v0.6.0 // indirect
93-
github.com/ugorji/go/codec v1.1.7 // indirect
108+
github.com/tidwall/sjson v1.2.5 // indirect
109+
github.com/tklauser/go-sysconf v0.3.12 // indirect
110+
github.com/tklauser/numcpus v0.6.1 // indirect
111+
github.com/ugorji/go/codec v1.2.7 // indirect
94112
github.com/vektah/gqlparser/v2 v2.5.1 // indirect
113+
github.com/x448/float16 v0.8.4 // indirect
95114
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
96115
github.com/xdg-go/scram v1.1.2 // indirect
97116
github.com/xdg-go/stringprep v1.0.4 // indirect
98117
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
99118
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
100-
golang.org/x/crypto v0.3.0 // indirect
101-
golang.org/x/net v0.9.0 // indirect
102-
golang.org/x/sync v0.1.0 // indirect
103-
golang.org/x/sys v0.8.0 // indirect
104-
golang.org/x/text v0.9.0 // indirect
105-
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
106-
google.golang.org/protobuf v1.28.1 // indirect
119+
golang.org/x/crypto v0.17.0 // indirect
120+
golang.org/x/net v0.19.0 // indirect
121+
golang.org/x/sync v0.3.0 // indirect
122+
golang.org/x/sys v0.15.0 // indirect
123+
golang.org/x/term v0.15.0 // indirect
124+
golang.org/x/text v0.14.0 // indirect
125+
golang.org/x/time v0.3.0 // indirect
126+
google.golang.org/protobuf v1.29.1 // indirect
107127
gopkg.in/yaml.v2 v2.4.0 // indirect
108128
gopkg.in/yaml.v3 v3.0.1 // indirect
129+
rsc.io/tmplfunc v0.0.3 // indirect
109130
)

jobs.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ import (
1414
"github.com/everFinance/arseeding/schema"
1515
"github.com/everFinance/go-everpay/account"
1616
"github.com/everFinance/go-everpay/config"
17-
sdkSchema "github.com/everFinance/go-everpay/sdk/schema"
18-
paySchema "github.com/everFinance/go-everpay/token/schema"
1917
tokUtils "github.com/everFinance/go-everpay/token/utils"
2018
"github.com/everFinance/goar"
2119
"github.com/everFinance/goar/types"
2220
"github.com/everFinance/goar/utils"
21+
sdkSchema "github.com/everVision/everpay-kits/schema"
2322
"github.com/google/uuid"
2423
"github.com/panjf2000/ants/v2"
2524
"github.com/shopspring/decimal"
@@ -71,7 +70,7 @@ func (s *Arseeding) runJobs(bundleInterval int) {
7170
// delete tmp file, one may be repeat request same data,tmp file can be reserve with short time
7271
s.scheduler.Every(2).Minute().SingletonMode().Do(s.deleteTmpFile)
7372

74-
//statistic
73+
// statistic
7574
s.scheduler.Every(1).Minute().SingletonMode().Do(s.UpdateRealTime)
7675
go s.ProduceDailyStatistic()
7776
s.scheduler.Every(1).Day().At("00:01").SingletonMode().Do(s.ProduceDailyStatistic)
@@ -204,7 +203,6 @@ func (s *Arseeding) watchEverReceiptTxs() {
204203
subTx := s.everpaySdk.Cli.SubscribeTxs(sdkSchema.FilterQuery{
205204
StartCursor: int64(startCursor),
206205
Address: s.bundler.Signer.Address,
207-
Action: paySchema.TxActionTransfer,
208206
})
209207
defer subTx.Unsubscribe()
210208

@@ -219,6 +217,17 @@ func (s *Arseeding) watchEverReceiptTxs() {
219217
log.Error("account.IDCheck(tt.From)", "err", err, "from", tt.From)
220218
continue
221219
}
220+
// decode payment meta
221+
paymentMeta := schema.PaymentMeta{}
222+
if err = json.Unmarshal([]byte(tt.Data), &paymentMeta); err != nil {
223+
log.Error("json.Unmarshal([]byte(tt.Data), &paymentMeta)", "err", err, "everTx", tt.EverHash)
224+
continue
225+
}
226+
newData, err := json.Marshal(paymentMeta)
227+
if err != nil {
228+
log.Error("json.Marshal(paymentMeta)", "err", err, "paymentMeta", paymentMeta)
229+
continue
230+
}
222231

223232
res := schema.ReceiptEverTx{
224233
RawId: uint64(tt.RawId),
@@ -228,7 +237,7 @@ func (s *Arseeding) watchEverReceiptTxs() {
228237
TokenTag: tokUtils.Tag(tt.ChainType, tt.TokenSymbol, tt.TokenID),
229238
From: from,
230239
Amount: tt.Amount,
231-
Data: tt.Data,
240+
Data: string(newData),
232241
Sig: tt.Sig,
233242
Status: schema.UnSpent,
234243
}
@@ -1144,7 +1153,7 @@ func (s *Arseeding) ProduceDailyStatistic() {
11441153
var firstOrder schema.Order
11451154
var osc schema.OrderStatistic
11461155
err := s.wdb.Db.Model(&schema.Order{}).First(&firstOrder).Error
1147-
//Not found
1156+
// Not found
11481157
if err != nil {
11491158
return
11501159
}
@@ -1156,7 +1165,7 @@ func (s *Arseeding) ProduceDailyStatistic() {
11561165
}
11571166
end := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
11581167

1159-
//If yesterday's record already exists, return
1168+
// If yesterday's record already exists, return
11601169
if !s.wdb.WhetherExec(schema.TimeRange{Start: end.Add(-24 * time.Hour), End: end}) {
11611170
return
11621171
}

schema/bundle.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ const (
44
DefaultPaymentExpiredRange = int64(2592000) // 30 days
55
DefaultExpectedRange = 50 // block height range
66
)
7+
8+
type PaymentMeta struct {
9+
AppName string `json:"appName"`
10+
Action string `json:"action"`
11+
ItemIds []string `json:"itemIds"`
12+
}

sdk/manifest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"encoding/json"
55
seedSchema "github.com/everFinance/arseeding/schema"
66
"github.com/everFinance/arseeding/sdk/schema"
7-
paySchema "github.com/everFinance/go-everpay/pay/schema"
87
"github.com/everFinance/goar/types"
8+
paySchema "github.com/everVision/everpay-kits/schema"
99
"github.com/panjf2000/ants/v2"
1010
"io/ioutil"
1111
"mime"
@@ -26,7 +26,7 @@ func (s *SDK) UploadFolderAndPay(rootPath string, batchSize int, indexFile strin
2626
if err != nil {
2727
return
2828
}
29-
everTxs, err = s.BatchPayOrders(orders)
29+
everTxs, err = s.BatchPayOrders(orders, nil)
3030
return
3131
}
3232

sdk/manifest_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestSDK_UploadFolder(t *testing.T) {
3838
t.Log(len(orders))
3939
t.Log("manifestId:", manifestId)
4040
// pay fee
41-
everTxs, err := sdk.BatchPayOrders(orders)
41+
everTxs, err := sdk.BatchPayOrders(orders, nil)
4242
t.Log("everTx:", everTxs[0].HexHash())
4343
}
4444

0 commit comments

Comments
 (0)