From c45415f73a095665a8ff6172b57eb818cf572547 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Tue, 6 Nov 2018 09:23:28 -0500 Subject: Refactor keymetadata writing to a separate method --- src/wallet/walletdb.cpp | 9 +++++++-- src/wallet/walletdb.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 6e037808e3..6e7b944e49 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -57,9 +57,14 @@ bool WalletBatch::EraseTx(uint256 hash) return EraseIC(std::make_pair(std::string("tx"), hash)); } +bool WalletBatch::WriteKeyMetadata(const CKeyMetadata& meta, const CPubKey& pubkey, const bool overwrite) +{ + return WriteIC(std::make_pair(std::string("keymeta"), pubkey), meta, overwrite); +} + bool WalletBatch::WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata& keyMeta) { - if (!WriteIC(std::make_pair(std::string("keymeta"), vchPubKey), keyMeta, false)) { + if (!WriteKeyMetadata(keyMeta, vchPubKey, false)) { return false; } @@ -76,7 +81,7 @@ bool WalletBatch::WriteCryptedKey(const CPubKey& vchPubKey, const std::vector& vchCryptedSecret, const CKeyMetadata &keyMeta) { - if (!WriteIC(std::make_pair(std::string("keymeta"), vchPubKey), keyMeta)) { + if (!WriteKeyMetadata(keyMeta, vchPubKey, true)) { return false; } diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h index 5584407a56..2e8d9b16ba 100644 --- a/src/wallet/walletdb.h +++ b/src/wallet/walletdb.h @@ -177,6 +177,7 @@ public: bool WriteTx(const CWalletTx& wtx); bool EraseTx(uint256 hash); + bool WriteKeyMetadata(const CKeyMetadata& meta, const CPubKey& pubkey, const bool overwrite); bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta); bool WriteCryptedKey(const CPubKey& vchPubKey, const std::vector& vchCryptedSecret, const CKeyMetadata &keyMeta); bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey); -- cgit v1.2.3 From e7652d3f64212a6af68fc7d788411d28fcbdbd0a Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Tue, 6 Nov 2018 09:23:43 -0500 Subject: Add WriteHDKeypath function and move *HDKeypath to util/bip32.{h,cpp} Creates new files util/bip32.h and util/bip32.cpp for containing BIP 32 stuff. Moves FormatKeyPath from descriptor.cpp to util/bip32. Adds a wrapper around it to prepent the 'm' for when just the BIP 32 style keypath is needed. --- src/Makefile.am | 2 ++ src/rpc/rawtransaction.cpp | 1 + src/script/descriptor.cpp | 17 +++------ src/util/bip32.cpp | 66 +++++++++++++++++++++++++++++++++++ src/util/bip32.h | 19 ++++++++++ src/util/strencodings.cpp | 41 ---------------------- src/util/strencodings.h | 3 -- src/wallet/rpcwallet.cpp | 1 + src/wallet/test/psbt_wallet_tests.cpp | 1 + src/wallet/wallet.cpp | 1 + 10 files changed, 95 insertions(+), 57 deletions(-) create mode 100644 src/util/bip32.cpp create mode 100644 src/util/bip32.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 7490d8b790..e3f5734c0b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -196,6 +196,7 @@ BITCOIN_CORE_H = \ txmempool.h \ ui_interface.h \ undo.h \ + util/bip32.h \ util/bytevectorhash.h \ util/system.h \ util/memory.h \ @@ -456,6 +457,7 @@ libbitcoin_util_a_SOURCES = \ support/cleanse.cpp \ sync.cpp \ threadinterrupt.cpp \ + util/bip32.cpp \ util/bytevectorhash.cpp \ util/system.cpp \ util/moneystr.cpp \ diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 7fe73e56da..3c7fa7b806 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -26,6 +26,7 @@ #include