Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing transaction list issue after recovery #1017

Merged
merged 1 commit into from
Apr 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/hdmint/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ bool CHDMintWallet::SetLelantusMintSeedSeen(CWalletDB& walletdb, std::pair<uint2
GroupElement bnValue;
uint256 hashSerial;
// Can regenerate if unlocked (cheaper)
Scalar serial;
if(!pwalletMain->IsLocked()) {
LogPrintf("%s: Wallet not locked, creating mind seed..\n", __func__);
uint512 mintSeed;
Expand All @@ -547,6 +548,7 @@ bool CHDMintWallet::SetLelantusMintSeedSeen(CWalletDB& walletdb, std::pair<uint2
return false;
hashSerial = primitives::GetSerialHash(coin.getSerialNumber());
bnValue = coin.getPublicCoin().getValue();
serial = coin.getSerialNumber();
} else {
LogPrintf("%s: Wallet locked, retrieving mind seed..\n", __func__);
// Get serial and pubcoin data from the db
Expand Down Expand Up @@ -585,6 +587,7 @@ bool CHDMintWallet::SetLelantusMintSeedSeen(CWalletDB& walletdb, std::pair<uint2
int nHeightTx;
uint256 txidSpend;
CTransactionRef txSpend;
bool used = false;
if (IsLelantusSerialInBlockchain(hashSerial, nHeightTx, txidSpend, txSpend)) {
//Find transaction details and make a wallettx and add to wallet
LogPrintf("%s: Mint object is spent. Setting used..\n", __func__);
Expand All @@ -597,12 +600,28 @@ bool CHDMintWallet::SetLelantusMintSeedSeen(CWalletDB& walletdb, std::pair<uint2

wtx.nTimeReceived = pindex->nTime;
pwalletMain->AddToWallet(wtx, false);
used = true;
} else {
lelantus::CLelantusState *lelantusState = lelantus::CLelantusState::GetState();
// this is for some edge cases, when mint is used but the serial is not at map
Scalar s;
if (lelantusState->IsUsedCoinSerialHash(s, hashSerial)) {
dMint.SetUsed(true);
serial = s;
used = true;
}
}

// Adding spend entry into db,
if(used && (serial != uint64_t(0))) {
CLelantusSpendEntry spend;
spend.coinSerial = serial;
spend.pubCoin = bnValue;
spend.id = id;
spend.amount = amount;

if (!walletdb.WriteLelantusSpendSerialEntry(spend)) {
throw std::runtime_error(_("Failed to write coin serial number into wallet"));
}
}

Expand Down