diff --git a/blockwebserver.go b/blockwebserver.go index 898b90f..7cd6aa1 100644 --- a/blockwebserver.go +++ b/blockwebserver.go @@ -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) diff --git a/config.go b/config.go index f9b3ef3..04875d7 100644 --- a/config.go +++ b/config.go @@ -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 diff --git a/util.go b/util.go index 0f3f0e2..a36e321 100644 --- a/util.go +++ b/util.go @@ -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 { @@ -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