Changeset View
Changeset View
Standalone View
Standalone View
src/primitives/transaction.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <hash.h> | #include <hash.h> | ||||
#include <tinyformat.h> | #include <tinyformat.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <cassert> | |||||
std::string COutPoint::ToString() const { | std::string COutPoint::ToString() const { | ||||
return strprintf("COutPoint(%s, %u)", txid.ToString().substr(0, 10), n); | return strprintf("COutPoint(%s, %u)", txid.ToString().substr(0, 10), n); | ||||
} | } | ||||
std::string CTxIn::ToString() const { | std::string CTxIn::ToString() const { | ||||
std::string str; | std::string str; | ||||
str += "CTxIn("; | str += "CTxIn("; | ||||
str += prevout.ToString(); | str += prevout.ToString(); | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | : 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) | ||||
: vin(std::move(tx.vin)), vout(std::move(tx.vout)), nVersion(tx.nVersion), | : 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; | if (!MoneyRange(tx_out.nValue) || | ||||
if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut)) { | !MoneyRange(nValueOut + tx_out.nValue)) { | ||||
throw std::runtime_error(std::string(__func__) + | throw std::runtime_error(std::string(__func__) + | ||||
": value out of range"); | ": value out of range"); | ||||
} | } | ||||
nValueOut += tx_out.nValue; | |||||
} | } | ||||
assert(MoneyRange(nValueOut)); | |||||
return nValueOut; | return nValueOut; | ||||
} | } | ||||
unsigned int CTransaction::GetTotalSize() const { | unsigned int CTransaction::GetTotalSize() const { | ||||
return ::GetSerializeSize(*this, PROTOCOL_VERSION); | return ::GetSerializeSize(*this, PROTOCOL_VERSION); | ||||
} | } | ||||
std::string CTransaction::ToString() const { | std::string CTransaction::ToString() const { | ||||
Show All 13 Lines |