balance

package
v1.32.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package balance provides utilities for fetching a Flipcash user's balance from the OCP server.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound indicates the user has no account bound to a public key, so
	// there's no owner account to fetch a balance for.
	ErrNotFound = errors.New("no owner account found for user")

	// ErrDenied indicates the OCP server refused to disclose the balance of an
	// owner account.
	ErrDenied = errors.New("denied access to balance")

	// ErrAmbiguousOwner indicates the user has more than one public key bound,
	// so there is no single owner account to fetch a balance for. Nothing
	// binds a second key today; a user in this state is a bug, not a case.
	ErrAmbiguousOwner = errors.New("more than one owner account found for user")

	// ErrUnsupportedCurrency indicates the OCP server could not value a balance
	// in the requested fiat currency: it answered the owner, but with no value
	// for that currency code. OCP is the authority on which currencies it can
	// price, so this is how a code it does not know — or cannot quote right
	// now — surfaces; no list of supported codes is kept here.
	ErrUnsupportedCurrency = errors.New("unsupported balance currency")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client fetches user balances from the OCP server.

func NewClient

func NewClient(
	log *zap.Logger,
	accounts account.Store,
	ocpBalance ocp_balancepb.BalanceClient,
) *Client

NewClient returns a Client backed by the OCP Balance service. The parent application is responsible for constructing ocpBalance against the OCP server's gRPC endpoint.

func (*Client) GetTotalFiatValue added in v1.32.0

func (c *Client) GetTotalFiatValue(ctx context.Context, userID *commonpb.UserId, currency currency_lib.Code, mints ...*commonpb.PublicKey) (float64, error)

GetTotalFiatValue returns a user's total balance valued in a fiat currency, in that currency's major units — the same holdings GetTotalUsdfBalance totals, and the same mint filter, but as OCP values them at its current exchange rate rather than in quarks. The value is a quoted rate applied to a quark total, so a comparison against it should allow rounding slack.

The currency is any ISO 4217 code OCP can price. One it cannot is ErrUnsupportedCurrency, never a zero: a caller gating on the value must not mistake "no answer" for "holds nothing". A user that hasn't opened OCP accounts yet holds nothing in any currency, and ErrNotFound is returned when the user has no public key bound at all.

func (*Client) GetTotalUsdfBalance

func (c *Client) GetTotalUsdfBalance(ctx context.Context, userID *commonpb.UserId, mints ...*commonpb.PublicKey) (uint64, error)

GetTotalUsdfBalance returns a user's total balance in USDF quarks.

The value is what OCP reports as the owner account's core mint value, which is USDF for Flipcash. It spans every mint the user holds, with non-core mint holdings valued in USDF, so it is the user's total balance and not just the quarks sitting in their USDF accounts. Given mints, it spans only the holdings in those mints, still valued in USDF; a mint the user holds nothing of contributes nothing.

No fiat valuation is asked for, so the answer never depends on an exchange rate: a USD comparison against it is exact, in quarks.

A user that hasn't opened OCP accounts yet has a zero balance. ErrNotFound is returned when the user has no public key bound at all.

Jump to

Keyboard shortcuts

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