-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (45 loc) · 1.23 KB
/
main.go
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
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/daniel-burghardt/ethereum-parser/data"
"github.com/daniel-burghardt/ethereum-parser/ethrpc"
"github.com/daniel-burghardt/ethereum-parser/httphandler"
"github.com/daniel-burghardt/ethereum-parser/observer"
)
const serverPort = 3000
func main() {
// Get ENVs
ethServerUrl := os.Getenv("ETH_SERVER_URL")
if ethServerUrl == "" {
ethServerUrl = "https://cloudflare-eth.com"
}
webhookUrl := os.Getenv("WEBHOOK_URL")
// Setup dependencies
repo := data.NewInMemoryStorage()
handler := httphandler.Handler{
Repo: repo,
}
rpcService := ethrpc.Service{
Url: ethServerUrl,
}
observerService := observer.Service{
RPC: rpcService,
Repo: repo,
WebhookUrl: webhookUrl,
}
go func() {
err := observerService.Start()
if err != nil {
log.Fatalf("observer killed: %v", err)
}
}()
log.Printf("Starting the server on port %d...", serverPort)
http.HandleFunc("/", http.NotFound)
http.HandleFunc("GET /current-block", handler.GetCurrentBlock)
http.HandleFunc("POST /subscribe/{address}", handler.PostSubscribe)
http.HandleFunc("GET /transactions/{address}", handler.GetTransactions)
http.ListenAndServe(fmt.Sprintf("localhost:%d", serverPort), nil)
}