You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
983 B

  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "net/http"
  6. )
  7. type Routes []Route
  8. var routes = Routes{
  9. Route{
  10. "Index",
  11. "GET",
  12. "/",
  13. Index,
  14. },
  15. Route{
  16. "GetPeers",
  17. "GET",
  18. "/peers",
  19. GetPeers,
  20. },
  21. Route{
  22. "GetBlockchain",
  23. "GET",
  24. "/blockchain",
  25. GetBlockchain,
  26. },
  27. }
  28. type Address struct {
  29. Address string `json:"address"` //the pubK of the user, to perform logins
  30. }
  31. func Index(w http.ResponseWriter, r *http.Request) {
  32. fmt.Fprintln(w, "CA")
  33. }
  34. func GetPeers(w http.ResponseWriter, r *http.Request) {
  35. getPeers()
  36. jResp, err := json.Marshal(peersList)
  37. check(err)
  38. fmt.Fprintln(w, string(jResp))
  39. }
  40. func GetBlockchain(w http.ResponseWriter, r *http.Request) {
  41. fmt.Print("aaaaa: ")
  42. fmt.Println(blockchain.Blocks[len(blockchain.Blocks)-1].Hash)
  43. reconstructBlockchainFromBlock("http://"+config.IP+":"+config.ServerRESTPort, blockchain.Blocks[len(blockchain.Blocks)-1].Hash)
  44. jResp, err := json.Marshal(blockchain)
  45. check(err)
  46. fmt.Fprintln(w, string(jResp))
  47. }