Commit b479cbf5 authored by 贾浩@五瓣科技's avatar 贾浩@五瓣科技

update api

parent e52d8129
......@@ -34,7 +34,7 @@ func getWorkload(c *gin.Context) {
return
}
utcNow := time.Now().UTC()
if t.After(time.Date(utcNow.Year(), utcNow.Month(), utcNow.Day(), 0, 0, 0, 0, time.UTC)) {
if t.After(time.Date(utcNow.Year(), utcNow.Month(), utcNow.Day(), 0, 0, 0, 0, time.UTC).Add(time.Hour * 24)) {
c.JSON(200, withError(DateOutOfRange))
return
}
......@@ -110,6 +110,21 @@ func getRecord(c *gin.Context) {
c.Data(200, "application/json", data)
}
func getWithdrawProof(c *gin.Context) {
address := c.Query("address")
if !common.IsHexAddress(address) || len(address) != 42 {
c.JSON(200, withError(InvalidParams))
return
}
amount, proofs := validator.GetMerkleProof(common.HexToAddress(address), "")
c.JSON(200, withSuccess(gin.H{
"amount": amount,
"proofs": proofs,
}))
}
func withSuccess(data interface{}) interface{} {
return map[string]interface{}{
"code": 0,
......
......@@ -9,4 +9,9 @@ func initRouter(engine *gin.Engine) {
g.POST("/workload", getWorkload)
g.POST("/reward", getReward)
g.POST("/record", getRecord)
proof := g.Group("/proof")
{
proof.POST("/withdraw", getWithdrawProof)
}
}
\ No newline at end of file
......@@ -67,7 +67,7 @@ func RunValidator(q *quest.Quest, cfg *conf.Config) *Validator {
<-time.After(time.Second * 3)
if v.date != "" {
// 当前5号,假设db 1号
// v.date = 1, 2,需要处理的是 2,3号
// v.date = 1或2时,需要处理的是 2或3号
for v.dateToTimestamp(v.date) < v.yesterdayTimestamp()-86400 {
if err = v.SyncDayJob(v.dateToTimestamp(v.date)+86400, true); err != nil {
return nil
......
# Validator for AIGIC
定时扫描昨天(UTC+0)的任务,验证签名,写入statedb,将昨日工作量/奖励生成merkle sum tree,将历史总奖励生成merkle tree,提交到合约
## leveldb kv
merkle sum tree:
......@@ -27,4 +28,3 @@ state:
sroot:2020-01-01 -> root(32bytes)
txid:2020-0101 -> txhash(32bytes)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment