Changeset View
Changeset View
Standalone View
Standalone View
src/primitives/transaction.h
// 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. | ||||
#ifndef BITCOIN_PRIMITIVES_TRANSACTION_H | #ifndef BITCOIN_PRIMITIVES_TRANSACTION_H | ||||
#define BITCOIN_PRIMITIVES_TRANSACTION_H | #define BITCOIN_PRIMITIVES_TRANSACTION_H | ||||
#include "amount.h" | #include "amount.h" | ||||
#include "script/script.h" | #include "script/script.h" | ||||
#include "serialize.h" | #include "serialize.h" | ||||
#include "uint256.h" | #include "uint256.h" | ||||
static const int SERIALIZE_TRANSACTION = 0x00; | static const int SERIALIZE_TRANSACTION = 0x00; | ||||
/** | /** | ||||
* A TxId is the identifier of a transaction. Currently identical to TxHash but | |||||
* differentiated for type safety. | |||||
*/ | |||||
struct TxId : public uint256 { | |||||
explicit TxId(const uint256 &b) : uint256(b) {} | |||||
}; | |||||
/** | |||||
* A TxHash is the double sha256 hash of the full transaction data. | |||||
*/ | |||||
struct TxHash : public uint256 { | |||||
explicit TxHash(const uint256 &b) : uint256(b) {} | |||||
}; | |||||
/** | |||||
* An outpoint - a combination of a transaction hash and an index n into its | * An outpoint - a combination of a transaction hash and an index n into its | ||||
* vout. | * vout. | ||||
*/ | */ | ||||
class COutPoint { | class COutPoint { | ||||
public: | public: | ||||
uint256 hash; | uint256 hash; | ||||
uint32_t n; | uint32_t n; | ||||
▲ Show 20 Lines • Show All 250 Lines • ▼ Show 20 Lines | public: | ||||
* const fields. | * const fields. | ||||
*/ | */ | ||||
template <typename Stream> | template <typename Stream> | ||||
CTransaction(deserialize_type, Stream &s) | CTransaction(deserialize_type, Stream &s) | ||||
: CTransaction(CMutableTransaction(deserialize, s)) {} | : CTransaction(CMutableTransaction(deserialize, s)) {} | ||||
bool IsNull() const { return vin.empty() && vout.empty(); } | bool IsNull() const { return vin.empty() && vout.empty(); } | ||||
const uint256 &GetId() const { return hash; } | const TxId GetId() const { return TxId(hash); } | ||||
const TxHash GetHash() const { return TxHash(hash); } | |||||
// Compute a hash that includes both transaction and witness data | |||||
uint256 GetHash() const; | |||||
// Return sum of txouts. | // Return sum of txouts. | ||||
Amount GetValueOut() const; | Amount GetValueOut() const; | ||||
// GetValueIn() is a method on CCoinsViewCache, because | // GetValueIn() is a method on CCoinsViewCache, because | ||||
// inputs must be known to compute value in. | // inputs must be known to compute value in. | ||||
// Compute priority, given priority of inputs and (optionally) tx size | // Compute priority, given priority of inputs and (optionally) tx size | ||||
double ComputePriority(double dPriorityInputs, | double ComputePriority(double dPriorityInputs, | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
template <typename Stream> | template <typename Stream> | ||||
CMutableTransaction(deserialize_type, Stream &s) { | CMutableTransaction(deserialize_type, Stream &s) { | ||||
Unserialize(s); | Unserialize(s); | ||||
} | } | ||||
/** | /** | ||||
* Compute the hash of this CMutableTransaction. This is computed on the | * Compute the id and hash of this CMutableTransaction. This is computed on | ||||
* fly, as opposed to GetId() in CTransaction, which uses a cached result. | * the fly, as opposed to GetId() and GetHash() in CTransaction, which uses | ||||
* a cached result. | |||||
*/ | */ | ||||
uint256 GetId() const; | TxId GetId() const; | ||||
TxHash GetHash() const; | |||||
friend bool operator==(const CMutableTransaction &a, | friend bool operator==(const CMutableTransaction &a, | ||||
const CMutableTransaction &b) { | const CMutableTransaction &b) { | ||||
return a.GetId() == b.GetId(); | return a.GetId() == b.GetId(); | ||||
} | } | ||||
}; | }; | ||||
typedef std::shared_ptr<const CTransaction> CTransactionRef; | typedef std::shared_ptr<const CTransaction> CTransactionRef; | ||||
Show All 26 Lines |