1
This commit is contained in:
parent
22d8936b85
commit
4b4406070d
@ -5,14 +5,12 @@ import (
|
|||||||
"f5"
|
"f5"
|
||||||
"main/mt"
|
"main/mt"
|
||||||
"main/constant"
|
"main/constant"
|
||||||
|
"main/service"
|
||||||
"jccommon"
|
"jccommon"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"math/big"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const DECIMALS = 18
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
EVENT_NAME_STAKE_CEC = "StakeCec"
|
EVENT_NAME_STAKE_CEC = "StakeCec"
|
||||||
EVENT_NAME_UNSTAKE_CEC = "UnstakeCec"
|
EVENT_NAME_UNSTAKE_CEC = "UnstakeCec"
|
||||||
@ -87,6 +85,25 @@ func (this *stackingCec) saveToDb(ds *f5.DataSet) bool {
|
|||||||
p := jccommon.NewContractStakeAndUnstakeCecPo()
|
p := jccommon.NewContractStakeAndUnstakeCecPo()
|
||||||
if q5.DecodeJson(returnValues, p) == nil {
|
if q5.DecodeJson(returnValues, p) == nil {
|
||||||
decodeJsonOk = true
|
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(
|
dbErr, _, _ := f5.GetGoStyleDb().NewUpsert(
|
||||||
constant.BCEVENT_DB,
|
constant.BCEVENT_DB,
|
||||||
"t_staking_cec_record",
|
"t_staking_cec_record",
|
||||||
@ -104,8 +121,8 @@ func (this *stackingCec) saveToDb(ds *f5.DataSet) bool {
|
|||||||
{"contract_address", strings.ToLower(contractAddress)},
|
{"contract_address", strings.ToLower(contractAddress)},
|
||||||
{"src_idx", q5.ToString(idx)},
|
{"src_idx", q5.ToString(idx)},
|
||||||
{"event_name", eventName},
|
{"event_name", eventName},
|
||||||
{"account_address", p.Account},
|
{"account_address", strings.ToLower(p.Account)},
|
||||||
{"token_address", p.Token},
|
{"token_address", strings.ToLower(p.Token)},
|
||||||
{"amount", p.Amount},
|
{"amount", p.Amount},
|
||||||
{"createtime", createTime},
|
{"createtime", createTime},
|
||||||
{"modifytime", modifyTime},
|
{"modifytime", modifyTime},
|
||||||
@ -113,9 +130,6 @@ func (this *stackingCec) saveToDb(ds *f5.DataSet) bool {
|
|||||||
if dbErr != nil {
|
if dbErr != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !this.apply(idx, eventName, p) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !decodeJsonOk {
|
if !decodeJsonOk {
|
||||||
jccommon.AddDbLog(constant.BCEVENT_DB, "stackingCec", "decodeJsonError",
|
jccommon.AddDbLog(constant.BCEVENT_DB, "stackingCec", "decodeJsonError",
|
||||||
@ -129,84 +143,3 @@ func (this *stackingCec) saveToDb(ds *f5.DataSet) bool {
|
|||||||
}
|
}
|
||||||
return true
|
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
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user