Skip to content

Commit

Permalink
Merge #5854: refactor: move HD code from CWallet to LegacyScriptPubKe…
Browse files Browse the repository at this point in the history
…yMan

b5f4411 fix: extra logs to distinct WriteHDChain for encrypted/raw batches (Konstantin Akimov)
e8f84af refactor: move BIP39 related code to wallet (Konstantin Akimov)
fa6519f refactor: move hdchain to wallet/ because it belongs there (Konstantin Akimov)
392b51b refactor: obsolete hdCryptedChain from ScriptPubKeyMan (Konstantin Akimov)
a0389e1 refactor: rename EncryptHDChain to EncryptAndSetHDChain (Konstantin Akimov)
b2143f9 refactor: re-order public and private methods in scriptpubkeyman (Konstantin Akimov)
a219748 refactor: make SetHDChain private in ScriptPubKeyManager (Konstantin Akimov)
f418b9a refactor: move Encrypt chain call inside ScriptPubKeyMan::Encrypt (Konstantin Akimov)
c3754d5 refactor: move DecryptHDChain from public to private (Konstantin Akimov)
e08b64a refactor: unify SetHDChainSingle and SetCryptedHDChainSingle (Konstantin Akimov)
59a9988 refactor: unify ScriptPubKeyMan's SetHDChain nad SetHDCryptedChain (Konstantin Akimov)
a180d73 refactor: unify WalletBatch's WriteHDChain and WriteCryptedHDChain (Konstantin Akimov)
9c8e458 refactor: unify SetHDChain and SetCryptedHDChain helpers (Konstantin Akimov)
7b72726 refactor: SetCryptedHDChain moved to scriptpubkeyman (Konstantin Akimov)
6993d11 feat: extra check failure case CWallet::GenerateNewHDChainEncrypted (Konstantin Akimov)

Pull request description:

  ## Issue being fixed or feature implemented
  During backport bitcoin#17261 significant part of HD chain has been forgotten in CWallet due to our own implementation.

  This PR do not change behaviour of HD wallets, it's just refactoring.

  ## What was done?
  This PR refactor HD wallets implementation:
   - key related stuff is moved from CWallet to LegacyScriptPubKeyMan (to follow-up bitcoin#17261)
   - refactored duplicated code between hdChain and hdCryptedChain
   - modules hdchain and bip39 related moved to wallet/ module

  ## How Has This Been Tested?
  Run unit/functional tests

  ## Breaking Changes
  N/A

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [x] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone

Top commit has no ACKs.

Tree-SHA512: 763ea6dd9af902dfc4dd99896c1cb16a75e3c0322e806e37ff05bc9229923057c544732ebf9fca705da870568643370867d3f81a46cab1e9d229b2949016c484
  • Loading branch information
PastaPastaPasta committed Mar 5, 2024
2 parents 2441489 + b5f4411 commit 8459820
Show file tree
Hide file tree
Showing 16 changed files with 161 additions and 214 deletions.
10 changes: 5 additions & 5 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ BITCOIN_CORE_H = \
base58.h \
batchedlogger.h \
bech32.h \
bip39.h \
bip39_english.h \
blockencodings.h \
bloom.h \
cachemap.h \
Expand Down Expand Up @@ -203,7 +201,6 @@ BITCOIN_CORE_H = \
gsl/assert.h \
gsl/pointers.h \
flat-database.h \
hdchain.h \
flatfile.h \
fs.h \
httprpc.h \
Expand Down Expand Up @@ -365,12 +362,15 @@ BITCOIN_CORE_H = \
validationinterface.h \
versionbits.h \
wallet/bdb.h \
wallet/bip39.h \
wallet/bip39_english.h \
wallet/coincontrol.h \
wallet/coinselection.h \
wallet/context.h \
wallet/crypter.h \
wallet/db.h \
wallet/fees.h \
wallet/hdchain.h \
wallet/ismine.h \
wallet/load.h \
wallet/rpcwallet.h \
Expand Down Expand Up @@ -540,12 +540,13 @@ libbitcoin_wallet_a_SOURCES = \
coinjoin/client.cpp \
coinjoin/interfaces.cpp \
coinjoin/util.cpp \
hdchain.cpp \
wallet/bip39.cpp \
wallet/coincontrol.cpp \
wallet/context.cpp \
wallet/crypter.cpp \
wallet/db.cpp \
wallet/fees.cpp \
wallet/hdchain.cpp \
wallet/interfaces.cpp \
wallet/load.cpp \
wallet/rpcdump.cpp \
Expand Down Expand Up @@ -708,7 +709,6 @@ libbitcoin_common_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libbitcoin_common_a_SOURCES = \
base58.cpp \
bech32.cpp \
bip39.cpp \
bloom.cpp \
chainparams.cpp \
coins.cpp \
Expand Down
4 changes: 2 additions & 2 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ FUZZ_SUITE_LD_COMMON = \
$(LIBTEST_FUZZ) \
$(LIBTEST_UTIL) \
$(LIBBITCOIN_CONSENSUS) \
$(LIBBITCOIN_CRYPTO) \
$(LIBBITCOIN_WALLET) \
$(LIBBITCOIN_CRYPTO) \
$(LIBBITCOIN_CLI) \
$(LIBDASHBLS) \
$(BDB_LIBS) \
Expand Down Expand Up @@ -83,7 +83,6 @@ BITCOIN_TESTS =\
test/base64_tests.cpp \
test/bech32_tests.cpp \
test/bip32_tests.cpp \
test/bip39_tests.cpp \
test/block_reward_reallocation_tests.cpp \
test/blockchain_tests.cpp \
test/blockencodings_tests.cpp \
Expand Down Expand Up @@ -181,6 +180,7 @@ BITCOIN_TESTS =\

if ENABLE_WALLET
BITCOIN_TESTS += \
wallet/test/bip39_tests.cpp \
wallet/test/coinjoin_tests.cpp \
wallet/test/psbt_wallet_tests.cpp \
wallet/test/wallet_tests.cpp \
Expand Down
1 change: 0 additions & 1 deletion src/script/signingprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#ifndef BITCOIN_SCRIPT_SIGNINGPROVIDER_H
#define BITCOIN_SCRIPT_SIGNINGPROVIDER_H

#include <hdchain.h>
#include <key.h>
#include <pubkey.h>
#include <script/script.h>
Expand Down
4 changes: 2 additions & 2 deletions src/bip39.cpp → src/wallet/bip39.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
// Source:
// https://github.com/trezor/trezor-crypto

#include <bip39.h>
#include <bip39_english.h>
#include <wallet/bip39.h>
#include <wallet/bip39_english.h>
#include <crypto/pkcs5_pbkdf2_hmac_sha512.h>
#include <crypto/sha256.h>
#include <random.h>
Expand Down
6 changes: 3 additions & 3 deletions src/bip39.h → src/wallet/bip39.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef BITCOIN_BIP39_H
#define BITCOIN_BIP39_H
#ifndef BITCOIN_WALLET_BIP39_H
#define BITCOIN_WALLET_BIP39_H

#include <support/allocators/secure.h>

Expand All @@ -36,4 +36,4 @@ class CMnemonic
static void ToSeed(SecureString mnemonic, SecureString passphrase, SecureVector& seedRet);
};

