Page MenuHomePhabricator

D755.diff
No OneTemporary

D755.diff

diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h
--- a/src/primitives/transaction.h
+++ b/src/primitives/transaction.h
@@ -13,6 +13,21 @@
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
* vout.
@@ -280,10 +295,8 @@
bool IsNull() const { return vin.empty() && vout.empty(); }
- const uint256 &GetId() const { return hash; }
-
- // Compute a hash that includes both transaction and witness data
- uint256 GetHash() const;
+ const TxId GetId() const { return TxId(hash); }
+ const TxHash GetHash() const { return TxHash(hash); }
// Return sum of txouts.
Amount GetValueOut() const;
@@ -346,10 +359,12 @@
}
/**
- * Compute the hash of this CMutableTransaction. This is computed on the
- * fly, as opposed to GetId() in CTransaction, which uses a cached result.
+ * Compute the id and hash of this CMutableTransaction. This is computed on
+ * 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,
const CMutableTransaction &b) {
diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp
--- a/src/primitives/transaction.cpp
+++ b/src/primitives/transaction.cpp
@@ -60,16 +60,20 @@
: nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout),
nLockTime(tx.nLockTime) {}
-uint256 CMutableTransaction::GetId() const {
- return SerializeHash(*this, SER_GETHASH, 0);
+static uint256 ComputeCMutableTransactionHash(const CMutableTransaction &tx) {
+ return SerializeHash(tx, SER_GETHASH, 0);
}
-uint256 CTransaction::ComputeHash() const {
- return SerializeHash(*this, SER_GETHASH, 0);
+TxId CMutableTransaction::GetId() const {
+ return TxId(ComputeCMutableTransactionHash(*this));
}
-uint256 CTransaction::GetHash() const {
- return GetId();
+TxHash CMutableTransaction::GetHash() const {
+ return TxHash(ComputeCMutableTransactionHash(*this));
+}
+
+uint256 CTransaction::ComputeHash() const {
+ return SerializeHash(*this, SER_GETHASH, 0);
}
/**
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -244,7 +244,7 @@
bool isAbandoned() const { return (hashBlock == ABANDON_HASH); }
void setAbandoned() { hashBlock = ABANDON_HASH; }
- const uint256 &GetId() const { return tx->GetId(); }
+ const TxId GetId() const { return tx->GetId(); }
bool IsCoinBase() const { return tx->IsCoinBase(); }
};

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 1, 09:10 (43 m, 30 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5187166
Default Alt Text
D755.diff (3 KB)

Event Timeline