diff --git a/src/primitives/block.cpp b/src/primitives/block.cpp index f3d3f941fb..288e072d54 100644 --- a/src/primitives/block.cpp +++ b/src/primitives/block.cpp @@ -1,28 +1,28 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "primitives/block.h" +#include -#include "crypto/common.h" -#include "hash.h" -#include "tinyformat.h" -#include "utilstrencodings.h" +#include +#include +#include +#include uint256 CBlockHeader::GetHash() const { return SerializeHash(*this); } std::string CBlock::ToString() const { std::stringstream s; s << strprintf("CBlock(hash=%s, ver=0x%08x, hashPrevBlock=%s, " "hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, " "vtx=%u)\n", GetHash().ToString(), nVersion, hashPrevBlock.ToString(), hashMerkleRoot.ToString(), nTime, nBits, nNonce, vtx.size()); for (const auto &tx : vtx) { s << " " << tx->ToString() << "\n"; } return s.str(); } diff --git a/src/primitives/block.h b/src/primitives/block.h index 41ac6ff1aa..5c06ca0d5b 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -1,131 +1,131 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_PRIMITIVES_BLOCK_H #define BITCOIN_PRIMITIVES_BLOCK_H -#include "primitives/transaction.h" -#include "serialize.h" -#include "uint256.h" +#include +#include +#include /** * Nodes collect new transactions into a block, hash them into a hash tree, and * scan through nonce values to make the block's hash satisfy proof-of-work * requirements. When they solve the proof-of-work, they broadcast the block to * everyone and the block is added to the block chain. The first transaction in * the block is a special one that creates a new coin owned by the creator of * the block. */ class CBlockHeader { public: // header int32_t nVersion; uint256 hashPrevBlock; uint256 hashMerkleRoot; uint32_t nTime; uint32_t nBits; uint32_t nNonce; CBlockHeader() { SetNull(); } ADD_SERIALIZE_METHODS; template inline void SerializationOp(Stream &s, Operation ser_action) { READWRITE(this->nVersion); READWRITE(hashPrevBlock); READWRITE(hashMerkleRoot); READWRITE(nTime); READWRITE(nBits); READWRITE(nNonce); } void SetNull() { nVersion = 0; hashPrevBlock.SetNull(); hashMerkleRoot.SetNull(); nTime = 0; nBits = 0; nNonce = 0; } bool IsNull() const { return (nBits == 0); } uint256 GetHash() const; int64_t GetBlockTime() const { return (int64_t)nTime; } }; class CBlock : public CBlockHeader { public: // network and disk std::vector vtx; // memory only mutable bool fChecked; CBlock() { SetNull(); } CBlock(const CBlockHeader &header) { SetNull(); *(static_cast(this)) = header; } ADD_SERIALIZE_METHODS; template inline void SerializationOp(Stream &s, Operation ser_action) { READWRITE(*static_cast(this)); READWRITE(vtx); } void SetNull() { CBlockHeader::SetNull(); vtx.clear(); fChecked = false; } CBlockHeader GetBlockHeader() const { CBlockHeader block; block.nVersion = nVersion; block.hashPrevBlock = hashPrevBlock; block.hashMerkleRoot = hashMerkleRoot; block.nTime = nTime; block.nBits = nBits; block.nNonce = nNonce; return block; } std::string ToString() const; }; /** * Describes a place in the block chain to another node such that if the other * node doesn't have the same branch, it can find a recent common trunk. The * further back it is, the further before the fork it may be. */ struct CBlockLocator { std::vector vHave; CBlockLocator() {} explicit CBlockLocator(const std::vector &vHaveIn) : vHave(vHaveIn) {} ADD_SERIALIZE_METHODS; template inline void SerializationOp(Stream &s, Operation ser_action) { int nVersion = s.GetVersion(); if (!(s.GetType() & SER_GETHASH)) READWRITE(nVersion); READWRITE(vHave); } void SetNull() { vHave.clear(); } bool IsNull() const { return vHave.empty(); } }; #endif // BITCOIN_PRIMITIVES_BLOCK_H diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index f4e58b39ab..0c9798ada0 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -1,137 +1,137 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "primitives/transaction.h" +#include -#include "hash.h" -#include "tinyformat.h" -#include "utilstrencodings.h" +#include +#include +#include std::string COutPoint::ToString() const { return strprintf("COutPoint(%s, %u)", txid.ToString().substr(0, 10), n); } std::string CTxIn::ToString() const { std::string str; str += "CTxIn("; str += prevout.ToString(); if (prevout.IsNull()) { str += strprintf(", coinbase %s", HexStr(scriptSig)); } else { str += strprintf(", scriptSig=%s", HexStr(scriptSig).substr(0, 24)); } if (nSequence != SEQUENCE_FINAL) { str += strprintf(", nSequence=%u", nSequence); } str += ")"; return str; } std::string CTxOut::ToString() const { return strprintf("CTxOut(nValue=%d.%08d, scriptPubKey=%s)", nValue / COIN, (nValue % COIN) / SATOSHI, HexStr(scriptPubKey).substr(0, 30)); } CMutableTransaction::CMutableTransaction() : nVersion(CTransaction::CURRENT_VERSION), nLockTime(0) {} CMutableTransaction::CMutableTransaction(const CTransaction &tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime) {} static uint256 ComputeCMutableTransactionHash(const CMutableTransaction &tx) { return SerializeHash(tx, SER_GETHASH, 0); } TxId CMutableTransaction::GetId() const { return TxId(ComputeCMutableTransactionHash(*this)); } TxHash CMutableTransaction::GetHash() const { return TxHash(ComputeCMutableTransactionHash(*this)); } uint256 CTransaction::ComputeHash() const { return SerializeHash(*this, SER_GETHASH, 0); } /** * For backward compatibility, the hash is initialized to 0. * TODO: remove the need for this default constructor entirely. */ CTransaction::CTransaction() : nVersion(CTransaction::CURRENT_VERSION), vin(), vout(), nLockTime(0), hash() {} CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime), hash(ComputeHash()) {} CTransaction::CTransaction(CMutableTransaction &&tx) : nVersion(tx.nVersion), vin(std::move(tx.vin)), vout(std::move(tx.vout)), nLockTime(tx.nLockTime), hash(ComputeHash()) {} Amount CTransaction::GetValueOut() const { Amount nValueOut = Amount::zero(); for (const auto &tx_out : vout) { nValueOut += tx_out.nValue; if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut)) { throw std::runtime_error(std::string(__func__) + ": value out of range"); } } return nValueOut; } double CTransaction::ComputePriority(double dPriorityInputs, unsigned int nTxSize) const { nTxSize = CalculateModifiedSize(nTxSize); if (nTxSize == 0) { return 0.0; } return dPriorityInputs / nTxSize; } unsigned int CTransaction::CalculateModifiedSize(unsigned int nTxSize) const { // In order to avoid disincentivizing cleaning up the UTXO set we don't // count the constant overhead for each txin and up to 110 bytes of // scriptSig (which is enough to cover a compressed pubkey p2sh redemption) // for priority. Providing any more cleanup incentive than making additional // inputs free would risk encouraging people to create junk outputs to // redeem later. if (nTxSize == 0) { nTxSize = GetTotalSize(); } for (const auto &nVin : vin) { unsigned int offset = 41U + std::min(110U, (unsigned int)nVin.scriptSig.size()); if (nTxSize > offset) { nTxSize -= offset; } } return nTxSize; } size_t CTransaction::GetBillableSize() const { return ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION); } unsigned int CTransaction::GetTotalSize() const { return ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION); } std::string CTransaction::ToString() const { std::string str; str += strprintf("CTransaction(txid=%s, ver=%d, vin.size=%u, vout.size=%u, " "nLockTime=%u)\n", GetId().ToString().substr(0, 10), nVersion, vin.size(), vout.size(), nLockTime); for (const auto &nVin : vin) { str += " " + nVin.ToString() + "\n"; } for (const auto &nVout : vout) { str += " " + nVout.ToString() + "\n"; } return str; } diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index ec4a414828..ea28eedf8e 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -1,391 +1,391 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2016 The Bitcoin Core developers // Copyright (c) 2017-2018 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_PRIMITIVES_TRANSACTION_H #define BITCOIN_PRIMITIVES_TRANSACTION_H -#include "amount.h" -#include "feerate.h" -#include "primitives/txid.h" -#include "script/script.h" -#include "serialize.h" +#include +#include +#include +#include