diff options
author | stoffu <stoffu@protonmail.ch> | 2017-12-15 12:08:36 +0900 |
---|---|---|
committer | stoffu <stoffu@protonmail.ch> | 2017-12-18 10:21:47 +0900 |
commit | 6b5bd129b460f75f0bdee1eaff66f9159152d2a7 (patch) | |
tree | 45850c663b2da98654592735808a43506f962448 /src/wallet/wallet2.cpp | |
parent | Merge pull request #2134 (diff) | |
download | monero-6b5bd129b460f75f0bdee1eaff66f9159152d2a7.tar.xz |
Account tagging
Diffstat (limited to 'src/wallet/wallet2.cpp')
-rw-r--r-- | src/wallet/wallet2.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 04c6ee236..436e7f972 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -7818,6 +7818,46 @@ std::string wallet2::get_description() const return get_attribute(ATTRIBUTE_DESCRIPTION); } +const std::pair<std::map<std::string, std::string>, std::vector<std::string>>& wallet2::get_account_tags() +{ + // ensure consistency + if (m_account_tags.second.size() != get_num_subaddress_accounts()) + m_account_tags.second.resize(get_num_subaddress_accounts(), ""); + for (const std::string& tag : m_account_tags.second) + { + if (!tag.empty() && m_account_tags.first.count(tag) == 0) + m_account_tags.first.insert({tag, ""}); + } + for (auto i = m_account_tags.first.begin(); i != m_account_tags.first.end(); ) + { + if (std::find(m_account_tags.second.begin(), m_account_tags.second.end(), i->first) == m_account_tags.second.end()) + i = m_account_tags.first.erase(i); + else + ++i; + } + return m_account_tags; +} + +void wallet2::set_account_tag(const std::set<uint32_t> account_indices, const std::string& tag) +{ + for (uint32_t account_index : account_indices) + { + THROW_WALLET_EXCEPTION_IF(account_index >= get_num_subaddress_accounts(), error::wallet_internal_error, "Account index out of bound"); + if (m_account_tags.second[account_index] == tag) + MDEBUG("This tag is already assigned to this account"); + else + m_account_tags.second[account_index] = tag; + } + get_account_tags(); +} + +void wallet2::set_account_tag_description(const std::string& tag, const std::string& description) +{ + THROW_WALLET_EXCEPTION_IF(tag.empty(), error::wallet_internal_error, "Tag must not be empty"); + THROW_WALLET_EXCEPTION_IF(m_account_tags.first.count(tag) == 0, error::wallet_internal_error, "Tag is unregistered"); + m_account_tags.first[tag] = description; +} + std::string wallet2::sign(const std::string &data) const { crypto::hash hash; |