Пример #1
0
func initStellarCoreVersion(app *App) {
	if app.config.StellarCoreUrl == "" {
		return
	}

	resp, err := http.Get(fmt.Sprint(app.config.StellarCoreUrl, "/info"))

	if err != nil {
		log.Warnf(app.ctx, "could not load stellar-core version: %s", err)
		return
	}

	defer resp.Body.Close()
	contents, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Warnf(app.ctx, "could not load stellar-core version: %s", err)
		return
	}

	var responseJson map[string]*json.RawMessage
	err = json.Unmarshal(contents, &responseJson)

	var serverInfo map[string]string
	err = json.Unmarshal(*responseJson["info"], &serverInfo)
	app.coreVersion = serverInfo["build"]
}
Пример #2
0
func initStellarCoreInfo(app *App) {
	if app.config.StellarCoreUrl == "" {
		return
	}

	fail := func(err error) {
		log.Warnf("could not load stellar-core info: %s", err)
	}

	resp, err := http.Get(fmt.Sprint(app.config.StellarCoreUrl, "/info"))

	if err != nil {
		fail(err)
		return
	}

	defer resp.Body.Close()
	contents, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fail(err)
		return
	}

	var responseJson map[string]*json.RawMessage
	err = json.Unmarshal(contents, &responseJson)
	if err != nil {
		fail(err)
		return
	}

	var serverInfo map[string]interface{}
	err = json.Unmarshal(*responseJson["info"], &serverInfo)
	if err != nil {
		fail(err)
		return
	}

	// TODO: make resilient to changes in stellar-core's info output
	app.coreVersion = serverInfo["build"].(string)
	app.networkPassphrase = serverInfo["network"].(string)

	return
}