1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
crate::ix!();
//-------------------------------------------[.cpp/bitcoin/src/qt/bitcoinunits.h]
/**
| U+2009 THIN SPACE = UTF-8 E2 80 89
|
*/
pub const REAL_THIN_SP_CP: usize = 0x2009;
pub const REAL_THIN_SP_UTF8: &[u8] = &[0xE2, 0x80, 0x89];
/**
| QMessageBox seems to have a bug whereby it
| doesn't display thin/hair spaces correctly.
| Workaround is to display a space in a small
| font. If you change this, please test that it
| doesn't cause the parent span to start
| wrapping.
*/
pub const HTML_HACK_SP: &'static str = "<span style='white-space: nowrap; font-size: 6pt'> </span>";
/**
Define THIN_SP_* variables to be our preferred
type of thin space
*/
macro_rules! thin_sp_cp {
() => {
/*
REAL_THIN_SP_CP
*/
}
}
macro_rules! thin_sp_utf8 {
() => {
/*
REAL_THIN_SP_UTF8
*/
}
}
macro_rules! thin_sp_html {
() => {
/*
HTML_HACK_SP
*/
}
}
/**
| Bitcoin unit definitions. Encapsulates
| parsing and formatting and serves as
| list model for drop-down selection
| boxes.
|
*/
#[Q_OBJECT]
pub struct BitcoinUnits {
base: QAbstractListModel,
unitlist: QList<bitcoin_units::Unit>,
}
pub mod bitcoin_units {
use super::*;
/**
| @name AbstractListModel implementation
|
| List model for unit drop-down selection
| box.
|
*/
#[repr(i32)]
pub enum RoleIndex {
/**
| Unit identifier
|
*/
UnitRole = USER_ROLE
}
/**
| Bitcoin units.
|
| -----------
| @note
|
| Source: https://en.bitcoin.it/wiki/Units
| . Please add only sensible ones
|
*/
pub enum Unit
{
BTC,
mBTC,
uBTC,
SAT
}
pub enum SeparatorStyle
{
NEVER,
STANDARD,
ALWAYS
}
/*
| @name Static API
|
| Unit conversion and formatting
|
*/
/**
| Get list of units, for drop-down box
|
*/
pub fn available_units() -> QList<Unit> {
todo!();
/*
*/
}
/**
| Is unit ID valid?
|
*/
pub fn valid(unit: i32) -> bool {
todo!();
/*
*/
}
/**
| Long name
|
*/
pub fn long_name(unit: i32) -> String {
todo!();
/*
*/
}
/**
| Short name
|
*/
pub fn short_name(unit: i32) -> String {
todo!();
/*
*/
}
/**
| Longer description
|
*/
pub fn description(unit: i32) -> String {
todo!();
/*
*/
}
/**
| Number of Satoshis (1e-8) per unit
|
*/
pub fn factor(unit: i32) -> i64 {
todo!();
/*
*/
}
/**
| Number of decimals left
|
*/
pub fn decimals(unit: i32) -> i32 {
todo!();
/*
*/
}
/**
| Format as string
|
*/
pub fn format(
unit: i32,
amount: &Amount,
plussign: Option<bool>,
separators: Option<SeparatorStyle>,
justify: Option<bool>) -> String {
let plussign: bool = plussign.unwrap_or(false);
let separators: SeparatorStyle = separators.unwrap_or(SeparatorStyle::STANDARD);
let justify: bool = justify.unwrap_or(false);
todo!();
/*
*/
}
/**
| Format as string (with unit)
|
*/
pub fn format_with_unit(
unit: i32,
amount: &Amount,
plussign: Option<bool>,
separators: Option<SeparatorStyle>) -> String {
let plussign: bool = plussign.unwrap_or(false);
let separators: SeparatorStyle = separators.unwrap_or(SeparatorStyle::STANDARD);
todo!();
/*
*/
}
/**
| Format as HTML string (with unit)
|
*/
pub fn format_html_with_unit(
unit: i32,
amount: &Amount,
plussign: Option<bool>,
separators: Option<SeparatorStyle>) -> String {
let plussign: bool = plussign.unwrap_or(false);
let separators: SeparatorStyle = separators.unwrap_or(SeparatorStyle::STANDARD);
todo!();
/*
*/
}
/**
| Format as string (with unit) of fixed
| length to preserve privacy, if it is
| set.
|
*/
pub fn format_with_privacy(
unit: i32,
amount: &Amount,
separators: SeparatorStyle,
privacy: bool) -> String {
todo!();
/*
*/
}
/**
| Parse string to coin amount
|
*/
pub fn parse(
unit: i32,
value: &String,
val_out: *mut Amount) -> bool {
todo!();
/*
*/
}
pub fn row_count(parent: &QModelIndex) -> i32 {
todo!();
/*
*/
}
pub fn data(
index: &QModelIndex,
role: i32) -> QVariant {
todo!();
/*
*/
}
pub fn remove_spaces(text: String) -> String {
todo!();
/*
text.remove(' ');
text.remove(QChar(THIN_SP_CP));
return text;
*/
}
/**
| Return maximum number of base units
| (Satoshis)
|
*/
pub fn max_money() -> Amount {
todo!();
/*
*/
}
}
pub type BitcoinUnit = bitcoin_units::Unit;
//-------------------------------------------[.cpp/bitcoin/src/qt/bitcoinunits.cpp]
pub const MAX_DIGITS_BTC: usize = 16;
impl BitcoinUnits {
pub fn new(parent: *mut QObject) -> Self {
todo!();
/*
: q_abstract_list_model(parent),
: unitlist(availableUnits()),
*/
}
pub fn available_units(&mut self) -> QList<bitcoin_units::Unit> {
todo!();
/*
QList<BitcoinUnits::Unit> unitlist;
unitlist.append(BTC);
unitlist.append(mBTC);
unitlist.append(uBTC);
unitlist.append(SAT);
return unitlist;
*/
}
pub fn valid(&mut self, unit: i32) -> bool {
todo!();
/*
switch(unit)
{
case BTC:
case mBTC:
case uBTC:
case SAT:
return true;
default:
return false;
}
*/
}
pub fn long_name(&mut self, unit: i32) -> String {
todo!();
/*
switch(unit)
{
case BTC: return QString("BTC");
case mBTC: return QString("mBTC");
case uBTC: return QString::fromUtf8("µBTC (bits)");
case SAT: return QString("Satoshi (sat)");
default: return QString("???");
}
*/
}
pub fn short_name(&mut self, unit: i32) -> String {
todo!();
/*
switch(unit)
{
case uBTC: return QString::fromUtf8("bits");
case SAT: return QString("sat");
default: return longName(unit);
}
*/
}
pub fn description(&mut self, unit: i32) -> String {
todo!();
/*
switch(unit)
{
case BTC: return QString("Bitcoins");
case mBTC: return QString("Milli-Bitcoins (1 / 1" THIN_SP_UTF8 "000)");
case uBTC: return QString("Micro-Bitcoins (bits) (1 / 1" THIN_SP_UTF8 "000" THIN_SP_UTF8 "000)");
case SAT: return QString("Satoshi (sat) (1 / 100" THIN_SP_UTF8 "000" THIN_SP_UTF8 "000)");
default: return QString("???");
}
*/
}
pub fn factor(&mut self, unit: i32) -> i64 {
todo!();
/*
switch(unit)
{
case BTC: return 100000000;
case mBTC: return 100000;
case uBTC: return 100;
case SAT: return 1;
default: return 100000000;
}
*/
}
pub fn decimals(&mut self, unit: i32) -> i32 {
todo!();
/*
switch(unit)
{
case BTC: return 8;
case mBTC: return 5;
case uBTC: return 2;
case SAT: return 0;
default: return 0;
}
*/
}
pub fn format(&mut self,
unit: i32,
n_in: &Amount,
plus: bool,
separators: bitcoin_units::SeparatorStyle,
justify: bool) -> String {
todo!();
/*
// Note: not using straight sprintf here because we do NOT want
// localized number formatting.
if(!valid(unit))
return QString(); // Refuse to format invalid unit
i64 n = (i64)nIn;
i64 coin = factor(unit);
int num_decimals = decimals(unit);
i64 n_abs = (n > 0 ? n : -n);
i64 quotient = n_abs / coin;
QString quotient_str = QString::number(quotient);
if (justify) {
quotient_str = quotient_str.rightJustified(MAX_DIGITS_BTC - num_decimals, ' ');
}
// Use SI-style thin space separators as these are locale independent and can't be
// confused with the decimal marker.
QChar thin_sp(THIN_SP_CP);
int q_size = quotient_str.size();
if (separators == SeparatorStyle::ALWAYS || (separators == SeparatorStyle::STANDARD && q_size > 4))
for (int i = 3; i < q_size; i += 3)
quotient_str.insert(q_size - i, thin_sp);
if (n < 0)
quotient_str.insert(0, '-');
else if (fPlus && n > 0)
quotient_str.insert(0, '+');
if (num_decimals > 0) {
i64 remainder = n_abs % coin;
QString remainder_str = QString::number(remainder).rightJustified(num_decimals, '0');
return quotient_str + QString(".") + remainder_str;
} else {
return quotient_str;
}
*/
}
/**
| NOTE: Using formatWithUnit in an HTML context
| risks wrapping quantities at the thousands
| separator. More subtly, it also results in
| a standard space rather than a thin space, due
| to a bug in Qt's XML whitespace
| canonicalisation
|
| Please take care to use formatHtmlWithUnit
| instead, when appropriate.
*/
pub fn format_with_unit(&mut self,
unit: i32,
amount: &Amount,
plussign: bool,
separators: bitcoin_units::SeparatorStyle) -> String {
todo!();
/*
return format(unit, amount, plussign, separators) + QString(" ") + shortName(unit);
*/
}
pub fn format_html_with_unit(&mut self,
unit: i32,
amount: &Amount,
plussign: bool,
separators: bitcoin_units::SeparatorStyle) -> String {
todo!();
/*
QString str(formatWithUnit(unit, amount, plussign, separators));
str.replace(QChar(THIN_SP_CP), QString(THIN_SP_HTML));
return QString("<span style='white-space: nowrap;'>%1</span>").arg(str);
*/
}
pub fn format_with_privacy(&mut self,
unit: i32,
amount: &Amount,
separators: bitcoin_units::SeparatorStyle,
privacy: bool) -> String {
todo!();
/*
assert(amount >= 0);
QString value;
if (privacy) {
value = format(unit, 0, false, separators, true).replace('0', '#');
} else {
value = format(unit, amount, false, separators, true);
}
return value + QString(" ") + shortName(unit);
*/
}
pub fn parse(&mut self,
unit: i32,
value: &String,
val_out: *mut Amount) -> bool {
todo!();
/*
if(!valid(unit) || value.isEmpty())
return false; // Refuse to parse invalid unit or empty string
int num_decimals = decimals(unit);
// Ignore spaces and thin spaces when parsing
QStringList parts = removeSpaces(value).split(".");
if(parts.size() > 2)
{
return false; // More than one dot
}
QString whole = parts[0];
QString decimals;
if(parts.size() > 1)
{
decimals = parts[1];
}
if(decimals.size() > num_decimals)
{
return false; // Exceeds max precision
}
bool ok = false;
QString str = whole + decimals.leftJustified(num_decimals, '0');
if(str.size() > 18)
{
return false; // Longer numbers will exceed 63 bits
}
CAmount retvalue(str.toLongLong(&ok));
if(val_out)
{
*val_out = retvalue;
}
return ok;
*/
}
/**
| Gets title for amount column including
| current display unit if optionsModel
| reference available
|
*/
pub fn get_amount_column_title(&mut self, unit: i32) -> String {
todo!();
/*
QString amountTitle = QObject::tr("Amount");
if (BitcoinUnits::valid(unit))
{
amountTitle += " ("+BitcoinUnits::shortName(unit) + ")";
}
return amountTitle;
*/
}
pub fn row_count(&self, parent: &QModelIndex) -> i32 {
todo!();
/*
Q_UNUSED(parent);
return unitlist.size();
*/
}
pub fn data(&self,
index: &QModelIndex,
role: i32) -> QVariant {
todo!();
/*
int row = index.row();
if(row >= 0 && row < unitlist.size())
{
Unit unit = unitlist.at(row);
switch(role)
{
case QtEditRole:
case QtDisplayRole:
return QVariant(longName(unit));
case QtToolTipRole:
return QVariant(description(unit));
case UnitRole:
return QVariant(static_cast<int>(unit));
}
}
return QVariant();
*/
}
pub fn max_money(&mut self) -> Amount {
todo!();
/*
return MAX_MONEY;
*/
}
}