amounts

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package amounts converts between SOVR display amounts and usovr base units with exact integer arithmetic (FR-017/FR-018). math/big only — no float64 on any path. Behavior is pinned by test-vectors/amounts.json; the TypeScript library mirrors every error code and check order exactly.

Index

Constants

View Source
const (
	// DisplayDecimals is the display exponent: 1 SOVR = 10^6 usovr.
	DisplayDecimals = 6
	// DefaultMaxBaseUnits is the 1,000,000,000-SOVR hard cap in usovr.
	DefaultMaxBaseUnits = "1000000000000000"
)
View Source
const (
	CodeTooManyDecimals    = "AMOUNT_TOO_MANY_DECIMALS"
	CodeNegative           = "AMOUNT_NEGATIVE"
	CodeScientificNotation = "AMOUNT_SCIENTIFIC_NOTATION"
	CodeCommas             = "AMOUNT_COMMAS"
	CodeEmpty              = "AMOUNT_EMPTY"
	CodeNotNumeric         = "AMOUNT_NOT_NUMERIC"
	CodeExceedsMax         = "AMOUNT_EXCEEDS_MAX"
)

FR-018 error codes. Stable API: exchanges branch on these strings.

Variables

This section is empty.

Functions

func BaseToDisplayUnits

func BaseToDisplayUnits(base string) (string, error)

BaseToDisplayUnits converts base units ("10250000") to the canonical display amount ("10.25") under the default 1B-SOVR maximum. Output is round-trip exact: DisplayToBaseUnits(BaseToDisplayUnits(x)) == x.

func BaseToDisplayUnitsWithMax

func BaseToDisplayUnitsWithMax(base, maxBaseUnits string) (string, error)

BaseToDisplayUnitsWithMax is BaseToDisplayUnits with a caller-configured maximum (inclusive) in base units.

func CodeOf

func CodeOf(err error) string

CodeOf returns the FR-018 code of err, or "" if err is not an amounts.Error.

func DisplayToBaseUnits

func DisplayToBaseUnits(display string) (string, error)

DisplayToBaseUnits converts a display amount ("10.25") to base units ("10250000") under the default 1B-SOVR maximum.

func DisplayToBaseUnitsWithMax

func DisplayToBaseUnitsWithMax(display, maxBaseUnits string) (string, error)

DisplayToBaseUnitsWithMax is DisplayToBaseUnits with a caller-configured maximum (inclusive), itself expressed in base units.

Types

type Error

type Error struct {
	Code    string
	Message string
}

Error is an amount-conversion rejection with its FR-018 code.

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

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