LCOV - code coverage report
Current view: top level - src/primitives - transaction.cpp (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 76 78 97.4 %
Date: 2021-06-29 14:35:33 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: 15 20 75.0 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2009-2010 Satoshi Nakamoto
#       2                 :            : // Copyright (c) 2009-2020 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 <hash.h>
#       9                 :            : #include <tinyformat.h>
#      10                 :            : #include <util/strencodings.h>
#      11                 :            : 
#      12                 :            : #include <assert.h>
#      13                 :            : 
#      14                 :            : std::string COutPoint::ToString() const
#      15                 :       6092 : {
#      16                 :       6092 :     return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10), n);
#      17                 :       6092 : }
#      18                 :            : 
#      19                 :            : CTxIn::CTxIn(COutPoint prevoutIn, CScript scriptSigIn, uint32_t nSequenceIn)
#      20                 :     577296 : {
#      21                 :     577296 :     prevout = prevoutIn;
#      22                 :     577296 :     scriptSig = scriptSigIn;
#      23                 :     577296 :     nSequence = nSequenceIn;
#      24                 :     577296 : }
#      25                 :            : 
#      26                 :            : CTxIn::CTxIn(uint256 hashPrevTx, uint32_t nOut, CScript scriptSigIn, uint32_t nSequenceIn)
#      27                 :          5 : {
#      28                 :          5 :     prevout = COutPoint(hashPrevTx, nOut);
#      29                 :          5 :     scriptSig = scriptSigIn;
#      30                 :          5 :     nSequence = nSequenceIn;
#      31                 :          5 : }
#      32                 :            : 
#      33                 :            : std::string CTxIn::ToString() const
#      34                 :       6092 : {
#      35                 :       6092 :     std::string str;
#      36                 :       6092 :     str += "CTxIn(";
#      37                 :       6092 :     str += prevout.ToString();
#      38         [ -  + ]:       6092 :     if (prevout.IsNull())
#      39                 :          0 :         str += strprintf(", coinbase %s", HexStr(scriptSig));
#      40                 :       6092 :     else
#      41                 :       6092 :         str += strprintf(", scriptSig=%s", HexStr(scriptSig).substr(0, 24));
#      42         [ +  - ]:       6092 :     if (nSequence != SEQUENCE_FINAL)
#      43                 :       6092 :         str += strprintf(", nSequence=%u", nSequence);
#      44                 :       6092 :     str += ")";
#      45                 :       6092 :     return str;
#      46                 :       6092 : }
#      47                 :            : 
#      48                 :            : CTxOut::CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn)
#      49                 :      78771 : {
#      50                 :      78771 :     nValue = nValueIn;
#      51                 :      78771 :     scriptPubKey = scriptPubKeyIn;
#      52                 :      78771 : }
#      53                 :            : 
#      54                 :            : std::string CTxOut::ToString() const
#      55                 :       9032 : {
#      56                 :       9032 :     return strprintf("CTxOut(nValue=%d.%08d, scriptPubKey=%s)", nValue / COIN, nValue % COIN, HexStr(scriptPubKey).substr(0, 30));
#      57                 :       9032 : }
#      58                 :            : 
#      59                 :    1238582 : CMutableTransaction::CMutableTransaction() : nVersion(CTransaction::CURRENT_VERSION), nLockTime(0) {}
#      60                 :     211682 : CMutableTransaction::CMutableTransaction(const CTransaction& tx) : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), nLockTime(tx.nLockTime) {}
#      61                 :            : 
#      62                 :            : uint256 CMutableTransaction::GetHash() const
#      63                 :     136491 : {
#      64                 :     136491 :     return SerializeHash(*this, SER_GETHASH, SERIALIZE_TRANSACTION_NO_WITNESS);
#      65                 :     136491 : }
#      66                 :            : 
#      67                 :            : uint256 CTransaction::ComputeHash() const
#      68                 :    1354417 : {
#      69                 :    1354417 :     return SerializeHash(*this, SER_GETHASH, SERIALIZE_TRANSACTION_NO_WITNESS);
#      70                 :    1354417 : }
#      71                 :            : 
#      72                 :            : uint256 CTransaction::ComputeWitnessHash() const
#      73                 :    1354417 : {
#      74         [ +  + ]:    1354417 :     if (!HasWitness()) {
#      75                 :    1101196 :         return hash;
#      76                 :    1101196 :     }
#      77                 :     253221 :     return SerializeHash(*this, SER_GETHASH, 0);
#      78                 :     253221 : }
#      79                 :            : 
#      80                 :     484348 : CTransaction::CTransaction(const CMutableTransaction& tx) : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), nLockTime(tx.nLockTime), hash{ComputeHash()}, m_witness_hash{ComputeWitnessHash()} {}
#      81                 :     870069 : 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()} {}
#      82                 :            : 
#      83                 :            : CAmount CTransaction::GetValueOut() const
#      84                 :    5420687 : {
#      85                 :    5420687 :     CAmount nValueOut = 0;
#      86         [ +  + ]:   11202490 :     for (const auto& tx_out : vout) {
#      87 [ -  + ][ -  + ]:   11202490 :         if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut + tx_out.nValue))
#                 [ -  + ]
#      88                 :          0 :             throw std::runtime_error(std::string(__func__) + ": value out of range");
#      89                 :   11202490 :         nValueOut += tx_out.nValue;
#      90                 :   11202490 :     }
#      91                 :    5420687 :     assert(MoneyRange(nValueOut));
#      92                 :    5420687 :     return nValueOut;
#      93                 :    5420687 : }
#      94                 :            : 
#      95                 :            : unsigned int CTransaction::GetTotalSize() const
#      96                 :         32 : {
#      97                 :         32 :     return ::GetSerializeSize(*this, PROTOCOL_VERSION);
#      98                 :         32 : }
#      99                 :            : 
#     100                 :            : std::string CTransaction::ToString() const
#     101                 :       2195 : {
#     102                 :       2195 :     std::string str;
#     103                 :       2195 :     str += strprintf("CTransaction(hash=%s, ver=%d, vin.size=%u, vout.size=%u, nLockTime=%u)\n",
#     104                 :       2195 :         GetHash().ToString().substr(0,10),
#     105                 :       2195 :         nVersion,
#     106                 :       2195 :         vin.size(),
#     107                 :       2195 :         vout.size(),
#     108                 :       2195 :         nLockTime);
#     109         [ +  + ]:       2195 :     for (const auto& tx_in : vin)
#     110                 :       6092 :         str += "    " + tx_in.ToString() + "\n";
#     111         [ +  + ]:       2195 :     for (const auto& tx_in : vin)
#     112                 :       6092 :         str += "    " + tx_in.scriptWitness.ToString() + "\n";
#     113         [ +  + ]:       2195 :     for (const auto& tx_out : vout)
#     114                 :       9028 :         str += "    " + tx_out.ToString() + "\n";
#     115                 :       2195 :     return str;
#     116                 :       2195 : }

Generated by: LCOV version 1.14