Skip to content

Commit

Permalink
wallet: Add wallet/types.h for simple public enum and struct types
Browse files Browse the repository at this point in the history
Move isminetype and isminefilter there this commit, add WalletPurpose type next
commit.
  • Loading branch information
ryanofsky authored and achow101 committed Apr 11, 2023
1 parent 27dcc07 commit 8741522
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ BITCOIN_CORE_H = \
wallet/external_signer_scriptpubkeyman.h \
wallet/feebumper.h \
wallet/fees.h \
wallet/ismine.h \
wallet/load.h \
wallet/receive.h \
wallet/rpc/util.h \
Expand All @@ -339,6 +338,7 @@ BITCOIN_CORE_H = \
wallet/spend.h \
wallet/sqlite.h \
wallet/transaction.h \
wallet/types.h \
wallet/wallet.h \
wallet/walletdb.h \
wallet/wallettool.h \
Expand Down
2 changes: 1 addition & 1 deletion src/qt/transactiondesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <policy/policy.h>
#include <util/system.h>
#include <validation.h>
#include <wallet/ismine.h>
#include <wallet/types.h>

#include <stdint.h>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <chain.h>
#include <interfaces/wallet.h>
#include <key_io.h>
#include <wallet/ismine.h>
#include <wallet/types.h>

#include <stdint.h>

Expand Down
2 changes: 1 addition & 1 deletion src/wallet/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <wallet/context.h>
#include <wallet/feebumper.h>
#include <wallet/fees.h>
#include <wallet/ismine.h>
#include <wallet/types.h>
#include <wallet/load.h>
#include <wallet/receive.h>
#include <wallet/rpc/wallet.h>
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/receive.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#define BITCOIN_WALLET_RECEIVE_H

#include <consensus/amount.h>
#include <wallet/ismine.h>
#include <wallet/transaction.h>
#include <wallet/types.h>
#include <wallet/wallet.h>

namespace wallet {
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/scriptpubkeyman.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <util/result.h>
#include <util/time.h>
#include <wallet/crypter.h>
#include <wallet/ismine.h>
#include <wallet/types.h>
#include <wallet/walletdb.h>
#include <wallet/walletutil.h>

Expand Down
2 changes: 1 addition & 1 deletion src/wallet/test/ismine_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <script/script.h>
#include <script/standard.h>
#include <test/util/setup_common.h>
#include <wallet/ismine.h>
#include <wallet/types.h>
#include <wallet/wallet.h>

#include <boost/test/unit_test.hpp>
Expand Down
25 changes: 24 additions & 1 deletion src/wallet/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#ifndef BITCOIN_WALLET_TRANSACTION_H
#define BITCOIN_WALLET_TRANSACTION_H

#include <bitset>
#include <cstdint>
#include <consensus/amount.h>
#include <primitives/transaction.h>
#include <serialize.h>
#include <wallet/ismine.h>
#include <wallet/types.h>
#include <threadsafety.h>
#include <tinyformat.h>
#include <util/overloaded.h>
Expand Down Expand Up @@ -108,8 +110,29 @@ static inline int TxStateSerializedIndex(const TxState& state)
}


/**
* Cachable amount subdivided into watchonly and spendable parts.
*/
struct CachableAmount
{
// NO and ALL are never (supposed to be) cached
std::bitset<ISMINE_ENUM_ELEMENTS> m_cached;
CAmount m_value[ISMINE_ENUM_ELEMENTS];
inline void Reset()
{
m_cached.reset();
}
void Set(isminefilter filter, CAmount value)
{
m_cached.set(filter);
m_value[filter] = value;
}
};


typedef std::map<std::string, std::string> mapValue_t;


/** Legacy class used for deserializing vtxPrev for backwards compatibility.
* vtxPrev was removed in commit 93a18a3650292afbb441a47d1fa1b94aeb0164e3,
* but old wallet.dat files may still contain vtxPrev vectors of CMerkleTxs.
Expand Down
38 changes: 9 additions & 29 deletions src/wallet/ismine.h → src/wallet/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_WALLET_ISMINE_H
#define BITCOIN_WALLET_ISMINE_H
//! @file Public type definitions that are used inside and outside of the wallet
//! (e.g. by src/wallet and src/interfaces and src/qt code).
//!
//! File is home for simple enum and struct definitions that don't deserve
//! separate header files. More complicated wallet public types like
//! CCoinControl that are used externally can have separate headers.

#include <script/standard.h>
#ifndef BITCOIN_WALLET_TYPES_H
#define BITCOIN_WALLET_TYPES_H

#include <bitset>
#include <cstdint>
#include <type_traits>

class CScript;

namespace wallet {
class CWallet;

/**
* IsMine() return codes, which depend on ScriptPubKeyMan implementation.
* Not every ScriptPubKeyMan covers all types, please refer to
Expand Down Expand Up @@ -49,25 +48,6 @@ enum isminetype : unsigned int {
};
/** used for bitflags of isminetype */
using isminefilter = std::underlying_type<isminetype>::type;

/**
* Cachable amount subdivided into watchonly and spendable parts.
*/
struct CachableAmount
{
// NO and ALL are never (supposed to be) cached
std::bitset<ISMINE_ENUM_ELEMENTS> m_cached;
CAmount m_value[ISMINE_ENUM_ELEMENTS];
inline void Reset()
{
m_cached.reset();
}
void Set(isminefilter filter, CAmount value)
{
m_cached.set(filter);
m_value[filter] = value;
}
};
} // namespace wallet

#endif // BITCOIN_WALLET_ISMINE_H
#endif // BITCOIN_WALLET_TYPES_H

0 comments on commit 8741522

Please sign in to comment.