Raven Core  3.0.0
P2P Digital Currency
assetrecord.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef RAVEN_QT_ASSETRECORD_H
7 #define RAVEN_QT_ASSETRECORD_H
8 
9 #include "math.h"
10 #include "amount.h"
11 #include "tinyformat.h"
12 
13 
17 {
18 public:
19 
21  name(""), quantity(0), units(0), fIsAdministrator(false)
22  {
23  }
24 
25  AssetRecord(const std::string _name, const CAmount& _quantity, const int _units, const bool _fIsAdministrator):
26  name(_name), quantity(_quantity), units(_units), fIsAdministrator(_fIsAdministrator)
27  {
28  }
29 
30  std::string formattedQuantity() const {
31  bool sign = quantity < 0;
32  int64_t n_abs = (sign ? -quantity : quantity);
33  int64_t quotient = n_abs / COIN;
34  int64_t remainder = n_abs % COIN;
35  remainder = remainder / pow(10, 8 - units);
36 
37  if (remainder == 0) {
38  return strprintf("%s%d", sign ? "-" : "", quotient);
39  }
40  else {
41  return strprintf("%s%d.%0" + std::to_string(units) + "d", sign ? "-" : "", quotient, remainder);
42  }
43  }
44 
47  std::string name;
49  int units;
53 };
54 
55 #endif // RAVEN_QT_ASSETRECORD_H
#define strprintf
Definition: tinyformat.h:1054
std::string name
Definition: assetrecord.h:47
int64_t CAmount
Amount in corbies (Can be negative)
Definition: amount.h:13
UI model for unspent assets.
Definition: assetrecord.h:16
bool fIsAdministrator
Definition: assetrecord.h:50
AssetRecord(const std::string _name, const CAmount &_quantity, const int _units, const bool _fIsAdministrator)
Definition: assetrecord.h:25
std::string formattedQuantity() const
Definition: assetrecord.h:30
CAmount quantity
Definition: assetrecord.h:48