client

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 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)

	// Transfers
	GetTransfer(ctx context.Context, contractID string) (*indexer.Transfer, error)
	GetTransfers(
		ctx context.Context, partyID string, query indexer.TransferQuery, p indexer.Pagination,
	) (*indexer.Page[indexer.Transfer], error)
	GetPendingTransfers(ctx context.Context, p indexer.Pagination) (*indexer.Page[indexer.Transfer], 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"
	OpGetTransfer          ClientOperation = "get_transfer"
	OpGetTransfers         ClientOperation = "get_transfers"
	OpGetPendingTransfers  ClientOperation = "get_pending_transfers"
)

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) 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) GetPendingTransfers added in v0.8.0

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

GetPendingTransfers calls GET /indexer/v1/admin/pending-transfers.

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) GetTransfer added in v0.8.0

func (c *HTTP) GetTransfer(ctx context.Context, contractID string) (*indexer.Transfer, error)

GetTransfer calls GET /indexer/v1/admin/transfers/{contractID}. A 404 is mapped to a not-found app error by getJSON.

func (*HTTP) GetTransfers added in v0.8.0

func (c *HTTP) GetTransfers(
	ctx context.Context, partyID string, query indexer.TransferQuery, p indexer.Pagination,
) (*indexer.Page[indexer.Transfer], error)

GetTransfers calls GET /indexer/v1/admin/parties/{partyID}/transfers, filtering by role (receiver/sender/any) and status (pending/expired/completed/canceled; "" = all).

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) 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) GetPendingTransfers added in v0.8.0

func (c *InstrumentedClient) GetPendingTransfers(
	ctx context.Context, p indexer.Pagination,
) (*indexer.Page[indexer.Transfer], error)

func (*InstrumentedClient) GetToken

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

func (*InstrumentedClient) GetTransfer added in v0.8.0

func (c *InstrumentedClient) GetTransfer(ctx context.Context, contractID string) (*indexer.Transfer, error)

func (*InstrumentedClient) GetTransfers added in v0.8.0

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