Commit 22ca51dd authored by jixing wei's avatar jixing wei Committed by vipwzw

remove float

parent 71f5a595
......@@ -49,7 +49,7 @@ const (
const (
luckyNumMol = 100000
decimal = 100000000 //1e8
decimal = types.Coin //1e8
blockNum = 5
)
......@@ -177,7 +177,7 @@ func (action *Action) GetBuyReceiptLog(lottery *pty.Lottery, preStatus int32, ro
// GetDrawReceiptLog generate logs for lottery draw action
func (action *Action) GetDrawReceiptLog(lottery *pty.Lottery, preStatus int32, round int64, luckyNum int64, updateInfo *pty.LotteryUpdateBuyInfo, addrNumThisRound int64, buyAmountThisRound int64, gainInfos *pty.LotteryGainInfos,
luckyAddrNum int64, totalFund int64, factor float64) *types.ReceiptLog {
luckyAddrNum int64, totalFund int64, factor int64) *types.ReceiptLog {
log := &types.ReceiptLog{}
log.Ty = pty.TyLogLotteryDraw
......@@ -191,7 +191,7 @@ func (action *Action) GetDrawReceiptLog(lottery *pty.Lottery, preStatus int32, r
l.BuyAmount = buyAmountThisRound
l.LuckyAddrNum = luckyAddrNum
l.TotalFund = totalFund
l.Factor = float32(factor)
l.Factor = factor
if len(updateInfo.BuyInfo) > 0 {
l.UpdateInfo = updateInfo
}
......@@ -578,7 +578,7 @@ func checkFundAmount(luckynum int64, guessnum int64, way int64) (int64, int64) {
}
}
func (action *Action) checkDraw(lott *LotteryDB) (*types.Receipt, *pty.LotteryUpdateBuyInfo, *pty.LotteryGainInfos, int64, int64, float64, error) {
func (action *Action) checkDraw(lott *LotteryDB) (*types.Receipt, *pty.LotteryUpdateBuyInfo, *pty.LotteryGainInfos, int64, int64, int64, error) {
luckynum, err := action.findLuckyNum(false, lott)
if luckynum < 0 || luckynum >= luckyNumMol {
return nil, nil, nil, 0, 0, 0, err
......@@ -616,35 +616,27 @@ func (action *Action) checkDraw(lott *LotteryDB) (*types.Receipt, *pty.LotteryUp
}
llog.Debug("checkDraw", "lenofupdate", len(updateInfo.BuyInfo), "update", updateInfo.BuyInfo)
var factor = 1.0
var factor = decimal
if totalFund > 0 {
if totalFund > lott.GetFund()/2 {
llog.Debug("checkDraw ajust fund", "lott.Fund", lott.Fund, "totalFund", totalFund)
factor = (float64)(lott.GetFund()) / 2 / (float64)(totalFund)
factor = decimal * (lott.GetFund()) / 2 / (totalFund)
lott.Fund = lott.Fund / 2
} else {
factor = 1.0
lott.Fund -= totalFund
}
llog.Debug("checkDraw", "factor", factor, "totalFund", totalFund)
//protection for rollback
if factor == 1.0 {
if !action.CheckExecAccount(lott.CreateAddr, totalFund, true) {
return nil, nil, nil, 0, 0, 0, pty.ErrLotteryFundNotEnough
}
} else {
if !action.CheckExecAccount(lott.CreateAddr, decimal*lott.Fund/2+1, true) {
return nil, nil, nil, 0, 0, 0, pty.ErrLotteryFundNotEnough
}
if !action.CheckExecAccount(lott.CreateAddr, factor*totalFund+1, true) {
return nil, nil, nil, 0, 0, 0, pty.ErrLotteryFundNotEnough
}
for _, recs := range lott.PurRecords {
if recs.FundWin > 0 {
fund := (recs.FundWin * int64(factor*exciting)) * decimal * (rewardBase - lott.OpRewardRatio - lott.DevRewardRatio) / (exciting * rewardBase) //any problem when too little?
fund := (recs.FundWin * factor) * (rewardBase - lott.OpRewardRatio - lott.DevRewardRatio) / rewardBase //any problem when too little?
llog.Debug("checkDraw", "fund", fund)
gain := &pty.LotteryGainInfo{Addr: recs.Addr, BuyAmount: recs.AmountOneRound, FundAmount: float32(fund) / float32(decimal)}
gain := &pty.LotteryGainInfo{Addr: recs.Addr, BuyAmount: recs.AmountOneRound, FundAmount: fund}
gainInfos.Gains = append(gainInfos.Gains, gain)
receipt, err := action.coinsAccount.ExecTransferFrozen(lott.CreateAddr, recs.Addr, action.execaddr, fund)
if err != nil {
......@@ -660,7 +652,7 @@ func (action *Action) checkDraw(lott *LotteryDB) (*types.Receipt, *pty.LotteryUp
}
//op reward
fundOp := int64(factor*decimal) * totalFund * lott.OpRewardRatio / rewardBase
fundOp := factor * totalFund * lott.OpRewardRatio / rewardBase
receipt, err := action.coinsAccount.ExecTransferFrozen(lott.CreateAddr, opRewardAddr, action.execaddr, fundOp)
if err != nil {
return nil, nil, nil, 0, 0, 0, err
......@@ -668,7 +660,7 @@ func (action *Action) checkDraw(lott *LotteryDB) (*types.Receipt, *pty.LotteryUp
kv = append(kv, receipt.KV...)
logs = append(logs, receipt.Logs...)
//dev reward
fundDev := int64(factor*decimal) * totalFund * lott.DevRewardRatio / rewardBase
fundDev := factor * totalFund * lott.DevRewardRatio / rewardBase
receipt, err = action.coinsAccount.ExecTransferFrozen(lott.CreateAddr, devRewardAddr, action.execaddr, fundDev)
if err != nil {
return nil, nil, nil, 0, 0, 0, err
......
......@@ -96,7 +96,7 @@ message ReceiptLottery {
LotteryGainInfos gainInfos = 16;
int64 luckyAddrNum = 17;
int64 totalFund = 18;
float factor = 19;
int64 factor = 19;
}
message ReqLotteryInfo {
......@@ -194,7 +194,7 @@ message LotteryDrawRecord {
int64 buyAmount = 6;
int64 luckyAddrNum = 7;
int64 totalFund = 8;
float factor = 9;
int64 factor = 9;
}
message LotteryDrawRecords {
......@@ -225,13 +225,13 @@ message LotteryGainInfos{
message LotteryGainInfo{
string addr = 1;
int64 buyAmount = 2;
float fundAmount = 3;
int64 fundAmount = 3;
}
message LotteryGainRecord{
string addr = 1;
int64 buyAmount = 2;
float fundAmount = 3;
int64 fundAmount = 3;
int64 round = 4;
}
......
This diff is collapsed.
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