A monetary amount in the smallest units of its asset.
value is a decimal string from "0" through "18446744073709551615".
asset_scale is an integer from 0 through 255. For example, a value of
"1000" with asset code "USD" and scale 2 represents USD 10.00.
new/3 and from_map/1 validate input without coercing numbers or changing
asset codes. Additional JSON fields are retained in extensions, as permitted
by the amount schema. JSON encoding uses the protocol's assetCode and
assetScale field names.
Struct literals can bypass constructor checks. Call validate/1 before using
a manually constructed or modified amount; to_map/1 only converts its shape.
Summary
Functions
Decodes a string-keyed JSON object and retains additional fields.
Constructs and validates an amount, keeping the supplied decimal string.
Converts an amount to its JSON field names without validating it.
Checks a struct against the shared amount contract.
Types
Functions
@spec from_map(map()) :: {:ok, t()} | {:error, OpenPayments.Error.t()}
Decodes a string-keyed JSON object and retains additional fields.
@spec new(String.t(), String.t(), integer()) :: {:ok, t()} | {:error, OpenPayments.Error.t()}
Constructs and validates an amount, keeping the supplied decimal string.
Converts an amount to its JSON field names without validating it.
@spec validate(t()) :: :ok | {:error, OpenPayments.Error.t()}
Checks a struct against the shared amount contract.