-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathethscanner.go
More file actions
55 lines (50 loc) · 1.22 KB
/
ethscanner.go
File metadata and controls
55 lines (50 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"bufio"
"encoding/json"
_ "ethscanner/memstore" // initialize mem storage
"ethscanner/parser"
"fmt"
"log"
"os"
)
const URL = "https://cloudflare-eth.com"
// "0xdac17f958d2ee523a2206206994597c13d831ec7" // usdt contract address
func main() {
p := parser.New(URL)
in := bufio.NewScanner(os.Stdin)
for in.Scan() {
switch in.Text() {
case "exit":
return
case "block":
block := p.GetCurrentBlock()
log.Println(fmt.Sprintf("Last processed block: %d", block))
case "tx":
log.Println("Enter address:")
if in.Scan() {
address := in.Text()
log.Println(fmt.Sprintf("Transactions for address %s:", address))
transactions := p.GetTransactions(address)
if len(transactions) == 0 {
log.Println("Not found")
} else {
marshal, _ := json.Marshal(transactions)
log.Println(fmt.Sprintf("%s", string(marshal)))
}
}
case "sub":
log.Println("Enter address:")
if in.Scan() {
address := in.Text()
if p.Subscribe(address) {
log.Println(fmt.Sprintf("Address %s has been subscribed", address))
} else {
log.Println(fmt.Sprintf("Address %s has already been subscribed", address))
}
}
default:
log.Println("Unknown command")
}
}
}