Skip to content

Commit

Permalink
Implemented getting chainparams.json as a starting step to "daisy pull"
Browse files Browse the repository at this point in the history
  • Loading branch information
ivoras committed Feb 10, 2019
1 parent 206a7c5 commit 460f84d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
12 changes: 12 additions & 0 deletions blockwebserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,21 @@ func blockWebSendBlock(w http.ResponseWriter, r *http.Request) {
// log.Println("Done serving block", blockHeight)
}

func blockWebSendChainParams(w http.ResponseWriter, r *http.Request) {
log.Println("Serving chainparams.json to", r.RemoteAddr)

w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Disposition", "attachment; filename=\"chainparams.json\"")
_, err := w.Write(jsonifyWhateverToBytes(chainParams))
if err != nil {
log.Println(err)
}
}

func blockWebServer() {
r := mux.NewRouter()
r.HandleFunc("/block/{height}", blockWebSendBlock)
r.HandleFunc("/chainparams.json", blockWebSendChainParams)

serverAddress := fmt.Sprintf(":%d", cfg.httpPort)

Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var cfg struct {
configFile string
P2pPort int `json:"p2p_port"`
DataDir string `json:"data_dir"`
httpPort int
httpPort int `json:"http_port"`
showHelp bool
faster bool
p2pBlockInline bool
Expand Down
11 changes: 10 additions & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (ss *StringSetWithExpiry) TestAndSet(s string) bool {
return ok
}

// Convert whatever to JSON
// Convert whatever to a JSON string
func jsonifyWhatever(i interface{}) string {
jsonb, err := json.Marshal(i)
if err != nil {
Expand All @@ -276,6 +276,15 @@ func jsonifyWhatever(i interface{}) string {
return string(jsonb)
}

// Convert whatever to JSON bytes
func jsonifyWhateverToBytes(i interface{}) []byte {
jsonb, err := json.Marshal(i)
if err != nil {
log.Panic(err)
}
return jsonb
}

// Splits an address string in the form of "host:port" into its separate host and port parts
func splitAddress(address string) (string, int, error) {
i := strings.LastIndex(address, ":") // Not using strings.Split because of IPv6
Expand Down

0 comments on commit 460f84d

Please sign in to comment.