Documentation ¶
Overview ¶
package horizonclient is an experimental horizon client that provides access to the horizon server
Index ¶
- Variables
- type AccountRequest
- type AssetCode
- type AssetIssuer
- type AssetRequest
- type Client
- func (c *Client) AccountData(request AccountRequest) (accountData hProtocol.AccountData, err error)
- func (c *Client) AccountDetail(request AccountRequest) (account hProtocol.Account, err error)
- func (c *Client) Assets(request AssetRequest) (assets hProtocol.AssetsPage, err error)
- func (c *Client) Effects(request EffectRequest) (effects hProtocol.EffectsPage, err error)
- func (c *Client) FeeStats() (feestats hProtocol.FeeStats, err error)
- func (c *Client) LedgerDetail(sequence uint32) (ledger hProtocol.Ledger, err error)
- func (c *Client) Ledgers(request LedgerRequest) (ledgers hProtocol.LedgersPage, err error)
- func (c *Client) Metrics() (metrics hProtocol.Metrics, err error)
- func (c *Client) Offers(request OfferRequest) (offers hProtocol.OffersPage, err error)
- func (c *Client) Stream(ctx context.Context, request StreamRequest, handler func(interface{})) (err error)
- type ClientInterface
- type Cursor
- type EffectHandler
- type EffectRequest
- type Error
- type HTTP
- type HorizonRequest
- type LedgerRequest
- type Limit
- type MockClient
- func (m *MockClient) AccountData(request AccountRequest) (hProtocol.AccountData, error)
- func (m *MockClient) AccountDetail(request AccountRequest) (hProtocol.Account, error)
- func (m *MockClient) Assets(request AssetRequest) (hProtocol.AssetsPage, error)
- func (m *MockClient) Effects(request EffectRequest) (hProtocol.EffectsPage, error)
- func (m *MockClient) FeeStats() (hProtocol.FeeStats, error)
- func (m *MockClient) LedgerDetail(sequence uint32) (hProtocol.Ledger, error)
- func (m *MockClient) Ledgers(request LedgerRequest) (hProtocol.LedgersPage, error)
- func (m *MockClient) Metrics() (hProtocol.Metrics, error)
- func (m *MockClient) Offers(request OfferRequest) (hProtocol.OffersPage, error)
- func (m *MockClient) Stream(ctx context.Context, request StreamRequest, handler func(interface{})) error
- type OfferRequest
- type Order
- type StreamRequest
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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") )
var DefaultPublicNetClient = &Client{ HorizonURL: "https://horizon.stellar.org", HTTP: http.DefaultClient, }
DefaultPublicNetClient is a default client to connect to public network
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 AccountRequest ¶
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 AssetRequest ¶
type AssetRequest struct { ForAssetCode AssetCode ForAssetIssuer AssetIssuer Order Order Cursor Cursor Limit Limit }
AssetRequest struct contains data for getting asset details from an horizon server.
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 Client ¶
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 hProtocol.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 hProtocol.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 hProtocol.AssetsPage, err error)
Assets returns asset information. See https://www.stellar.org/developers/horizon/reference/endpoints/assets-all.html
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 hProtocol.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:
func (*Client) FeeStats ¶
FeeStats returns information about fees in the last 5 ledgers. See https://www.stellar.org/developers/horizon/reference/endpoints/fee-stats.html
Example ¶
client := DefaultPublicNetClient // horizon fees fees, err := client.FeeStats() if err != nil { fmt.Println(err) return } fmt.Print(fees)
Output:
func (*Client) LedgerDetail ¶
LedgerDetails returns information about a particular ledger for a given sequence number See https://www.stellar.org/developers/horizon/reference/endpoints/ledgers-single.html
Example ¶
client := DefaultPublicNetClient // details for a ledger sequence := uint32(12345) ledger, err := client.LedgerDetail(sequence) if err != nil { fmt.Println(err) return } fmt.Print(ledger)
Output:
func (*Client) Ledgers ¶
func (c *Client) Ledgers(request LedgerRequest) (ledgers hProtocol.LedgersPage, err error)
Ledgers returns information about all ledgers. See https://www.stellar.org/developers/horizon/reference/endpoints/ledgers-all.html
func (*Client) Metrics ¶
Metrics returns monitoring information about a horizon server See https://www.stellar.org/developers/horizon/reference/endpoints/metrics.html
Example ¶
client := DefaultPublicNetClient // horizon metrics metrics, err := client.Metrics() if err != nil { fmt.Println(err) return } fmt.Print(metrics)
Output:
func (*Client) Offers ¶
func (c *Client) Offers(request OfferRequest) (offers hProtocol.OffersPage, err error)
Offers returns information about offers made on the SDEX. See https://www.stellar.org/developers/horizon/reference/endpoints/offers-for-account.html
Example ¶
client := DefaultPublicNetClient offerRequest := OfferRequest{ForAccount: "GCLWGQPMKXQSPF776IU33AH4PZNOOWNAWGGKVTBQMIC5IMKUNP3E6NVU", Cursor: "now", Order: OrderDesc} offers, err := client.Offers(offerRequest) if err != nil { fmt.Println(err) return } fmt.Print(offers)
Output:
func (*Client) Stream ¶
func (c *Client) Stream(ctx context.Context, request StreamRequest, handler func(interface{})) (err error)
Stream is for endpoints that support streaming
Example ¶
// stream effects client := DefaultPublicNetClient effectRequest := EffectRequest{Cursor: "now"} ctx, cancel := context.WithCancel(context.Background()) go func() { // Stop streaming after 60 seconds. time.Sleep(60 * time.Second) cancel() }() // to do: can `e interface{}` be `e Effect` ?? Then we won't have type assertion. err := client.Stream(ctx, effectRequest, func(e interface{}) { resp, ok := e.(effects.Base) if ok { fmt.Println(resp.Type) } }) if err != nil { fmt.Println(err) }
Output:
type ClientInterface ¶
type ClientInterface interface { AccountDetail(request AccountRequest) (hProtocol.Account, error) AccountData(request AccountRequest) (hProtocol.AccountData, error) Effects(request EffectRequest) (hProtocol.EffectsPage, error) Assets(request AssetRequest) (hProtocol.AssetsPage, error) Ledgers(request LedgerRequest) (hProtocol.LedgersPage, error) LedgerDetail(sequence uint32) (hProtocol.Ledger, error) Metrics() (hProtocol.Metrics, error) Stream(ctx context.Context, request StreamRequest, handler func(interface{})) error FeeStats() (hProtocol.FeeStats, error) Offers(request OfferRequest) (hProtocol.OffersPage, error) }
ClientInterface contains methods implemented by the horizon client
type EffectHandler ¶
EffectHandler is a function that is called when a new effect is received
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 Error ¶
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) ResultCodes ¶
func (herr *Error) ResultCodes() (*hProtocol.TransactionResultCodes, error)
ResultCodes extracts a result code summary from the error, if possible.
func (*Error) ResultString ¶
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 HorizonRequest ¶
HorizonRequest contains methods implemented by request structs for horizon endpoints
type LedgerRequest ¶
type LedgerRequest struct { Order Order Cursor Cursor Limit Limit // contains filtered or unexported fields }
LedgerRequest struct contains data for getting ledger details from an horizon server.
func (LedgerRequest) BuildUrl ¶
func (lr LedgerRequest) BuildUrl() (endpoint string, err error)
BuildUrl creates the endpoint to be queried based on the data in the LedgerRequest struct. If no data is set, it defaults to the build the URL for all ledgers
type MockClient ¶
MockClient is a mockable horizon client.
func (*MockClient) AccountData ¶
func (m *MockClient) AccountData(request AccountRequest) (hProtocol.AccountData, error)
AccountData is a mocking method
func (*MockClient) AccountDetail ¶
func (m *MockClient) AccountDetail(request AccountRequest) (hProtocol.Account, error)
AccountDetail is a mocking method
func (*MockClient) Assets ¶
func (m *MockClient) Assets(request AssetRequest) (hProtocol.AssetsPage, error)
Assets is a mocking method
func (*MockClient) Effects ¶
func (m *MockClient) Effects(request EffectRequest) (hProtocol.EffectsPage, error)
Effects is a mocking method
func (*MockClient) LedgerDetail ¶
func (m *MockClient) LedgerDetail(sequence uint32) (hProtocol.Ledger, error)
func (*MockClient) Ledgers ¶
func (m *MockClient) Ledgers(request LedgerRequest) (hProtocol.LedgersPage, error)
func (*MockClient) Offers ¶
func (m *MockClient) Offers(request OfferRequest) (hProtocol.OffersPage, error)
func (*MockClient) Stream ¶
func (m *MockClient) Stream(ctx context.Context, request StreamRequest, handler func(interface{}), ) error
type OfferRequest ¶
OfferRequest struct contains data for getting offers made by an account from an horizon server
func (OfferRequest) BuildUrl ¶
func (or OfferRequest) BuildUrl() (endpoint string, err error)
BuildUrl creates the endpoint to be queried based on the data in the OfferRequest struct.