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
fddd06f8
Commit
fddd06f8
authored
Dec 14, 2018
by
vipwzw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hello
parent
de416732
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
100 deletions
+35
-100
pokerbulldb.go
plugin/dapp/pokerbull/executor/pokerbulldb.go
+5
-4
query.go
plugin/dapp/pokerbull/executor/query.go
+0
-1
jrpc_channel_test.go
plugin/dapp/pokerbull/rpc/jrpc_channel_test.go
+27
-13
const.go
plugin/dapp/pokerbull/types/const.go
+3
-3
types.go
plugin/dapp/pokerbull/types/types.go
+0
-79
No files found.
plugin/dapp/pokerbull/executor/pokerbulldb.go
View file @
fddd06f8
...
...
@@ -64,14 +64,14 @@ func Key(id string) (key []byte) {
func
readGame
(
db
dbm
.
KV
,
id
string
)
(
*
pkt
.
PokerBull
,
error
)
{
data
,
err
:=
db
.
Get
(
Key
(
id
))
if
err
!=
nil
{
logger
.
Error
(
"query data have err:"
,
err
.
Error
()
)
logger
.
Error
(
"query data have err:"
,
"err"
,
err
)
return
nil
,
err
}
var
game
pkt
.
PokerBull
//decode
err
=
types
.
Decode
(
data
,
&
game
)
if
err
!=
nil
{
logger
.
Error
(
"decode game have err:"
,
err
.
Error
()
)
logger
.
Error
(
"decode game have err:"
,
"err"
,
err
)
return
nil
,
err
}
return
&
game
,
nil
...
...
@@ -102,7 +102,6 @@ func getGameListByAddr(db dbm.Lister, addr string, index int64) (types.Message,
if
err
!=
nil
{
return
nil
,
err
}
var
gameIds
[]
*
pkt
.
PBGameRecord
for
_
,
value
:=
range
values
{
var
record
pkt
.
PBGameRecord
...
...
@@ -112,7 +111,9 @@ func getGameListByAddr(db dbm.Lister, addr string, index int64) (types.Message,
}
gameIds
=
append
(
gameIds
,
&
record
)
}
if
len
(
gameIds
)
==
0
{
return
nil
,
types
.
ErrNotFound
}
return
&
pkt
.
PBGameRecords
{
Records
:
gameIds
},
nil
}
...
...
plugin/dapp/pokerbull/executor/query.go
View file @
fddd06f8
...
...
@@ -29,7 +29,6 @@ func (g *PokerBull) Query_QueryGameByAddr(in *pkt.QueryPBGameInfo) (types.Messag
if
err
!=
nil
{
return
nil
,
err
}
return
gameIds
,
nil
}
...
...
plugin/dapp/pokerbull/rpc/jrpc_channel_test.go
View file @
fddd06f8
...
...
@@ -5,7 +5,7 @@
package
rpc_test
import
(
"
strings
"
"
fmt
"
"testing"
commonlog
"github.com/33cn/chain33/common/log"
...
...
@@ -41,51 +41,65 @@ 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
:
testQueryGameByIDs
},
{
fn
:
testQueryGameByStatus
},
{
fn
:
testQueryGameByRound
},
}
for
index
,
testCase
:=
range
testCases
{
err
:=
testCase
.
fn
(
t
,
jrpcClient
)
if
err
==
nil
{
continue
}
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
)
}
assert
.
Equal
(
t
,
err
,
types
.
ErrNotFound
,
fmt
.
Sprint
(
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
{
payload
:=
&
pty
.
PBGameStart
{
Value
:
123
}
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pty
.
PokerBullX
),
ActionName
:
pty
.
CreateStartTx
,
Payload
:
[]
byte
(
""
),
Payload
:
types
.
MustPBToJSON
(
payload
),
}
var
res
string
return
jrpc
.
Call
(
"Chain33.CreateTransaction"
,
params
,
&
res
)
}
func
testContinueRawTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
payload
:=
&
pty
.
PBGameContinue
{
GameId
:
"123"
}
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pty
.
PokerBullX
),
ActionName
:
pty
.
CreateContinueTx
,
Payload
:
[]
byte
(
""
),
Payload
:
types
.
MustPBToJSON
(
payload
),
}
var
res
string
return
jrpc
.
Call
(
"Chain33.CreateTransaction"
,
params
,
&
res
)
}
func
testQuitRawTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
payload
:=
&
pty
.
PBGameQuit
{
GameId
:
"123"
}
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pty
.
PokerBullX
),
ActionName
:
pty
.
CreatequitTx
,
Payload
:
[]
byte
(
""
),
Payload
:
types
.
MustPBToJSON
(
payload
),
}
var
res
string
return
jrpc
.
Call
(
"Chain33.CreateTransaction"
,
params
,
&
res
)
}
...
...
plugin/dapp/pokerbull/types/const.go
View file @
fddd06f8
...
...
@@ -53,11 +53,11 @@ const (
// FuncNameQueryGameByRound 查询某一回合游戏结果
FuncNameQueryGameByRound
=
"QueryGameByRound"
// CreateStartTx 创建开始交易
CreateStartTx
=
"
CreateStartTx
"
CreateStartTx
=
"
Start
"
// CreateContinueTx 创建继续交易
CreateContinueTx
=
"C
reateContinueTx
"
CreateContinueTx
=
"C
ontinue
"
// CreatequitTx 创建退出交易
CreatequitTx
=
"
CreatequitTx
"
CreatequitTx
=
"
Quit
"
)
const
(
...
...
plugin/dapp/pokerbull/types/types.go
View file @
fddd06f8
...
...
@@ -7,9 +7,6 @@ package types
import
(
"reflect"
"encoding/json"
"errors"
log
"github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/types"
)
...
...
@@ -66,79 +63,3 @@ func (t *PokerBullType) GetLogMap() map[int64]*types.LogInfo {
TyLogPBGameQuery
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptPBGame
{}),
Name
:
"TyLogPBGameQuery"
},
}
}
// CreateTx method
func
(
t
*
PokerBullType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
llog
.
Debug
(
"pokerbull.CreateTx"
,
"action"
,
action
)
if
action
==
CreateStartTx
{
var
param
PBGameStart
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawPBStartTx
(
&
param
)
}
else
if
action
==
CreateContinueTx
{
var
param
PBGameContinue
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawPBContinueTx
(
&
param
)
}
else
if
action
==
CreatequitTx
{
var
param
PBGameQuit
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawPBQuitTx
(
&
param
)
}
return
nil
,
types
.
ErrNotSupport
}
// CreateRawPBStartTx method
func
CreateRawPBStartTx
(
head
*
PBGameStart
)
(
*
types
.
Transaction
,
error
)
{
if
head
.
PlayerNum
>
MaxPlayerNum
{
return
nil
,
errors
.
New
(
"Player number should be maximum 5"
)
}
val
:=
&
PBGameAction
{
Ty
:
PBGameActionStart
,
Value
:
&
PBGameAction_Start
{
Start
:
head
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
PokerBullX
),
types
.
Encode
(
val
))
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawPBContinueTx method
func
CreateRawPBContinueTx
(
head
*
PBGameContinue
)
(
*
types
.
Transaction
,
error
)
{
val
:=
&
PBGameAction
{
Ty
:
PBGameActionContinue
,
Value
:
&
PBGameAction_Continue
{
Continue
:
head
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
PokerBullX
),
types
.
Encode
(
val
))
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawPBQuitTx method
func
CreateRawPBQuitTx
(
head
*
PBGameQuit
)
(
*
types
.
Transaction
,
error
)
{
val
:=
&
PBGameAction
{
Ty
:
PBGameActionQuit
,
Value
:
&
PBGameAction_Quit
{
Quit
:
head
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
types
.
ExecName
(
PokerBullX
),
types
.
Encode
(
val
))
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment