Skip to content

Commit 4a3587d

Browse files
author
jtimon
committed
MOVEONLY: Separate CTransaction and dependencies from core
1 parent eda3733 commit 4a3587d

26 files changed

Lines changed: 441 additions & 419 deletions

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ BITCOIN_CORE_H = \
8181
coins.h \
8282
compat.h \
8383
core.h \
84+
core/transaction.h \
8485
core_io.h \
8586
crypter.h \
8687
db.h \
@@ -213,6 +214,7 @@ libbitcoin_common_a_SOURCES = \
213214
chainparams.cpp \
214215
coins.cpp \
215216
core.cpp \
217+
core/transaction.cpp \
216218
core_read.cpp \
217219
core_write.cpp \
218220
hash.cpp \

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include "base58.h"
6-
#include "core.h"
6+
#include "core/transaction.h"
77
#include "core_io.h"
88
#include "keystore.h"
99
#include "main.h" // for MAX_BLOCK_SIZE

src/bloom.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "bloom.h"
66

7-
#include "core.h"
7+
#include "core/transaction.h"
88
#include "script/script.h"
99
#include "script/standard.h"
1010
#include "streams.h"

src/coincontrol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifndef COINCONTROL_H
66
#define COINCONTROL_H
77

8-
#include "core.h"
8+
#include "core/transaction.h"
99

1010
/** Coin Control Features. */
1111
class CCoinControl

src/coins.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#ifndef BITCOIN_COINS_H
77
#define BITCOIN_COINS_H
88

9-
#include "core.h"
9+
#include "core.h" // Only for CTxOutCompressor
10+
#include "core/transaction.h"
1011
#include "serialize.h"
1112
#include "uint256.h"
1213

src/core.cpp

Lines changed: 0 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -9,138 +9,6 @@
99
#include "tinyformat.h"
1010
#include "utilstrencodings.h"
1111

12-
std::string COutPoint::ToString() const
13-
{
14-
return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10), n);
15-
}
16-
17-
CTxIn::CTxIn(COutPoint prevoutIn, CScript scriptSigIn, uint32_t nSequenceIn)
18-
{
19-
prevout = prevoutIn;
20-
scriptSig = scriptSigIn;
21-
nSequence = nSequenceIn;
22-
}
23-
24-
CTxIn::CTxIn(uint256 hashPrevTx, uint32_t nOut, CScript scriptSigIn, uint32_t nSequenceIn)
25-
{
26-
prevout = COutPoint(hashPrevTx, nOut);
27-
scriptSig = scriptSigIn;
28-
nSequence = nSequenceIn;
29-
}
30-
31-
std::string CTxIn::ToString() const
32-
{
33-
std::string str;
34-
str += "CTxIn(";
35-
str += prevout.ToString();
36-
if (prevout.IsNull())
37-
str += strprintf(", coinbase %s", HexStr(scriptSig));
38-
else
39-
str += strprintf(", scriptSig=%s", scriptSig.ToString().substr(0,24));
40-
if (nSequence != std::numeric_limits<unsigned int>::max())
41-
str += strprintf(", nSequence=%u", nSequence);
42-
str += ")";
43-
return str;
44-
}
45-
46-
CTxOut::CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn)
47-
{
48-
nValue = nValueIn;
49-
scriptPubKey = scriptPubKeyIn;
50-
}
51-
52-
uint256 CTxOut::GetHash() const
53-
{
54-
return SerializeHash(*this);
55-
}
56-
57-
std::string CTxOut::ToString() const
58-
{
59-
return strprintf("CTxOut(nValue=%d.%08d, scriptPubKey=%s)", nValue / COIN, nValue % COIN, scriptPubKey.ToString().substr(0,30));
60-
}
61-
62-
CMutableTransaction::CMutableTransaction() : nVersion(CTransaction::CURRENT_VERSION), nLockTime(0) {}
63-
CMutableTransaction::CMutableTransaction(const CTransaction& tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime) {}
64-
65-
uint256 CMutableTransaction::GetHash() const
66-
{
67-
return SerializeHash(*this);
68-
}
69-
70-
void CTransaction::UpdateHash() const
71-
{
72-
*const_cast<uint256*>(&hash) = SerializeHash(*this);
73-
}
74-
75-
CTransaction::CTransaction() : hash(0), nVersion(CTransaction::CURRENT_VERSION), vin(), vout(), nLockTime(0) { }
76-
77-
CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime) {
78-
UpdateHash();
79-
}
80-
81-
CTransaction& CTransaction::operator=(const CTransaction &tx) {
82-
*const_cast<int*>(&nVersion) = tx.nVersion;
83-
*const_cast<std::vector<CTxIn>*>(&vin) = tx.vin;
84-
*const_cast<std::vector<CTxOut>*>(&vout) = tx.vout;
85-
*const_cast<unsigned int*>(&nLockTime) = tx.nLockTime;
86-
*const_cast<uint256*>(&hash) = tx.hash;
87-
return *this;
88-
}
89-
90-
CAmount CTransaction::GetValueOut() const
91-
{
92-
CAmount nValueOut = 0;
93-
for (std::vector<CTxOut>::const_iterator it(vout.begin()); it != vout.end(); ++it)
94-
{
95-
nValueOut += it->nValue;
96-
if (!MoneyRange(it->nValue) || !MoneyRange(nValueOut))
97-
throw std::runtime_error("CTransaction::GetValueOut() : value out of range");
98-
}
99-
return nValueOut;
100-
}
101-
102-
double CTransaction::ComputePriority(double dPriorityInputs, unsigned int nTxSize) const
103-
{
104-
nTxSize = CalculateModifiedSize(nTxSize);
105-
if (nTxSize == 0) return 0.0;
106-
107-
return dPriorityInputs / nTxSize;
108-
}
109-
110-
unsigned int CTransaction::CalculateModifiedSize(unsigned int nTxSize) const
111-
{
112-
// In order to avoid disincentivizing cleaning up the UTXO set we don't count
113-
// the constant overhead for each txin and up to 110 bytes of scriptSig (which
114-
// is enough to cover a compressed pubkey p2sh redemption) for priority.
115-
// Providing any more cleanup incentive than making additional inputs free would
116-
// risk encouraging people to create junk outputs to redeem later.
117-
if (nTxSize == 0)
118-
nTxSize = ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION);
119-
for (std::vector<CTxIn>::const_iterator it(vin.begin()); it != vin.end(); ++it)
120-
{
121-
unsigned int offset = 41U + std::min(110U, (unsigned int)it->scriptSig.size());
122-
if (nTxSize > offset)
123-
nTxSize -= offset;
124-
}
125-
return nTxSize;
126-
}
127-
128-
std::string CTransaction::ToString() const
129-
{
130-
std::string str;
131-
str += strprintf("CTransaction(hash=%s, ver=%d, vin.size=%u, vout.size=%u, nLockTime=%u)\n",
132-
GetHash().ToString().substr(0,10),
133-
nVersion,
134-
vin.size(),
135-
vout.size(),
136-
nLockTime);
137-
for (unsigned int i = 0; i < vin.size(); i++)
138-
str += " " + vin[i].ToString() + "\n";
139-
for (unsigned int i = 0; i < vout.size(); i++)
140-
str += " " + vout[i].ToString() + "\n";
141-
return str;
142-
}
143-
14412
// Amount compression:
14513
// * If the amount is 0, output 0
14614
// * first, divide the amount (in base units) by the largest power of 10 possible; call the exponent e (e is max 9)

0 commit comments

Comments
 (0)