Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 1,384 Lines • ▼ Show 20 Lines | bool CWallet::IsChange(const CScript &script) const { | ||||
// TODO: fix handling of 'change' outputs. The assumption is that any | // TODO: fix handling of 'change' outputs. The assumption is that any | ||||
// payment to a script that is ours, but is not in the address book is | // payment to a script that is ours, but is not in the address book is | ||||
// change. That assumption is likely to break when we implement | // change. That assumption is likely to break when we implement | ||||
// multisignature wallets that return change back into a | // multisignature wallets that return change back into a | ||||
// multi-signature-protected address; a better way of identifying which | // multi-signature-protected address; a better way of identifying which | ||||
// outputs are 'the send' and which are 'the change' will need to be | // outputs are 'the send' and which are 'the change' will need to be | ||||
// implemented (maybe extend CWalletTx to remember which output, if any, was | // implemented (maybe extend CWalletTx to remember which output, if any, was | ||||
// change). | // change). | ||||
LOCK(cs_wallet); | AssertLockHeld(cs_wallet); | ||||
if (IsMine(script)) { | if (IsMine(script)) { | ||||
CTxDestination address; | CTxDestination address; | ||||
if (!ExtractDestination(script, address)) { | if (!ExtractDestination(script, address)) { | ||||
return true; | return true; | ||||
} | } | ||||
if (!FindAddressBookEntry(address)) { | if (!FindAddressBookEntry(address)) { | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
Amount CWallet::GetChange(const CTxOut &txout) const { | Amount CWallet::GetChange(const CTxOut &txout) const { | ||||
AssertLockHeld(cs_wallet); | |||||
if (!MoneyRange(txout.nValue)) { | if (!MoneyRange(txout.nValue)) { | ||||
throw std::runtime_error(std::string(__func__) + | throw std::runtime_error(std::string(__func__) + | ||||
": value out of range"); | ": value out of range"); | ||||
} | } | ||||
return (IsChange(txout) ? txout.nValue : Amount::zero()); | return (IsChange(txout) ? txout.nValue : Amount::zero()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | for (const CTxOut &txout : tx.vout) { | ||||
": value out of range"); | ": value out of range"); | ||||
} | } | ||||
} | } | ||||
return nCredit; | return nCredit; | ||||
} | } | ||||
Amount CWallet::GetChange(const CTransaction &tx) const { | Amount CWallet::GetChange(const CTransaction &tx) const { | ||||
LOCK(cs_wallet); | |||||
Amount nChange = Amount::zero(); | Amount nChange = Amount::zero(); | ||||
for (const CTxOut &txout : tx.vout) { | for (const CTxOut &txout : tx.vout) { | ||||
nChange += GetChange(txout); | nChange += GetChange(txout); | ||||
if (!MoneyRange(nChange)) { | if (!MoneyRange(nChange)) { | ||||
throw std::runtime_error(std::string(__func__) + | throw std::runtime_error(std::string(__func__) + | ||||
": value out of range"); | ": value out of range"); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 3,590 Lines • Show Last 20 Lines |