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
227b3081
Commit
227b3081
authored
Jun 14, 2023
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add api and change test runmode
parent
d2847d49
Changes
10
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
1289 additions
and
71 deletions
+1289
-71
app.conf
conf/app.conf
+7
-8
LotteryController.go
controllers/LotteryController.go
+124
-44
go.mod
go.mod
+3
-1
go.sum
go.sum
+4
-0
reqConstant.go
models/reqConstant.go
+1
-0
response.go
models/response.go
+5
-5
Handler.go
sync/Handler.go
+2
-4
sync.go
sync/sync.go
+9
-7
ERC721.go
utils/ERC721.go
+1096
-0
util.go
utils/util.go
+38
-2
No files found.
conf/app.conf
View file @
227b3081
appname
=
nft
-
event
httpport
=
900
0
runmode
=
dev
mysql
=
debian
-
sys
-
maint
:
H4khSGKhjhMJogpE
@
tcp
(
127
.
0
.
0
.
1
:
3306
)/
nftEvent
?
charset
=
utf8
appname
=
nft
-
event
-
test
httpport
=
900
1
runmode
=
test
mysql
=
debian
-
sys
-
maint
:
H4khSGKhjhMJogpE
@
tcp
(
127
.
0
.
0
.
1
:
3306
)/
nftEvent
Test
?
charset
=
utf8
rpcUrl
=
https
://
eth
-
mainnet
.
g
.
alchemy
.
com
/
v2
/
1
GbX5zRzYZHK
-
ZoFbbI2zQM2WOjafq2s
deployedBlock
=
17
385225
deployedBlock
=
17
475300
isSyncLog
=
true
beforeEndReqUrl
=
https
://
meta
.
hapeprime
.
com
/
beforeEndReqUrl
=
https
://
nftstorage
.
link
/
ipfs
/
httpUrlRegex
= ^(
http
|
https
):\/\/[
a
-
zA
-
Z0
-
9
\-\.]+\.[
a
-
zA
-
Z
]{
2
,}(\/\
S
*)?$
goBackBlockNum
=
5
lotteryContract
=
0
x847bF863DB75e25853DE42516bb4E0eFA715d9de
lotteryContract
=
"0x0d593A2e848306506602f266F7434430f9d8E121;0x3fD11D9B782f7F1505B0C494efD13eA56D0da965"
secret
=
0
x2Fc9Ba75f1c78ECc77D1a8fD3BDd6bA83eA68b7e
signAccPrv
=
84
ffa1fd6216691a968ad3ce78ca66a5d3d2c56772fcd78b6b8e2a7976487e0f
# redis config
...
...
controllers/LotteryController.go
View file @
227b3081
This diff is collapsed.
Click to expand it.
go.mod
View file @
227b3081
...
...
@@ -5,6 +5,7 @@ go 1.19
require github.com/astaxie/beego v1.12.1
require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/ethereum/go-ethereum v1.12.0
github.com/garyburd/redigo v1.6.4
github.com/go-sql-driver/mysql v1.7.1
...
...
@@ -17,9 +18,10 @@ require (
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/
dgrijalva/jwt-go v3.2.0+incompatible
// indirect
github.com/
fsnotify/fsnotify v1.6.0
// indirect
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c // indirect
...
...
go.sum
View file @
227b3081
...
...
@@ -14,6 +14,7 @@ github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPx
github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
github.com/casbin/casbin v1.7.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE=
github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
github.com/cockroachdb/errors v1.9.1 h1:yFVvsI0VxmRShfawbt/laCIDy/mtTqqnvoNgiy5bEV8=
...
...
@@ -43,6 +44,7 @@ github.com/ethereum/go-ethereum v1.12.0 h1:bdnhLPtqETd4m3mS8BGMNvBTf36bO5bx/hxE2
github.com/ethereum/go-ethereum v1.12.0/go.mod h1:/oo2X/dZLJjf2mJ6YT9wcWxa4nNJDBKDBU6sFIpx1Gs=
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/garyburd/redigo v1.6.4 h1:LFu2R3+ZOPgSMWMOL+saa/zXRjw0ID2G8FepO53BGlg=
github.com/garyburd/redigo v1.6.4/go.mod h1:rTb6epsqigu3kYKBnaF028A7Tf/Aw5s0cqA47doKKqw=
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqGNY4FhTFhk+o9oFHGINQ/+vhlm8HFzi6znCI=
...
...
@@ -64,6 +66,7 @@ github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8l
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk=
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
...
...
@@ -148,6 +151,7 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
...
...
models/reqConstant.go
View file @
227b3081
...
...
@@ -14,4 +14,5 @@ const (
CALL_CONTRACT_ERR
=
"Failed to pack contract call data"
PACK_ABI_ERR
=
"ABI pack func name err"
UNPACK_ABI_RETURN_PARM_ERR
=
"Failed to unpack contract output"
BUILD_ERR
=
"Build contract error"
)
models/response.go
View file @
227b3081
...
...
@@ -37,8 +37,8 @@ type PoolInfoRes struct {
type
WinnerListRes
struct
{
PoolAddr
string
`json:"poolAddr"`
Period
int64
`json:"period
"`
Winner
string
`json:"winne
r"`
TxHash
string
`json:"txHash
"`
Sign
string
`json:"sign
"`
Period
Arr
[][]
int64
`json:"periodArr
"`
Winner
Arr
[][]
string
`json:"winnerAr
r"`
TxHash
Arr
[][]
string
`json:"txHashArr
"`
Sign
Arr
[][]
string
`json:"signArr
"`
}
sync/Handler.go
View file @
227b3081
...
...
@@ -2,7 +2,6 @@ package sync
import
(
"bufio"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm"
"github.com/ethereum/go-ethereum/accounts/abi"
...
...
@@ -20,8 +19,7 @@ import (
// LotteryTopic ERC721 transfer event topic
var
LotteryTopic
=
crypto
.
Keccak256Hash
([]
byte
(
"Lottery(address,uint256,uint256,address,uint256)"
))
.
Hex
()
func
LotteryContractHandler
(
vLog
types
.
Log
)
error
{
contractAddr
:=
beego
.
AppConfig
.
String
(
"lotteryContract"
)
func
LotteryContractHandler
(
vLog
types
.
Log
,
contractAddr
common
.
Address
)
error
{
logs
.
Info
(
"handler lottery contract logs"
)
file
,
err
:=
os
.
Open
(
"./sync/Lottery_Event.json"
)
if
err
!=
nil
{
...
...
@@ -51,7 +49,7 @@ func LotteryContractHandler(vLog types.Log) error {
log
.
Info
(
"value:"
,
value
.
String
())
tokenId
,
_
:=
utils
.
HexToInt64
(
vLog
.
Topics
[
3
]
.
Hex
())
lottery
:=
&
models
.
Lottery
{
ContractAddr
:
contractAddr
,
ContractAddr
:
contractAddr
.
Hex
()
,
PoolAddr
:
utils
.
HexToAddr
(
vLog
.
Topics
[
1
]
.
Hex
())
.
String
(),
Period
:
period
,
User
:
userAddr
,
...
...
sync/sync.go
View file @
227b3081
...
...
@@ -26,7 +26,7 @@ var (
bigEight
=
big
.
NewInt
(
700
)
)
type
logHandler
func
(
log
types
.
Log
)
error
type
logHandler
func
(
log
types
.
Log
,
contractAddr
common
.
Address
)
error
type
PullEvent
struct
{
ctx
context
.
Context
...
...
@@ -64,14 +64,16 @@ func init() {
pullTask
.
ctx
=
context
.
Background
()
pullTask
.
contractList
=
make
([]
common
.
Address
,
0
)
{
lotteryAddr
:=
beego
.
AppConfig
.
String
(
"lotteryContract"
)
if
l
otteryAddr
==
""
{
lotteryAddr
Arr
:=
beego
.
AppConfig
.
Strings
(
"lotteryContract"
)
if
l
en
(
lotteryAddrArr
)
==
0
{
return
}
for
_
,
lotteryAddr
:=
range
lotteryAddrArr
{
addr
:=
common
.
HexToAddress
(
lotteryAddr
)
pullTask
.
contractList
=
append
(
pullTask
.
contractList
,
addr
)
pullTask
.
contractHandler
[
addr
]
=
LotteryContractHandler
}
}
}
func
(
p
*
PullEvent
)
GetLogs
()
{
...
...
@@ -113,7 +115,7 @@ func (p *PullEvent) GetLogs() {
log
.
Info
(
"Logs to be processed:"
,
vlog
)
handle
,
exist
:=
p
.
contractHandler
[
vlog
.
Address
]
if
exist
{
handle
(
vlog
)
handle
(
vlog
,
vlog
.
Address
)
}
}
}
...
...
utils/ERC721.go
0 → 100644
View file @
227b3081
This diff is collapsed.
Click to expand it.
utils/util.go
View file @
227b3081
package
utils
import
(
"context"
"encoding/hex"
"fmt"
"github.com/astaxie/beego"
"github.com/dgrijalva/jwt-go"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
log
"github.com/sirupsen/logrus"
"regexp"
)
func
IsAddress
(
val
string
)
bool
{
return
common
.
IsHexAddress
(
val
)
func
IsAddress
(
params
...
string
)
bool
{
res
:=
true
for
_
,
param
:=
range
params
{
res
=
common
.
IsHexAddress
(
param
)
}
return
res
}
func
HexToAddr
(
val
string
)
common
.
Address
{
return
common
.
HexToAddress
(
val
)
}
func
IsContractAddr
(
address
string
,
client
*
ethclient
.
Client
)
bool
{
contractAddress
:=
common
.
HexToAddress
(
address
)
bytecode
,
err
:=
client
.
CodeAt
(
context
.
Background
(),
contractAddress
,
nil
)
if
err
!=
nil
{
return
false
}
isContract
:=
len
(
bytecode
)
>
0
return
isContract
}
func
IsNilString
(
params
...
string
)
bool
{
for
_
,
param
:=
range
params
{
if
param
==
""
{
return
false
}
}
return
true
}
func
GetHttpRegex
()
*
regexp
.
Regexp
{
urlPattern
:=
beego
.
AppConfig
.
String
(
"httpUrlRegex"
)
// 编译正则表达式
regex
,
err
:=
regexp
.
Compile
(
urlPattern
)
if
err
!=
nil
{
return
nil
}
return
regex
}
func
HexToInt64
(
hexStr
string
)
(
int64
,
error
)
{
// 去除十六进制字符串的前缀 "0x"
if
len
(
hexStr
)
>
2
&&
hexStr
[
0
:
2
]
==
"0x"
{
...
...
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