Changeset View
Changeset View
Standalone View
Standalone View
src/primitives/transaction.cpp
Show All 32 Lines | std::string CTxOut::ToString() const { | ||||
return strprintf("CTxOut(nValue=%d.%08d, scriptPubKey=%s)", nValue / COIN, | return strprintf("CTxOut(nValue=%d.%08d, scriptPubKey=%s)", nValue / COIN, | ||||
(nValue % COIN) / SATOSHI, | (nValue % COIN) / SATOSHI, | ||||
HexStr(scriptPubKey).substr(0, 30)); | HexStr(scriptPubKey).substr(0, 30)); | ||||
} | } | ||||
CMutableTransaction::CMutableTransaction() | CMutableTransaction::CMutableTransaction() | ||||
: nVersion(CTransaction::CURRENT_VERSION), nLockTime(0) {} | : nVersion(CTransaction::CURRENT_VERSION), nLockTime(0) {} | ||||
CMutableTransaction::CMutableTransaction(const CTransaction &tx) | CMutableTransaction::CMutableTransaction(const CTransaction &tx) | ||||
: nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), | : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), | ||||
nLockTime(tx.nLockTime) {} | nLockTime(tx.nLockTime) {} | ||||
static uint256 ComputeCMutableTransactionHash(const CMutableTransaction &tx) { | static uint256 ComputeCMutableTransactionHash(const CMutableTransaction &tx) { | ||||
return SerializeHash(tx, SER_GETHASH, 0); | return SerializeHash(tx, SER_GETHASH, 0); | ||||
} | } | ||||
TxId CMutableTransaction::GetId() const { | TxId CMutableTransaction::GetId() const { | ||||
return TxId(ComputeCMutableTransactionHash(*this)); | return TxId(ComputeCMutableTransactionHash(*this)); | ||||
} | } | ||||
TxHash CMutableTransaction::GetHash() const { | TxHash CMutableTransaction::GetHash() const { | ||||
return TxHash(ComputeCMutableTransactionHash(*this)); | return TxHash(ComputeCMutableTransactionHash(*this)); | ||||
} | } | ||||
uint256 CTransaction::ComputeHash() const { | uint256 CTransaction::ComputeHash() const { | ||||
return SerializeHash(*this, SER_GETHASH, 0); | return SerializeHash(*this, SER_GETHASH, 0); | ||||
} | } | ||||
/** | /** | ||||
* For backward compatibility, the hash is initialized to 0. | * For backward compatibility, the hash is initialized to 0. | ||||
* TODO: remove the need for this default constructor entirely. | * TODO: remove the need for this default constructor entirely. | ||||
*/ | */ | ||||
CTransaction::CTransaction() | CTransaction::CTransaction() | ||||
: nVersion(CTransaction::CURRENT_VERSION), vin(), vout(), nLockTime(0), | : vin(), vout(), nVersion(CTransaction::CURRENT_VERSION), nLockTime(0), | ||||
hash() {} | hash() {} | ||||
CTransaction::CTransaction(const CMutableTransaction &tx) | CTransaction::CTransaction(const CMutableTransaction &tx) | ||||
: nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), | : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), | ||||
nLockTime(tx.nLockTime), hash(ComputeHash()) {} | nLockTime(tx.nLockTime), hash(ComputeHash()) {} | ||||
CTransaction::CTransaction(CMutableTransaction &&tx) | CTransaction::CTransaction(CMutableTransaction &&tx) | ||||
: nVersion(tx.nVersion), vin(std::move(tx.vin)), vout(std::move(tx.vout)), | : vin(std::move(tx.vin)), vout(std::move(tx.vout)), nVersion(tx.nVersion), | ||||
nLockTime(tx.nLockTime), hash(ComputeHash()) {} | nLockTime(tx.nLockTime), hash(ComputeHash()) {} | ||||
Amount CTransaction::GetValueOut() const { | Amount CTransaction::GetValueOut() const { | ||||
Amount nValueOut = Amount::zero(); | Amount nValueOut = Amount::zero(); | ||||
for (const auto &tx_out : vout) { | for (const auto &tx_out : vout) { | ||||
nValueOut += tx_out.nValue; | nValueOut += tx_out.nValue; | ||||
if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut)) { | if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut)) { | ||||
throw std::runtime_error(std::string(__func__) + | throw std::runtime_error(std::string(__func__) + | ||||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |