Commit 43c631f6 authored by 张振华's avatar 张振华

lint

parent 5c0ea3b1
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
"strings" "strings"
) )
//GuessCmd Guess合约命令行
func GuessCmd() *cobra.Command { func GuessCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "guess", Use: "guess",
...@@ -32,6 +33,7 @@ func GuessCmd() *cobra.Command { ...@@ -32,6 +33,7 @@ func GuessCmd() *cobra.Command {
return cmd return cmd
} }
//GuessStartRawTxCmd 构造Guess合约的start原始交易(未签名)的命令行
func GuessStartRawTxCmd() *cobra.Command { func GuessStartRawTxCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "start", Use: "start",
...@@ -107,6 +109,7 @@ func guessStart(cmd *cobra.Command, args []string) { ...@@ -107,6 +109,7 @@ func guessStart(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal() ctx.RunWithoutMarshal()
} }
//GuessBetRawTxCmd 构造Guess合约的bet原始交易(未签名)的命令行
func GuessBetRawTxCmd() *cobra.Command { func GuessBetRawTxCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "bet", Use: "bet",
...@@ -129,13 +132,13 @@ func addGuessBetFlags(cmd *cobra.Command) { ...@@ -129,13 +132,13 @@ func addGuessBetFlags(cmd *cobra.Command) {
func guessBet(cmd *cobra.Command, args []string) { func guessBet(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr") rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
gameId, _ := cmd.Flags().GetString("gameId") gameID, _ := cmd.Flags().GetString("gameId")
option, _ := cmd.Flags().GetString("option") option, _ := cmd.Flags().GetString("option")
betsNumber, _ := cmd.Flags().GetInt64("betsNumber") betsNumber, _ := cmd.Flags().GetInt64("betsNumber")
fee, _ := cmd.Flags().GetFloat64("fee") fee, _ := cmd.Flags().GetFloat64("fee")
params := &pkt.GuessBetTxReq{ params := &pkt.GuessBetTxReq{
GameId: gameId, GameId: gameID,
Option: option, Option: option,
Bets: betsNumber, Bets: betsNumber,
Fee: int64(fee * float64(1e8)), Fee: int64(fee * float64(1e8)),
...@@ -146,6 +149,7 @@ func guessBet(cmd *cobra.Command, args []string) { ...@@ -146,6 +149,7 @@ func guessBet(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal() ctx.RunWithoutMarshal()
} }
//GuessStopBetRawTxCmd 构造Guess合约的停止下注(stopBet)原始交易(未签名)的命令行
func GuessStopBetRawTxCmd() *cobra.Command { func GuessStopBetRawTxCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "stop bet", Use: "stop bet",
...@@ -164,11 +168,11 @@ func addGuessStopBetFlags(cmd *cobra.Command) { ...@@ -164,11 +168,11 @@ func addGuessStopBetFlags(cmd *cobra.Command) {
func guessStopBet(cmd *cobra.Command, args []string) { func guessStopBet(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr") rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
gameId, _ := cmd.Flags().GetString("gameId") gameID, _ := cmd.Flags().GetString("gameId")
fee, _ := cmd.Flags().GetFloat64("fee") fee, _ := cmd.Flags().GetFloat64("fee")
params := &pkt.GuessStopBetTxReq{ params := &pkt.GuessStopBetTxReq{
GameId: gameId, GameId: gameID,
Fee: int64(fee * float64(1e8)), Fee: int64(fee * float64(1e8)),
} }
...@@ -177,7 +181,7 @@ func guessStopBet(cmd *cobra.Command, args []string) { ...@@ -177,7 +181,7 @@ func guessStopBet(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal() ctx.RunWithoutMarshal()
} }
//GuessAbortRawTxCmd 构造Guess合约的撤销(Abort)原始交易(未签名)的命令行
func GuessAbortRawTxCmd() *cobra.Command { func GuessAbortRawTxCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "abort", Use: "abort",
...@@ -196,10 +200,10 @@ func addGuessAbortFlags(cmd *cobra.Command) { ...@@ -196,10 +200,10 @@ func addGuessAbortFlags(cmd *cobra.Command) {
func guessAbort(cmd *cobra.Command, args []string) { func guessAbort(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr") rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
gameId, _ := cmd.Flags().GetString("gameId") gameID, _ := cmd.Flags().GetString("gameId")
fee, _ := cmd.Flags().GetFloat64("fee") fee, _ := cmd.Flags().GetFloat64("fee")
params := &pkt.GuessAbortTxReq{ params := &pkt.GuessAbortTxReq{
GameId: gameId, GameId: gameID,
Fee: int64(fee * float64(1e8)), Fee: int64(fee * float64(1e8)),
} }
...@@ -208,6 +212,7 @@ func guessAbort(cmd *cobra.Command, args []string) { ...@@ -208,6 +212,7 @@ func guessAbort(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal() ctx.RunWithoutMarshal()
} }
//GuessPublishRawTxCmd 构造Guess合约的发布结果(Publish)原始交易(未签名)的命令行
func GuessPublishRawTxCmd() *cobra.Command { func GuessPublishRawTxCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "publish", Use: "publish",
...@@ -230,12 +235,12 @@ func addGuessPublishFlags(cmd *cobra.Command) { ...@@ -230,12 +235,12 @@ func addGuessPublishFlags(cmd *cobra.Command) {
func guessPublish(cmd *cobra.Command, args []string) { func guessPublish(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr") rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
gameId, _ := cmd.Flags().GetString("gameId") gameID, _ := cmd.Flags().GetString("gameId")
result, _ := cmd.Flags().GetString("result") result, _ := cmd.Flags().GetString("result")
fee, _ := cmd.Flags().GetFloat64("fee") fee, _ := cmd.Flags().GetFloat64("fee")
params := &pkt.GuessPublishTxReq{ params := &pkt.GuessPublishTxReq{
GameId: gameId, GameId: gameID,
Result: result, Result: result,
Fee: int64(fee * float64(1e8)), Fee: int64(fee * float64(1e8)),
} }
...@@ -245,7 +250,7 @@ func guessPublish(cmd *cobra.Command, args []string) { ...@@ -245,7 +250,7 @@ func guessPublish(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal() ctx.RunWithoutMarshal()
} }
//GuessQueryRawTxCmd 构造Guess合约的查询(Query)命令行
func GuessQueryRawTxCmd() *cobra.Command { func GuessQueryRawTxCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "query", Use: "query",
...@@ -270,7 +275,7 @@ func addGuessQueryFlags(cmd *cobra.Command) { ...@@ -270,7 +275,7 @@ func addGuessQueryFlags(cmd *cobra.Command) {
func guessQuery(cmd *cobra.Command, args []string) { func guessQuery(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr") rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
ty, _ := cmd.Flags().GetInt32("type") ty, _ := cmd.Flags().GetInt32("type")
gameId, _ := cmd.Flags().GetString("gameId") gameID, _ := cmd.Flags().GetString("gameId")
addr, _ := cmd.Flags().GetString("addr") addr, _ := cmd.Flags().GetString("addr")
adminAddr, _ := cmd.Flags().GetString("adminAddr") adminAddr, _ := cmd.Flags().GetString("adminAddr")
status, _ := cmd.Flags().GetInt32("status") status, _ := cmd.Flags().GetInt32("status")
...@@ -304,7 +309,7 @@ func guessQuery(cmd *cobra.Command, args []string) { ...@@ -304,7 +309,7 @@ func guessQuery(cmd *cobra.Command, args []string) {
case 2: case 2:
req := &pkt.QueryGuessGameInfo{ req := &pkt.QueryGuessGameInfo{
GameId: gameId, GameId: gameID,
} }
params.FuncName = pkt.FuncName_QueryGameById params.FuncName = pkt.FuncName_QueryGameById
params.Payload = types.MustPBToJSON(req) params.Payload = types.MustPBToJSON(req)
......
...@@ -9,26 +9,31 @@ import ( ...@@ -9,26 +9,31 @@ import (
pkt "github.com/33cn/plugin/plugin/dapp/guess/types" pkt "github.com/33cn/plugin/plugin/dapp/guess/types"
) )
//Exec_Start Guess执行器创建游戏
func (c *Guess) Exec_Start(payload *pkt.GuessGameStart, tx *types.Transaction, index int) (*types.Receipt, error) { func (c *Guess) Exec_Start(payload *pkt.GuessGameStart, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(c, tx, index) action := NewAction(c, tx, index)
return action.GameStart(payload) return action.GameStart(payload)
} }
//Exec_Bet Guess执行器参与游戏
func (c *Guess) Exec_Bet(payload *pkt.GuessGameBet, tx *types.Transaction, index int) (*types.Receipt, error) { func (c *Guess) Exec_Bet(payload *pkt.GuessGameBet, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(c, tx, index) action := NewAction(c, tx, index)
return action.GameBet(payload) return action.GameBet(payload)
} }
//Exec_StopBet Guess执行器停止游戏下注
func (c *Guess) Exec_StopBet(payload *pkt.GuessGameStopBet, tx *types.Transaction, index int) (*types.Receipt, error) { func (c *Guess) Exec_StopBet(payload *pkt.GuessGameStopBet, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(c, tx, index) action := NewAction(c, tx, index)
return action.GameStopBet(payload) return action.GameStopBet(payload)
} }
//Exec_Publish Guess执行器公布游戏结果
func (c *Guess) Exec_Publish(payload *pkt.GuessGamePublish, tx *types.Transaction, index int) (*types.Receipt, error) { func (c *Guess) Exec_Publish(payload *pkt.GuessGamePublish, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(c, tx, index) action := NewAction(c, tx, index)
return action.GamePublish(payload) return action.GamePublish(payload)
} }
//Exec_Abort Guess执行器撤销未结束游戏
func (c *Guess) Exec_Abort(payload *pkt.GuessGameAbort, tx *types.Transaction, index int) (*types.Receipt, error) { func (c *Guess) Exec_Abort(payload *pkt.GuessGameAbort, tx *types.Transaction, index int) (*types.Receipt, error) {
action := NewAction(c, tx, index) action := NewAction(c, tx, index)
return action.GameAbort(payload) return action.GameAbort(payload)
......
...@@ -76,18 +76,22 @@ func (g *Guess) execDelLocal(receiptData *types.ReceiptData) (*types.LocalDBSet, ...@@ -76,18 +76,22 @@ func (g *Guess) execDelLocal(receiptData *types.ReceiptData) (*types.LocalDBSet,
return dbSet, nil return dbSet, nil
} }
//ExecDelLocal_Start Guess执行器Start交易撤销
func (g *Guess) ExecDelLocal_Start(payload *pkt.GuessGameStart, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *Guess) ExecDelLocal_Start(payload *pkt.GuessGameStart, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execLocal(receiptData) return g.execLocal(receiptData)
} }
//ExecDelLocal_Bet Guess执行器Bet交易撤销
func (g *Guess) ExecDelLocal_Bet(payload *pkt.GuessGameBet, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *Guess) ExecDelLocal_Bet(payload *pkt.GuessGameBet, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execLocal(receiptData) return g.execLocal(receiptData)
} }
//ExecDelLocal_Publish Guess执行器Publish交易撤销
func (g *Guess) ExecDelLocal_Publish(payload *pkt.GuessGamePublish, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *Guess) ExecDelLocal_Publish(payload *pkt.GuessGamePublish, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execLocal(receiptData) return g.execLocal(receiptData)
} }
//ExecDelLocal_Abort Guess执行器Abort交易撤销
func (g *Guess) ExecDelLocal_Abort(payload *pkt.GuessGameAbort, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *Guess) ExecDelLocal_Abort(payload *pkt.GuessGameAbort, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execLocal(receiptData) return g.execLocal(receiptData)
} }
\ No newline at end of file
...@@ -75,22 +75,27 @@ func (g *Guess) execLocal(receipt *types.ReceiptData) (*types.LocalDBSet, error) ...@@ -75,22 +75,27 @@ func (g *Guess) execLocal(receipt *types.ReceiptData) (*types.LocalDBSet, error)
return dbSet, nil return dbSet, nil
} }
//ExecLocal_Start method
func (g *Guess) ExecLocal_Start(payload *pkt.GuessGameStart, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *Guess) ExecLocal_Start(payload *pkt.GuessGameStart, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execLocal(receiptData) return g.execLocal(receiptData)
} }
//ExecLocal_Bet method
func (g *Guess) ExecLocal_Bet(payload *pkt.GuessGameBet, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *Guess) ExecLocal_Bet(payload *pkt.GuessGameBet, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execLocal(receiptData) return g.execLocal(receiptData)
} }
//ExecLocal_StopBet method
func (g *Guess) ExecLocal_StopBet(payload *pkt.GuessGameStopBet, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *Guess) ExecLocal_StopBet(payload *pkt.GuessGameStopBet, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execLocal(receiptData) return g.execLocal(receiptData)
} }
//ExecLocal_Publish method
func (g *Guess) ExecLocal_Publish(payload *pkt.GuessGamePublish, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *Guess) ExecLocal_Publish(payload *pkt.GuessGamePublish, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execLocal(receiptData) return g.execLocal(receiptData)
} }
//ExecLocal_Abort method
func (g *Guess) ExecLocal_Abort(payload *pkt.GuessGameAbort, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) { func (g *Guess) ExecLocal_Abort(payload *pkt.GuessGameAbort, tx *types.Transaction, receiptData *types.ReceiptData, index int) (*types.LocalDBSet, error) {
return g.execLocal(receiptData) return g.execLocal(receiptData)
} }
\ No newline at end of file
...@@ -39,6 +39,7 @@ func Init(name string, sub []byte) { ...@@ -39,6 +39,7 @@ func Init(name string, sub []byte) {
drivers.Register(driverName, newGuessGame, types.GetDappFork(driverName, "Enable")) drivers.Register(driverName, newGuessGame, types.GetDappFork(driverName, "Enable"))
} }
//Guess 执行器,用于竞猜合约的具体执行
type Guess struct { type Guess struct {
drivers.DriverBase drivers.DriverBase
} }
...@@ -50,10 +51,12 @@ func newGuessGame() drivers.Driver { ...@@ -50,10 +51,12 @@ func newGuessGame() drivers.Driver {
return t return t
} }
//GetName 获取Guess执行器的名称
func GetName() string { func GetName() string {
return newGuessGame().GetName() return newGuessGame().GetName()
} }
//GetDriverName 获取Guess执行器的名称
func (g *Guess) GetDriverName() string { func (g *Guess) GetDriverName() string {
return pkt.GuessX return pkt.GuessX
} }
......
...@@ -21,27 +21,38 @@ import ( ...@@ -21,27 +21,38 @@ import (
) )
const ( const (
//ListDESC 表示记录降序排列
ListDESC = int32(0) ListDESC = int32(0)
//ListASC 表示记录升序排列
ListASC = int32(1) ListASC = int32(1)
DefaultCount = int32(20) //默认一次取多少条记录 //DefaultCount 默认一次获取的记录数
DefaultCount = int32(20)
//DefaultCategory 默认分类
DefaultCategory= "default" DefaultCategory= "default"
MaxBetsOneTime = 10000e8 //一次最多下多少注 //MaxBetsOneTime 一次最多下多少注
MaxBetsNumber = 10000000e8 //一局游戏最多接受多少注 MaxBetsOneTime = 10000e8
MaxBetHeight = 1000000 //距离游戏创建区块的最大可下注高度差
MaxExpireHeight = 1000000 //距离游戏创建区块的最大过期高度差 //MaxBetsNumber 一局游戏最多接受多少注
MaxBetsNumber = 10000000e8
MinBetBlockNum = 720 //从创建游戏开始,一局游戏最少的可下注区块数量 //MaxBetHeight 距离游戏创建区块的最大可下注高度差
MinBetTimeInterval = "2h" //从创建游戏开始,一局游戏最短的可下注时间 MaxBetHeight = 1000000
MinBetTimeoutNum = 8640 //从游戏结束下注开始,一局游戏最少的超时块数
MinBetTimeoutInterval = "24h" //从游戏结束下注开始,一局游戏最短的超时时间
grpcRecSize int = 5 * 30 * 1024 * 1024 //MaxExpireHeight 距离游戏创建区块的最大过期高度差
MaxExpireHeight = 1000000
//grpcRecSize 接收缓冲大小
grpcRecSize int = 30 * 1024 * 1024
//retryNum 失败时的重试次数
retryNum = 10 retryNum = 10
) )
//Action 具体动作执行
type Action struct { type Action struct {
coinsAccount *account.DB coinsAccount *account.DB
db dbm.KV db dbm.KV
...@@ -57,6 +68,7 @@ type Action struct { ...@@ -57,6 +68,7 @@ type Action struct {
grpcClient types.Chain33Client grpcClient types.Chain33Client
} }
//NewAction 生成Action对象
func NewAction(guess *Guess, tx *types.Transaction, index int) *Action { func NewAction(guess *Guess, tx *types.Transaction, index int) *Action {
hash := tx.Hash() hash := tx.Hash()
fromAddr := tx.From() fromAddr := tx.From()
...@@ -90,6 +102,7 @@ func NewAction(guess *Guess, tx *types.Transaction, index int) *Action { ...@@ -90,6 +102,7 @@ func NewAction(guess *Guess, tx *types.Transaction, index int) *Action {
} }
} }
//CheckExecAccountBalance 检查地址在Guess合约中的余额是否足够
func (action *Action) CheckExecAccountBalance(fromAddr string, ToFrozen, ToActive int64) bool { func (action *Action) CheckExecAccountBalance(fromAddr string, ToFrozen, ToActive int64) bool {
acc := action.coinsAccount.LoadExecAccount(fromAddr, action.execaddr) acc := action.coinsAccount.LoadExecAccount(fromAddr, action.execaddr)
if acc.GetBalance() >= ToFrozen && acc.GetFrozen() >= ToActive { if acc.GetBalance() >= ToFrozen && acc.GetFrozen() >= ToActive {
...@@ -98,6 +111,7 @@ func (action *Action) CheckExecAccountBalance(fromAddr string, ToFrozen, ToActiv ...@@ -98,6 +111,7 @@ func (action *Action) CheckExecAccountBalance(fromAddr string, ToFrozen, ToActiv
return false return false
} }
//Key State数据库中存储记录的Key值格式转换
func Key(id string) (key []byte) { func Key(id string) (key []byte) {
//key = append(key, []byte("mavl-"+types.ExecName(pkt.GuessX)+"-")...) //key = append(key, []byte("mavl-"+types.ExecName(pkt.GuessX)+"-")...)
key = append(key, []byte("mavl-"+pkt.GuessX+"-")...) key = append(key, []byte("mavl-"+pkt.GuessX+"-")...)
...@@ -121,6 +135,7 @@ func readGame(db dbm.KV, id string) (*pkt.GuessGame, error) { ...@@ -121,6 +135,7 @@ func readGame(db dbm.KV, id string) (*pkt.GuessGame, error) {
return &game, nil return &game, nil
} }
//Infos 根据游戏id列表查询多个游戏详情信息
func Infos(db dbm.KV, infos *pkt.QueryGuessGameInfos) (types.Message, error) { func Infos(db dbm.KV, infos *pkt.QueryGuessGameInfos) (types.Message, error) {
var games []*pkt.GuessGame var games []*pkt.GuessGame
for i := 0; i < len(infos.GameIds); i++ { for i := 0; i < len(infos.GameIds); i++ {
...@@ -295,6 +310,7 @@ func (action *Action) getIndex() int64 { ...@@ -295,6 +310,7 @@ func (action *Action) getIndex() int64 {
return action.height*types.MaxTxsPerBlock + int64(action.index) return action.height*types.MaxTxsPerBlock + int64(action.index)
} }
//GetReceiptLog 根据游戏信息生成收据记录
func (action *Action) GetReceiptLog(game *pkt.GuessGame, statusChange bool) *types.ReceiptLog { func (action *Action) GetReceiptLog(game *pkt.GuessGame, statusChange bool) *types.ReceiptLog {
log := &types.ReceiptLog{} log := &types.ReceiptLog{}
r := &pkt.ReceiptGuessGame{} r := &pkt.ReceiptGuessGame{}
...@@ -340,12 +356,12 @@ func (action *Action) readGame(id string) (*pkt.GuessGame, error) { ...@@ -340,12 +356,12 @@ func (action *Action) readGame(id string) (*pkt.GuessGame, error) {
} }
// 新建一局游戏 // 新建一局游戏
func (action *Action) newGame(gameId string, start *pkt.GuessGameStart) (*pkt.GuessGame, error) { func (action *Action) newGame(gameID string, start *pkt.GuessGameStart) (*pkt.GuessGame, error) {
game := &pkt.GuessGame{ game := &pkt.GuessGame{
GameId: gameId, GameId: gameID,
Status: pkt.GuessGameActionStart, Status: pkt.GuessGameActionStart,
//StartTime: action.blocktime, //StartTime: action.blocktime,
StartTxHash: gameId, StartTxHash: gameID,
Topic: start.Topic, Topic: start.Topic,
Category: start.Category, Category: start.Category,
Options: start.Options, Options: start.Options,
...@@ -366,7 +382,7 @@ func (action *Action) newGame(gameId string, start *pkt.GuessGameStart) (*pkt.Gu ...@@ -366,7 +382,7 @@ func (action *Action) newGame(gameId string, start *pkt.GuessGameStart) (*pkt.Gu
return game, nil return game, nil
} }
//GameStart 创建游戏动作执行
func (action *Action) GameStart(start *pkt.GuessGameStart) (*types.Receipt, error) { func (action *Action) GameStart(start *pkt.GuessGameStart) (*types.Receipt, error) {
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
var kv []*types.KeyValue var kv []*types.KeyValue
...@@ -385,8 +401,8 @@ func (action *Action) GameStart(start *pkt.GuessGameStart) (*types.Receipt, erro ...@@ -385,8 +401,8 @@ func (action *Action) GameStart(start *pkt.GuessGameStart) (*types.Receipt, erro
if start.MaxBetsNumber >= MaxBetsNumber { if start.MaxBetsNumber >= MaxBetsNumber {
logger.Error("GameStart", "addr", action.fromaddr, "execaddr", action.execaddr, logger.Error("GameStart", "addr", action.fromaddr, "execaddr", action.execaddr,
"err", fmt.Sprintf("The maximum bets number is %d which is less than start.MaxBetsNumber %d", MaxBetsNumber, start.MaxBetsNumber)) "err", fmt.Sprintf("The maximum bets number is %d which is less than start.MaxBetsNumber %d", int64(MaxBetsNumber), start.MaxBetsNumber))
return nil, types.ErrInvalidParam return nil, pkt.ErrOverBetsLimit
} }
if len(start.Topic) == 0 || len(start.Options) == 0 { if len(start.Topic) == 0 || len(start.Options) == 0 {
...@@ -416,8 +432,8 @@ func (action *Action) GameStart(start *pkt.GuessGameStart) (*types.Receipt, erro ...@@ -416,8 +432,8 @@ func (action *Action) GameStart(start *pkt.GuessGameStart) (*types.Receipt, erro
start.MaxBetsOneTime = MaxBetsOneTime start.MaxBetsOneTime = MaxBetsOneTime
} }
gameId := common.ToHex(action.txhash) gameID := common.ToHex(action.txhash)
game, _ := action.newGame(gameId, start) game, _ := action.newGame(gameID, start)
game.StartTime = action.blocktime game.StartTime = action.blocktime
if types.IsPara() { if types.IsPara() {
mainHeight := action.GetMainHeightByTxHash(action.txhash) mainHeight := action.GetMainHeightByTxHash(action.txhash)
...@@ -446,6 +462,7 @@ func (action *Action) GameStart(start *pkt.GuessGameStart) (*types.Receipt, erro ...@@ -446,6 +462,7 @@ func (action *Action) GameStart(start *pkt.GuessGameStart) (*types.Receipt, erro
return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil
} }
//GameBet 参与游戏动作执行
func (action *Action) GameBet(pbBet *pkt.GuessGameBet) (*types.Receipt, error) { func (action *Action) GameBet(pbBet *pkt.GuessGameBet) (*types.Receipt, error) {
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
var kv []*types.KeyValue var kv []*types.KeyValue
...@@ -539,6 +556,7 @@ func (action *Action) GameBet(pbBet *pkt.GuessGameBet) (*types.Receipt, error) { ...@@ -539,6 +556,7 @@ func (action *Action) GameBet(pbBet *pkt.GuessGameBet) (*types.Receipt, error) {
return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil
} }
//GameStopBet 停止游戏下注动作执行
func (action *Action) GameStopBet(pbBet *pkt.GuessGameStopBet) (*types.Receipt, error) { func (action *Action) GameStopBet(pbBet *pkt.GuessGameStopBet) (*types.Receipt, error) {
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
var kv []*types.KeyValue var kv []*types.KeyValue
...@@ -576,6 +594,7 @@ func (action *Action) GameStopBet(pbBet *pkt.GuessGameStopBet) (*types.Receipt, ...@@ -576,6 +594,7 @@ func (action *Action) GameStopBet(pbBet *pkt.GuessGameStopBet) (*types.Receipt,
return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil
} }
//AddGuessBet 向游戏结构中加入下注信息
func (action *Action) AddGuessBet(game *pkt.GuessGame, pbBet *pkt.GuessGameBet) { func (action *Action) AddGuessBet(game *pkt.GuessGame, pbBet *pkt.GuessGameBet) {
bet := &pkt.GuessBet{ Option: pbBet.GetOption(), BetsNumber: pbBet.BetsNum, Index: game.Index} bet := &pkt.GuessBet{ Option: pbBet.GetOption(), BetsNumber: pbBet.BetsNum, Index: game.Index}
player := &pkt.GuessPlayer{ Addr: action.fromaddr, Bet: bet} player := &pkt.GuessPlayer{ Addr: action.fromaddr, Bet: bet}
...@@ -597,6 +616,7 @@ func (action *Action) AddGuessBet(game *pkt.GuessGame, pbBet *pkt.GuessGameBet) ...@@ -597,6 +616,7 @@ func (action *Action) AddGuessBet(game *pkt.GuessGame, pbBet *pkt.GuessGameBet)
game.BetsNumber += pbBet.GetBetsNum() game.BetsNumber += pbBet.GetBetsNum()
} }
//GamePublish 公布竞猜游戏结果动作执行
func (action *Action) GamePublish(publish *pkt.GuessGamePublish) (*types.Receipt, error) { func (action *Action) GamePublish(publish *pkt.GuessGamePublish) (*types.Receipt, error) {
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
var kv []*types.KeyValue var kv []*types.KeyValue
...@@ -740,6 +760,7 @@ func (action *Action) GamePublish(publish *pkt.GuessGamePublish) (*types.Receipt ...@@ -740,6 +760,7 @@ func (action *Action) GamePublish(publish *pkt.GuessGamePublish) (*types.Receipt
return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil
} }
//GameAbort 撤销游戏动作执行
func (action *Action) GameAbort(pbend *pkt.GuessGameAbort) (*types.Receipt, error) { func (action *Action) GameAbort(pbend *pkt.GuessGameAbort) (*types.Receipt, error) {
var logs []*types.ReceiptLog var logs []*types.ReceiptLog
var kv []*types.KeyValue var kv []*types.KeyValue
...@@ -804,6 +825,7 @@ func (action *Action) GameAbort(pbend *pkt.GuessGameAbort) (*types.Receipt, erro ...@@ -804,6 +825,7 @@ func (action *Action) GameAbort(pbend *pkt.GuessGameAbort) (*types.Receipt, erro
return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil
} }
//GetOptions 获得竞猜选项,并判断是否符合约定格式,类似"A:xxxx;B:xxxx;C:xxx",“:”前为选项名称,不能重复,":"后为选项说明。
func GetOptions(strOptions string) (options []string, legal bool){ func GetOptions(strOptions string) (options []string, legal bool){
legal = true legal = true
items := strings.Split(strOptions, ";") items := strings.Split(strOptions, ";")
...@@ -822,6 +844,7 @@ func GetOptions(strOptions string) (options []string, legal bool){ ...@@ -822,6 +844,7 @@ func GetOptions(strOptions string) (options []string, legal bool){
return options, legal return options, legal
} }
//IsLegalOption 判断选项是否为合法选项
func IsLegalOption(options []string, option string) bool { func IsLegalOption(options []string, option string) bool {
for i := 0; i < len(options); i++ { for i := 0; i < len(options); i++ {
if options[i] == option { if options[i] == option {
...@@ -832,6 +855,7 @@ func IsLegalOption(options []string, option string) bool { ...@@ -832,6 +855,7 @@ func IsLegalOption(options []string, option string) bool {
return false return false
} }
//ChangeStatus 修改游戏状态,同步更新历史记录
func (action *Action) ChangeStatus(game *pkt.GuessGame, destStatus int32) { func (action *Action) ChangeStatus(game *pkt.GuessGame, destStatus int32) {
if game.Status != destStatus { if game.Status != destStatus {
game.PreStatus = game.Status game.PreStatus = game.Status
...@@ -843,6 +867,7 @@ func (action *Action) ChangeStatus(game *pkt.GuessGame, destStatus int32) { ...@@ -843,6 +867,7 @@ func (action *Action) ChangeStatus(game *pkt.GuessGame, destStatus int32) {
return return
} }
//ChangeAllAddrIndex 状态更新时,更新下注记录的历史信息
func (action *Action) ChangeAllAddrIndex(game *pkt.GuessGame) { func (action *Action) ChangeAllAddrIndex(game *pkt.GuessGame) {
for i := 0; i < len(game.Plays) ; i++ { for i := 0; i < len(game.Plays) ; i++ {
player := game.Plays[i] player := game.Plays[i]
...@@ -851,6 +876,7 @@ func (action *Action) ChangeAllAddrIndex(game *pkt.GuessGame) { ...@@ -851,6 +876,7 @@ func (action *Action) ChangeAllAddrIndex(game *pkt.GuessGame) {
} }
} }
//RefreshStatusByTime 检测游戏是否过期,是否可以下注
func (action *Action) RefreshStatusByTime(game *pkt.GuessGame) (canBet bool) { func (action *Action) RefreshStatusByTime(game *pkt.GuessGame) (canBet bool) {
var mainHeight int64 var mainHeight int64
...@@ -895,6 +921,7 @@ func (action *Action) RefreshStatusByTime(game *pkt.GuessGame) (canBet bool) { ...@@ -895,6 +921,7 @@ func (action *Action) RefreshStatusByTime(game *pkt.GuessGame) (canBet bool) {
return canBet return canBet
} }
//CheckTime 检测游戏的过期设置。
func (action *Action) CheckTime(start *pkt.GuessGameStart) bool { func (action *Action) CheckTime(start *pkt.GuessGameStart) bool {
if start.MaxBetHeight == 0 && start.ExpireHeight == 0 { if start.MaxBetHeight == 0 && start.ExpireHeight == 0 {
//如果上述字段都不携带,则认为完全由admin的指令驱动。 //如果上述字段都不携带,则认为完全由admin的指令驱动。
......
...@@ -9,10 +9,12 @@ import ( ...@@ -9,10 +9,12 @@ import (
pkt "github.com/33cn/plugin/plugin/dapp/guess/types" pkt "github.com/33cn/plugin/plugin/dapp/guess/types"
) )
//Query_QueryGamesByIds method
func (g *Guess) Query_QueryGamesByIds(in *pkt.QueryGuessGameInfos) (types.Message, error) { func (g *Guess) Query_QueryGamesByIds(in *pkt.QueryGuessGameInfos) (types.Message, error) {
return Infos(g.GetStateDB(), in) return Infos(g.GetStateDB(), in)
} }
//Query_QueryGameById method
func (g *Guess) Query_QueryGameById(in *pkt.QueryGuessGameInfo) (types.Message, error) { func (g *Guess) Query_QueryGameById(in *pkt.QueryGuessGameInfo) (types.Message, error) {
game, err := readGame(g.GetStateDB(), in.GetGameId()) game, err := readGame(g.GetStateDB(), in.GetGameId())
if err != nil { if err != nil {
...@@ -21,6 +23,7 @@ func (g *Guess) Query_QueryGameById(in *pkt.QueryGuessGameInfo) (types.Message, ...@@ -21,6 +23,7 @@ func (g *Guess) Query_QueryGameById(in *pkt.QueryGuessGameInfo) (types.Message,
return &pkt.ReplyGuessGameInfo{Game: game}, nil return &pkt.ReplyGuessGameInfo{Game: game}, nil
} }
//Query_QueryGamesByAddr method
func (g *Guess) Query_QueryGamesByAddr(in *pkt.QueryGuessGameInfo) (types.Message, error) { func (g *Guess) Query_QueryGamesByAddr(in *pkt.QueryGuessGameInfo) (types.Message, error) {
records, err := getGameListByAddr(g.GetLocalDB(), in.Addr, in.Index) records, err := getGameListByAddr(g.GetLocalDB(), in.Addr, in.Index)
if err != nil { if err != nil {
...@@ -30,6 +33,7 @@ func (g *Guess) Query_QueryGamesByAddr(in *pkt.QueryGuessGameInfo) (types.Messag ...@@ -30,6 +33,7 @@ func (g *Guess) Query_QueryGamesByAddr(in *pkt.QueryGuessGameInfo) (types.Messag
return records, nil return records, nil
} }
//Query_QueryGamesByStatus method
func (g *Guess) Query_QueryGamesByStatus(in *pkt.QueryGuessGameInfo) (types.Message, error) { func (g *Guess) Query_QueryGamesByStatus(in *pkt.QueryGuessGameInfo) (types.Message, error) {
records, err := getGameListByStatus(g.GetLocalDB(), in.Status, in.Index) records, err := getGameListByStatus(g.GetLocalDB(), in.Status, in.Index)
if err != nil { if err != nil {
...@@ -39,6 +43,7 @@ func (g *Guess) Query_QueryGamesByStatus(in *pkt.QueryGuessGameInfo) (types.Mess ...@@ -39,6 +43,7 @@ func (g *Guess) Query_QueryGamesByStatus(in *pkt.QueryGuessGameInfo) (types.Mess
return records, nil return records, nil
} }
//Query_QueryGamesByAdminAddr method
func (g *Guess) Query_QueryGamesByAdminAddr(in *pkt.QueryGuessGameInfo) (types.Message, error) { func (g *Guess) Query_QueryGamesByAdminAddr(in *pkt.QueryGuessGameInfo) (types.Message, error) {
records, err := getGameListByAdminAddr(g.GetLocalDB(), in.AdminAddr, in.Index) records, err := getGameListByAdminAddr(g.GetLocalDB(), in.AdminAddr, in.Index)
if err != nil { if err != nil {
...@@ -48,6 +53,7 @@ func (g *Guess) Query_QueryGamesByAdminAddr(in *pkt.QueryGuessGameInfo) (types.M ...@@ -48,6 +53,7 @@ func (g *Guess) Query_QueryGamesByAdminAddr(in *pkt.QueryGuessGameInfo) (types.M
return records, nil return records, nil
} }
//Query_QueryGamesByAddrStatus method
func (g *Guess) Query_QueryGamesByAddrStatus(in *pkt.QueryGuessGameInfo) (types.Message, error) { func (g *Guess) Query_QueryGamesByAddrStatus(in *pkt.QueryGuessGameInfo) (types.Message, error) {
records, err := getGameListByAddrStatus(g.GetLocalDB(), in.Addr, in.Status, in.Index) records, err := getGameListByAddrStatus(g.GetLocalDB(), in.Addr, in.Status, in.Index)
if err != nil { if err != nil {
...@@ -57,6 +63,7 @@ func (g *Guess) Query_QueryGamesByAddrStatus(in *pkt.QueryGuessGameInfo) (types. ...@@ -57,6 +63,7 @@ func (g *Guess) Query_QueryGamesByAddrStatus(in *pkt.QueryGuessGameInfo) (types.
return records, nil return records, nil
} }
//Query_QueryGamesByAdminStatus method
func (g *Guess) Query_QueryGamesByAdminStatus(in *pkt.QueryGuessGameInfo) (types.Message, error) { func (g *Guess) Query_QueryGamesByAdminStatus(in *pkt.QueryGuessGameInfo) (types.Message, error) {
records, err := getGameListByAdminStatus(g.GetLocalDB(), in.AdminAddr, in.Status, in.Index) records, err := getGameListByAdminStatus(g.GetLocalDB(), in.AdminAddr, in.Status, in.Index)
if err != nil { if err != nil {
...@@ -66,6 +73,7 @@ func (g *Guess) Query_QueryGamesByAdminStatus(in *pkt.QueryGuessGameInfo) (types ...@@ -66,6 +73,7 @@ func (g *Guess) Query_QueryGamesByAdminStatus(in *pkt.QueryGuessGameInfo) (types
return records, nil return records, nil
} }
//Query_QueryGamesByCategoryStatus method
func (g *Guess) Query_QueryGamesByCategoryStatus(in *pkt.QueryGuessGameInfo) (types.Message, error) { func (g *Guess) Query_QueryGamesByCategoryStatus(in *pkt.QueryGuessGameInfo) (types.Message, error) {
records, err := getGameListByCategoryStatus(g.GetLocalDB(), in.Category, in.Status, in.Index) records, err := getGameListByCategoryStatus(g.GetLocalDB(), in.Category, in.Status, in.Index)
if err != nil { if err != nil {
......
...@@ -4,7 +4,7 @@ import "transaction.proto"; ...@@ -4,7 +4,7 @@ import "transaction.proto";
package types; package types;
//竞猜游戏内容 //GuessGame 竞猜游戏详情
message GuessGame { message GuessGame {
string gameId = 1; //游戏ID string gameId = 1; //游戏ID
int32 status = 2; //游戏的状态:创建->投注->截止投注->开奖 int32 status = 2; //游戏的状态:创建->投注->截止投注->开奖
...@@ -33,11 +33,13 @@ message GuessGame { ...@@ -33,11 +33,13 @@ message GuessGame {
bool drivenByAdmin = 25; bool drivenByAdmin = 25;
} }
//GuessPlayer 竞猜玩家信息
message GuessPlayer { message GuessPlayer {
string addr = 1; string addr = 1;
GuessBet bet = 2; GuessBet bet = 2;
} }
//GuessBet 竞猜下注信息
message GuessBet { message GuessBet {
string option = 1; string option = 1;
int64 betsNumber = 2; int64 betsNumber = 2;
...@@ -47,19 +49,21 @@ message GuessBet { ...@@ -47,19 +49,21 @@ message GuessBet {
int64 preIndex = 6; int64 preIndex = 6;
} }
//GuessBetStat 竞猜下注统计信息
message GuessBetStat { message GuessBetStat {
int64 totalBetTimes = 1; int64 totalBetTimes = 1;
int64 totalBetsNumber = 2; int64 totalBetsNumber = 2;
repeated GuessBetStatItem items = 3; repeated GuessBetStatItem items = 3;
} }
//GuessBetStat 竞猜下注子选项统计信息
message GuessBetStatItem { message GuessBetStatItem {
string option = 1; string option = 1;
int64 betsNumber = 2; int64 betsNumber = 2;
int64 betsTimes = 3; int64 betsTimes = 3;
} }
//游戏状态 //GuessGameAction 竞猜游戏动作
message GuessGameAction { message GuessGameAction {
oneof value { oneof value {
GuessGameStart start = 1; GuessGameStart start = 1;
...@@ -72,7 +76,7 @@ message GuessGameAction { ...@@ -72,7 +76,7 @@ message GuessGameAction {
int32 ty = 7; int32 ty = 7;
} }
//游戏启动 //GuessGameStart 游戏创建
message GuessGameStart{ message GuessGameStart{
string topic = 1; string topic = 1;
string options = 2; string options = 2;
...@@ -88,36 +92,36 @@ message GuessGameStart{ ...@@ -88,36 +92,36 @@ message GuessGameStart{
bool drivenByAdmin = 12; bool drivenByAdmin = 12;
} }
//参与游戏下注 //GuessGameBet 参与游戏下注
message GuessGameBet{ message GuessGameBet{
string gameId = 1; string gameId = 1;
string option = 2; string option = 2;
int64 betsNum = 3; int64 betsNum = 3;
} }
//游戏停止下注 //GuessGameStopBet 游戏停止下注
message GuessGameStopBet{ message GuessGameStopBet{
string gameId = 1; string gameId = 1;
} }
//游戏异常终止,退还下注 //GuessGameAbort 游戏异常终止,退还下注
message GuessGameAbort{ message GuessGameAbort{
string gameId = 1; string gameId = 1;
} }
//游戏结果揭晓 //GuessGamePublish 游戏结果揭晓
message GuessGamePublish{ message GuessGamePublish{
string gameId = 1; string gameId = 1;
string result = 2; string result = 2;
} }
//查询游戏结果 //GuessGameQuery 查询游戏结果
message GuessGameQuery{ message GuessGameQuery{
string gameId = 1; string gameId = 1;
uint32 ty = 2; uint32 ty = 2;
} }
//QueryGuessGameInfo 游戏信息查询消息
message QueryGuessGameInfo { message QueryGuessGameInfo {
string gameId = 1; string gameId = 1;
string addr = 2; string addr = 2;
...@@ -127,18 +131,22 @@ message QueryGuessGameInfo { ...@@ -127,18 +131,22 @@ message QueryGuessGameInfo {
string category = 6; string category = 6;
} }
//ReplyGuessGameInfo 游戏信息查询响应消息
message ReplyGuessGameInfo { message ReplyGuessGameInfo {
GuessGame game = 1; GuessGame game = 1;
} }
//QueryGuessGameInfos 游戏信息列表查询消息
message QueryGuessGameInfos { message QueryGuessGameInfos {
repeated string gameIds = 1; repeated string gameIds = 1;
} }
//ReplyGuessGameInfos 游戏信息列表查询响应消息
message ReplyGuessGameInfos { message ReplyGuessGameInfos {
repeated GuessGame games = 1; repeated GuessGame games = 1;
} }
//ReceiptGuessGame 竞猜游戏收据信息
message ReceiptGuessGame { message ReceiptGuessGame {
string gameId = 1; string gameId = 1;
int32 preStatus = 2; int32 preStatus = 2;
...@@ -151,6 +159,7 @@ message ReceiptGuessGame { ...@@ -151,6 +159,7 @@ message ReceiptGuessGame {
bool statusChange = 9; bool statusChange = 9;
} }
//GuessStartTxReq 构造start交易的请求
message GuessStartTxReq { message GuessStartTxReq {
string topic = 1; string topic = 1;
string options = 2; string options = 2;
...@@ -167,6 +176,7 @@ message GuessStartTxReq { ...@@ -167,6 +176,7 @@ message GuessStartTxReq {
int64 fee = 13; int64 fee = 13;
} }
//GuessBetTxReq 构造bet交易的请求
message GuessBetTxReq { message GuessBetTxReq {
string gameId = 1; string gameId = 1;
string option = 2; string option = 2;
...@@ -174,40 +184,39 @@ message GuessBetTxReq { ...@@ -174,40 +184,39 @@ message GuessBetTxReq {
int64 fee = 4; int64 fee = 4;
} }
//GuessStopBetTxReq 构造stopBet交易的请求
message GuessStopBetTxReq { message GuessStopBetTxReq {
string gameId = 1; string gameId = 1;
int64 fee = 2; int64 fee = 2;
} }
//GuessAbortTxReq 构造abort交易的请求
message GuessAbortTxReq { message GuessAbortTxReq {
string gameId = 1; string gameId = 1;
int64 fee = 2; int64 fee = 2;
} }
//GuessPublishTxReq 构造publish交易的请求
message GuessPublishTxReq { message GuessPublishTxReq {
string gameId = 1; string gameId = 1;
string result = 2; string result = 2;
int64 fee = 3; int64 fee = 3;
} }
// 索引value值 // GuessGameRecord game信息查询记录
message GuessGameRecord { message GuessGameRecord {
string gameId = 1; string gameId = 1;
int32 status = 2; int32 status = 2;
int64 index = 3; int64 index = 3;
} }
message GuessGameIndexRecord { // GuessGameRecords game信息查询记录集
string gameId = 1;
int64 index = 2;
}
message GuessGameRecords { message GuessGameRecords {
repeated GuessGameRecord records = 1; repeated GuessGameRecord records = 1;
} }
// guess 对外提供服务的接口 // service guess 为guess 对外提供服务的接口
service guess { service guess {
//游戏开始 //游戏开始
rpc GuessStart(GuessGameStart) returns (UnsignTx) {} rpc GuessStart(GuessGameStart) returns (UnsignTx) {}
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
pb "github.com/33cn/plugin/plugin/dapp/guess/types" pb "github.com/33cn/plugin/plugin/dapp/guess/types"
) )
//GuessStartTx 构造start原始交易
func (c *Jrpc) GuessStartTx(parm *pb.GuessStartTxReq, result *interface{}) error { func (c *Jrpc) GuessStartTx(parm *pb.GuessStartTxReq, result *interface{}) error {
if parm == nil { if parm == nil {
return types.ErrInvalidParam return types.ErrInvalidParam
...@@ -25,6 +26,7 @@ func (c *Jrpc) GuessStartTx(parm *pb.GuessStartTxReq, result *interface{}) error ...@@ -25,6 +26,7 @@ func (c *Jrpc) GuessStartTx(parm *pb.GuessStartTxReq, result *interface{}) error
return nil return nil
} }
//GuessBetTx 构造bet原始交易
func (c *Jrpc) GuessBetTx(parm *pb.GuessBetTxReq, result *interface{}) error { func (c *Jrpc) GuessBetTx(parm *pb.GuessBetTxReq, result *interface{}) error {
if parm == nil { if parm == nil {
return types.ErrInvalidParam return types.ErrInvalidParam
...@@ -39,6 +41,7 @@ func (c *Jrpc) GuessBetTx(parm *pb.GuessBetTxReq, result *interface{}) error { ...@@ -39,6 +41,7 @@ func (c *Jrpc) GuessBetTx(parm *pb.GuessBetTxReq, result *interface{}) error {
return nil return nil
} }
//GuessStopBetTx 构造stopBet原始交易
func (c *Jrpc) GuessStopBetTx(parm *pb.GuessStopBetTxReq, result *interface{}) error { func (c *Jrpc) GuessStopBetTx(parm *pb.GuessStopBetTxReq, result *interface{}) error {
if parm == nil { if parm == nil {
return types.ErrInvalidParam return types.ErrInvalidParam
...@@ -53,6 +56,7 @@ func (c *Jrpc) GuessStopBetTx(parm *pb.GuessStopBetTxReq, result *interface{}) e ...@@ -53,6 +56,7 @@ func (c *Jrpc) GuessStopBetTx(parm *pb.GuessStopBetTxReq, result *interface{}) e
return nil return nil
} }
//GuessAbortTx 构造abort原始交易
func (c *Jrpc) GuessAbortTx(parm *pb.GuessAbortTxReq, result *interface{}) error { func (c *Jrpc) GuessAbortTx(parm *pb.GuessAbortTxReq, result *interface{}) error {
if parm == nil { if parm == nil {
return types.ErrInvalidParam return types.ErrInvalidParam
...@@ -67,6 +71,7 @@ func (c *Jrpc) GuessAbortTx(parm *pb.GuessAbortTxReq, result *interface{}) error ...@@ -67,6 +71,7 @@ func (c *Jrpc) GuessAbortTx(parm *pb.GuessAbortTxReq, result *interface{}) error
return nil return nil
} }
//GuessPublishTx 构造publish原始交易
func (c *Jrpc) GuessPublishTx(parm *pb.GuessPublishTxReq, result *interface{}) error { func (c *Jrpc) GuessPublishTx(parm *pb.GuessPublishTxReq, result *interface{}) error {
if parm == nil { if parm == nil {
return types.ErrInvalidParam return types.ErrInvalidParam
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
pb "github.com/33cn/plugin/plugin/dapp/guess/types" pb "github.com/33cn/plugin/plugin/dapp/guess/types"
) )
//构造start原始交易
func (c *channelClient) GuessStart(ctx context.Context, parm *pb.GuessStartTxReq) (*types.UnsignTx, error) { func (c *channelClient) GuessStart(ctx context.Context, parm *pb.GuessStartTxReq) (*types.UnsignTx, error) {
v := &pb.GuessGameStart{ v := &pb.GuessGameStart{
Topic: parm.Topic, Topic: parm.Topic,
...@@ -28,7 +29,7 @@ func (c *channelClient) GuessStart(ctx context.Context, parm *pb.GuessStartTxReq ...@@ -28,7 +29,7 @@ func (c *channelClient) GuessStart(ctx context.Context, parm *pb.GuessStartTxReq
val := &pb.GuessGameAction{ val := &pb.GuessGameAction{
Ty: pb.GuessGameActionStart, Ty: pb.GuessGameActionStart,
Value: &pb.GuessGameAction_Start{v}, Value: &pb.GuessGameAction_Start{Start: v},
} }
name := types.ExecName(pb.GuessX) name := types.ExecName(pb.GuessX)
...@@ -47,6 +48,7 @@ func (c *channelClient) GuessStart(ctx context.Context, parm *pb.GuessStartTxReq ...@@ -47,6 +48,7 @@ func (c *channelClient) GuessStart(ctx context.Context, parm *pb.GuessStartTxReq
return &types.UnsignTx{Data: data}, nil return &types.UnsignTx{Data: data}, nil
} }
//构造bet原始交易
func (c *channelClient) GuessBet(ctx context.Context, parm *pb.GuessBetTxReq) (*types.UnsignTx, error) { func (c *channelClient) GuessBet(ctx context.Context, parm *pb.GuessBetTxReq) (*types.UnsignTx, error) {
v := &pb.GuessGameBet{ v := &pb.GuessGameBet{
GameId: parm.GameId, GameId: parm.GameId,
...@@ -56,7 +58,7 @@ func (c *channelClient) GuessBet(ctx context.Context, parm *pb.GuessBetTxReq) (* ...@@ -56,7 +58,7 @@ func (c *channelClient) GuessBet(ctx context.Context, parm *pb.GuessBetTxReq) (*
val := &pb.GuessGameAction{ val := &pb.GuessGameAction{
Ty: pb.GuessGameActionBet, Ty: pb.GuessGameActionBet,
Value: &pb.GuessGameAction_Bet{v}, Value: &pb.GuessGameAction_Bet{Bet: v},
} }
name := types.ExecName(pb.GuessX) name := types.ExecName(pb.GuessX)
...@@ -75,6 +77,7 @@ func (c *channelClient) GuessBet(ctx context.Context, parm *pb.GuessBetTxReq) (* ...@@ -75,6 +77,7 @@ func (c *channelClient) GuessBet(ctx context.Context, parm *pb.GuessBetTxReq) (*
return &types.UnsignTx{Data: data}, nil return &types.UnsignTx{Data: data}, nil
} }
//构造stopBet原始交易
func (c *channelClient) GuessStopBet(ctx context.Context, parm *pb.GuessStopBetTxReq) (*types.UnsignTx, error) { func (c *channelClient) GuessStopBet(ctx context.Context, parm *pb.GuessStopBetTxReq) (*types.UnsignTx, error) {
v := &pb.GuessGameStopBet{ v := &pb.GuessGameStopBet{
GameId: parm.GameId, GameId: parm.GameId,
...@@ -82,7 +85,7 @@ func (c *channelClient) GuessStopBet(ctx context.Context, parm *pb.GuessStopBetT ...@@ -82,7 +85,7 @@ func (c *channelClient) GuessStopBet(ctx context.Context, parm *pb.GuessStopBetT
val := &pb.GuessGameAction{ val := &pb.GuessGameAction{
Ty: pb.GuessGameActionStopBet, Ty: pb.GuessGameActionStopBet,
Value: &pb.GuessGameAction_StopBet{v}, Value: &pb.GuessGameAction_StopBet{StopBet: v},
} }
name := types.ExecName(pb.GuessX) name := types.ExecName(pb.GuessX)
...@@ -101,6 +104,7 @@ func (c *channelClient) GuessStopBet(ctx context.Context, parm *pb.GuessStopBetT ...@@ -101,6 +104,7 @@ func (c *channelClient) GuessStopBet(ctx context.Context, parm *pb.GuessStopBetT
return &types.UnsignTx{Data: data}, nil return &types.UnsignTx{Data: data}, nil
} }
//构造abort原始交易
func (c *channelClient) GuessAbort(ctx context.Context, parm *pb.GuessAbortTxReq) (*types.UnsignTx, error) { func (c *channelClient) GuessAbort(ctx context.Context, parm *pb.GuessAbortTxReq) (*types.UnsignTx, error) {
v := &pb.GuessGameAbort{ v := &pb.GuessGameAbort{
GameId: parm.GameId, GameId: parm.GameId,
...@@ -108,7 +112,7 @@ func (c *channelClient) GuessAbort(ctx context.Context, parm *pb.GuessAbortTxReq ...@@ -108,7 +112,7 @@ func (c *channelClient) GuessAbort(ctx context.Context, parm *pb.GuessAbortTxReq
val := &pb.GuessGameAction{ val := &pb.GuessGameAction{
Ty: pb.GuessGameActionAbort, Ty: pb.GuessGameActionAbort,
Value: &pb.GuessGameAction_Abort{v}, Value: &pb.GuessGameAction_Abort{Abort: v},
} }
name := types.ExecName(pb.GuessX) name := types.ExecName(pb.GuessX)
tx := &types.Transaction{ tx := &types.Transaction{
...@@ -126,6 +130,7 @@ func (c *channelClient) GuessAbort(ctx context.Context, parm *pb.GuessAbortTxReq ...@@ -126,6 +130,7 @@ func (c *channelClient) GuessAbort(ctx context.Context, parm *pb.GuessAbortTxReq
return &types.UnsignTx{Data: data}, nil return &types.UnsignTx{Data: data}, nil
} }
//构造publish原始交易
func (c *channelClient) GuessPublish(ctx context.Context, parm *pb.GuessPublishTxReq) (*types.UnsignTx, error) { func (c *channelClient) GuessPublish(ctx context.Context, parm *pb.GuessPublishTxReq) (*types.UnsignTx, error) {
v := &pb.GuessGamePublish{ v := &pb.GuessGamePublish{
GameId: parm.GameId, GameId: parm.GameId,
...@@ -134,7 +139,7 @@ func (c *channelClient) GuessPublish(ctx context.Context, parm *pb.GuessPublishT ...@@ -134,7 +139,7 @@ func (c *channelClient) GuessPublish(ctx context.Context, parm *pb.GuessPublishT
val := &pb.GuessGameAction{ val := &pb.GuessGameAction{
Ty: pb.GuessGameActionPublish, Ty: pb.GuessGameActionPublish,
Value: &pb.GuessGameAction_Publish{v}, Value: &pb.GuessGameAction_Publish{Publish: v},
} }
name := types.ExecName(pb.GuessX) name := types.ExecName(pb.GuessX)
...@@ -153,10 +158,11 @@ func (c *channelClient) GuessPublish(ctx context.Context, parm *pb.GuessPublishT ...@@ -153,10 +158,11 @@ func (c *channelClient) GuessPublish(ctx context.Context, parm *pb.GuessPublishT
return &types.UnsignTx{Data: data}, nil return &types.UnsignTx{Data: data}, nil
} }
//构造查询交易
func (c *channelClient) Show(ctx context.Context, head *pb.GuessGameQuery) (*types.UnsignTx, error) { func (c *channelClient) Show(ctx context.Context, head *pb.GuessGameQuery) (*types.UnsignTx, error) {
val := &pb.GuessGameAction{ val := &pb.GuessGameAction{
Ty: pb.GuessGameActionQuery, Ty: pb.GuessGameActionQuery,
Value: &pb.GuessGameAction_Query{head}, Value: &pb.GuessGameAction_Query{Query: head},
} }
tx, err := types.CreateFormatTx(pb.GuessX, types.Encode(val)) tx, err := types.CreateFormatTx(pb.GuessX, types.Encode(val))
if err != nil { if err != nil {
......
...@@ -8,10 +8,12 @@ import ( ...@@ -8,10 +8,12 @@ import (
"github.com/33cn/chain33/rpc/types" "github.com/33cn/chain33/rpc/types"
) )
//Jrpc struct
type Jrpc struct { type Jrpc struct {
cli *channelClient cli *channelClient
} }
//Grpc struct
type Grpc struct { type Grpc struct {
*channelClient *channelClient
} }
...@@ -20,6 +22,7 @@ type channelClient struct { ...@@ -20,6 +22,7 @@ type channelClient struct {
types.ChannelClient types.ChannelClient
} }
//Init method
func Init(name string, s types.RPCServer) { func Init(name string, s types.RPCServer) {
cli := &channelClient{} cli := &channelClient{}
grpc := &Grpc{channelClient: cli} grpc := &Grpc{channelClient: cli}
......
...@@ -26,6 +26,7 @@ const ( ...@@ -26,6 +26,7 @@ const (
GuessGameStatusTimeOut GuessGameStatusTimeOut
) )
//game log ty
const ( const (
TyLogGuessGameStart = 901 TyLogGuessGameStart = 901
TyLogGuessGameBet = 902 TyLogGuessGameBet = 902
...@@ -45,18 +46,28 @@ var ( ...@@ -45,18 +46,28 @@ var (
) )
const ( const (
//查询方法名 //FuncName_QueryGamesByIds func name
FuncName_QueryGamesByIds = "QueryGamesByIds" FuncName_QueryGamesByIds = "QueryGamesByIds"
//FuncName_QueryGameById func name
FuncName_QueryGameById = "QueryGameById" FuncName_QueryGameById = "QueryGameById"
//FuncName_QueryGameByAddr func name
FuncName_QueryGameByAddr = "QueryGamesByAddr" FuncName_QueryGameByAddr = "QueryGamesByAddr"
//FuncName_QueryGameByStatus func name
FuncName_QueryGameByStatus = "QueryGamesByStatus" FuncName_QueryGameByStatus = "QueryGamesByStatus"
//FuncName_QueryGameByAdminAddr func name
FuncName_QueryGameByAdminAddr = "QueryGamesByAdminAddr" FuncName_QueryGameByAdminAddr = "QueryGamesByAdminAddr"
//FuncName_QueryGameByAddrStatus func name
FuncName_QueryGameByAddrStatus = "QueryGamesByAddrStatus" FuncName_QueryGameByAddrStatus = "QueryGamesByAddrStatus"
//FuncName_QueryGameByAdminStatus func name
FuncName_QueryGameByAdminStatus = "QueryGamesByAdminStatus" FuncName_QueryGameByAdminStatus = "QueryGamesByAdminStatus"
//FuncName_QueryGameByCategoryStatus func name
FuncName_QueryGameByCategoryStatus="QueryGamesByCategoryStatus" FuncName_QueryGameByCategoryStatus="QueryGamesByCategoryStatus"
) )
const ( const (
//DevShareAddr default value
DevShareAddr = "1D6RFZNp2rh6QdbcZ1d7RWuBUz61We6SD7" DevShareAddr = "1D6RFZNp2rh6QdbcZ1d7RWuBUz61We6SD7"
//PlatformShareAddr default value
PlatformShareAddr = "1PHtChNt3UcfssR7v7trKSk3WJtAWjKjjX" PlatformShareAddr = "1PHtChNt3UcfssR7v7trKSk3WJtAWjKjjX"
) )
\ No newline at end of file
...@@ -10,4 +10,5 @@ import "errors" ...@@ -10,4 +10,5 @@ import "errors"
var ( var (
ErrNoPrivilege = errors.New("ErrNoPrivilege") ErrNoPrivilege = errors.New("ErrNoPrivilege")
ErrGuessStatus = errors.New("ErrGuessStatus") ErrGuessStatus = errors.New("ErrGuessStatus")
ErrOverBetsLimit = errors.New("ErrOverBetsLimit")
) )
This diff is collapsed.
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package types package types
//GuessGameStartTx struct
type GuessGameStartTx struct { type GuessGameStartTx struct {
Topic string `json:"topic,omitempty"` Topic string `json:"topic,omitempty"`
Options string `json:"options,omitempty"` Options string `json:"options,omitempty"`
...@@ -19,6 +20,7 @@ type GuessGameStartTx struct { ...@@ -19,6 +20,7 @@ type GuessGameStartTx struct {
Fee int64 `json:"fee,omitempty"` Fee int64 `json:"fee,omitempty"`
} }
//GuessGameBetTx struct
type GuessGameBetTx struct { type GuessGameBetTx struct {
GameId string `json:"gameId,omitempty"` GameId string `json:"gameId,omitempty"`
Option string `json:"option,omitempty"` Option string `json:"option,omitempty"`
...@@ -26,17 +28,20 @@ type GuessGameBetTx struct { ...@@ -26,17 +28,20 @@ type GuessGameBetTx struct {
Fee int64 `json:"fee,omitempty"` Fee int64 `json:"fee,omitempty"`
} }
//GuessGameStopBetTx struct
type GuessGameStopBetTx struct { type GuessGameStopBetTx struct {
GameId string `json:"gameId,omitempty"` GameId string `json:"gameId,omitempty"`
Fee int64 `json:"fee,omitempty"` Fee int64 `json:"fee,omitempty"`
} }
//GuessGamePublishTx struct
type GuessGamePublishTx struct { type GuessGamePublishTx struct {
GameId string `json:"gameId,omitempty"` GameId string `json:"gameId,omitempty"`
Result string `json:"result,omitempty"` Result string `json:"result,omitempty"`
Fee int64 `json:"fee,omitempty"` Fee int64 `json:"fee,omitempty"`
} }
//GuessGameAbortTx struct
type GuessGameAbortTx struct { type GuessGameAbortTx struct {
GameId string `json:"gameId,omitempty"` GameId string `json:"gameId,omitempty"`
Fee int64 `json:"fee,omitempty"` Fee int64 `json:"fee,omitempty"`
......
...@@ -24,21 +24,24 @@ func init() { ...@@ -24,21 +24,24 @@ func init() {
types.RegisterDappFork(GuessX, "Enable", 0) types.RegisterDappFork(GuessX, "Enable", 0)
} }
// exec // GuessType struct
type GuessType struct { type GuessType struct {
types.ExecTypeBase types.ExecTypeBase
} }
// NewType method
func NewType() *GuessType { func NewType() *GuessType {
c := &GuessType{} c := &GuessType{}
c.SetChild(c) c.SetChild(c)
return c return c
} }
// GetPayload method
func (t *GuessType) GetPayload() types.Message { func (t *GuessType) GetPayload() types.Message {
return &GuessGameAction{} return &GuessGameAction{}
} }
// GetTypeMap method
func (t *GuessType) GetTypeMap() map[string]int32 { func (t *GuessType) GetTypeMap() map[string]int32 {
return map[string]int32{ return map[string]int32{
"Start": GuessGameActionStart, "Start": GuessGameActionStart,
...@@ -50,14 +53,15 @@ func (t *GuessType) GetTypeMap() map[string]int32 { ...@@ -50,14 +53,15 @@ func (t *GuessType) GetTypeMap() map[string]int32 {
} }
} }
// GetLogMap method
func (t *GuessType) GetLogMap() map[int64]*types.LogInfo { func (t *GuessType) GetLogMap() map[int64]*types.LogInfo {
return map[int64]*types.LogInfo{ return map[int64]*types.LogInfo{
TyLogGuessGameStart: {reflect.TypeOf(ReceiptGuessGame{}), "TyLogGuessGameStart"}, TyLogGuessGameStart: { Ty: reflect.TypeOf(ReceiptGuessGame{}), Name: "TyLogGuessGameStart"},
TyLogGuessGameBet: {reflect.TypeOf(ReceiptGuessGame{}), "TyLogGuessGameBet"}, TyLogGuessGameBet: { Ty: reflect.TypeOf(ReceiptGuessGame{}), Name: "TyLogGuessGameBet"},
TyLogGuessGameStopBet: {reflect.TypeOf(ReceiptGuessGame{}), "TyLogGuessGameStopBet"}, TyLogGuessGameStopBet: { Ty: reflect.TypeOf(ReceiptGuessGame{}), Name: "TyLogGuessGameStopBet"},
TyLogGuessGameAbort: {reflect.TypeOf(ReceiptGuessGame{}), "TyLogGuessGameAbort"}, TyLogGuessGameAbort: { Ty: reflect.TypeOf(ReceiptGuessGame{}), Name: "TyLogGuessGameAbort"},
TyLogGuessGamePublish: {reflect.TypeOf(ReceiptGuessGame{}), "TyLogGuessGamePublish"}, TyLogGuessGamePublish: { Ty: reflect.TypeOf(ReceiptGuessGame{}), Name: "TyLogGuessGamePublish"},
TyLogGuessGameTimeout: {reflect.TypeOf(ReceiptGuessGame{}), "TyLogGuessGameTimeout"}, TyLogGuessGameTimeout: { Ty: reflect.TypeOf(ReceiptGuessGame{}), Name: "TyLogGuessGameTimeout"},
} }
} }
...@@ -105,12 +109,12 @@ func (t *GuessType) CreateTx(action string, message json.RawMessage) (*types.Tra ...@@ -105,12 +109,12 @@ func (t *GuessType) CreateTx(action string, message json.RawMessage) (*types.Tra
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
return CreateRawGuessAbortTx(&param) return CreateRawGuessAbortTx(&param)
} else {
return nil, types.ErrNotSupport
} }
return nil, types.ErrNotSupport
} }
// CreateRawLotteryCreateTx method // CreateRawGuessStartTx method
func CreateRawGuessStartTx(parm *GuessGameStartTx) (*types.Transaction, error) { func CreateRawGuessStartTx(parm *GuessGameStartTx) (*types.Transaction, error) {
if parm == nil { if parm == nil {
llog.Error("CreateRawGuessStartTx", "parm", parm) llog.Error("CreateRawGuessStartTx", "parm", parm)
......
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