#pragma once #include #include #include namespace dragonx { namespace util { std::string formatAmountFixed(double amount, int decimals = 8); // DRGX amounts are 8-decimal. Converting to int64 satoshis and comparing there avoids the IEEE-double // rounding that could block a valid exact-max send (amount+fee computed in doubles landed 1 ulp over). inline std::int64_t toSats(double coins) { return static_cast(std::llround(coins * 1e8)); } // True when amount + fee fits within available, compared in integer satoshis (not doubles). inline bool canAfford(double amount, double fee, double available) { return toSats(amount) + toSats(fee) <= toSats(available); } // Convert a coin amount to zatoshis for a send, rejecting non-finite / non-positive / rounds-to-zero / // over-supply values. Returns false (and leaves out untouched) on any of those. inline bool coinsToZatoshis(double coins, std::uint64_t& out) { if (!std::isfinite(coins) || coins <= 0.0) return false; const std::int64_t z = toSats(coins); if (z <= 0 || z > static_cast(21000000) * 100000000LL) return false; out = static_cast(z); return true; } } // namespace util } // namespace dragonx