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
d6f96f30
Commit
d6f96f30
authored
Dec 21, 2018
by
张振华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor
parent
5407d79b
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
244 additions
and
637 deletions
+244
-637
game.go
plugin/dapp/guess/commands/game.go
+42
-63
plugin.go
plugin/dapp/guess/plugin.go
+0
-2
jrpc.go
plugin/dapp/guess/rpc/jrpc.go
+0
-87
jrpc_channel_test.go
plugin/dapp/guess/rpc/jrpc_channel_test.go
+160
-0
rpc.go
plugin/dapp/guess/rpc/rpc.go
+0
-174
types.go
plugin/dapp/guess/rpc/types.go
+0
-30
const.go
plugin/dapp/guess/types/const.go
+39
-17
tx.go
plugin/dapp/guess/types/tx.go
+0
-48
types.go
plugin/dapp/guess/types/types.go
+2
-215
const.go
plugin/dapp/pokerbull/types/const.go
+1
-1
No files found.
plugin/dapp/guess/commands/game.go
View file @
d6f96f30
...
...
@@ -5,6 +5,7 @@
package
commands
import
(
"fmt"
"strings"
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
...
...
@@ -53,26 +54,14 @@ func addGuessStartFlags(cmd *cobra.Command) {
cmd
.
MarkFlagRequired
(
"options"
)
cmd
.
Flags
()
.
StringP
(
"category"
,
"c"
,
"default"
,
"options"
)
cmd
.
Flags
()
.
Int64P
(
"maxBetHeight"
,
"m"
,
0
,
"max height to bet, after this bet is forbidden"
)
cmd
.
Flags
()
.
Int64P
(
"maxBetsOneTime"
,
"s"
,
10000
,
"max bets one time"
)
//cmd.MarkFlagRequired("maxBets")
cmd
.
Flags
()
.
Int64P
(
"maxBetsNumber"
,
"n"
,
100000
,
"max bets number"
)
//cmd.MarkFlagRequired("maxBetsNumber")
cmd
.
Flags
()
.
Int64P
(
"devFeeFactor"
,
"d"
,
0
,
"dev fee factor, unit: 1/1000"
)
cmd
.
Flags
()
.
StringP
(
"devFeeAddr"
,
"f"
,
""
,
"dev address to receive share"
)
cmd
.
Flags
()
.
Int64P
(
"platFeeFactor"
,
"p"
,
0
,
"plat fee factor, unit: 1/1000"
)
cmd
.
Flags
()
.
StringP
(
"platFeeAddr"
,
"q"
,
""
,
"plat address to receive share"
)
cmd
.
Flags
()
.
Int64P
(
"expireHeight"
,
"e"
,
0
,
"expire height of the game, after this any addr can abort it"
)
cmd
.
Flags
()
.
Float64P
(
"fee"
,
"g"
,
0.01
,
"tx fee"
)
}
func
guessStart
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
...
...
@@ -88,26 +77,18 @@ func guessStart(cmd *cobra.Command, args []string) {
platFeeFactor
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"platFeeFactor"
)
platFeeAddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"platFeeAddr"
)
expireHeight
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"expireHeight"
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
params
:=
&
pkt
.
GuessStartTxReq
{
Topic
:
topic
,
Options
:
options
,
Category
:
category
,
MaxBetHeight
:
maxBetHeight
,
MaxBetsOneTime
:
maxBetsOneTime
*
1e8
,
MaxBetsNumber
:
maxBetsNumber
*
1e8
,
DevFeeFactor
:
devFeeFactor
,
DevFeeAddr
:
devFeeAddr
,
PlatFeeFactor
:
platFeeFactor
,
PlatFeeAddr
:
platFeeAddr
,
ExpireHeight
:
expireHeight
,
Fee
:
int64
(
fee
*
float64
(
1e8
)),
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
,
Payload
:
[]
byte
(
payload
),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"
guess.GuessStartTx
"
,
params
,
&
res
)
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"
Chain33.CreateTransaction
"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
//GuessBetRawTxCmd 构造Guess合约的bet原始交易(未签名)的命令行
...
...
@@ -128,7 +109,6 @@ func addGuessBetFlags(cmd *cobra.Command) {
cmd
.
MarkFlagRequired
(
"option"
)
cmd
.
Flags
()
.
Int64P
(
"betsNumber"
,
"b"
,
1
,
"bets number for one option in a guess game"
)
cmd
.
MarkFlagRequired
(
"betsNumber"
)
cmd
.
Flags
()
.
Float64P
(
"fee"
,
"f"
,
0.01
,
"tx fee"
)
}
func
guessBet
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
...
...
@@ -136,17 +116,16 @@ func guessBet(cmd *cobra.Command, args []string) {
gameID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"gameId"
)
option
,
_
:=
cmd
.
Flags
()
.
GetString
(
"option"
)
betsNumber
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"betsNumber"
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
pa
rams
:=
&
pkt
.
GuessBetTxReq
{
GameID
:
gameID
,
Option
:
option
,
Bets
:
betsNumber
,
Fee
:
int64
(
fee
*
float64
(
1e8
)
),
pa
yload
:=
fmt
.
Sprintf
(
"{
\"
gameID
\"
:
\"
%s
\"
,
\"
option
\"
:
\"
%s
\"
,
\"
betsNum
\"
:%d}"
,
gameID
,
option
,
betsNumber
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
GuessX
)
,
ActionName
:
pkt
.
CreateBetTx
,
Payload
:
[]
byte
(
payload
),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"
guess.GuessBetTx
"
,
params
,
&
res
)
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"
Chain33.CreateTransaction
"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
...
...
@@ -170,15 +149,16 @@ func addGuessStopBetFlags(cmd *cobra.Command) {
func
guessStopBet
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
gameID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"gameId"
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
params
:=
&
pkt
.
GuessStopBetTxReq
{
GameID
:
gameID
,
Fee
:
int64
(
fee
*
float64
(
1e8
)),
payload
:=
fmt
.
Sprintf
(
"{
\"
gameID
\"
:
\"
%s
\"
}"
,
gameID
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
GuessX
),
ActionName
:
pkt
.
CreateStopBetTx
,
Payload
:
[]
byte
(
payload
),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"
guess.GuessStopBetTx
"
,
params
,
&
res
)
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"
Chain33.CreateTransaction
"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
...
...
@@ -196,20 +176,21 @@ func GuessAbortRawTxCmd() *cobra.Command {
func
addGuessAbortFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"gameId"
,
"g"
,
""
,
"game Id"
)
cmd
.
MarkFlagRequired
(
"gameId"
)
cmd
.
Flags
()
.
Float64P
(
"fee"
,
"f"
,
0.01
,
"tx fee"
)
}
func
guessAbort
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
gameID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"gameId"
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
params
:=
&
pkt
.
GuessAbortTxReq
{
GameID
:
gameID
,
Fee
:
int64
(
fee
*
float64
(
1e8
)),
payload
:=
fmt
.
Sprintf
(
"{
\"
gameID
\"
:
\"
%s
\"
}"
,
gameID
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
GuessX
),
ActionName
:
pkt
.
CreateAbortTx
,
Payload
:
[]
byte
(
payload
),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"
guess.GuessAbortTx
"
,
params
,
&
res
)
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"
Chain33.CreateTransaction
"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
...
...
@@ -230,24 +211,22 @@ func addGuessPublishFlags(cmd *cobra.Command) {
cmd
.
Flags
()
.
StringP
(
"result"
,
"r"
,
""
,
"result of a guess game"
)
cmd
.
MarkFlagRequired
(
"result"
)
cmd
.
Flags
()
.
Float64P
(
"fee"
,
"f"
,
0.01
,
"tx fee"
)
}
func
guessPublish
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
gameID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"gameId"
)
result
,
_
:=
cmd
.
Flags
()
.
GetString
(
"result"
)
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
params
:=
&
pkt
.
GuessPublishTxReq
{
GameID
:
gameID
,
Result
:
result
,
Fee
:
int64
(
fee
*
float64
(
1e8
)),
payload
:=
fmt
.
Sprintf
(
"{
\"
gameID
\"
:
\"
%s
\"
,
\"
result
\"
:
\"
%s
\"
}"
,
gameID
,
result
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
GuessX
),
ActionName
:
pkt
.
CreatePublishTx
,
Payload
:
[]
byte
(
payload
),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"
guess.GuessPublishTx
"
,
params
,
&
res
)
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"
Chain33.CreateTransaction
"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
...
...
@@ -302,7 +281,7 @@ func guessQuery(cmd *cobra.Command, args []string) {
req
:=
&
pkt
.
QueryGuessGameInfos
{
GameIDs
:
gameIds
,
}
params
.
FuncName
=
pkt
.
FuncName
_
QueryGamesByIds
params
.
FuncName
=
pkt
.
FuncNameQueryGamesByIds
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
ReplyGuessGameInfos
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
...
...
@@ -312,7 +291,7 @@ func guessQuery(cmd *cobra.Command, args []string) {
req
:=
&
pkt
.
QueryGuessGameInfo
{
GameID
:
gameID
,
}
params
.
FuncName
=
pkt
.
FuncName
_
QueryGameById
params
.
FuncName
=
pkt
.
FuncNameQueryGameById
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
ReplyGuessGameInfo
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
...
...
@@ -323,7 +302,7 @@ func guessQuery(cmd *cobra.Command, args []string) {
Addr
:
addr
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncName
_
QueryGameByAddr
params
.
FuncName
=
pkt
.
FuncNameQueryGameByAddr
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
...
...
@@ -334,7 +313,7 @@ func guessQuery(cmd *cobra.Command, args []string) {
Status
:
status
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncName
_
QueryGameByStatus
params
.
FuncName
=
pkt
.
FuncNameQueryGameByStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
...
...
@@ -345,7 +324,7 @@ func guessQuery(cmd *cobra.Command, args []string) {
AdminAddr
:
adminAddr
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncName
_
QueryGameByAdminAddr
params
.
FuncName
=
pkt
.
FuncNameQueryGameByAdminAddr
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
...
...
@@ -357,7 +336,7 @@ func guessQuery(cmd *cobra.Command, args []string) {
Status
:
status
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncName
_
QueryGameByAddrStatus
params
.
FuncName
=
pkt
.
FuncNameQueryGameByAddrStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
...
...
@@ -369,7 +348,7 @@ func guessQuery(cmd *cobra.Command, args []string) {
Status
:
status
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncName
_
QueryGameByAdminStatus
params
.
FuncName
=
pkt
.
FuncNameQueryGameByAdminStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
...
...
@@ -381,7 +360,7 @@ func guessQuery(cmd *cobra.Command, args []string) {
Status
:
status
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncName
_
QueryGameByCategoryStatus
params
.
FuncName
=
pkt
.
FuncNameQueryGameByCategoryStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
GuessGameRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
...
...
plugin/dapp/guess/plugin.go
View file @
d6f96f30
...
...
@@ -8,7 +8,6 @@ import (
"github.com/33cn/chain33/pluginmgr"
"github.com/33cn/plugin/plugin/dapp/guess/commands"
"github.com/33cn/plugin/plugin/dapp/guess/executor"
"github.com/33cn/plugin/plugin/dapp/guess/rpc"
"github.com/33cn/plugin/plugin/dapp/guess/types"
)
...
...
@@ -18,6 +17,5 @@ func init() {
ExecName
:
executor
.
GetName
(),
Exec
:
executor
.
Init
,
Cmd
:
commands
.
GuessCmd
,
RPC
:
rpc
.
Init
,
})
}
plugin/dapp/guess/rpc/jrpc.go
deleted
100644 → 0
View file @
5407d79b
// 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/guess/types"
)
//GuessStartTx 构造start原始交易
func
(
c
*
Jrpc
)
GuessStartTx
(
parm
*
pb
.
GuessStartTxReq
,
result
*
interface
{})
error
{
if
parm
==
nil
{
return
types
.
ErrInvalidParam
}
reply
,
err
:=
c
.
cli
.
GuessStart
(
context
.
Background
(),
parm
)
if
err
!=
nil
{
return
err
}
*
result
=
hex
.
EncodeToString
(
reply
.
Data
)
return
nil
}
//GuessBetTx 构造bet原始交易
func
(
c
*
Jrpc
)
GuessBetTx
(
parm
*
pb
.
GuessBetTxReq
,
result
*
interface
{})
error
{
if
parm
==
nil
{
return
types
.
ErrInvalidParam
}
reply
,
err
:=
c
.
cli
.
GuessBet
(
context
.
Background
(),
parm
)
if
err
!=
nil
{
return
err
}
*
result
=
hex
.
EncodeToString
(
reply
.
Data
)
return
nil
}
//GuessStopBetTx 构造stopBet原始交易
func
(
c
*
Jrpc
)
GuessStopBetTx
(
parm
*
pb
.
GuessStopBetTxReq
,
result
*
interface
{})
error
{
if
parm
==
nil
{
return
types
.
ErrInvalidParam
}
reply
,
err
:=
c
.
cli
.
GuessStopBet
(
context
.
Background
(),
parm
)
if
err
!=
nil
{
return
err
}
*
result
=
hex
.
EncodeToString
(
reply
.
Data
)
return
nil
}
//GuessAbortTx 构造abort原始交易
func
(
c
*
Jrpc
)
GuessAbortTx
(
parm
*
pb
.
GuessAbortTxReq
,
result
*
interface
{})
error
{
if
parm
==
nil
{
return
types
.
ErrInvalidParam
}
reply
,
err
:=
c
.
cli
.
GuessAbort
(
context
.
Background
(),
parm
)
if
err
!=
nil
{
return
err
}
*
result
=
hex
.
EncodeToString
(
reply
.
Data
)
return
nil
}
//GuessPublishTx 构造publish原始交易
func
(
c
*
Jrpc
)
GuessPublishTx
(
parm
*
pb
.
GuessPublishTxReq
,
result
*
interface
{})
error
{
if
parm
==
nil
{
return
types
.
ErrInvalidParam
}
reply
,
err
:=
c
.
cli
.
GuessPublish
(
context
.
Background
(),
parm
)
if
err
!=
nil
{
return
err
}
*
result
=
hex
.
EncodeToString
(
reply
.
Data
)
return
nil
}
plugin/dapp/guess/rpc/jrpc_channel_test.go
0 → 100644
View file @
d6f96f30
// 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_test
import
(
"fmt"
"testing"
commonlog
"github.com/33cn/chain33/common/log"
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util/testnode"
pty
"github.com/33cn/plugin/plugin/dapp/pokerbull/types"
"github.com/stretchr/testify/assert"
_
"github.com/33cn/chain33/system"
_
"github.com/33cn/plugin/plugin"
)
func
init
()
{
commonlog
.
SetLogLevel
(
"error"
)
}
func
TestJRPCChannel
(
t
*
testing
.
T
)
{
// 启动RPCmocker
mocker
:=
testnode
.
New
(
"--notset--"
,
nil
)
defer
func
()
{
mocker
.
Close
()
}()
mocker
.
Listen
()
jrpcClient
:=
mocker
.
GetJSONC
()
assert
.
NotNil
(
t
,
jrpcClient
)
testCases
:=
[]
struct
{
fn
func
(
*
testing
.
T
,
*
jsonclient
.
JSONClient
)
error
}{
{
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
)
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
:
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
:
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
:
types
.
MustPBToJSON
(
payload
),
}
var
res
string
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
=
pty
.
PokerBullX
params
.
FuncName
=
pty
.
FuncNameQueryGameByID
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
pty
.
ReplyPBGame
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
}
func
testQueryGameByAddr
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
pty
.
QueryPBGameInfo
{}
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/guess/rpc/rpc.go
deleted
100644 → 0
View file @
5407d79b
// 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/common/address"
"github.com/33cn/chain33/types"
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
,
Options
:
parm
.
Options
,
Category
:
parm
.
Category
,
MaxBetHeight
:
parm
.
MaxBetHeight
,
MaxBetsOneTime
:
parm
.
MaxBetsOneTime
,
MaxBetsNumber
:
parm
.
MaxBetsNumber
,
DevFeeFactor
:
parm
.
DevFeeFactor
,
DevFeeAddr
:
parm
.
DevFeeAddr
,
PlatFeeFactor
:
parm
.
PlatFeeFactor
,
PlatFeeAddr
:
parm
.
PlatFeeAddr
,
ExpireHeight
:
parm
.
ExpireHeight
,
}
val
:=
&
pb
.
GuessGameAction
{
Ty
:
pb
.
GuessGameActionStart
,
Value
:
&
pb
.
GuessGameAction_Start
{
Start
:
v
},
}
name
:=
types
.
ExecName
(
pb
.
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
pb
.
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
data
:=
types
.
Encode
(
tx
)
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
,
Option
:
parm
.
Option
,
BetsNum
:
parm
.
Bets
,
}
val
:=
&
pb
.
GuessGameAction
{
Ty
:
pb
.
GuessGameActionBet
,
Value
:
&
pb
.
GuessGameAction_Bet
{
Bet
:
v
},
}
name
:=
types
.
ExecName
(
pb
.
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
pb
.
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
data
:=
types
.
Encode
(
tx
)
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
,
}
val
:=
&
pb
.
GuessGameAction
{
Ty
:
pb
.
GuessGameActionStopBet
,
Value
:
&
pb
.
GuessGameAction_StopBet
{
StopBet
:
v
},
}
name
:=
types
.
ExecName
(
pb
.
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
pb
.
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
data
:=
types
.
Encode
(
tx
)
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
,
}
val
:=
&
pb
.
GuessGameAction
{
Ty
:
pb
.
GuessGameActionAbort
,
Value
:
&
pb
.
GuessGameAction_Abort
{
Abort
:
v
},
}
name
:=
types
.
ExecName
(
pb
.
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
pb
.
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
data
:=
types
.
Encode
(
tx
)
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
,
Result
:
parm
.
Result
,
}
val
:=
&
pb
.
GuessGameAction
{
Ty
:
pb
.
GuessGameActionPublish
,
Value
:
&
pb
.
GuessGameAction_Publish
{
Publish
:
v
},
}
name
:=
types
.
ExecName
(
pb
.
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
pb
.
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
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
.
GuessGameQuery
)
(
*
types
.
UnsignTx
,
error
)
{
val
:=
&
pb
.
GuessGameAction
{
Ty
:
pb
.
GuessGameActionQuery
,
Value
:
&
pb
.
GuessGameAction_Query
{
Query
:
head
},
}
tx
,
err
:=
types
.
CreateFormatTx
(
pb
.
GuessX
,
types
.
Encode
(
val
))
if
err
!=
nil
{
return
nil
,
err
}
data
:=
types
.
Encode
(
tx
)
return
&
types
.
UnsignTx
{
Data
:
data
},
nil
}
plugin/dapp/guess/rpc/types.go
deleted
100644 → 0
View file @
5407d79b
// 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 struct
type
Jrpc
struct
{
cli
*
channelClient
}
//Grpc struct
type
Grpc
struct
{
*
channelClient
}
type
channelClient
struct
{
types
.
ChannelClient
}
//Init method
func
Init
(
name
string
,
s
types
.
RPCServer
)
{
cli
:=
&
channelClient
{}
grpc
:=
&
Grpc
{
channelClient
:
cli
}
cli
.
Init
(
name
,
s
,
&
Jrpc
{
cli
:
cli
},
grpc
)
}
plugin/dapp/guess/types/const.go
View file @
d6f96f30
...
...
@@ -40,28 +40,50 @@ const (
//建议用github的组织名称,或者用户名字开头, 再加上自己的插件的名字
//如果发生重名,可以通过配置文件修改这些名字
var
(
JRPCName
=
"guess"
GuessX
=
"guess"
ExecerGuess
=
[]
byte
(
GuessX
)
)
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"
//FuncNameQueryGamesByIds func name
FuncNameQueryGamesByIds
=
"QueryGamesByIds"
//FuncNameQueryGameById func name
FuncNameQueryGameById
=
"QueryGameById"
//FuncNameQueryGameByAddr func name
FuncNameQueryGameByAddr
=
"QueryGamesByAddr"
//FuncNameQueryGameByStatus func name
FuncNameQueryGameByStatus
=
"QueryGamesByStatus"
//FuncNameQueryGameByAdminAddr func name
FuncNameQueryGameByAdminAddr
=
"QueryGamesByAdminAddr"
//FuncNameQueryGameByAddrStatus func name
FuncNameQueryGameByAddrStatus
=
"QueryGamesByAddrStatus"
//FuncNameQueryGameByAdminStatus func name
FuncNameQueryGameByAdminStatus
=
"QueryGamesByAdminStatus"
//FuncNameQueryGameByCategoryStatus func name
FuncNameQueryGameByCategoryStatus
=
"QueryGamesByCategoryStatus"
//CreateStartTx 创建开始交易
CreateStartTx
=
"Start"
//CreateBetTx 创建下注交易
CreateBetTx
=
"Bet"
//CreateStopBetTx 创建停止下注交易
CreateStopBetTx
=
"StopBet"
//CreatePublishTx 创建公布结果交易
CreatePublishTx
=
"Publish"
//CreateAbortTx 创建撤销游戏交易
CreateAbortTx
=
"Abort"
)
const
(
...
...
plugin/dapp/guess/types/tx.go
deleted
100644 → 0
View file @
5407d79b
// 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
types
//GuessGameStartTx struct
type
GuessGameStartTx
struct
{
Topic
string
`json:"topic,omitempty"`
Options
string
`json:"options,omitempty"`
Category
string
`json:"category,omitempty"`
MaxBetHeight
int64
`json:"maxHeight,omitempty"`
MaxBets
int64
`json:"maxBets,omitempty"`
MaxBetsNumber
int64
`json:"maxBetsNumber,omitempty"`
DevFeeFactor
int64
`json:"devFeeFactor,omitempty"`
DevFeeAddr
string
`json:"devFeeAddr,omitempty"`
PlatFeeFactor
int64
`json:"platFeeFactor,omitempty"`
PlatFeeAddr
string
`json:"platFeeAddr,omitempty"`
ExpireHeight
int64
`json:"expireHeight,omitempty"`
Fee
int64
`json:"fee,omitempty"`
}
//GuessGameBetTx struct
type
GuessGameBetTx
struct
{
GameID
string
`json:"gameId,omitempty"`
Option
string
`json:"option,omitempty"`
BetsNum
int64
`json:"betsNum,omitempty"`
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 @
d6f96f30
...
...
@@ -5,11 +5,8 @@
package
types
import
(
"encoding/json"
"reflect"
"github.com/33cn/chain33/common/address"
log
"github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/types"
)
...
...
@@ -64,215 +61,4 @@ func (t *GuessType) GetLogMap() map[int64]*types.LogInfo {
TyLogGuessGamePublish
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptGuessGame
{}),
Name
:
"TyLogGuessGamePublish"
},
TyLogGuessGameTimeout
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptGuessGame
{}),
Name
:
"TyLogGuessGameTimeout"
},
}
}
// CreateTx method
func
(
t
*
GuessType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
llog
.
Debug
(
"Guess.CreateTx"
,
"action"
,
action
)
if
action
==
"GuessStart"
{
var
param
GuessGameStartTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx.GuessStart"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawGuessStartTx
(
&
param
)
}
else
if
action
==
"GuessBet"
{
var
param
GuessGameBetTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx.GuessBet"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawGuessBetTx
(
&
param
)
}
else
if
action
==
"GuessStopBet"
{
var
param
GuessGameStopBetTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx.GuessStopBet"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawGuessStopBetTx
(
&
param
)
}
else
if
action
==
"GuessPublish"
{
var
param
GuessGamePublishTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx.GuessPublish"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawGuessPublishTx
(
&
param
)
}
else
if
action
==
"GuessAbort"
{
var
param
GuessGameAbortTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx.GuessAbort"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawGuessAbortTx
(
&
param
)
}
return
nil
,
types
.
ErrNotSupport
}
// CreateRawGuessStartTx method
func
CreateRawGuessStartTx
(
parm
*
GuessGameStartTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawGuessStartTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
GuessGameStart
{
Topic
:
parm
.
Topic
,
Options
:
parm
.
Options
,
Category
:
parm
.
Category
,
MaxBetHeight
:
parm
.
MaxBetHeight
,
MaxBetsOneTime
:
parm
.
MaxBets
,
MaxBetsNumber
:
parm
.
MaxBetsNumber
,
DevFeeFactor
:
parm
.
DevFeeFactor
,
DevFeeAddr
:
parm
.
DevFeeAddr
,
PlatFeeFactor
:
parm
.
PlatFeeFactor
,
PlatFeeAddr
:
parm
.
PlatFeeAddr
,
ExpireHeight
:
parm
.
ExpireHeight
,
}
val
:=
&
GuessGameAction
{
Ty
:
GuessGameActionStart
,
Value
:
&
GuessGameAction_Start
{
Start
:
v
},
}
llog
.
Info
(
"CreateRawGuessStartTx"
,
"Ty"
,
val
.
Ty
,
"GuessGameActionStart"
,
GuessGameActionStart
)
name
:=
types
.
ExecName
(
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawGuessBetTx method
func
CreateRawGuessBetTx
(
parm
*
GuessGameBetTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawGuessBet"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
GuessGameBet
{
GameID
:
parm
.
GameID
,
Option
:
parm
.
Option
,
BetsNum
:
parm
.
BetsNum
,
}
val
:=
&
GuessGameAction
{
Ty
:
GuessGameActionBet
,
Value
:
&
GuessGameAction_Bet
{
Bet
:
v
},
}
name
:=
types
.
ExecName
(
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawGuessStopBetTx method
func
CreateRawGuessStopBetTx
(
parm
*
GuessGameStopBetTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawGuessBet"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
GuessGameStopBet
{
GameID
:
parm
.
GameID
,
}
val
:=
&
GuessGameAction
{
Ty
:
GuessGameActionStopBet
,
Value
:
&
GuessGameAction_StopBet
{
StopBet
:
v
},
}
name
:=
types
.
ExecName
(
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawGuessPublishTx method
func
CreateRawGuessPublishTx
(
parm
*
GuessGamePublishTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawGuessPublish"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
GuessGamePublish
{
GameID
:
parm
.
GameID
,
Result
:
parm
.
Result
,
}
val
:=
&
GuessGameAction
{
Ty
:
GuessGameActionPublish
,
Value
:
&
GuessGameAction_Publish
{
Publish
:
v
},
}
name
:=
types
.
ExecName
(
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawGuessAbortTx method
func
CreateRawGuessAbortTx
(
parm
*
GuessGameAbortTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawGuessAbortTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
GuessGameAbort
{
GameID
:
parm
.
GameID
,
}
val
:=
&
GuessGameAction
{
Ty
:
GuessGameActionAbort
,
Value
:
&
GuessGameAction_Abort
{
Abort
:
v
},
}
name
:=
types
.
ExecName
(
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
}
\ No newline at end of file
plugin/dapp/pokerbull/types/const.go
View file @
d6f96f30
...
...
@@ -53,7 +53,7 @@ const (
// FuncNameQueryGameByRound 查询某一回合游戏结果
FuncNameQueryGameByRound
=
"QueryGameByRound"
// CreateStartTx 创建开始交易
CreateStartTx
=
"Start"
CreateStartTx
=
"Start"
// CreateContinueTx 创建继续交易
CreateContinueTx
=
"Continue"
// CreatequitTx 创建退出交易
...
...
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