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
9ea7ec98
Commit
9ea7ec98
authored
Nov 19, 2018
by
wjx@disanbo.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix vet
parent
c2dcd5af
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
30 deletions
+25
-30
lottery.go
plugin/dapp/lottery/executor/lottery.go
+7
-10
lotteryblock.go
plugin/dapp/lottery/executor/lotteryblock.go
+3
-3
lotterydb.go
plugin/dapp/lottery/executor/lotterydb.go
+10
-10
query.go
plugin/dapp/lottery/executor/query.go
+4
-4
lottery.go
plugin/dapp/lottery/types/lottery.go
+1
-3
No files found.
plugin/dapp/lottery/executor/lottery.go
View file @
9ea7ec98
...
...
@@ -124,9 +124,8 @@ func (lott *Lottery) findLotteryDrawRecord(key []byte) (*pty.LotteryDrawRecord,
func
(
lott
*
Lottery
)
saveLotteryBuy
(
lotterylog
*
pty
.
ReceiptLottery
)
(
kvs
[]
*
types
.
KeyValue
)
{
key
:=
calcLotteryBuyKey
(
lotterylog
.
LotteryId
,
lotterylog
.
Addr
,
lotterylog
.
Round
,
lotterylog
.
Index
)
kv
:=
&
types
.
KeyValue
{}
record
:=
&
pty
.
LotteryBuyRecord
{
lotterylog
.
Number
,
lotterylog
.
Amount
,
lotterylog
.
Round
,
0
,
lotterylog
.
Way
,
lotterylog
.
Index
,
lotterylog
.
Time
,
lotterylog
.
TxHash
}
kv
=
&
types
.
KeyValue
{
key
,
types
.
Encode
(
record
)}
record
:=
&
pty
.
LotteryBuyRecord
{
Number
:
lotterylog
.
Number
,
Amount
:
lotterylog
.
Amount
,
Round
:
lotterylog
.
Round
,
Type
:
0
,
Way
:
lotterylog
.
Way
,
Index
:
lotterylog
.
Index
,
Time
:
lotterylog
.
Time
,
TxHash
:
lotterylog
.
TxHash
}
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
record
)}
kvs
=
append
(
kvs
,
kv
)
return
kvs
...
...
@@ -135,7 +134,7 @@ func (lott *Lottery) saveLotteryBuy(lotterylog *pty.ReceiptLottery) (kvs []*type
func
(
lott
*
Lottery
)
deleteLotteryBuy
(
lotterylog
*
pty
.
ReceiptLottery
)
(
kvs
[]
*
types
.
KeyValue
)
{
key
:=
calcLotteryBuyKey
(
lotterylog
.
LotteryId
,
lotterylog
.
Addr
,
lotterylog
.
Round
,
lotterylog
.
Index
)
kv
:=
&
types
.
KeyValue
{
key
,
nil
}
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
}
kvs
=
append
(
kvs
,
kv
)
return
kvs
}
...
...
@@ -162,7 +161,6 @@ func (lott *Lottery) updateLotteryBuy(lotterylog *pty.ReceiptLottery, isAdd bool
if
err
!=
nil
||
record
==
nil
{
return
kvs
}
kv
:=
&
types
.
KeyValue
{}
if
isAdd
{
llog
.
Debug
(
"updateLotteryBuy update key"
)
...
...
@@ -171,7 +169,7 @@ func (lott *Lottery) updateLotteryBuy(lotterylog *pty.ReceiptLottery, isAdd bool
record
.
Type
=
0
}
kv
=
&
types
.
KeyValue
{
key
,
types
.
Encode
(
record
)}
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
record
)}
kvs
=
append
(
kvs
,
kv
)
}
}
...
...
@@ -182,16 +180,15 @@ func (lott *Lottery) updateLotteryBuy(lotterylog *pty.ReceiptLottery, isAdd bool
func
(
lott
*
Lottery
)
saveLotteryDraw
(
lotterylog
*
pty
.
ReceiptLottery
)
(
kvs
[]
*
types
.
KeyValue
)
{
key
:=
calcLotteryDrawKey
(
lotterylog
.
LotteryId
,
lotterylog
.
Round
)
kv
:=
&
types
.
KeyValue
{}
record
:=
&
pty
.
LotteryDrawRecord
{
lotterylog
.
LuckyNumber
,
lotterylog
.
Round
,
lotterylog
.
Time
,
lotterylog
.
TxHash
}
kv
=
&
types
.
KeyValue
{
key
,
types
.
Encode
(
record
)}
record
:=
&
pty
.
LotteryDrawRecord
{
Number
:
lotterylog
.
LuckyNumber
,
Round
:
lotterylog
.
Round
,
Time
:
lotterylog
.
Time
,
TxHash
:
lotterylog
.
TxHash
}
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
record
)}
kvs
=
append
(
kvs
,
kv
)
return
kvs
}
func
(
lott
*
Lottery
)
deleteLotteryDraw
(
lotterylog
*
pty
.
ReceiptLottery
)
(
kvs
[]
*
types
.
KeyValue
)
{
key
:=
calcLotteryDrawKey
(
lotterylog
.
LotteryId
,
lotterylog
.
Round
)
kv
:=
&
types
.
KeyValue
{
key
,
nil
}
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
}
kvs
=
append
(
kvs
,
kv
)
return
kvs
}
...
...
plugin/dapp/lottery/executor/lotteryblock.go
View file @
9ea7ec98
...
...
@@ -20,7 +20,7 @@ func (action *Action) getTxActions(height int64, blockNum int64) ([]*tickettypes
var
txActions
[]
*
tickettypes
.
TicketAction
llog
.
Error
(
"getTxActions"
,
"height"
,
height
,
"blockNum"
,
blockNum
)
if
!
types
.
IsPara
()
{
req
:=
&
types
.
ReqBlocks
{
height
-
blockNum
+
1
,
height
,
false
,
[]
string
{
""
}}
req
:=
&
types
.
ReqBlocks
{
Start
:
height
-
blockNum
+
1
,
End
:
height
,
IsDetail
:
false
,
Pid
:
[]
string
{
""
}}
blockDetails
,
err
:=
action
.
api
.
GetBlocks
(
req
)
if
err
!=
nil
{
...
...
@@ -65,7 +65,7 @@ func (action *Action) getTxActions(height int64, blockNum int64) ([]*tickettypes
// GetMainHeightByTxHash get Block height
func
(
action
*
Action
)
GetMainHeightByTxHash
(
txHash
[]
byte
)
int64
{
for
i
:=
0
;
i
<
retryNum
;
i
++
{
req
:=
&
types
.
ReqHash
{
txHash
}
req
:=
&
types
.
ReqHash
{
Hash
:
txHash
}
txDetail
,
err
:=
action
.
grpcClient
.
QueryTransaction
(
context
.
Background
(),
req
)
if
err
!=
nil
{
time
.
Sleep
(
time
.
Second
)
...
...
@@ -79,7 +79,7 @@ func (action *Action) GetMainHeightByTxHash(txHash []byte) int64 {
// GetBlocksOnMain get Block from main chain
func
(
action
*
Action
)
GetBlocksOnMain
(
start
int64
,
end
int64
)
(
*
types
.
BlockDetails
,
error
)
{
req
:=
&
types
.
ReqBlocks
{
start
,
end
,
false
,
[]
string
{
""
}}
req
:=
&
types
.
ReqBlocks
{
Start
:
start
,
End
:
end
,
IsDetail
:
false
,
Pid
:
[]
string
{
""
}}
getBlockSucc
:=
false
var
reply
*
types
.
Reply
var
err
error
...
...
plugin/dapp/lottery/executor/lotterydb.go
View file @
9ea7ec98
...
...
@@ -79,7 +79,7 @@ func NewLotteryDB(lotteryID string, purBlock int64, drawBlock int64,
lott
.
MissingRecords
=
make
([]
*
pty
.
MissingRecord
,
5
)
for
index
:=
range
lott
.
MissingRecords
{
tempTimes
:=
make
([]
int32
,
10
)
lott
.
MissingRecords
[
index
]
=
&
pty
.
MissingRecord
{
tempTimes
}
lott
.
MissingRecords
[
index
]
=
&
pty
.
MissingRecord
{
Times
:
tempTimes
}
}
return
lott
}
...
...
@@ -87,7 +87,7 @@ func NewLotteryDB(lotteryID string, purBlock int64, drawBlock int64,
// GetKVSet for LotteryDB
func
(
lott
*
LotteryDB
)
GetKVSet
()
(
kvset
[]
*
types
.
KeyValue
)
{
value
:=
types
.
Encode
(
&
lott
.
Lottery
)
kvset
=
append
(
kvset
,
&
types
.
KeyValue
{
Key
(
lott
.
LotteryId
),
value
})
kvset
=
append
(
kvset
,
&
types
.
KeyValue
{
Key
:
Key
(
lott
.
LotteryId
),
Value
:
value
})
return
kvset
}
...
...
@@ -230,7 +230,7 @@ func (action *Action) LotteryCreate(create *pty.LotteryCreate) (*types.Receipt,
receiptLog
:=
action
.
GetReceiptLog
(
&
lott
.
Lottery
,
0
,
pty
.
TyLogLotteryCreate
,
0
,
0
,
0
,
0
,
0
,
nil
)
logs
=
append
(
logs
,
receiptLog
)
receipt
=
&
types
.
Receipt
{
types
.
ExecOk
,
kv
,
logs
}
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
}
...
...
@@ -316,7 +316,7 @@ func (action *Action) LotteryBuy(buy *pty.LotteryBuy) (*types.Receipt, error) {
lott
.
Records
=
make
(
map
[
string
]
*
pty
.
PurchaseRecords
)
}
newRecord
:=
&
pty
.
PurchaseRecord
{
buy
.
GetAmount
(),
buy
.
GetNumber
(),
action
.
GetIndex
(),
buy
.
GetWay
()}
newRecord
:=
&
pty
.
PurchaseRecord
{
Amount
:
buy
.
GetAmount
(),
Number
:
buy
.
GetNumber
(),
Index
:
action
.
GetIndex
(),
Way
:
buy
.
GetWay
()}
llog
.
Debug
(
"LotteryBuy"
,
"amount"
,
buy
.
GetAmount
(),
"number"
,
buy
.
GetNumber
())
/**********
...
...
@@ -360,7 +360,7 @@ func (action *Action) LotteryBuy(buy *pty.LotteryBuy) (*types.Receipt, error) {
receiptLog
:=
action
.
GetReceiptLog
(
&
lott
.
Lottery
,
preStatus
,
pty
.
TyLogLotteryBuy
,
lott
.
Round
,
buy
.
GetNumber
(),
buy
.
GetAmount
(),
buy
.
GetWay
(),
0
,
nil
)
logs
=
append
(
logs
,
receiptLog
)
receipt
=
&
types
.
Receipt
{
types
.
ExecOk
,
kv
,
logs
}
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
}
...
...
@@ -424,7 +424,7 @@ func (action *Action) LotteryDraw(draw *pty.LotteryDraw) (*types.Receipt, error)
receiptLog
:=
action
.
GetReceiptLog
(
&
lott
.
Lottery
,
preStatus
,
pty
.
TyLogLotteryDraw
,
lott
.
Round
,
0
,
0
,
0
,
lott
.
LuckyNumber
,
updateInfo
)
logs
=
append
(
logs
,
receiptLog
)
receipt
=
&
types
.
Receipt
{
types
.
ExecOk
,
kv
,
logs
}
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
}
...
...
@@ -502,7 +502,7 @@ func (action *Action) LotteryClose(draw *pty.LotteryClose) (*types.Receipt, erro
receiptLog
:=
action
.
GetReceiptLog
(
&
lott
.
Lottery
,
preStatus
,
pty
.
TyLogLotteryClose
,
0
,
0
,
0
,
0
,
0
,
nil
)
logs
=
append
(
logs
,
receiptLog
)
return
&
types
.
Receipt
{
types
.
ExecOk
,
kv
,
logs
},
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
}
// GetCalculableHash return hash for calculation
...
...
@@ -513,7 +513,7 @@ func (action *Action) GetCalculableHash(beg, end int64, randMolNum int64) ([]byt
//last := []byte("last")
newmodify
:=
""
for
i
:=
beg
;
i
<
end
;
i
+=
randMolNum
{
req
:=
&
types
.
ReqBlocks
{
i
,
i
,
false
,
[]
string
{
""
}}
req
:=
&
types
.
ReqBlocks
{
Start
:
i
,
End
:
i
,
IsDetail
:
false
,
Pid
:
[]
string
{
""
}}
blocks
,
err
:=
action
.
api
.
GetBlocks
(
req
)
if
err
!=
nil
{
return
[]
byte
{},
err
...
...
@@ -617,7 +617,7 @@ func (action *Action) checkDraw(lott *LotteryDB) (*types.Receipt, *pty.LotteryUp
for
_
,
rec
:=
range
lott
.
Records
[
addr
]
.
Record
{
fund
,
fundType
:=
checkFundAmount
(
luckynum
,
rec
.
Number
,
rec
.
Way
)
if
fund
!=
0
{
newUpdateRec
:=
&
pty
.
LotteryUpdateRec
{
rec
.
Index
,
fundType
}
newUpdateRec
:=
&
pty
.
LotteryUpdateRec
{
Index
:
rec
.
Index
,
Type
:
fundType
}
if
update
,
ok
:=
updateInfo
.
BuyInfo
[
addr
];
ok
{
update
.
Records
=
append
(
update
.
Records
,
newUpdateRec
)
}
else
{
...
...
@@ -693,7 +693,7 @@ func (action *Action) checkDraw(lott *LotteryDB) (*types.Receipt, *pty.LotteryUp
lott
.
LastTransToDrawStateOnMain
=
mainHeight
}
return
&
types
.
Receipt
{
types
.
ExecOk
,
kv
,
logs
},
&
updateInfo
,
nil
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
&
updateInfo
,
nil
}
func
(
action
*
Action
)
recordMissing
(
lott
*
LotteryDB
)
{
temp
:=
int32
(
lott
.
LuckyNumber
)
...
...
plugin/dapp/lottery/executor/query.go
View file @
9ea7ec98
...
...
@@ -15,10 +15,10 @@ func (l *Lottery) Query_GetLotteryNormalInfo(param *pty.ReqLotteryInfo) (types.M
if
err
!=
nil
{
return
nil
,
err
}
return
&
pty
.
ReplyLotteryNormalInfo
{
lottery
.
CreateHeight
,
lottery
.
PurBlockNum
,
lottery
.
DrawBlockNum
,
lottery
.
CreateAddr
},
nil
return
&
pty
.
ReplyLotteryNormalInfo
{
CreateHeight
:
lottery
.
CreateHeight
,
PurBlockNum
:
lottery
.
PurBlockNum
,
DrawBlockNum
:
lottery
.
DrawBlockNum
,
CreateAddr
:
lottery
.
CreateAddr
},
nil
}
// Query_GetLotteryPurchaseAddr for current round
...
...
plugin/dapp/lottery/types/lottery.go
View file @
9ea7ec98
...
...
@@ -53,7 +53,7 @@ func (lottery *LotteryType) GetPayload() types.Message {
// CreateTx method
func
(
lottery
LotteryType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
llog
.
Debug
(
"lottery.CreateTx"
,
"action"
,
action
)
var
tx
*
types
.
Transaction
if
action
==
"LotteryCreate"
{
var
param
LotteryCreateTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
...
...
@@ -89,8 +89,6 @@ func (lottery LotteryType) CreateTx(action string, message json.RawMessage) (*ty
}
else
{
return
nil
,
types
.
ErrNotSupport
}
return
tx
,
nil
}
// GetTypeMap method
...
...
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