horizonclient

package
v0.0.0-...-5b4d345 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

package horizonclient is an experimental horizon client that provides access to the horizon server

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrResultCodesNotPopulated is the error returned from a call to
	// ResultCodes() against a `Problem` value that doesn't have the
	// "result_codes" extra field populated when it is expected to be.
	ErrResultCodesNotPopulated = errors.New("result_codes not populated")

	// ErrEnvelopeNotPopulated is the error returned from a call to
	// Envelope() against a `Problem` value that doesn't have the
	// "envelope_xdr" extra field populated when it is expected to be.
	ErrEnvelopeNotPopulated = errors.New("envelope_xdr not populated")

	// ErrResultNotPopulated is the error returned from a call to
	// Result() against a `Problem` value that doesn't have the
	// "result_xdr" extra field populated when it is expected to be.
	ErrResultNotPopulated = errors.New("result_xdr not populated")
)
View Source
var DefaultPublicNetClient = &Client{
	HorizonURL: "https://horizon.stellar.org",
	HTTP:       http.DefaultClient,
}

DefaultPublicNetClient is a default client to connect to public network

View Source
var DefaultTestNetClient = &Client{
	HorizonURL: "https://horizon-testnet.stellar.org",
	HTTP:       http.DefaultClient,
}

DefaultTestNetClient is a default client to connect to test network

Functions

This section is empty.

Types

type Account deprecated

type Account = hProtocol.Account

Deprecated: use protocols/horizon instead

type AccountData

type AccountData struct {
	Value string `json:"value"`
}

type AccountFlags deprecated

type AccountFlags = hProtocol.AccountFlags

Deprecated: use protocols/horizon instead

type AccountRequest

type AccountRequest struct {
	AccountId string
	DataKey   string
}

AccountRequest struct contains data for making requests to the accounts endpoint of an horizon server

func (AccountRequest) BuildUrl

func (ar AccountRequest) BuildUrl() (endpoint string, err error)

BuildUrl creates the endpoint to be queried based on the data in the AccountRequest struct. If only AccountId is present, then the endpoint for account details is returned. If both AccounId and DataKey are present, then the endpoint for getting account data is returned

type AccountThresholds deprecated

type AccountThresholds = hProtocol.AccountThresholds

Deprecated: use protocols/horizon instead

type Asset deprecated

type Asset = hProtocol.Asset

Deprecated: use protocols/horizon instead

type AssetCode

type AssetCode string

AssetCode represets `asset_code` param in queries

type AssetIssuer

type AssetIssuer string

AssetIssuer represents `asset_issuer` param in queries

type AssetRequest

type AssetRequest struct {
	ForAssetCode   AssetCode
	ForAssetIssuer AssetIssuer
	Order          Order
	Cursor         Cursor
	Limit          Limit
}

func (AssetRequest) BuildUrl

func (ar AssetRequest) BuildUrl() (endpoint string, err error)

BuildUrl creates the endpoint to be queried based on the data in the AssetRequest struct. If no data is set, it defaults to the build the URL for all assets

type AssetStat deprecated

type AssetStat = hProtocol.AssetStat

Deprecated: use protocols/horizon instead

type AssetsPage

type AssetsPage struct {
	Embedded struct {
		Records []AssetStat
	} `json:"_embedded"`
}

AssetsPage contains page of assets returned by Horizon.

type Balance deprecated

type Balance = hProtocol.Balance

Deprecated: use protocols/horizon instead

type Client

type Client struct {
	HorizonURL string
	HTTP       HTTP
}

Client struct contains data for creating an horizon client that connects to the stellar network

func (*Client) AccountData

func (c *Client) AccountData(request AccountRequest) (accountData AccountData, err error)

AccountData returns a single data associated with a given account See https://www.stellar.org/developers/horizon/reference/endpoints/data-for-account.html

func (*Client) AccountDetail

func (c *Client) AccountDetail(request AccountRequest) (account Account, err error)

AccountDetail returns information for a single account. See https://www.stellar.org/developers/horizon/reference/endpoints/accounts-single.html

Example
client := DefaultPublicNetClient
accountRequest := AccountRequest{AccountId: "GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU"}

account, err := client.AccountDetail(accountRequest)
if err != nil {
	fmt.Println(err)
	return
}

fmt.Print(account)
Output:

func (*Client) Assets

