Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
goDemo
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
goDemo
Commits
ffdb9455
Commit
ffdb9455
authored
Sep 04, 2022
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change scan block
parent
42785f15
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
19 deletions
+22
-19
ScanBlock.go
ScanBlock.go
+22
-19
No files found.
ScanBlock.go
View file @
ffdb9455
...
...
@@ -17,25 +17,32 @@ import (
)
func
main
()
{
// Get the last block height
var
currentScanedBlock
int64
=
getLastTimeBlockNumber
()
addressArr
:=
[]
string
{
"0x5b68ff12be7fd90284ebe2702050879d4d50061a"
}
start
(
"https://galaxy.block.caduceus.foundation"
,
addressArr
)
}
func
start
(
url
string
,
addArr
[]
string
)
{
// get operate signal
makeSignal
:=
make
(
chan
os
.
Signal
,
1
)
// monitor all signals
signal
.
Notify
(
makeSignal
,
syscall
.
SIGINT
)
go
start
(
"https://galaxy.block.caduceus.foundation"
,
addressArr
,
&
currentScanedBlock
)
processSignal
:=
<-
makeSignal
if
processSignal
!=
nil
{
fmt
.
Println
(
currentScanedBlock
)
stop
(
currentScanedBlock
)
fmt
.
Println
(
"process end:"
,
processSignal
)
os
.
Exit
(
3
)
}
}
func
start
(
url
string
,
addArr
[]
string
,
currentScanedBlock
*
int64
)
{
//Block until a signal comes in
fmt
.
Println
(
"monitor start"
)
client
,
err
:=
ethclient
.
Dial
(
url
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
// Get the last block height
num
:=
getLastTimeBlockNumber
()
var
currentScanedBlock
int64
=
num
// create ticker
var
ticker
*
time
.
Ticker
=
time
.
NewTicker
(
1
*
time
.
Second
)
count
:=
10
for
{
select
{
case
<-
ticker
.
C
:
...
...
@@ -46,25 +53,22 @@ func start(url string, addArr []string) {
}
newBlockNum
:=
header
.
Number
.
Int64
()
fmt
.
Println
(
"newBlockNum:"
,
newBlockNum
)
if
currentScanedBlock
<
newBlockNum
{
fmt
.
Println
(
"currentScanedBlock:"
,
&
currentScanedBlock
)
for
num
:=
*
currentScanedBlock
;
num
<
newBlockNum
;
num
++
{
if
count
==
0
{
*
currentScanedBlock
=
*
currentScanedBlock
+
100
break
}
fmt
.
Println
(
"current scan block number:"
,
currentScanedBlock
)
for
_
,
pendingVerifyAddress
:=
range
addArr
{
// Get tx with in a block
if
getBlockTxThroughAddress
(
client
,
big
.
NewInt
(
currentScanedBlock
),
pendingVerifyAddress
)
{
if
getBlockTxThroughAddress
(
client
,
big
.
NewInt
(
num
),
pendingVerifyAddress
)
{
fmt
.
Println
(
"verify success:"
,
pendingVerifyAddress
)
}
else
{
fmt
.
Println
(
"verifing......"
,
pendingVerifyAddress
)
}
}
currentScanedBlock
++
}
}
case
processSignal
:=
<-
makeSignal
:
{
if
processSignal
!=
nil
{
stop
(
currentScanedBlock
,
*
ticker
)
fmt
.
Println
(
"process end:"
,
processSignal
)
os
.
Exit
(
3
)
count
--
}
}
}
...
...
@@ -110,8 +114,7 @@ func getLastTimeBlockNumber() (number int64) {
number
=
7048864
return
}
func
stop
(
blockNum
int64
,
ticker
time
.
Ticker
)
{
ticker
.
Stop
()
func
stop
(
blockNum
int64
)
{
// In Mysql storage end blockNum
fmt
.
Println
(
"Ticker stopped and storage blockNum:"
,
blockNum
)
}
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