-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.go
71 lines (59 loc) · 2.05 KB
/
node.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"github.com/gorilla/mux"
"github.com/manguilar22/construct-block/client"
"github.com/manguilar22/construct-block/server"
"html/template"
"log"
"net/http"
"os"
"time"
)
var version = os.Getenv("VERSION")
var hostname = os.Getenv("HOSTNAME")
var publicKey = os.Getenv("PUBLIC_KEY")
var hostEthDataDir = os.Getenv("DATADIR")
var hostKeyStoreFilePath = os.Getenv("KEYSTORE")
var privateKey = os.Getenv("PRIVATE_KEY")
var keyStorePassword = os.Getenv("PASSWORD_FILE")
var tpl *template.Template
func init() {
tpl = template.Must(template.ParseGlob("./public/*.gohtml"))
}
func main(){
// Private Keystore and Host IPC
client, ks, _, _ := network.ConnectEthIPC(hostname, hostKeyStoreFilePath)
defer client.Close()
// Get All Blocks
allBlocks := network.GetAllBlocks(client)
// Get all blocks with tx
allTxBlocks := network.SearchTxBlocks(client)
// Server Routes
router := mux.NewRouter()
router.HandleFunc("/", server.GetEthereumStatusIndex(hostname, client, tpl))
router.HandleFunc("/blockchain", server.GetBlockchainData(client,hostname))
router.HandleFunc("/accounts", server.GetAllAccounts(hostKeyStoreFilePath))
router.HandleFunc("/accounts/balance",server.GetAllAccountBalance(client,ks))
router.HandleFunc("/accounts/id/{num}", server.GetAccountById(hostKeyStoreFilePath))
router.HandleFunc("/accounts/{account}", server.FindByAccount(hostKeyStoreFilePath))
router.HandleFunc("/accounts/{account}/balance",server.GetBalanceByAccount(client))
router.HandleFunc("/eth", func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprintln(writer, ks.Accounts())
})
router.HandleFunc("/eth/blocks", func(writer http.ResponseWriter, request *http.Request) {
data := allBlocks
fmt.Fprintln(writer, data)
})
router.HandleFunc("/eth/blocks/tx", func(writer http.ResponseWriter, request *http.Request) {
data := allTxBlocks
fmt.Fprintln(writer, data)
})
srv := &http.Server{
Handler: router,
Addr: ":8000",
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
log.Fatalln(srv.ListenAndServe())
}