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
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
44 additions
and
43 deletions
+44
-43
game.go
plugin/dapp/guess/commands/game.go
+5
-4
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
+17
-16
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
+0
-0
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
+13
-14
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合约命令行
...
...
@@ -94,7 +95,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
,
...
...
@@ -205,6 +206,7 @@ func guessAbort(cmd *cobra.Command, args []string) {
params
:=
&
pkt
.
GuessAbortTxReq
{
GameId
:
gameID
,
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
{
...
...
@@ -362,7 +364,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 @
4c0076ad
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
))
...
...
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
))
...
...
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"
...
...
@@ -449,7 +450,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
)
...
...
@@ -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
...
...
@@ -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
...
...
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"
...
...
plugin/dapp/guess/types/const.go
View file @
4c0076ad
plugin/dapp/guess/types/errors.go
View file @
4c0076ad
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
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
()
{
...
...
@@ -46,7 +47,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
,
...
...
@@ -56,12 +57,12 @@ func (t *GuessType) GetTypeMap() map[string]int32 {
// 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,7 +122,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
,
...
...
@@ -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