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