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
4c0076ad
Commit
4c0076ad
authored
Dec 18, 2018
by
张振华
Browse files
Options
Browse Files
Download
Plain Diff
linter
parents
43c631f6
a6754637
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
174 additions
and
177 deletions
+174
-177
game.go
plugin/dapp/guess/commands/game.go
+30
-29
exec.go
plugin/dapp/guess/executor/exec.go
+1
-2
exec_del_local.go
plugin/dapp/guess/executor/exec_del_local.go
+4
-5
exec_local.go
plugin/dapp/guess/executor/exec_local.go
+3
-4
guess.go
plugin/dapp/guess/executor/guess.go
+0
-1
guessdb.go
plugin/dapp/guess/executor/guessdb.go
+44
-43
keys.go
plugin/dapp/guess/executor/keys.go
+1
-1
jrpc.go
plugin/dapp/guess/rpc/jrpc.go
+0
-1
rpc.go
plugin/dapp/guess/rpc/rpc.go
+28
-27
const.go
plugin/dapp/guess/types/const.go
+6
-7
errors.go
plugin/dapp/guess/types/errors.go
+3
-3
guess.pb.go
plugin/dapp/guess/types/guess.pb.go
+2
-1
tx.go
plugin/dapp/guess/types/tx.go
+23
-23
types.go
plugin/dapp/guess/types/types.go
+29
-30
No files found.
plugin/dapp/guess/commands/game.go
View file @
4c0076ad
...
...
@@ -5,12 +5,13 @@
package
commands
import
(
"strings"
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
pkt
"github.com/33cn/plugin/plugin/dapp/guess/types"
"github.com/spf13/cobra"
"strings"
)
//GuessCmd Guess合约命令行
...
...
@@ -90,18 +91,18 @@ func guessStart(cmd *cobra.Command, args []string) {
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
)),
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
)),
}
var
res
string
...
...
@@ -140,8 +141,8 @@ func guessBet(cmd *cobra.Command, args []string) {
params
:=
&
pkt
.
GuessBetTxReq
{
GameId
:
gameID
,
Option
:
option
,
Bets
:
betsNumber
,
Fee
:
int64
(
fee
*
float64
(
1e8
)),
Bets
:
betsNumber
,
Fee
:
int64
(
fee
*
float64
(
1e8
)),
}
var
res
string
...
...
@@ -173,7 +174,7 @@ func guessStopBet(cmd *cobra.Command, args []string) {
params
:=
&
pkt
.
GuessStopBetTxReq
{
GameId
:
gameID
,
Fee
:
int64
(
fee
*
float64
(
1e8
)),
Fee
:
int64
(
fee
*
float64
(
1e8
)),
}
var
res
string
...
...
@@ -204,7 +205,8 @@ func guessAbort(cmd *cobra.Command, args []string) {
fee
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"fee"
)
params
:=
&
pkt
.
GuessAbortTxReq
{
GameId
:
gameID
,
Fee
:
int64
(
fee
*
float64
(
1e8
)),
Fee
:
int64
(
fee
*
float64
(
1e8
)),
}
var
res
string
...
...
@@ -242,7 +244,7 @@ func guessPublish(cmd *cobra.Command, args []string) {
params
:=
&
pkt
.
GuessPublishTxReq
{
GameId
:
gameID
,
Result
:
result
,
Fee
:
int64
(
fee
*
float64
(
1e8
)),
Fee
:
int64
(
fee
*
float64
(
1e8
)),
}
var
res
string
...
...
@@ -295,7 +297,7 @@ func guessQuery(cmd *cobra.Command, args []string) {
//6:QueryGameByAddrStatus,
//7:QueryGameByAdminStatus,
//8:QueryGameByCategoryStatus,
switch
ty
{
switch
ty
{
case
1
:
gameIds
:=
strings
.
Split
(
gameIDs
,
";"
)
req
:=
&
pkt
.
QueryGuessGameInfos
{
...
...
@@ -319,7 +321,7 @@ func guessQuery(cmd *cobra.Command, args []string) {
case
3
:
req
:=
&
pkt
.
QueryGuessGameInfo
{
Addr
:
addr
,
Addr
:
addr
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncName_QueryGameByAddr
...
...
@@ -331,7 +333,7 @@ func guessQuery(cmd *cobra.Command, args []string) {
case
4
:
req
:=
&
pkt
.
QueryGuessGameInfo
{
Status
:
status
,
Index
:
index
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncName_QueryGameByStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
...
...
@@ -342,7 +344,7 @@ func guessQuery(cmd *cobra.Command, args []string) {
case
5
:
req
:=
&
pkt
.
QueryGuessGameInfo
{
AdminAddr
:
adminAddr
,
Index
:
index
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncName_QueryGameByAdminAddr
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
...
...
@@ -352,9 +354,9 @@ func guessQuery(cmd *cobra.Command, args []string) {
case
6
:
req
:=
&
pkt
.
QueryGuessGameInfo
{
Addr
:
addr
,
Addr
:
addr
,
Status
:
status
,
Index
:
index
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncName_QueryGameByAddrStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
...
...
@@ -362,12 +364,11 @@ func guessQuery(cmd *cobra.Command, args []string) {
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
case
7
:
req
:=
&
pkt
.
QueryGuessGameInfo
{
AdminAddr
:
adminAddr
,
Status
:
status
,
Index
:
index
,
Status
:
status
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncName_QueryGameByAdminStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
...
...
@@ -378,8 +379,8 @@ func guessQuery(cmd *cobra.Command, args []string) {
case
8
:
req
:=
&
pkt
.
QueryGuessGameInfo
{
Category
:
category
,
Status
:
status
,
Index
:
index
,
Status
:
status
,
Index
:
index
,
}
params
.
FuncName
=
pkt
.
FuncName_QueryGameByCategoryStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
...
...
plugin/dapp/guess/executor/exec.go
View file @
4c0076ad
...
...
@@ -37,4 +37,4 @@ func (c *Guess) Exec_Publish(payload *pkt.GuessGamePublish, tx *types.Transactio
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
)
}
\ No newline at end of file
}
plugin/dapp/guess/executor/exec_del_local.go
View file @
4c0076ad
...
...
@@ -11,10 +11,10 @@ import (
func
(
g
*
Guess
)
rollbackIndex
(
log
*
pkt
.
ReceiptGuessGame
)
(
kvs
[]
*
types
.
KeyValue
)
{
//新创建游戏,将增加的记录都删除掉
if
log
.
Status
==
pkt
.
GuessGameStatusStart
{
if
log
.
Status
==
pkt
.
GuessGameStatusStart
{
//kvs = append(kvs, addGuessGameAddrIndexKey(log.Status, log.Addr, log.GameId, log.Index))
kvs
=
append
(
kvs
,
delGuessGameStatusIndexKey
(
log
.
Status
,
log
.
Index
))
kvs
=
append
(
kvs
,
delGuessGameAdminIndexKey
(
log
.
AdminAddr
,
log
.
Index
))
kvs
=
append
(
kvs
,
delGuessGameAdminIndexKey
(
log
.
AdminAddr
,
log
.
Index
))
kvs
=
append
(
kvs
,
delGuessGameAdminStatusIndexKey
(
log
.
Status
,
log
.
AdminAddr
,
log
.
Index
))
kvs
=
append
(
kvs
,
delGuessGameCategoryStatusIndexKey
(
log
.
Status
,
log
.
Category
,
log
.
Index
))
}
else
if
log
.
Status
==
pkt
.
GuessGameStatusBet
{
...
...
@@ -32,7 +32,7 @@ func (g *Guess) rollbackIndex(log *pkt.ReceiptGuessGame) (kvs []*types.KeyValue)
kvs
=
append
(
kvs
,
delGuessGameAdminStatusIndexKey
(
log
.
Status
,
log
.
AdminAddr
,
log
.
Index
))
kvs
=
append
(
kvs
,
delGuessGameCategoryStatusIndexKey
(
log
.
Status
,
log
.
Category
,
log
.
Index
))
}
}
else
if
log
.
StatusChange
{
}
else
if
log
.
StatusChange
{
//其他状态时的状态发生变化的情况,要将老状态对应的记录恢复,同时删除新加的状态记录;对于每个地址的下注记录也需要遍历处理。
kvs
=
append
(
kvs
,
addGuessGameStatusIndexKey
(
log
.
PreStatus
,
log
.
GameId
,
log
.
PreIndex
))
kvs
=
append
(
kvs
,
addGuessGameAdminStatusIndexKey
(
log
.
PreStatus
,
log
.
AdminAddr
,
log
.
GameId
,
log
.
PreIndex
))
...
...
@@ -94,4 +94,4 @@ func (g *Guess) ExecDelLocal_Publish(payload *pkt.GuessGamePublish, tx *types.Tr
//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 @
4c0076ad
...
...
@@ -11,7 +11,7 @@ import (
func
(
g
*
Guess
)
updateIndex
(
log
*
pkt
.
ReceiptGuessGame
)
(
kvs
[]
*
types
.
KeyValue
)
{
//新创建游戏
if
log
.
Status
==
pkt
.
GuessGameStatusStart
{
if
log
.
Status
==
pkt
.
GuessGameStatusStart
{
//kvs = append(kvs, addGuessGameAddrIndexKey(log.Status, log.Addr, log.GameId, log.Index))
kvs
=
append
(
kvs
,
addGuessGameStatusIndexKey
(
log
.
Status
,
log
.
GameId
,
log
.
Index
))
kvs
=
append
(
kvs
,
addGuessGameAdminIndexKey
(
log
.
Status
,
log
.
AdminAddr
,
log
.
GameId
,
log
.
Index
))
...
...
@@ -31,7 +31,7 @@ func (g *Guess) updateIndex(log *pkt.ReceiptGuessGame) (kvs []*types.KeyValue) {
kvs
=
append
(
kvs
,
delGuessGameAdminStatusIndexKey
(
log
.
PreStatus
,
log
.
AdminAddr
,
log
.
PreIndex
))
kvs
=
append
(
kvs
,
delGuessGameCategoryStatusIndexKey
(
log
.
PreStatus
,
log
.
Category
,
log
.
PreIndex
))
}
}
else
if
log
.
StatusChange
{
}
else
if
log
.
StatusChange
{
//其他状态时的状态发生变化,要将老状态对应的记录删除,同时加入新状态记录;对于每个地址的下注记录也需要遍历处理。
kvs
=
append
(
kvs
,
addGuessGameStatusIndexKey
(
log
.
Status
,
log
.
GameId
,
log
.
Index
))
kvs
=
append
(
kvs
,
addGuessGameAdminStatusIndexKey
(
log
.
Status
,
log
.
AdminAddr
,
log
.
GameId
,
log
.
Index
))
...
...
@@ -98,4 +98,4 @@ func (g *Guess) ExecLocal_Publish(payload *pkt.GuessGamePublish, tx *types.Trans
//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 @
4c0076ad
...
...
@@ -26,7 +26,6 @@ type subConfig struct {
var
cfg
subConfig
// Init Guess
func
Init
(
name
string
,
sub
[]
byte
)
{
driverName
:=
GetName
()
...
...
plugin/dapp/guess/executor/guessdb.go
View file @
4c0076ad
...
...
@@ -7,11 +7,12 @@ package executor
import
(
"context"
"fmt"
"github.com/33cn/chain33/client"
"google.golang.org/grpc"
"strings"
"time"
"github.com/33cn/chain33/client"
"google.golang.org/grpc"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/common"
dbm
"github.com/33cn/chain33/common/db"
...
...
@@ -88,17 +89,17 @@ func NewAction(guess *Guess, tx *types.Transaction, index int) *Action {
return
&
Action
{
coinsAccount
:
guess
.
GetCoinsAccount
(),
db
:
guess
.
GetStateDB
(),
txhash
:
hash
,
fromaddr
:
fromAddr
,
blocktime
:
guess
.
GetBlockTime
(),
height
:
guess
.
GetHeight
(),
execaddr
:
dapp
.
ExecAddress
(
string
(
tx
.
Execer
)),
localDB
:
guess
.
GetLocalDB
(),
index
:
index
,
api
:
guess
.
GetAPI
(),
conn
:
conn
,
grpcClient
:
grpcClient
,
db
:
guess
.
GetStateDB
(),
txhash
:
hash
,
fromaddr
:
fromAddr
,
blocktime
:
guess
.
GetBlockTime
(),
height
:
guess
.
GetHeight
(),
execaddr
:
dapp
.
ExecAddress
(
string
(
tx
.
Execer
)),
localDB
:
guess
.
GetLocalDB
(),
index
:
index
,
api
:
guess
.
GetAPI
(),
conn
:
conn
,
grpcClient
:
grpcClient
,
}
}
...
...
@@ -358,21 +359,21 @@ func (action *Action) readGame(id string) (*pkt.GuessGame, error) {
// 新建一局游戏
func
(
action
*
Action
)
newGame
(
gameID
string
,
start
*
pkt
.
GuessGameStart
)
(
*
pkt
.
GuessGame
,
error
)
{
game
:=
&
pkt
.
GuessGame
{
GameId
:
gameID
,
Status
:
pkt
.
GuessGameActionStart
,
GameId
:
gameID
,
Status
:
pkt
.
GuessGameActionStart
,
//StartTime: action.blocktime,
StartTxHash
:
gameID
,
Topic
:
start
.
Topic
,
Category
:
start
.
Category
,
Options
:
start
.
Options
,
StartTxHash
:
gameID
,
Topic
:
start
.
Topic
,
Category
:
start
.
Category
,
Options
:
start
.
Options
,
MaxBetHeight
:
start
.
MaxBetHeight
,
MaxBetsOneTime
:
start
.
MaxBetsOneTime
,
MaxBetsNumber
:
start
.
MaxBetsNumber
,
DevFeeFactor
:
start
.
DevFeeFactor
,
DevFeeAddr
:
start
.
DevFeeAddr
,
PlatFeeFactor
:
start
.
PlatFeeFactor
,
PlatFeeAddr
:
start
.
PlatFeeAddr
,
ExpireHeight
:
start
.
ExpireHeight
,
MaxBetsOneTime
:
start
.
MaxBetsOneTime
,
MaxBetsNumber
:
start
.
MaxBetsNumber
,
DevFeeFactor
:
start
.
DevFeeFactor
,
DevFeeAddr
:
start
.
DevFeeAddr
,
PlatFeeFactor
:
start
.
PlatFeeFactor
,
PlatFeeAddr
:
start
.
PlatFeeAddr
,
ExpireHeight
:
start
.
ExpireHeight
,
//AdminAddr: action.fromaddr,
BetsNumber
:
0
,
//Index: action.getIndex(game),
...
...
@@ -449,8 +450,8 @@ func (action *Action) GameStart(start *pkt.GuessGameStart) (*types.Receipt, erro
game
.
PreIndex
=
0
game
.
Index
=
action
.
getIndex
()
game
.
Status
=
pkt
.
GuessGameStatusStart
game
.
BetStat
=
&
pkt
.
GuessBetStat
{
TotalBetTimes
:
0
,
TotalBetsNumber
:
0
}
for
i
:=
0
;
i
<
len
(
options
);
i
++
{
game
.
BetStat
=
&
pkt
.
GuessBetStat
{
TotalBetTimes
:
0
,
TotalBetsNumber
:
0
}
for
i
:=
0
;
i
<
len
(
options
);
i
++
{
item
:=
&
pkt
.
GuessBetStatItem
{
Option
:
options
[
i
],
BetsNumber
:
0
,
BetsTimes
:
0
}
game
.
BetStat
.
Items
=
append
(
game
.
BetStat
.
Items
,
item
)
}
...
...
@@ -501,7 +502,7 @@ func (action *Action) GameBet(pbBet *pkt.GuessGameBet) (*types.Receipt, error) {
//检查竞猜选项是否合法
options
,
legal
:=
GetOptions
(
game
.
GetOptions
())
if
!
legal
||
len
(
options
)
==
0
{
if
!
legal
||
len
(
options
)
==
0
{
logger
.
Error
(
"GameBet"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"Game Options illegal"
,
game
.
GetOptions
())
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -518,7 +519,7 @@ func (action *Action) GameBet(pbBet *pkt.GuessGameBet) (*types.Receipt, error) {
pbBet
.
BetsNum
=
game
.
GetMaxBetsOneTime
()
}
if
game
.
BetsNumber
+
pbBet
.
GetBetsNum
()
>
game
.
MaxBetsNumber
{
if
game
.
BetsNumber
+
pbBet
.
GetBetsNum
()
>
game
.
MaxBetsNumber
{
logger
.
Error
(
"GameBet"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"MaxBetsNumber over limit"
,
game
.
MaxBetsNumber
,
"current Bets Number"
,
game
.
BetsNumber
)
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -568,7 +569,7 @@ func (action *Action) GameStopBet(pbBet *pkt.GuessGameStopBet) (*types.Receipt,
return
nil
,
err
}
if
game
.
Status
!=
pkt
.
GuessGameStatusStart
&&
game
.
Status
!=
pkt
.
GuessGameStatusBet
{
if
game
.
Status
!=
pkt
.
GuessGameStatusStart
&&
game
.
Status
!=
pkt
.
GuessGameStatusBet
{
logger
.
Error
(
"GameBet"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"Status error"
,
game
.
GetStatus
())
return
nil
,
pkt
.
ErrGuessStatus
...
...
@@ -596,11 +597,11 @@ func (action *Action) GameStopBet(pbBet *pkt.GuessGameStopBet) (*types.Receipt,
//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
}
bet
:=
&
pkt
.
GuessBet
{
Option
:
pbBet
.
GetOption
(),
BetsNumber
:
pbBet
.
BetsNum
,
Index
:
game
.
Index
}
player
:=
&
pkt
.
GuessPlayer
{
Addr
:
action
.
fromaddr
,
Bet
:
bet
}
game
.
Plays
=
append
(
game
.
Plays
,
player
)
for
i
:=
0
;
i
<
len
(
game
.
BetStat
.
Items
);
i
++
{
for
i
:=
0
;
i
<
len
(
game
.
BetStat
.
Items
);
i
++
{
if
game
.
BetStat
.
Items
[
i
]
.
Option
==
pbBet
.
GetOption
()
{
//针对具体选项更新统计项
game
.
BetStat
.
Items
[
i
]
.
BetsNumber
+=
pbBet
.
GetBetsNum
()
...
...
@@ -635,7 +636,7 @@ func (action *Action) GamePublish(publish *pkt.GuessGamePublish) (*types.Receipt
return
nil
,
pkt
.
ErrNoPrivilege
}
if
game
.
Status
!=
pkt
.
GuessGameStatusStart
&&
game
.
Status
!=
pkt
.
GuessGameStatusBet
&&
game
.
Status
!=
pkt
.
GuessGameStatusStopBet
{
if
game
.
Status
!=
pkt
.
GuessGameStatusStart
&&
game
.
Status
!=
pkt
.
GuessGameStatusBet
&&
game
.
Status
!=
pkt
.
GuessGameStatusStopBet
{
logger
.
Error
(
"GamePublish"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"Status error"
,
game
.
GetStatus
())
return
nil
,
pkt
.
ErrGuessStatus
...
...
@@ -643,7 +644,7 @@ func (action *Action) GamePublish(publish *pkt.GuessGamePublish) (*types.Receipt
//检查竞猜选项是否合法
options
,
legal
:=
GetOptions
(
game
.
GetOptions
())
if
!
legal
||
len
(
options
)
==
0
{
if
!
legal
||
len
(
options
)
==
0
{
logger
.
Error
(
"GamePublish"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"Game Options illegal"
,
game
.
GetOptions
())
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -751,7 +752,7 @@ func (action *Action) GamePublish(publish *pkt.GuessGamePublish) (*types.Receipt
}
var
receiptLog
*
types
.
ReceiptLog
action
.
ChangeAllAddrIndex
(
game
)
action
.
ChangeAllAddrIndex
(
game
)
receiptLog
=
action
.
GetReceiptLog
(
game
,
true
)
logs
=
append
(
logs
,
receiptLog
)
...
...
@@ -772,7 +773,7 @@ func (action *Action) GameAbort(pbend *pkt.GuessGameAbort) (*types.Receipt, erro
return
nil
,
err
}
if
game
.
Status
==
pkt
.
GuessGameStatusPublish
||
game
.
Status
==
pkt
.
GuessGameStatusAbort
{
if
game
.
Status
==
pkt
.
GuessGameStatusPublish
||
game
.
Status
==
pkt
.
GuessGameStatusAbort
{
logger
.
Error
(
"GameAbort"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"game status not allow abort"
,
game
.
Status
)
...
...
@@ -826,11 +827,11 @@ func (action *Action) GameAbort(pbend *pkt.GuessGameAbort) (*types.Receipt, erro
}
//GetOptions 获得竞猜选项,并判断是否符合约定格式,类似"A:xxxx;B:xxxx;C:xxx",“:”前为选项名称,不能重复,":"后为选项说明。
func
GetOptions
(
strOptions
string
)
(
options
[]
string
,
legal
bool
){
func
GetOptions
(
strOptions
string
)
(
options
[]
string
,
legal
bool
)
{
legal
=
true
items
:=
strings
.
Split
(
strOptions
,
";"
)
for
i
:=
0
;
i
<
len
(
items
);
i
++
{
item
:=
strings
.
Split
(
items
[
i
],
":"
)
for
i
:=
0
;
i
<
len
(
items
);
i
++
{
item
:=
strings
.
Split
(
items
[
i
],
":"
)
for
j
:=
0
;
j
<
len
(
options
);
j
++
{
if
item
[
0
]
==
options
[
j
]
{
legal
=
false
...
...
@@ -869,7 +870,7 @@ func (action *Action) ChangeStatus(game *pkt.GuessGame, destStatus int32) {
//ChangeAllAddrIndex 状态更新时,更新下注记录的历史信息
func
(
action
*
Action
)
ChangeAllAddrIndex
(
game
*
pkt
.
GuessGame
)
{
for
i
:=
0
;
i
<
len
(
game
.
Plays
)
;
i
++
{
for
i
:=
0
;
i
<
len
(
game
.
Plays
);
i
++
{
player
:=
game
.
Plays
[
i
]
player
.
Bet
.
PreIndex
=
player
.
Bet
.
Index
player
.
Bet
.
Index
=
game
.
Index
...
...
@@ -914,7 +915,7 @@ func (action *Action) RefreshStatusByTime(game *pkt.GuessGame) (canBet bool) {
}
canBet
=
false
return
canBet
return
canBet
}
canBet
=
true
...
...
plugin/dapp/guess/executor/keys.go
View file @
4c0076ad
...
...
@@ -2,6 +2,7 @@ package executor
import
(
"fmt"
"github.com/33cn/chain33/types"
pkt
"github.com/33cn/plugin/plugin/dapp/guess/types"
)
...
...
@@ -189,4 +190,3 @@ func delGuessGameCategoryStatusIndexKey(status int32, category string, index int
kv
.
Value
=
nil
return
kv
}
plugin/dapp/guess/rpc/jrpc.go
View file @
4c0076ad
...
...
@@ -85,4 +85,3 @@ func (c *Jrpc) GuessPublishTx(parm *pb.GuessPublishTxReq, result *interface{}) e
*
result
=
hex
.
EncodeToString
(
reply
.
Data
)
return
nil
}
plugin/dapp/guess/rpc/rpc.go
View file @
4c0076ad
...
...
@@ -6,6 +6,7 @@ package rpc
import
(
"context"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/types"
pb
"github.com/33cn/plugin/plugin/dapp/guess/types"
...
...
@@ -14,17 +15,17 @@ import (
//构造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
,
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
,
MaxBetsNumber
:
parm
.
MaxBetsNumber
,
DevFeeFactor
:
parm
.
DevFeeFactor
,
DevFeeAddr
:
parm
.
DevFeeAddr
,
PlatFeeFactor
:
parm
.
PlatFeeFactor
,
PlatFeeAddr
:
parm
.
PlatFeeAddr
,
ExpireHeight
:
parm
.
ExpireHeight
,
}
val
:=
&
pb
.
GuessGameAction
{
...
...
@@ -34,10 +35,10 @@ func (c *channelClient) GuessStart(ctx context.Context, parm *pb.GuessStartTxReq
name
:=
types
.
ExecName
(
pb
.
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
pb
.
GuessX
)),
Execer
:
[]
byte
(
types
.
ExecName
(
pb
.
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
...
...
@@ -51,8 +52,8 @@ func (c *channelClient) GuessStart(ctx context.Context, parm *pb.GuessStartTxReq
//构造bet原始交易
func
(
c
*
channelClient
)
GuessBet
(
ctx
context
.
Context
,
parm
*
pb
.
GuessBetTxReq
)
(
*
types
.
UnsignTx
,
error
)
{
v
:=
&
pb
.
GuessGameBet
{
GameId
:
parm
.
GameId
,
Option
:
parm
.
Option
,
GameId
:
parm
.
GameId
,
Option
:
parm
.
Option
,
BetsNum
:
parm
.
Bets
,
}
...
...
@@ -63,10 +64,10 @@ func (c *channelClient) GuessBet(ctx context.Context, parm *pb.GuessBetTxReq) (*
name
:=
types
.
ExecName
(
pb
.
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
pb
.
GuessX
)),
Execer
:
[]
byte
(
types
.
ExecName
(
pb
.
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
...
...
@@ -90,10 +91,10 @@ func (c *channelClient) GuessStopBet(ctx context.Context, parm *pb.GuessStopBetT
name
:=
types
.
ExecName
(
pb
.
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
pb
.
GuessX
)),
Execer
:
[]
byte
(
types
.
ExecName
(
pb
.
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
...
...
@@ -116,10 +117,10 @@ func (c *channelClient) GuessAbort(ctx context.Context, parm *pb.GuessAbortTxReq
}
name
:=
types
.
ExecName
(
pb
.
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
pb
.
GuessX
)),
Execer
:
[]
byte
(
types
.
ExecName
(
pb
.
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
...
...
@@ -144,10 +145,10 @@ func (c *channelClient) GuessPublish(ctx context.Context, parm *pb.GuessPublishT
name
:=
types
.
ExecName
(
pb
.
GuessX
)
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
pb
.
GuessX
)),
Execer
:
[]
byte
(
types
.
ExecName
(
pb
.
GuessX
)),
Payload
:
types
.
Encode
(
val
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
name
),
}
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
...
...
plugin/dapp/guess/types/const.go
View file @
4c0076ad
...
...
@@ -28,10 +28,10 @@ const (
//game log ty
const
(
TyLogGuessGameStart
=
901
TyLogGuessGameBet
=
902
TyLogGuessGameStart
=
901
TyLogGuessGameBet
=
902
TyLogGuessGameStopBet
=
903
TyLogGuessGameAbort
=
904
TyLogGuessGameAbort
=
904
TyLogGuessGamePublish
=
905
TyLogGuessGameTimeout
=
906
)
...
...
@@ -40,8 +40,8 @@ const (
//建议用github的组织名称,或者用户名字开头, 再加上自己的插件的名字
//如果发生重名,可以通过配置文件修改这些名字
var
(
JRPCName
=
"guess"
GuessX
=
"guess"
JRPCName
=
"guess"
GuessX
=
"guess"
ExecerGuess
=
[]
byte
(
GuessX
)
)
...
...
@@ -70,4 +70,4 @@ const (
//PlatformShareAddr default value
PlatformShareAddr
=
"1PHtChNt3UcfssR7v7trKSk3WJtAWjKjjX"
)
\ No newline at end of file
)
plugin/dapp/guess/types/errors.go
View file @
4c0076ad
...
...
@@ -8,7 +8,7 @@ import "errors"
// Errors for lottery
var
(
ErrNoPrivilege
=
errors
.
New
(
"ErrNoPrivilege"
)
ErrGuessStatus
=
errors
.
New
(
"ErrGuessStatus"
)
ErrOverBetsLimit
=
errors
.
New
(
"ErrOverBetsLimit"
)
ErrNoPrivilege
=
errors
.
New
(
"ErrNoPrivilege"
)
ErrGuessStatus
=
errors
.
New
(
"ErrGuessStatus"
)
ErrOverBetsLimit
=
errors
.
New
(
"ErrOverBetsLimit"
)
)
plugin/dapp/guess/types/guess.pb.go
View file @
4c0076ad
...
...
@@ -6,10 +6,11 @@ package types
import
(
context
"context"
fmt
"fmt"
math
"math"
types
"github.com/33cn/chain33/types"
proto
"github.com/golang/protobuf/proto"
grpc
"google.golang.org/grpc"
math
"math"
)
// Reference imports to suppress errors if they are not otherwise used.
...
...
plugin/dapp/guess/types/tx.go
View file @
4c0076ad
...
...
@@ -6,43 +6,43 @@ 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"`
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"`
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"`
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"`
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"`
GameId
string
`json:"gameId,omitempty"`
Fee
int64
`json:"fee,omitempty"`
}
plugin/dapp/guess/types/types.go
View file @
4c0076ad
...
...
@@ -6,15 +6,16 @@ package types
import
(
"encoding/json"
"github.com/33cn/chain33/common/address"
"reflect"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/common/address"
log
"github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/types"
)
var
(
llog
=
log
.
New
(
"module"
,
"exectype."
+
GuessX
)
llog
=
log
.
New
(
"module"
,
"exectype."
+
GuessX
)
)
func
init
()
{
...
...
@@ -44,24 +45,24 @@ func (t *GuessType) GetPayload() types.Message {
// GetTypeMap method
func
(
t
*
GuessType
)
GetTypeMap
()
map
[
string
]
int32
{
return
map
[
string
]
int32
{
"Start"
:
GuessGameActionStart
,
"Bet"
:
GuessGameActionBet
,
"StopBet"
:
GuessGameActionStopBet
,
"Abort"
:
GuessGameActionAbort
,
"Start"
:
GuessGameActionStart
,
"Bet"
:
GuessGameActionBet
,
"StopBet"
:
GuessGameActionStopBet
,
"Abort"
:
GuessGameActionAbort
,
"Publish"
:
GuessGameActionPublish
,
"Query"
:
GuessGameActionQuery
,
"Query"
:
GuessGameActionQuery
,
}
}
// GetLogMap method
func
(
t
*
GuessType
)
GetLogMap
()
map
[
int64
]
*
types
.
LogInfo
{
return
map
[
int64
]
*
types
.
LogInfo
{
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"
},
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"
},
}
}
...
...
@@ -121,18 +122,18 @@ func CreateRawGuessStartTx(parm *GuessGameStartTx) (*types.Transaction, error) {
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
GuessGameStart
{
Topic
:
parm
.
Topic
,
Options
:
parm
.
Options
,
Category
:
parm
.
Category
,
MaxBetHeight
:
parm
.
MaxBetHeight
,
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
,
MaxBetsNumber
:
parm
.
MaxBetsNumber
,
DevFeeFactor
:
parm
.
DevFeeFactor
,
DevFeeAddr
:
parm
.
DevFeeAddr
,
PlatFeeFactor
:
parm
.
PlatFeeFactor
,
PlatFeeAddr
:
parm
.
PlatFeeAddr
,
ExpireHeight
:
parm
.
ExpireHeight
,
}
val
:=
&
GuessGameAction
{
...
...
@@ -163,8 +164,8 @@ func CreateRawGuessBetTx(parm *GuessGameBetTx) (*types.Transaction, error) {
}
v
:=
&
GuessGameBet
{
GameId
:
parm
.
GameId
,
Option
:
parm
.
Option
,
GameId
:
parm
.
GameId
,
Option
:
parm
.
Option
,
BetsNum
:
parm
.
BetsNum
,
}
val
:=
&
GuessGameAction
{
...
...
@@ -253,7 +254,7 @@ func CreateRawGuessAbortTx(parm *GuessGameAbortTx) (*types.Transaction, error) {
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
GuessGameAbort
{
v
:=
&
GuessGameAbort
{
GameId
:
parm
.
GameId
,
}
...
...
@@ -275,5 +276,3 @@ func CreateRawGuessAbortTx(parm *GuessGameAbortTx) (*types.Transaction, error) {
}
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