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
a6754637
Commit
a6754637
authored
Dec 18, 2018
by
vipwzw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto ci
parent
5c0ea3b1
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
39 additions
and
42 deletions
+39
-42
game.go
plugin/dapp/guess/commands/game.go
+4
-6
exec.go
plugin/dapp/guess/executor/exec.go
+0
-0
exec_del_local.go
plugin/dapp/guess/executor/exec_del_local.go
+3
-3
exec_local.go
plugin/dapp/guess/executor/exec_local.go
+2
-2
guess.go
plugin/dapp/guess/executor/guess.go
+0
-1
guessdb.go
plugin/dapp/guess/executor/guessdb.go
+18
-18
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
+1
-0
const.go
plugin/dapp/guess/types/const.go
+1
-1
errors.go
plugin/dapp/guess/types/errors.go
+0
-0
guess.pb.go
plugin/dapp/guess/types/guess.pb.go
+2
-1
tx.go
plugin/dapp/guess/types/tx.go
+0
-0
types.go
plugin/dapp/guess/types/types.go
+7
-8
No files found.
plugin/dapp/guess/commands/game.go
View file @
a6754637
...
...
@@ -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"
)
func
GuessCmd
()
*
cobra
.
Command
{
...
...
@@ -92,7 +93,7 @@ func guessStart(cmd *cobra.Command, args []string) {
Options
:
options
,
Category
:
category
,
MaxBetHeight
:
maxBetHeight
,
MaxBetsOneTime
:
maxBetsOneTime
*
1e8
,
MaxBetsOneTime
:
maxBetsOneTime
*
1e8
,
MaxBetsNumber
:
maxBetsNumber
*
1e8
,
DevFeeFactor
:
devFeeFactor
,
DevFeeAddr
:
devFeeAddr
,
...
...
@@ -177,7 +178,6 @@ func guessStopBet(cmd *cobra.Command, args []string) {
ctx
.
RunWithoutMarshal
()
}
func
GuessAbortRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"abort"
,
...
...
@@ -245,7 +245,6 @@ func guessPublish(cmd *cobra.Command, args []string) {
ctx
.
RunWithoutMarshal
()
}
func
GuessQueryRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"query"
,
...
...
@@ -290,7 +289,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
{
...
...
@@ -357,7 +356,6 @@ func guessQuery(cmd *cobra.Command, args []string) {
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
case
7
:
req
:=
&
pkt
.
QueryGuessGameInfo
{
AdminAddr
:
adminAddr
,
...
...
plugin/dapp/guess/executor/exec.go
View file @
a6754637
plugin/dapp/guess/executor/exec_del_local.go
View file @
a6754637
...
...
@@ -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
))
...
...
plugin/dapp/guess/executor/exec_local.go
View file @
a6754637
...
...
@@ -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
))
...
...
plugin/dapp/guess/executor/guess.go
View file @
a6754637
...
...
@@ -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 @
a6754637
...
...
@@ -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"
...
...
@@ -25,7 +26,7 @@ const (
ListASC
=
int32
(
1
)
DefaultCount
=
int32
(
20
)
//默认一次取多少条记录
DefaultCategory
=
"default"
DefaultCategory
=
"default"
MaxBetsOneTime
=
10000e8
//一次最多下多少注
MaxBetsNumber
=
10000000e8
//一局游戏最多接受多少注
...
...
@@ -366,7 +367,6 @@ func (action *Action) newGame(gameId string, start *pkt.GuessGameStart) (*pkt.Gu
return
game
,
nil
}
func
(
action
*
Action
)
GameStart
(
start
*
pkt
.
GuessGameStart
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
...
...
@@ -433,7 +433,7 @@ 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
}
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
)
...
...
@@ -484,7 +484,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
...
...
@@ -501,7 +501,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
...
...
@@ -550,7 +550,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
...
...
@@ -577,11 +577,11 @@ func (action *Action) GameStopBet(pbBet *pkt.GuessGameStopBet) (*types.Receipt,
}
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
()
...
...
@@ -615,7 +615,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
...
...
@@ -623,7 +623,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 +751,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
)
...
...
@@ -804,11 +804,11 @@ func (action *Action) GameAbort(pbend *pkt.GuessGameAbort) (*types.Receipt, erro
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
}
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
...
...
@@ -844,7 +844,7 @@ func (action *Action) ChangeStatus(game *pkt.GuessGame, destStatus int32) {
}
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
...
...
plugin/dapp/guess/executor/keys.go
View file @
a6754637
...
...
@@ -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 @
a6754637
...
...
@@ -80,4 +80,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 @
a6754637
...
...
@@ -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"
...
...
plugin/dapp/guess/types/const.go
View file @
a6754637
...
...
@@ -53,7 +53,7 @@ const (
FuncName_QueryGameByAdminAddr
=
"QueryGamesByAdminAddr"
FuncName_QueryGameByAddrStatus
=
"QueryGamesByAddrStatus"
FuncName_QueryGameByAdminStatus
=
"QueryGamesByAdminStatus"
FuncName_QueryGameByCategoryStatus
=
"QueryGamesByCategoryStatus"
FuncName_QueryGameByCategoryStatus
=
"QueryGamesByCategoryStatus"
)
const
(
...
...
plugin/dapp/guess/types/errors.go
View file @
a6754637
plugin/dapp/guess/types/guess.pb.go
View file @
a6754637
...
...
@@ -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 @
a6754637
plugin/dapp/guess/types/types.go
View file @
a6754637
...
...
@@ -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
()
{
...
...
@@ -43,7 +44,7 @@ func (t *GuessType) GetTypeMap() map[string]int32 {
return
map
[
string
]
int32
{
"Start"
:
GuessGameActionStart
,
"Bet"
:
GuessGameActionBet
,
"StopBet"
:
GuessGameActionStopBet
,
"StopBet"
:
GuessGameActionStopBet
,
"Abort"
:
GuessGameActionAbort
,
"Publish"
:
GuessGameActionPublish
,
"Query"
:
GuessGameActionQuery
,
...
...
@@ -117,7 +118,7 @@ func CreateRawGuessStartTx(parm *GuessGameStartTx) (*types.Transaction, error) {
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
GuessGameStart
{
v
:=
&
GuessGameStart
{
Topic
:
parm
.
Topic
,
Options
:
parm
.
Options
,
Category
:
parm
.
Category
,
...
...
@@ -249,7 +250,7 @@ func CreateRawGuessAbortTx(parm *GuessGameAbortTx) (*types.Transaction, error) {
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
GuessGameAbort
{
v
:=
&
GuessGameAbort
{
GameId
:
parm
.
GameId
,
}
...
...
@@ -271,5 +272,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