Skip to content

Commit

Permalink
add GetRedEnvelopeUsers and update go version
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobeyw committed Feb 2, 2024
1 parent 5cfc948 commit db8cce6
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 7 deletions.
2 changes: 1 addition & 1 deletion neo3fura_http/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17
FROM golang:1.21

ENV GO111MODULE="on"

Expand Down
161 changes: 161 additions & 0 deletions neo3fura_http/biz/api/re.GetRedEnvelopeUsers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package api

import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/joeqian10/neo3-gogogo/crypto"
"github.com/joeqian10/neo3-gogogo/helper"
"github.com/joeqian10/neo3-gogogo/rpc"
"github.com/joeqian10/neo3-gogogo/sc"
"go.mongodb.org/mongo-driver/bson/primitive"
log2 "neo3fura_http/lib/log"
"neo3fura_http/lib/type/Contract"
"neo3fura_http/lib/type/h160"
"neo3fura_http/var/stderr"
"os"

"go.mongodb.org/mongo-driver/bson"
)

func (me *T) GetRedEnvelopeUsers(args struct {
Asset h160.T
StartTime uint64
EndTime uint64
Filter map[string]interface{}
Raw *[]map[string]interface{}
}, ret *json.RawMessage) error {
if args.Asset.Valid() == false {
return stderr.ErrInvalidArgs
}

if args.EndTime < args.StartTime {
return stderr.ErrInvalidArgs
}
rt := os.ExpandEnv("${RUNTIME}")
NetEndPoint := "http://seed2.neo.org:10332"
nnsContract := Contract.Test_NNS
switch rt {
case "test":
NetEndPoint = "http://seed2t5.neo.org:20332"
nnsContract = Contract.Test_NNS
case "test2":
NetEndPoint = "http://seed2t5.neo.org:20332"
nnsContract = Contract.Test_NNS
case "staging":
NetEndPoint = "http://seed2.neo.org:10332"
nnsContract = Contract.Main_NNS
default:
log2.Fatalf("runtime environment mismatch")
}

flag, err := isExpiresNNS(NetEndPoint, nnsContract, "Y3J5cHRvem9tYmllLm5lbw==")
fmt.Println(flag, err)
r1, err := me.Client.QueryAggregate(struct {
Collection string
Index string
Sort bson.M
Filter bson.M
Pipeline []bson.M
Query []string
}{Collection: "Nep11TransferNotification",
Index: "GetRedEnvelopeUsers",
Sort: bson.M{},
Filter: bson.M{},
Pipeline: []bson.M{
bson.M{"$match": bson.M{"contract": args.Asset,
"$and": []interface{}{
bson.M{"timestamp": bson.M{"$gte": args.StartTime}},
bson.M{"timestamp": bson.M{"$lte": args.EndTime}},
}}},

bson.M{"$lookup": bson.M{
"from": "Address-Asset",
"let": bson.M{"to": "$to"},
"pipeline": []bson.M{
bson.M{"$match": bson.M{"asset": nnsContract.Val(), "$expr": bson.M{"$and": []interface{}{
bson.M{"$eq": []interface{}{"$address", "$$to"}},
}}}},
bson.M{"$project": bson.M{"asset": 1, "tokenid": 1, "address": 1}}, // bson.M{"$eq": []interface{}{"$address", "$$to"}},
},
"as": "nns"},
},

bson.M{"$group": bson.M{"_id": "$tokenId", "transferList": bson.M{"$push": "$$ROOT"}}},
bson.M{"$sort": bson.M{"from": 1}},
},
Query: []string{},
}, ret)
if err != nil {
return err
}

result := make(map[string]interface{})
for _, item := range r1 {
var minter string
var minterInfo []primitive.A
transferList := item["transferList"].(primitive.A)
if len(transferList) > 1 {
for _, transfer := range transferList {
transferItem := transfer.(map[string]interface{})
if transferItem["from"] == nil { //mint
minter = transferItem["to"].(string)
if transferItem["nns"] != nil {
nnsList := transferItem["nns"].(primitive.A)
for _, nns := range nnsList {
nnsItem := nns.(map[string]interface{})
tokenid, err := base64.URLEncoding.DecodeString(nnsItem["tokenid"].(string))
if err != nil {
return fmt.Errorf("tokenid base64.URLEncoding.DecodeString error %s", err)
}
isExpired, _ := isExpiresNNS(NetEndPoint, nnsContract, string(tokenid))
if isExpired {
minterInfo = append(minterInfo, transferList)
goto endfor
}
}
}
}

}
endfor:
}
result[minter] = minterInfo
}

//r2, err := me.FilterArrayAndAppendCount(result, 0, args.Filter)
r2, err := me.Filter(result, args.Filter)
if err != nil {
return err
}

r, err := json.Marshal(r2)
if err != nil {
return err
}
*ret = json.RawMessage(r)
return nil
}

func isExpiresNNS(endPoint string, contract Contract.T, nns string) (bool, error) {
client := rpc.NewClient(endPoint)
sb := sc.NewScriptBuilder()
sh, err := helper.UInt160FromString(contract.Val())
if err != nil {
return false, err
}
var arg = []interface{}{nns}
sb.EmitDynamicCall(sh, "ownerOf", arg)
script, err := sb.ToArray()
if err != nil {
return false, err
}

response := client.InvokeScript(crypto.Base64Encode(script), nil)
if response.Result.State == "HALT" {
return true, nil
} else {
return false, nil
}
return false, nil
}
1 change: 1 addition & 0 deletions neo3fura_http/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,5 @@ var Apis = []string{
"GetNFTByAssetClassPrimaryMarket",
"GetInfoByNFTPrimaryMarket",
"GetMarketCollectionWhitelist",
"GetRedEnvelopeUsers",
}
2 changes: 1 addition & 1 deletion neo3fura_http/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module neo3fura_http

go 1.17
go 1.21.3

require (
github.com/go-redis/redis/v8 v8.11.3
Expand Down
2 changes: 1 addition & 1 deletion neo3fura_ws/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.15.6
FROM golang:1.21

ENV GO111MODULE="on"

Expand Down
19 changes: 15 additions & 4 deletions neo3fura_ws/go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
module neo3fura_ws

go 1.15
go 1.21

require (
github.com/google/go-cmp v0.5.6 // indirect
github.com/gorilla/websocket v1.4.2
github.com/stretchr/testify v1.7.0 // indirect
go.mongodb.org/mongo-driver v1.7.1
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/go-stack/stack v1.8.0 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/klauspost/compress v1.9.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.0.2 // indirect
github.com/xdg-go/stringprep v1.0.2 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

0 comments on commit db8cce6

Please sign in to comment.