Commit 751ac5c3 authored by duanjinfei's avatar duanjinfei

change node and scan block from、to

parent 15a2b46b
......@@ -2,11 +2,12 @@ appname = nft-event
httpport = 9000
runmode = dev
mysql = debian-sys-maint:H4khSGKhjhMJogpE@tcp(127.0.0.1:3306)/nftEvent?charset=utf8
rpcUrl = https://cloudflare-eth.com
rpcUrl = https://eth-mainnet.g.alchemy.com/v2/1GbX5zRzYZHK-ZoFbbI2zQM2WOjafq2s
deployedBlock = 17367500
isSyncLog = true
beforeEndReqUrl = https://meta.hapeprime.com/
httpUrlRegex = ^(http|https):\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,}(\/\S*)?$
goBackBlockNum = 5
lotteryContract = 0x38BbA41d42D6ED244302a0D7561E98DA806a86DE
secret = 0x2Fc9Ba75f1c78ECc77D1a8fD3BDd6bA83eA68b7e
......
......@@ -62,6 +62,10 @@ func LotteryContractHandler(vLog types.Log) error {
}
log.Info("Insert data lottery:", lottery)
o := orm.NewOrm()
exist := o.QueryTable("lottery").Filter("hash", lottery.Hash).Exist()
if exist {
break
}
_, err = o.Insert(lottery)
if err != nil {
logs.Error("Insert lottery error:", err.Error())
......
......@@ -74,6 +74,11 @@ func init() {
}
func (p *PullEvent) GetLogs() {
backBlock, err := beego.AppConfig.Int64("goBackBlockNum")
if err != nil {
log.Error("Get backBlock error:", err.Error())
return
}
query := ethereum.FilterQuery{}
query.FromBlock = p.lastBlock
query.ToBlock = new(big.Int).Add(p.lastBlock, big.NewInt(1))
......@@ -83,7 +88,7 @@ func (p *PullEvent) GetLogs() {
log.Info("start fileter start at ", p.lastBlock.Text(10))
height, err := p.client.BlockNumber(p.ctx)
log.Info("current node height:", height)
if height <= p.lastBlock.Uint64() {
if height < p.lastBlock.Uint64() {
time.Sleep(time.Second)
continue
} else if (height - 700) >= p.lastBlock.Uint64() {
......@@ -93,7 +98,8 @@ func (p *PullEvent) GetLogs() {
} else if (height - 10) >= p.lastBlock.Uint64() {
query.ToBlock = new(big.Int).Add(p.lastBlock, bigTen)
} else {
query.ToBlock = new(big.Int).Add(p.lastBlock, bigOne)
query.FromBlock = new(big.Int).Sub(p.lastBlock, big.NewInt(backBlock))
query.ToBlock = p.lastBlock
}
allLogs, err := p.client.FilterLogs(p.ctx, query)
if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment