Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2011-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_QT_BITCOINUNITS_H6#define BITCOIN_QT_BITCOINUNITS_H8#include <consensus/amount.h>10#include <QAbstractListModel>11#include <QDataStream>12#include <QString>14// U+2009 THIN SPACE = UTF-8 E2 80 8915#define REAL_THIN_SP_CP 0x200916#define REAL_THIN_SP_UTF8 "\xE2\x80\x89"18// QMessageBox seems to have a bug whereby it doesn't display thin/hair spaces19// correctly. Workaround is to display a space in a small font. If you20// change this, please test that it doesn't cause the parent span to start21// wrapping.22#define HTML_HACK_SP "<span style='white-space: nowrap; font-size: 6pt'> </span>"24// Define THIN_SP_* variables to be our preferred type of thin space25#define THIN_SP_CP REAL_THIN_SP_CP26#define THIN_SP_UTF8 REAL_THIN_SP_UTF827#define THIN_SP_HTML HTML_HACK_SP29/** Bitcoin unit definitions. Encapsulates parsing and formatting30and serves as list model for drop-down selection boxes.31*/32class BitcoinUnits: public QAbstractListModel33{34Q_OBJECT36public:37explicit BitcoinUnits(QObject *parent);39/** Bitcoin units.40@note Source: https://en.bitcoin.it/wiki/Units . Please add only sensible ones41*/42enum class Unit {43BTC,44mBTC,45uBTC,46SAT47};48Q_ENUM(Unit)50enum class SeparatorStyle51{52NEVER,53STANDARD,54ALWAYS55};57//! @name Static API58//! Unit conversion and formatting59///@{61//! Get list of units, for drop-down box62static QList<Unit> availableUnits();63//! Long name64static QString longName(Unit unit);65//! Short name66static QString shortName(Unit unit);67//! Longer description68static QString description(Unit unit);69//! Number of Satoshis (1e-8) per unit70static qint64 factor(Unit unit);71//! Number of decimals left72static int decimals(Unit unit);73//! Format as string74static QString format(Unit unit, const CAmount& amount, bool plussign = false, SeparatorStyle separators = SeparatorStyle::STANDARD, bool justify = false);75//! Format as string (with unit)76static QString formatWithUnit(Unit unit, const CAmount& amount, bool plussign = false, SeparatorStyle separators = SeparatorStyle::STANDARD);77//! Format as HTML string (with unit)78static QString formatHtmlWithUnit(Unit unit, const CAmount& amount, bool plussign = false, SeparatorStyle separators = SeparatorStyle::STANDARD);79//! Format as string (with unit) of fixed length to preserve privacy, if it is set.80static QString formatWithPrivacy(Unit unit, const CAmount& amount, SeparatorStyle separators, bool privacy);81//! Parse string to coin amount82static bool parse(Unit unit, const QString& value, CAmount* val_out);83//! Gets title for amount column including current display unit if optionsModel reference available */84static QString getAmountColumnTitle(Unit unit);85///@}87//! @name AbstractListModel implementation88//! List model for unit drop-down selection box.89///@{90enum RoleIndex {91/** Unit identifier */92UnitRole = Qt::UserRole93};94int rowCount(const QModelIndex &parent) const override;95QVariant data(const QModelIndex &index, int role) const override;96///@}98static QString removeSpaces(QString text)99{100text.remove(' ');101text.remove(QChar(THIN_SP_CP));102return text;103}105//! Return maximum number of base units (Satoshis)106static CAmount maxMoney();108private:109QList<Unit> unitlist;110};111typedef BitcoinUnits::Unit BitcoinUnit;113QDataStream& operator<<(QDataStream& out, const BitcoinUnit& unit);114QDataStream& operator>>(QDataStream& in, BitcoinUnit& unit);116#endif // BITCOIN_QT_BITCOINUNITS_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.