Commit 751ac5c3 authored by duanjinfei's avatar duanjinfei

change node and scan block from、to

parent 15a2b46b
...@@ -2,11 +2,12 @@ appname = nft-event ...@@ -2,11 +2,12 @@ appname = nft-event
httpport = 9000 httpport = 9000
runmode = dev runmode = dev
mysql = debian-sys-maint:H4khSGKhjhMJogpE@tcp(127.0.0.1:3306)/nftEvent?charset=utf8 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 deployedBlock = 17367500
isSyncLog = true isSyncLog = true
beforeEndReqUrl = https://meta.hapeprime.com/ beforeEndReqUrl = https://meta.hapeprime.com/
httpUrlRegex = ^(http|https):\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,}(\/\S*)?$ httpUrlRegex = ^(http|https):\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,}(\/\S*)?$
goBackBlockNum = 5
lotteryContract = 0x38BbA41d42D6ED244302a0D7561E98DA806a86DE lotteryContract = 0x38BbA41d42D6ED244302a0D7561E98DA806a86DE
secret = 0x2Fc9Ba75f1c78ECc77D1a8fD3BDd6bA83eA68b7e secret = 0x2Fc9Ba75f1c78ECc77D1a8fD3BDd6bA83eA68b7e
......
...@@ -62,6 +62,10 @@ func LotteryContractHandler(vLog types.Log) error { ...@@ -62,6 +62,10 @@ func LotteryContractHandler(vLog types.Log) error {
} }
log.Info("Insert data lottery:", lottery) log.Info("Insert data lottery:", lottery)
o := orm.NewOrm() o := orm.NewOrm()
exist := o.QueryTable("lottery").Filter("hash", lottery.Hash).Exist()
if exist {
break
}
_, err = o.Insert(lottery) _, err = o.Insert(lottery)
if err != nil { if err != nil {
logs.Error("Insert lottery error:", err.Error()) logs.Error("Insert lottery error:", err.Error())
......
...@@ -74,6 +74,11 @@ func init() { ...@@ -74,6 +74,11 @@ func init() {
} }
func (p *PullEvent) GetLogs() { 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 := ethereum.FilterQuery{}
query.FromBlock = p.lastBlock query.FromBlock = p.lastBlock
query.ToBlock = new(big.Int).Add(p.lastBlock, big.NewInt(1)) query.ToBlock = new(big.Int).Add(p.lastBlock, big.NewInt(1))
...@@ -83,7 +88,7 @@ func (p *PullEvent) GetLogs() { ...@@ -83,7 +88,7 @@ func (p *PullEvent) GetLogs() {
log.Info("start fileter start at ", p.lastBlock.Text(10)) log.Info("start fileter start at ", p.lastBlock.Text(10))
height, err := p.client.BlockNumber(p.ctx) height, err := p.client.BlockNumber(p.ctx)
log.Info("current node height:", height) log.Info("current node height:", height)
if height <= p.lastBlock.Uint64() { if height < p.lastBlock.Uint64() {
time.Sleep(time.Second) time.Sleep(time.Second)
continue continue
} else if (height - 700) >= p.lastBlock.Uint64() { } else if (height - 700) >= p.lastBlock.Uint64() {
...@@ -93,7 +98,8 @@ func (p *PullEvent) GetLogs() { ...@@ -93,7 +98,8 @@ func (p *PullEvent) GetLogs() {
} else if (height - 10) >= p.lastBlock.Uint64() { } else if (height - 10) >= p.lastBlock.Uint64() {
query.ToBlock = new(big.Int).Add(p.lastBlock, bigTen) query.ToBlock = new(big.Int).Add(p.lastBlock, bigTen)
} else { } 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) allLogs, err := p.client.FilterLogs(p.ctx, query)
if err != nil { 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