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
8b29c90a
Commit
8b29c90a
authored
Dec 02, 2018
by
wjx@disanbo.com
Committed by
vipwzw
Dec 04, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update lottery
parent
8222696c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
25 additions
and
116 deletions
+25
-116
lotteryblock.go
plugin/dapp/lottery/executor/lotteryblock.go
+0
-104
lotterydb.go
plugin/dapp/lottery/executor/lotterydb.go
+0
-0
query.go
plugin/dapp/lottery/executor/query.go
+7
-5
lottery.proto
plugin/dapp/lottery/proto/lottery.proto
+15
-7
errors.go
plugin/dapp/lottery/types/errors.go
+1
-0
lottery.pb.go
plugin/dapp/lottery/types/lottery.pb.go
+0
-0
tx.go
plugin/dapp/lottery/types/tx.go
+2
-0
No files found.
plugin/dapp/lottery/executor/lotteryblock.go
View file @
8b29c90a
...
...
@@ -9,59 +9,10 @@ import (
"time"
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/lottery/types"
tickettypes
"github.com/33cn/plugin/plugin/dapp/ticket/types"
)
const
retryNum
=
10
//different impl on main chain and parachain
func
(
action
*
Action
)
getTxActions
(
height
int64
,
blockNum
int64
)
([]
*
tickettypes
.
TicketAction
,
error
)
{
var
txActions
[]
*
tickettypes
.
TicketAction
llog
.
Error
(
"getTxActions"
,
"height"
,
height
,
"blockNum"
,
blockNum
)
if
!
types
.
IsPara
()
{
req
:=
&
types
.
ReqBlocks
{
Start
:
height
-
blockNum
+
1
,
End
:
height
,
IsDetail
:
false
,
Pid
:
[]
string
{
""
}}
blockDetails
,
err
:=
action
.
api
.
GetBlocks
(
req
)
if
err
!=
nil
{
llog
.
Error
(
"getTxActions"
,
"height"
,
height
,
"blockNum"
,
blockNum
,
"err"
,
err
)
return
txActions
,
err
}
for
_
,
block
:=
range
blockDetails
.
Items
{
llog
.
Debug
(
"getTxActions"
,
"blockHeight"
,
block
.
Block
.
Height
,
"blockhash"
,
block
.
Block
.
Hash
())
ticketAction
,
err
:=
action
.
getMinerTx
(
block
.
Block
)
if
err
!=
nil
{
return
txActions
,
err
}
txActions
=
append
(
txActions
,
ticketAction
)
}
return
txActions
,
nil
}
//block height on main
mainHeight
:=
action
.
GetMainHeightByTxHash
(
action
.
txhash
)
if
mainHeight
<
0
{
llog
.
Error
(
"LotteryCreate"
,
"mainHeight"
,
mainHeight
)
return
nil
,
pty
.
ErrLotteryStatus
}
blockDetails
,
err
:=
action
.
GetBlocksOnMain
(
mainHeight
-
blockNum
,
mainHeight
-
1
)
if
err
!=
nil
{
llog
.
Error
(
"LotteryCreate"
,
"mainHeight"
,
mainHeight
)
return
nil
,
pty
.
ErrLotteryStatus
}
for
_
,
block
:=
range
blockDetails
.
Items
{
ticketAction
,
err
:=
action
.
getMinerTx
(
block
.
Block
)
if
err
!=
nil
{
return
txActions
,
err
}
txActions
=
append
(
txActions
,
ticketAction
)
}
return
txActions
,
nil
}
// GetMainHeightByTxHash get Block height
func
(
action
*
Action
)
GetMainHeightByTxHash
(
txHash
[]
byte
)
int64
{
for
i
:=
0
;
i
<
retryNum
;
i
++
{
...
...
@@ -76,58 +27,3 @@ func (action *Action) GetMainHeightByTxHash(txHash []byte) int64 {
return
-
1
}
// GetBlocksOnMain get Block from main chain
func
(
action
*
Action
)
GetBlocksOnMain
(
start
int64
,
end
int64
)
(
*
types
.
BlockDetails
,
error
)
{
req
:=
&
types
.
ReqBlocks
{
Start
:
start
,
End
:
end
,
IsDetail
:
false
,
Pid
:
[]
string
{
""
}}
getBlockSucc
:=
false
var
reply
*
types
.
Reply
var
err
error
for
i
:=
0
;
i
<
retryNum
;
i
++
{
reply
,
err
=
action
.
grpcClient
.
GetBlocks
(
context
.
Background
(),
req
)
if
err
!=
nil
{
llog
.
Error
(
"GetBlocksOnMain"
,
"start"
,
start
,
"end"
,
end
,
"err"
,
err
)
time
.
Sleep
(
time
.
Second
)
}
else
{
getBlockSucc
=
true
break
}
}
if
!
getBlockSucc
{
return
nil
,
err
}
var
blockDetails
types
.
BlockDetails
err
=
types
.
Decode
(
reply
.
Msg
,
&
blockDetails
)
if
err
!=
nil
{
llog
.
Error
(
"GetBlocksOnMain"
,
"err"
,
err
)
return
nil
,
err
}
return
&
blockDetails
,
nil
}
func
(
action
*
Action
)
getMinerTx
(
current
*
types
.
Block
)
(
*
tickettypes
.
TicketAction
,
error
)
{
//检查第一个笔交易的execs, 以及执行状态
if
len
(
current
.
Txs
)
==
0
{
return
nil
,
types
.
ErrEmptyTx
}
baseTx
:=
current
.
Txs
[
0
]
//判断交易类型和执行情况
var
ticketAction
tickettypes
.
TicketAction
err
:=
types
.
Decode
(
baseTx
.
GetPayload
(),
&
ticketAction
)
if
err
!=
nil
{
return
nil
,
err
}
if
ticketAction
.
GetTy
()
!=
tickettypes
.
TicketActionMiner
{
return
nil
,
types
.
ErrCoinBaseTxType
}
//判断交易执行是否OK
if
ticketAction
.
GetMiner
()
==
nil
{
return
nil
,
tickettypes
.
ErrEmptyMinerTx
}
return
&
ticketAction
,
nil
}
plugin/dapp/lottery/executor/lotterydb.go
View file @
8b29c90a
This diff is collapsed.
Click to expand it.
plugin/dapp/lottery/executor/query.go
View file @
8b29c90a
...
...
@@ -16,9 +16,11 @@ func (l *Lottery) Query_GetLotteryNormalInfo(param *pty.ReqLotteryInfo) (types.M
return
nil
,
err
}
return
&
pty
.
ReplyLotteryNormalInfo
{
CreateHeight
:
lottery
.
CreateHeight
,
PurBlockNum
:
lottery
.
PurBlockNum
,
DrawBlockNum
:
lottery
.
DrawBlockNum
,
CreateAddr
:
lottery
.
CreateAddr
},
nil
PurBlockNum
:
lottery
.
PurBlockNum
,
DrawBlockNum
:
lottery
.
DrawBlockNum
,
CreateAddr
:
lottery
.
CreateAddr
,
OpRewardRatio
:
lottery
.
OpRewardRatio
,
DevRewardRatio
:
lottery
.
DevRewardRatio
},
nil
}
// Query_GetLotteryPurchaseAddr for current round
...
...
@@ -28,8 +30,8 @@ func (l *Lottery) Query_GetLotteryPurchaseAddr(param *pty.ReqLotteryInfo) (types
return
nil
,
err
}
reply
:=
&
pty
.
ReplyLotteryPurchaseAddr
{}
for
addr
:=
range
lottery
.
Records
{
reply
.
Address
=
append
(
reply
.
Address
,
a
ddr
)
for
_
,
recs
:=
range
lottery
.
Pur
Records
{
reply
.
Address
=
append
(
reply
.
Address
,
recs
.
A
ddr
)
}
//lottery.Records
return
reply
,
nil
...
...
plugin/dapp/lottery/proto/lottery.proto
100644 → 100755
View file @
8b29c90a
...
...
@@ -13,6 +13,7 @@ message PurchaseRecords {
repeated
PurchaseRecord
record
=
1
;
int64
fundWin
=
2
;
int64
amountOneRound
=
3
;
string
addr
=
4
;
}
message
Lottery
{
...
...
@@ -24,7 +25,7 @@ message Lottery {
int64
drawBlockNum
=
6
;
int64
lastTransToPurState
=
7
;
int64
lastTransToDrawState
=
8
;
map
<
string
,
PurchaseRecords
>
records
=
9
;
//
map<string, PurchaseRecords> records = 9;
int64
totalPurchasedTxNum
=
10
;
string
createAddr
=
11
;
int64
round
=
12
;
...
...
@@ -33,6 +34,9 @@ message Lottery {
int64
lastTransToPurStateOnMain
=
15
;
int64
lastTransToDrawStateOnMain
=
16
;
repeated
MissingRecord
missingRecords
=
17
;
int64
opRewardRatio
=
18
;
int64
devRewardRatio
=
19
;
repeated
PurchaseRecords
purRecords
=
20
;
}
message
MissingRecord
{
...
...
@@ -50,8 +54,10 @@ message LotteryAction {
}
message
LotteryCreate
{
int64
purBlockNum
=
1
;
int64
drawBlockNum
=
2
;
int64
purBlockNum
=
1
;
int64
drawBlockNum
=
2
;
int64
opRewardRatio
=
3
;
int64
devRewardRatio
=
4
;
}
message
LotteryBuy
{
...
...
@@ -117,10 +123,12 @@ message ReqLotteryLuckyHistory {
}
message
ReplyLotteryNormalInfo
{
int64
createHeight
=
1
;
int64
purBlockNum
=
2
;
int64
drawBlockNum
=
3
;
string
createAddr
=
4
;
int64
createHeight
=
1
;
int64
purBlockNum
=
2
;
int64
drawBlockNum
=
3
;
string
createAddr
=
4
;
int64
opRewardRatio
=
5
;
int64
devRewardRatio
=
6
;
}
message
ReplyLotteryCurrentInfo
{
...
...
plugin/dapp/lottery/types/errors.go
View file @
8b29c90a
...
...
@@ -25,4 +25,5 @@ var (
ErrLotteryErrUnableClose
=
errors
.
New
(
"ErrLotteryErrUnableClose"
)
ErrNodeNotExist
=
errors
.
New
(
"ErrNodeNotExist"
)
ErrEmptyMinerTx
=
errors
.
New
(
"ErrEmptyMinerTx"
)
ErrRewardFactor
=
errors
.
New
(
"ErrRewardFactor"
)
)
plugin/dapp/lottery/types/lottery.pb.go
View file @
8b29c90a
This diff is collapsed.
Click to expand it.
plugin/dapp/lottery/types/tx.go
View file @
8b29c90a
...
...
@@ -9,6 +9,8 @@ type LotteryCreateTx struct {
PurBlockNum
int64
`json:"purBlockNum"`
DrawBlockNum
int64
`json:"drawBlockNum"`
Fee
int64
`json:"fee"`
OpRewardRatio
int64
`json:"opRewardRatio"`
DevRewardRatio
int64
`json:"devRewardRatio"`
}
// LotteryBuyTx for construction
...
...
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