Commit 09d43a1a authored by harrylee2015's avatar harrylee2015 Committed by vipwzw

rejust code for golint,vet,ineffassign

parent 1dd4066a
...@@ -6,6 +6,7 @@ package commands ...@@ -6,6 +6,7 @@ package commands
import "github.com/spf13/cobra" import "github.com/spf13/cobra"
// Cmd The command line is not used.
func Cmd() *cobra.Command { func Cmd() *cobra.Command {
return nil return nil
} }
...@@ -26,3 +26,8 @@ status: Create 1 -> Match 2 -> Cancel 3 -> Close 4 ...@@ -26,3 +26,8 @@ status: Create 1 -> Match 2 -> Cancel 3 -> Close 4
//1. 我的所有赌局,按照状态进行分类 (按照地址查询) //1. 我的所有赌局,按照状态进行分类 (按照地址查询)
//2. 系统所有正在进行的赌局 (按照时间进行排序) //2. 系统所有正在进行的赌局 (按照时间进行排序)
*/ */
//game 的状态变化:
// staus == 1 (创建,开始猜拳游戏)
// status == 2 (匹配,参与)
// status == 3 (取消)
// status == 4 (Close的情况)
\ No newline at end of file
...@@ -9,21 +9,25 @@ import ( ...@@ -9,21 +9,25 @@ import (
gt "github.com/33cn/plugin/plugin/dapp/game/types" gt "github.com/33cn/plugin/plugin/dapp/game/types"
) )
// Exec_Create Create game
func (g *Game) Exec_Create(payload *gt.GameCreate, tx *types.Transaction, index int) (*types.Receipt, error) { func (g *Game) Exec_Create(payload *gt.GameCreate, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(g, tx, index) action := NewAction(g, tx, index)
return action.GameCreate(payload) return action.GameCreate(payload)
} }
// Exec_Cancel Cancel game
func (g *Game) Exec_Cancel(payload *gt.GameCancel, tx *types.Transaction, index int) (*types.Receipt, error) { func (g *Game) Exec_Cancel(payload *gt.GameCancel, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(g, tx, index) action := NewAction(g, tx, index)
return action.GameCancel(payload) return action.GameCancel(payload)
} }
// Exec_Close Close game
func (g *Game) Exec_Close(payload *gt.GameClose, tx *types.Transaction, index int) (*types.Receipt, error) { func (g *Game) Exec_Close(payload *gt.GameClose, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(g, tx, index) action := NewAction(g, tx, index)
return action.GameClose(payload) return action.GameClose(payload)
} }
// Exec_Match Match game
func (g *Game) Exec_Match(payload *gt.GameMatch, tx *types.Transaction, index int) (*types.Receipt, error) { func (g *Game) Exec_Match(payload *gt.GameMatch, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(g, tx, index) action := NewAction(g, tx, index)
return action.GameMatch(payload) return action.GameMatch(payload)
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
gt "github.com/33cn/plugin/plugin/dapp/game/types" gt "github.com/33cn/plugin/plugin/dapp/game/types"
) )
// roll back local db data
func (g *Game) execDelLocal(receiptData *types.ReceiptData) (*types.LocalDBSet, error) { func (g *Game) execDelLocal(receiptData *types.ReceiptData) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{} dbSet := &types.LocalDBSet{}
if receiptData.GetTy() != types.ExecOk { if receiptData.GetTy() != types.ExecOk {
...@@ -28,18 +29,22 @@ func (g *Game) execDelLocal(receiptData *types.ReceiptData) (*types.LocalDBSet, ...@@ -28,18 +29,22 @@ func (g *Game) execDelLocal(receiptData *types.ReceiptData) (*types.LocalDBSet,
return dbSet, nil return dbSet, nil
} }
// ExecDelLocal_Create roll back local db data for create
func (g *Game) ExecDelLocal_Create(payload *gt.GameCreate, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *Game) ExecDelLocal_Create(payload *gt.GameCreate, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execDelLocal(receiptData) return g.execDelLocal(receiptData)
} }
// ExecDelLocal_Cancel roll back local db data for cancel
func (g *Game) ExecDelLocal_Cancel(payload *gt.GameCancel, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *Game) ExecDelLocal_Cancel(payload *gt.GameCancel, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execDelLocal(receiptData) return g.execDelLocal(receiptData)
} }
// ExecDelLocal_Close roll back local db data for close
func (g *Game) ExecDelLocal_Close(payload *gt.GameClose, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *Game) ExecDelLocal_Close(payload *gt.GameClose, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execDelLocal(receiptData) return g.execDelLocal(receiptData)
} }
// ExecDelLocal_Match roll back local db data for match
func (g *Game) ExecDelLocal_Match(payload *gt.GameMatch, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *Game) ExecDelLocal_Match(payload *gt.GameMatch, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execDelLocal(receiptData) return g.execDelLocal(receiptData)
} }
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
gt "github.com/33cn/plugin/plugin/dapp/game/types" gt "github.com/33cn/plugin/plugin/dapp/game/types"
) )
// save receiptData to local db
func (g *Game) execLocal(receiptData *types.ReceiptData) (*types.LocalDBSet, error) { func (g *Game) execLocal(receiptData *types.ReceiptData) (*types.LocalDBSet, error) {
dbSet := &types.LocalDBSet{} dbSet := &types.LocalDBSet{}
if receiptData.GetTy() != types.ExecOk { if receiptData.GetTy() != types.ExecOk {
...@@ -28,18 +29,22 @@ func (g *Game) execLocal(receiptData *types.ReceiptData) (*types.LocalDBSet, err ...@@ -28,18 +29,22 @@ func (g *Game) execLocal(receiptData *types.ReceiptData) (*types.LocalDBSet, err
return dbSet, nil return dbSet, nil
} }
// ExecLocal_Create save receiptData for create
func (g *Game) ExecLocal_Create(payload *gt.GameCreate, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *Game) ExecLocal_Create(payload *gt.GameCreate, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execLocal(receiptData) return g.execLocal(receiptData)
} }
// ExecLocal_Cancel save receiptData for cancel
func (g *Game) ExecLocal_Cancel(payload *gt.GameCancel, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *Game) ExecLocal_Cancel(payload *gt.GameCancel, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execLocal(receiptData) return g.execLocal(receiptData)
} }
// ExecLocal_Close save receiptData for close
func (g *Game) ExecLocal_Close(payload *gt.GameClose, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *Game) ExecLocal_Close(payload *gt.GameClose, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execLocal(receiptData) return g.execLocal(receiptData)
} }
// ExecLocal_Match save receiptData for Match
func (g *Game) ExecLocal_Match(payload *gt.GameMatch, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *Game) ExecLocal_Match(payload *gt.GameMatch, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execLocal(receiptData) return g.execLocal(receiptData)
} }
...@@ -22,32 +22,36 @@ func init() { ...@@ -22,32 +22,36 @@ func init() {
ety.InitFuncList(types.ListMethod(&Game{})) ety.InitFuncList(types.ListMethod(&Game{}))
} }
// Init register dapp
func Init(name string, sub []byte) { func Init(name string, sub []byte) {
drivers.Register(GetName(), newGame, types.GetDappFork(driverName, "Enable")) drivers.Register(GetName(), newGame, types.GetDappFork(driverName, "Enable"))
} }
// Game the game inherits all the attributes of the driverBase.
type Game struct { type Game struct {
drivers.DriverBase drivers.DriverBase
} }
func newGame() drivers.Driver { func newGame() drivers.Driver {
t := &Game{} g := &Game{}
t.SetChild(t) g.SetChild(g)
t.SetExecutorType(types.LoadExecutorType(driverName)) g.SetExecutorType(types.LoadExecutorType(driverName))
return t return g
} }
// GetName get name
func GetName() string { func GetName() string {
return newGame().GetName() return newGame().GetName()
} }
// GetDriverName get driver name
func (g *Game) GetDriverName() string { func (g *Game) GetDriverName() string {
return driverName return driverName
} }
//更新索引 // update Index
func (g *Game) updateIndex(log *gt.ReceiptGame) (kvs []*types.KeyValue) { func (g *Game) updateIndex(log *gt.ReceiptGame) (kvs []*types.KeyValue) {
//先保存本次Action产生的索引 // save the index generated by this action first.
kvs = append(kvs, addGameAddrIndex(log.Status, log.GameId, log.Addr, log.Index)) kvs = append(kvs, addGameAddrIndex(log.Status, log.GameId, log.Addr, log.Index))
kvs = append(kvs, addGameStatusIndex(log.Status, log.GameId, log.Index)) kvs = append(kvs, addGameStatusIndex(log.Status, log.GameId, log.Index))
if log.Status == gt.GameActionMatch { if log.Status == gt.GameActionMatch {
...@@ -69,9 +73,9 @@ func (g *Game) updateIndex(log *gt.ReceiptGame) (kvs []*types.KeyValue) { ...@@ -69,9 +73,9 @@ func (g *Game) updateIndex(log *gt.ReceiptGame) (kvs []*types.KeyValue) {
return kvs return kvs
} }
//回滚索引 // rollback Index
func (g *Game) rollbackIndex(log *gt.ReceiptGame) (kvs []*types.KeyValue) { func (g *Game) rollbackIndex(log *gt.ReceiptGame) (kvs []*types.KeyValue) {
//先删除本次Action产生的索引
kvs = append(kvs, delGameAddrIndex(log.Status, log.Addr, log.Index)) kvs = append(kvs, delGameAddrIndex(log.Status, log.Addr, log.Index))
kvs = append(kvs, delGameStatusIndex(log.Status, log.Index)) kvs = append(kvs, delGameStatusIndex(log.Status, log.Index))
...@@ -112,21 +116,21 @@ func calcGameAddrIndexPrefix(status int32, addr string) []byte { ...@@ -112,21 +116,21 @@ func calcGameAddrIndexPrefix(status int32, addr string) []byte {
key := fmt.Sprintf("LODB-game-addr:%d:%s:", status, addr) key := fmt.Sprintf("LODB-game-addr:%d:%s:", status, addr)
return []byte(key) return []byte(key)
} }
func addGameStatusIndex(status int32, gameId string, index int64) *types.KeyValue { func addGameStatusIndex(status int32, gameID string, index int64) *types.KeyValue {
kv := &types.KeyValue{} kv := &types.KeyValue{}
kv.Key = calcGameStatusIndexKey(status, index) kv.Key = calcGameStatusIndexKey(status, index)
record := &gt.GameRecord{ record := &gt.GameRecord{
GameId: gameId, GameId: gameID,
Index: index, Index: index,
} }
kv.Value = types.Encode(record) kv.Value = types.Encode(record)
return kv return kv
} }
func addGameAddrIndex(status int32, gameId, addr string, index int64) *types.KeyValue { func addGameAddrIndex(status int32, gameID, addr string, index int64) *types.KeyValue {
kv := &types.KeyValue{} kv := &types.KeyValue{}
kv.Key = calcGameAddrIndexKey(status, addr, index) kv.Key = calcGameAddrIndexKey(status, addr, index)
record := &gt.GameRecord{ record := &gt.GameRecord{
GameId: gameId, GameId: gameID,
Index: index, Index: index,
} }
kv.Value = types.Encode(record) kv.Value = types.Encode(record)
...@@ -146,19 +150,23 @@ func delGameAddrIndex(status int32, addr string, index int64) *types.KeyValue { ...@@ -146,19 +150,23 @@ func delGameAddrIndex(status int32, addr string, index int64) *types.KeyValue {
return kv return kv
} }
// ReplyGameList the data structure returned when querying the game list.
type ReplyGameList struct { type ReplyGameList struct {
Games []*Game `json:"games"` Games []*Game `json:"games"`
} }
// ReplyGame the data structure returned when querying a single game.
type ReplyGame struct { type ReplyGame struct {
Game *Game `json:"game"` Game *Game `json:"game"`
} }
func (c *Game) GetPayloadValue() types.Message { // GetPayloadValue get payload value
func (g *Game) GetPayloadValue() types.Message {
return &gt.GameAction{} return &gt.GameAction{}
} }
func (c *Game) GetTypeMap() map[string]int32 { // GetTypeMap get TypeMap
func (g *Game) GetTypeMap() map[string]int32 {
return map[string]int32{ return map[string]int32{
"Create": gt.GameActionCreate, "Create": gt.GameActionCreate,
"Match": gt.GameActionMatch, "Match": gt.GameActionMatch,
......
This diff is collapsed.
...@@ -9,18 +9,22 @@ import ( ...@@ -9,18 +9,22 @@ import (
gt "github.com/33cn/plugin/plugin/dapp/game/types" gt "github.com/33cn/plugin/plugin/dapp/game/types"
) )
// Query_QueryGameListByIds query game list by gameIDs
func (g *Game) Query_QueryGameListByIds(in *gt.QueryGameInfos) (types.Message, error) { func (g *Game) Query_QueryGameListByIds(in *gt.QueryGameInfos) (types.Message, error) {
return Infos(g.GetStateDB(), in) return QueryGameListByIds(g.GetStateDB(), in)
} }
// Query_QueryGameListCount query game count by status and addr
func (g *Game) Query_QueryGameListCount(in *gt.QueryGameListCount) (types.Message, error) { func (g *Game) Query_QueryGameListCount(in *gt.QueryGameListCount) (types.Message, error) {
return QueryGameListCount(g.GetStateDB(), in) return QueryGameListCount(g.GetStateDB(), in)
} }
// Query_QueryGameListByStatusAndAddr query game list by status and addr
func (g *Game) Query_QueryGameListByStatusAndAddr(in *gt.QueryGameListByStatusAndAddr) (types.Message, error) { func (g *Game) Query_QueryGameListByStatusAndAddr(in *gt.QueryGameListByStatusAndAddr) (types.Message, error) {
return List(g.GetLocalDB(), g.GetStateDB(), in) return List(g.GetLocalDB(), g.GetStateDB(), in)
} }
// Query_QueryGameById query game by gameID
func (g *Game) Query_QueryGameById(in *gt.QueryGameInfo) (types.Message, error) { func (g *Game) Query_QueryGameById(in *gt.QueryGameInfo) (types.Message, error) {
game, err := readGame(g.GetStateDB(), in.GetGameId()) game, err := readGame(g.GetStateDB(), in.GetGameId())
if err != nil { if err != nil {
......
...@@ -26,16 +26,18 @@ var ( ...@@ -26,16 +26,18 @@ var (
ExecerGame = []byte(GameX) ExecerGame = []byte(GameX)
) )
// action name
const ( const (
Action_CreateGame = "createGame" ActionCreateGame = "createGame"
Action_MatchGame = "matchGame" ActionMatchGame = "matchGame"
Action_CancelGame = "cancelGame" ActionCancelGame = "cancelGame"
Action_CloseGame = "closeGame" ActionCloseGame = "closeGame"
) )
// query func name
const ( const (
FuncName_QueryGameListByIds = "QueryGameListByIds" FuncNameQueryGameListByIds = "QueryGameListByIds"
FuncName_QueryGameListCount = "QueryGameListCount" FuncNameQueryGameListCount = "QueryGameListCount"
FuncName_QueryGameListByStatusAndAddr = "QueryGameListByStatusAndAddr" FuncNameQueryGameListByStatusAndAddr = "QueryGameListByStatusAndAddr"
FuncName_QueryGameById = "QueryGameById" FuncNameQueryGameByID = "QueryGameById"
) )
...@@ -4,15 +4,16 @@ ...@@ -4,15 +4,16 @@
package types package types
import "errors" import "fmt"
// some errors definition
var ( var (
ErrGameCreateAmount = errors.New("You fill in more than the maximum number of games.") ErrGameCreateAmount = fmt.Errorf("%s","You fill in more than the maximum number of games.")
ErrGameCancleAddr = errors.New("You don't have permission to cancel someone else's game.") ErrGameCancleAddr = fmt.Errorf("%s","You don't have permission to cancel someone else's game.")
ErrGameCloseAddr = errors.New("The game time has not yet expired,You don't have permission to call yet.") ErrGameCloseAddr = fmt.Errorf("%s","The game time has not yet expired,You don't have permission to call yet.")
ErrGameTimeOut = errors.New("The game has expired.,You don't have permission to call.") ErrGameTimeOut = fmt.Errorf("%s","The game has expired.,You don't have permission to call.")
ErrGameMatchStatus = errors.New("can't join the game, the game has matched or finished!") ErrGameMatchStatus = fmt.Errorf("%s","can't join the game, the game has matched or finished!")
ErrGameMatch = errors.New("can't join the game, You can't match the game you created!") ErrGameMatch = fmt.Errorf("%s","can't join the game, You can't match the game you created!")
ErrGameCancleStatus = errors.New("can't cancle the game, the game has matched!") ErrGameCancleStatus = fmt.Errorf("%s","can't cancle the game, the game has matched!")
ErrGameCloseStatus = errors.New("can't close the game again, the game has finished!") ErrGameCloseStatus = fmt.Errorf("%s","can't close the game again, the game has finished!")
) )
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package types package types
// GamePreCreateTx pre create game,unused
type GamePreCreateTx struct { type GamePreCreateTx struct {
//Secret string `json:"secret"` //Secret string `json:"secret"`
//下注必须时偶数,不能时级数 //下注必须时偶数,不能时级数
...@@ -14,59 +15,23 @@ type GamePreCreateTx struct { ...@@ -14,59 +15,23 @@ type GamePreCreateTx struct {
Fee int64 `json:"fee"` Fee int64 `json:"fee"`
} }
// GamePreMatchTx pre match game,unused
type GamePreMatchTx struct { type GamePreMatchTx struct {
GameId string `json:"gameId"` GameID string `json:"game_i_d"`
Guess int32 `json:"guess"` Guess int32 `json:"guess"`
Fee int64 `json:"fee"` Fee int64 `json:"fee"`
} }
// GamePreCancelTx pre cancel tx,unused
type GamePreCancelTx struct { type GamePreCancelTx struct {
GameId string `json:"gameId"` GameID string `json:"game_i_d"`
Fee int64 `json:"fee"` Fee int64 `json:"fee"`
} }
// GamePreCloseTx pre close game, unused
type GamePreCloseTx struct { type GamePreCloseTx struct {
GameId string `json:"gameId"` GameID string `json:"game_i_d"`
Secret string `json:"secret"` Secret string `json:"secret"`
Result int32 `json:"result"` Result int32 `json:"result"`
Fee int64 `json:"fee"` Fee int64 `json:"fee"`
} }
type GameData struct {
// 默认是由创建这局游戏的txHash作为gameId
GameId string `json:"gameId"`
// create 1 -> Match 2 -> Cancel 3 -> Close 4 Pending 5 //表示有人参与游戏,但还未打包
Status int32 `json:"status"`
// 创建时间
CreateTime int64 `json:"createTime"`
// 匹配时间(何时参与对赌)
MatchTime int64 `json:"matchTime"`
// 状态close的时间(包括cancel)
Closetime int64 `json:"closetime"`
// 赌注
Value int64 `json:"value"`
// 发起者账号地址
CreateAddress string `json:"createAddress"`
// 对赌者账号地址
MatchAddress string `json:"matchAddress"`
// hash 类型,预留字段
HashType string `json:"hashType"`
// 庄家创建游戏时,庄家自己出拳结果加密后的hash值
HashValue []byte `json:"hashValue"`
// 用来公布庄家出拳结果的私钥
Secret string `json:"secret"`
// 1平局,2 庄家获胜,3 matcher获胜,4 庄家开奖超时,matcher获胜,并获得本局所有赌资
Result int32 `json:"result"`
// matcher 出拳结果
MatcherGuess int32 `json:"matcherGuess"`
// create txHash
CreateTxHash string `json:"createTxHash"`
// matche交易hash
MatchTxHash string `json:"matchTxHash"`
// close txhash
CloseTxHash string `json:"closeTxHash"`
// cancel txhash
CancelTxHash string `json:"cancelTxHash"`
CreatorGuess int32 `json:"creatorGuess"`
Index int64 `json:"index"`
}
...@@ -30,18 +30,20 @@ func getRealExecName(paraName string) string { ...@@ -30,18 +30,20 @@ func getRealExecName(paraName string) string {
return types.ExecName(paraName + GameX) return types.ExecName(paraName + GameX)
} }
// NewType new type
func NewType() *GameType { func NewType() *GameType {
c := &GameType{} c := &GameType{}
c.SetChild(c) c.SetChild(c)
return c return c
} }
// exec // GameType execType
type GameType struct { type GameType struct {
types.ExecTypeBase types.ExecTypeBase
} }
func (at *GameType) GetLogMap() map[int64]*types.LogInfo { // GetLogMap get log
func (gt *GameType) GetLogMap() map[int64]*types.LogInfo {
return map[int64]*types.LogInfo{ return map[int64]*types.LogInfo{
TyLogCreateGame: {reflect.TypeOf(ReceiptGame{}), "LogLotteryCreate"}, TyLogCreateGame: {reflect.TypeOf(ReceiptGame{}), "LogLotteryCreate"},
TyLogCancleGame: {reflect.TypeOf(ReceiptGame{}), "LogCancleGame"}, TyLogCancleGame: {reflect.TypeOf(ReceiptGame{}), "LogCancleGame"},
...@@ -50,11 +52,13 @@ func (at *GameType) GetLogMap() map[int64]*types.LogInfo { ...@@ -50,11 +52,13 @@ func (at *GameType) GetLogMap() map[int64]*types.LogInfo {
} }
} }
func (g *GameType) GetPayload() types.Message { // GetPayload get payload
func (gt *GameType) GetPayload() types.Message {
return &GameAction{} return &GameAction{}
} }
func (g *GameType) GetTypeMap() map[string]int32 { // GetTypeMap get typeMap
func (gt *GameType) GetTypeMap() map[string]int32 {
return map[string]int32{ return map[string]int32{
"Create": GameActionCreate, "Create": GameActionCreate,
"Cancel": GameActionCancel, "Cancel": GameActionCancel,
...@@ -63,11 +67,10 @@ func (g *GameType) GetTypeMap() map[string]int32 { ...@@ -63,11 +67,10 @@ func (g *GameType) GetTypeMap() map[string]int32 {
} }
} }
// TODO createTx接口暂时没法用,作为一个预留接口 // CreateTx unused,just empty implementation
func (game GameType) CreateTx(action string, message json.RawMessage) (*types.Transaction, error) { func (gt GameType) CreateTx(action string, message json.RawMessage) (*types.Transaction, error) {
tlog.Debug("Game.CreateTx", "action", action) tlog.Debug("Game.CreateTx", "action", action)
var tx *types.Transaction if action == ActionCreateGame {
if action == Action_CreateGame {
var param GamePreCreateTx var param GamePreCreateTx
err := json.Unmarshal(message, &param) err := json.Unmarshal(message, &param)
if err != nil { if err != nil {
...@@ -76,7 +79,7 @@ func (game GameType) CreateTx(action string, message json.RawMessage) (*types.Tr ...@@ -76,7 +79,7 @@ func (game GameType) CreateTx(action string, message json.RawMessage) (*types.Tr
} }
return CreateRawGamePreCreateTx(&param) return CreateRawGamePreCreateTx(&param)
} else if action == Action_MatchGame { } else if action == ActionMatchGame {
var param GamePreMatchTx var param GamePreMatchTx
err := json.Unmarshal(message, &param) err := json.Unmarshal(message, &param)
if err != nil { if err != nil {
...@@ -85,7 +88,7 @@ func (game GameType) CreateTx(action string, message json.RawMessage) (*types.Tr ...@@ -85,7 +88,7 @@ func (game GameType) CreateTx(action string, message json.RawMessage) (*types.Tr
} }
return CreateRawGamePreMatchTx(&param) return CreateRawGamePreMatchTx(&param)
} else if action == Action_CancelGame { } else if action == ActionCancelGame {
var param GamePreCancelTx var param GamePreCancelTx
err := json.Unmarshal(message, &param) err := json.Unmarshal(message, &param)
if err != nil { if err != nil {
...@@ -94,7 +97,7 @@ func (game GameType) CreateTx(action string, message json.RawMessage) (*types.Tr ...@@ -94,7 +97,7 @@ func (game GameType) CreateTx(action string, message json.RawMessage) (*types.Tr
} }
return CreateRawGamePreCancelTx(&param) return CreateRawGamePreCancelTx(&param)
} else if action == Action_CloseGame { } else if action == ActionCloseGame {
var param GamePreCloseTx var param GamePreCloseTx
err := json.Unmarshal(message, &param) err := json.Unmarshal(message, &param)
if err != nil { if err != nil {
...@@ -103,13 +106,11 @@ func (game GameType) CreateTx(action string, message json.RawMessage) (*types.Tr ...@@ -103,13 +106,11 @@ func (game GameType) CreateTx(action string, message json.RawMessage) (*types.Tr
} }
return CreateRawGamePreCloseTx(&param) return CreateRawGamePreCloseTx(&param)
} else {
return nil, types.ErrNotSupport
} }
return nil, types.ErrNotSupport
return tx, nil
} }
// CreateRawGamePreCreateTx unused,just empty implementation
func CreateRawGamePreCreateTx(parm *GamePreCreateTx) (*types.Transaction, error) { func CreateRawGamePreCreateTx(parm *GamePreCreateTx) (*types.Transaction, error) {
if parm == nil { if parm == nil {
tlog.Error("CreateRawGamePreCreateTx", "parm", parm) tlog.Error("CreateRawGamePreCreateTx", "parm", parm)
...@@ -139,13 +140,14 @@ func CreateRawGamePreCreateTx(parm *GamePreCreateTx) (*types.Transaction, error) ...@@ -139,13 +140,14 @@ func CreateRawGamePreCreateTx(parm *GamePreCreateTx) (*types.Transaction, error)
return tx, nil return tx, nil
} }
// CreateRawGamePreMatchTx unused,just empty implementation
func CreateRawGamePreMatchTx(parm *GamePreMatchTx) (*types.Transaction, error) { func CreateRawGamePreMatchTx(parm *GamePreMatchTx) (*types.Transaction, error) {
if parm == nil { if parm == nil {
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
v := &GameMatch{ v := &GameMatch{
GameId: parm.GameId, GameId: parm.GameID,
Guess: parm.Guess, Guess: parm.Guess,
} }
game := &GameAction{ game := &GameAction{
...@@ -166,12 +168,13 @@ func CreateRawGamePreMatchTx(parm *GamePreMatchTx) (*types.Transaction, error) { ...@@ -166,12 +168,13 @@ func CreateRawGamePreMatchTx(parm *GamePreMatchTx) (*types.Transaction, error) {
return tx, nil return tx, nil
} }
// CreateRawGamePreCancelTx unused,just empty implementation
func CreateRawGamePreCancelTx(parm *GamePreCancelTx) (*types.Transaction, error) { func CreateRawGamePreCancelTx(parm *GamePreCancelTx) (*types.Transaction, error) {
if parm == nil { if parm == nil {
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
v := &GameCancel{ v := &GameCancel{
GameId: parm.GameId, GameId: parm.GameID,
} }
cancel := &GameAction{ cancel := &GameAction{
Ty: GameActionCancel, Ty: GameActionCancel,
...@@ -191,13 +194,13 @@ func CreateRawGamePreCancelTx(parm *GamePreCancelTx) (*types.Transaction, error) ...@@ -191,13 +194,13 @@ func CreateRawGamePreCancelTx(parm *GamePreCancelTx) (*types.Transaction, error)
return tx, nil return tx, nil
} }
//CreateRawGamePreCloseTx // CreateRawGamePreCloseTx unused,just empty implementation
func CreateRawGamePreCloseTx(parm *GamePreCloseTx) (*types.Transaction, error) { func CreateRawGamePreCloseTx(parm *GamePreCloseTx) (*types.Transaction, error) {
if parm == nil { if parm == nil {
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
v := &GameClose{ v := &GameClose{
GameId: parm.GameId, GameId: parm.GameID,
Secret: parm.Secret, Secret: parm.Secret,
} }
close := &GameAction{ close := &GameAction{
......
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