diff --git a/server/marketserver/api/v1/activity/stacking.go b/server/marketserver/api/v1/activity/stacking.go index 120adcbe..74bf12e8 100644 --- a/server/marketserver/api/v1/activity/stacking.go +++ b/server/marketserver/api/v1/activity/stacking.go @@ -1,28 +1,27 @@ package activity import ( - "q5" "f5" - "mt" + "fmt" "jccommon" "main/constant" - "github.com/gin-gonic/gin" + "mt" + "q5" "strings" - "fmt" + + "github.com/gin-gonic/gin" ) 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"` + ErrCode int32 `json:"errcode"` + ErrMsg string `json:"errmsg"` ContributionPoint string `json:"contribution_point"` - }{ - } + }{} nowTime := f5.GetApp().GetRealSeconds() { sql := ` @@ -36,13 +35,13 @@ token_type <> ? AND last_lock_address = ? AND last_lock_time <= ? AND owner_addr } { lockMetas := []*mt.Contract{} - mt.Table.Contract.Traverse(func (ele *mt.Contract) bool { + 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 { + if len(lockMetas) <= 0 { c.JSON(200, rspObj) return } @@ -62,7 +61,7 @@ token_type <> ? AND last_lock_address = ? AND last_lock_time <= ? AND owner_addr constant.BCNFT_DB, sql, params, - func (err error, ds *f5.DataSet) { + func(err error, ds *f5.DataSet) { if err != nil { c.JSON(200, rspObj) return @@ -83,3 +82,43 @@ token_type <> ? AND last_lock_address = ? AND last_lock_time <= ? AND owner_addr }) } } + +func (this *StackingApi) ContributionQuery(c *gin.Context) { + accountAddress := strings.ToLower(c.Param("account_address")) + rspObj := struct { + ErrCode int32 `json:"errcode"` + ErrMsg string `json:"errmsg"` + Rows []struct { + Date int32 `json:"date"` + ContributionPoint string `json:"contribution_point"` + } + }{} + + { + sql := `SELECT * FROM t_staking_daily_settlement WHERE account_address = ? ORDER BY settle_date DESC LIMIT 1` + params := []string{ + accountAddress, + } + + f5.GetGoStyleDb().RawQuery( + constant.BCNFT_DB, + sql, + params, + func(err error, ds *f5.DataSet) { + if err != nil { + c.JSON(200, rspObj) + return + } + obj := struct { + Date int32 `json:"date"` + ContributionPoint string `json:"contribution_point"` + }{} + for ds.Next() { + obj.Date = q5.SafeToInt32(ds.GetByName("settle_date")) + obj.ContributionPoint = ds.GetByName("contribution") + rspObj.Rows = append(rspObj.Rows, obj) + } + }) + } + c.JSON(200, rspObj) +} diff --git a/server/marketserver/router/activity/stacking.go b/server/marketserver/router/activity/stacking.go index 793c1064..b07b9197 100644 --- a/server/marketserver/router/activity/stacking.go +++ b/server/marketserver/router/activity/stacking.go @@ -2,7 +2,7 @@ package activity import ( "f5" - "main/api/v1" + v1 "main/api/v1" ) type StackingRouter struct{} @@ -11,4 +11,6 @@ func (this *StackingRouter) InitRouter() { api := v1.ApiGroupApp.ActivityApiGroup f5.GetApp().GetGinEngine().GET("/api/activity/stacking/expected_daily/:account_address", api.StackingApi.ExpectedDaily) + f5.GetApp().GetGinEngine().GET("/api/activity/stacking/history/:account_address", + api.StackingApi.ContributionQuery) }