|
10 | 10 | #include "stealth.h"
|
11 | 11 | #include "ringsig.h"
|
12 | 12 |
|
| 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 | + |
13 | 53 | class CKeyPool;
|
14 | 54 | class CAccount;
|
15 | 55 | class CAccountingEntry;
|
@@ -168,11 +208,41 @@ class CWalletDB : public CDB
|
168 | 208 | {
|
169 | 209 | return activeTxn;
|
170 | 210 | }
|
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 | + |
172 | 240 | bool WriteName(const std::string& strAddress, const std::string& strName);
|
173 | 241 |
|
174 | 242 | bool EraseName(const std::string& strAddress);
|
175 | 243 |
|
| 244 | + bool EraseRange(const std::string& sPrefix, uint32_t &nAffected); |
| 245 | + |
176 | 246 | bool WriteTx(uint256 hash, const CWalletTx& wtx)
|
177 | 247 | {
|
178 | 248 | nWalletDBUpdated++;
|
@@ -345,7 +415,83 @@ class CWalletDB : public CDB
|
345 | 415 | {
|
346 | 416 | return Write(std::string("minversion"), nVersion);
|
347 | 417 | }
|
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 | + } |
349 | 495 |
|
350 | 496 | bool ReadAccount(const std::string& strAccount, CAccount& account);
|
351 | 497 | bool WriteAccount(const std::string& strAccount, const CAccount& account);
|
|
0 commit comments