Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nft-event
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
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
duanjinfei
nft-event
Commits
d2847d49
Commit
d2847d49
authored
Jun 05, 2023
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get sortBy API add param & add getWinnerSign API
parent
46184d5c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
2 deletions
+62
-2
app.conf
conf/app.conf
+1
-0
LotteryController.go
controllers/LotteryController.go
+52
-2
response.go
models/response.go
+8
-0
router.go
routers/router.go
+1
-0
No files found.
conf/app.conf
View file @
d2847d49
...
...
@@ -11,6 +11,7 @@ goBackBlockNum = 5
lotteryContract
=
0
x847bF863DB75e25853DE42516bb4E0eFA715d9de
secret
=
0
x2Fc9Ba75f1c78ECc77D1a8fD3BDd6bA83eA68b7e
signAccPrv
=
84
ffa1fd6216691a968ad3ce78ca66a5d3d2c56772fcd78b6b8e2a7976487e0f
# redis config
[
cache
]
collectionName
=
redis
...
...
controllers/LotteryController.go
View file @
d2847d49
...
...
@@ -3,12 +3,14 @@ package controllers
import
(
"bufio"
"context"
"encoding/binary"
"encoding/json"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
log
"github.com/sirupsen/logrus"
"github.com/wuban/nft-event/models"
...
...
@@ -77,19 +79,21 @@ func (c *LotteryController) GetUserList() {
}
func
(
c
*
LotteryController
)
GetHashSortByCondition
()
{
poolAddr
:=
c
.
GetString
(
"poolAddr"
)
period
:=
c
.
GetString
(
"period"
)
if
period
==
""
{
if
period
==
""
||
poolAddr
==
""
||
!
utils
.
IsAddress
(
poolAddr
)
{
c
.
ResponseInfo
(
500
,
models
.
PARAM_ERR
,
nil
)
}
contractAddr
:=
beego
.
AppConfig
.
String
(
"lotteryContract"
)
o
:=
orm
.
NewOrm
()
lotteries
:=
make
([]
models
.
Lottery
,
0
)
_
,
err
:=
o
.
QueryTable
(
"lottery"
)
.
Filter
(
"contract_addr"
,
contractAddr
)
.
Filter
(
"period"
,
period
)
.
OrderBy
(
"-sort_by"
)
.
All
(
&
lotteries
)
_
,
err
:=
o
.
QueryTable
(
"lottery"
)
.
Filter
(
"contract_addr"
,
contractAddr
)
.
Filter
(
"p
oolAddr"
,
poolAddr
)
.
Filter
(
"p
eriod"
,
period
)
.
OrderBy
(
"-sort_by"
)
.
All
(
&
lotteries
)
if
err
!=
nil
{
c
.
ResponseInfo
(
500
,
models
.
SORTBY_ERR
,
err
.
Error
())
}
if
len
(
lotteries
)
==
0
{
c
.
ResponseInfo
(
200
,
models
.
DATA_NIL
,
nil
)
return
}
lotteryHashLastSix
:=
&
models
.
LotteryHashLastSix
{
Hash
:
lotteries
[
0
]
.
Hash
,
...
...
@@ -177,3 +181,49 @@ func (c *LotteryController) GetPoolInfo() {
}
c
.
ResponseInfo
(
200
,
models
.
SUCCESS
,
res
)
}
func
(
c
*
LotteryController
)
GetBeforePeriodWinnerAndSign
()
{
poolAddr
:=
c
.
GetString
(
"poolAddr"
)
period
,
err
:=
c
.
GetInt64
(
"period"
)
beforeNum
,
err
:=
c
.
GetInt64
(
"beforeNum"
)
if
err
!=
nil
||
poolAddr
==
""
{
c
.
ResponseInfo
(
500
,
models
.
PARAM_ERR
,
nil
)
}
if
beforeNum
>=
period
{
c
.
ResponseInfo
(
500
,
models
.
PARAM_ERR
,
nil
)
}
contractAddr
:=
beego
.
AppConfig
.
String
(
"lotteryContract"
)
signPrv
,
err
:=
crypto
.
HexToECDSA
(
beego
.
AppConfig
.
String
(
"signAccPrv"
))
if
err
!=
nil
{
c
.
ResponseInfo
(
200
,
models
.
FAILED
,
err
.
Error
())
}
o
:=
orm
.
NewOrm
()
winnerListRes
:=
make
([]
*
models
.
WinnerListRes
,
0
)
for
i
:=
period
-
beforeNum
;
i
<
period
;
i
++
{
lottery
:=
&
models
.
Lottery
{}
o
.
QueryTable
(
"lottery"
)
.
Filter
(
"contract_addr"
,
contractAddr
)
.
Filter
(
"period"
,
i
)
.
OrderBy
(
"-sort_by"
)
.
One
(
lottery
)
periodBytes
:=
make
([]
byte
,
8
)
binary
.
BigEndian
.
PutUint64
(
periodBytes
,
uint64
(
lottery
.
Period
))
winnerAddr
:=
utils
.
HexToAddr
(
lottery
.
User
)
hashData
:=
[]
byte
(
lottery
.
Hash
)
hash
:=
crypto
.
Keccak256Hash
(
common
.
LeftPadBytes
(
periodBytes
,
32
),
winnerAddr
.
Bytes
(),
hashData
)
signature
,
err
:=
crypto
.
Sign
(
hash
.
Bytes
(),
signPrv
)
if
err
!=
nil
{
c
.
ResponseInfo
(
500
,
models
.
FAILED
,
nil
)
}
signature
[
64
]
+=
27
winnerRes
:=
&
models
.
WinnerListRes
{
PoolAddr
:
lottery
.
PoolAddr
,
Period
:
lottery
.
Period
,
Winner
:
lottery
.
User
,
TxHash
:
lottery
.
Hash
,
Sign
:
"0x"
+
common
.
Bytes2Hex
(
signature
),
}
winnerListRes
=
append
(
winnerListRes
,
winnerRes
)
}
if
len
(
winnerListRes
)
>
0
{
c
.
ResponseInfo
(
200
,
models
.
SUCCESS
,
winnerListRes
)
}
else
{
c
.
ResponseInfo
(
200
,
models
.
DATA_NIL
,
nil
)
}
}
models/response.go
View file @
d2847d49
...
...
@@ -34,3 +34,11 @@ type PoolInfoRes struct {
PoolInfo_
[][]
*
big
.
Int
`abi:"poolInfo_" json:"poolInfo_"`
PoolHistory_
[][]
*
big
.
Int
`abi:"poolHistory_" json:"poolHistory_"`
}
type
WinnerListRes
struct
{
PoolAddr
string
`json:"poolAddr"`
Period
int64
`json:"period"`
Winner
string
`json:"winner"`
TxHash
string
`json:"txHash"`
Sign
string
`json:"sign"`
}
routers/router.go
View file @
d2847d49
...
...
@@ -11,6 +11,7 @@ func init() {
beego
.
Router
(
"/api/v1/event/get/sortCondition"
,
&
controllers
.
LotteryController
{},
"get:GetHashSortByCondition"
)
beego
.
Router
(
"/api/v1/event/get/param"
,
&
controllers
.
LotteryController
{},
"get:ForwardReq"
)
beego
.
Router
(
"/api/v1/event/get/poolInfo"
,
&
controllers
.
LotteryController
{},
"get:GetPoolInfo"
)
beego
.
Router
(
"/api/v1/event/get/winnerSign"
,
&
controllers
.
LotteryController
{},
"get:GetBeforePeriodWinnerAndSign"
)
beego
.
Router
(
"/getToken"
,
&
controllers
.
AuthController
{},
"get:GetToken"
)
// 添加鉴权过滤器
//beego.InsertFilter("/*", beego.BeforeRouter, utils.AuthFilter)
...
...
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