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
4a9c662c
Commit
4a9c662c
authored
Dec 17, 2018
by
张振华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor
parent
96391f7b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
0 deletions
+80
-0
game.go
plugin/dapp/guess/commands/game.go
+33
-0
guess.proto
plugin/dapp/guess/proto/guess.proto
+7
-0
jrpc.go
plugin/dapp/guess/rpc/jrpc.go
+14
-0
rpc.go
plugin/dapp/guess/rpc/rpc.go
+26
-0
guess.pb.go
plugin/dapp/guess/types/guess.pb.go
+0
-0
No files found.
plugin/dapp/guess/commands/game.go
View file @
4a9c662c
...
...
@@ -26,6 +26,7 @@ func GuessCmd() *cobra.Command {
GuessAbortRawTxCmd
(),
GuessQueryRawTxCmd
(),
GuessPublishRawTxCmd
(),
GuessStopBetRawTxCmd
(),
)
return
cmd
...
...
@@ -145,6 +146,38 @@ func guessBet(cmd *cobra.Command, args []string) {
ctx
.
RunWithoutMarshal
()
}
func
GuessStopBetRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"stop bet"
,
Short
:
"stop bet for a guess game"
,
Run
:
guessStopBet
,
}
addGuessStopBetFlags
(
cmd
)
return
cmd
}
func
addGuessStopBetFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"gameId"
,
"g"
,
""
,
"game ID"
)
cmd
.
MarkFlagRequired
(
"gameId"
)
cmd
.
Flags
()
.
Float64P
(
"fee"
,
"f"
,
0.01
,
"tx fee"
)
}
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
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"guess.GuessStopBetTx"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
func
GuessAbortRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"abort"
,
...
...
plugin/dapp/guess/proto/guess.proto
View file @
4a9c662c
...
...
@@ -174,6 +174,11 @@ message GuessBetTxReq {
int64
fee
=
4
;
}
message
GuessStopBetTxReq
{
string
gameId
=
1
;
int64
fee
=
2
;
}
message
GuessAbortTxReq
{
string
gameId
=
1
;
int64
fee
=
2
;
...
...
@@ -208,6 +213,8 @@ service guess {
rpc
GuessStart
(
GuessGameStart
)
returns
(
UnsignTx
)
{}
//游戏下注
rpc
GuessBet
(
GuessGameBet
)
returns
(
UnsignTx
)
{}
//游戏终止下注
rpc
GuessStopBet
(
GuessGameStopBet
)
returns
(
UnsignTx
)
{}
//游戏异常终止
rpc
GuessAbort
(
GuessGameAbort
)
returns
(
UnsignTx
)
{}
//游戏结束
...
...
plugin/dapp/guess/rpc/jrpc.go
View file @
4a9c662c
...
...
@@ -39,6 +39,20 @@ func (c *Jrpc) GuessBetTx(parm *pb.GuessBetTxReq, result *interface{}) error {
return
nil
}
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
}
func
(
c
*
Jrpc
)
GuessAbortTx
(
parm
*
pb
.
GuessAbortTxReq
,
result
*
interface
{})
error
{
if
parm
==
nil
{
return
types
.
ErrInvalidParam
...
...
plugin/dapp/guess/rpc/rpc.go
View file @
4a9c662c
...
...
@@ -75,6 +75,32 @@ func (c *channelClient) GuessBet(ctx context.Context, parm *pb.GuessBetTxReq) (*
return
&
types
.
UnsignTx
{
Data
:
data
},
nil
}
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
{
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
)
GuessAbort
(
ctx
context
.
Context
,
parm
*
pb
.
GuessAbortTxReq
)
(
*
types
.
UnsignTx
,
error
)
{
v
:=
&
pb
.
GuessGameAbort
{
GameId
:
parm
.
GameId
,
...
...
plugin/dapp/guess/types/guess.pb.go
View file @
4a9c662c
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