diff options
| author | Pieter Wuille <[email protected]> | 2014-06-22 20:40:53 +0200 |
|---|---|---|
| committer | Pieter Wuille <[email protected]> | 2014-06-22 20:45:30 +0200 |
| commit | d4e4e05435a93a72711120f46ee79482c13fae45 (patch) | |
| tree | aeb3e1ba960864e331b647abbfabe2ecb5a90c45 /src/core.cpp | |
| parent | Merge pull request #4381 (diff) | |
| parent | Code simplifications after CTransaction::GetHash() caching (diff) | |
| download | discoin-d4e4e05435a93a72711120f46ee79482c13fae45.tar.xz discoin-d4e4e05435a93a72711120f46ee79482c13fae45.zip | |
Merge pull request #4309
d38da59 Code simplifications after CTransaction::GetHash() caching (Pieter Wuille)
4949004 Add CMutableTransaction and make CTransaction immutable. (Pieter Wuille)
Diffstat (limited to 'src/core.cpp')
| -rw-r--r-- | src/core.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/core.cpp b/src/core.cpp index 6039986e6..6c5ee1c0f 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -91,11 +91,34 @@ std::string CFeeRate::ToString() const return result; } -uint256 CTransaction::GetHash() const +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) {} + +uint256 CMutableTransaction::GetHash() const { return SerializeHash(*this); } +void CTransaction::UpdateHash() const +{ + *const_cast<uint256*>(&hash) = SerializeHash(*this); +} + +CTransaction::CTransaction() : hash(0), nVersion(CTransaction::CURRENT_VERSION), vin(), vout(), nLockTime(0) { } + +CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime) { + UpdateHash(); +} + +CTransaction& CTransaction::operator=(const CTransaction &tx) { + *const_cast<int*>(&nVersion) = tx.nVersion; + *const_cast<std::vector<CTxIn>*>(&vin) = tx.vin; + *const_cast<std::vector<CTxOut>*>(&vout) = tx.vout; + *const_cast<unsigned int*>(&nLockTime) = tx.nLockTime; + *const_cast<uint256*>(&hash) = tx.hash; + return *this; +} + int64_t CTransaction::GetValueOut() const { int64_t nValueOut = 0; |