199 lines
4.6 KiB
Go
199 lines
4.6 KiB
Go
package event
|
|
|
|
import (
|
|
"f5"
|
|
"fmt"
|
|
"main/common"
|
|
"main/constant"
|
|
|
|
. "main/global"
|
|
"main/mt"
|
|
"net/http"
|
|
"q5"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type EventApi struct {
|
|
}
|
|
|
|
var EVENTYPE = map[string]int32{
|
|
"mint": 1,
|
|
"lock": 2,
|
|
"unlock": 3,
|
|
}
|
|
|
|
func (ea *EventApi) TxQuery(c *gin.Context) {
|
|
netid := q5.SafeToInt32(c.Param("net_id"))
|
|
txhash := strings.ToLower(c.Param("txhash"))
|
|
|
|
rspObj := struct {
|
|
ErrCode int32 `json:"errcode"`
|
|
ErrMsg string `json:"errmsg"`
|
|
Confirmed int32 `json:"confirmed"`
|
|
}{}
|
|
|
|
{
|
|
sql := fmt.Sprintf(`SELECT idx FROM t_blockchain_event WHERE idx > 0 AND txhash = ? AND net_id = %d`, netid)
|
|
params := []string{
|
|
txhash,
|
|
}
|
|
f5.GetGoStyleDb().RawQuery(
|
|
constant.PAY_DB,
|
|
sql,
|
|
params,
|
|
func(err error, ds *f5.DataSet) {
|
|
if err != nil {
|
|
c.JSON(200, rspObj)
|
|
return
|
|
}
|
|
|
|
if ds != nil {
|
|
rspObj.Confirmed = 1
|
|
}
|
|
|
|
c.JSON(200, rspObj)
|
|
})
|
|
}
|
|
}
|
|
|
|
func (ea *EventApi) ActivityQuery(c *gin.Context) {
|
|
account := strings.ToLower(c.Param("account_address"))
|
|
reqJson := struct {
|
|
PageSize interface{} `json:"page_size"`
|
|
Cursor interface{} `json:"cursor"`
|
|
Search struct {
|
|
Name string `json:"name"`
|
|
} `json:"search"`
|
|
Filter struct {
|
|
ItemIds []interface{} `json:"item_ids"`
|
|
} `json:"filter"`
|
|
Sort struct {
|
|
Fields []struct {
|
|
Name string `json:"name"`
|
|
Type interface{} `json:"type"`
|
|
} `json:"fields"`
|
|
} `json:"sort"`
|
|
}{}
|
|
if err := c.ShouldBindJSON(&reqJson); err != nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"errcode": 1,
|
|
"errmsg": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
pageSize := q5.AdjustRangeValue(q5.SafeToInt32(reqJson.PageSize), 1, 20)
|
|
cursor := q5.SafeToInt64(reqJson.Cursor)
|
|
|
|
sql := fmt.Sprintf(`
|
|
SELECT * FROM t_chain_activity
|
|
WHERE idx > %d AND (sender_address = ? OR to_address = ?) `,
|
|
cursor)
|
|
|
|
params := []string{account, account}
|
|
subFilters := []f5.DbQueryFilter{}
|
|
|
|
{
|
|
itemIds := map[int32]int32{}
|
|
if reqJson.Search.Name != "" {
|
|
mt.Table.Item.Search(reqJson.Search.Name, itemIds)
|
|
}
|
|
for _, val := range reqJson.Filter.ItemIds {
|
|
itemId := q5.SafeToInt32(val)
|
|
itemIds[itemId] = 1
|
|
}
|
|
if len(itemIds) > 0 {
|
|
inSub := `item_id IN (`
|
|
i := 0
|
|
for key, _ := range itemIds {
|
|
if i == 0 {
|
|
inSub += q5.ToString(key)
|
|
} else {
|
|
inSub += "," + q5.ToString(key)
|
|
}
|
|
i += 1
|
|
}
|
|
inSub += ")"
|
|
q5.AppendSlice(&subFilters, f5.GetDbFilter().Custom(inSub).And())
|
|
}
|
|
}
|
|
orderBy := " ORDER BY createtime DESC "
|
|
// {
|
|
// for _, val := range reqJson.Sort.Fields {
|
|
// if val.Name == "price" && orderBy == "" {
|
|
// t := q5.SafeToInt32(val.Type)
|
|
// if t < 0 {
|
|
// orderBy = " ORDER BY price_len DESC, price DESC"
|
|
// } else {
|
|
// orderBy = " ORDER BY price_len ASC, price ASC"
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
rspObj := struct {
|
|
ErrCode int32 `json:"errcode"`
|
|
ErrMsg string `json:"errmsg"`
|
|
Page common.StreamPagination `json:"page"`
|
|
Rows []struct {
|
|
Nft interface{} `json:"nft"`
|
|
Type int32 `json:"type"`
|
|
From string `json:"from"`
|
|
To string `json:"to"`
|
|
Date int32 `json:"date"`
|
|
} `json:"rows"`
|
|
}{}
|
|
q5.NewSlice(&rspObj.Rows, 0, 10)
|
|
nfts := []*common.NftDto{}
|
|
|
|
f5.GetGoStyleDb().StreamPageQuery(
|
|
constant.PAY_DB,
|
|
pageSize,
|
|
cursor,
|
|
sql,
|
|
params,
|
|
f5.GetDbFilter().Comp(subFilters...),
|
|
orderBy,
|
|
func(err error, pagination *f5.StreamPagination) {
|
|
rspObj.Page.FillPage(pagination)
|
|
},
|
|
func(ds *f5.DataSet) {
|
|
p := new(common.NftDto)
|
|
p.NetId = q5.ToInt32(ds.GetByName("net_id"))
|
|
p.ContractAddress = ds.GetByName("nft_contract_address")
|
|
p.TokenId = ds.GetByName("token_id")
|
|
p.Payload = map[string]string{}
|
|
if ds.GetByName("is_mint") != "0" {
|
|
p.Payload.(map[string]string)["type"] = "mint"
|
|
} else {
|
|
p.Payload.(map[string]string)["type"] = ds.GetByName("event_name")
|
|
}
|
|
p.Payload.(map[string]string)["to"] = ds.GetByName("to_address")
|
|
p.Payload.(map[string]string)["from"] = ds.GetByName("sender_address")
|
|
p.Payload.(map[string]string)["date"] = ds.GetByName("createtime")
|
|
q5.AppendSlice(&nfts, p)
|
|
})
|
|
GetCacheMgr().GetNfts(nfts)
|
|
{
|
|
for _, val := range nfts {
|
|
p := q5.NewSliceElement(&rspObj.Rows)
|
|
jsonData := val.NftCache.GetJsonData()
|
|
if jsonData != nil {
|
|
if v, ok := jsonData.(map[string]interface{}); ok {
|
|
v := q5.MapClone(v)
|
|
tmpmap := val.Payload.(map[string]string)
|
|
p.Type = EVENTYPE[strings.ToLower(tmpmap["type"])]
|
|
p.To = tmpmap["to"]
|
|
p.From = tmpmap["from"]
|
|
p.Date = q5.SafeToInt32(tmpmap["date"])
|
|
jsonData = v
|
|
}
|
|
}
|
|
p.Nft = jsonData
|
|
}
|
|
}
|
|
c.JSON(200, rspObj)
|
|
}
|