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
c5730591
Unverified
Commit
c5730591
authored
Jan 23, 2019
by
vipwzw
Committed by
GitHub
Jan 23, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #229 from zzh33cn/guess
Guess
parents
fe35ee74
8caed19d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
77 deletions
+6
-77
guess.go
plugin/dapp/guess/executor/guess.go
+1
-9
guessdb.go
plugin/dapp/guess/executor/guessdb.go
+5
-68
No files found.
plugin/dapp/guess/executor/guess.go
View file @
c5730591
...
...
@@ -20,21 +20,13 @@ func init() {
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Guess
{}))
}
type
subConfig
struct
{
ParaRemoteGrpcClient
string
`json:"paraRemoteGrpcClient"`
}
var
cfg
subConfig
// Init Guess
func
Init
(
name
string
,
sub
[]
byte
)
{
driverName
:=
GetName
()
if
name
!=
driverName
{
panic
(
"system dapp can't be rename"
)
}
if
sub
!=
nil
{
types
.
MustDecode
(
sub
,
&
cfg
)
}
drivers
.
Register
(
driverName
,
newGuessGame
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
}
...
...
plugin/dapp/guess/executor/guessdb.go
View file @
c5730591
...
...
@@ -5,17 +5,12 @@
package
executor
import
(
"context"
"fmt"
"strings"
"time"
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db/table"
"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"
...
...
@@ -48,12 +43,6 @@ const (
//MaxExpireHeight 距离游戏创建区块的最大过期高度差
MaxExpireHeight
=
1000000
//grpcRecSize 接收缓冲大小
grpcRecSize
int
=
30
*
1024
*
1024
//retryNum 失败时的重试次数
retryNum
=
10
)
//Action 具体动作执行
...
...
@@ -67,9 +56,7 @@ type Action struct {
execaddr
string
localDB
dbm
.
KVDB
index
int
api
client
.
QueueProtocolAPI
conn
*
grpc
.
ClientConn
grpcClient
types
.
Chain33Client
mainHeight
int64
}
//NewAction 生成Action对象
...
...
@@ -77,19 +64,6 @@ func NewAction(guess *Guess, tx *types.Transaction, index int) *Action {
hash
:=
tx
.
Hash
()
fromAddr
:=
tx
.
From
()
msgRecvOp
:=
grpc
.
WithMaxMsgSize
(
grpcRecSize
)
paraRemoteGrpcClient
:=
types
.
Conf
(
"config.consensus"
)
.
GStr
(
"ParaRemoteGrpcClient"
)
if
types
.
IsPara
()
&&
paraRemoteGrpcClient
==
""
{
panic
(
"ParaRemoteGrpcClient error"
)
}
conn
,
err
:=
grpc
.
Dial
(
paraRemoteGrpcClient
,
grpc
.
WithInsecure
(),
msgRecvOp
)
if
err
!=
nil
{
panic
(
err
)
}
grpcClient
:=
types
.
NewChain33Client
(
conn
)
return
&
Action
{
coinsAccount
:
guess
.
GetCoinsAccount
(),
db
:
guess
.
GetStateDB
(),
...
...
@@ -100,9 +74,7 @@ func NewAction(guess *Guess, tx *types.Transaction, index int) *Action {
execaddr
:
dapp
.
ExecAddress
(
string
(
tx
.
Execer
)),
localDB
:
guess
.
GetLocalDB
(),
index
:
index
,
api
:
guess
.
GetAPI
(),
conn
:
conn
,
grpcClient
:
grpcClient
,
mainHeight
:
guess
.
GetMainHeight
(),
}
}
...
...
@@ -299,7 +271,7 @@ func (action *Action) readGame(id string) (*gty.GuessGame, error) {
func
(
action
*
Action
)
newGame
(
gameID
string
,
start
*
gty
.
GuessGameStart
)
(
*
gty
.
GuessGame
,
error
)
{
game
:=
&
gty
.
GuessGame
{
GameID
:
gameID
,
Status
:
gty
.
GuessGame
Action
Start
,
Status
:
gty
.
GuessGame
Status
Start
,
//StartTime: action.blocktime,
StartTxHash
:
gameID
,
Topic
:
start
.
Topic
,
...
...
@@ -375,16 +347,7 @@ func (action *Action) GameStart(start *gty.GuessGameStart) (*types.Receipt, erro
gameID
:=
common
.
ToHex
(
action
.
txhash
)
game
,
_
:=
action
.
newGame
(
gameID
,
start
)
game
.
StartTime
=
action
.
blocktime
if
types
.
IsPara
()
{
mainHeight
:=
action
.
GetMainHeightByTxHash
(
action
.
txhash
)
if
mainHeight
<
0
{
logger
.
Error
(
"GameStart"
,
"mainHeight"
,
mainHeight
)
return
nil
,
gty
.
ErrGuessStatus
}
game
.
StartHeight
=
mainHeight
}
else
{
game
.
StartHeight
=
action
.
height
}
game
.
StartHeight
=
action
.
mainHeight
game
.
AdminAddr
=
action
.
fromaddr
game
.
PreIndex
=
0
game
.
Index
=
action
.
getIndex
()
...
...
@@ -831,18 +794,7 @@ func (action *Action) changeAllAddrIndex(game *gty.GuessGame) {
//refreshStatusByTime 检测游戏是否过期,是否可以下注
func
(
action
*
Action
)
refreshStatusByTime
(
game
*
gty
.
GuessGame
)
(
canBet
bool
)
{
var
mainHeight
int64
if
types
.
IsPara
()
{
mainHeight
=
action
.
GetMainHeightByTxHash
(
action
.
txhash
)
if
mainHeight
<
0
{
logger
.
Error
(
"RefreshStatusByTime"
,
"mainHeight err"
,
mainHeight
)
return
true
}
}
else
{
mainHeight
=
action
.
height
}
mainHeight
:=
action
.
mainHeight
//如果完全由管理员驱动状态变化,则除了保护性过期判断外,不需要做其他判断。
if
game
.
DrivenByAdmin
{
...
...
@@ -899,18 +851,3 @@ func (action *Action) checkTime(start *gty.GuessGameStart) bool {
return
false
}
// GetMainHeightByTxHash get Block height
func
(
action
*
Action
)
GetMainHeightByTxHash
(
txHash
[]
byte
)
int64
{
for
i
:=
0
;
i
<
retryNum
;
i
++
{
req
:=
&
types
.
ReqHash
{
Hash
:
txHash
}
txDetail
,
err
:=
action
.
grpcClient
.
QueryTransaction
(
context
.
Background
(),
req
)
if
err
!=
nil
{
time
.
Sleep
(
time
.
Second
)
}
else
{
return
txDetail
.
GetHeight
()
}
}
return
-
1
}
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