-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
34 lines (29 loc) · 914 Bytes
/
server.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
package main
import (
"flag"
"fmt"
"log"
"net/http"
_ "github.com/ashishmax31/blockchain/core/consensus/crons"
"github.com/ashishmax31/blockchain/core/nodes"
"github.com/ashishmax31/blockchain/requesthandler"
)
var NodeAddress = "127.0.0.1"
var port = flag.String("p", "3000", "Port number")
func main() {
flag.Parse()
NodeAddress = NodeAddress + fmt.Sprintf(":%s", *port)
nodes.CurrentNodeAddress = NodeAddress
mux := http.NewServeMux()
mux.HandleFunc("/chain", requesthandler.ShowChain)
mux.HandleFunc("/new_transaction", requesthandler.NewTransaction)
mux.HandleFunc("/mine", requesthandler.Mine)
mux.HandleFunc("/register_node", requesthandler.RegisterNode)
mux.HandleFunc("/show_nodes", requesthandler.ShowNodes)
log.Println("Starting server...on :", NodeAddress)
nodes.RegNode(NodeAddress)
err := http.ListenAndServe(NodeAddress, mux)
if err != nil {
log.Println(err.Error())
}
}