Skip to content

Commit 5b9bac1

Browse files
committed
[Ed25519] Recover BDAP Links after import mnemonic
1 parent 009e015 commit 5b9bac1

8 files changed

+24
-151
lines changed

src/bdap/linkmanager.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,11 @@ bool CLinkManager::ListMyCompleted(std::vector<CLink>& vchLinks)
256256

257257
bool CLinkManager::ProcessLink(const CLinkStorage& storage, const bool fStoreInQueueOnly)
258258
{
259-
if (!pwalletMain)
260-
return false;
259+
260+
if (!pwalletMain) {
261+
linkQueue.push(storage);
262+
return true;
263+
}
261264

262265
if (fStoreInQueueOnly || pwalletMain->IsLocked()) {
263266
linkQueue.push(storage);

src/bdap/rpcdomainentry.cpp

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,44 +48,24 @@ static UniValue AddDomainEntry(const JSONRPCRequest& request, BDAP::ObjectType b
4848
if (GetDomainEntry(txDomainEntry.vchFullObjectPath(), txDomainEntry))
4949
throw std::runtime_error("BDAP_ADD_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3500 - " + txDomainEntry.GetFullObjectPath() + _(" entry already exists. Can not add duplicate."));
5050

51-
LogPrintf("DEBUGGER ED %s - made it here! BEFORE\n", __func__);
52-
53-
//now using GetKeyFromPool instead of MakeNewKey
51+
//now using GetKeyFromPool instead of MakeNewKey
5452
CPubKey pubWalletKey;
5553
CharString vchDHTPubKey;
5654
if (!pwalletMain->GetEdKeyFromPool(pubWalletKey, vchDHTPubKey, true))
5755
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: EdKeypool ran out, please call edkeypoolrefill first");
5856

59-
// while (pDomainEntryDB->DomainEntryExistsPubKey(vchDHTPubKey)) {
60-
// if (!pwalletMain->GetEdKeyFromPool(pubWalletKey, vchDHTPubKey, true))
61-
// throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: EdKeypool ran out, please call edkeypoolrefill first");
62-
// };
63-
6457
CKeyID keyWalletID = pubWalletKey.GetID();
6558
CDynamicAddress walletAddress = CDynamicAddress(keyWalletID);
6659

67-
6860
pwalletMain->SetAddressBook(keyWalletID, strObjectID, "bdap-wallet");
6961

7062
CharString vchWalletAddress = vchFromString(walletAddress.ToString());
7163
txDomainEntry.WalletAddress = vchWalletAddress;
7264

73-
// TODO: Add ability to pass in the DHT public key
74-
//CKeyEd25519 privDHTKey;
75-
//CharString vchDHTPubKey = privDHTKey.GetPubKey();
76-
77-
//if (pwalletMain && !pwalletMain->AddDHTKey(privDHTKey, vchDHTPubKey))
78-
// throw std::runtime_error("BDAP_ADD_PUBLIC_ENTRY_RPC_ERROR: ERRCODE: 3503 - " + _("Error adding ed25519 key to wallet for BDAP"));
79-
8065
txDomainEntry.DHTPublicKey = vchDHTPubKey;
81-
CKeyID vchDHTPubKeyID = GetIdFromCharVector(vchDHTPubKey); // CKeyID(Hash160(vchDHTPubKey.begin(), vchDHTPubKey.end()));
82-
//pwalletMain->SetAddressBook(privDHTKey.GetID(), strObjectID, "bdap-dht-key"); //need private key for this?
66+
CKeyID vchDHTPubKeyID = GetIdFromCharVector(vchDHTPubKey);
8367
pwalletMain->SetAddressBook(vchDHTPubKeyID, strObjectID, "bdap-dht-key");
8468

85-
LogPrintf("DEBUGGER ED %s - made it here! AFTER\n", __func__);
86-
87-
88-
8969
// TODO: Add ability to pass in the link address
9070
// TODO: Use stealth address for the link address so linking will be private
9171
//now using GetKeyFromPool instead of MakeNewKey
@@ -94,13 +74,9 @@ static UniValue AddDomainEntry(const JSONRPCRequest& request, BDAP::ObjectType b
9474
if (!pwalletMain->GetEdKeyFromPool(pubLinkKey, NAvchDHTPubKey, true))
9575
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: EdKeypool ran out, please call edkeypoolrefill first");
9676

97-
// if (!pwalletMain->GetKeyFromPool(pubLinkKey, true))
98-
// throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
99-
10077
CKeyID keyLinkID = pubLinkKey.GetID();
10178
CDynamicAddress linkAddress = CDynamicAddress(keyLinkID);
10279

103-
10480
pwalletMain->SetAddressBook(keyLinkID, strObjectID, "bdap-link");
10581

10682
CharString vchLinkAddress = vchFromString(linkAddress.ToString());
@@ -169,10 +145,6 @@ static UniValue AddDomainEntry(const JSONRPCRequest& request, BDAP::ObjectType b
169145
std::string strPubKeyHash = GetHashFromCharVector(vchDHTPubKey).ToString();
170146
std::string strPubKeyID = GetIdFromCharVector(vchDHTPubKey).ToString();
171147

172-
LogPrintf("DEBUGGER ED %s - GetHashFromCharVector [%s]\n", __func__,strPubKeyHash);
173-
LogPrintf("DEBUGGER ED %s - GetIdFromCharVector [%s]\n", __func__,strPubKeyID);
174-
175-
176148
oName.push_back(Pair("dht_pubkey_hash", strPubKeyHash));
177149
oName.push_back(Pair("dht_pubkey_id", strPubKeyID));
178150
return oName;
@@ -882,14 +854,10 @@ UniValue mybdapaccounts(const JSONRPCRequest& request)
882854
if (!pwalletMain->GetDHTPubKeys(vvchDHTPubKeys))
883855
return NullUniValue;
884856

885-
LogPrintf("DEBUGGER ED %s - size [%d]\n",__func__,vvchDHTPubKeys.size());
886-
887-
888857
UniValue result(UniValue::VOBJ);
889858
uint32_t nCount = 1;
890859
for (const std::vector<unsigned char>& vchPubKey : vvchDHTPubKeys) {
891860
CDomainEntry entry;
892-
//LogPrintf("DEBUGGER ED %s - PubKey [%s]\n",__func__,stringFromVch(vchPubKey));
893861
if (pDomainEntryDB->ReadDomainEntryPubKey(vchPubKey, entry)) {
894862
UniValue oAccount(UniValue::VOBJ);
895863
if (BuildBDAPJson(entry, oAccount, false)) {

src/bdap/rpclinking.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,7 @@ static UniValue SendLinkRequest(const JSONRPCRequest& request)
164164
CKeyID vchDHTPubKeyID = GetIdFromCharVector(vchDHTPubKey);
165165
if (!pwalletMain->GetDHTKey(vchDHTPubKeyID, privReqDHTKey))
166166
throw std::runtime_error("BDAP_SEND_LINK_RPC_ERROR: Unable to retrieve DHT Key");
167-
else LogPrintf("DEBUGGER ED %s - got request privatekey [%s]\n",__func__,privReqDHTKey.GetPrivKeyString());
168167

169-
//CKeyEd25519 privReqDHTKey;
170-
//CharString vchDHTPubKey = privReqDHTKey.GetPubKey();
171-
//if (pwalletMain && !pwalletMain->AddDHTKey(privReqDHTKey, vchDHTPubKey))
172-
// throw std::runtime_error("BDAP_SEND_LINK_RPC_ERROR: ERRCODE: 4002 - " + _("Error adding ed25519 key to wallet for BDAP link"));
173-
174168
txLink.RequestorPubKey = vchDHTPubKey;
175169

176170
pwalletMain->SetAddressBook(privReqDHTKey.GetID(), strRequestorFQDN, "bdap-dht-key");
@@ -318,7 +312,6 @@ static UniValue SendLinkAccept(const JSONRPCRequest& request)
318312
txLinkAccept.RequestorFullObjectPath = vchRequestorFQDN;
319313
txLinkAccept.RecipientFullObjectPath = vchAcceptorFQDN;
320314

321-
322315
CPubKey pubWalletKey; //won't be needing this
323316
CharString vchDHTPubKey;
324317
CKeyEd25519 privAcceptDHTKey;
@@ -328,12 +321,6 @@ static UniValue SendLinkAccept(const JSONRPCRequest& request)
328321
CKeyID vchDHTPubKeyID = GetIdFromCharVector(vchDHTPubKey);
329322
if (!pwalletMain->GetDHTKey(vchDHTPubKeyID, privAcceptDHTKey))
330323
throw std::runtime_error("BDAP_SEND_LINK_RPC_ERROR: Unable to retrieve DHT Key");
331-
else LogPrintf("DEBUGGER ED %s - got accept privatekey [%s]\n",__func__,privAcceptDHTKey.GetPrivKeyString());
332-
333-
//CKeyEd25519 privAcceptDHTKey;
334-
//CharString vchDHTPubKey = privAcceptDHTKey.GetPubKey();
335-
//if (pwalletMain && !pwalletMain->AddDHTKey(privAcceptDHTKey, vchDHTPubKey))
336-
// throw std::runtime_error("BDAP_ACCEPT_LINK_RPC_ERROR: ERRCODE: 4104 - " + _("Error adding ed25519 key to wallet for BDAP link"));
337324

338325
txLinkAccept.RecipientPubKey = vchDHTPubKey;
339326

@@ -1015,7 +1002,8 @@ static UniValue SendMessage(const JSONRPCRequest& request)
10151002
int64_t stoptime = timestamp + 60; // stop relaying after 1 minute.
10161003
uint256 messageID = GetMessageID(key, timestamp);
10171004
CPubKey newPubKey;
1018-
if (!pwalletMain->GetKeyFromPool(newPubKey, false))
1005+
std::vector<unsigned char> newEdKey;
1006+
if (!pwalletMain->GetEdKeyFromPool(newPubKey, newEdKey, false))
10191007
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
10201008

10211009
CKeyID keyID = newPubKey.GetID();

src/bdap/rpcrawbdap.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ UniValue createrawbdapaccount(const JSONRPCRequest& request)
8888

8989
// TODO: Add ability to pass in the wallet address
9090
//now using GetKeyFromPool instead of MakeNewKey
91+
std::vector<unsigned char> newEdKey;
9192
CPubKey pubWalletKey;
92-
if (!pwalletMain->GetKeyFromPool(pubWalletKey, true))
93+
if (!pwalletMain->GetEdKeyFromPool(pubWalletKey, newEdKey, true))
9394
throw std::runtime_error("Error: Keypool ran out, please call keypoolrefill first");
9495
CKeyID keyWalletID = pubWalletKey.GetID();
9596
CDynamicAddress walletAddress = CDynamicAddress(keyWalletID);
@@ -114,7 +115,8 @@ UniValue createrawbdapaccount(const JSONRPCRequest& request)
114115
// TODO: Use stealth address for the link address so linking will be private
115116
//now using GetKeyFromPool instead of MakeNewKey
116117
CPubKey pubLinkKey;
117-
if (!pwalletMain->GetKeyFromPool(pubLinkKey, true))
118+
std::vector<unsigned char> newEdKey2;
119+
if (!pwalletMain->GetEdKeyFromPool(pubLinkKey, newEdKey2, true))
118120
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
119121
CKeyID keyLinkID = pubLinkKey.GetID();
120122
CDynamicAddress linkAddress = CDynamicAddress(keyLinkID);

src/qt/addresstablemodel.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,15 @@ QString AddressTableModel::addRow(const QString& type, const QString& label, con
335335
} else if (type == Receive) {
336336
// Generate a new address to associate with given label
337337
CPubKey newKey;
338-
if (!wallet->GetKeyFromPool(newKey, false)) {
338+
std::vector<unsigned char> newEdKey;
339+
if (!wallet->GetEdKeyFromPool(newKey, newEdKey, false)) {
339340
WalletModel::UnlockContext ctx(walletModel->requestUnlock());
340341
if (!ctx.isValid()) {
341342
// Unlock wallet failed or was cancelled
342343
editStatus = WALLET_UNLOCK_FAILURE;
343344
return QString();
344345
}
345-
if (!wallet->GetKeyFromPool(newKey, false)) {
346+
if (!wallet->GetEdKeyFromPool(newKey, newEdKey, false)) {
346347
editStatus = KEY_GENERATION_FAILURE;
347348
return QString();
348349
}

src/qt/paymentserver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ void PaymentServer::fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipien
616616
refund_to->set_script(&s[0], s.size());
617617
} else {
618618
CPubKey newKey;
619-
if (wallet->GetKeyFromPool(newKey, false)) {
619+
std::vector<unsigned char> newEdKey;
620+
if (wallet->GetEdKeyFromPool(newKey, newEdKey, false)) {
620621
CKeyID keyID = newKey.GetID();
621622
wallet->SetAddressBook(keyID, strAccount, "refund");
622623

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ UniValue getnewaddress(const JSONRPCRequest& request)
135135

136136
// Generate a new key that is added to wallet
137137
CPubKey newKey;
138-
if (!pwalletMain->GetKeyFromPool(newKey, false))
138+
std::vector<unsigned char> newEdKey; //not really using this here, keeps keypools synced
139+
if (!pwalletMain->GetEdKeyFromPool(newKey, newEdKey, false))
139140
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
140141
CKeyID keyID = newKey.GetID();
141142

0 commit comments

Comments
 (0)