Skip to content

Commit

Permalink
Merge pull request #90 from everFinance/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
zyjblockchain authored Feb 1, 2024
2 parents 89c8b15 + 320607d commit c543de2
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ platform:

steps:
- name: build
image: golang:1.17-buster
image: golang:1.21.6-bullseye
environment:
SSH_KEY:
from_secret: ssh_key_github
Expand Down
75 changes: 75 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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.CreateAndSignItemStream(dataFile, "", "", tags)

} else {
item, err = s.bundlerItemSigner.CreateAndSignItem(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 {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion arseeding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
85 changes: 53 additions & 32 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
module github.com/everFinance/arseeding

go 1.17
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/everFinance/goar v1.5.7
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.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
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
Expand All @@ -31,79 +33,98 @@ require (
require (
github.com/Khan/genqlient v0.6.0
github.com/allegro/bigcache/v3 v3.1.0
github.com/everFinance/go-everpay v0.1.1
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
)

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.6 // 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.3.0 // indirect
golang.org/x/net v0.9.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/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
google.golang.org/protobuf v1.28.1 // indirect
golang.org/x/crypto v0.17.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.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
)
23 changes: 16 additions & 7 deletions jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +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"
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"
"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"
Expand Down Expand Up @@ -71,7 +70,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)
Expand Down Expand Up @@ -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()

Expand All @@ -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),
Expand All @@ -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,
}
Expand Down Expand Up @@ -1144,7 +1153,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
}
Expand All @@ -1156,7 +1165,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
}
Expand Down
6 changes: 6 additions & 0 deletions schema/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
4 changes: 2 additions & 2 deletions sdk/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
Loading

0 comments on commit c543de2

Please sign in to comment.