client

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package client provides an HTTP client for the indexer's admin API.

Index

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

func New(baseURL string, httpClient *http.Client) (*HTTP, error)

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

func (c *HTTP) GetBalance(ctx context.Context, partyID, admin, id string) (*indexer.Balance, error)

GetBalance calls GET /indexer/v1/admin/parties/{partyID}/balances/{admin}/{id}. Returns apperrors.ResourceNotFoundError when the party has no balance record.

func (*HTTP) GetEvent

func (c *HTTP) GetEvent(ctx context.Context, contractID string) (*indexer.ParsedEvent, error)

GetEvent calls GET /indexer/v1/admin/events/{contractID}.

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) GetToken

func (c *HTTP) GetToken(ctx context.Context, admin, id string) (*indexer.Token, error)

GetToken calls GET /indexer/v1/admin/tokens/{admin}/{id}.

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.

func (*HTTP) ListTokens

func (c *HTTP) ListTokens(ctx context.Context, p indexer.Pagination) (*indexer.Page[*indexer.Token], error)

ListTokens calls GET /indexer/v1/admin/tokens.

func (*HTTP) TotalSupply

func (c *HTTP) TotalSupply(ctx context.Context, admin, id string) (string, error)

TotalSupply calls GET /indexer/v1/admin/tokens/{admin}/{id}/supply.

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 (c *InstrumentedClient) GetBalance(ctx context.Context, partyID, admin, id string) (*indexer.Balance, error)

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) GetToken

func (c *InstrumentedClient) GetToken(ctx context.Context, admin, id string) (*indexer.Token, error)

func (*InstrumentedClient) ListBalancesForParty

func (c *InstrumentedClient) ListBalancesForParty(
	ctx context.Context, partyID string, p indexer.Pagination,
) (*indexer.Page[*indexer.Balance], error)

func (*InstrumentedClient) ListBalancesForToken

func (c *InstrumentedClient) ListBalancesForToken(
	ctx context.Context, admin, id string, p indexer.Pagination,
) (*indexer.Page[*indexer.Balance], error)

func (*InstrumentedClient) ListPartyEvents

func (*InstrumentedClient) ListTokenEvents

func (*InstrumentedClient) ListTokens

func (*InstrumentedClient) TotalSupply

func (c *InstrumentedClient) TotalSupply(ctx context.Context, admin, id string) (string, error)

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

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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