upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/db.cpp
diff options
context:
space:
mode:
authormtg0001 <106211915+mtg0001@users.noreply.github.com>2026-08-03 15:11:55 -0300
committerGitHub <noreply@github.com>2026-08-03 15:11:55 -0300
commitaba252206bf39ac81e6627354062c28fae05b0aa (patch)
tree751691f0baaf925c54a2c03f9f02ca87fb29956f /src/db.cpp
parent1aee805b232a33484e3db1dc8ea4bfb3f585212e (diff)
Activate BIP44 wallet derivation (#124)
* Add BIP32 path derivation foundation * Add HD wallet schema metadata * Add provisional BIP44 coin type metadata * Activate BIP44 wallet derivation * wallet: scan BIP44 restore depth per branch * wallet: widen default BIP44 restore lookahead --------- Co-authored-by: Gilcimar Duarte <ti@gpm.infra>
Diffstat (limited to 'src/db.cpp')
-rw-r--r--src/db.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/db.cpp b/src/db.cpp
index 294920b..b7e7b91 100644
--- a/src/db.cpp
+++ b/src/db.cpp
@@ -554,6 +554,7 @@ bool CWalletDB::LoadWallet(vector<unsigned char>& vchDefaultKeyRet)
554 // Whether wallet.dat actually carried a mining mode, as opposed to just the 554 // Whether wallet.dat actually carried a mining mode, as opposed to just the
555 // ancient fGenerateBitcoins flag. See the reconciliation further down. 555 // ancient fGenerateBitcoins flag. See the reconciliation further down.
556 bool fHaveStoredMineMode = false; 556 bool fHaveStoredMineMode = false;
557 bool fHaveStoredHDCoinType = false;
557 vchDefaultKeyRet.clear(); 558 vchDefaultKeyRet.clear();
558 559
559 // Satoshi's "todo: shouldn't we catch exceptions" sat here since 2009, and 560 // Satoshi's "todo: shouldn't we catch exceptions" sat here since 2009, and
@@ -651,6 +652,23 @@ bool CWalletDB::LoadWallet(vector<unsigned char>& vchDefaultKeyRet)
651 { 652 {
652 ssValue >> nHDNext; 653 ssValue >> nHDNext;
653 } 654 }
655 else if (strType == "hdschema")
656 {
657 ssValue >> nHDKeySchema;
658 }
659 else if (strType == "hdcointype")
660 {
661 ssValue >> nHDCoinType;
662 fHaveStoredHDCoinType = true;
663 }
664 else if (strType == "hdreceivenext")
665 {
666 ssValue >> nHDReceiveNext;
667 }
668 else if (strType == "hdchangenext")
669 {
670 ssValue >> nHDChangeNext;
671 }
654 else if (strType == "pool") 672 else if (strType == "pool")
655 { 673 {
656 int64 nIndex; 674 int64 nIndex;
@@ -707,6 +725,38 @@ bool CWalletDB::LoadWallet(vector<unsigned char>& vchDefaultKeyRet)
707 return false; 725 return false;
708 } 726 }
709 727
728 if (HaveHDSeed())
729 {
730 if (nHDKeySchema == HD_SCHEMA_NONE)
731 {
732 nHDKeySchema = HD_SCHEMA_LEGACY;
733 printf("LoadWallet: deterministic seed has no schema metadata; "
734 "treating it as legacy m/index'\n");
735 }
736 else if (nHDKeySchema != HD_SCHEMA_LEGACY &&
737 nHDKeySchema != HD_SCHEMA_BIP44)
738 {
739 printf("LoadWallet: deterministic wallet schema %d (%s) is not "
740 "supported by this build\n",
741 nHDKeySchema, HDKeySchemaName(nHDKeySchema).c_str());
742 return false;
743 }
744 if (!fHaveStoredHDCoinType)
745 {
746 nHDCoinType = HD_BIP44_COIN_TYPE_BITFLASH_PROVISIONAL;
747 printf("LoadWallet: deterministic seed has no BIP44 coin type metadata; "
748 "using provisional Bitflash coin type %u\n", nHDCoinType);
749 }
750 }
751 else
752 {
753 nHDKeySchema = HD_SCHEMA_NONE;
754 nHDNext = 0;
755 nHDReceiveNext = 0;
756 nHDChangeNext = 0;
757 nHDCoinType = HD_BIP44_COIN_TYPE_BITFLASH_PROVISIONAL;
758 }
759
710 // fGenerateBitcoins and nMineMode only mean anything together, and a 760 // fGenerateBitcoins and nMineMode only mean anything together, and a
711 // wallet.dat can easily hold one without the other: Bitcoin 0.1.0 already 761 // wallet.dat can easily hold one without the other: Bitcoin 0.1.0 already
712 // wrote fGenerateBitcoins when mining was toggled, years before this fork 762 // wrote fGenerateBitcoins when mining was toggled, years before this fork