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