aozhiwei ec71264cad 1
2024-07-21 03:22:21 +08:00

85 lines
1.9 KiB
Go

package activity
import (
"q5"
"f5"
"mt"
"jccommon"
"main/constant"
"github.com/gin-gonic/gin"
"strings"
)
type StackingApi struct {
}
func (this *StackingApi) ExpectedDaily(c *gin.Context) {
accountAddress := strings.ToLower(c.Param("account_address"))
rspObj := struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
ContributionPoint int64 `json:"contribution_point"`
}{
}
nowTime := f5.GetApp().GetRealSeconds()
{
sql := `
SELECT * FROM t_nft WHERE
token_type <> ? AND last_lock_address = ? AND last_lock_time <= ? AND owner_address IN (
`
params := []string{
q5.ToString(jccommon.NFT_TYPE_GOLD_BULLION),
accountAddress,
q5.ToString(q5.GetDaySeconds(nowTime, 0)),
}
{
lockMetas := []*mt.Contract{}
mt.Table.Contract.Traverse(func (ele *mt.Contract) bool {
if ele.GetName() == jccommon.CONTRACT_NAME_NFTLock {
q5.AppendSlice(&lockMetas, ele)
}
return true
})
if len(lockMetas)<= 0 {
c.JSON(200, rspObj)
return
}
inited := false
for _, lockMeta := range lockMetas {
if !inited {
inited = true
sql += "?"
} else {
sql += ",?"
}
q5.AppendSlice(&params, lockMeta.GetAddress())
}
sql += ")"
}
f5.GetGoStyleDb().RawQuery(
constant.BCNFT_DB,
sql,
params,
func (err error, ds *f5.DataSet) {
if err != nil {
c.JSON(200, rspObj)
return
}
nfts := []*jccommon.NftStacking{}
for ds.Next() {
p := new(jccommon.NftStacking)
p.NetId = q5.ToInt32(ds.GetByName("net_id"))
p.ContractAddress = ds.GetByName("contract_address")
p.TokenType = q5.ToInt32(ds.GetByName("token_type"))
p.TokenId = ds.GetByName("token_id")
p.ItemId = q5.ToInt32(ds.GetByName("item_id"))
p.Quality = q5.ToInt32(ds.GetByName("quality"))
q5.AppendSlice(&nfts, p)
}
rspObj.ContributionPoint = jccommon.CalcContributionScore(nfts)
c.JSON(200, rspObj)
})
}
}