75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
package task
|
|
|
|
import (
|
|
"q5"
|
|
"f5"
|
|
"main/mt"
|
|
"main/constant"
|
|
"jccommon"
|
|
"fmt"
|
|
)
|
|
|
|
const VESTER_DEPOSIT_EVENT_NAME = "Deposit"
|
|
const VESTER_WITHDRAW_EVENT_NAME = "Withdraw"
|
|
|
|
/*
|
|
Deposit amount his_amount 衰减,最后的存覆盖之前的
|
|
Withdraw 所有
|
|
|
|
按时间排序处理事件的先后顺序
|
|
|
|
通过Vester.sol的remainingEsToken方法获取, 如果要本地计算的话, 那就取每次Deposit事件的时间和amount, 加上先前的转换的余额, 再按total * (now - deposit_time) / (365 * 24 * 2600)
|
|
*/
|
|
type vester struct {
|
|
|
|
}
|
|
|
|
func (this *vester) init() {
|
|
mt.Table.Contract.Traverse(func (ele *mt.Contract) bool {
|
|
if ele.GetName() == jccommon.CONTRACT_NAME_Vester {
|
|
go this.process(ele.GetNetId(), ele.GetAddress())
|
|
}
|
|
return true
|
|
})
|
|
}
|
|
|
|
func (this *vester) unInit() {
|
|
}
|
|
|
|
func (this *vester) process(netId int32, contractAddress string) {
|
|
key := fmt.Sprintf("vester.depositAndWithdraw.lastIdx.%d.%s", netId, contractAddress)
|
|
if dbLastIdxStr, err := jccommon.GetDbParam(constant.BCEVENT_DB, key); err == nil {
|
|
f5.GetGoStyleDb().IncrementLoad(
|
|
constant.BCEVENT_DB,
|
|
"vester.depositAndWithdraw." + q5.ToString(netId) + "." + contractAddress,
|
|
"t_blockchain_event",
|
|
q5.ToInt64(dbLastIdxStr),
|
|
func (lastIdx int64, maxIdx int64) (string, []string) {
|
|
sql := fmt.Sprintf(`
|
|
SELECT * FROM t_blockchain_event
|
|
WHERE idx > %d AND idx <= %d AND net_id = %d AND contract_address = ? AND event_name IN (?, ?)
|
|
ORDER BY idx LIMIT 1000
|
|
`,
|
|
lastIdx,
|
|
maxIdx,
|
|
netId)
|
|
params := []string{
|
|
contractAddress,
|
|
"Deposit",
|
|
"Withdraw",
|
|
}
|
|
return sql, params
|
|
},
|
|
func (newLastIdx int64) {
|
|
jccommon.SaveDbParam(constant.BCEVENT_DB, key, q5.ToString(newLastIdx))
|
|
},
|
|
this.saveToDb)
|
|
} else {
|
|
panic(fmt.Sprintf("vester.depositAndWithdraw getDBParam error %s", err))
|
|
}
|
|
}
|
|
|
|
func (this* vester) saveToDb(ds *f5.DataSet) bool {
|
|
return true
|
|
}
|