Changeset View
Changeset View
Standalone View
Standalone View
src/qt/walletmodel.cpp
Show First 20 Lines • Show All 539 Lines • ▼ Show 20 Lines | bool WalletModel::getPrivKey(const CKeyID &address, CKey &vchPrivKeyOut) const { | ||||
return wallet->GetKey(address, vchPrivKeyOut); | return wallet->GetKey(address, vchPrivKeyOut); | ||||
} | } | ||||
// returns a list of COutputs from COutPoints | // returns a list of COutputs from COutPoints | ||||
void WalletModel::getOutputs(const std::vector<COutPoint> &vOutpoints, | void WalletModel::getOutputs(const std::vector<COutPoint> &vOutpoints, | ||||
std::vector<COutput> &vOutputs) { | std::vector<COutput> &vOutputs) { | ||||
LOCK2(cs_main, wallet->cs_wallet); | LOCK2(cs_main, wallet->cs_wallet); | ||||
for (const COutPoint &outpoint : vOutpoints) { | for (const COutPoint &outpoint : vOutpoints) { | ||||
if (!wallet->mapWallet.count(outpoint.hash)) continue; | if (!wallet->mapWallet.count(outpoint.GetTxId())) { | ||||
int nDepth = wallet->mapWallet[outpoint.hash].GetDepthInMainChain(); | continue; | ||||
if (nDepth < 0) continue; | } | ||||
COutput out(&wallet->mapWallet[outpoint.hash], outpoint.n, nDepth, | int nDepth = | ||||
true /* spendable */, true /* solvable */, true /* safe */); | wallet->mapWallet[outpoint.GetTxId()].GetDepthInMainChain(); | ||||
if (nDepth < 0) { | |||||
continue; | |||||
} | |||||
COutput out(&wallet->mapWallet[outpoint.GetTxId()], outpoint.GetN(), | |||||
nDepth, true /* spendable */, true /* solvable */, | |||||
true /* safe */); | |||||
vOutputs.push_back(out); | vOutputs.push_back(out); | ||||
} | } | ||||
} | } | ||||
bool WalletModel::isSpent(const COutPoint &outpoint) const { | bool WalletModel::isSpent(const COutPoint &outpoint) const { | ||||
LOCK2(cs_main, wallet->cs_wallet); | LOCK2(cs_main, wallet->cs_wallet); | ||||
return wallet->IsSpent(outpoint.hash, outpoint.n); | return wallet->IsSpent(outpoint.GetTxId(), outpoint.GetN()); | ||||
} | } | ||||
// AvailableCoins + LockedCoins grouped by wallet address (put change in one | // AvailableCoins + LockedCoins grouped by wallet address (put change in one | ||||
// group with wallet address) | // group with wallet address) | ||||
void WalletModel::listCoins( | void WalletModel::listCoins( | ||||
std::map<QString, std::vector<COutput>> &mapCoins) const { | std::map<QString, std::vector<COutput>> &mapCoins) const { | ||||
std::vector<COutput> vCoins; | std::vector<COutput> vCoins; | ||||
wallet->AvailableCoins(vCoins); | wallet->AvailableCoins(vCoins); | ||||
// ListLockedCoins, mapWallet | // ListLockedCoins, mapWallet | ||||
LOCK2(cs_main, wallet->cs_wallet); | LOCK2(cs_main, wallet->cs_wallet); | ||||
std::vector<COutPoint> vLockedCoins; | std::vector<COutPoint> vLockedCoins; | ||||
wallet->ListLockedCoins(vLockedCoins); | wallet->ListLockedCoins(vLockedCoins); | ||||
// add locked coins | // add locked coins | ||||
for (const COutPoint &outpoint : vLockedCoins) { | for (const COutPoint &outpoint : vLockedCoins) { | ||||
if (!wallet->mapWallet.count(outpoint.hash)) continue; | if (!wallet->mapWallet.count(outpoint.GetTxId())) { | ||||
int nDepth = wallet->mapWallet[outpoint.hash].GetDepthInMainChain(); | continue; | ||||
if (nDepth < 0) continue; | } | ||||
COutput out(&wallet->mapWallet[outpoint.hash], outpoint.n, nDepth, | int nDepth = | ||||
true /* spendable */, true /* solvable */, true /* safe */); | wallet->mapWallet[outpoint.GetTxId()].GetDepthInMainChain(); | ||||
if (outpoint.n < out.tx->tx->vout.size() && | if (nDepth < 0) { | ||||
wallet->IsMine(out.tx->tx->vout[outpoint.n]) == ISMINE_SPENDABLE) { | continue; | ||||
} | |||||
COutput out(&wallet->mapWallet[outpoint.GetTxId()], outpoint.GetN(), | |||||
nDepth, true /* spendable */, true /* solvable */, | |||||
true /* safe */); | |||||
if (outpoint.GetN() < out.tx->tx->vout.size() && | |||||
wallet->IsMine(out.tx->tx->vout[outpoint.GetN()]) == | |||||
ISMINE_SPENDABLE) { | |||||
vCoins.push_back(out); | vCoins.push_back(out); | ||||
} | } | ||||
} | } | ||||
for (const COutput &out : vCoins) { | for (const COutput &out : vCoins) { | ||||
COutput cout = out; | COutput cout = out; | ||||
while (wallet->IsChange(cout.tx->tx->vout[cout.i]) && | while (wallet->IsChange(cout.tx->tx->vout[cout.i]) && | ||||
cout.tx->tx->vin.size() > 0 && | cout.tx->tx->vin.size() > 0 && | ||||
wallet->IsMine(cout.tx->tx->vin[0])) { | wallet->IsMine(cout.tx->tx->vin[0])) { | ||||
if (!wallet->mapWallet.count(cout.tx->tx->vin[0].prevout.hash)) | if (!wallet->mapWallet.count( | ||||
cout.tx->tx->vin[0].prevout.GetTxId())) { | |||||
break; | break; | ||||
cout = COutput(&wallet->mapWallet[cout.tx->tx->vin[0].prevout.hash], | } | ||||
cout.tx->tx->vin[0].prevout.n, 0 /* depth */, | cout = COutput( | ||||
true /* spendable */, true /* solvable */, | &wallet->mapWallet[cout.tx->tx->vin[0].prevout.GetTxId()], | ||||
true /* safe */); | cout.tx->tx->vin[0].prevout.GetN(), 0 /* depth */, | ||||
true /* spendable */, true /* solvable */, true /* safe */); | |||||
} | } | ||||
CTxDestination address; | CTxDestination address; | ||||
if (!out.fSpendable || | if (!out.fSpendable || | ||||
!ExtractDestination(cout.tx->tx->vout[cout.i].scriptPubKey, | !ExtractDestination(cout.tx->tx->vout[cout.i].scriptPubKey, | ||||
address)) | address)) { | ||||
continue; | continue; | ||||
} | |||||
mapCoins[QString::fromStdString(EncodeDestination(address))].push_back( | mapCoins[QString::fromStdString(EncodeDestination(address))].push_back( | ||||
out); | out); | ||||
} | } | ||||
} | } | ||||
bool WalletModel::isLockedCoin(uint256 hash, unsigned int n) const { | bool WalletModel::isLockedCoin(uint256 hash, unsigned int n) const { | ||||
LOCK2(cs_main, wallet->cs_wallet); | LOCK2(cs_main, wallet->cs_wallet); | ||||
return wallet->IsLockedCoin(hash, n); | return wallet->IsLockedCoin(hash, n); | ||||
▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines |