upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/db.h
diff options
context:
space:
mode:
authorBitflash <btf01@proton.me>2026-08-01 12:56:16 -0300
committerGitHub <noreply@github.com>2026-08-01 12:56:16 -0300
commit7131c30c33c980f0ba1d37dfc6a3fbe8c319813e (patch)
tree668de28f9aec4f8f350146f1d824b487752cf747 /src/db.h
parentb426948b966405b65f3ea6c1994164b462980694 (diff)
wallet: generate keys ahead of use so a backup outlives the next block (#85)
The wallet made a key per address and per block mined, so a backup only ever contained the keys that existed the moment it was taken -- mine one block and the coin lands on a key the backup has never heard of. The README warned about it, which is an admission rather than a fix. Keys are now generated a hundred at a time and handed out one at a time, each written to wallet.dat before it can be pointed at. A backup covers the next hundred addresses. Deterministic derivation (#47) stays open; this buys back the distance between a backup and the next mistake.
Diffstat (limited to 'src/db.h')
-rw-r--r--src/db.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/db.h b/src/db.h
index 22efc77..f51047e 100644
--- a/src/db.h
+++ b/src/db.h
@@ -386,6 +386,19 @@ public:
386 return Write(string("defaultkey"), vchPubKey); 386 return Write(string("defaultkey"), vchPubKey);
387 } 387 }
388 388
389 // Keys generated ahead of time and not yet handed out. The private key of
390 // each is already stored under its own "key" record by AddKey; a "pool"
391 // record only says that this one is still unspoken for.
392 bool WritePool(int64 nIndex, const vector<unsigned char>& vchPubKey)
393 {
394 return Write(make_pair(string("pool"), nIndex), vchPubKey);
395 }
396
397 bool ErasePool(int64 nIndex)
398 {
399 return Erase(make_pair(string("pool"), nIndex));
400 }
401
389 template<typename T> 402 template<typename T>
390 bool ReadSetting(const string& strKey, T& value) 403 bool ReadSetting(const string& strKey, T& value)
391 { 404 {