Commit 2f8cb126 authored by 张振华's avatar 张振华 Committed by vipwzw

fix-overflow-bug

parent 4b45e6c8
......@@ -6,10 +6,10 @@ package executor
import (
"fmt"
"strings"
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db/table"
"math/big"
"strings"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/common"
......@@ -562,7 +562,7 @@ func (action *Action) GamePublish(publish *gty.GuessGamePublish) (*types.Receipt
return nil, types.ErrInvalidParam
}
game.Result = publish.Result
game.Result = trimStr(publish.Result)
//先遍历所有下注数据,转移资金到Admin账户合约地址;
for i := 0; i < len(game.Plays); i++ {
......@@ -612,7 +612,10 @@ func (action *Action) GamePublish(publish *gty.GuessGamePublish) (*types.Receipt
}
if game.DevFeeFactor > 0 {
devFee = totalBetsNumber / 1000 * game.DevFeeFactor
fee := big.NewInt(totalBetsNumber)
factor := big.NewInt(game.DevFeeFactor)
thousand := big.NewInt(1000)
devFee = fee.Mul(fee, factor).Div(fee, thousand).Int64()
receipt, err := action.coinsAccount.ExecTransfer(game.AdminAddr, devAddr, action.execaddr, devFee)
if err != nil {
//action.coinsAccount.ExecFrozen(game.AdminAddr, action.execaddr, devFee) // rollback
......@@ -625,7 +628,10 @@ func (action *Action) GamePublish(publish *gty.GuessGamePublish) (*types.Receipt
}
if game.PlatFeeFactor > 0 {
platFee = totalBetsNumber / 1000 * game.PlatFeeFactor
fee := big.NewInt(totalBetsNumber)
factor := big.NewInt(game.PlatFeeFactor)
thousand := big.NewInt(1000)
platFee = fee.Mul(fee, factor).Div(fee, thousand).Int64()
receipt, err := action.coinsAccount.ExecTransfer(game.AdminAddr, platAddr, action.execaddr, platFee)
if err != nil {
//action.coinsAccount.ExecFrozen(game.AdminAddr, action.execaddr, platFee) // rollback
......@@ -642,7 +648,11 @@ func (action *Action) GamePublish(publish *gty.GuessGamePublish) (*types.Receipt
for j := 0; j < len(game.Plays); j++ {
player := game.Plays[j]
if trimStr(player.Bet.Option) == trimStr(game.Result) {
value := int64(float64(player.Bet.BetsNumber) / float64(winBetsNumber) * float64(winValue))
betsNumber := big.NewInt(player.Bet.BetsNumber)
totalWinBetsNumber := big.NewInt(winBetsNumber)
leftWinBetsNumber := big.NewInt(winValue)
value := betsNumber.Mul(betsNumber, leftWinBetsNumber).Div(betsNumber, totalWinBetsNumber).Int64()
receipt, err := action.coinsAccount.ExecTransfer(game.AdminAddr, player.Addr, action.execaddr, value)
if err != nil {
//action.coinsAccount.ExecFrozen(player.Addr, action.execaddr, value) // rollback
......
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