go: github.com/stellar/go/clients/horizon Index | Examples | Files

package horizon

import "github.com/stellar/go/clients/horizon"

Package horizon is DEPRECATED in favour of clients/horizonclient! It used to provide client access to a horizon server, allowing an application to post transactions and lookup ledger information.

Deprecated: clients/horizon package with all its exported methods and variables will no longer be maintained. It will be removed in future versions of the SDK. Use clients/horizonclient (https://godoc.org/github.com/stellar/go/clients/horizonclient) instead.

Index

Examples

Package Files

client.go error.go internal.go main.go mocks.go responses.go

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{
    URL:  "https://horizon.stellar.org",
    HTTP: http.DefaultClient,
}

DefaultPublicNetClient is a default client to connect to public network

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

DefaultTestNetClient is a default client to connect to test network

type Account Uses

type Account = hProtocol.Account

Deprecated: use protocols/horizon instead

type AccountFlags Uses

type AccountFlags = hProtocol.AccountFlags

Deprecated: use protocols/horizon instead

type AccountThresholds Uses

type AccountThresholds = hProtocol.AccountThresholds

Deprecated: use protocols/horizon instead

type Asset Uses

type Asset = hProtocol.Asset

Deprecated: use protocols/horizon instead

type At Uses

type At string

At is a paging parameter that can be used to override the URL loaded in a remote method call to horizon.

type Balance Uses

type Balance = hProtocol.Balance

Deprecated: use protocols/horizon instead

type Client Uses

type Client struct {
    // URL of Horizon server to connect
    URL string

    // HTTP client to make requests with
    HTTP HTTP

    AppName    string
    AppVersion string
    // contains filtered or unexported fields
}

Client struct contains data required to connect to Horizon instance It is okay to call methods on Client concurrently. A Client must not be copied after first use.

func (*Client) HomeDomainForAccount Uses

func (c *Client) HomeDomainForAccount(aid string) (string, error)

HomeDomainForAccount returns the home domain for the provided strkey-encoded account id. Deprecated: use clients/horizonclient instead

func (*Client) LoadAccount Uses

func (c *Client) LoadAccount(accountID string) (account Account, err error)

LoadAccount loads the account state from horizon. err can be either error object or horizon.Error object. Deprecated: use horizonclient.AccountDetail instead

func (*Client) LoadAccountMergeAmount Uses

func (c *Client) LoadAccountMergeAmount(p *Payment) error

LoadAccountMergeAmount loads `account_merge` operation amount from it's effects Deprecated: use clients/horizonclient instead

func (*Client) LoadAccountOffers Uses

func (c *Client) LoadAccountOffers(
    accountID string,
    params ...interface{},
) (offers OffersPage, err error)

LoadAccountOffers loads the account offers from horizon. err can be either error object or horizon.Error object. Deprecated: use horizonclient.Offers instead

func (*Client) LoadAccountTransactions Uses

func (c *Client) LoadAccountTransactions(accountID string, params ...interface{}) (TransactionsPage, error)

Deprecated: use horizonclient.Transactions instead

func (*Client) LoadMemo Uses

func (c *Client) LoadMemo(p *Payment) (err error)

LoadMemo loads memo for a transaction in Payment Deprecated: use clients/horizonclient instead

func (*Client) LoadOperation Uses

func (c *Client) LoadOperation(operationID string) (payment Payment, err error)

LoadOperation loads a single operation from Horizon server Deprecated: use horizonclient.OperationDetail instead

func (*Client) LoadOrderBook Uses

func (c *Client) LoadOrderBook(
    selling Asset,
    buying Asset,
    params ...interface{},
) (orderBook OrderBookSummary, err error)

LoadOrderBook loads order book for given selling and buying assets. Deprecated: use horizonclient.OrderBook instead

func (*Client) LoadTradeAggregations Uses

func (c *Client) LoadTradeAggregations(
    baseAsset Asset,
    counterAsset Asset,
    resolution int64,
    params ...interface{},
) (tradeAggrs TradeAggregationsPage, err error)

LoadTradeAggregations loads the trade aggregation from horizon. Deprecated: use horizonclient.TradeAggregations instead

func (*Client) LoadTrades Uses

func (c *Client) LoadTrades(
    baseAsset Asset,
    counterAsset Asset,
    offerID int64,
    resolution int64,
    params ...interface{},
) (tradesPage TradesPage, err error)

LoadTrades loads the /trades endpoint from horizon. Deprecated: use horizonclient.Trades instead

func (*Client) LoadTransaction Uses

func (c *Client) LoadTransaction(transactionID string) (transaction Transaction, err error)

LoadTransaction loads a single transaction from Horizon server Deprecated: use horizonclient.TransactionDetail instead

func (*Client) Root Uses

func (c *Client) Root() (root Root, err error)

Root loads the root endpoint of horizon Deprecated: use clients/horizonclient instead

func (*Client) SequenceForAccount Uses

func (c *Client) SequenceForAccount(
    accountID string,
) (xdr.SequenceNumber, error)

SequenceForAccount implements build.SequenceProvider Deprecated: use clients/horizonclient instead

func (*Client) StreamLedgers Uses

func (c *Client) StreamLedgers(
    ctx context.Context,
    cursor *Cursor,
    handler LedgerHandler,
) (err error)

StreamLedgers streams incoming ledgers. Use context.WithCancel to stop streaming or context.Background() if you want to stream indefinitely. Deprecated: use horizonclient.StreamLedgers instead

Code:

client := DefaultPublicNetClient
cursor := Cursor("now")

ctx, cancel := context.WithCancel(context.Background())

go func() {
    // Stop streaming after 60 seconds.
    time.Sleep(60 * time.Second)
    cancel()
}()

err := client.StreamLedgers(ctx, &cursor, func(l Ledger) {
    fmt.Println(l.Sequence)
})

if err != nil {
    fmt.Println(err)
}

func (*Client) StreamPayments Uses

func (c *Client) StreamPayments(
    ctx context.Context,
    accountID string,
    cursor *Cursor,
    handler PaymentHandler,
) (err error)

StreamPayments streams payments, for which the given `accountID` was either the sender or receiver. Use context.WithCancel to stop streaming or context.Background() if you want to stream indefinitely. Deprecated: use horizonclient.StreamPayments instead

func (*Client) StreamTransactions Uses

func (c *Client) StreamTransactions(
    ctx context.Context,
    accountID string,
    cursor *Cursor,
    handler TransactionHandler,
) (err error)

StreamTransactions streams incoming transactions. Use context.WithCancel to stop streaming or context.Background() if you want to stream indefinitely. Deprecated: use horizonclient.StreamTransactions instead

func (*Client) SubmitTransaction Uses

func (c *Client) SubmitTransaction(
    transactionEnvelopeXdr string,
) (response TransactionSuccess, err error)

SubmitTransaction submits a transaction to the network. err can be either error object or horizon.Error object. Deprecated: use horizonclient.SubmitTransactionXDR instead

Code:

client := DefaultPublicNetClient
transactionEnvelopeXdr := "AAAAABSxFjMo7qcQlJBlrZQypSqYsHA5hHaYxk5hFXwiehh6AAAAZAAIdakAAABZAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAFLEWMyjupxCUkGWtlDKlKpiwcDmEdpjGTmEVfCJ6GHoAAAAAAAAAAACYloAAAAAAAAAAASJ6GHoAAABAp0FnKOQ9lJPDXPTh/a91xoZ8BaznwLj59sdDGK94eGzCOk7oetw7Yw50yOSZg2mqXAST6Agc9Ao/f5T9gB+GCw=="

response, err := client.SubmitTransaction(transactionEnvelopeXdr)
if err != nil {
    fmt.Println(err)
    herr, isHorizonError := err.(*Error)
    if isHorizonError {
        resultCodes, err := herr.ResultCodes()
        if err != nil {
            fmt.Println("failed to extract result codes from horizon response")
            return
        }
        fmt.Println(resultCodes)
    }
    return
}

fmt.Println("Success")
fmt.Println(response)

type ClientInterface Uses

type ClientInterface interface {
    Root() (Root, error)
    HomeDomainForAccount(aid string) (string, error)
    LoadAccount(accountID string) (Account, error)
    LoadAccountOffers(accountID string, params ...interface{}) (offers OffersPage, err error)
    LoadTradeAggregations(
        baseAsset Asset,
        counterAsset Asset,
        resolution int64,
        params ...interface{},
    ) (tradeAggrs TradeAggregationsPage, err error)
    LoadTrades(
        baseAsset Asset,
        counterAsset Asset,
        offerID int64,
        resolution int64,
        params ...interface{},
    ) (tradesPage TradesPage, err error)
    LoadAccountMergeAmount(p *Payment) error
    LoadMemo(p *Payment) error
    LoadOperation(operationID string) (payment Payment, err error)
    LoadOrderBook(selling Asset, buying Asset, params ...interface{}) (orderBook OrderBookSummary, err error)
    LoadTransaction(transactionID string) (transaction Transaction, err error)
    LoadAccountTransactions(transactionID string, params ...interface{}) (transactions TransactionsPage, err error)
    SequenceForAccount(accountID string) (xdr.SequenceNumber, error)
    StreamLedgers(ctx context.Context, cursor *Cursor, handler LedgerHandler) error
    StreamPayments(ctx context.Context, accountID string, cursor *Cursor, handler PaymentHandler) error
    StreamTransactions(ctx context.Context, accountID string, cursor *Cursor, handler TransactionHandler) error
    SubmitTransaction(txeBase64 string) (TransactionSuccess, error)
}

type Cursor Uses

type Cursor string

Cursor represents `cursor` param in queries

type Effect Uses

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

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

type EffectsPage Uses

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

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

type EndTime Uses

type EndTime int64

EndTime is an integer values of timestamp

type Error Uses

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

Error struct contains the problem returned by Horizon

func (*Error) Envelope Uses

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

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

func (Error) Error Uses

func (herr Error) Error() string

func (*Error) ResultCodes Uses

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

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

func (*Error) ResultString Uses

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

ResultString extracts the transaction result as a string.

type HTTP Uses

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 Ledger Uses

type Ledger = hProtocol.Ledger

Deprecated: use protocols/horizon instead

type LedgerHandler Uses

type LedgerHandler func(Ledger)

LedgerHandler is a function that is called when a new ledger is received

type Limit Uses

type Limit uint

Limit represents `limit` param in queries

type Link = hal.Link

Deprecated: use render/hal instead

type MockClient Uses

type MockClient struct {
    mock.Mock
}

MockClient is a mockable horizon client.

func (*MockClient) HomeDomainForAccount Uses

func (m *MockClient) HomeDomainForAccount(aid string) (string, error)

HomeDomainForAccount is a mocking a method

func (*MockClient) LoadAccount Uses

func (m *MockClient) LoadAccount(accountID string) (Account, error)

LoadAccount is a mocking a method

func (*MockClient) LoadAccountMergeAmount Uses

func (m *MockClient) LoadAccountMergeAmount(p *Payment) error

LoadAccountMergeAmount is a mocking a method

func (*MockClient) LoadAccountOffers Uses

func (m *MockClient) LoadAccountOffers(
    accountID string,
    params ...interface{},
) (offers OffersPage, err error)

LoadAccountOffers is a mocking a method

func (*MockClient) LoadAccountTransactions Uses

func (m *MockClient) LoadAccountTransactions(accountId string, params ...interface{}) (transactionPage TransactionsPage, err error)

LoadAccountTransactions is a mocking a method

func (*MockClient) LoadMemo Uses

func (m *MockClient) LoadMemo(p *Payment) error

LoadMemo is a mocking a method

func (*MockClient) LoadOperation Uses

func (m *MockClient) LoadOperation(operationID string) (payment Payment, err error)

LoadMemo is a mocking a method

func (*MockClient) LoadOrderBook Uses

func (m *MockClient) LoadOrderBook(
    selling Asset,
    buying Asset,
    params ...interface{},
) (orderBook OrderBookSummary, err error)

LoadOrderBook is a mocking a method

func (*MockClient) LoadTradeAggregations Uses

func (m *MockClient) LoadTradeAggregations(
    baseAsset Asset,
    counterAsset Asset,
    resolution int64,
    params ...interface{},
) (tradeAggrs TradeAggregationsPage, err error)

LoadTradeAggregations is a mocking a method

func (*MockClient) LoadTrades Uses

func (m *MockClient) LoadTrades(
    baseAsset Asset,
    counterAsset Asset,
    offerID int64,
    resolution int64,
    params ...interface{},
) (tradesPage TradesPage, err error)

LoadTrades is a mocking a method

func (*MockClient) LoadTransaction Uses

func (m *MockClient) LoadTransaction(transactionID string) (transaction Transaction, err error)

LoadTransaction is a mocking a method

func (*MockClient) Root Uses

func (m *MockClient) Root() (Root, error)

Root is a mocking a method

func (*MockClient) SequenceForAccount Uses

func (m *MockClient) SequenceForAccount(accountID string) (xdr.SequenceNumber, error)

SequenceForAccount is a mocking a method

func (*MockClient) StreamLedgers Uses

func (m *MockClient) StreamLedgers(
    ctx context.Context,
    cursor *Cursor,
    handler LedgerHandler,
) error

StreamLedgers is a mocking a method

func (*MockClient) StreamPayments Uses

func (m *MockClient) StreamPayments(
    ctx context.Context,
    accountID string,
    cursor *Cursor,
    handler PaymentHandler,
) error

StreamPayments is a mocking a method

func (*MockClient) StreamTransactions Uses

func (m *MockClient) StreamTransactions(
    ctx context.Context,
    accountID string,
    cursor *Cursor,
    handler TransactionHandler,
) error

StreamTransactions is a mocking a method

func (*MockClient) SubmitTransaction Uses

func (m *MockClient) SubmitTransaction(
    txeBase64 string,
) (TransactionSuccess, error)

SubmitTransaction is a mocking a method

type Offer Uses

type Offer = hProtocol.Offer

Deprecated: use protocols/horizon instead

type OffersPage Uses

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

OffersPage returns a list of offers

type Order Uses

type Order string

Order represents `order` param in queries

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

type OrderBookSummary Uses

type OrderBookSummary = hProtocol.OrderBookSummary

Deprecated: use protocols/horizon instead

type Payment Uses

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 PaymentHandler Uses

type PaymentHandler func(Payment)

PaymentHandler is a function that is called when a new payment is received

type Price Uses

type Price = hProtocol.Price

Deprecated: use protocols/horizon instead

type PriceLevel Uses

type PriceLevel = hProtocol.PriceLevel

Deprecated: use protocols/horizon instead

type Problem Uses

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 Uses

func (prob Problem) ToProblem() problem.P

ToProblem converts the Problem to a problem.P

type Root Uses

type Root = hProtocol.Root

Deprecated: use protocols/horizon instead

type Signer Uses

type Signer = hProtocol.Signer

Deprecated: use protocols/horizon instead

type StartTime Uses

type StartTime int64

StartTime is an integer values of timestamp

type Trade Uses

type Trade = hProtocol.Trade

Deprecated: use protocols/horizon instead

type TradeAggregation Uses

type TradeAggregation = hProtocol.TradeAggregation

Deprecated: use protocols/horizon instead

type TradeAggregationsPage Uses

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 Uses

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 Uses

type Transaction = hProtocol.Transaction

Deprecated: use protocols/horizon instead

type TransactionHandler Uses

type TransactionHandler func(Transaction)

TransactionHandler is a function that is called when a new transaction is received

type TransactionResultCodes Uses

type TransactionResultCodes = hProtocol.TransactionResultCodes

Deprecated: use protocols/horizon instead

type TransactionSuccess Uses

type TransactionSuccess = hProtocol.TransactionSuccess

Deprecated: use protocols/horizon instead

type TransactionsPage Uses

type TransactionsPage struct {
    Links    hal.Links `json:"_links"`
    Embedded struct {
        Records []hProtocol.Transaction `json:"records"`
    }   `json:"_embedded"`
}

Package horizon imports 20 packages (graph) and is imported by 83 packages. Updated 2019-09-13. Refresh now. Tools for package owners.