Commit 462ecf6e authored by 张振华's avatar 张振华

Merge branch 'guess' of https://github.com/zzh33cn/plugin into guess

parents 131919e2 4315b7b3
......@@ -6,12 +6,13 @@ package commands
import (
"fmt"
"strings"
jsonrpc "github.com/33cn/chain33/rpc/jsonclient"
rpctypes "github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
gty "github.com/33cn/plugin/plugin/dapp/guess/types"
"github.com/spf13/cobra"
"strings"
)
//GuessCmd Guess合约命令行
......@@ -306,8 +307,8 @@ func guessQuery(cmd *cobra.Command, args []string) {
case "addr":
req := &gty.QueryGuessGameInfo{
Addr: addr,
Index: index,
Addr: addr,
Index: index,
PrimaryKey: primaryKey,
}
params.FuncName = gty.FuncNameQueryGameByAddr
......@@ -318,8 +319,8 @@ func guessQuery(cmd *cobra.Command, args []string) {
case "status":
req := &gty.QueryGuessGameInfo{
Status: status,
Index: index,
Status: status,
Index: index,
PrimaryKey: primaryKey,
}
params.FuncName = gty.FuncNameQueryGameByStatus
......@@ -330,8 +331,8 @@ func guessQuery(cmd *cobra.Command, args []string) {
case "adminAddr":
req := &gty.QueryGuessGameInfo{
AdminAddr: adminAddr,
Index: index,
AdminAddr: adminAddr,
Index: index,
PrimaryKey: primaryKey,
}
params.FuncName = gty.FuncNameQueryGameByAdminAddr
......@@ -342,9 +343,9 @@ func guessQuery(cmd *cobra.Command, args []string) {
case "addrStatus":
req := &gty.QueryGuessGameInfo{
Addr: addr,
Status: status,
Index: index,
Addr: addr,
Status: status,
Index: index,
PrimaryKey: primaryKey,
}
params.FuncName = gty.FuncNameQueryGameByAddrStatus
......@@ -355,9 +356,9 @@ func guessQuery(cmd *cobra.Command, args []string) {
case "adminStatus":
req := &gty.QueryGuessGameInfo{
AdminAddr: adminAddr,
Status: status,
Index: index,
AdminAddr: adminAddr,
Status: status,
Index: index,
PrimaryKey: primaryKey,
}
params.FuncName = gty.FuncNameQueryGameByAdminStatus
......@@ -368,9 +369,9 @@ func guessQuery(cmd *cobra.Command, args []string) {
case "categoryStatus":
req := &gty.QueryGuessGameInfo{
Category: category,
Status: status,
Index: index,
Category: category,
Status: status,
Index: index,
PrimaryKey: primaryKey,
}
params.FuncName = gty.FuncNameQueryGameByCategoryStatus
......
......@@ -6,12 +6,13 @@ package executor
import (
"fmt"
"github.com/33cn/chain33/common/db/table"
"github.com/33cn/chain33/types"
gty "github.com/33cn/plugin/plugin/dapp/guess/types"
)
func (g *Guess) rollbackGame(game *gty.GuessGame, log *gty.ReceiptGuessGame){
func (g *Guess) rollbackGame(game *gty.GuessGame, log *gty.ReceiptGuessGame) {
if game == nil || log == nil {
return
}
......@@ -35,7 +36,7 @@ func (g *Guess) rollbackGame(game *gty.GuessGame, log *gty.ReceiptGuessGame){
game.BetStat.TotalBetsNumber -= log.BetsNumber
for i := 0; i < len(game.BetStat.Items); i++ {
item := game.BetStat.Items[i]
if item.Option == log.Option{
if item.Option == log.Option {
item.BetsTimes--
item.BetsNumber -= log.BetsNumber
break
......@@ -45,7 +46,7 @@ func (g *Guess) rollbackGame(game *gty.GuessGame, log *gty.ReceiptGuessGame){
//玩家下注信息回滚
for i := 0; i < len(game.Plays); i++ {
player := game.Plays[i]
if player.Addr == log.Addr && player.Bet.Index == log.Index {
if player.Addr == log.Addr && player.Bet.Index == log.Index {
game.Plays = append(game.Plays[:i], game.Plays[i+1:]...)
break
}
......
......@@ -28,8 +28,8 @@ func (g *Guess) updateIndex(log *gty.ReceiptGuessGame) (kvs []*types.KeyValue) {
userTable := gty.NewGuessUserTable(g.GetLocalDB())
gameTable := gty.NewGuessGameTable(g.GetLocalDB())
tablejoin, err := table.NewJoinTable(userTable, gameTable, []string{"addr#status"})
if err != nil {
return nil
if err != nil {
return nil
}
if log.Status == gty.GuessGameStatusStart {
......
......@@ -7,11 +7,12 @@ package executor
import (
"context"
"fmt"
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db/table"
"strings"
"time"
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db/table"
"github.com/33cn/chain33/client"
"google.golang.org/grpc"
......@@ -167,7 +168,7 @@ func QueryUserTableData(query *table.Query, indexName string, prefix, primaryKey
userBet := rows[i].Data.(*gty.UserBet)
var record gty.GuessGameRecord
record.GameID = userBet.GameID
record.StartIndex = userBet.StartIndex
record.StartIndex = userBet.StartIndex
records = append(records, &record)
}
......@@ -194,7 +195,7 @@ func QueryGameTableData(query *table.Query, indexName string, prefix, primaryKey
game := rows[i].Data.(*gty.GuessGame)
var record gty.GuessGameRecord
record.GameID = game.GameID
record.StartIndex = game.StartIndex
record.StartIndex = game.StartIndex
records = append(records, &record)
}
......@@ -414,7 +415,7 @@ func (action *Action) GameBet(pbBet *gty.GuessGameBet) (*types.Receipt, error) {
var kv []*types.KeyValue
game, err := QueryGameInfo(action.localDB, []byte(pbBet.GetGameID()))
if err != nil || game == nil{
if err != nil || game == nil {
logger.Error("GameBet", "addr", action.fromaddr, "execaddr", action.execaddr, "get game failed",
pbBet.GetGameID(), "err", err)
return nil, err
......@@ -464,7 +465,7 @@ func (action *Action) GameBet(pbBet *gty.GuessGameBet) (*types.Receipt, error) {
pbBet.BetsNum = game.GetMaxBetsOneTime()
}
if game.BetsNumber + pbBet.GetBetsNum() > game.MaxBetsNumber {
if game.BetsNumber+pbBet.GetBetsNum() > game.MaxBetsNumber {
logger.Error("GameBet", "addr", action.fromaddr, "execaddr", action.execaddr, "MaxBetsNumber over limit",
game.MaxBetsNumber, "current Bets Number", game.BetsNumber)
return nil, types.ErrInvalidParam
......@@ -510,7 +511,7 @@ func (action *Action) GameStopBet(pbBet *gty.GuessGameStopBet) (*types.Receipt,
var kv []*types.KeyValue
game, err := QueryGameInfo(action.localDB, []byte(pbBet.GetGameID()))
if err != nil || game == nil{
if err != nil || game == nil {
logger.Error("GameStopBet", "addr", action.fromaddr, "execaddr", action.execaddr, "get game failed",
pbBet.GetGameID(), "err", err)
return nil, err
......@@ -572,7 +573,7 @@ func (action *Action) GamePublish(publish *gty.GuessGamePublish) (*types.Receipt
var kv []*types.KeyValue
game, err := QueryGameInfo(action.localDB, []byte(publish.GetGameID()))
if err != nil || game == nil{
if err != nil || game == nil {
logger.Error("GamePublish", "addr", action.fromaddr, "execaddr", action.execaddr, "get game failed",
publish.GetGameID(), "err", err)
return nil, err
......@@ -718,7 +719,7 @@ func (action *Action) GameAbort(pbend *gty.GuessGameAbort) (*types.Receipt, erro
var kv []*types.KeyValue
game, err := QueryGameInfo(action.localDB, []byte(pbend.GetGameID()))
if err != nil || game == nil{
if err != nil || game == nil {
logger.Error("GameAbort", "addr", action.fromaddr, "execaddr", action.execaddr, "get game failed",
pbend.GetGameID(), "err", err)
return nil, err
......
......@@ -6,6 +6,7 @@ package executor
import (
"fmt"
"github.com/33cn/chain33/common/db/table"
"github.com/33cn/chain33/types"
gty "github.com/33cn/plugin/plugin/dapp/guess/types"
......
......@@ -8,11 +8,11 @@ import "errors"
// Errors for lottery
var (
ErrNoPrivilege = errors.New("ErrNoPrivilege")
ErrGuessStatus = errors.New("ErrGuessStatus")
ErrOverBetsLimit = errors.New("ErrOverBetsLimit")
ErrParamStatusInvalid = errors.New("ErrParamStatusInvalid")
ErrNoPrivilege = errors.New("ErrNoPrivilege")
ErrGuessStatus = errors.New("ErrGuessStatus")
ErrOverBetsLimit = errors.New("ErrOverBetsLimit")
ErrParamStatusInvalid = errors.New("ErrParamStatusInvalid")
ErrParamAddressMustnotEmpty = errors.New("ErrParamAddressMustnotEmpty")
ErrGameNotExist = errors.New("ErrGameNotExist")
ErrSaveTable = errors.New("ErrSaveTable")
ErrGameNotExist = errors.New("ErrGameNotExist")
ErrSaveTable = errors.New("ErrSaveTable")
)
......@@ -6,10 +6,11 @@ package types
import (
context "context"
fmt "fmt"
math "math"
types "github.com/33cn/chain33/types"
proto "github.com/golang/protobuf/proto"
grpc "google.golang.org/grpc"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
......
......@@ -73,7 +73,7 @@ var opt_guess_game = &table.Option{
Prefix: "LODB_guess",
Name: "game",
Primary: "startindex",
Index: []string{"gameid", "status","admin","admin_status", "category_status"},
Index: []string{"gameid", "status", "admin", "admin_status", "category_status"},
}
//NewTable 新建表
......@@ -112,9 +112,9 @@ func (tx *GuessGameRow) SetPayload(data types.Message) error {
//Get 按照indexName 查询 indexValue
func (tx *GuessGameRow) Get(key string) ([]byte, error) {
if key == "startindex"{
if key == "startindex" {
return []byte(fmt.Sprintf("%018d", tx.StartIndex)), nil
}else if key == "gameid" {
} else if key == "gameid" {
return []byte(fmt.Sprintf("%s", tx.GameID)), nil
} else if key == "status" {
return []byte(fmt.Sprintf("%2d", tx.Status)), nil
......@@ -127,4 +127,4 @@ func (tx *GuessGameRow) Get(key string) ([]byte, error) {
}
return nil, types.ErrNotFound
}
\ No newline at end of file
}
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