@@ -1310,7 +1310,7 @@ bool CWallet::LoadToWallet(const CWalletTx& wtxIn)
1310
1310
* Abandoned state should probably be more carefuly tracked via different
1311
1311
* posInBlock signals or by checking mempool presence when necessary.
1312
1312
*/
1313
- bool CWallet::AddToWalletIfInvolvingMe (const CTransaction& tx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate , bool fUpdateKeyPool )
1313
+ bool CWallet::AddToWalletIfInvolvingMe (const CTransaction& tx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate )
1314
1314
{
1315
1315
{
1316
1316
AssertLockHeld (cs_wallet);
@@ -1344,9 +1344,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlockIndex
1344
1344
std::vector<std::vector<unsigned char >> vvchOpParameters;
1345
1345
if (GetBDAPOpScript (ptx, bdapOpScript, vvchOpParameters, op1, op2)) {
1346
1346
std::string strOpType = GetBDAPOpTypeString (op1, op2);
1347
- if (fUpdateKeyPool && vvchOpParameters.size () > 1 ) {
1348
- UpdateKeyPoolsFromTransactions (strOpType,vvchOpParameters);
1349
- }
1347
+ UpdateKeyPoolsFromTransactions (strOpType,vvchOpParameters);
1350
1348
if (GetOpCodeType (strOpType) == " link" && vvchOpParameters.size () > 1 ) {
1351
1349
uint64_t nExpireTime = 0 ;
1352
1350
if (vvchOpParameters.size () > 2 ) {
@@ -1545,6 +1543,19 @@ void CWallet::SyncTransaction(const CTransaction& tx, const CBlockIndex* pindex,
1545
1543
1546
1544
fAnonymizableTallyCached = false ;
1547
1545
fAnonymizableTallyCachedNonDenom = false ;
1546
+
1547
+ if (fNeedToUpdateKeyPools ) {
1548
+ LogPrintf (" DEBUGGER ED %s - fNeedToUpdateKeyPools is TRUE\n " ,__func__);
1549
+ TopUpKeyPoolCombo ();
1550
+ fNeedToUpdateKeyPools = false ;
1551
+ }
1552
+
1553
+ if (fNeedToUpdateLinks ) {
1554
+ LogPrintf (" DEBUGGER ED %s - fNeedToUpdateLinks is TRUE\n " ,__func__);
1555
+ ProcessLinkQueue ();
1556
+ fNeedToUpdateLinks = false ;
1557
+ }
1558
+
1548
1559
}
1549
1560
1550
1561
@@ -2061,7 +2072,19 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool f
2061
2072
CBlock block;
2062
2073
if (ReadBlockFromDisk (block, pindex, Params ().GetConsensus ())) {
2063
2074
for (size_t posInBlock = 0 ; posInBlock < block.vtx .size (); ++posInBlock) {
2064
- AddToWalletIfInvolvingMe (*block.vtx [posInBlock], pindex, posInBlock, fUpdate , true ); // need to also update keypool
2075
+ AddToWalletIfInvolvingMe (*block.vtx [posInBlock], pindex, posInBlock, fUpdate );
2076
+
2077
+ if (fNeedToUpdateKeyPools ) {
2078
+ LogPrintf (" DEBUGGER ED %s - fNeedToUpdateKeyPools is TRUE\n " ,__func__);
2079
+ TopUpKeyPoolCombo ();
2080
+ fNeedToUpdateKeyPools = false ;
2081
+ }
2082
+
2083
+ if (fNeedToUpdateLinks ) {
2084
+ LogPrintf (" DEBUGGER ED %s - fNeedToUpdateLinks is TRUE\n " ,__func__);
2085
+ ProcessLinkQueue ();
2086
+ fNeedToUpdateLinks = false ;
2087
+ }
2065
2088
}
2066
2089
if (!ret) {
2067
2090
ret = pindex;
@@ -2070,10 +2093,30 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool f
2070
2093
ret = nullptr ;
2071
2094
}
2072
2095
pindex = chainActive.Next (pindex);
2096
+
2097
+
2073
2098
}
2074
- ReserveEdKeyForTransactions ();
2075
- TopUpKeyPoolCombo ();
2076
- ProcessLinkQueue ();
2099
+ // ReserveEdKeyForTransactions();
2100
+
2101
+ // if (fNeedToUpdatePoolsAndLinks) {
2102
+ // LogPrintf("DEBUGGER ED %s - fNeedToUpdatePoolsAndLinks is TRUE\n",__func__);
2103
+ // TopUpKeyPoolCombo();
2104
+ // ProcessLinkQueue();
2105
+ // fNeedToUpdatePoolsAndLinks = false;
2106
+ // }
2107
+
2108
+ // if (fNeedToUpdateKeyPools) {
2109
+ // LogPrintf("DEBUGGER ED %s - fNeedToUpdateKeyPools is TRUE\n",__func__);
2110
+ // TopUpKeyPoolCombo();
2111
+ // fNeedToUpdateKeyPools = false;
2112
+ // }
2113
+
2114
+ // if (fNeedToUpdateLinks) {
2115
+ // LogPrintf("DEBUGGER ED %s - fNeedToUpdateLinks is TRUE\n",__func__);
2116
+ // ProcessLinkQueue();
2117
+ // fNeedToUpdateLinks = false;
2118
+ // }
2119
+
2077
2120
ShowProgress (_ (" Rescanning..." ), 100 ); // hide progress dialog in GUI
2078
2121
}
2079
2122
return ret;
@@ -4648,10 +4691,15 @@ void CWallet::UpdateKeyPoolsFromTransactions(const std::string& strOpType, const
4648
4691
std::vector<unsigned char > key0 = vvchOpParameters[0 ];
4649
4692
std::vector<unsigned char > key1 = vvchOpParameters[1 ];
4650
4693
4651
- if (strOpType == " bdap_new_account" )
4652
- reservedEd25519PubKeys.push_back (key1);
4653
- else if (strOpType == " bdap_new_link_request" || strOpType == " bdap_new_link_accept" )
4654
- reservedEd25519PubKeys.push_back (key0);
4694
+ if (strOpType == " bdap_new_account" ) {
4695
+ // reservedEd25519PubKeys.push_back(key1);
4696
+ ReserveEdKeyForTransactions (key1);
4697
+ }
4698
+ else if (strOpType == " bdap_new_link_request" || strOpType == " bdap_new_link_accept" ) {
4699
+ // reservedEd25519PubKeys.push_back(key0);
4700
+ ReserveEdKeyForTransactions (key0);
4701
+ fNeedToUpdateLinks = true ;
4702
+ }
4655
4703
4656
4704
} // UpdateKeyPoolsFromTransactions
4657
4705
@@ -4739,6 +4787,8 @@ void CWallet::ReserveEdKeyForTransactions()
4739
4787
KeepKey (nIndex);
4740
4788
KeepEdKey (nIndex);
4741
4789
keypoolIndexes.push_back (nIndex);
4790
+
4791
+ LogPrintf (" DEBUGGER ED %s - reserving index [%d]\n " ,__func__,nIndex);
4742
4792
}
4743
4793
}
4744
4794
@@ -4755,9 +4805,58 @@ void CWallet::ReserveEdKeyForTransactions()
4755
4805
setInternalKeyPool.erase (*setInternalKeyPool.begin ());
4756
4806
setInternalEdKeyPool.erase (*setInternalEdKeyPool.begin ());
4757
4807
}
4808
+ LogPrintf (" DEBUGGER ED %s - keypool now pointing at [%d]\n " ,__func__,*setInternalKeyPool.begin ());
4809
+ LogPrintf (" DEBUGGER ED %s - edkeypool now pointing at [%d]\n " ,__func__,*setInternalEdKeyPool.begin ());
4810
+
4811
+
4758
4812
4759
4813
} // ReserveEdKeyForTransactions
4760
4814
4815
+ void CWallet::ReserveEdKeyForTransactions (const std::vector<unsigned char >& pubKeyToReserve)
4816
+ {
4817
+ CWalletDB walletdb (strWalletFile);
4818
+ CEdKeyPool edkeypool;
4819
+ std::vector<unsigned char > edPubKey;
4820
+ std::vector<int64_t > keypoolIndexes;
4821
+ bool EraseIndex = false ;
4822
+ int64_t IndexToErase = 0 ;
4823
+ int64_t nIndex = 0 ;
4824
+ std::set<std::int64_t >::iterator it = setInternalEdKeyPool.begin ();
4825
+
4826
+ while ((it != setInternalEdKeyPool.end ()) && (!EraseIndex)) {
4827
+ // for (int64_t nIndex : setInternalEdKeyPool) {
4828
+ nIndex = *it;
4829
+ if (!walletdb.ReadEdPool (nIndex, edkeypool)) {
4830
+ throw std::runtime_error (std::string (__func__) + " : read failed" );
4831
+ }
4832
+ edPubKey = edkeypool.edPubKey ;
4833
+
4834
+ if (pubKeyToReserve == edPubKey) {
4835
+ KeepKey (nIndex);
4836
+ KeepEdKey (nIndex);
4837
+ fNeedToUpdateKeyPools = true ;
4838
+ EraseIndex = true ;
4839
+ IndexToErase = nIndex;
4840
+ LogPrintf (" DEBUGGER ED %s - reserving index [%d]\n " ,__func__,nIndex);
4841
+ }
4842
+ it++;
4843
+ }
4844
+
4845
+ if (EraseIndex) {
4846
+ std::set<int64_t >::iterator eraseIndexEd = setInternalEdKeyPool.find (IndexToErase);
4847
+ std::set<int64_t >::iterator eraseIndex = setInternalKeyPool.find (IndexToErase);
4848
+
4849
+ setInternalEdKeyPool.erase (eraseIndexEd);
4850
+ setInternalKeyPool.erase (eraseIndex);
4851
+
4852
+ }
4853
+ LogPrintf (" DEBUGGER ED %s - keypool now pointing at [%d]\n " ,__func__,*setInternalKeyPool.begin ());
4854
+ LogPrintf (" DEBUGGER ED %s - edkeypool now pointing at [%d]\n " ,__func__,*setInternalEdKeyPool.begin ());
4855
+
4856
+
4857
+ } // ReserveEdKeyForTransactions OVERLOAD
4858
+
4859
+
4761
4860
void CWallet::KeepKey (int64_t nIndex)
4762
4861
{
4763
4862
// Remove from key pool
0 commit comments