diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index d00af6dbf6..b18d737f74 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4471,3 +4471,32 @@ std::vector CWallet::GroupOutputs(const std::vector& outpu } return groups; } + +bool CWallet::SetOnlinePubKey(const CPubKey& online_key_in) +{ + LOCK(cs_wallet); + if (!WalletBatch(*database).WriteOnlineKey(online_key_in)) { + return false; + } + online_key = online_key_in; + return true; +} + +bool CWallet::SetOfflineXPubKey(const CExtPubKey& offline_xpub_in) +{ + LOCK(cs_wallet); + if (!WalletBatch(*database).WriteOfflineXPubKey(offline_xpub_in)) { + return false; + } + offline_xpub = offline_xpub_in; + return true; +} + +bool CWallet::SetOfflineCounter(int counter) { + LOCK(cs_wallet); + if (!WalletBatch(*database).WriteOfflineCounter(counter)) { + return false; + } + offline_counter = counter; + return true; +} diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index f1e2b5b40c..2d8fbc9bfa 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -832,6 +832,17 @@ public: std::set setLockedCoins; + // ELEMENTS // + //! The online PAK aka `liquid_pak` in the wallet set by `initpegoutwallet` + CPubKey online_key; + + //! The offline xpub aka `bitcoin_xpub` in the wallet set by `initpegoutwallet` + CExtPubKey offline_xpub; + + //! The derivation counter for offline_xpub + int offline_counter; + // END ELEMENTS + const CWalletTx* GetWalletTx(const uint256& hash) const; //! check whether we are allowed to upgrade (or already support) to the named feature @@ -1211,6 +1222,12 @@ public: LogPrintf(("%s " + fmt).c_str(), GetDisplayName(), parameters...); }; + // ELEMENTS + //! Setters for online/offline pubkey pairs for PAK + bool SetOnlinePubKey(const CPubKey& online_key_in); + bool SetOfflineXPubKey(const CExtPubKey& offline_xpub_in); + bool SetOfflineCounter(int counter); + }; /** A key allocated from the key pool. */ diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 15c5b82c52..bd8e7661ae 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -171,6 +171,24 @@ bool WalletBatch::WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccou return WriteIC(std::make_pair(std::string("acentry"), std::make_pair(acentry.strAccount, nAccEntryNum)), acentry); } +bool WalletBatch::WriteOnlineKey(const CPubKey& online_key) +{ + return WriteIC(std::string("onlinekey"), online_key); +} + +bool WalletBatch::WriteOfflineXPubKey(const CExtPubKey& offline_xpub) +{ + std::vector vxpub; + vxpub.resize(BIP32_EXTKEY_SIZE); + offline_xpub.Encode(&vxpub[0]); + return WriteIC(std::string("offlinexpub"), vxpub); +} + +bool WalletBatch::WriteOfflineCounter(int counter) +{ + return WriteIC(std::string("offlinecounter"), counter); +} + CAmount WalletBatch::GetAccountCreditDebit(const std::string& strAccount) { std::list entries; @@ -509,6 +527,26 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, strErr = "Error reading wallet database: Unknown non-tolerable wallet flags found"; return false; } + } + else if (strType == "onlinekey") + { + CPubKey key; + ssValue >> key; + pwallet->online_key = key; + } + else if (strType == "offlinexpub") + { + std::vector vxpub; + CExtPubKey xpub; + ssValue >> vxpub; + xpub.Decode(&vxpub[0]); + pwallet->offline_xpub = xpub; + } + else if (strType == "offlinecounter") + { + int counter; + ssValue >> counter; + pwallet->offline_counter = counter; } else if (strType != "bestblock" && strType != "bestblock_nomerkle") { wss.m_unknown_records++; } diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h index 0e6cb1bba4..2c5b8722c1 100644 --- a/src/wallet/walletdb.h +++ b/src/wallet/walletdb.h @@ -214,6 +214,11 @@ public: CAmount GetAccountCreditDebit(const std::string& strAccount); void ListAccountCreditDebit(const std::string& strAccount, std::list& acentries); + /// ELEMENTS: Storage of PAK settings + bool WriteOnlineKey(const CPubKey& online_key); + bool WriteOfflineXPubKey(const CExtPubKey& offline_xpub); + bool WriteOfflineCounter(int counter); + DBErrors LoadWallet(CWallet* pwallet); DBErrors FindWalletTx(std::vector& vTxHash, std::vector& vWtx); DBErrors ZapWalletTx(std::vector& vWtx);