func (c *Client) Assets(request AssetRequest) (assets AssetsPage, err error)
Example
client := DefaultPublicNetClient
// assets for asset issuer
assetRequest := AssetRequest{ForAssetIssuer: "GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU"}
asset, err := client.Assets(assetRequest)
if err != nil {
	fmt.Println(err)
	return
}
fmt.Print(asset)

// all assets
assetRequest = AssetRequest{}
asset, err = client.Assets(assetRequest)
if err != nil {
	fmt.Println(err)
	return
}
fmt.Print(asset)
Output:

func (*Client) Effects

func (c *Client) Effects(request EffectRequest) (effects EffectsPage, err error)

Effects returns effects(https://www.stellar.org/developers/horizon/reference/resources/effect.html) It can be used to return effects for an account, a ledger, an operation, a transaction and all effects on the network.

Example
client := DefaultPublicNetClient
// effects for an account
effectRequest := EffectRequest{ForAccount: "GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU"}
effect, err := client.Effects(effectRequest)
if err != nil {
	fmt.Println(err)
	return
}
fmt.Print(effect)

// all effects
effectRequest = EffectRequest{}
effect, err = client.Effects(effectRequest)
if err != nil {
	fmt.Println(err)
	return
}
fmt.Print(effect)
Output:

type ClientInterface

type ClientInterface interface {
	AccountDetail(request AccountRequest) (Account, error)
	AccountData(request AccountRequest) (AccountData, error)
	Effects(request EffectRequest) (EffectsPage, error)
	Assets(request AssetRequest) (AssetsPage, error)
}

ClientInterface contains methods implemented by the horizon client

type Cursor

type Cursor string

Cursor represents `cursor` param in queries

type Effect

type Effect struct {
	Type   string `json:"type"`
	Amount string `json:"amount"`
}

EffectResponse contains effect data returned by Horizon. Currently used by LoadAccountMergeAmount only.

type EffectRequest

type EffectRequest struct {
	ForAccount     string
	ForLedger      string
	ForOperation   string
	ForTransaction string
	Order          Order
	Cursor         Cursor
	Limit          Limit
}

EffectRequest struct contains data for getting effects from an horizon server. ForAccount, ForLedger, ForOperation and ForTransaction: Not more than one of these can be set at a time. If none are set, the default is to return all effects. The query parameters (Order, Cursor and Limit) can all be set at the same time

func (EffectRequest) BuildUrl

func (er EffectRequest) BuildUrl() (endpoint string, err error)

BuildUrl creates the endpoint to be queried based on the data in the EffectRequest struct. If no data is set, it defaults to the build the URL for all effects

type EffectsPage

type EffectsPage struct {
	Embedded struct {
		Records []Effect
	} `json:"_embedded"`
}

EffectsPageResponse contains page of effects returned by Horizon. Currently used by LoadAccountMergeAmount only.

type Error

type Error struct {
	Response *http.Response
	Problem  Problem
}

Error struct contains the problem returned by Horizon

func (*Error) Envelope

func (herr *Error) Envelope() (*xdr.TransactionEnvelope, error)

Envelope extracts the transaction envelope that triggered this error from the extra fields.

func (Error) Error

func (herr Error) Error() string

func (*Error) ResultCodes

func (herr *Error) ResultCodes() (*TransactionResultCodes, error)

ResultCodes extracts a result code summary from the error, if possible.

func (*Error) ResultString

func (herr *Error) ResultString() (string, error)

ResultString extracts the transaction result as a string.

type HTTP

type HTTP interface {
	Do(req *http.Request) (resp *http.Response, err error)
	Get(url string) (resp *http.Response, err error)
	PostForm(url string, data url.Values) (resp *http.Response, err error)
}

HTTP represents the HTTP client that a horizon client uses to communicate

type HistoryAccount deprecated

type HistoryAccount = hProtocol.HistoryAccount

Deprecated: use protocols/horizon instead

type HorizonRequest

type HorizonRequest interface {
	BuildUrl() (string, error)
}

type Ledger deprecated

type Ledger = hProtocol.Ledger

Deprecated: use protocols/horizon instead

type Limit

type Limit uint

Limit represents `limit` param in queries

type Link = hal.Link

Deprecated: use render/hal instead

type MockClient

type MockClient struct {
	mock.Mock
}

MockClient is a mockable horizon client.

func (*MockClient) AccountData

func (m *MockClient) AccountData(request AccountRequest) (AccountData, error)

AccountData is a mocking method

func (*MockClient) AccountDetail

func (m *MockClient) AccountDetail(request AccountRequest) (Account, error)

AccountDetail is a mocking method

func (*MockClient) Assets

func (m *MockClient) Assets(request AssetRequest) (AssetsPage, error)

Assets is a mocking method

func (*MockClient) Effects

func (m *MockClient) Effects(request EffectRequest) (EffectsPage, error)

Effects is a mocking method

type Offer deprecated

type Offer = hProtocol.Offer

Deprecated: use protocols/horizon instead

type OffersPage

type OffersPage struct {
	Links    hal.Links `json:"_links"`
	Embedded struct {
		Records []Offer `json:"records"`
	} `json:"_embedded"`
}

OffersPage returns a list of offers

type Order

type Order string

Order represents `order` param in queries

const (
	OrderAsc  Order = "asc"
	OrderDesc Order = "desc"
)

type OrderBookSummary deprecated

type OrderBookSummary = hProtocol.OrderBookSummary

Deprecated: use protocols/horizon instead

type Payment

type Payment struct {
	ID          string `json:"id"`
	Type        string `json:"type"`
	PagingToken string `json:"paging_token"`

	Links struct {
		Effects struct {
			Href string `json:"href"`
		} `json:"effects"`
		Transaction struct {
			Href string `json:"href"`
		} `json:"transaction"`
	} `json:"_links"`

	SourceAccount string `json:"source_account"`
	CreatedAt     string `json:"created_at"`

	// create_account and account_merge field
	Account string `json:"account"`

	// create_account fields
	Funder          string `json:"funder"`
	StartingBalance string `json:"starting_balance"`

	// account_merge fields
	Into string `json:"into"`

	// payment/path_payment fields
	From        string `json:"from"`
	To          string `json:"to"`
	AssetType   string `json:"asset_type"`
	AssetCode   string `json:"asset_code"`
	AssetIssuer string `json:"asset_issuer"`
	Amount      string `json:"amount"`

	// transaction fields
	TransactionHash string `json:"transaction_hash"`
	Memo            struct {
		Type  string `json:"memo_type"`
		Value string `json:"memo"`
	}
}

type Price deprecated

type Price = hProtocol.Price

Deprecated: use protocols/horizon instead

type PriceLevel deprecated

type PriceLevel = hProtocol.PriceLevel

Deprecated: use protocols/horizon instead

type Problem deprecated

type Problem struct {
	Type     string                     `json:"type"`
	Title    string                     `json:"title"`
	Status   int                        `json:"status"`
	Detail   string                     `json:"detail,omitempty"`
	Instance string                     `json:"instance,omitempty"`
	Extras   map[string]json.RawMessage `json:"extras,omitempty"`
}

Deprecated: use protocols/horizon instead

func (Problem) ToProblem

func (prob Problem) ToProblem() problem.P

ToProblem converts the Prolem to a problem.P

type Root deprecated

type Root = hProtocol.Root

Deprecated: use protocols/horizon instead

type Signer deprecated

type Signer = hProtocol.Signer

Deprecated: use protocols/horizon instead

type Trade deprecated

type Trade = hProtocol.Trade

Deprecated: use protocols/horizon instead

type TradeAggregation deprecated

type TradeAggregation = hProtocol.TradeAggregation

Deprecated: use protocols/horizon instead

type TradeAggregationsPage

type TradeAggregationsPage struct {
	Links    hal.Links `json:"_links"`
	Embedded struct {
		Records []TradeAggregation `json:"records"`
	} `json:"_embedded"`
}

TradeAggregationsPage returns a list of aggregated trade records, aggregated by resolution

type TradesPage

type TradesPage struct {
	Links    hal.Links `json:"_links"`
	Embedded struct {
		Records []Trade `json:"records"`
	} `json:"_embedded"`
}

TradesPage returns a list of trade records

type Transaction deprecated

type Transaction = hProtocol.Transaction

Deprecated: use protocols/horizon instead

type TransactionResultCodes deprecated

type TransactionResultCodes = hProtocol.TransactionResultCodes

Deprecated: use protocols/horizon instead

type TransactionSuccess deprecated

type TransactionSuccess = hProtocol.TransactionSuccess

Deprecated: use protocols/horizon instead

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL