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

remove float

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