Documentation ¶
Overview ¶
package horizonclient is an experimental horizon client that provides access to the horizon server
Index ¶
- Variables
- type Accountdeprecated
- type AccountData
- type AccountFlagsdeprecated
- type AccountRequest
- type AccountThresholdsdeprecated
- type Assetdeprecated
- type AssetCode
- type AssetIssuer
- type AssetRequest
- type AssetStatdeprecated
- type AssetsPage
- type Balancedeprecated
- type Client
- func (c *Client) AccountData(request AccountRequest) (accountData AccountData, err error)
- func (c *Client) AccountDetail(request AccountRequest) (account Account, err error)
- func (c *Client) Assets(request AssetRequest) (assets AssetsPage, err error)
- func (c *Client) Effects(request EffectRequest) (effects EffectsPage, err error)
- type ClientInterface
- type Cursor
- type Effect
- type EffectRequest
- type EffectsPage
- type Error
- type HTTP
- type HistoryAccountdeprecated
- type HorizonRequest
- type Ledgerdeprecated
- type Limit
- type Linkdeprecated
- type MockClient
- type Offerdeprecated
- type OffersPage
- type Order
- type OrderBookSummarydeprecated
- type Payment
- type Pricedeprecated
- type PriceLeveldeprecated
- type Problemdeprecated
- type Rootdeprecated
- type Signerdeprecated
- type Tradedeprecated
- type TradeAggregationdeprecated
- type TradeAggregationsPage
- type TradesPage
- type Transactiondeprecated
- type TransactionResultCodesdeprecated
- type TransactionSuccessdeprecated
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 AccountData ¶
type AccountData struct {
Value string `json:"value"`
}
type AccountFlags
deprecated
type AccountFlags = hProtocol.AccountFlags
Deprecated: use protocols/horizon instead
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 AccountThresholds
deprecated
type AccountThresholds = hProtocol.AccountThresholds
Deprecated: use protocols/horizon instead
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 AssetsPage ¶
type AssetsPage struct { Embedded struct { Records []AssetStat } `json:"_embedded"` }
AssetsPage contains page of assets returned by Horizon.
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 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 Effect ¶
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 ¶
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() (*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 HistoryAccount
deprecated
type HistoryAccount = hProtocol.HistoryAccount
Deprecated: use protocols/horizon instead
type HorizonRequest ¶
type MockClient ¶
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 OffersPage ¶
type OffersPage struct { Links hal.Links `json:"_links"` Embedded struct { Records []Offer `json:"records"` } `json:"_embedded"` }
OffersPage returns a list of offers
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 PriceLevel
deprecated
type PriceLevel = hProtocol.PriceLevel
Deprecated: use protocols/horizon instead
type Problem
deprecated
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