#endif // BITCOIN_BIP39_H
#endif // BITCOIN_WALLET_BIP39_H
6 changes: 3 additions & 3 deletions src/bip39_english.h → src/wallet/bip39_english.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef BITCOIN_BIP39_ENGLISH_H
#define BITCOIN_BIP39_ENGLISH_H
#ifndef BITCOIN_WALLET_BIP39_ENGLISH_H
#define BITCOIN_WALLET_BIP39_ENGLISH_H

const char * const wordlist[] = {
"abandon",
Expand Down Expand Up @@ -2076,4 +2076,4 @@ const char * const wordlist[] = {
0,
};

#endif // BITCOIN_BIP39_ENGLISH_H
#endif // BITCOIN_WALLET_BIP39_ENGLISH_H
5 changes: 3 additions & 2 deletions src/hdchain.cpp → src/wallet/hdchain.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) 2014-2023 The Dash Core developers
// Distributed under the MIT software license, see the accompanying

#include <bip39.h>
#include <wallet/hdchain.h>

#include <wallet/bip39.h>
#include <chainparams.h>
#include <hdchain.h>
#include <key_io.h>
#include <tinyformat.h>
#include <util/system.h>
Expand Down
6 changes: 3 additions & 3 deletions src/hdchain.h → src/wallet/hdchain.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2014-2023 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
#ifndef BITCOIN_HDCHAIN_H
#define BITCOIN_HDCHAIN_H
#ifndef BITCOIN_WALLET_HDCHAIN_H
#define BITCOIN_WALLET_HDCHAIN_H

#include <key.h>
#include <script/keyorigin.h>
Expand Down Expand Up @@ -142,4 +142,4 @@ class CHDPubKey
std::string GetKeyPath() const;
};

#endif // BITCOIN_HDCHAIN_H
#endif // BITCOIN_WALLET_HDCHAIN_H
4 changes: 2 additions & 2 deletions src/wallet/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
#ifdef USE_BDB
#include <wallet/bdb.h>
#endif
#include <wallet/bip39.h>
#include <wallet/coincontrol.h>
#include <wallet/hdchain.h>
#include <wallet/wallet.h>
#include <walletinitinterface.h>

#include <bip39.h>
#include <coinjoin/client.h>
#include <coinjoin/options.h>
#include <hdchain.h>

class WalletInit : public WalletInitInterface
{
Expand Down
Loading

0 comments on commit 8459820

Please sign in to comment.