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
3c399015
Commit
3c399015
authored
Dec 06, 2018
by
wjx@disanbo.com
Committed by
vipwzw
Dec 07, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add query item
parent
1fb4c5b2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
77 additions
and
17 deletions
+77
-17
lottery.go
plugin/dapp/lottery/executor/lottery.go
+1
-1
lotterydb.go
plugin/dapp/lottery/executor/lotterydb.go
+66
-15
query.go
plugin/dapp/lottery/executor/query.go
+2
-1
lottery.proto
plugin/dapp/lottery/proto/lottery.proto
+8
-0
lottery.pb.go
plugin/dapp/lottery/types/lottery.pb.go
+0
-0
No files found.
plugin/dapp/lottery/executor/lottery.go
View file @
3c399015
...
@@ -180,7 +180,7 @@ func (lott *Lottery) updateLotteryBuy(lotterylog *pty.ReceiptLottery, isAdd bool
...
@@ -180,7 +180,7 @@ func (lott *Lottery) updateLotteryBuy(lotterylog *pty.ReceiptLottery, isAdd bool
func
(
lott
*
Lottery
)
saveLotteryDraw
(
lotterylog
*
pty
.
ReceiptLottery
)
(
kvs
[]
*
types
.
KeyValue
)
{
func
(
lott
*
Lottery
)
saveLotteryDraw
(
lotterylog
*
pty
.
ReceiptLottery
)
(
kvs
[]
*
types
.
KeyValue
)
{
key
:=
calcLotteryDrawKey
(
lotterylog
.
LotteryId
,
lotterylog
.
Round
)
key
:=
calcLotteryDrawKey
(
lotterylog
.
LotteryId
,
lotterylog
.
Round
)
record
:=
&
pty
.
LotteryDrawRecord
{
Number
:
lotterylog
.
LuckyNumber
,
Round
:
lotterylog
.
Round
,
Time
:
lotterylog
.
Time
,
TxHash
:
lotterylog
.
TxHash
}
record
:=
&
pty
.
LotteryDrawRecord
{
Number
:
lotterylog
.
LuckyNumber
,
Round
:
lotterylog
.
Round
,
Time
:
lotterylog
.
Time
,
TxHash
:
lotterylog
.
TxHash
,
TotalAddrNum
:
lotterylog
.
TotalAddrNum
,
BuyAmount
:
lotterylog
.
BuyAmount
}
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
record
)}
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
record
)}
kvs
=
append
(
kvs
,
kv
)
kvs
=
append
(
kvs
,
kv
)
return
kvs
return
kvs
...
...
plugin/dapp/lottery/executor/lotterydb.go
View file @
3c399015
...
@@ -149,18 +149,34 @@ func NewLotteryAction(l *Lottery, tx *types.Transaction, index int) *Action {
...
@@ -149,18 +149,34 @@ func NewLotteryAction(l *Lottery, tx *types.Transaction, index int) *Action {
l
.
GetHeight
(),
dapp
.
ExecAddress
(
string
(
tx
.
Execer
)),
l
.
GetDifficulty
(),
l
.
GetAPI
(),
conn
,
grpcClient
,
index
}
l
.
GetHeight
(),
dapp
.
ExecAddress
(
string
(
tx
.
Execer
)),
l
.
GetDifficulty
(),
l
.
GetAPI
(),
conn
,
grpcClient
,
index
}
}
}
// GetReceiptLog generate logs for all lottery action
// GetLottCommonRecipt generate logs for lottery common action
func
(
action
*
Action
)
GetReceiptLog
(
lottery
*
pty
.
Lottery
,
preStatus
int32
,
logTy
int32
,
func
(
action
*
Action
)
GetLottCommonRecipt
(
lottery
*
pty
.
Lottery
,
preStatus
int32
)
*
pty
.
ReceiptLottery
{
round
int64
,
buyNumber
int64
,
amount
int64
,
way
int64
,
luckyNum
int64
,
updateInfo
*
pty
.
LotteryUpdateBuyInfo
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
l
:=
&
pty
.
ReceiptLottery
{}
l
:=
&
pty
.
ReceiptLottery
{}
log
.
Ty
=
logTy
l
.
LotteryId
=
lottery
.
LotteryId
l
.
LotteryId
=
lottery
.
LotteryId
l
.
Status
=
lottery
.
Status
l
.
Status
=
lottery
.
Status
l
.
PrevStatus
=
preStatus
l
.
PrevStatus
=
preStatus
if
logTy
==
pty
.
TyLogLotteryBuy
{
return
l
}
// GetCreateReceiptLog generate logs for lottery create action
func
(
action
*
Action
)
GetCreateReceiptLog
(
lottery
*
pty
.
Lottery
,
preStatus
int32
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogLotteryCreate
l
:=
action
.
GetLottCommonRecipt
(
lottery
,
preStatus
)
log
.
Log
=
types
.
Encode
(
l
)
return
log
}
// GetBuyReceiptLog generate logs for lottery buy action
func
(
action
*
Action
)
GetBuyReceiptLog
(
lottery
*
pty
.
Lottery
,
preStatus
int32
,
round
int64
,
buyNumber
int64
,
amount
int64
,
way
int64
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogLotteryBuy
l
:=
action
.
GetLottCommonRecipt
(
lottery
,
preStatus
)
l
.
Round
=
round
l
.
Round
=
round
l
.
Number
=
buyNumber
l
.
Number
=
buyNumber
l
.
Amount
=
amount
l
.
Amount
=
amount
...
@@ -169,18 +185,43 @@ func (action *Action) GetReceiptLog(lottery *pty.Lottery, preStatus int32, logTy
...
@@ -169,18 +185,43 @@ func (action *Action) GetReceiptLog(lottery *pty.Lottery, preStatus int32, logTy
l
.
Index
=
action
.
GetIndex
()
l
.
Index
=
action
.
GetIndex
()
l
.
Time
=
action
.
blocktime
l
.
Time
=
action
.
blocktime
l
.
TxHash
=
common
.
ToHex
(
action
.
txhash
)
l
.
TxHash
=
common
.
ToHex
(
action
.
txhash
)
}
if
logTy
==
pty
.
TyLogLotteryDraw
{
log
.
Log
=
types
.
Encode
(
l
)
return
log
}
// GetDrawReceiptLog generate logs for lottery draw action
func
(
action
*
Action
)
GetDrawReceiptLog
(
lottery
*
pty
.
Lottery
,
preStatus
int32
,
round
int64
,
luckyNum
int64
,
updateInfo
*
pty
.
LotteryUpdateBuyInfo
,
addrNumThisRound
int64
,
buyAmountThisRound
int64
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogLotteryDraw
l
:=
action
.
GetLottCommonRecipt
(
lottery
,
preStatus
)
l
.
Round
=
round
l
.
Round
=
round
l
.
LuckyNumber
=
luckyNum
l
.
LuckyNumber
=
luckyNum
l
.
Time
=
action
.
blocktime
l
.
Time
=
action
.
blocktime
l
.
TxHash
=
common
.
ToHex
(
action
.
txhash
)
l
.
TxHash
=
common
.
ToHex
(
action
.
txhash
)
l
.
TotalAddrNum
=
addrNumThisRound
l
.
BuyAmount
=
buyAmountThisRound
if
len
(
updateInfo
.
BuyInfo
)
>
0
{
if
len
(
updateInfo
.
BuyInfo
)
>
0
{
l
.
UpdateInfo
=
updateInfo
l
.
UpdateInfo
=
updateInfo
}
}
}
log
.
Log
=
types
.
Encode
(
l
)
log
.
Log
=
types
.
Encode
(
l
)
return
log
}
// GetCloseReceiptLog generate logs for lottery close action
func
(
action
*
Action
)
GetCloseReceiptLog
(
lottery
*
pty
.
Lottery
,
preStatus
int32
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogLotteryClose
l
:=
action
.
GetLottCommonRecipt
(
lottery
,
preStatus
)
log
.
Log
=
types
.
Encode
(
l
)
return
log
return
log
}
}
...
@@ -228,6 +269,8 @@ func (action *Action) LotteryCreate(create *pty.LotteryCreate) (*types.Receipt,
...
@@ -228,6 +269,8 @@ func (action *Action) LotteryCreate(create *pty.LotteryCreate) (*types.Receipt,
lott
.
OpRewardRatio
=
create
.
OpRewardRatio
lott
.
OpRewardRatio
=
create
.
OpRewardRatio
lott
.
DevRewardRatio
=
create
.
DevRewardRatio
lott
.
DevRewardRatio
=
create
.
DevRewardRatio
lott
.
TotalAddrNum
=
0
lott
.
BuyAmount
=
0
llog
.
Debug
(
"LotteryCreate"
,
"OpRewardRatio"
,
lott
.
OpRewardRatio
,
"DevRewardRatio"
,
lott
.
DevRewardRatio
)
llog
.
Debug
(
"LotteryCreate"
,
"OpRewardRatio"
,
lott
.
OpRewardRatio
,
"DevRewardRatio"
,
lott
.
DevRewardRatio
)
if
types
.
IsPara
()
{
if
types
.
IsPara
()
{
mainHeight
:=
action
.
GetMainHeightByTxHash
(
action
.
txhash
)
mainHeight
:=
action
.
GetMainHeightByTxHash
(
action
.
txhash
)
...
@@ -243,7 +286,7 @@ func (action *Action) LotteryCreate(create *pty.LotteryCreate) (*types.Receipt,
...
@@ -243,7 +286,7 @@ func (action *Action) LotteryCreate(create *pty.LotteryCreate) (*types.Receipt,
lott
.
Save
(
action
.
db
)
lott
.
Save
(
action
.
db
)
kv
=
append
(
kv
,
lott
.
GetKVSet
()
...
)
kv
=
append
(
kv
,
lott
.
GetKVSet
()
...
)
receiptLog
:=
action
.
Get
ReceiptLog
(
&
lott
.
Lottery
,
0
,
pty
.
TyLogLotteryCreate
,
0
,
0
,
0
,
0
,
0
,
nil
)
receiptLog
:=
action
.
Get
CreateReceiptLog
(
&
lott
.
Lottery
,
0
)
logs
=
append
(
logs
,
receiptLog
)
logs
=
append
(
logs
,
receiptLog
)
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
...
@@ -352,6 +395,7 @@ func (action *Action) LotteryBuy(buy *pty.LotteryBuy) (*types.Receipt, error) {
...
@@ -352,6 +395,7 @@ func (action *Action) LotteryBuy(buy *pty.LotteryBuy) (*types.Receipt, error) {
kv
=
append
(
kv
,
receipt
.
KV
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
lott
.
Fund
+=
buy
.
GetAmount
()
lott
.
Fund
+=
buy
.
GetAmount
()
lott
.
BuyAmount
+=
buy
.
GetAmount
()
lott
.
TotalPurchasedTxNum
++
lott
.
TotalPurchasedTxNum
++
newAddr
:=
true
newAddr
:=
true
...
@@ -370,12 +414,13 @@ func (action *Action) LotteryBuy(buy *pty.LotteryBuy) (*types.Receipt, error) {
...
@@ -370,12 +414,13 @@ func (action *Action) LotteryBuy(buy *pty.LotteryBuy) (*types.Receipt, error) {
initrecord
.
AmountOneRound
=
buy
.
Amount
initrecord
.
AmountOneRound
=
buy
.
Amount
initrecord
.
Addr
=
action
.
fromaddr
initrecord
.
Addr
=
action
.
fromaddr
lott
.
PurRecords
=
append
(
lott
.
PurRecords
,
initrecord
)
lott
.
PurRecords
=
append
(
lott
.
PurRecords
,
initrecord
)
lott
.
TotalAddrNum
++
}
}
lott
.
Save
(
action
.
db
)
lott
.
Save
(
action
.
db
)
kv
=
append
(
kv
,
lott
.
GetKVSet
()
...
)
kv
=
append
(
kv
,
lott
.
GetKVSet
()
...
)
receiptLog
:=
action
.
Get
ReceiptLog
(
&
lott
.
Lottery
,
preStatus
,
pty
.
TyLogLotteryBuy
,
lott
.
Round
,
buy
.
GetNumber
(),
buy
.
GetAmount
(),
buy
.
GetWay
(),
0
,
nil
)
receiptLog
:=
action
.
Get
BuyReceiptLog
(
&
lott
.
Lottery
,
preStatus
,
lott
.
Round
,
buy
.
GetNumber
(),
buy
.
GetAmount
(),
buy
.
GetWay
()
)
logs
=
append
(
logs
,
receiptLog
)
logs
=
append
(
logs
,
receiptLog
)
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
...
@@ -427,6 +472,10 @@ func (action *Action) LotteryDraw(draw *pty.LotteryDraw) (*types.Receipt, error)
...
@@ -427,6 +472,10 @@ func (action *Action) LotteryDraw(draw *pty.LotteryDraw) (*types.Receipt, error)
//}
//}
}
}
//record addr and amount this round
addrNumThisRound
:=
lott
.
TotalAddrNum
buyAmountThisRound
:=
lott
.
BuyAmount
rec
,
updateInfo
,
err
:=
action
.
checkDraw
(
lott
)
rec
,
updateInfo
,
err
:=
action
.
checkDraw
(
lott
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -437,7 +486,7 @@ func (action *Action) LotteryDraw(draw *pty.LotteryDraw) (*types.Receipt, error)
...
@@ -437,7 +486,7 @@ func (action *Action) LotteryDraw(draw *pty.LotteryDraw) (*types.Receipt, error)
lott
.
Save
(
action
.
db
)
lott
.
Save
(
action
.
db
)
kv
=
append
(
kv
,
lott
.
GetKVSet
()
...
)
kv
=
append
(
kv
,
lott
.
GetKVSet
()
...
)
receiptLog
:=
action
.
Get
ReceiptLog
(
&
lott
.
Lottery
,
preStatus
,
pty
.
TyLogLotteryDraw
,
lott
.
Round
,
0
,
0
,
0
,
lott
.
LuckyNumber
,
updateInfo
)
receiptLog
:=
action
.
Get
DrawReceiptLog
(
&
lott
.
Lottery
,
preStatus
,
lott
.
Round
,
lott
.
LuckyNumber
,
updateInfo
,
addrNumThisRound
,
buyAmountThisRound
)
logs
=
append
(
logs
,
receiptLog
)
logs
=
append
(
logs
,
receiptLog
)
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
...
@@ -508,7 +557,7 @@ func (action *Action) LotteryClose(draw *pty.LotteryClose) (*types.Receipt, erro
...
@@ -508,7 +557,7 @@ func (action *Action) LotteryClose(draw *pty.LotteryClose) (*types.Receipt, erro
lott
.
Save
(
action
.
db
)
lott
.
Save
(
action
.
db
)
kv
=
append
(
kv
,
lott
.
GetKVSet
()
...
)
kv
=
append
(
kv
,
lott
.
GetKVSet
()
...
)
receiptLog
:=
action
.
Get
ReceiptLog
(
&
lott
.
Lottery
,
preStatus
,
pty
.
TyLogLotteryClose
,
0
,
0
,
0
,
0
,
0
,
nil
)
receiptLog
:=
action
.
Get
CloseReceiptLog
(
&
lott
.
Lottery
,
preStatus
)
logs
=
append
(
logs
,
receiptLog
)
logs
=
append
(
logs
,
receiptLog
)
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
...
@@ -677,6 +726,8 @@ func (action *Action) checkDraw(lott *LotteryDB) (*types.Receipt, *pty.LotteryUp
...
@@ -677,6 +726,8 @@ func (action *Action) checkDraw(lott *LotteryDB) (*types.Receipt, *pty.LotteryUp
lott
.
Status
=
pty
.
LotteryDrawed
lott
.
Status
=
pty
.
LotteryDrawed
lott
.
TotalPurchasedTxNum
=
0
lott
.
TotalPurchasedTxNum
=
0
lott
.
LuckyNumber
=
luckynum
lott
.
LuckyNumber
=
luckynum
lott
.
TotalAddrNum
=
0
lott
.
BuyAmount
=
0
action
.
recordMissing
(
lott
)
action
.
recordMissing
(
lott
)
if
types
.
IsPara
()
{
if
types
.
IsPara
()
{
...
...
plugin/dapp/lottery/executor/query.go
View file @
3c399015
...
@@ -55,7 +55,8 @@ func (l *Lottery) Query_GetLotteryCurrentInfo(param *pty.ReqLotteryInfo) (types.
...
@@ -55,7 +55,8 @@ func (l *Lottery) Query_GetLotteryCurrentInfo(param *pty.ReqLotteryInfo) (types.
PurBlockNum
:
lottery
.
PurBlockNum
,
PurBlockNum
:
lottery
.
PurBlockNum
,
DrawBlockNum
:
lottery
.
DrawBlockNum
,
DrawBlockNum
:
lottery
.
DrawBlockNum
,
MissingRecords
:
lottery
.
MissingRecords
,
MissingRecords
:
lottery
.
MissingRecords
,
}
TotalAddrNum
:
lottery
.
TotalAddrNum
,
BuyAmount
:
lottery
.
BuyAmount
}
return
reply
,
nil
return
reply
,
nil
}
}
...
...
plugin/dapp/lottery/proto/lottery.proto
View file @
3c399015
...
@@ -37,6 +37,8 @@ message Lottery {
...
@@ -37,6 +37,8 @@ message Lottery {
int64
opRewardRatio
=
18
;
int64
opRewardRatio
=
18
;
int64
devRewardRatio
=
19
;
int64
devRewardRatio
=
19
;
repeated
PurchaseRecords
purRecords
=
20
;
repeated
PurchaseRecords
purRecords
=
20
;
int64
totalAddrNum
=
21
;
int64
buyAmount
=
22
;
}
}
message
MissingRecord
{
message
MissingRecord
{
...
@@ -89,6 +91,8 @@ message ReceiptLottery {
...
@@ -89,6 +91,8 @@ message ReceiptLottery {
LotteryUpdateBuyInfo
updateInfo
=
11
;
LotteryUpdateBuyInfo
updateInfo
=
11
;
int64
way
=
12
;
int64
way
=
12
;
int64
index
=
13
;
int64
index
=
13
;
int64
totalAddrNum
=
14
;
int64
buyAmount
=
15
;
}
}
message
ReqLotteryInfo
{
message
ReqLotteryInfo
{
...
@@ -144,6 +148,8 @@ message ReplyLotteryCurrentInfo {
...
@@ -144,6 +148,8 @@ message ReplyLotteryCurrentInfo {
int64
purBlockNum
=
10
;
int64
purBlockNum
=
10
;
int64
drawBlockNum
=
11
;
int64
drawBlockNum
=
11
;
repeated
MissingRecord
missingRecords
=
12
;
repeated
MissingRecord
missingRecords
=
12
;
int64
totalAddrNum
=
13
;
int64
buyAmount
=
14
;
}
}
message
ReplyLotteryHistoryLuckyNumber
{
message
ReplyLotteryHistoryLuckyNumber
{
...
@@ -180,6 +186,8 @@ message LotteryDrawRecord {
...
@@ -180,6 +186,8 @@ message LotteryDrawRecord {
int64
round
=
2
;
int64
round
=
2
;
int64
time
=
3
;
int64
time
=
3
;
string
txHash
=
4
;
string
txHash
=
4
;
int64
totalAddrNum
=
5
;
int64
buyAmount
=
6
;
}
}
message
LotteryDrawRecords
{
message
LotteryDrawRecords
{
...
...
plugin/dapp/lottery/types/lottery.pb.go
View file @
3c399015
This diff is collapsed.
Click to expand it.
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