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
063535fc
Commit
063535fc
authored
Dec 27, 2018
by
jixing wei
Committed by
vipwzw
Jan 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
randnum
parent
ed0f98f0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
19 deletions
+60
-19
lotteryblock.go
plugin/dapp/lottery/executor/lotteryblock.go
+15
-0
lotterydb.go
plugin/dapp/lottery/executor/lotterydb.go
+17
-7
query.go
plugin/dapp/ticket/executor/query.go
+1
-1
ticketnum.go
plugin/dapp/ticket/executor/ticketnum.go
+27
-11
No files found.
plugin/dapp/lottery/executor/lotteryblock.go
View file @
063535fc
...
...
@@ -27,3 +27,18 @@ func (action *Action) GetMainHeightByTxHash(txHash []byte) int64 {
return
-
1
}
// GetMainBlockHashByHeight get Hash
func
(
action
*
Action
)
GetMainBlockHashByHeight
(
height
int64
)
([]
byte
,
error
)
{
for
i
:=
0
;
i
<
retryNum
;
i
++
{
req
:=
&
types
.
ReqInt
{
Height
:
height
}
replyHash
,
err
:=
action
.
grpcClient
.
GetBlockHash
(
context
.
Background
(),
req
)
if
err
!=
nil
{
time
.
Sleep
(
time
.
Second
)
}
else
{
return
replyHash
.
Hash
,
nil
}
}
return
nil
,
types
.
ErrBlockNotFound
}
plugin/dapp/lottery/executor/lotterydb.go
View file @
063535fc
...
...
@@ -135,10 +135,9 @@ func NewLotteryAction(l *Lottery, tx *types.Transaction, index int) *Action {
fromaddr
:=
tx
.
From
()
msgRecvOp
:=
grpc
.
WithMaxMsgSize
(
grpcRecSize
)
if
types
.
IsPara
()
&&
cfg
.
ParaRemoteGrpcClient
==
""
{
panic
(
"ParaRemoteGrpcClient error"
)
}
conn
,
err
:=
grpc
.
Dial
(
cfg
.
ParaRemoteGrpcClient
,
grpc
.
WithInsecure
(),
msgRecvOp
)
paraRemoteGrpcClient
:=
types
.
Conf
(
"config.consensus"
)
.
GStr
(
"ParaRemoteGrpcClient"
)
conn
,
err
:=
grpc
.
Dial
(
paraRemoteGrpcClient
,
grpc
.
WithInsecure
(),
msgRecvOp
)
if
err
!=
nil
{
panic
(
err
)
...
...
@@ -569,7 +568,6 @@ func (action *Action) LotteryClose(draw *pty.LotteryClose) (*types.Receipt, erro
func
(
action
*
Action
)
findLuckyNum
(
isSolo
bool
,
lott
*
LotteryDB
)
int64
{
var
num
int64
var
msg
types
.
Message
var
err
error
var
hash
[]
byte
if
isSolo
{
//used for internal verification
...
...
@@ -579,7 +577,12 @@ func (action *Action) findLuckyNum(isSolo bool, lott *LotteryDB) int64 {
//在主链上,当前高度查询不到,如果要保证区块个数,高度传入action.height-1
llog
.
Debug
(
"findLuckyNum on randnum module"
)
if
!
types
.
IsPara
()
{
req
:=
&
types
.
ReqRandHash
{
ExecName
:
"ticket"
,
Height
:
action
.
height
-
1
,
BlockNum
:
blockNum
}
blockHash
,
err
:=
action
.
api
.
GetBlockHash
(
&
types
.
ReqInt
{
Height
:
action
.
height
-
1
})
if
err
!=
nil
{
return
-
1
}
req
:=
&
types
.
ReqRandHash
{
ExecName
:
"ticket"
,
Hash
:
blockHash
.
Hash
,
BlockNum
:
blockNum
}
msg
,
err
=
action
.
api
.
Query
(
"ticket"
,
"RandNumHash"
,
req
)
if
err
!=
nil
{
return
-
1
...
...
@@ -592,7 +595,14 @@ func (action *Action) findLuckyNum(isSolo bool, lott *LotteryDB) int64 {
llog
.
Error
(
"findLuckyNum"
,
"mainHeight"
,
mainHeight
)
return
-
1
}
req
:=
&
types
.
ReqRandHash
{
ExecName
:
"ticket"
,
Height
:
mainHeight
,
BlockNum
:
blockNum
}
mainBlockHash
,
err
:=
action
.
GetMainBlockHashByHeight
(
mainHeight
)
if
err
!=
nil
{
llog
.
Error
(
"findLuckyNum"
,
"err"
,
err
)
return
-
1
}
req
:=
&
types
.
ReqRandHash
{
ExecName
:
"ticket"
,
Hash
:
mainBlockHash
,
BlockNum
:
blockNum
}
reply
,
err
:=
action
.
grpcClient
.
QueryRandNum
(
context
.
Background
(),
req
)
if
err
!=
nil
{
return
-
1
...
...
plugin/dapp/ticket/executor/query.go
View file @
063535fc
...
...
@@ -47,5 +47,5 @@ func (ticket *Ticket) Query_MinerSourceList(param *types.ReqString) (types.Messa
// Query_RandNumHash query randnumhash
func
(
ticket
*
Ticket
)
Query_RandNumHash
(
param
*
types
.
ReqRandHash
)
(
types
.
Message
,
error
)
{
return
ticket
.
GetRandNum
(
param
.
H
eight
,
param
.
BlockNum
)
return
ticket
.
GetRandNum
(
param
.
H
ash
,
param
.
BlockNum
)
}
plugin/dapp/ticket/executor/ticketnum.go
View file @
063535fc
...
...
@@ -18,19 +18,19 @@ const (
)
// GetRandNum for ticket executor
func
(
ticket
*
Ticket
)
GetRandNum
(
height
int64
,
blockNum
int64
)
(
types
.
Message
,
error
)
{
tlog
.
Debug
(
"GetRandNum"
,
"
height"
,
height
,
"blockNum"
,
blockNum
)
func
(
ticket
*
Ticket
)
GetRandNum
(
blockHash
[]
byte
,
blockNum
int64
)
(
types
.
Message
,
error
)
{
tlog
.
Debug
(
"GetRandNum"
,
"
blockHash"
,
blockHash
,
"blockNum"
,
blockNum
)
if
blockNum
<
minBlockNum
{
blockNum
=
minBlockNum
}
else
if
blockNum
>
maxBlockNum
{
blockNum
=
maxBlockNum
}
if
blockNum
>=
height
{
return
nil
,
types
.
ErrNotFound
if
len
(
blockHash
)
==
0
{
return
nil
,
types
.
Err
Block
NotFound
}
txActions
,
err
:=
ticket
.
getTxActions
(
height
,
blockNum
)
txActions
,
err
:=
ticket
.
getTxActions
(
blockHash
,
blockNum
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -54,20 +54,36 @@ func (ticket *Ticket) GetRandNum(height int64, blockNum int64) (types.Message, e
return
&
types
.
ReplyHash
{
Hash
:
modify
},
nil
}
func
(
ticket
*
Ticket
)
getTxActions
(
height
int64
,
blockNum
int64
)
([]
*
tickettypes
.
TicketAction
,
error
)
{
func
(
ticket
*
Ticket
)
getTxActions
(
blockHash
[]
byte
,
blockNum
int64
)
([]
*
tickettypes
.
TicketAction
,
error
)
{
var
txActions
[]
*
tickettypes
.
TicketAction
var
reqHashes
types
.
ReqHashes
currHash
:=
blockHash
tlog
.
Debug
(
"getTxActions"
,
"blockHash"
,
blockHash
,
"blockNum"
,
blockNum
)
tlog
.
Debug
(
"getTxActions"
,
"height"
,
height
,
"blockNum"
,
blockNum
)
//根据blockHash,查询block,循环blockNum
for
blockNum
>
0
{
req
:=
types
.
ReqHash
{
Hash
:
currHash
}
req
:=
&
types
.
ReqBlocks
{
Start
:
height
-
blockNum
+
1
,
End
:
height
,
IsDetail
:
false
,
Pid
:
[]
string
{
""
}}
tempBlock
,
err
:=
ticket
.
GetAPI
()
.
GetBlockOverview
(
&
req
)
if
err
!=
nil
{
return
txActions
,
err
}
reqHashes
.
Hashes
=
append
(
reqHashes
.
Hashes
,
currHash
)
currHash
=
tempBlock
.
Head
.
ParentHash
if
tempBlock
.
Head
.
Height
<
0
&&
blockNum
>
1
{
return
txActions
,
types
.
ErrBlockNotFound
}
blockNum
--
}
blockDetails
,
err
:=
ticket
.
GetAPI
()
.
GetBlock
s
(
req
)
blockDetails
,
err
:=
ticket
.
GetAPI
()
.
GetBlock
ByHashes
(
&
reqHashes
)
if
err
!=
nil
{
tlog
.
Error
(
"getTxActions"
,
"
height"
,
height
,
"blockNum"
,
blockNum
,
"err"
,
err
)
tlog
.
Error
(
"getTxActions"
,
"
blockHash"
,
blockHash
,
"blockNum"
,
blockNum
,
"err"
,
err
)
return
txActions
,
err
}
for
_
,
block
:=
range
blockDetails
.
Items
{
//
tlog.Debug("getTxActions", "blockHeight", block.Block.Height, "blockhash", block.Block.Hash())
tlog
.
Debug
(
"getTxActions"
,
"blockHeight"
,
block
.
Block
.
Height
,
"blockhash"
,
block
.
Block
.
Hash
())
ticketAction
,
err
:=
ticket
.
getMinerTx
(
block
.
Block
)
if
err
!=
nil
{
return
txActions
,
err
...
...
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