Browse Source

add 区块星链

tags/v2.2.6
DengBiao 2 years ago
parent
commit
6fb025891c
1 changed files with 26 additions and 20 deletions
  1. +26
    -20
      rule/block_star_chain_settlement.go

+ 26
- 20
rule/block_star_chain_settlement.go View File

@@ -59,19 +59,22 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string) (err error)
//initialCoinTotal := zhios_order_relate_utils.StrToFloat64(blockStarChain.InitialCoinTotal) //初始区块币总量
todayPublishCoin := zhios_order_relate_utils.StrToFloat64(blockStarChain.TodayPublishCoin) //今日区块币发行数量(若为0,则按当前每日区块币发行数量)
nowEverydayPublishCoin := zhios_order_relate_utils.StrToFloat64(blockStarChain.NowEverydayPublishCoin) //当前每日区块币发行数量
var publishCoin = todayPublishCoin

//2、判断今日是否有系统销毁
var destroyCoinForSystem string
if todayPublishCoin != 0 && todayPublishCoin != nowEverydayPublishCoin {
destroyCoinForSystem = decimal.NewFromFloat(nowEverydayPublishCoin).Sub(decimal.NewFromFloat(todayPublishCoin)).String()
err := DealDestroyCoin(session, int(enum.SystemDestroy), zhios_order_relate_utils.StrToFloat64(destroyCoinForSystem), enum.SystemDestroy.String(), blockStarChain)
destroyCoinForSystem, _ := decimal.NewFromFloat(nowEverydayPublishCoin).Sub(decimal.NewFromFloat(todayPublishCoin)).Float64()
if destroyCoinForSystem < 0 {
_ = session.Rollback()
return errors.New("当前\"今日区块币发行数量\"大于\"当前每日区块币发行数量\"")
}
err := DealDestroyCoin(session, int(enum.SystemDestroy), destroyCoinForSystem, enum.SystemDestroy.String(), blockStarChain)
if err != nil {
_ = session.Rollback()
return err
}
publishCoin = nowEverydayPublishCoin
}
var publishCoin = nowEverydayPublishCoin

//3、进行系统区块币发放
err = dealIssueCoin(session, int(enum.SystemTimingIssue), publishCoin, enum.SystemTimingIssue.String(), blockStarChain)
@@ -147,14 +150,14 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string) (err error)
return err
}

//6、计算当前每日区块币应发行数量
//9、计算当前每日区块币应发行数量
err = calcNowEverydayPublishCoin(session, *blockStarChain)
if err != nil {
_ = session.Rollback()
return err
}

//7、更新 block_star_chain 中的 settlement_date 字段
//10、更新 block_star_chain 中的 settlement_date 字段
blockStarChain.SettlementDate = today
updateAffected, err := db.BlockStarChainUpdate(session, blockStarChain.Id, blockStarChain, "settlement_date")
if err != nil {
@@ -166,7 +169,7 @@ func DailySettlementBlockStarChain(engine *xorm.Engine, mid string) (err error)
return errors.New("更新 block_star_chain 的 settlement_date 记录失败")
}

//8、将昨日的“平台区块币指导价”插入到 block_coin_platform_guide_price_for_coin_records
//11、将昨日的“平台区块币指导价”插入到 block_coin_platform_guide_price_for_coin_records
var blockCoinPlatformGuidePriceForCoinRecords = model.BlockCoinPlatformGuidePriceForCoinRecords{
CoinId: blockStarChain.Coin1,
PlatformGuidePriceForCoin: blockStarChain.PlatformGuidePriceForCoin,
@@ -444,7 +447,10 @@ func statisticsAndDistributeCoinForOther(session *xorm.Session, mid string, publ
//计算当前每日区块币应发行数量
func calcNowEverydayPublishCoin(session *xorm.Session, chain model.BlockStarChain) error {
now := time.Now()
startAt := zhios_order_relate_utils.String2Time(chain.StartAt) //起始时间
startAt, err := time.ParseInLocation("2006-01-02", chain.StartAt, time.Local) //起始时间
if err != nil {
return err
}
diffDays := zhios_order_relate_utils.GetDiffDays(now, startAt) //相差天数
remainder := diffDays % 30
if remainder == 0 {
@@ -475,11 +481,11 @@ func dealIssueCoin(session *xorm.Session, kind int, amount float64, title string
switch kind {
case int(enum.SystemTimingIssue):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
blockStarChainFlow.AfterTotalNowCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalRemainderCoin) + amount)
blockStarChainFlow.AfterTotalNowCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalNowCoin) + amount)
blockStarChainFlow.BeforeTotalRemainderCoin = chain.TotalRemainderCoin
blockStarChainFlow.AfterTotalRemainderCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalRemainderCoin) - amount)
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalRemainderCoin) + amount)
blockStarChainFlow.AfterTotalPublishCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalPublishCoin) + amount)
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = chain.TotalDestroyCoin
break
@@ -525,7 +531,7 @@ func DealDestroyCoin(session *xorm.Session, kind int, amount float64, title stri
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalRemainderCoin) + amount)
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
break
case int(enum.StaticUnallocatedAndDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
@@ -535,7 +541,7 @@ func DealDestroyCoin(session *xorm.Session, kind int, amount float64, title stri
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalRemainderCoin) + amount)
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
break
case int(enum.DynamicallyUnallocatedAndDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
@@ -545,7 +551,7 @@ func DealDestroyCoin(session *xorm.Session, kind int, amount float64, title stri
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalRemainderCoin) + amount)
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
break
case int(enum.OperationCenterUnallocatedAndDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
@@ -555,7 +561,7 @@ func DealDestroyCoin(session *xorm.Session, kind int, amount float64, title stri
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalRemainderCoin) + amount)
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
break
case int(enum.OtherUnallocatedAndDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
@@ -565,7 +571,7 @@ func DealDestroyCoin(session *xorm.Session, kind int, amount float64, title stri
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalRemainderCoin) + amount)
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
break
case int(enum.RewardDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
@@ -575,7 +581,7 @@ func DealDestroyCoin(session *xorm.Session, kind int, amount float64, title stri
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalRemainderCoin) + amount)
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
break
case int(enum.RewardUnallocatedAndDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
@@ -585,7 +591,7 @@ func DealDestroyCoin(session *xorm.Session, kind int, amount float64, title stri
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalRemainderCoin) + amount)
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
break
case int(enum.GroupLotteryAndDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
@@ -595,7 +601,7 @@ func DealDestroyCoin(session *xorm.Session, kind int, amount float64, title stri
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalRemainderCoin) + amount)
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
break
case int(enum.RedEnvelopeTransferBalanceAndDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
@@ -605,7 +611,7 @@ func DealDestroyCoin(session *xorm.Session, kind int, amount float64, title stri
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalRemainderCoin) + amount)
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
break
case int(enum.TransferFeeAndDestroy):
blockStarChainFlow.BeforeTotalNowCoin = chain.TotalNowCoin
@@ -615,7 +621,7 @@ func DealDestroyCoin(session *xorm.Session, kind int, amount float64, title stri
blockStarChainFlow.BeforeTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.AfterTotalPublishCoin = chain.TotalPublishCoin
blockStarChainFlow.BeforeTotalDestroyCoin = chain.TotalDestroyCoin
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalRemainderCoin) + amount)
blockStarChainFlow.AfterTotalDestroyCoin = zhios_order_relate_utils.Float64ToStrPrec10(zhios_order_relate_utils.StrToFloat64(chain.TotalDestroyCoin) + amount)
break
}



Loading…
Cancel
Save