Ejemplo n.º 1
0
// LookupByAddress performs a federated lookup following to the stellar
// federation protocol using the "name" type request.  The provided address is
// used to resolve what server the request should be made against.  NOTE: the
// "name" type is a legacy holdover from the legacy stellar network's federation
// protocol. It is unfortunate.
func (c *Client) LookupByAddress(addy string) (*NameResponse, error) {
	_, domain, err := address.Split(addy)
	if err != nil {
		return nil, errors.Wrap(err, "parse address failed")
	}

	fserv, err := c.getFederationServer(domain)
	if err != nil {
		return nil, errors.Wrap(err, "lookup federation server failed")
	}

	url := c.url(fserv, "name", addy)

	var resp NameResponse
	err = c.getJSON(url, &resp)
	if err != nil {
		return nil, errors.Wrap(err, "get federation failed")
	}

	if resp.MemoType != "" && resp.Memo == "" {
		return nil, errors.New("Invalid federation response (memo)")
	}

	return &resp, nil
}
Ejemplo n.º 2
0
func (h *Handler) lookupByName(w http.ResponseWriter, q string) {
	name, domain, err := address.Split(q)
	if err != nil {
		h.writeJSON(w, ErrorResponse{
			Code:    "invalid_query",
			Message: "Please use an address of the form name*domain.com",
		}, http.StatusBadRequest)
		return
	}

	rec, err := h.Driver.LookupRecord(name, domain)
	if err != nil {
		h.writeError(w, errors.Wrap(err, "lookup record"))
		return
	}
	if rec == nil {
		h.failNotFound(w)
		return
	}

	h.writeJSON(w, SuccessResponse{
		StellarAddress: q,
		AccountID:      rec.AccountID,
		Memo:           rec.Memo,
		MemoType:       rec.MemoType,
	}, http.StatusOK)
}
Ejemplo n.º 3
0
// GetStellarTomlByAddress returns stellar.toml file of a domain fetched from a
// given address
func (c *Client) GetStellarTomlByAddress(addy string) (*Response, error) {
	_, domain, err := address.Split(addy)
	if err != nil {
		return nil, errors.Wrap(err, "parse address failed")
	}

	return c.GetStellarToml(domain)
}