LCOV - code coverage report
Current view: top level - src/primitives - transaction.cpp (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 75 78 96.2 %
Date: 2022-04-21 14:51:19 Functions: 16 16 100.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 16 20 80.0 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2009-2010 Satoshi Nakamoto
#       2                 :            : // Copyright (c) 2009-2021 The Bitcoin Core developers
#       3                 :            : // Distributed under the MIT software license, see the accompanying
#       4                 :            : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#       5                 :            : 
#       6                 :            : #include <primitives/transaction.h>
#       7                 :            : 
#       8                 :            : #include <consensus/amount.h>
#       9                 :            : #include <hash.h>
#      10                 :            : #include <tinyformat.h>
#      11                 :            : #include <util/strencodings.h>
#      12                 :            : 
#      13                 :            : #include <assert.h>
#      14                 :            : 
#      15                 :            : std::string COutPoint::ToString() const
#      16                 :       5061 : {
#      17                 :       5061 :     return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10), n);
#      18                 :       5061 : }
#      19                 :            : 
#      20                 :            : CTxIn::CTxIn(COutPoint prevoutIn, CScript scriptSigIn, uint32_t nSequenceIn)
#      21                 :     489333 : {
#      22                 :     489333 :     prevout = prevoutIn;
#      23                 :     489333 :     scriptSig = scriptSigIn;
#      24                 :     489333 :     nSequence = nSequenceIn;
#      25                 :     489333 : }
#      26                 :            : 
#      27                 :            : CTxIn::CTxIn(uint256 hashPrevTx, uint32_t nOut, CScript scriptSigIn, uint32_t nSequenceIn)
#      28                 :         98 : {
#      29                 :         98 :     prevout = COutPoint(hashPrevTx, nOut);
#      30                 :         98 :     scriptSig = scriptSigIn;
#      31                 :         98 :     nSequence = nSequenceIn;
#      32                 :         98 : }
#      33                 :            : 
#      34                 :            : std::string CTxIn::ToString() const
#      35                 :       5061 : {
#      36                 :       5061 :     std::string str;
#      37                 :       5061 :     str += "CTxIn(";
#      38                 :       5061 :     str += prevout.ToString();
#      39         [ -  + ]:       5061 :     if (prevout.IsNull())
#      40                 :          0 :         str += strprintf(", coinbase %s", HexStr(scriptSig));
#      41                 :       5061 :     else
#      42                 :       5061 :         str += strprintf(", scriptSig=%s", HexStr(scriptSig).substr(0, 24));
#      43         [ +  + ]:       5061 :     if (nSequence != SEQUENCE_FINAL)
#      44                 :       4995 :         str += strprintf(", nSequence=%u", nSequence);
#      45                 :       5061 :     str += ")";
#      46                 :       5061 :     return str;
#      47                 :       5061 : }
#      48                 :            : 
#      49                 :            : CTxOut::CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn)
#      50                 :     153683 : {
#      51                 :     153683 :     nValue = nValueIn;
#      52                 :     153683 :     scriptPubKey = scriptPubKeyIn;
#      53                 :     153683 : }
#      54                 :            : 
#      55                 :            : std::string CTxOut::ToString() const
#      56                 :       7791 : {
#      57                 :       7791 :     return strprintf("CTxOut(nValue=%d.%08d, scriptPubKey=%s)", nValue / COIN, nValue % COIN, HexStr(scriptPubKey).substr(0, 30));
#      58                 :       7791 : }
#      59                 :            : 
#      60                 :    1107117 : CMutableTransaction::CMutableTransaction() : nVersion(CTransaction::CURRENT_VERSION), nLockTime(0) {}
#      61                 :     187478 : CMutableTransaction::CMutableTransaction(const CTransaction& tx) : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), nLockTime(tx.nLockTime) {}
#      62                 :            : 
#      63                 :            : uint256 CMutableTransaction::GetHash() const
#      64                 :     296606 : {
#      65                 :     296606 :     return SerializeHash(*this, SER_GETHASH, SERIALIZE_TRANSACTION_NO_WITNESS);
#      66                 :     296606 : }
#      67                 :            : 
#      68                 :            : uint256 CTransaction::ComputeHash() const
#      69                 :    1227663 : {
#      70                 :    1227663 :     return SerializeHash(*this, SER_GETHASH, SERIALIZE_TRANSACTION_NO_WITNESS);
#      71                 :    1227663 : }
#      72                 :            : 
#      73                 :            : uint256 CTransaction::ComputeWitnessHash() const
#      74                 :    1227662 : {
#      75         [ +  + ]:    1227662 :     if (!HasWitness()) {
#      76                 :     930849 :         return hash;
#      77                 :     930849 :     }
#      78                 :     296813 :     return SerializeHash(*this, SER_GETHASH, 0);
#      79                 :    1227662 : }
#      80                 :            : 
#      81                 :     446560 : CTransaction::CTransaction(const CMutableTransaction& tx) : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), nLockTime(tx.nLockTime), hash{ComputeHash()}, m_witness_hash{ComputeWitnessHash()} {}
#      82                 :     781103 : CTransaction::CTransaction(CMutableTransaction&& tx) : vin(std::move(tx.vin)), vout(std::move(tx.vout)), nVersion(tx.nVersion), nLockTime(tx.nLockTime), hash{ComputeHash()}, m_witness_hash{ComputeWitnessHash()} {}
#      83                 :            : 
#      84                 :            : CAmount CTransaction::GetValueOut() const
#      85                 :   11198459 : {
#      86                 :   11198459 :     CAmount nValueOut = 0;
#      87         [ +  + ]:   24930589 :     for (const auto& tx_out : vout) {
#      88 [ -  + ][ -  + ]:   24930589 :         if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut + tx_out.nValue))
#                 [ -  + ]
#      89                 :          0 :             throw std::runtime_error(std::string(__func__) + ": value out of range");
#      90                 :   24930589 :         nValueOut += tx_out.nValue;
#      91                 :   24930589 :     }
#      92                 :   11198459 :     assert(MoneyRange(nValueOut));
#      93                 :          0 :     return nValueOut;
#      94                 :   11198459 : }
#      95                 :            : 
#      96                 :            : unsigned int CTransaction::GetTotalSize() const
#      97                 :         32 : {
#      98                 :         32 :     return ::GetSerializeSize(*this, PROTOCOL_VERSION);
#      99                 :         32 : }
#     100                 :            : 
#     101                 :            : std::string CTransaction::ToString() const
#     102                 :       2311 : {
#     103                 :       2311 :     std::string str;
#     104                 :       2311 :     str += strprintf("CTransaction(hash=%s, ver=%d, vin.size=%u, vout.size=%u, nLockTime=%u)\n",
#     105                 :       2311 :         GetHash().ToString().substr(0,10),
#     106                 :       2311 :         nVersion,
#     107                 :       2311 :         vin.size(),
#     108                 :       2311 :         vout.size(),
#     109                 :       2311 :         nLockTime);
#     110         [ +  + ]:       2311 :     for (const auto& tx_in : vin)
#     111                 :       5061 :         str += "    " + tx_in.ToString() + "\n";
#     112         [ +  + ]:       2311 :     for (const auto& tx_in : vin)
#     113                 :       5061 :         str += "    " + tx_in.scriptWitness.ToString() + "\n";
#     114         [ +  + ]:       2311 :     for (const auto& tx_out : vout)
#     115                 :       7787 :         str += "    " + tx_out.ToString() + "\n";
#     116                 :       2311 :     return str;
#     117                 :       2311 : }

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a