Skip to content

Commit d679e16

Browse files
committed
wallet database h
1 parent 69c2d32 commit d679e16

File tree

1 file changed

+148
-2
lines changed

1 file changed

+148
-2
lines changed

src/walletdb.h

+148-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,46 @@
1010
#include "stealth.h"
1111
#include "ringsig.h"
1212

13+
14+
/*
15+
prefixes
16+
name
17+
acc
18+
acentry
19+
keymeta
20+
key
21+
ckey
22+
wkey
23+
mkey
24+
defaultkey
25+
sxAddr
26+
sxKeyMeta
27+
keymeta
28+
lastfilteredheight
29+
pool
30+
version
31+
cscript
32+
orderposnext
33+
minversion
34+
tx
35+
lao - locked anon output
36+
oao - owned anon output
37+
oal
38+
bestblock
39+
bestblockheader
40+
minversion
41+
ek32 - bip32 extended keypair
42+
eknm - named extended key
43+
eacc - extended account
44+
epak - extended account key pack
45+
espk - extended account stealth key pack
46+
ecpk - extended account stealth child key pack
47+
flag - named integer flag
48+
49+
old:
50+
51+
*/
52+
1353
class CKeyPool;
1454
class CAccount;
1555
class CAccountingEntry;
@@ -168,11 +208,41 @@ class CWalletDB : public CDB
168208
{
169209
return activeTxn;
170210
}
171-
211+
212+
template< typename T>
213+
bool Replace(Dbc *pcursor, const T& value)
214+
{
215+
if (!pcursor)
216+
return false;
217+
218+
if (fReadOnly)
219+
assert(!"Replace called on database in read-only mode");
220+
221+
// Value
222+
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
223+
ssValue.reserve(10000);
224+
ssValue << value;
225+
Dbt datValue(&ssValue[0], ssValue.size());
226+
227+
// Write
228+
int ret = pcursor->put(NULL, &datValue, DB_CURRENT);
229+
230+
if (ret != 0)
231+
{
232+
LogPrintf("CursorPut ret %d - %s\n", ret, DbEnv::strerror(ret));
233+
};
234+
// Clear memory in case it was a private key
235+
memset(datValue.get_data(), 0, datValue.get_size());
236+
237+
return (ret == 0);
238+
}
239+
172240
bool WriteName(const std::string& strAddress, const std::string& strName);
173241

174242
bool EraseName(const std::string& strAddress);
175243

244+
bool EraseRange(const std::string& sPrefix, uint32_t &nAffected);
245+
176246
bool WriteTx(uint256 hash, const CWalletTx& wtx)
177247
{
178248
nWalletDBUpdated++;
@@ -345,7 +415,83 @@ class CWalletDB : public CDB
345415
{
346416
return Write(std::string("minversion"), nVersion);
347417
}
348-
418+
419+
bool ReadNamedExtKeyId(const std::string &name, CKeyID &identifier, uint32_t nFlags=DB_READ_UNCOMMITTED)
420+
{
421+
return Read(std::make_pair(std::string("eknm"), name), identifier, nFlags);
422+
}
423+
424+
bool WriteNamedExtKeyId(const std::string &name, const CKeyID &identifier)
425+
{
426+
nWalletDBUpdated++;
427+
return Write(std::make_pair(std::string("eknm"), name), identifier, true);
428+
}
429+
430+
bool ReadExtKey(const CKeyID &identifier, CStoredExtKey &ek32, uint32_t nFlags=DB_READ_UNCOMMITTED)
431+
{
432+
return Read(std::make_pair(std::string("ek32"), identifier), ek32, nFlags);
433+
}
434+
435+
bool WriteExtKey(const CKeyID &identifier, const CStoredExtKey &ek32)
436+
{
437+
nWalletDBUpdated++;
438+
return Write(std::make_pair(std::string("ek32"), identifier), ek32, true);
439+
}
440+
441+
bool ReadExtAccount(const CKeyID &identifier, CExtKeyAccount &ekAcc, uint32_t nFlags=DB_READ_UNCOMMITTED)
442+
{
443+
return Read(std::make_pair(std::string("eacc"), identifier), ekAcc, nFlags);
444+
}
445+
446+
bool WriteExtAccount(const CKeyID &identifier, const CExtKeyAccount &ekAcc)
447+
{
448+
nWalletDBUpdated++;
449+
return Write(std::make_pair(std::string("eacc"), identifier), ekAcc, true);
450+
}
451+
452+
bool ReadExtKeyPack(const CKeyID &identifier, const uint32_t nPack, std::vector<CEKAKeyPack> &ekPak, uint32_t nFlags=DB_READ_UNCOMMITTED)
453+
{
454+
return Read(boost::make_tuple(std::string("epak"), identifier, nPack), ekPak, nFlags);
455+
}
456+
457+
bool WriteExtKeyPack(const CKeyID &identifier, const uint32_t nPack, const std::vector<CEKAKeyPack> &ekPak)
458+
{
459+
nWalletDBUpdated++;
460+
return Write(boost::make_tuple(std::string("epak"), identifier, nPack), ekPak, true);
461+
}
462+
463+
bool ReadExtStealthKeyPack(const CKeyID &identifier, const uint32_t nPack, std::vector<CEKAStealthKeyPack> &aksPak, uint32_t nFlags=DB_READ_UNCOMMITTED)
464+
{
465+
return Read(boost::make_tuple(std::string("espk"), identifier, nPack), aksPak, nFlags);
466+
}
467+
468+
bool WriteExtStealthKeyPack(const CKeyID &identifier, const uint32_t nPack, const std::vector<CEKAStealthKeyPack> &aksPak)
469+
{
470+
nWalletDBUpdated++;
471+
return Write(boost::make_tuple(std::string("espk"), identifier, nPack), aksPak, true);
472+
}
473+
474+
bool ReadExtStealthKeyChildPack(const CKeyID &identifier, const uint32_t nPack, std::vector<CEKASCKeyPack> &asckPak, uint32_t nFlags=DB_READ_UNCOMMITTED)
475+
{
476+
return Read(boost::make_tuple(std::string("ecpk"), identifier, nPack), asckPak, nFlags);
477+
}
478+
479+
bool WriteExtStealthKeyChildPack(const CKeyID &identifier, const uint32_t nPack, const std::vector<CEKASCKeyPack> &asckPak)
480+
{
481+
nWalletDBUpdated++;
482+
return Write(boost::make_tuple(std::string("ecpk"), identifier, nPack), asckPak, true);
483+
}
484+
485+
bool ReadFlag(const std::string &name, int32_t &nValue, uint32_t nFlags=DB_READ_UNCOMMITTED)
486+
{
487+
return Read(std::make_pair(std::string("flag"), name), nValue, nFlags);
488+
}
489+
490+
bool WriteFlag(const std::string &name, int32_t nValue)
491+
{
492+
nWalletDBUpdated++;
493+
return Write(std::make_pair(std::string("flag"), name), nValue, true);
494+
}
349495

350496
bool ReadAccount(const std::string& strAccount, CAccount& account);
351497
bool WriteAccount(const std::string& strAccount, const CAccount& account);

0 commit comments

Comments
 (0)