Changeset View
Changeset View
Standalone View
Standalone View
src/qt/walletmodel.cpp
Show First 20 Lines • Show All 440 Lines • ▼ Show 20 Lines | qDebug() << "NotifyAddressBookChanged: " + strAddress + " " + strLabel + | ||||
strPurpose + " status=" + QString::number(status); | strPurpose + " status=" + QString::number(status); | ||||
QMetaObject::invokeMethod(walletmodel, "updateAddressBook", | QMetaObject::invokeMethod(walletmodel, "updateAddressBook", | ||||
Qt::QueuedConnection, Q_ARG(QString, strAddress), | Qt::QueuedConnection, Q_ARG(QString, strAddress), | ||||
Q_ARG(QString, strLabel), Q_ARG(bool, isMine), | Q_ARG(QString, strLabel), Q_ARG(bool, isMine), | ||||
Q_ARG(QString, strPurpose), Q_ARG(int, status)); | Q_ARG(QString, strPurpose), Q_ARG(int, status)); | ||||
} | } | ||||
static void NotifyTransactionChanged(WalletModel *walletmodel, CWallet *wallet, | static void NotifyTransactionChanged(WalletModel *walletmodel, CWallet *wallet, | ||||
const uint256 &hash, ChangeType status) { | const txhash_t &hash, ChangeType status) { | ||||
Q_UNUSED(wallet); | Q_UNUSED(wallet); | ||||
Q_UNUSED(hash); | Q_UNUSED(hash); | ||||
Q_UNUSED(status); | Q_UNUSED(status); | ||||
QMetaObject::invokeMethod(walletmodel, "updateTransaction", | QMetaObject::invokeMethod(walletmodel, "updateTransaction", | ||||
Qt::QueuedConnection); | Qt::QueuedConnection); | ||||
} | } | ||||
static void ShowProgress(WalletModel *walletmodel, const std::string &title, | static void ShowProgress(WalletModel *walletmodel, const std::string &title, | ||||
▲ Show 20 Lines • Show All 80 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; | const CWalletTx *wtx = wallet->GetWalletTx(outpoint.unspentid); | ||||
int nDepth = wallet->mapWallet[outpoint.hash].GetDepthInMainChain(); | if (!wtx) continue; | ||||
int nDepth = wtx->GetDepthInMainChain(); | |||||
if (nDepth < 0) continue; | if (nDepth < 0) continue; | ||||
COutput out(&wallet->mapWallet[outpoint.hash], outpoint.n, nDepth, true, | COutput out(wtx, outpoint.n, nDepth, true, true); | ||||
true); | |||||
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); | ||||
} | } | ||||
// 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; | const CWalletTx *wtx = wallet->GetWalletTx(outpoint.unspentid); | ||||
int nDepth = wallet->mapWallet[outpoint.hash].GetDepthInMainChain(); | if (!wtx) continue; | ||||
int nDepth = wtx->GetDepthInMainChain(); | |||||
if (nDepth < 0) continue; | if (nDepth < 0) continue; | ||||
COutput out(&wallet->mapWallet[outpoint.hash], outpoint.n, nDepth, true, | COutput out(wtx, outpoint.n, nDepth, true, true); | ||||
true); | |||||
if (outpoint.n < out.tx->tx->vout.size() && | if (outpoint.n < out.tx->tx->vout.size() && | ||||
wallet->IsMine(out.tx->tx->vout[outpoint.n]) == ISMINE_SPENDABLE) | wallet->IsMine(out.tx->tx->vout[outpoint.n]) == 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)) | const CWalletTx *wtx = | ||||
break; | wallet->GetWalletTx(cout.tx->tx->vin[0].prevout.unspentid); | ||||
cout = COutput(&wallet->mapWallet[cout.tx->tx->vin[0].prevout.hash], | if (!wtx) break; | ||||
cout.tx->tx->vin[0].prevout.n, 0, true, true); | cout = COutput(wtx, cout.tx->tx->vin[0].prevout.n, 0, true, true); | ||||
} | } | ||||
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(txhash_t hash, unsigned int n) const { | ||||
LOCK2(cs_main, wallet->cs_wallet); | LOCK2(cs_main, wallet->cs_wallet); | ||||
return wallet->IsLockedCoin(hash, n); | const CWalletTx *wtx = wallet->GetWalletTx(hash); | ||||
if (!wtx) { | |||||
return false; | |||||
} | |||||
return wallet->IsLockedCoin(COutPoint(wtx->tx->GetUnspentid(), n)); | |||||
} | } | ||||
void WalletModel::lockCoin(COutPoint &output) { | void WalletModel::lockCoin(COutPoint &output) { | ||||
LOCK2(cs_main, wallet->cs_wallet); | LOCK2(cs_main, wallet->cs_wallet); | ||||
wallet->LockCoin(output); | wallet->LockCoin(output); | ||||
} | } | ||||
void WalletModel::unlockCoin(COutPoint &output) { | void WalletModel::unlockCoin(COutPoint &output) { | ||||
Show All 31 Lines | bool WalletModel::saveReceiveRequest(const std::string &sAddress, | ||||
LOCK(wallet->cs_wallet); | LOCK(wallet->cs_wallet); | ||||
if (sRequest.empty()) | if (sRequest.empty()) | ||||
return wallet->EraseDestData(dest, key); | return wallet->EraseDestData(dest, key); | ||||
else | else | ||||
return wallet->AddDestData(dest, key, sRequest); | return wallet->AddDestData(dest, key, sRequest); | ||||
} | } | ||||
bool WalletModel::transactionCanBeAbandoned(uint256 hash) const { | bool WalletModel::transactionCanBeAbandoned(txhash_t hash) const { | ||||
LOCK2(cs_main, wallet->cs_wallet); | LOCK2(cs_main, wallet->cs_wallet); | ||||
const CWalletTx *wtx = wallet->GetWalletTx(hash); | const CWalletTx *wtx = wallet->GetWalletTx(hash); | ||||
if (!wtx || wtx->isAbandoned() || wtx->GetDepthInMainChain() > 0 || | if (!wtx || wtx->isAbandoned() || wtx->GetDepthInMainChain() > 0 || | ||||
wtx->InMempool()) | wtx->InMempool()) | ||||
return false; | return false; | ||||
return true; | return true; | ||||
} | } | ||||
bool WalletModel::abandonTransaction(uint256 hash) const { | bool WalletModel::abandonTransaction(txhash_t hash) const { | ||||
LOCK2(cs_main, wallet->cs_wallet); | LOCK2(cs_main, wallet->cs_wallet); | ||||
return wallet->AbandonTransaction(hash); | return wallet->AbandonTransaction(hash); | ||||
} | } | ||||
bool WalletModel::isWalletEnabled() { | bool WalletModel::isWalletEnabled() { | ||||
return !GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET); | return !GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET); | ||||
} | } | ||||
bool WalletModel::hdEnabled() const { | bool WalletModel::hdEnabled() const { | ||||
return wallet->IsHDEnabled(); | return wallet->IsHDEnabled(); | ||||
} | } | ||||
int WalletModel::getDefaultConfirmTarget() const { | int WalletModel::getDefaultConfirmTarget() const { | ||||
return nTxConfirmTarget; | return nTxConfirmTarget; | ||||
} | } |