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
0c4557b7
Commit
0c4557b7
authored
Dec 24, 2018
by
张振华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor
parent
2bea5d2e
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
167 additions
and
172 deletions
+167
-172
game.go
plugin/dapp/guess/commands/game.go
+36
-36
exec.go
plugin/dapp/guess/executor/exec.go
+6
-6
exec_del_local.go
plugin/dapp/guess/executor/exec_del_local.go
+10
-10
exec_local.go
plugin/dapp/guess/executor/exec_local.go
+11
-11
guess.go
plugin/dapp/guess/executor/guess.go
+3
-3
guessdb.go
plugin/dapp/guess/executor/guessdb.go
+84
-84
keys.go
plugin/dapp/guess/executor/keys.go
+7
-7
query.go
plugin/dapp/guess/executor/query.go
+10
-10
types.go
plugin/dapp/guess/types/types.go
+0
-5
No files found.
plugin/dapp/guess/commands/game.go
View file @
0c4557b7
...
...
@@ -11,7 +11,7 @@ import (
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
pkt
"github.com/33cn/plugin/plugin/dapp/guess/types"
gty
"github.com/33cn/plugin/plugin/dapp/guess/types"
"github.com/spf13/cobra"
)
...
...
@@ -80,8 +80,8 @@ func guessStart(cmd *cobra.Command, args []string) {
payload
:=
fmt
.
Sprintf
(
"{
\"
topic
\"
:
\"
%s
\"
,
\"
options
\"
:
\"
%s
\"
,
\"
category
\"
:
\"
%s
\"
,
\"
maxBetHeight
\"
:%d,
\"
maxBetsOneTime
\"
:%d,
\"
maxBetsNumber
\"
:%d,
\"
devFeeFactor
\"
:%d,
\"
platFeeFactor
\"
:%d,
\"
expireHeight
\"
:%d,
\"
devFeeAddr
\"
:
\"
%s
\"
,
\"
platFeeAddr
\"
:
\"
%s
\"
}"
,
topic
,
options
,
category
,
maxBetHeight
,
maxBetsOneTime
,
maxBetsNumber
,
devFeeFactor
,
platFeeFactor
,
expireHeight
,
devFeeAddr
,
platFeeAddr
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
GuessX
),
ActionName
:
pkt
.
CreateStartTx
,
Execer
:
types
.
ExecName
(
gty
.
GuessX
),
ActionName
:
gty
.
CreateStartTx
,
Payload
:
[]
byte
(
payload
),
}
...
...
@@ -119,8 +119,8 @@ func guessBet(cmd *cobra.Command, args []string) {
payload
:=
fmt
.
Sprintf
(
"{
\"
gameID
\"
:
\"
%s
\"
,
\"
option
\"
:
\"
%s
\"
,
\"
betsNum
\"
:%d}"
,
gameID
,
option
,
betsNumber
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
GuessX
),
ActionName
:
pkt
.
CreateBetTx
,
Execer
:
types
.
ExecName
(
gty
.
GuessX
),
ActionName
:
gty
.
CreateBetTx
,
Payload
:
[]
byte
(
payload
),
}
...
...
@@ -152,8 +152,8 @@ func guessStopBet(cmd *cobra.Command, args []string) {
payload
:=
fmt
.
Sprintf
(
"{
\"
gameID
\"
:
\"
%s
\"
}"
,
gameID
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
GuessX
),
ActionName
:
pkt
.
CreateStopBetTx
,
Execer
:
types
.
ExecName
(
gty
.
GuessX
),
ActionName
:
gty
.
CreateStopBetTx
,
Payload
:
[]
byte
(
payload
),
}
...
...
@@ -184,8 +184,8 @@ func guessAbort(cmd *cobra.Command, args []string) {
payload
:=
fmt
.
Sprintf
(
"{
\"
gameID
\"
:
\"
%s
\"
}"
,
gameID
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
GuessX
),
ActionName
:
pkt
.
CreateAbortTx
,
Execer
:
types
.
ExecName
(
gty
.
GuessX
),
ActionName
:
gty
.
CreateAbortTx
,
Payload
:
[]
byte
(
payload
),
}
...
...
@@ -220,8 +220,8 @@ func guessPublish(cmd *cobra.Command, args []string) {
payload
:=
fmt
.
Sprintf
(
"{
\"
gameID
\"
:
\"
%s
\"
,
\"
result
\"
:
\"
%s
\"
}"
,
gameID
,
result
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
GuessX
),
ActionName
:
pkt
.
CreatePublishTx
,
Execer
:
types
.
ExecName
(
gty
.
GuessX
),
ActionName
:
gty
.
CreatePublishTx
,
Payload
:
[]
byte
(
payload
),
}
...
...
@@ -264,7 +264,7 @@ func guessQuery(cmd *cobra.Command, args []string) {
category
,
_
:=
cmd
.
Flags
()
.
GetString
(
"category"
)
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
pkt
.
GuessX
params
.
Execer
=
gty
.
GuessX
//query type,
//1:QueryGamesByIds,
...
...
@@ -278,91 +278,91 @@ func guessQuery(cmd *cobra.Command, args []string) {
switch
ty
{
case
1
:
gameIds
:=
strings
.
Split
(
gameIDs
,
";"
)
req
:=
&
pkt
.
QueryGuessGameInfos
{
req
:=
&
gty
.
QueryGuessGameInfos
{
GameIDs
:
gameIds
,
}
params
.
FuncName
=
pkt
.
FuncNameQueryGamesByIDs
params
.
FuncName
=
gty
.
FuncNameQueryGamesByIDs
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
ReplyGuessGameInfos
var
res
gty
.
ReplyGuessGameInfos
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
case
2
:
req
:=
&
pkt
.
QueryGuessGameInfo
{
req
:=
&
gty
.
QueryGuessGameInfo
{
GameID
:
gameID
,
}
params
.
FuncName
=
pkt
.
FuncNameQueryGameByID
params
.
FuncName
=
gty
.
FuncNameQueryGameByID
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
ReplyGuessGameInfo
var
res
gty
.
ReplyGuessGameInfo
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
case
3
:
req
:=
&
pkt
.
QueryGuessGameInfo
{
req
:=
&
gty
.
QueryGuessGameInfo
{
Addr
:
addr
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncNameQueryGameByAddr
params
.
FuncName
=
gty
.
FuncNameQueryGameByAddr
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
GuessGameRecords
var
res
gty
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
case
4
:
req
:=
&
pkt
.
QueryGuessGameInfo
{
req
:=
&
gty
.
QueryGuessGameInfo
{
Status
:
status
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncNameQueryGameByStatus
params
.
FuncName
=
gty
.
FuncNameQueryGameByStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
GuessGameRecords
var
res
gty
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
case
5
:
req
:=
&
pkt
.
QueryGuessGameInfo
{
req
:=
&
gty
.
QueryGuessGameInfo
{
AdminAddr
:
adminAddr
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncNameQueryGameByAdminAddr
params
.
FuncName
=
gty
.
FuncNameQueryGameByAdminAddr
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
GuessGameRecords
var
res
gty
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
case
6
:
req
:=
&
pkt
.
QueryGuessGameInfo
{
req
:=
&
gty
.
QueryGuessGameInfo
{
Addr
:
addr
,
Status
:
status
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncNameQueryGameByAddrStatus
params
.
FuncName
=
gty
.
FuncNameQueryGameByAddrStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
GuessGameRecords
var
res
gty
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
case
7
:
req
:=
&
pkt
.
QueryGuessGameInfo
{
req
:=
&
gty
.
QueryGuessGameInfo
{
AdminAddr
:
adminAddr
,
Status
:
status
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncNameQueryGameByAdminStatus
params
.
FuncName
=
gty
.
FuncNameQueryGameByAdminStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
GuessGameRecords
var
res
gty
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
case
8
:
req
:=
&
pkt
.
QueryGuessGameInfo
{
req
:=
&
gty
.
QueryGuessGameInfo
{
Category
:
category
,
Status
:
status
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncNameQueryGameByCategoryStatus
params
.
FuncName
=
gty
.
FuncNameQueryGameByCategoryStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
GuessGameRecords
var
res
gty
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
...
...
plugin/dapp/guess/executor/exec.go
View file @
0c4557b7
...
...
@@ -6,35 +6,35 @@ package executor
import
(
"github.com/33cn/chain33/types"
pkt
"github.com/33cn/plugin/plugin/dapp/guess/types"
gty
"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
*
gty
.
GuessGameStart
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
NewAction
(
c
,
tx
,
index
)
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
*
gty
.
GuessGameBet
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
NewAction
(
c
,
tx
,
index
)
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
*
gty
.
GuessGameStopBet
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
NewAction
(
c
,
tx
,
index
)
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
*
gty
.
GuessGamePublish
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
NewAction
(
c
,
tx
,
index
)
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
*
gty
.
GuessGameAbort
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
action
:=
NewAction
(
c
,
tx
,
index
)
return
action
.
GameAbort
(
payload
)
}
plugin/dapp/guess/executor/exec_del_local.go
View file @
0c4557b7
...
...
@@ -6,18 +6,18 @@ package executor
import
(
"github.com/33cn/chain33/types"
pkt
"github.com/33cn/plugin/plugin/dapp/guess/types"
gty
"github.com/33cn/plugin/plugin/dapp/guess/types"
)
func
(
g
*
Guess
)
rollbackIndex
(
log
*
pkt
.
ReceiptGuessGame
)
(
kvs
[]
*
types
.
KeyValue
)
{
func
(
g
*
Guess
)
rollbackIndex
(
log
*
gty
.
ReceiptGuessGame
)
(
kvs
[]
*
types
.
KeyValue
)
{
//新创建游戏,将增加的记录都删除掉
if
log
.
Status
==
pkt
.
GuessGameStatusStart
{
if
log
.
Status
==
gty
.
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
{
}
else
if
log
.
Status
==
gty
.
GuessGameStatusBet
{
//如果是下注状态,则有用户进行了下注操作,对这些记录进行删除
kvs
=
append
(
kvs
,
delGuessGameAddrIndexKey
(
log
.
Addr
,
log
.
Index
))
kvs
=
append
(
kvs
,
delGuessGameAddrStatusIndexKey
(
log
.
Status
,
log
.
Addr
,
log
.
Index
))
...
...
@@ -64,8 +64,8 @@ func (g *Guess) execDelLocal(receiptData *types.ReceiptData) (*types.LocalDBSet,
for
_
,
log
:=
range
receiptData
.
Logs
{
switch
log
.
GetTy
()
{
case
pkt
.
TyLogGuessGameStart
,
pkt
.
TyLogGuessGameBet
,
pkt
.
TyLogGuessGameStopBet
,
pkt
.
TyLogGuessGameAbort
,
pkt
.
TyLogGuessGamePublish
,
pkt
.
TyLogGuessGameTimeout
:
receiptGame
:=
&
pkt
.
ReceiptGuessGame
{}
case
gty
.
TyLogGuessGameStart
,
gty
.
TyLogGuessGameBet
,
gty
.
TyLogGuessGameStopBet
,
gty
.
TyLogGuessGameAbort
,
gty
.
TyLogGuessGamePublish
,
gty
.
TyLogGuessGameTimeout
:
receiptGame
:=
&
gty
.
ReceiptGuessGame
{}
if
err
:=
types
.
Decode
(
log
.
Log
,
receiptGame
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -77,21 +77,21 @@ func (g *Guess) execDelLocal(receiptData *types.ReceiptData) (*types.LocalDBSet,
}
//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
*
gty
.
GuessGameStart
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
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
*
gty
.
GuessGameBet
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
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
*
gty
.
GuessGamePublish
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
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
*
gty
.
GuessGameAbort
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
g
.
execLocal
(
receiptData
)
}
plugin/dapp/guess/executor/exec_local.go
View file @
0c4557b7
...
...
@@ -6,18 +6,18 @@ package executor
import
(
"github.com/33cn/chain33/types"
pkt
"github.com/33cn/plugin/plugin/dapp/guess/types"
gty
"github.com/33cn/plugin/plugin/dapp/guess/types"
)
func
(
g
*
Guess
)
updateIndex
(
log
*
pkt
.
ReceiptGuessGame
)
(
kvs
[]
*
types
.
KeyValue
)
{
func
(
g
*
Guess
)
updateIndex
(
log
*
gty
.
ReceiptGuessGame
)
(
kvs
[]
*
types
.
KeyValue
)
{
//新创建游戏
if
log
.
Status
==
pkt
.
GuessGameStatusStart
{
if
log
.
Status
==
gty
.
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
.
AdminAddr
,
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
{
}
else
if
log
.
Status
==
gty
.
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
))
...
...
@@ -62,8 +62,8 @@ func (g *Guess) execLocal(receipt *types.ReceiptData) (*types.LocalDBSet, error)
}
for
i
:=
0
;
i
<
len
(
receipt
.
Logs
);
i
++
{
item
:=
receipt
.
Logs
[
i
]
if
item
.
Ty
>=
pkt
.
TyLogGuessGameStart
&&
item
.
Ty
<=
pkt
.
TyLogGuessGameTimeout
{
var
Gamelog
pkt
.
ReceiptGuessGame
if
item
.
Ty
>=
gty
.
TyLogGuessGameStart
&&
item
.
Ty
<=
gty
.
TyLogGuessGameTimeout
{
var
Gamelog
gty
.
ReceiptGuessGame
err
:=
types
.
Decode
(
item
.
Log
,
&
Gamelog
)
if
err
!=
nil
{
panic
(
err
)
//数据错误了,已经被修改了
...
...
@@ -76,26 +76,26 @@ func (g *Guess) execLocal(receipt *types.ReceiptData) (*types.LocalDBSet, error)
}
//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
*
gty
.
GuessGameStart
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
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
*
gty
.
GuessGameBet
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
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
*
gty
.
GuessGameStopBet
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
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
*
gty
.
GuessGamePublish
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
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
*
gty
.
GuessGameAbort
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
g
.
execLocal
(
receiptData
)
}
plugin/dapp/guess/executor/guess.go
View file @
0c4557b7
...
...
@@ -8,12 +8,12 @@ import (
log
"github.com/33cn/chain33/common/log/log15"
drivers
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
pkt
"github.com/33cn/plugin/plugin/dapp/guess/types"
gty
"github.com/33cn/plugin/plugin/dapp/guess/types"
)
var
logger
=
log
.
New
(
"module"
,
"execs.guess"
)
var
driverName
=
pkt
.
GuessX
var
driverName
=
gty
.
GuessX
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
...
...
@@ -57,7 +57,7 @@ func GetName() string {
//GetDriverName 获取Guess执行器的名称
func
(
g
*
Guess
)
GetDriverName
()
string
{
return
pkt
.
GuessX
return
gty
.
GuessX
}
/*
...
...
plugin/dapp/guess/executor/guessdb.go
View file @
0c4557b7
...
...
@@ -18,7 +18,7 @@ import (
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
pkt
"github.com/33cn/plugin/plugin/dapp/guess/types"
gty
"github.com/33cn/plugin/plugin/dapp/guess/types"
)
const
(
...
...
@@ -115,18 +115,18 @@ func (action *Action) CheckExecAccountBalance(fromAddr string, ToFrozen, ToActiv
//Key State数据库中存储记录的Key值格式转换
func
Key
(
id
string
)
(
key
[]
byte
)
{
//key = append(key, []byte("mavl-"+types.ExecName(pkt.GuessX)+"-")...)
key
=
append
(
key
,
[]
byte
(
"mavl-"
+
pkt
.
GuessX
+
"-"
)
...
)
key
=
append
(
key
,
[]
byte
(
"mavl-"
+
gty
.
GuessX
+
"-"
)
...
)
key
=
append
(
key
,
[]
byte
(
id
)
...
)
return
key
}
func
readGame
(
db
dbm
.
KV
,
id
string
)
(
*
pkt
.
GuessGame
,
error
)
{
func
readGame
(
db
dbm
.
KV
,
id
string
)
(
*
gty
.
GuessGame
,
error
)
{
data
,
err
:=
db
.
Get
(
Key
(
id
))
if
err
!=
nil
{
logger
.
Error
(
"query data have err:"
,
err
.
Error
())
return
nil
,
err
}
var
game
pkt
.
GuessGame
var
game
gty
.
GuessGame
//decode
err
=
types
.
Decode
(
data
,
&
game
)
if
err
!=
nil
{
...
...
@@ -137,8 +137,8 @@ func readGame(db dbm.KV, id string) (*pkt.GuessGame, error) {
}
//Infos 根据游戏id列表查询多个游戏详情信息
func
Infos
(
db
dbm
.
KV
,
infos
*
pkt
.
QueryGuessGameInfos
)
(
types
.
Message
,
error
)
{
var
games
[]
*
pkt
.
GuessGame
func
Infos
(
db
dbm
.
KV
,
infos
*
gty
.
QueryGuessGameInfos
)
(
types
.
Message
,
error
)
{
var
games
[]
*
gty
.
GuessGame
for
i
:=
0
;
i
<
len
(
infos
.
GameIDs
);
i
++
{
id
:=
infos
.
GameIDs
[
i
]
game
,
err
:=
readGame
(
db
,
id
)
...
...
@@ -147,7 +147,7 @@ func Infos(db dbm.KV, infos *pkt.QueryGuessGameInfos) (types.Message, error) {
}
games
=
append
(
games
,
game
)
}
return
&
pkt
.
ReplyGuessGameInfos
{
Games
:
games
},
nil
return
&
gty
.
ReplyGuessGameInfos
{
Games
:
games
},
nil
}
func
getGameListByAddr
(
db
dbm
.
Lister
,
addr
string
,
index
int64
)
(
types
.
Message
,
error
)
{
...
...
@@ -162,9 +162,9 @@ func getGameListByAddr(db dbm.Lister, addr string, index int64) (types.Message,
return
nil
,
err
}
var
records
[]
*
pkt
.
GuessGameRecord
var
records
[]
*
gty
.
GuessGameRecord
for
_
,
value
:=
range
values
{
var
record
pkt
.
GuessGameRecord
var
record
gty
.
GuessGameRecord
err
:=
types
.
Decode
(
value
,
&
record
)
if
err
!=
nil
{
continue
...
...
@@ -172,7 +172,7 @@ func getGameListByAddr(db dbm.Lister, addr string, index int64) (types.Message,
records
=
append
(
records
,
&
record
)
}
return
&
pkt
.
GuessGameRecords
{
Records
:
records
},
nil
return
&
gty
.
GuessGameRecords
{
Records
:
records
},
nil
}
func
getGameListByAdminAddr
(
db
dbm
.
Lister
,
addr
string
,
index
int64
)
(
types
.
Message
,
error
)
{
...
...
@@ -187,9 +187,9 @@ func getGameListByAdminAddr(db dbm.Lister, addr string, index int64) (types.Mess
return
nil
,
err
}
var
records
[]
*
pkt
.
GuessGameRecord
var
records
[]
*
gty
.
GuessGameRecord
for
_
,
value
:=
range
values
{
var
record
pkt
.
GuessGameRecord
var
record
gty
.
GuessGameRecord
err
:=
types
.
Decode
(
value
,
&
record
)
if
err
!=
nil
{
continue
...
...
@@ -197,7 +197,7 @@ func getGameListByAdminAddr(db dbm.Lister, addr string, index int64) (types.Mess
records
=
append
(
records
,
&
record
)
}
return
&
pkt
.
GuessGameRecords
{
Records
:
records
},
nil
return
&
gty
.
GuessGameRecords
{
Records
:
records
},
nil
}
func
getGameListByStatus
(
db
dbm
.
Lister
,
status
int32
,
index
int64
)
(
types
.
Message
,
error
)
{
...
...
@@ -212,9 +212,9 @@ func getGameListByStatus(db dbm.Lister, status int32, index int64) (types.Messag
return
nil
,
err
}
var
records
[]
*
pkt
.
GuessGameRecord
var
records
[]
*
gty
.
GuessGameRecord
for
_
,
value
:=
range
values
{
var
record
pkt
.
GuessGameRecord
var
record
gty
.
GuessGameRecord
err
:=
types
.
Decode
(
value
,
&
record
)
if
err
!=
nil
{
continue
...
...
@@ -222,7 +222,7 @@ func getGameListByStatus(db dbm.Lister, status int32, index int64) (types.Messag
records
=
append
(
records
,
&
record
)
}
return
&
pkt
.
GuessGameRecords
{
Records
:
records
},
nil
return
&
gty
.
GuessGameRecords
{
Records
:
records
},
nil
}
func
getGameListByAddrStatus
(
db
dbm
.
Lister
,
addr
string
,
status
int32
,
index
int64
)
(
types
.
Message
,
error
)
{
...
...
@@ -237,9 +237,9 @@ func getGameListByAddrStatus(db dbm.Lister, addr string, status int32, index int
return
nil
,
err
}
var
records
[]
*
pkt
.
GuessGameRecord
var
records
[]
*
gty
.
GuessGameRecord
for
_
,
value
:=
range
values
{
var
record
pkt
.
GuessGameRecord
var
record
gty
.
GuessGameRecord
err
:=
types
.
Decode
(
value
,
&
record
)
if
err
!=
nil
{
continue
...
...
@@ -247,7 +247,7 @@ func getGameListByAddrStatus(db dbm.Lister, addr string, status int32, index int
records
=
append
(
records
,
&
record
)
}
return
&
pkt
.
GuessGameRecords
{
Records
:
records
},
nil
return
&
gty
.
GuessGameRecords
{
Records
:
records
},
nil
}
func
getGameListByAdminStatus
(
db
dbm
.
Lister
,
admin
string
,
status
int32
,
index
int64
)
(
types
.
Message
,
error
)
{
...
...
@@ -262,9 +262,9 @@ func getGameListByAdminStatus(db dbm.Lister, admin string, status int32, index i
return
nil
,
err
}
var
records
[]
*
pkt
.
GuessGameRecord
var
records
[]
*
gty
.
GuessGameRecord
for
_
,
value
:=
range
values
{
var
record
pkt
.
GuessGameRecord
var
record
gty
.
GuessGameRecord
err
:=
types
.
Decode
(
value
,
&
record
)
if
err
!=
nil
{
continue
...
...
@@ -272,7 +272,7 @@ func getGameListByAdminStatus(db dbm.Lister, admin string, status int32, index i
records
=
append
(
records
,
&
record
)
}
return
&
pkt
.
GuessGameRecords
{
Records
:
records
},
nil
return
&
gty
.
GuessGameRecords
{
Records
:
records
},
nil
}
func
getGameListByCategoryStatus
(
db
dbm
.
Lister
,
category
string
,
status
int32
,
index
int64
)
(
types
.
Message
,
error
)
{
...
...
@@ -287,9 +287,9 @@ func getGameListByCategoryStatus(db dbm.Lister, category string, status int32, i
return
nil
,
err
}
var
records
[]
*
pkt
.
GuessGameRecord
var
records
[]
*
gty
.
GuessGameRecord
for
_
,
value
:=
range
values
{
var
record
pkt
.
GuessGameRecord
var
record
gty
.
GuessGameRecord
err
:=
types
.
Decode
(
value
,
&
record
)
if
err
!=
nil
{
continue
...
...
@@ -297,10 +297,10 @@ func getGameListByCategoryStatus(db dbm.Lister, category string, status int32, i
records
=
append
(
records
,
&
record
)
}
return
&
pkt
.
GuessGameRecords
{
Records
:
records
},
nil
return
&
gty
.
GuessGameRecords
{
Records
:
records
},
nil
}
func
(
action
*
Action
)
saveGame
(
game
*
pkt
.
GuessGame
)
(
kvset
[]
*
types
.
KeyValue
)
{
func
(
action
*
Action
)
saveGame
(
game
*
gty
.
GuessGame
)
(
kvset
[]
*
types
.
KeyValue
)
{
value
:=
types
.
Encode
(
game
)
action
.
db
.
Set
(
Key
(
game
.
GetGameID
()),
value
)
kvset
=
append
(
kvset
,
&
types
.
KeyValue
{
Key
:
Key
(
game
.
GameID
),
Value
:
value
})
...
...
@@ -312,22 +312,22 @@ func (action *Action) getIndex() int64 {
}
//GetReceiptLog 根据游戏信息生成收据记录
func
(
action
*
Action
)
GetReceiptLog
(
game
*
pkt
.
GuessGame
,
statusChange
bool
)
*
types
.
ReceiptLog
{
func
(
action
*
Action
)
GetReceiptLog
(
game
*
gty
.
GuessGame
,
statusChange
bool
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
r
:=
&
pkt
.
ReceiptGuessGame
{}
r
:=
&
gty
.
ReceiptGuessGame
{}
r
.
Addr
=
action
.
fromaddr
if
game
.
Status
==
pkt
.
GuessGameStatusStart
{
log
.
Ty
=
pkt
.
TyLogGuessGameStart
}
else
if
game
.
Status
==
pkt
.
GuessGameStatusBet
{
log
.
Ty
=
pkt
.
TyLogGuessGameBet
}
else
if
game
.
Status
==
pkt
.
GuessGameStatusStopBet
{
log
.
Ty
=
pkt
.
TyLogGuessGameStopBet
}
else
if
game
.
Status
==
pkt
.
GuessGameStatusAbort
{
log
.
Ty
=
pkt
.
TyLogGuessGameAbort
}
else
if
game
.
Status
==
pkt
.
GuessGameStatusPublish
{
log
.
Ty
=
pkt
.
TyLogGuessGamePublish
}
else
if
game
.
Status
==
pkt
.
GuessGameStatusTimeOut
{
log
.
Ty
=
pkt
.
TyLogGuessGameTimeout
if
game
.
Status
==
gty
.
GuessGameStatusStart
{
log
.
Ty
=
gty
.
TyLogGuessGameStart
}
else
if
game
.
Status
==
gty
.
GuessGameStatusBet
{
log
.
Ty
=
gty
.
TyLogGuessGameBet
}
else
if
game
.
Status
==
gty
.
GuessGameStatusStopBet
{
log
.
Ty
=
gty
.
TyLogGuessGameStopBet
}
else
if
game
.
Status
==
gty
.
GuessGameStatusAbort
{
log
.
Ty
=
gty
.
TyLogGuessGameAbort
}
else
if
game
.
Status
==
gty
.
GuessGameStatusPublish
{
log
.
Ty
=
gty
.
TyLogGuessGamePublish
}
else
if
game
.
Status
==
gty
.
GuessGameStatusTimeOut
{
log
.
Ty
=
gty
.
TyLogGuessGameTimeout
}
r
.
Index
=
game
.
Index
...
...
@@ -342,12 +342,12 @@ func (action *Action) GetReceiptLog(game *pkt.GuessGame, statusChange bool) *typ
return
log
}
func
(
action
*
Action
)
readGame
(
id
string
)
(
*
pkt
.
GuessGame
,
error
)
{
func
(
action
*
Action
)
readGame
(
id
string
)
(
*
gty
.
GuessGame
,
error
)
{
data
,
err
:=
action
.
db
.
Get
(
Key
(
id
))
if
err
!=
nil
{
return
nil
,
err
}
var
game
pkt
.
GuessGame
var
game
gty
.
GuessGame
//decode
err
=
types
.
Decode
(
data
,
&
game
)
if
err
!=
nil
{
...
...
@@ -357,10 +357,10 @@ func (action *Action) readGame(id string) (*pkt.GuessGame, error) {
}
// 新建一局游戏
func
(
action
*
Action
)
newGame
(
gameID
string
,
start
*
pkt
.
GuessGameStart
)
(
*
pkt
.
GuessGame
,
error
)
{
game
:=
&
pkt
.
GuessGame
{
func
(
action
*
Action
)
newGame
(
gameID
string
,
start
*
gty
.
GuessGameStart
)
(
*
gty
.
GuessGame
,
error
)
{
game
:=
&
gty
.
GuessGame
{
GameID
:
gameID
,
Status
:
pkt
.
GuessGameActionStart
,
Status
:
gty
.
GuessGameActionStart
,
//StartTime: action.blocktime,
StartTxHash
:
gameID
,
Topic
:
start
.
Topic
,
...
...
@@ -384,7 +384,7 @@ func (action *Action) newGame(gameID string, start *pkt.GuessGameStart) (*pkt.Gu
}
//GameStart 创建游戏动作执行
func
(
action
*
Action
)
GameStart
(
start
*
pkt
.
GuessGameStart
)
(
*
types
.
Receipt
,
error
)
{
func
(
action
*
Action
)
GameStart
(
start
*
gty
.
GuessGameStart
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
...
...
@@ -403,7 +403,7 @@ func (action *Action) GameStart(start *pkt.GuessGameStart) (*types.Receipt, erro
if
start
.
MaxBetsNumber
>=
MaxBetsNumber
{
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"
,
int64
(
MaxBetsNumber
),
start
.
MaxBetsNumber
))
return
nil
,
pkt
.
ErrOverBetsLimit
return
nil
,
gty
.
ErrOverBetsLimit
}
if
len
(
start
.
Topic
)
==
0
||
len
(
start
.
Options
)
==
0
{
...
...
@@ -440,7 +440,7 @@ func (action *Action) GameStart(start *pkt.GuessGameStart) (*types.Receipt, erro
mainHeight
:=
action
.
GetMainHeightByTxHash
(
action
.
txhash
)
if
mainHeight
<
0
{
logger
.
Error
(
"GameStart"
,
"mainHeight"
,
mainHeight
)
return
nil
,
pkt
.
ErrGuessStatus
return
nil
,
gty
.
ErrGuessStatus
}
game
.
StartHeight
=
mainHeight
}
else
{
...
...
@@ -449,10 +449,10 @@ func (action *Action) GameStart(start *pkt.GuessGameStart) (*types.Receipt, erro
game
.
AdminAddr
=
action
.
fromaddr
game
.
PreIndex
=
0
game
.
Index
=
action
.
getIndex
()
game
.
Status
=
pkt
.
GuessGameStatusStart
game
.
BetStat
=
&
pkt
.
GuessBetStat
{
TotalBetTimes
:
0
,
TotalBetsNumber
:
0
}
game
.
Status
=
gty
.
GuessGameStatusStart
game
.
BetStat
=
&
gty
.
GuessBetStat
{
TotalBetTimes
:
0
,
TotalBetsNumber
:
0
}
for
i
:=
0
;
i
<
len
(
options
);
i
++
{
item
:=
&
pkt
.
GuessBetStatItem
{
Option
:
options
[
i
],
BetsNumber
:
0
,
BetsTimes
:
0
}
item
:=
&
gty
.
GuessBetStatItem
{
Option
:
options
[
i
],
BetsNumber
:
0
,
BetsTimes
:
0
}
game
.
BetStat
.
Items
=
append
(
game
.
BetStat
.
Items
,
item
)
}
...
...
@@ -464,7 +464,7 @@ func (action *Action) GameStart(start *pkt.GuessGameStart) (*types.Receipt, erro
}
//GameBet 参与游戏动作执行
func
(
action
*
Action
)
GameBet
(
pbBet
*
pkt
.
GuessGameBet
)
(
*
types
.
Receipt
,
error
)
{
func
(
action
*
Action
)
GameBet
(
pbBet
*
gty
.
GuessGameBet
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
...
...
@@ -476,10 +476,10 @@ func (action *Action) GameBet(pbBet *pkt.GuessGameBet) (*types.Receipt, error) {
}
prevStatus
:=
game
.
Status
if
game
.
Status
!=
pkt
.
GuessGameStatusStart
&&
game
.
Status
!=
pkt
.
GuessGameStatusBet
{
if
game
.
Status
!=
gty
.
GuessGameStatusStart
&&
game
.
Status
!=
gty
.
GuessGameStatusBet
{
logger
.
Error
(
"GameBet"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"Status error"
,
game
.
GetStatus
())
return
nil
,
pkt
.
ErrGuessStatus
return
nil
,
gty
.
ErrGuessStatus
}
canBet
:=
action
.
RefreshStatusByTime
(
game
)
...
...
@@ -542,8 +542,8 @@ func (action *Action) GameBet(pbBet *pkt.GuessGameBet) (*types.Receipt, error) {
kv
=
append
(
kv
,
receipt
.
KV
...
)
var
receiptLog
*
types
.
ReceiptLog
if
prevStatus
!=
pkt
.
GuessGameStatusBet
{
action
.
ChangeStatus
(
game
,
pkt
.
GuessGameStatusBet
)
if
prevStatus
!=
gty
.
GuessGameStatusBet
{
action
.
ChangeStatus
(
game
,
gty
.
GuessGameStatusBet
)
action
.
AddGuessBet
(
game
,
pbBet
)
receiptLog
=
action
.
GetReceiptLog
(
game
,
true
)
}
else
{
...
...
@@ -558,7 +558,7 @@ func (action *Action) GameBet(pbBet *pkt.GuessGameBet) (*types.Receipt, error) {
}
//GameStopBet 停止游戏下注动作执行
func
(
action
*
Action
)
GameStopBet
(
pbBet
*
pkt
.
GuessGameStopBet
)
(
*
types
.
Receipt
,
error
)
{
func
(
action
*
Action
)
GameStopBet
(
pbBet
*
gty
.
GuessGameStopBet
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
...
...
@@ -569,20 +569,20 @@ func (action *Action) GameStopBet(pbBet *pkt.GuessGameStopBet) (*types.Receipt,
return
nil
,
err
}
if
game
.
Status
!=
pkt
.
GuessGameStatusStart
&&
game
.
Status
!=
pkt
.
GuessGameStatusBet
{
if
game
.
Status
!=
gty
.
GuessGameStatusStart
&&
game
.
Status
!=
gty
.
GuessGameStatusBet
{
logger
.
Error
(
"GameBet"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"Status error"
,
game
.
GetStatus
())
return
nil
,
pkt
.
ErrGuessStatus
return
nil
,
gty
.
ErrGuessStatus
}
//只有adminAddr可以发起stopBet
if
game
.
AdminAddr
!=
action
.
fromaddr
{
logger
.
Error
(
"GameStopBet"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"fromAddr is not adminAddr"
,
action
.
fromaddr
,
"adminAddr"
,
game
.
AdminAddr
)
return
nil
,
pkt
.
ErrNoPrivilege
return
nil
,
gty
.
ErrNoPrivilege
}
action
.
ChangeStatus
(
game
,
pkt
.
GuessGameStatusStopBet
)
action
.
ChangeStatus
(
game
,
gty
.
GuessGameStatusStopBet
)
var
receiptLog
*
types
.
ReceiptLog
//状态发生变化,更新所有addr对应记录的index
...
...
@@ -596,9 +596,9 @@ func (action *Action) GameStopBet(pbBet *pkt.GuessGameStopBet) (*types.Receipt,
}
//AddGuessBet 向游戏结构中加入下注信息
func
(
action
*
Action
)
AddGuessBet
(
game
*
pkt
.
GuessGame
,
pbBet
*
pkt
.
GuessGameBet
)
{
bet
:=
&
pkt
.
GuessBet
{
Option
:
pbBet
.
GetOption
(),
BetsNumber
:
pbBet
.
BetsNum
,
Index
:
game
.
Index
}
player
:=
&
pkt
.
GuessPlayer
{
Addr
:
action
.
fromaddr
,
Bet
:
bet
}
func
(
action
*
Action
)
AddGuessBet
(
game
*
gty
.
GuessGame
,
pbBet
*
gty
.
GuessGameBet
)
{
bet
:=
&
gty
.
GuessBet
{
Option
:
pbBet
.
GetOption
(),
BetsNumber
:
pbBet
.
BetsNum
,
Index
:
game
.
Index
}
player
:=
&
gty
.
GuessPlayer
{
Addr
:
action
.
fromaddr
,
Bet
:
bet
}
game
.
Plays
=
append
(
game
.
Plays
,
player
)
for
i
:=
0
;
i
<
len
(
game
.
BetStat
.
Items
);
i
++
{
...
...
@@ -618,7 +618,7 @@ func (action *Action) AddGuessBet(game *pkt.GuessGame, pbBet *pkt.GuessGameBet)
}
//GamePublish 公布竞猜游戏结果动作执行
func
(
action
*
Action
)
GamePublish
(
publish
*
pkt
.
GuessGamePublish
)
(
*
types
.
Receipt
,
error
)
{
func
(
action
*
Action
)
GamePublish
(
publish
*
gty
.
GuessGamePublish
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
...
...
@@ -633,13 +633,13 @@ func (action *Action) GamePublish(publish *pkt.GuessGamePublish) (*types.Receipt
if
game
.
AdminAddr
!=
action
.
fromaddr
{
logger
.
Error
(
"GamePublish"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"fromAddr is not adminAddr"
,
action
.
fromaddr
,
"adminAddr"
,
game
.
AdminAddr
)
return
nil
,
pkt
.
ErrNoPrivilege
return
nil
,
gty
.
ErrNoPrivilege
}
if
game
.
Status
!=
pkt
.
GuessGameStatusStart
&&
game
.
Status
!=
pkt
.
GuessGameStatusBet
&&
game
.
Status
!=
pkt
.
GuessGameStatusStopBet
{
if
game
.
Status
!=
gty
.
GuessGameStatusStart
&&
game
.
Status
!=
gty
.
GuessGameStatusBet
&&
game
.
Status
!=
gty
.
GuessGameStatusStopBet
{
logger
.
Error
(
"GamePublish"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"Status error"
,
game
.
GetStatus
())
return
nil
,
pkt
.
ErrGuessStatus
return
nil
,
gty
.
ErrGuessStatus
}
//检查竞猜选项是否合法
...
...
@@ -682,7 +682,7 @@ func (action *Action) GamePublish(publish *pkt.GuessGamePublish) (*types.Receipt
kv
=
append
(
kv
,
receipt
.
KV
...
)
}
action
.
ChangeStatus
(
game
,
pkt
.
GuessGameStatusPublish
)
action
.
ChangeStatus
(
game
,
gty
.
GuessGameStatusPublish
)
//计算竞猜正确的筹码总数
totalBetsNumber
:=
game
.
BetStat
.
TotalBetsNumber
winBetsNumber
:=
int64
(
0
)
...
...
@@ -693,8 +693,8 @@ func (action *Action) GamePublish(publish *pkt.GuessGamePublish) (*types.Receipt
}
//按创建游戏时设定的比例,转移佣金到开发者账户和平台账户
devAddr
:=
pkt
.
DevShareAddr
platAddr
:=
pkt
.
PlatformShareAddr
devAddr
:=
gty
.
DevShareAddr
platAddr
:=
gty
.
PlatformShareAddr
devFee
:=
int64
(
0
)
platFee
:=
int64
(
0
)
if
len
(
game
.
DevFeeAddr
)
>
0
{
...
...
@@ -762,7 +762,7 @@ func (action *Action) GamePublish(publish *pkt.GuessGamePublish) (*types.Receipt
}
//GameAbort 撤销游戏动作执行
func
(
action
*
Action
)
GameAbort
(
pbend
*
pkt
.
GuessGameAbort
)
(
*
types
.
Receipt
,
error
)
{
func
(
action
*
Action
)
GameAbort
(
pbend
*
gty
.
GuessGameAbort
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
...
...
@@ -773,11 +773,11 @@ func (action *Action) GameAbort(pbend *pkt.GuessGameAbort) (*types.Receipt, erro
return
nil
,
err
}
if
game
.
Status
==
pkt
.
GuessGameStatusPublish
||
game
.
Status
==
pkt
.
GuessGameStatusAbort
{
if
game
.
Status
==
gty
.
GuessGameStatusPublish
||
game
.
Status
==
gty
.
GuessGameStatusAbort
{
logger
.
Error
(
"GameAbort"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"game status not allow abort"
,
game
.
Status
)
return
nil
,
pkt
.
ErrGuessStatus
return
nil
,
gty
.
ErrGuessStatus
}
preStatus
:=
game
.
Status
...
...
@@ -785,7 +785,7 @@ func (action *Action) GameAbort(pbend *pkt.GuessGameAbort) (*types.Receipt, erro
action
.
RefreshStatusByTime
(
game
)
//如果游戏超时,则任何地址都可以Abort,否则只有创建游戏的地址可以Abort
if
game
.
Status
!=
pkt
.
GuessGameStatusTimeOut
{
if
game
.
Status
!=
gty
.
GuessGameStatusTimeOut
{
if
game
.
AdminAddr
!=
action
.
fromaddr
{
logger
.
Error
(
"GameAbort"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"Only admin can abort"
,
action
.
fromaddr
,
"status"
,
game
.
Status
)
...
...
@@ -812,9 +812,9 @@ func (action *Action) GameAbort(pbend *pkt.GuessGameAbort) (*types.Receipt, erro
if
game
.
Status
!=
preStatus
{
//说明action.RefreshStatusByTime(game)调用时已经更新过状态和index了,这里直接再改状态就行了。
game
.
Status
=
pkt
.
GuessGameStatusAbort
game
.
Status
=
gty
.
GuessGameStatusAbort
}
else
{
action
.
ChangeStatus
(
game
,
pkt
.
GuessGameStatusAbort
)
action
.
ChangeStatus
(
game
,
gty
.
GuessGameStatusAbort
)
}
//状态发生变化,统一更新所有addr记录的index
...
...
@@ -857,7 +857,7 @@ func IsLegalOption(options []string, option string) bool {
}
//ChangeStatus 修改游戏状态,同步更新历史记录
func
(
action
*
Action
)
ChangeStatus
(
game
*
pkt
.
GuessGame
,
destStatus
int32
)
{
func
(
action
*
Action
)
ChangeStatus
(
game
*
gty
.
GuessGame
,
destStatus
int32
)
{
if
game
.
Status
!=
destStatus
{
game
.
PreStatus
=
game
.
Status
game
.
PreIndex
=
game
.
Index
...
...
@@ -867,7 +867,7 @@ func (action *Action) ChangeStatus(game *pkt.GuessGame, destStatus int32) {
}
//ChangeAllAddrIndex 状态更新时,更新下注记录的历史信息
func
(
action
*
Action
)
ChangeAllAddrIndex
(
game
*
pkt
.
GuessGame
)
{
func
(
action
*
Action
)
ChangeAllAddrIndex
(
game
*
gty
.
GuessGame
)
{
for
i
:=
0
;
i
<
len
(
game
.
Plays
);
i
++
{
player
:=
game
.
Plays
[
i
]
player
.
Bet
.
PreIndex
=
player
.
Bet
.
Index
...
...
@@ -876,7 +876,7 @@ func (action *Action) ChangeAllAddrIndex(game *pkt.GuessGame) {
}
//RefreshStatusByTime 检测游戏是否过期,是否可以下注
func
(
action
*
Action
)
RefreshStatusByTime
(
game
*
pkt
.
GuessGame
)
(
canBet
bool
)
{
func
(
action
*
Action
)
RefreshStatusByTime
(
game
*
gty
.
GuessGame
)
(
canBet
bool
)
{
var
mainHeight
int64
if
types
.
IsPara
()
{
...
...
@@ -893,7 +893,7 @@ func (action *Action) RefreshStatusByTime(game *pkt.GuessGame) (canBet bool) {
if
game
.
DrivenByAdmin
{
if
(
mainHeight
-
game
.
StartHeight
)
>=
game
.
ExpireHeight
{
action
.
ChangeStatus
(
game
,
pkt
.
GuessGameStatusTimeOut
)
action
.
ChangeStatus
(
game
,
gty
.
GuessGameStatusTimeOut
)
canBet
=
false
return
canBet
}
...
...
@@ -907,9 +907,9 @@ func (action *Action) RefreshStatusByTime(game *pkt.GuessGame) (canBet bool) {
logger
.
Error
(
"GameBet"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"Height over limit"
,
mainHeight
,
"startHeight"
,
game
.
StartHeight
,
"MaxHeightDiff"
,
game
.
GetMaxBetHeight
())
if
game
.
ExpireHeight
>
heightDiff
{
action
.
ChangeStatus
(
game
,
pkt
.
GuessGameStatusStopBet
)
action
.
ChangeStatus
(
game
,
gty
.
GuessGameStatusStopBet
)
}
else
{
action
.
ChangeStatus
(
game
,
pkt
.
GuessGameStatusTimeOut
)
action
.
ChangeStatus
(
game
,
gty
.
GuessGameStatusTimeOut
)
}
canBet
=
false
...
...
@@ -921,7 +921,7 @@ func (action *Action) RefreshStatusByTime(game *pkt.GuessGame) (canBet bool) {
}
//CheckTime 检测游戏的过期设置。
func
(
action
*
Action
)
CheckTime
(
start
*
pkt
.
GuessGameStart
)
bool
{
func
(
action
*
Action
)
CheckTime
(
start
*
gty
.
GuessGameStart
)
bool
{
if
start
.
MaxBetHeight
==
0
&&
start
.
ExpireHeight
==
0
{
//如果上述字段都不携带,则认为完全由admin的指令驱动。
start
.
DrivenByAdmin
=
true
...
...
plugin/dapp/guess/executor/keys.go
View file @
0c4557b7
...
...
@@ -4,7 +4,7 @@ import (
"fmt"
"github.com/33cn/chain33/types"
pkt
"github.com/33cn/plugin/plugin/dapp/guess/types"
gty
"github.com/33cn/plugin/plugin/dapp/guess/types"
)
//addr prefix
...
...
@@ -80,7 +80,7 @@ func calcGuessGameCategoryStatusKey(category string, status int32, index int64)
func
addGuessGameAddrIndexKey
(
status
int32
,
addr
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAddrKey
(
addr
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
record
:=
&
gty
.
GuessGameRecord
{
GameID
:
gameID
,
Status
:
status
,
Index
:
index
,
...
...
@@ -99,7 +99,7 @@ func delGuessGameAddrIndexKey(addr string, index int64) *types.KeyValue {
func
addGuessGameStatusIndexKey
(
status
int32
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameStatusKey
(
status
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
record
:=
&
gty
.
GuessGameRecord
{
GameID
:
gameID
,
Status
:
status
,
Index
:
index
,
...
...
@@ -118,7 +118,7 @@ func delGuessGameStatusIndexKey(status int32, index int64) *types.KeyValue {
func
addGuessGameAddrStatusIndexKey
(
status
int32
,
addr
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAddrStatusKey
(
addr
,
status
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
record
:=
&
gty
.
GuessGameRecord
{
GameID
:
gameID
,
Status
:
status
,
Index
:
index
,
...
...
@@ -137,7 +137,7 @@ func delGuessGameAddrStatusIndexKey(status int32, addr string, index int64) *typ
func
addGuessGameAdminIndexKey
(
status
int32
,
addr
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAdminKey
(
addr
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
record
:=
&
gty
.
GuessGameRecord
{
GameID
:
gameID
,
Status
:
status
,
Index
:
index
,
...
...
@@ -156,7 +156,7 @@ func delGuessGameAdminIndexKey(addr string, index int64) *types.KeyValue {
func
addGuessGameAdminStatusIndexKey
(
status
int32
,
addr
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameAdminStatusKey
(
addr
,
status
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
record
:=
&
gty
.
GuessGameRecord
{
GameID
:
gameID
,
Status
:
status
,
Index
:
index
,
...
...
@@ -175,7 +175,7 @@ func delGuessGameAdminStatusIndexKey(status int32, addr string, index int64) *ty
func
addGuessGameCategoryStatusIndexKey
(
status
int32
,
category
,
gameID
string
,
index
int64
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcGuessGameCategoryStatusKey
(
category
,
status
,
index
)
record
:=
&
pkt
.
GuessGameRecord
{
record
:=
&
gty
.
GuessGameRecord
{
GameID
:
gameID
,
Status
:
status
,
Index
:
index
,
...
...
plugin/dapp/guess/executor/query.go
View file @
0c4557b7
...
...
@@ -6,25 +6,25 @@ package executor
import
(
"github.com/33cn/chain33/types"
pkt
"github.com/33cn/plugin/plugin/dapp/guess/types"
gty
"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
*
gty
.
QueryGuessGameInfos
)
(
types
.
Message
,
error
)
{
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
*
gty
.
QueryGuessGameInfo
)
(
types
.
Message
,
error
)
{
game
,
err
:=
readGame
(
g
.
GetStateDB
(),
in
.
GetGameID
())
if
err
!=
nil
{
return
nil
,
err
}
return
&
pkt
.
ReplyGuessGameInfo
{
Game
:
game
},
nil
return
&
gty
.
ReplyGuessGameInfo
{
Game
:
game
},
nil
}
//Query_QueryGamesByAddr method
func
(
g
*
Guess
)
Query_QueryGamesByAddr
(
in
*
pkt
.
QueryGuessGameInfo
)
(
types
.
Message
,
error
)
{
func
(
g
*
Guess
)
Query_QueryGamesByAddr
(
in
*
gty
.
QueryGuessGameInfo
)
(
types
.
Message
,
error
)
{
records
,
err
:=
getGameListByAddr
(
g
.
GetLocalDB
(),
in
.
Addr
,
in
.
Index
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -34,7 +34,7 @@ func (g *Guess) Query_QueryGamesByAddr(in *pkt.QueryGuessGameInfo) (types.Messag
}
//Query_QueryGamesByStatus method
func
(
g
*
Guess
)
Query_QueryGamesByStatus
(
in
*
pkt
.
QueryGuessGameInfo
)
(
types
.
Message
,
error
)
{
func
(
g
*
Guess
)
Query_QueryGamesByStatus
(
in
*
gty
.
QueryGuessGameInfo
)
(
types
.
Message
,
error
)
{
records
,
err
:=
getGameListByStatus
(
g
.
GetLocalDB
(),
in
.
Status
,
in
.
Index
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -44,7 +44,7 @@ func (g *Guess) Query_QueryGamesByStatus(in *pkt.QueryGuessGameInfo) (types.Mess
}
//Query_QueryGamesByAdminAddr method
func
(
g
*
Guess
)
Query_QueryGamesByAdminAddr
(
in
*
pkt
.
QueryGuessGameInfo
)
(
types
.
Message
,
error
)
{
func
(
g
*
Guess
)
Query_QueryGamesByAdminAddr
(
in
*
gty
.
QueryGuessGameInfo
)
(
types
.
Message
,
error
)
{
records
,
err
:=
getGameListByAdminAddr
(
g
.
GetLocalDB
(),
in
.
AdminAddr
,
in
.
Index
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -54,7 +54,7 @@ func (g *Guess) Query_QueryGamesByAdminAddr(in *pkt.QueryGuessGameInfo) (types.M
}
//Query_QueryGamesByAddrStatus method
func
(
g
*
Guess
)
Query_QueryGamesByAddrStatus
(
in
*
pkt
.
QueryGuessGameInfo
)
(
types
.
Message
,
error
)
{
func
(
g
*
Guess
)
Query_QueryGamesByAddrStatus
(
in
*
gty
.
QueryGuessGameInfo
)
(
types
.
Message
,
error
)
{
records
,
err
:=
getGameListByAddrStatus
(
g
.
GetLocalDB
(),
in
.
Addr
,
in
.
Status
,
in
.
Index
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -64,7 +64,7 @@ func (g *Guess) Query_QueryGamesByAddrStatus(in *pkt.QueryGuessGameInfo) (types.
}
//Query_QueryGamesByAdminStatus method
func
(
g
*
Guess
)
Query_QueryGamesByAdminStatus
(
in
*
pkt
.
QueryGuessGameInfo
)
(
types
.
Message
,
error
)
{
func
(
g
*
Guess
)
Query_QueryGamesByAdminStatus
(
in
*
gty
.
QueryGuessGameInfo
)
(
types
.
Message
,
error
)
{
records
,
err
:=
getGameListByAdminStatus
(
g
.
GetLocalDB
(),
in
.
AdminAddr
,
in
.
Status
,
in
.
Index
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -74,7 +74,7 @@ func (g *Guess) Query_QueryGamesByAdminStatus(in *pkt.QueryGuessGameInfo) (types
}
//Query_QueryGamesByCategoryStatus method
func
(
g
*
Guess
)
Query_QueryGamesByCategoryStatus
(
in
*
pkt
.
QueryGuessGameInfo
)
(
types
.
Message
,
error
)
{
func
(
g
*
Guess
)
Query_QueryGamesByCategoryStatus
(
in
*
gty
.
QueryGuessGameInfo
)
(
types
.
Message
,
error
)
{
records
,
err
:=
getGameListByCategoryStatus
(
g
.
GetLocalDB
(),
in
.
Category
,
in
.
Status
,
in
.
Index
)
if
err
!=
nil
{
return
nil
,
err
...
...
plugin/dapp/guess/types/types.go
View file @
0c4557b7
...
...
@@ -7,14 +7,9 @@ package types
import
(
"reflect"
log
"github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/types"
)
var
(
llog
=
log
.
New
(
"module"
,
"exectype."
+
GuessX
)
)
func
init
()
{
// init executor type
types
.
RegistorExecutor
(
GuessX
,
NewType
())
...
...
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