Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
82b582dc
Commit
82b582dc
authored
Nov 30, 2018
by
张振华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
guess
parent
80bdb1bb
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
474 additions
and
409 deletions
+474
-409
game.go
plugin/dapp/guess/commands/game.go
+3
-5
exec_del_local.go
plugin/dapp/guess/executor/exec_del_local.go
+57
-18
exec_local.go
plugin/dapp/guess/executor/exec_local.go
+33
-23
guess.go
plugin/dapp/guess/executor/guess.go
+23
-187
guessdb.go
plugin/dapp/guess/executor/guessdb.go
+0
-0
keys.go
plugin/dapp/guess/executor/keys.go
+192
-0
query.go
plugin/dapp/guess/executor/query.go
+2
-2
guess.proto
plugin/dapp/guess/proto/guess.proto
+10
-161
jrpc.go
plugin/dapp/guess/rpc/jrpc.go
+3
-2
const.go
plugin/dapp/guess/types/const.go
+0
-11
guess.pb.go
plugin/dapp/guess/types/guess.pb.go
+0
-0
types.go
plugin/dapp/guess/types/types.go
+151
-0
No files found.
plugin/dapp/guess/commands/game.go
View file @
82b582dc
...
...
@@ -5,12 +5,7 @@
package
commands
import
(
"fmt"
"go.uber.org/zap"
"strconv"
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
"github.com/33cn/chain33/types"
pkt
"github.com/33cn/plugin/plugin/dapp/guess/types"
"github.com/spf13/cobra"
)
...
...
@@ -231,7 +226,9 @@ func addGuessQueryFlags(cmd *cobra.Command) {
cmd
.
Flags
()
.
StringP
(
"gameIDs"
,
"d"
,
""
,
"gameIDs"
)
}
func
guessQuery
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
/*
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
gameID, _ := cmd.Flags().GetString("gameID")
address, _ := cmd.Flags().GetString("address")
...
...
@@ -279,4 +276,5 @@ func guessQuery(cmd *cobra.Command, args []string) {
fmt.Println("Error: requeres at least one of gameID, address or status")
cmd.Help()
}
*/
}
plugin/dapp/guess/executor/exec_del_local.go
View file @
82b582dc
...
...
@@ -6,32 +6,66 @@ package executor
import
(
"github.com/33cn/chain33/types"
pkt
"github.com/33cn/plugin/plugin/dapp/
pokerbull
/types"
pkt
"github.com/33cn/plugin/plugin/dapp/
guess
/types"
)
func
(
g
*
PokerBull
)
rollbackIndex
(
log
*
pkt
.
ReceiptPBGame
)
(
kvs
[]
*
types
.
KeyValue
)
{
kvs
=
append
(
kvs
,
delPBGameStatusAndPlayer
(
log
.
Status
,
log
.
PlayerNum
,
log
.
Value
,
log
.
Index
))
kvs
=
append
(
kvs
,
addPBGameStatusAndPlayer
(
log
.
PreStatus
,
log
.
PlayerNum
,
log
.
PrevIndex
,
log
.
Value
,
log
.
GameId
))
kvs
=
append
(
kvs
,
delPBGameStatusIndexKey
(
log
.
Status
,
log
.
Index
))
kvs
=
append
(
kvs
,
addPBGameStatusIndexKey
(
log
.
PreStatus
,
log
.
GameId
,
log
.
PrevIndex
))
func
(
g
*
Guess
)
rollbackIndex
(
log
*
pkt
.
ReceiptGuessGame
)
(
kvs
[]
*
types
.
KeyValue
)
{
//新创建游戏,将增加的记录都删除掉
if
log
.
Status
==
pkt
.
GuessGameStatusStart
{
//kvs = append(kvs, addGuessGameAddrIndexKey(log.Status, log.Addr, log.GameId, log.Index))
kvs
=
append
(
kvs
,
delGuessGameStatusIndexKey
(
log
.
Status
,
log
.
Index
))
kvs
=
append
(
kvs
,
delGuessGameAdminIndexKey
(
log
.
AdminAddr
,
log
.
Index
))
kvs
=
append
(
kvs
,
delGuessGameAdminStatusIndexKey
(
log
.
Status
,
log
.
AdminAddr
,
log
.
Index
))
kvs
=
append
(
kvs
,
delGuessGameCategoryStatusIndexKey
(
log
.
Status
,
log
.
Category
,
log
.
Index
))
}
else
if
log
.
Status
==
pkt
.
GuessGameStatusBet
{
//如果是下注状态,则有用户进行了下注操作,对这些记录进行删除
kvs
=
append
(
kvs
,
delGuessGameAddrIndexKey
(
log
.
Addr
,
log
.
Index
))
kvs
=
append
(
kvs
,
delGuessGameAddrStatusIndexKey
(
log
.
Status
,
log
.
Addr
,
log
.
Index
))
for
_
,
v
:=
range
log
.
Players
{
kvs
=
append
(
kvs
,
delPBGameAddrIndexKey
(
v
,
log
.
Index
))
kvs
=
append
(
kvs
,
addPBGameAddrIndexKey
(
log
.
PreStatus
,
v
,
log
.
GameId
,
log
.
PrevIndex
))
//如果发生了状态变化,恢复老状态的记录,删除新添加的状态记录
if
log
.
StatusChange
{
kvs
=
append
(
kvs
,
addGuessGameStatusIndexKey
(
log
.
PreStatus
,
log
.
GameId
,
log
.
PreIndex
))
kvs
=
append
(
kvs
,
addGuessGameAdminStatusIndexKey
(
log
.
PreStatus
,
log
.
AdminAddr
,
log
.
GameId
,
log
.
PreIndex
))
kvs
=
append
(
kvs
,
addGuessGameCategoryStatusIndexKey
(
log
.
PreStatus
,
log
.
Category
,
log
.
GameId
,
log
.
PreIndex
))
kvs
=
append
(
kvs
,
delGuessGameStatusIndexKey
(
log
.
Status
,
log
.
Index
))
kvs
=
append
(
kvs
,
delGuessGameAdminStatusIndexKey
(
log
.
Status
,
log
.
AdminAddr
,
log
.
Index
))
kvs
=
append
(
kvs
,
delGuessGameCategoryStatusIndexKey
(
log
.
Status
,
log
.
Category
,
log
.
Index
))
}
}
else
if
log
.
StatusChange
{
//其他状态时的状态发生变化的情况,要将老状态对应的记录恢复,同时删除新加的状态记录;对于每个地址的下注记录也需要遍历处理。
kvs
=
append
(
kvs
,
addGuessGameStatusIndexKey
(
log
.
PreStatus
,
log
.
GameId
,
log
.
PreIndex
))
kvs
=
append
(
kvs
,
addGuessGameAdminStatusIndexKey
(
log
.
PreStatus
,
log
.
AdminAddr
,
log
.
GameId
,
log
.
PreIndex
))
kvs
=
append
(
kvs
,
addGuessGameCategoryStatusIndexKey
(
log
.
PreStatus
,
log
.
Category
,
log
.
GameId
,
log
.
PreIndex
))
kvs
=
append
(
kvs
,
delGuessGameStatusIndexKey
(
log
.
Status
,
log
.
Index
))
kvs
=
append
(
kvs
,
delGuessGameAdminStatusIndexKey
(
log
.
Status
,
log
.
AdminAddr
,
log
.
Index
))
kvs
=
append
(
kvs
,
delGuessGameCategoryStatusIndexKey
(
log
.
Status
,
log
.
Category
,
log
.
Index
))
//从game中遍历每个地址的记录进行删除新增记录,回复老记录
game
,
err
:=
readGame
(
g
.
GetStateDB
(),
log
.
GameId
)
if
err
==
nil
{
for
i
:=
0
;
i
<
len
(
game
.
Plays
);
i
++
{
player
:=
game
.
Plays
[
i
]
kvs
=
append
(
kvs
,
addGuessGameAddrStatusIndexKey
(
log
.
PreStatus
,
player
.
Addr
,
log
.
GameId
,
player
.
Bet
.
PreIndex
))
kvs
=
append
(
kvs
,
delGuessGameAddrStatusIndexKey
(
log
.
Status
,
player
.
Addr
,
log
.
Index
)
}
}
}
return
kvs
}
func
(
g
*
PokerBull
)
execDelLocal
(
receiptData
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
g
*
Guess
)
execDelLocal
(
receiptData
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
dbSet
:=
&
types
.
LocalDBSet
{}
if
receiptData
.
GetTy
()
!=
types
.
ExecOk
{
return
dbSet
,
nil
}
for
_
,
log
:=
range
receiptData
.
Logs
{
switch
log
.
GetTy
()
{
case
pkt
.
TyLog
PBGameStart
,
pkt
.
TyLogPBGameContinue
,
pkt
.
TyLogPBGameQui
t
:
receiptGame
:=
&
pkt
.
Receipt
PB
Game
{}
case
pkt
.
TyLog
GuessGameStart
,
pkt
.
TyLogGuessGameBet
,
pkt
.
TyLogGuessGameStopBet
,
pkt
.
TyLogGuessGameAbort
,
pkt
.
TyLogGuessGamePublish
,
pkt
.
TyLogGuessGameTimeou
t
:
receiptGame
:=
&
pkt
.
Receipt
Guess
Game
{}
if
err
:=
types
.
Decode
(
log
.
Log
,
receiptGame
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -42,14 +76,18 @@ func (g *PokerBull) execDelLocal(receiptData *types.ReceiptData) (*types.LocalDB
return
dbSet
,
nil
}
func
(
g
*
PokerBull
)
ExecDelLocal_Start
(
payload
*
pkt
.
PB
GameStart
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
g
.
exec
Del
Local
(
receiptData
)
func
(
g
*
Guess
)
ExecDelLocal_Start
(
payload
*
pkt
.
Guess
GameStart
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
g
.
execLocal
(
receiptData
)
}
func
(
g
*
PokerBull
)
ExecDelLocal_Continue
(
payload
*
pkt
.
PBGameContinue
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
g
.
exec
Del
Local
(
receiptData
)
func
(
g
*
Guess
)
ExecDelLocal_Bet
(
payload
*
pkt
.
GuessGameBet
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
g
.
execLocal
(
receiptData
)
}
func
(
g
*
PokerBull
)
ExecDelLocal_Quit
(
payload
*
pkt
.
PBGameQuit
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
g
.
exec
Del
Local
(
receiptData
)
func
(
g
*
Guess
)
ExecDelLocal_Publish
(
payload
*
pkt
.
GuessGamePublish
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
g
.
execLocal
(
receiptData
)
}
func
(
g
*
Guess
)
ExecDelLocal_Abort
(
payload
*
pkt
.
GuessGameAbort
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
g
.
execLocal
(
receiptData
)
}
\ No newline at end of file
plugin/dapp/guess/executor/exec_local.go
View file @
82b582dc
...
...
@@ -9,27 +9,28 @@ import (
pkt
"github.com/33cn/plugin/plugin/dapp/guess/types"
)
func
(
c
*
Guess
)
updateIndex
(
log
*
pkt
.
ReceiptGuessGame
)
(
kvs
[]
*
types
.
KeyValue
)
{
func
(
g
*
Guess
)
updateIndex
(
log
*
pkt
.
ReceiptGuessGame
)
(
kvs
[]
*
types
.
KeyValue
)
{
//新创建游戏
if
log
.
Status
==
pkt
.
GuessGameStatusStart
{
//kvs = append(kvs, addGuessGameAddrIndexKey(log.Status, log.Addr, log.GameId, log.Index))
kvs
=
append
(
kvs
,
addGuessGameStatusIndexKey
(
log
.
Status
,
log
.
GameId
,
log
.
Index
))
kvs
=
append
(
kvs
,
addGuessGameAdminIndexKey
(
log
.
Status
,
log
.
Addr
,
log
.
GameId
,
log
.
Index
))
kvs
=
append
(
kvs
,
addGuessGameAdminIndexKey
(
log
.
Status
,
log
.
Ad
minAd
dr
,
log
.
GameId
,
log
.
Index
))
kvs
=
append
(
kvs
,
addGuessGameAdminStatusIndexKey
(
log
.
Status
,
log
.
AdminAddr
,
log
.
GameId
,
log
.
Index
))
kvs
=
append
(
kvs
,
addGuessGameCategoryStatusIndexKey
(
log
.
Status
,
log
.
Category
,
log
.
GameId
,
log
.
Index
))
}
else
if
log
.
Status
==
pkt
.
GuessGameStatusBet
{
//如果是下注状态,则有用户进行了下注操作
kvs
=
append
(
kvs
,
addGuessGameAddrIndexKey
(
log
.
Status
,
log
.
Addr
,
log
.
GameId
,
log
.
Index
))
kvs
=
append
(
kvs
,
addGuessGameAddrStatusIndexKey
(
log
.
Status
,
log
.
Addr
,
log
.
GameId
,
log
.
Index
))
//如果发生了状态变化,则是从start->bet,对于老状态的记录进行删除操作,并增加新状态记录
if
log
.
StatusChange
{
kvs
=
append
(
kvs
,
addGuessGameStatusIndexKey
(
log
.
Status
,
log
.
GameId
,
log
.
Index
))
kvs
=
append
(
kvs
,
addGuessGameAdminStatusIndexKey
(
log
.
Status
,
log
.
AdminAddr
,
log
.
GameId
,
log
.
Index
))
kvs
=
append
(
kvs
,
addGuessGameCategoryStatusIndexKey
(
log
.
Status
,
log
.
Category
,
log
.
GameId
,
log
.
Index
))
kvs
=
append
(
kvs
,
addGuessGameStatusIndexKey
(
log
.
Status
,
log
.
GameId
,
log
.
Index
))
kvs
=
append
(
kvs
,
addGuessGameAdminStatusIndexKey
(
log
.
Status
,
log
.
AdminAddr
,
log
.
GameId
,
log
.
Index
))
kvs
=
append
(
kvs
,
addGuessGameAddrStatusIndexKey
(
log
.
Status
,
log
.
Addr
,
log
.
GameId
,
log
.
Index
))
kvs
=
append
(
kvs
,
addGuessGameCategoryStatusIndexKey
(
log
.
Status
,
log
.
Category
,
log
.
GameId
,
log
.
Index
))
//对于老状态进行删除
kvs
=
append
(
kvs
,
delGuessGameStatusIndexKey
(
log
.
PreStatus
,
log
.
PreIndex
))
kvs
=
append
(
kvs
,
delGuessGameAdminStatusIndexKey
(
log
.
PreStatus
,
log
.
AdminAddr
,
log
.
PreIndex
))
kvs
=
append
(
kvs
,
delGuessGameCategoryStatusIndexKey
(
log
.
PreStatus
,
log
.
Category
,
log
.
PreIndex
))
kvs
=
append
(
kvs
,
delGuessGameStatusIndexKey
(
log
.
PreStatus
,
log
.
PreIndex
))
kvs
=
append
(
kvs
,
delGuessGameAdminStatusIndexKey
(
log
.
PreStatus
,
log
.
AdminAddr
,
log
.
PreIndex
))
kvs
=
append
(
kvs
,
delGuessGameCategoryStatusIndexKey
(
log
.
PreStatus
,
log
.
Category
,
log
.
PreIndex
))
}
}
else
if
log
.
StatusChange
{
//其他状态时的状态发生变化,要将老状态对应的记录删除,同时加入新状态记录;对于每个地址的下注记录也需要遍历处理。
kvs
=
append
(
kvs
,
addGuessGameStatusIndexKey
(
log
.
Status
,
log
.
GameId
,
log
.
Index
))
...
...
@@ -40,17 +41,21 @@ func (c *Guess) updateIndex(log *pkt.ReceiptGuessGame) (kvs []*types.KeyValue) {
kvs
=
append
(
kvs
,
delGuessGameAdminStatusIndexKey
(
log
.
PreStatus
,
log
.
AdminAddr
,
log
.
PreIndex
))
kvs
=
append
(
kvs
,
delGuessGameCategoryStatusIndexKey
(
log
.
PreStatus
,
log
.
Category
,
log
.
PreIndex
))
//从game中遍历每个地址的记录进行新增和删除
kvs
=
append
(
kvs
,
addGuessGameAddrStatusIndexKey
(
log
.
Status
,
log
.
Addr
,
log
.
GameId
,
log
.
Index
))
kvs
=
append
(
kvs
,
delGuessGameAddrStatusIndexKey
(
log
.
Status
,
log
.
Addr
,
log
.
Index
))
//从game中遍历每个地址的记录进行新状态记录的增和老状态记录的删除
game
,
err
:=
readGame
(
g
.
GetStateDB
(),
log
.
GameId
)
if
err
==
nil
{
for
i
:=
0
;
i
<
len
(
game
.
Plays
);
i
++
{
player
:=
game
.
Plays
[
i
]
kvs
=
append
(
kvs
,
addGuessGameAddrStatusIndexKey
(
log
.
Status
,
player
.
Addr
,
log
.
GameId
,
log
.
Index
))
kvs
=
append
(
kvs
,
delGuessGameAddrStatusIndexKey
(
log
.
PreStatus
,
player
.
Addr
,
player
.
Bet
.
PreIndex
)
}
}
}
return
kvs
}
func
(
c
*
Guess
)
execLocal
(
receipt
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
g
*
Guess
)
execLocal
(
receipt
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
dbSet
:=
&
types
.
LocalDBSet
{}
if
receipt
.
GetTy
()
!=
types
.
ExecOk
{
return
dbSet
,
nil
...
...
@@ -63,21 +68,25 @@ func (c *Guess) execLocal(receipt *types.ReceiptData) (*types.LocalDBSet, error)
if
err
!=
nil
{
panic
(
err
)
//数据错误了,已经被修改了
}
kv
:=
c
.
updateIndex
(
&
Gamelog
)
kv
:=
g
.
updateIndex
(
&
Gamelog
)
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kv
...
)
}
}
return
dbSet
,
nil
}
func
(
c
*
Guess
)
ExecLocal_Start
(
payload
*
pkt
.
PB
GameStart
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
receiptData
)
func
(
g
*
Guess
)
ExecLocal_Start
(
payload
*
pkt
.
Guess
GameStart
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
g
.
execLocal
(
receiptData
)
}
func
(
c
*
Guess
)
ExecLocal_Continue
(
payload
*
pkt
.
PBGameContinue
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
receiptData
)
func
(
g
*
Guess
)
ExecLocal_Bet
(
payload
*
pkt
.
GuessGameBet
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
g
.
execLocal
(
receiptData
)
}
func
(
c
*
Guess
)
ExecLocal_Quit
(
payload
*
pkt
.
PBGameQuit
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
receiptData
)
func
(
g
*
Guess
)
ExecLocal_Publish
(
payload
*
pkt
.
GuessGamePublish
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
g
.
execLocal
(
receiptData
)
}
func
(
g
*
Guess
)
ExecLocal_Abort
(
payload
*
pkt
.
GuessGameAbort
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
g
.
execLocal
(
receiptData
)
}
\ No newline at end of file
plugin/dapp/guess/executor/guess.go
View file @
82b582dc
...
...
@@ -5,8 +5,6 @@
package
executor
import
(
"fmt"
log
"github.com/33cn/chain33/common/log/log15"
drivers
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
...
...
@@ -15,10 +13,6 @@ import (
var
logger
=
log
.
New
(
"module"
,
"execs.guess"
)
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
newGuessGame
()
.
GetName
(),
newGuessGame
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
}
var
driverName
=
pkt
.
GuessX
func
init
()
{
...
...
@@ -26,6 +20,25 @@ func init() {
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Guess
{}))
}
type
subConfig
struct
{
ParaRemoteGrpcClient
string
`json:"paraRemoteGrpcClient"`
}
var
cfg
subConfig
// Init Guess
func
Init
(
name
string
,
sub
[]
byte
)
{
driverName
:=
GetName
()
if
name
!=
driverName
{
panic
(
"system dapp can't be rename"
)
}
if
sub
!=
nil
{
types
.
MustDecode
(
sub
,
&
cfg
)
}
drivers
.
Register
(
driverName
,
newGuessGame
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
}
type
Guess
struct
{
drivers
.
DriverBase
}
...
...
@@ -45,186 +58,8 @@ func (g *Guess) GetDriverName() string {
return
pkt
.
GuessX
}
//addr prefix
func
calcGuessGameAddrPrefix
(
addr
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-addr:%s:"
,
addr
)
return
[]
byte
(
key
)
}
//addr index
func
calcGuessGameAddrKey
(
addr
string
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-addr:%s:%018d"
,
addr
,
index
)
return
[]
byte
(
key
)
}
//status prefix
func
calcGuessGameStatusPrefix
(
status
int32
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-status-index:%d:"
,
status
)
return
[]
byte
(
key
)
}
//status index
func
calcGuessGameStatusKey
(
status
int32
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-status-index:%d:%018d"
,
status
,
index
)
return
[]
byte
(
key
)
}
//addr status prefix
func
calcGuessGameAddrStatusPrefix
(
addr
string
,
status
int32
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-addr-status-index:%s:%d:"
,
addr
,
status
)
return
[]
byte
(
key
)
}
//addr status index
func
calcGuessGameAddrStatusKey
(
addr
string
,
status
int32
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-addr-status-index:%s:%d:%018d"
,
addr
,
status
,
index
)
return
[]
byte
(
key
)
}
//admin prefix
func
calcGuessGameAdminPrefix
(
addr
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-admin:%s:"
,
addr
)
return
[]
byte
(
key
)
}
//admin index
func
calcGuessGameAdminKey
(
addr
string
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-admin:%s:%018d"
,
addr
,
index
)
return
[]
byte
(
key
)
}
//admin status prefix
func
calcGuessGameAdminStatusPrefix
(
admin
string
,
status
int32
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-admin-status-index:%s:%d:"
,
admin
,
status
)
return
[]
byte
(
key
)
}
//admin status index
func
calcGuessGameAdminStatusKey
(
admin
string
,
status
int32
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-admin-status-index:%s:%d:%018d"
,
admin
,
status
,
index
)
return
[]
byte
(
key
)
}
func
calcGuessGameCategoryStatusPrefix
(
category
string
,
status
int32
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-category-status-index:%s:%d:"
,
category
,
status
)
return
[]
byte
(
key
)
}
func
calcGuessGameCategoryStatusKey
(
category
string
,
status
int32
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-category-status-index:%s:%d:%018d"
,
category
,
status
,
index
)
return
[]
byte
(
key
)
}
func
addGuessGameAddrIndexKey
(
status
int32
,
addr
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAddrKey
(
addr
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
GameId
:
gameID
,
Status
:
status
,
Index
:
index
,
}
kv
.
Value
=
types
.
Encode
(
record
)
return
kv
}
func
delGuessGameAddrIndexKey
(
addr
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAddrKey
(
addr
,
index
)
kv
.
Value
=
nil
return
kv
}
func
addGuessGameStatusIndexKey
(
status
int32
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameStatusKey
(
status
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
GameId
:
gameID
,
Status
:
status
,
Index
:
index
,
}
kv
.
Value
=
types
.
Encode
(
record
)
return
kv
}
func
delGuessGameStatusIndexKey
(
status
int32
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameStatusKey
(
status
,
index
)
kv
.
Value
=
nil
return
kv
}
func
addGuessGameAddrStatusIndexKey
(
status
int32
,
addr
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAddrStatusKey
(
addr
,
status
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
GameId
:
gameID
,
Status
:
status
,
Index
:
index
,
}
kv
.
Value
=
types
.
Encode
(
record
)
return
kv
}
func
delGuessGameAddrStatusIndexKey
(
status
int32
,
addr
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAddrStatusKey
(
addr
,
status
,
index
)
kv
.
Value
=
nil
return
kv
}
func
addGuessGameAdminIndexKey
(
status
int32
,
addr
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAdminKey
(
addr
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
GameId
:
gameID
,
Status
:
status
,
Index
:
index
,
}
kv
.
Value
=
types
.
Encode
(
record
)
return
kv
}
func
delGuessGameAdminIndexKey
(
addr
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAdminKey
(
addr
,
index
)
kv
.
Value
=
nil
return
kv
}
func
addGuessGameAdminStatusIndexKey
(
status
int32
,
addr
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAdminStatusKey
(
addr
,
status
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
GameId
:
gameID
,
Status
:
status
,
Index
:
index
,
}
kv
.
Value
=
types
.
Encode
(
record
)
return
kv
}
func
delGuessGameAdminStatusIndexKey
(
status
int32
,
addr
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAdminStatusKey
(
addr
,
status
,
index
)
kv
.
Value
=
nil
return
kv
}
func
addGuessGameCategoryStatusIndexKey
(
status
int32
,
category
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameCategoryStatusKey
(
category
,
status
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
GameId
:
gameID
,
Status
:
status
,
Index
:
index
,
}
kv
.
Value
=
types
.
Encode
(
record
)
return
kv
}
func
delGuessGameCategoryStatusIndexKey
(
status
int32
,
category
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameCategoryStatusKey
(
category
,
status
,
index
)
kv
.
Value
=
nil
return
kv
// GetPayloadValue GuessAction
func
(
g
*
Guess
)
GetPayloadValue
()
types
.
Message
{
return
&
pkt
.
GuessGameAction
{}
}
\ No newline at end of file
plugin/dapp/guess/executor/guessdb.go
View file @
82b582dc
This diff is collapsed.
Click to expand it.
plugin/dapp/guess/executor/keys.go
0 → 100644
View file @
82b582dc
package
executor
import
(
"fmt"
"github.com/33cn/chain33/types"
pkt
"github.com/33cn/plugin/plugin/dapp/guess/types"
)
//addr prefix
func
calcGuessGameAddrPrefix
(
addr
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-addr:%s:"
,
addr
)
return
[]
byte
(
key
)
}
//addr index
func
calcGuessGameAddrKey
(
addr
string
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-addr:%s:%018d"
,
addr
,
index
)
return
[]
byte
(
key
)
}
//status prefix
func
calcGuessGameStatusPrefix
(
status
int32
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-status-index:%d:"
,
status
)
return
[]
byte
(
key
)
}
//status index
func
calcGuessGameStatusKey
(
status
int32
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-status-index:%d:%018d"
,
status
,
index
)
return
[]
byte
(
key
)
}
//addr status prefix
func
calcGuessGameAddrStatusPrefix
(
addr
string
,
status
int32
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-addr-status-index:%s:%d:"
,
addr
,
status
)
return
[]
byte
(
key
)
}
//addr status index
func
calcGuessGameAddrStatusKey
(
addr
string
,
status
int32
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-addr-status-index:%s:%d:%018d"
,
addr
,
status
,
index
)
return
[]
byte
(
key
)
}
//admin prefix
func
calcGuessGameAdminPrefix
(
addr
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-admin:%s:"
,
addr
)
return
[]
byte
(
key
)
}
//admin index
func
calcGuessGameAdminKey
(
addr
string
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-admin:%s:%018d"
,
addr
,
index
)
return
[]
byte
(
key
)
}
//admin status prefix
func
calcGuessGameAdminStatusPrefix
(
admin
string
,
status
int32
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-admin-status-index:%s:%d:"
,
admin
,
status
)
return
[]
byte
(
key
)
}
//admin status index
func
calcGuessGameAdminStatusKey
(
admin
string
,
status
int32
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-admin-status-index:%s:%d:%018d"
,
admin
,
status
,
index
)
return
[]
byte
(
key
)
}
func
calcGuessGameCategoryStatusPrefix
(
category
string
,
status
int32
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-category-status-index:%s:%d:"
,
category
,
status
)
return
[]
byte
(
key
)
}
func
calcGuessGameCategoryStatusKey
(
category
string
,
status
int32
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-guess-category-status-index:%s:%d:%018d"
,
category
,
status
,
index
)
return
[]
byte
(
key
)
}
func
addGuessGameAddrIndexKey
(
status
int32
,
addr
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAddrKey
(
addr
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
GameId
:
gameID
,
Status
:
status
,
Index
:
index
,
}
kv
.
Value
=
types
.
Encode
(
record
)
return
kv
}
func
delGuessGameAddrIndexKey
(
addr
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAddrKey
(
addr
,
index
)
kv
.
Value
=
nil
return
kv
}
func
addGuessGameStatusIndexKey
(
status
int32
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameStatusKey
(
status
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
GameId
:
gameID
,
Status
:
status
,
Index
:
index
,
}
kv
.
Value
=
types
.
Encode
(
record
)
return
kv
}
func
delGuessGameStatusIndexKey
(
status
int32
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameStatusKey
(
status
,
index
)
kv
.
Value
=
nil
return
kv
}
func
addGuessGameAddrStatusIndexKey
(
status
int32
,
addr
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAddrStatusKey
(
addr
,
status
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
GameId
:
gameID
,
Status
:
status
,
Index
:
index
,
}
kv
.
Value
=
types
.
Encode
(
record
)
return
kv
}
func
delGuessGameAddrStatusIndexKey
(
status
int32
,
addr
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAddrStatusKey
(
addr
,
status
,
index
)
kv
.
Value
=
nil
return
kv
}
func
addGuessGameAdminIndexKey
(
status
int32
,
addr
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAdminKey
(
addr
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
GameId
:
gameID
,
Status
:
status
,
Index
:
index
,
}
kv
.
Value
=
types
.
Encode
(
record
)
return
kv
}
func
delGuessGameAdminIndexKey
(
addr
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAdminKey
(
addr
,
index
)
kv
.
Value
=
nil
return
kv
}
func
addGuessGameAdminStatusIndexKey
(
status
int32
,
addr
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAdminStatusKey
(
addr
,
status
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
GameId
:
gameID
,
Status
:
status
,
Index
:
index
,
}
kv
.
Value
=
types
.
Encode
(
record
)
return
kv
}
func
delGuessGameAdminStatusIndexKey
(
status
int32
,
addr
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAdminStatusKey
(
addr
,
status
,
index
)
kv
.
Value
=
nil
return
kv
}
func
addGuessGameCategoryStatusIndexKey
(
status
int32
,
category
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameCategoryStatusKey
(
category
,
status
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
GameId
:
gameID
,
Status
:
status
,
Index
:
index
,
}
kv
.
Value
=
types
.
Encode
(
record
)
return
kv
}
func
delGuessGameCategoryStatusIndexKey
(
status
int32
,
category
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameCategoryStatusKey
(
category
,
status
,
index
)
kv
.
Value
=
nil
return
kv
}
plugin/dapp/guess/executor/query.go
View file @
82b582dc
...
...
@@ -9,7 +9,7 @@ import (
pkt
"github.com/33cn/plugin/plugin/dapp/guess/types"
)
func
(
g
*
Guess
)
Query_QueryGame
List
ByIds
(
in
*
pkt
.
QueryGuessGameInfos
)
(
types
.
Message
,
error
)
{
func
(
g
*
Guess
)
Query_QueryGame
s
ByIds
(
in
*
pkt
.
QueryGuessGameInfos
)
(
types
.
Message
,
error
)
{
return
Infos
(
g
.
GetStateDB
(),
in
)
}
...
...
@@ -18,7 +18,7 @@ func (g *Guess) Query_QueryGameById(in *pkt.QueryGuessGameInfo) (types.Message,
if
err
!=
nil
{
return
nil
,
err
}
return
&
pkt
.
ReplyGuessGameInfo
{
game
},
nil
return
&
pkt
.
ReplyGuessGameInfo
{
Game
:
game
},
nil
}
func
(
g
*
Guess
)
Query_QueryGameByAddr
(
in
*
pkt
.
QueryGuessGameInfo
)
(
types
.
Message
,
error
)
{
...
...
plugin/dapp/guess/proto/guess.proto
View file @
82b582dc
...
...
@@ -7,8 +7,8 @@ package types;
//竞猜游戏内容
message
GuessGame
{
string
gameId
=
1
;
//游戏ID
u
int32
status
=
2
;
//游戏的状态:创建->投注->截止投注->开奖
u
int32
preStatus
=
3
;
int32
status
=
2
;
//游戏的状态:创建->投注->截止投注->开奖
int32
preStatus
=
3
;
int64
startTime
=
4
;
//创建游戏的时间
string
startTxHash
=
5
;
//创建游戏的交易hash
string
topic
=
6
;
//主题
...
...
@@ -21,7 +21,7 @@ message GuessGame {
uint32
oneBet
=
13
;
//一注等于多少bty或者token
uint32
maxBets
=
14
;
//单次可以下多少注,默认100
uint32
maxBetsNumber
=
15
;
//最多可以下多少注
u
int64
fee
=
16
;
//收取费用,不带则表示不收费
int64
fee
=
16
;
//收取费用,不带则表示不收费
string
feeAddr
=
17
;
//收费地址
string
expire
=
18
;
//游戏过期时间
int64
expireHeight
=
19
;
//游戏过期区块高度
...
...
@@ -60,90 +60,6 @@ message GuessBetStatItem {
uint32
betsTimes
=
3
;
}
//斗牛游戏内容
message
PokerBull
{
string
gameId
=
1
;
//默认是由创建这局游戏的txHash作为gameId
int32
status
=
2
;
// Start 1 -> Continue 2 -> Quit 3
int64
startTime
=
3
;
//开始时间
string
startTxHash
=
4
;
//游戏启动交易hash
int64
value
=
5
;
//赌注
PBPoker
poker
=
6
;
//扑克牌
repeated
PBPlayer
players
=
7
;
//玩家历史牌和结果集
int32
playerNum
=
8
;
//玩家数
repeated
PBResult
results
=
9
;
//游戏结果集
int64
index
=
10
;
//索引
int64
prevIndex
=
11
;
//上级索引
int64
quitTime
=
12
;
//游戏结束时间
string
quitTxHash
=
13
;
//游戏结束交易hash
string
dealerAddr
=
14
;
//下局庄家地址
bool
isWaiting
=
15
;
//游戏是否处于等待状态
int32
preStatus
=
16
;
//上一index的状态
}
//一把牌
message
PBHand
{
repeated
int32
cards
=
1
;
//一把牌,五张
int32
result
=
2
;
//斗牛结果 (没牛:0, 牛1-9:1-9, 牛牛:10)
string
address
=
3
;
//玩家地址
bool
isWin
=
4
;
//是否赢庄家
int32
leverage
=
5
;
//赌注倍数
}
//玩家
message
PBPlayer
{
repeated
PBHand
hands
=
1
;
//历史发牌和斗牛结果
string
address
=
2
;
//玩家地址
int64
txHash
=
3
;
//发牌随机数因子txhash的整数格式
bool
ready
=
4
;
// continue状态下,是否ready
}
//本局游戏结果
message
PBResult
{
repeated
PBHand
hands
=
1
;
//本局所有玩家的牌和结果,按牛大小升序排序
string
winner
=
2
;
//赢家地址
int32
leverage
=
3
;
//赢得赌注倍数
string
dealer
=
4
;
//庄家
int32
dealerLeverage
=
5
;
//庄家赌注倍数
}
//扑克牌
message
PBPoker
{
repeated
int32
cards
=
1
;
// 52张牌
int32
pointer
=
2
;
//已发牌偏移
}
//游戏状态
message
PBGameAction
{
oneof
value
{
PBGameStart
start
=
1
;
PBGameContinue
continue
=
2
;
PBGameQuit
quit
=
3
;
PBGameQuery
query
=
4
;
}
int32
ty
=
10
;
}
//游戏启动
message
PBGameStart
{
int64
value
=
1
;
int32
playerNum
=
2
;
}
//游戏继续
message
PBGameContinue
{
string
gameId
=
1
;
}
//游戏结束
message
PBGameQuit
{
string
gameId
=
1
;
}
//查询游戏结果
message
PBGameQuery
{
string
gameId
=
1
;
}
//游戏状态
message
GuessGameAction
{
oneof
value
{
...
...
@@ -168,7 +84,7 @@ message GuessGameStart{
uint32
oneBet
=
8
;
uint32
maxBets
=
9
;
uint32
maxBetsNumber
=
10
;
u
int64
fee
=
11
;
int64
fee
=
11
;
string
feeAddr
=
12
;
string
expire
=
13
;
int64
expireHeight
=
14
;
...
...
@@ -179,66 +95,29 @@ message GuessGameBet{
string
gameId
=
1
;
string
option
=
2
;
uint32
betsNum
=
3
;
int64
fee
=
4
;
}
//游戏异常终止,退还下注
message
GuessGameAbort
{
string
gameId
=
1
;
int64
fee
=
2
;
}
//游戏结果揭晓
message
GuessGamePublish
{
string
gameId
=
1
;
string
result
=
2
;
int64
fee
=
3
;
}
//查询游戏结果
message
GuessGameQuery
{
string
gameId
=
1
;
uint32
ty
=
2
;
int64
fee
=
3
;
}
//根据状态和游戏人数查找
message
QueryPBGameListByStatusAndPlayerNum
{
int32
status
=
1
;
int32
playerNum
=
2
;
int64
index
=
3
;
}
// 索引value值
message
PBGameRecord
{
string
gameId
=
1
;
int32
status
=
2
;
int64
index
=
3
;
}
message
PBGameIndexRecord
{
string
gameId
=
1
;
int64
index
=
2
;
}
message
PBGameRecords
{
repeated
PBGameRecord
records
=
1
;
}
message
QueryPBGameInfo
{
string
gameId
=
1
;
string
addr
=
2
;
int32
status
=
3
;
int64
index
=
4
;
}
message
ReplyPBGame
{
PokerBull
game
=
1
;
}
message
QueryPBGameInfos
{
repeated
string
gameIds
=
1
;
}
message
ReplyPBGameList
{
repeated
PokerBull
games
=
1
;
}
message
QueryGuessGameInfo
{
string
gameId
=
1
;
...
...
@@ -259,23 +138,10 @@ message ReplyGuessGameInfos {
repeated
GuessGame
games
=
1
;
}
message
ReceiptPBGame
{
string
gameId
=
1
;
int32
status
=
2
;
string
addr
=
3
;
int64
index
=
4
;
int64
prevIndex
=
5
;
int32
playerNum
=
6
;
int64
value
=
7
;
bool
isWaiting
=
8
;
repeated
string
players
=
9
;
int32
preStatus
=
10
;
}
message
ReceiptGuessGame
{
string
gameId
=
1
;
u
int32
preStatus
=
2
;
u
int32
status
=
3
;
int32
preStatus
=
2
;
int32
status
=
3
;
string
addr
=
4
;
string
adminAddr
=
5
;
int64
preIndex
=
6
;
...
...
@@ -316,23 +182,6 @@ message GuessPublishTxReq {
string
result
=
2
;
}
message
PBContinueTxReq
{
string
gameId
=
1
;
int64
fee
=
2
;
}
message
PBQuitTxReq
{
string
gameId
=
1
;
int64
fee
=
2
;
}
message
PBQueryReq
{
string
gameId
=
1
;
int64
fee
=
2
;
}
// 索引value值
message
GuessGameRecord
{
string
gameId
=
1
;
...
...
plugin/dapp/guess/rpc/jrpc.go
View file @
82b582dc
...
...
@@ -93,7 +93,8 @@ func (c *Jrpc) GuessPublishTx(parm *pb.GuessPublishTxReq, result *interface{}) e
return
nil
}
func
(
c
*
Jrpc
)
GuessQueryTx
(
parm
*
pb
.
PBQueryReq
,
result
*
interface
{})
error
{
/*
func (c *Jrpc) GuessQueryTx(parm *pb.GuessQueryReq, result *interface{}) error {
if parm == nil {
return types.ErrInvalidParam
}
...
...
@@ -107,4 +108,4 @@ func (c *Jrpc) GuessQueryTx(parm *pb.PBQueryReq, result *interface{}) error {
*result = hex.EncodeToString(reply.Data)
return nil
}
}
*/
plugin/dapp/guess/types/const.go
View file @
82b582dc
...
...
@@ -26,17 +26,6 @@ const (
)
const
(
PlayStyleDefault
=
iota
+
1
PlayStyleDealer
)
const
(
//log for PBgame
TyLogPBGameStart
=
721
TyLogPBGameContinue
=
722
TyLogPBGameQuit
=
723
TyLogPBGameQuery
=
724
TyLogGuessGameStart
=
901
TyLogGuessGameBet
=
902
TyLogGuessGameStopBet
=
903
...
...
plugin/dapp/guess/types/guess.pb.go
View file @
82b582dc
This diff is collapsed.
Click to expand it.
plugin/dapp/guess/types/types.go
View file @
82b582dc
...
...
@@ -5,9 +5,16 @@
package
types
import
(
"encoding/json"
"github.com/33cn/chain33/common/address"
"reflect"
"github.com/33cn/chain33/types"
log
"github.com/33cn/chain33/common/log/log15"
)
var
(
llog
=
log
.
New
(
"module"
,
"exectype."
+
GuessX
)
)
func
init
()
{
...
...
@@ -53,5 +60,149 @@ func (t *GuessType) GetLogMap() map[int64]*types.LogInfo {
}
}
// CreateTx method
func
(
t
*
GuessType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
llog
.
Debug
(
"Guess.CreateTx"
,
"action"
,
action
)
if
action
==
"GuessStart"
{
var
param
GuessStartTxReq
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx.GuessStart"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawGuessStartTx
(
&
param
)
}
else
if
action
==
"GuessBet"
{
var
param
GuessBetTxReq
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx.GuessBet"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawGuessBetTx
(
&
param
)
}
else
if
action
==
"GuessPublish"
{
var
param
GuessPublishTxReq
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx.GuessPublish"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawGuessPublishTx
(
&
param
)
}
else
if
action
==
"GuessAbort"
{
var
param
GuessAbortTxReq
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx.GuessAbort"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawGuessAbortTx
(
&
param
)
}
else
{
return
nil
,
types
.
ErrNotSupport
}
}
// CreateRawLotteryCreateTx method
func
CreateRawGuessStartTx
(
parm
*
GuessGameStart
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawGuessStartTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
val
:=
&
GuessGameAction
{
Ty
:
GuessGameActionStart
,
Value
:
&
GuessGameAction_Start
{
Start
:
parm
},
}
name
:=
types
.
ExecName
(
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawGuessBetTx method
func
CreateRawGuessBetTx
(
parm
*
GuessGameBet
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawGuessBet"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
val
:=
&
GuessGameAction
{
Ty
:
GuessGameActionBet
,
Value
:
&
GuessGameAction_Bet
{
Bet
:
parm
},
}
name
:=
types
.
ExecName
(
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawGuessPublishTx method
func
CreateRawGuessPublishTx
(
parm
*
GuessGamePublish
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawGuessPublish"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
val
:=
&
GuessGameAction
{
Ty
:
GuessGameActionPublish
,
Value
:
&
GuessGameAction_Publish
{
Publish
:
parm
},
}
name
:=
types
.
ExecName
(
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawGuessAbortTx method
func
CreateRawGuessAbortTx
(
parm
*
GuessGameAbort
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawGuessAbortTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
val
:=
&
GuessGameAction
{
Ty
:
GuessGameActionAbort
,
Value
:
&
GuessGameAction_Abort
{
Abort
:
parm
},
}
name
:=
types
.
ExecName
(
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment