Documentation
¶
Overview ¶
Package client provides an HTTP client for the indexer's admin API.
Index ¶
- type Client
- type ClientOperation
- type HTTP
- func (c *HTTP) GetAllPendingOffers(ctx context.Context, p indexer.Pagination) (*indexer.Page[indexer.PendingOffer], error)
- func (c *HTTP) GetBalance(ctx context.Context, partyID, admin, id string) (*indexer.Balance, error)
- func (c *HTTP) GetEvent(ctx context.Context, contractID string) (*indexer.ParsedEvent, error)
- func (c *HTTP) GetPendingOffersForParty(ctx context.Context, partyID string, p indexer.Pagination) (*indexer.Page[indexer.PendingOffer], error)
- func (c *HTTP) GetToken(ctx context.Context, admin, id string) (*indexer.Token, error)
- func (c *HTTP) ListBalancesForParty(ctx context.Context, partyID string, p indexer.Pagination) (*indexer.Page[*indexer.Balance], error)
- func (c *HTTP) ListBalancesForToken(ctx context.Context, admin, id string, p indexer.Pagination) (*indexer.Page[*indexer.Balance], error)
- func (c *HTTP) ListPartyEvents(ctx context.Context, partyID string, f indexer.EventFilter, ...) (*indexer.Page[*indexer.ParsedEvent], error)
- func (c *HTTP) ListTokenEvents(ctx context.Context, admin, id string, f indexer.EventFilter, ...) (*indexer.Page[*indexer.ParsedEvent], error)
- func (c *HTTP) ListTokens(ctx context.Context, p indexer.Pagination) (*indexer.Page[*indexer.Token], error)
- func (c *HTTP) TotalSupply(ctx context.Context, admin, id string) (string, error)
- type InstrumentedClient
- func (c *InstrumentedClient) GetAllPendingOffers(ctx context.Context, p indexer.Pagination) (*indexer.Page[indexer.PendingOffer], error)
- func (c *InstrumentedClient) GetBalance(ctx context.Context, partyID, admin, id string) (*indexer.Balance, error)
- func (c *InstrumentedClient) GetEvent(ctx context.Context, contractID string) (*indexer.ParsedEvent, error)
- func (c *InstrumentedClient) GetPendingOffersForParty(ctx context.Context, partyID string, p indexer.Pagination) (*indexer.Page[indexer.PendingOffer], error)
- func (c *InstrumentedClient) GetToken(ctx context.Context, admin, id string) (*indexer.Token, error)
- func (c *InstrumentedClient) ListBalancesForParty(ctx context.Context, partyID string, p indexer.Pagination) (*indexer.Page[*indexer.Balance], error)
- func (c *InstrumentedClient) ListBalancesForToken(ctx context.Context, admin, id string, p indexer.Pagination) (*indexer.Page[*indexer.Balance], error)
- func (c *InstrumentedClient) ListPartyEvents(ctx context.Context, partyID string, f indexer.EventFilter, ...) (*indexer.Page[*indexer.ParsedEvent], error)
- func (c *InstrumentedClient) ListTokenEvents(ctx context.Context, admin, id string, f indexer.EventFilter, ...) (*indexer.Page[*indexer.ParsedEvent], error)
- func (c *InstrumentedClient) ListTokens(ctx context.Context, p indexer.Pagination) (*indexer.Page[*indexer.Token], error)
- func (c *InstrumentedClient) TotalSupply(ctx context.Context, admin, id string) (string, error)
- type Metrics
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
// Token queries
GetToken(ctx context.Context, admin, id string) (*indexer.Token, error)
ListTokens(ctx context.Context, p indexer.Pagination) (*indexer.Page[*indexer.Token], error)
// ERC-20 analogs
TotalSupply(ctx context.Context, admin, id string) (string, error)
// Balance queries
GetBalance(ctx context.Context, partyID, admin, id string) (*indexer.Balance, error)
ListBalancesForParty(ctx context.Context, partyID string, p indexer.Pagination) (*indexer.Page[*indexer.Balance], error)
ListBalancesForToken(ctx context.Context, admin, id string, p indexer.Pagination) (*indexer.Page[*indexer.Balance], error)
// Audit trail
GetEvent(ctx context.Context, contractID string) (*indexer.ParsedEvent, error)
ListTokenEvents(
ctx context.Context,
admin, id string,
f indexer.EventFilter,
p indexer.Pagination,
) (*indexer.Page[*indexer.ParsedEvent], error)
ListPartyEvents(
ctx context.Context,
partyID string,
f indexer.EventFilter,
p indexer.Pagination,
) (*indexer.Page[*indexer.ParsedEvent], error)
// Pending inbound transfers
GetPendingOffersForParty(ctx context.Context, partyID string, p indexer.Pagination) (*indexer.Page[indexer.PendingOffer], error)
GetAllPendingOffers(ctx context.Context, p indexer.Pagination) (*indexer.Page[indexer.PendingOffer], error)
}
Client is the read interface over the indexer's HTTP admin API. Its method set mirrors indexer/service.Service so that callers are agnostic to whether they are talking to an in-process service or a remote indexer.
type ClientOperation ¶
type ClientOperation string
ClientOperation identifies an indexer client method for metrics labeling.
const ( OpGetToken ClientOperation = "get_token" OpListTokens ClientOperation = "list_tokens" OpTotalSupply ClientOperation = "total_supply" OpGetBalance ClientOperation = "get_balance" OpListBalancesForParty ClientOperation = "list_balances_for_party" OpListBalancesForToken ClientOperation = "list_balances_for_token" OpGetEvent ClientOperation = "get_event" OpListTokenEvents ClientOperation = "list_token_events" OpListPartyEvents ClientOperation = "list_party_events" OpGetPendingOffersForPty ClientOperation = "get_pending_offers_for_party" OpGetAllPendingOffers ClientOperation = "get_all_pending_offers" )
type HTTP ¶
type HTTP struct {
// contains filtered or unexported fields
}
HTTP implements Client by calling the indexer's unauthenticated admin HTTP API. All paths are under /indexer/v1/admin.
func New ¶
New creates an HTTP-backed indexer client. baseURL is the indexer's base URL (e.g. "http://localhost:8080" or "http://localhost:8080/"). The path component is cleaned so that appended paths are never double-slashed. httpClient may be nil; http.DefaultClient is used in that case.
func (*HTTP) GetAllPendingOffers ¶
func (c *HTTP) GetAllPendingOffers( ctx context.Context, p indexer.Pagination, ) (*indexer.Page[indexer.PendingOffer], error)
GetAllPendingOffers calls GET /indexer/v1/admin/pending-offers.
func (*HTTP) GetBalance ¶
GetBalance calls GET /indexer/v1/admin/parties/{partyID}/balances/{admin}/{id}. Returns apperrors.ResourceNotFoundError when the party has no balance record.
func (*HTTP) GetPendingOffersForParty ¶
func (c *HTTP) GetPendingOffersForParty( ctx context.Context, partyID string, p indexer.Pagination, ) (*indexer.Page[indexer.PendingOffer], error)
GetPendingOffersForParty calls GET /indexer/v1/admin/parties/{partyID}/pending-offers.
func (*HTTP) ListBalancesForParty ¶
func (c *HTTP) ListBalancesForParty(ctx context.Context, partyID string, p indexer.Pagination) (*indexer.Page[*indexer.Balance], error)
ListBalancesForParty calls GET /indexer/v1/admin/parties/{partyID}/balances.
func (*HTTP) ListBalancesForToken ¶
func (c *HTTP) ListBalancesForToken(ctx context.Context, admin, id string, p indexer.Pagination) (*indexer.Page[*indexer.Balance], error)
ListBalancesForToken calls GET /indexer/v1/admin/tokens/{admin}/{id}/balances.
func (*HTTP) ListPartyEvents ¶
func (c *HTTP) ListPartyEvents( ctx context.Context, partyID string, f indexer.EventFilter, p indexer.Pagination, ) (*indexer.Page[*indexer.ParsedEvent], error)
ListPartyEvents calls GET /indexer/v1/admin/parties/{partyID}/events.
func (*HTTP) ListTokenEvents ¶
func (c *HTTP) ListTokenEvents( ctx context.Context, admin, id string, f indexer.EventFilter, p indexer.Pagination, ) (*indexer.Page[*indexer.ParsedEvent], error)
ListTokenEvents calls GET /indexer/v1/admin/tokens/{admin}/{id}/events.
type InstrumentedClient ¶
type InstrumentedClient struct {
// contains filtered or unexported fields
}
InstrumentedClient wraps a Client and records Prometheus metrics for every outbound indexer HTTP call.
func NewInstrumentedClient ¶
func NewInstrumentedClient(inner Client, metrics *Metrics) *InstrumentedClient
NewInstrumentedClient returns a metrics-instrumented wrapper around the given Client.
func (*InstrumentedClient) GetAllPendingOffers ¶
func (c *InstrumentedClient) GetAllPendingOffers( ctx context.Context, p indexer.Pagination, ) (*indexer.Page[indexer.PendingOffer], error)
func (*InstrumentedClient) GetBalance ¶
func (*InstrumentedClient) GetEvent ¶
func (c *InstrumentedClient) GetEvent(ctx context.Context, contractID string) (*indexer.ParsedEvent, error)
func (*InstrumentedClient) GetPendingOffersForParty ¶
func (c *InstrumentedClient) GetPendingOffersForParty( ctx context.Context, partyID string, p indexer.Pagination, ) (*indexer.Page[indexer.PendingOffer], error)
func (*InstrumentedClient) ListBalancesForParty ¶
func (*InstrumentedClient) ListBalancesForToken ¶
func (*InstrumentedClient) ListPartyEvents ¶
func (c *InstrumentedClient) ListPartyEvents( ctx context.Context, partyID string, f indexer.EventFilter, p indexer.Pagination, ) (*indexer.Page[*indexer.ParsedEvent], error)
func (*InstrumentedClient) ListTokenEvents ¶
func (c *InstrumentedClient) ListTokenEvents( ctx context.Context, admin, id string, f indexer.EventFilter, p indexer.Pagination, ) (*indexer.Page[*indexer.ParsedEvent], error)
func (*InstrumentedClient) ListTokens ¶
func (c *InstrumentedClient) ListTokens(ctx context.Context, p indexer.Pagination) (*indexer.Page[*indexer.Token], error)
func (*InstrumentedClient) TotalSupply ¶
type Metrics ¶
type Metrics struct {
// RequestDuration tracks the duration of indexer HTTP calls by method.
RequestDuration *prometheus.HistogramVec
// RequestErrors counts indexer HTTP calls that returned an error, by method.
RequestErrors *prometheus.CounterVec
}
Metrics holds Prometheus collectors for the indexer HTTP client.
func NewMetrics ¶
func NewMetrics(reg sharedmetrics.NamespacedRegisterer) *Metrics
NewMetrics registers indexer client metrics against the given registerer.
func NewNopMetrics ¶
func NewNopMetrics() *Metrics
NewNopMetrics returns a Metrics instance backed by a throwaway registry. Use in tests where metric values are not asserted.