CatapultServer  v0.5.0.1 (Elephant)
AccountBalances.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "CompactMosaicMap.h"
23 #include "catapult/utils/Hashers.h"
24 #include "catapult/exceptions.h"
25 #include "catapult/types.h"
26 #include <unordered_map>
27 
28 namespace catapult { namespace state {
29 
32  public:
35 
37  AccountBalances(const AccountBalances& accountBalances);
38 
40  AccountBalances(AccountBalances&& accountBalances);
41 
42  public:
44  AccountBalances& operator=(const AccountBalances& accountBalances);
45 
47  AccountBalances& operator=(AccountBalances&& accountBalances);
48 
49  public:
51  size_t size() const {
52  return m_balances.size();
53  }
54 
56  auto begin() const {
57  return m_balances.begin();
58  }
59 
61  auto end() const {
62  return m_balances.end();
63  }
64 
67 
69  Amount get(MosaicId mosaicId) const;
70 
71  public:
73  AccountBalances& credit(MosaicId mosaicId, Amount amount);
74 
76  AccountBalances& debit(MosaicId mosaicId, Amount amount);
77 
79  void optimize(MosaicId id);
80 
81  private:
84  };
85 }}
catapult::state::AccountBalances::optimizedMosaicId
MosaicId optimizedMosaicId() const
Gets the optimized mosaic id.
Definition: AccountBalances.cpp:50
exceptions.h
catapult::utils::HexFormat
constexpr void HexFormat(const ByteArray< N, TTag > &)
catapult::Amount
utils::BaseValue< uint64_t, Amount_tag > Amount
Definition: src/catapult/types.h:76
catapult::state::AccountBalances
Container holding information about account.
Definition: AccountBalances.h:31
catapult::state::AccountBalances::optimize
void optimize(MosaicId id)
Optimizes access of the mosaic with id.
Definition: AccountBalances.cpp:94
catapult::state::AccountBalances::get
Amount get(MosaicId mosaicId) const
Returns amount of funds of a given mosaic (mosaicId).
Definition: AccountBalances.cpp:54
catapult::state::CompactMosaicMap::erase
void erase(MosaicId id)
Erases the mosaic with id.
Definition: CompactMosaicMap.cpp:259
catapult::state::AccountBalances::begin
auto begin() const
Returns a const iterator to the first element of the underlying set.
Definition: AccountBalances.h:56
catapult::state::CompactMosaicMap::find
const_iterator find(MosaicId id) const
Finds the mosaic with id.
Definition: CompactMosaicMap.cpp:199
catapult::utils::BaseValue< uint64_t, MosaicId_tag >
catapult::state::AccountBalances::end
auto end() const
Returns a const iterator to the element following the last element of the underlying set.
Definition: AccountBalances.h:61
catapult::state::CompactMosaicMap::insert
void insert(const Mosaic &pair)
Inserts a mosaic pair.
Definition: CompactMosaicMap.cpp:222
catapult::state::AccountBalances::operator=
AccountBalances & operator=(const AccountBalances &accountBalances)
Assignment operator that makes a deep copy of accountBalances.
Definition: AccountBalances.cpp:39
catapult::state::AccountBalances::credit
AccountBalances & credit(MosaicId mosaicId, Amount amount)
Adds amount funds to a given mosaic (mosaicId).
Definition: AccountBalances.cpp:59
catapult::state::AccountBalances::m_balances
CompactMosaicMap m_balances
Definition: AccountBalances.h:82
catapult::state::CompactMosaicMap::size
size_t size() const
Gets the number of mosaics in the map.
Definition: CompactMosaicMap.cpp:185
catapult::state::AccountBalances::size
size_t size() const
Returns the number of mosaics owned.
Definition: AccountBalances.h:51
catapult::state::CompactMosaicMap::optimize
void optimize(MosaicId id)
Optimizes access of the mosaic with id.
Definition: CompactMosaicMap.cpp:286
catapult::state::CompactMosaicMap
Definition: CompactMosaicMap.h:33
catapult::state::AccountBalances::debit
AccountBalances & debit(MosaicId mosaicId, Amount amount)
Subtracts amount funds from a given mosaic (mosaicId).
Definition: AccountBalances.cpp:72
CATAPULT_THROW_RUNTIME_ERROR
#define CATAPULT_THROW_RUNTIME_ERROR(MESSAGE)
Macro used to throw a catapult runtime error.
Definition: exceptions.h:167
types.h
catapult::state::CompactMosaicMap::end
const_iterator end() const
Returns a const iterator to the element following the last element of the underlying container.
Definition: CompactMosaicMap.cpp:169
catapult
Definition: AddressExtractionExtension.cpp:28
Hashers.h
CompactMosaicMap.h
AccountBalances.h
catapult::state::AccountBalances::AccountBalances
AccountBalances()
Creates an empty account balances.
catapult::state::AccountBalances::m_optimizedMosaicId
MosaicId m_optimizedMosaicId
Definition: AccountBalances.h:83
catapult::state::CompactMosaicMap::begin
const_iterator begin() const
Returns a const iterator to the first element of the underlying container.
Definition: CompactMosaicMap.cpp:165