Versions in this module Expand all Collapse all v0 v0.0.2 Oct 16, 2026 Changes in this version + const MaxDecimalPlaces v0.0.1 Oct 14, 2026 Changes in this version + var ErrAccountConflict = errors.New("ledgo: account already exists with different settings") + var ErrCurrencyMismatch = errors.New("ledgo: entry currency differs from its account's") + var ErrIdempotencyConflict = errors.New("ledgo: idempotency key reused with different content") + var ErrInsufficientFunds = errors.New("ledgo: commit would break an account's balance limit") + var ErrInvalidRate = errors.New("ledgo: invalid FX rate") + var ErrNoAccount = errors.New("ledgo: missing account") + var ErrNoIdempotencyKey = errors.New("ledgo: missing idempotency key") + var ErrTooFewEntries = errors.New("ledgo: a transaction needs at least two entries") + var ErrTooManyDecimals = errors.New("ledgo: amount has more decimal places than its currency allows") + var ErrUnbalanced = errors.New("ledgo: transaction does not balance") + var ErrUnknownAccount = errors.New("ledgo: unknown account") + var ErrUnknownCurrency = errors.New("ledgo: unknown currency") + var ErrZeroAmount = errors.New("ledgo: zero amount") + func CheckEntries(entries []Entry, accounts map[string]Account) error + func RegisterCurrency(code string, decimalPlaces int32) + type Account struct + CreditsMustNotExceedDebits bool + Currency string + DebitsMustNotExceedCredits bool + ID string + func (a Account) CheckBalance(balance decimal.Decimal) error + func (a Account) HasLimit() bool + type Entry struct + Account string + Amount decimal.Decimal + Currency string + type Ledger struct + func New(store Store) *Ledger + func (l *Ledger) Balance(ctx context.Context, account string) (decimal.Decimal, error) + func (l *Ledger) Commit(ctx context.Context, tx Transaction) error + func (l *Ledger) CreateAccount(ctx context.Context, account Account) error + type Rate struct + From string + Source string + Time time.Time + To string + Value decimal.Decimal + func (r Rate) Convert(amount decimal.Decimal) (decimal.Decimal, error) + type Store interface + Balance func(ctx context.Context, account string) (decimal.Decimal, error) + Commit func(ctx context.Context, tx Transaction) error + CreateAccount func(ctx context.Context, account Account) error + type Transaction struct + Entries []Entry + IdempotencyKey string + Rate *Rate + Reference string + func (tx Transaction) Fingerprint() []byte + func (tx Transaction) Validate() error + type TransactionBuilder struct + func NewTransaction(idempotencyKey, reference string) TransactionBuilder + func (b TransactionBuilder) Accounts() []Account + func (b TransactionBuilder) Build() Transaction + func (b TransactionBuilder) Credit(account Account, amount decimal.Decimal) TransactionBuilder + func (b TransactionBuilder) Debit(account Account, amount decimal.Decimal) TransactionBuilder + func (b TransactionBuilder) IsEmpty() bool + func (b TransactionBuilder) Negated() TransactionBuilder + func (b TransactionBuilder) WithRate(rate Rate) TransactionBuilder