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
afbd0de6
Unverified
Commit
afbd0de6
authored
Dec 15, 2018
by
33cn
Committed by
GitHub
Dec 15, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #141 from jpeng-go/pokerbull
Pokerbull问题修复
parents
62cbbdc6
66bcc4fb
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
217 additions
and
239 deletions
+217
-239
game.go
plugin/dapp/pokerbull/commands/game.go
+34
-23
pokerbull.go
plugin/dapp/pokerbull/executor/pokerbull.go
+2
-2
pokerbulldb.go
plugin/dapp/pokerbull/executor/pokerbulldb.go
+0
-0
query.go
plugin/dapp/pokerbull/executor/query.go
+46
-1
plugin.go
plugin/dapp/pokerbull/plugin.go
+0
-2
pokerbull.proto
plugin/dapp/pokerbull/proto/pokerbull.proto
+23
-11
jrpc.go
plugin/dapp/pokerbull/rpc/jrpc.go
+0
-84
jrpc_channel_test.go
plugin/dapp/pokerbull/rpc/jrpc_channel_test.go
+79
-16
rpc.go
plugin/dapp/pokerbull/rpc/rpc.go
+0
-70
types.go
plugin/dapp/pokerbull/rpc/types.go
+0
-30
const.go
plugin/dapp/pokerbull/types/const.go
+33
-0
pokerbull.pb.go
plugin/dapp/pokerbull/types/pokerbull.pb.go
+0
-0
No files found.
plugin/dapp/pokerbull/commands/game.go
View file @
afbd0de6
...
...
@@ -56,19 +56,15 @@ func pokerbullStart(cmd *cobra.Command, args []string) {
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
value
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"value"
)
playerCount
,
_
:=
cmd
.
Flags
()
.
GetUint32
(
"playerCount"
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
feeInt64
:=
int64
(
fee
*
1e4
)
amountInt64
:=
int64
(
value
)
params
:=
&
pkt
.
PBStartTxReq
{
Value
:
amountInt64
*
types
.
Coin
,
PlayerNum
:
int32
(
playerCount
),
Fee
:
feeInt64
,
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
PokerBullX
),
ActionName
:
pkt
.
CreateStartTx
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
value
\"
:%d,
\"
playerNum
\"
:%d}"
,
int64
(
value
)
*
types
.
Coin
,
int32
(
playerCount
))),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"
pokerbull.PokerBullStartTx
"
,
params
,
&
res
)
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"
Chain33.CreateTransaction
"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
...
...
@@ -91,17 +87,15 @@ func addPokerbullContinueFlags(cmd *cobra.Command) {
func
pokerbullContinue
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
gameID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"gameID"
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
feeInt64
:=
int64
(
fee
*
1e4
)
params
:=
&
pkt
.
PBContinueTxReq
{
GameId
:
gameID
,
Fee
:
feeInt64
,
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
PokerBullX
),
ActionName
:
pkt
.
CreateContinueTx
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
gameId
\"
:
\"
%s
\"
}"
,
gameID
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"
pokerbull.PokerBullContinueTx
"
,
params
,
&
res
)
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"
Chain33.CreateTransaction
"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
...
...
@@ -124,17 +118,15 @@ func addPokerbullQuitFlags(cmd *cobra.Command) {
func
pokerbullQuit
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
gameID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"gameID"
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
feeInt64
:=
int64
(
fee
*
1e4
)
params
:=
&
pkt
.
PBContinueTxReq
{
GameId
:
gameID
,
Fee
:
feeInt64
,
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
PokerBullX
),
ActionName
:
pkt
.
CreatequitTx
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
gameId
\"
:
\"
%s
\"
}"
,
gameID
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"
pokerbull.PokerBullQuitTx
"
,
params
,
&
res
)
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"
Chain33.CreateTransaction
"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
...
...
@@ -155,6 +147,7 @@ func addPokerbullQueryFlags(cmd *cobra.Command) {
cmd
.
Flags
()
.
StringP
(
"index"
,
"i"
,
""
,
"index"
)
cmd
.
Flags
()
.
StringP
(
"status"
,
"s"
,
""
,
"status"
)
cmd
.
Flags
()
.
StringP
(
"gameIDs"
,
"d"
,
""
,
"gameIDs"
)
cmd
.
Flags
()
.
StringP
(
"round"
,
"r"
,
""
,
"round"
)
}
func
pokerbullQuery
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
...
...
@@ -166,6 +159,7 @@ func pokerbullQuery(cmd *cobra.Command, args []string) {
indexstr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"index"
)
index
,
_
:=
strconv
.
ParseInt
(
indexstr
,
10
,
64
)
gameIDs
,
_
:=
cmd
.
Flags
()
.
GetString
(
"gameIDs"
)
round
,
_
:=
cmd
.
Flags
()
.
GetString
(
"round"
)
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
pkt
.
PokerBullX
...
...
@@ -177,10 +171,27 @@ func pokerbullQuery(cmd *cobra.Command, args []string) {
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
if
gameID
!=
""
{
if
round
==
""
{
params
.
FuncName
=
pkt
.
FuncNameQueryGameByID
var
res
pkt
.
ReplyPBGame
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
else
{
params
.
FuncName
=
pkt
.
FuncNameQueryGameByRound
roundInt
,
err
:=
strconv
.
ParseInt
(
round
,
10
,
32
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
}
req
:=
&
pkt
.
QueryPBGameByRound
{
GameId
:
gameID
,
Round
:
int32
(
roundInt
),
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
ReplyPBGameByRound
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
}
else
if
address
!=
""
{
params
.
FuncName
=
pkt
.
FuncNameQueryGameByAddr
var
res
pkt
.
PBGameRecords
...
...
plugin/dapp/pokerbull/executor/pokerbull.go
View file @
afbd0de6
...
...
@@ -70,7 +70,7 @@ func calcPBGameStatusKey(status int32, index int64) []byte {
}
func
calcPBGameStatusAndPlayerKey
(
status
,
player
int32
,
value
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-pokerbull-status:%d:%d:%d:%018d"
,
status
,
player
,
value
,
index
)
key
:=
fmt
.
Sprintf
(
"LODB-pokerbull-status:%d:%d:%
015
d:%018d"
,
status
,
player
,
value
,
index
)
return
[]
byte
(
key
)
}
...
...
@@ -79,7 +79,7 @@ func calcPBGameStatusAndPlayerPrefix(status, player int32, value int64) []byte {
if
value
==
0
{
key
=
fmt
.
Sprintf
(
"LODB-pokerbull-status:%d:%d:"
,
status
,
player
)
}
else
{
key
=
fmt
.
Sprintf
(
"LODB-pokerbull-status:%d:%d:%d"
,
status
,
player
,
value
)
key
=
fmt
.
Sprintf
(
"LODB-pokerbull-status:%d:%d:%
015
d"
,
status
,
player
,
value
)
}
return
[]
byte
(
key
)
...
...
plugin/dapp/pokerbull/executor/pokerbulldb.go
View file @
afbd0de6
This diff is collapsed.
Click to expand it.
plugin/dapp/pokerbull/executor/query.go
View file @
afbd0de6
...
...
@@ -29,7 +29,6 @@ func (g *PokerBull) Query_QueryGameByAddr(in *pkt.QueryPBGameInfo) (types.Messag
if
err
!=
nil
{
return
nil
,
err
}
return
gameIds
,
nil
}
...
...
@@ -42,3 +41,49 @@ func (g *PokerBull) Query_QueryGameByStatus(in *pkt.QueryPBGameInfo) (types.Mess
return
gameIds
,
nil
}
// Query_QueryGameByRound 查询某一回合游戏结果
func
(
g
*
PokerBull
)
Query_QueryGameByRound
(
in
*
pkt
.
QueryPBGameByRound
)
(
types
.
Message
,
error
)
{
game
,
err
:=
readGame
(
g
.
GetStateDB
(),
in
.
GetGameId
())
if
err
!=
nil
{
return
nil
,
err
}
if
in
.
Round
>
game
.
Round
{
return
nil
,
types
.
ErrInvalidParam
}
var
roundPlayers
[]
*
pkt
.
PBPlayer
for
_
,
player
:=
range
game
.
Players
{
var
isReady
bool
if
in
.
Round
==
game
.
Round
{
isReady
=
player
.
Ready
}
else
{
isReady
=
false
}
roundPlayer
:=
&
pkt
.
PBPlayer
{
Address
:
player
.
Address
,
Ready
:
isReady
,
}
roundPlayers
=
append
(
roundPlayers
,
roundPlayer
)
}
var
result
*
pkt
.
PBResult
if
len
(
game
.
Results
)
<
int
(
in
.
Round
)
{
result
=
nil
}
else
{
result
=
game
.
Results
[
in
.
Round
-
1
]
}
gameInfo
:=
&
pkt
.
ReplyPBGameByRound
{
GameId
:
game
.
GameId
,
Status
:
game
.
Status
,
Result
:
result
,
IsWaiting
:
game
.
IsWaiting
,
Value
:
game
.
Value
,
Players
:
roundPlayers
,
Return
:
(
game
.
Value
/
types
.
Coin
)
*
pkt
.
WinnerReturn
,
}
return
gameInfo
,
nil
}
plugin/dapp/pokerbull/plugin.go
View file @
afbd0de6
...
...
@@ -8,7 +8,6 @@ import (
"github.com/33cn/chain33/pluginmgr"
"github.com/33cn/plugin/plugin/dapp/pokerbull/commands"
"github.com/33cn/plugin/plugin/dapp/pokerbull/executor"
"github.com/33cn/plugin/plugin/dapp/pokerbull/rpc"
"github.com/33cn/plugin/plugin/dapp/pokerbull/types"
)
...
...
@@ -18,6 +17,5 @@ func init() {
ExecName
:
executor
.
GetName
(),
Exec
:
executor
.
Init
,
Cmd
:
commands
.
PokerBullCmd
,
RPC
:
rpc
.
Init
,
})
}
plugin/dapp/pokerbull/proto/pokerbull.proto
View file @
afbd0de6
syntax
=
"proto3"
;
import
"transaction.proto"
;
package
types
;
//斗牛游戏内容
...
...
@@ -22,6 +20,7 @@ message PokerBull {
string
dealerAddr
=
14
;
//下局庄家地址
bool
isWaiting
=
15
;
//游戏是否处于等待状态
int32
preStatus
=
16
;
//上一index的状态
int32
round
=
17
;
//当前游戏回合数
}
//一把牌
...
...
@@ -111,6 +110,10 @@ message PBGameRecords {
repeated
PBGameRecord
records
=
1
;
}
message
PBGameIndexRecords
{
repeated
PBGameIndexRecord
records
=
1
;
}
message
QueryPBGameInfo
{
string
gameId
=
1
;
string
addr
=
2
;
...
...
@@ -130,6 +133,23 @@ message ReplyPBGameList {
repeated
PokerBull
games
=
1
;
}
// QueryPBGameByRound 根据gameId和回合数查询某回合的游戏结果
message
QueryPBGameByRound
{
string
gameId
=
1
;
int32
round
=
2
;
}
// ReplyPBGameByRound 某一回合游戏结果
message
ReplyPBGameByRound
{
string
gameId
=
1
;
int32
status
=
2
;
PBResult
result
=
3
;
bool
isWaiting
=
4
;
int64
value
=
5
;
repeated
PBPlayer
players
=
6
;
int64
return
=
7
;
}
message
ReceiptPBGame
{
string
gameId
=
1
;
int32
status
=
2
;
...
...
@@ -141,6 +161,7 @@ message ReceiptPBGame {
bool
isWaiting
=
8
;
repeated
string
players
=
9
;
int32
preStatus
=
10
;
int32
round
=
11
;
}
message
PBStartTxReq
{
...
...
@@ -164,12 +185,3 @@ message PBQueryReq {
int64
fee
=
2
;
}
// pokerbull 对外提供服务的接口
service
pokerbull
{
//游戏开始
rpc
Start
(
PBGameStart
)
returns
(
UnsignTx
)
{}
//游戏继续
rpc
Continue
(
PBGameContinue
)
returns
(
UnsignTx
)
{}
//游戏结束
rpc
Quit
(
PBGameQuit
)
returns
(
UnsignTx
)
{}
}
plugin/dapp/pokerbull/rpc/jrpc.go
deleted
100644 → 0
View file @
62cbbdc6
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
rpc
import
(
"context"
"encoding/hex"
"github.com/33cn/chain33/types"
pb
"github.com/33cn/plugin/plugin/dapp/pokerbull/types"
)
// PokerBullStartTx 创建游戏开始交易
func
(
c
*
Jrpc
)
PokerBullStartTx
(
parm
*
pb
.
PBStartTxReq
,
result
*
interface
{})
error
{
if
parm
==
nil
{
return
types
.
ErrInvalidParam
}
head
:=
&
pb
.
PBGameStart
{
Value
:
parm
.
Value
,
PlayerNum
:
parm
.
PlayerNum
,
}
reply
,
err
:=
c
.
cli
.
Start
(
context
.
Background
(),
head
)
if
err
!=
nil
{
return
err
}
*
result
=
hex
.
EncodeToString
(
reply
.
Data
)
return
nil
}
// PokerBullContinueTx 创建游戏继续交易
func
(
c
*
Jrpc
)
PokerBullContinueTx
(
parm
*
pb
.
PBContinueTxReq
,
result
*
interface
{})
error
{
if
parm
==
nil
{
return
types
.
ErrInvalidParam
}
head
:=
&
pb
.
PBGameContinue
{
GameId
:
parm
.
GameId
,
}
reply
,
err
:=
c
.
cli
.
Continue
(
context
.
Background
(),
head
)
if
err
!=
nil
{
return
err
}
*
result
=
hex
.
EncodeToString
(
reply
.
Data
)
return
nil
}
// PokerBullQuitTx 创建游戏推出交易
func
(
c
*
Jrpc
)
PokerBullQuitTx
(
parm
*
pb
.
PBQuitTxReq
,
result
*
interface
{})
error
{
if
parm
==
nil
{
return
types
.
ErrInvalidParam
}
head
:=
&
pb
.
PBGameQuit
{
GameId
:
parm
.
GameId
,
}
reply
,
err
:=
c
.
cli
.
Quit
(
context
.
Background
(),
head
)
if
err
!=
nil
{
return
err
}
*
result
=
hex
.
EncodeToString
(
reply
.
Data
)
return
nil
}
// PokerBullQueryTx 创建游戏查询交易
func
(
c
*
Jrpc
)
PokerBullQueryTx
(
parm
*
pb
.
PBQueryReq
,
result
*
interface
{})
error
{
if
parm
==
nil
{
return
types
.
ErrInvalidParam
}
head
:=
&
pb
.
PBGameQuery
{
GameId
:
parm
.
GameId
,
}
reply
,
err
:=
c
.
cli
.
Show
(
context
.
Background
(),
head
)
if
err
!=
nil
{
return
err
}
*
result
=
hex
.
EncodeToString
(
reply
.
Data
)
return
nil
}
plugin/dapp/pokerbull/rpc/jrpc_channel_test.go
View file @
afbd0de6
...
...
@@ -5,7 +5,7 @@
package
rpc_test
import
(
"
strings
"
"
fmt
"
"testing"
commonlog
"github.com/33cn/chain33/common/log"
...
...
@@ -41,45 +41,75 @@ func TestJRPCChannel(t *testing.T) {
{
fn
:
testStartRawTxCmd
},
{
fn
:
testContinueRawTxCmd
},
{
fn
:
testQuitRawTxCmd
},
}
for
_
,
testCase
:=
range
testCases
{
err
:=
testCase
.
fn
(
t
,
jrpcClient
)
assert
.
Nil
(
t
,
err
)
}
testCases
=
[]
struct
{
fn
func
(
*
testing
.
T
,
*
jsonclient
.
JSONClient
)
error
}{
{
fn
:
testQueryGameByID
},
{
fn
:
testQueryGameByAddr
},
{
fn
:
testQueryGameByStatus
},
{
fn
:
testQueryGameByRound
},
}
for
index
,
testCase
:=
range
testCases
{
err
:=
testCase
.
fn
(
t
,
jrpcClient
)
if
err
==
nil
{
continue
assert
.
Equal
(
t
,
err
,
types
.
ErrNotFound
,
fmt
.
Sprint
(
index
))
}
assert
.
NotEqualf
(
t
,
err
,
types
.
ErrActionNotSupport
,
"test index %d"
,
index
)
if
strings
.
Contains
(
err
.
Error
(),
"rpc: can't find"
)
{
assert
.
FailNowf
(
t
,
err
.
Error
(),
"test index %d"
,
index
)
testCases
=
[]
struct
{
fn
func
(
*
testing
.
T
,
*
jsonclient
.
JSONClient
)
error
}{
{
fn
:
testQueryGameByIDs
},
}
for
index
,
testCase
:=
range
testCases
{
err
:=
testCase
.
fn
(
t
,
jrpcClient
)
assert
.
Equal
(
t
,
err
,
nil
,
fmt
.
Sprint
(
index
))
}
}
func
testStartRawTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
params
:=
pty
.
PBStartTxReq
{}
payload
:=
&
pty
.
PBGameStart
{
Value
:
123
}
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pty
.
PokerBullX
),
ActionName
:
pty
.
CreateStartTx
,
Payload
:
types
.
MustPBToJSON
(
payload
),
}
var
res
string
return
jrpc
.
Call
(
"
pokerbull.PokerBullStartTx
"
,
params
,
&
res
)
return
jrpc
.
Call
(
"
Chain33.CreateTransaction
"
,
params
,
&
res
)
}
func
testContinueRawTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
params
:=
pty
.
PBContinueTxReq
{}
payload
:=
&
pty
.
PBGameContinue
{
GameId
:
"123"
}
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pty
.
PokerBullX
),
ActionName
:
pty
.
CreateContinueTx
,
Payload
:
types
.
MustPBToJSON
(
payload
),
}
var
res
string
return
jrpc
.
Call
(
"
pokerbull.PokerBullContinueTx
"
,
params
,
&
res
)
return
jrpc
.
Call
(
"
Chain33.CreateTransaction
"
,
params
,
&
res
)
}
func
testQuitRawTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
params
:=
pty
.
PBContinueTxReq
{}
payload
:=
&
pty
.
PBGameQuit
{
GameId
:
"123"
}
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pty
.
PokerBullX
),
ActionName
:
pty
.
CreatequitTx
,
Payload
:
types
.
MustPBToJSON
(
payload
),
}
var
res
string
return
jrpc
.
Call
(
"
pokerbull.PokerBullQuitTx
"
,
params
,
&
res
)
return
jrpc
.
Call
(
"
Chain33.CreateTransaction
"
,
params
,
&
res
)
}
func
testQueryGameByID
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
pty
.
QueryPBGameInfo
{}
params
.
Execer
=
"pokerbull"
params
.
FuncName
=
"QueryGameByID"
params
.
Execer
=
pty
.
PokerBullX
params
.
FuncName
=
pty
.
FuncNameQueryGameByID
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
pty
.
ReplyPBGame
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
...
...
@@ -89,8 +119,41 @@ func testQueryGameByAddr(t *testing.T, jrpc *jsonclient.JSONClient) error {
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
pty
.
QueryPBGameInfo
{}
params
.
Execer
=
"pokerbull"
params
.
FuncName
=
"QueryGameByAddr"
params
.
Execer
=
pty
.
PokerBullX
params
.
FuncName
=
pty
.
FuncNameQueryGameByAddr
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
pty
.
PBGameRecords
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
}
func
testQueryGameByIDs
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
pty
.
QueryPBGameInfos
{}
params
.
Execer
=
pty
.
PokerBullX
params
.
FuncName
=
pty
.
FuncNameQueryGameListByIDs
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
pty
.
ReplyPBGameList
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
}
func
testQueryGameByStatus
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
pty
.
QueryPBGameInfo
{}
params
.
Execer
=
pty
.
PokerBullX
params
.
FuncName
=
pty
.
FuncNameQueryGameByStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
pty
.
PBGameRecords
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
}
func
testQueryGameByRound
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
pty
.
QueryPBGameByRound
{}
params
.
Execer
=
pty
.
PokerBullX
params
.
FuncName
=
pty
.
FuncNameQueryGameByRound
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
pty
.
PBGameRecords
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
...
...
plugin/dapp/pokerbull/rpc/rpc.go
deleted
100644 → 0
View file @
62cbbdc6
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
rpc
import
(
"context"
"github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/pokerbull/executor"
pb
"github.com/33cn/plugin/plugin/dapp/pokerbull/types"
"github.com/pkg/errors"
)
func
(
c
*
channelClient
)
Start
(
ctx
context
.
Context
,
head
*
pb
.
PBGameStart
)
(
*
types
.
UnsignTx
,
error
)
{
if
head
.
PlayerNum
>
executor
.
MaxPlayerNum
{
return
nil
,
errors
.
New
(
"Player number should be maximum 5"
)
}
val
:=
&
pb
.
PBGameAction
{
Ty
:
pb
.
PBGameActionStart
,
Value
:
&
pb
.
PBGameAction_Start
{
Start
:
head
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
pb
.
PokerBullX
,
types
.
Encode
(
val
))
if
err
!=
nil
{
return
nil
,
err
}
data
:=
types
.
Encode
(
tx
)
return
&
types
.
UnsignTx
{
Data
:
data
},
nil
}
func
(
c
*
channelClient
)
Continue
(
ctx
context
.
Context
,
head
*
pb
.
PBGameContinue
)
(
*
types
.
UnsignTx
,
error
)
{
val
:=
&
pb
.
PBGameAction
{
Ty
:
pb
.
PBGameActionContinue
,
Value
:
&
pb
.
PBGameAction_Continue
{
Continue
:
head
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
pb
.
PokerBullX
,
types
.
Encode
(
val
))
if
err
!=
nil
{
return
nil
,
err
}
data
:=
types
.
Encode
(
tx
)
return
&
types
.
UnsignTx
{
Data
:
data
},
nil
}
func
(
c
*
channelClient
)
Quit
(
ctx
context
.
Context
,
head
*
pb
.
PBGameQuit
)
(
*
types
.
UnsignTx
,
error
)
{
val
:=
&
pb
.
PBGameAction
{
Ty
:
pb
.
PBGameActionQuit
,
Value
:
&
pb
.
PBGameAction_Quit
{
Quit
:
head
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
pb
.
PokerBullX
,
types
.
Encode
(
val
))
if
err
!=
nil
{
return
nil
,
err
}
data
:=
types
.
Encode
(
tx
)
return
&
types
.
UnsignTx
{
Data
:
data
},
nil
}
func
(
c
*
channelClient
)
Show
(
ctx
context
.
Context
,
head
*
pb
.
PBGameQuery
)
(
*
types
.
UnsignTx
,
error
)
{
val
:=
&
pb
.
PBGameAction
{
Ty
:
pb
.
PBGameActionQuery
,
Value
:
&
pb
.
PBGameAction_Query
{
Query
:
head
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
pb
.
PokerBullX
,
types
.
Encode
(
val
))
if
err
!=
nil
{
return
nil
,
err
}
data
:=
types
.
Encode
(
tx
)
return
&
types
.
UnsignTx
{
Data
:
data
},
nil
}
plugin/dapp/pokerbull/rpc/types.go
deleted
100644 → 0
View file @
62cbbdc6
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
rpc
import
(
"github.com/33cn/chain33/rpc/types"
)
// Jrpc jrpc句柄
type
Jrpc
struct
{
cli
*
channelClient
}
// Grpc grpc句柄
type
Grpc
struct
{
*
channelClient
}
type
channelClient
struct
{
types
.
ChannelClient
}
// Init 初始化rpc
func
Init
(
name
string
,
s
types
.
RPCServer
)
{
cli
:=
&
channelClient
{}
grpc
:=
&
Grpc
{
channelClient
:
cli
}
cli
.
Init
(
name
,
s
,
&
Jrpc
{
cli
:
cli
},
grpc
)
}
plugin/dapp/pokerbull/types/const.go
View file @
afbd0de6
...
...
@@ -4,6 +4,8 @@
package
types
import
"github.com/33cn/chain33/types"
//game action ty
const
(
PBGameActionStart
=
iota
+
1
...
...
@@ -48,4 +50,35 @@ const (
FuncNameQueryGameByAddr
=
"QueryGameByAddr"
// FuncNameQueryGameByStatus 根据status查询game
FuncNameQueryGameByStatus
=
"QueryGameByStatus"
// FuncNameQueryGameByRound 查询某一回合游戏结果
FuncNameQueryGameByRound
=
"QueryGameByRound"
// CreateStartTx 创建开始交易
CreateStartTx
=
"Start"
// CreateContinueTx 创建继续交易
CreateContinueTx
=
"Continue"
// CreatequitTx 创建退出交易
CreatequitTx
=
"Quit"
)
const
(
// ListDESC 降序
ListDESC
=
int32
(
0
)
// DefaultCount 默认一次取多少条记录
DefaultCount
=
int32
(
20
)
// MaxPlayerNum 最大玩家数
MaxPlayerNum
=
5
// MinPlayValue 最小赌注
MinPlayValue
=
10
*
types
.
Coin
// DefaultStyle 默认游戏类型
DefaultStyle
=
PlayStyleDefault
// PlatformAddress 平台地址
PlatformAddress
=
"1PHtChNt3UcfssR7v7trKSk3WJtAWjKjjX"
// PlatformFee 平台佣金
PlatformFee
=
int64
(
0.005
*
float64
(
types
.
Coin
))
// DeveloperAddress 开发着地址
DeveloperAddress
=
"1D6RFZNp2rh6QdbcZ1d7RWuBUz61We6SD7"
// DeveloperFee 开发者佣金
DeveloperFee
=
int64
(
0.005
*
float64
(
types
.
Coin
))
// WinnerReturn 赢家回报率
WinnerReturn
=
types
.
Coin
-
DeveloperFee
)
plugin/dapp/pokerbull/types/pokerbull.pb.go
View file @
afbd0de6
This diff is collapsed.
Click to expand it.
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