This commit is contained in:
aozhiwei 2024-09-19 14:07:38 +08:00
parent 22d8936b85
commit 4b4406070d

View File

@ -5,14 +5,12 @@ import (
"f5"
"main/mt"
"main/constant"
"main/service"
"jccommon"
"fmt"
"strings"
"math/big"
)
const DECIMALS = 18
const (
EVENT_NAME_STAKE_CEC = "StakeCec"
EVENT_NAME_UNSTAKE_CEC = "UnstakeCec"
@ -87,6 +85,25 @@ func (this *stackingCec) saveToDb(ds *f5.DataSet) bool {
p := jccommon.NewContractStakeAndUnstakeCecPo()
if q5.DecodeJson(returnValues, p) == nil {
decodeJsonOk = true
if eventName == EVENT_NAME_STAKE_CEC {
if !service.Vip.Add(
p.Account,
p.Amount,
idx,
"escec_stacking",
"stacking_last_src_idx" ) {
return false
}
} else if eventName == EVENT_NAME_UNSTAKE_CEC {
if service.Vip.Add(
p.Account,
"-" + p.Amount,
idx,
"escec_stacking",
"stacking_last_src_idx" ) {
return false
}
}
dbErr, _, _ := f5.GetGoStyleDb().NewUpsert(
constant.BCEVENT_DB,
"t_staking_cec_record",
@ -104,8 +121,8 @@ func (this *stackingCec) saveToDb(ds *f5.DataSet) bool {
{"contract_address", strings.ToLower(contractAddress)},
{"src_idx", q5.ToString(idx)},
{"event_name", eventName},
{"account_address", p.Account},
{"token_address", p.Token},
{"account_address", strings.ToLower(p.Account)},
{"token_address", strings.ToLower(p.Token)},
{"amount", p.Amount},
{"createtime", createTime},
{"modifytime", modifyTime},
@ -113,9 +130,6 @@ func (this *stackingCec) saveToDb(ds *f5.DataSet) bool {
if dbErr != nil {
return false
}
if !this.apply(idx, eventName, p) {
return false
}
}
if !decodeJsonOk {
jccommon.AddDbLog(constant.BCEVENT_DB, "stackingCec", "decodeJsonError",
@ -129,84 +143,3 @@ func (this *stackingCec) saveToDb(ds *f5.DataSet) bool {
}
return true
}
func (this *stackingCec) apply(idx int64, eventName string,
p *jccommon.ContractStakeAndUnstakeCecPo) bool {
bnAmount, ok := new(big.Int).SetString(p.Amount, 10)
if !ok {
return false
}
if eventName == EVENT_NAME_STAKE_CEC {
} else if eventName == EVENT_NAME_UNSTAKE_CEC {
bnAmount = big.NewInt(0).Sub(big.NewInt(0), bnAmount)
} else {
return false
}
srcAmount := "0"
srcGrowthValue := "0"
{
dbErr, ds := f5.GetGoStyleDb().NewOrmSelect(
constant.BCNFT_DB,
"t_staking_cec",
[][]string{
{"account_address", strings.ToLower(p.Account)},
{"token_address", strings.ToLower(p.Token)},
},
)
if dbErr != nil {
return false
}
if ds.Next() {
if idx <= q5.ToInt64(ds.GetByName("last_apply_record_idx")) {
return true
}
srcAmount = ds.GetByName("amount")
srcGrowthValue = ds.GetByName("growth_value")
}
}
bnNewAmount, ok := new(big.Int).SetString(srcAmount, 10)
if !ok {
return false
}
bnNewGrowthValue, ok := new(big.Int).SetString(srcGrowthValue, 10)
if !ok {
return false
}
var growthValueInt64 = bnNewGrowthValue.Rsh(bnNewGrowthValue, DECIMALS).Int64()
newVipLv := this.calcVipLv(growthValueInt64)
bnNewAmount.Add(bnNewAmount, bnAmount)
{
nowTime := f5.GetApp().GetRealSeconds()
dbErr, _, _ := f5.GetGoStyleDb().NewUpsert(
constant.BCNFT_DB,
"t_staking_cec",
[][]string{
{"account_address", strings.ToLower(p.Account)},
{"token_address", strings.ToLower(p.Token)},
},
[][]string{
{"amount", bnNewAmount.String()},
{"growth_value", bnNewGrowthValue.String()},
{"growth_value_int64", q5.ToString(growthValueInt64)},
{"vip_lv", q5.ToString(newVipLv)},
{"last_apply_record_idx", q5.ToString(idx)},
{"modifytime", q5.ToString(nowTime)},
},
[][]string{
{"account_address", strings.ToLower(p.Account)},
{"token_address", strings.ToLower(p.Token)},
{"amount", bnNewAmount.String()},
{"growth_value", bnNewGrowthValue.String()},
{"growth_value_int64", q5.ToString(growthValueInt64)},
{"vip_lv", q5.ToString(newVipLv)},
{"last_apply_record_idx", q5.ToString(idx)},
{"createtime", q5.ToString(nowTime)},
{"modifytime", q5.ToString(nowTime)},
})
return dbErr == nil
}
}
func (this *stackingCec) calcVipLv(growthValue int64) int32 {
return 0
}