Write and load peg-out wallet functions on wallet load

This commit is contained in:
Gregory Sanders 2018-12-17 14:08:25 -05:00
parent 4e631bd778
commit 47422e71d8
4 changed files with 89 additions and 0 deletions

View file

@ -4471,3 +4471,32 @@ std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& 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;
}

View file

@ -832,6 +832,17 @@ public:
std::set<COutPoint> 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. */

View file

@ -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<unsigned char> 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<CAccountingEntry> 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<unsigned char> 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++;
}

View file

@ -214,6 +214,11 @@ public:
CAmount GetAccountCreditDebit(const std::string& strAccount);
void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& 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<uint256>& vTxHash, std::vector<CWalletTx>& vWtx);
DBErrors ZapWalletTx(std::vector<CWalletTx>& vWtx);