Changeset View
Changeset View
Standalone View
Standalone View
src/primitives/transaction.cpp
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | for (std::vector<CTxIn>::const_iterator it(vin.begin()); it != vin.end(); | ||||
++it) { | ++it) { | ||||
unsigned int offset = | unsigned int offset = | ||||
41U + std::min(110U, (unsigned int)it->scriptSig.size()); | 41U + std::min(110U, (unsigned int)it->scriptSig.size()); | ||||
if (nTxSize > offset) nTxSize -= offset; | if (nTxSize > offset) nTxSize -= offset; | ||||
} | } | ||||
return nTxSize; | return nTxSize; | ||||
} | } | ||||
size_t CTransaction::GetBillableSize() const { | |||||
size_t nTxSize = GetTotalSize(), inputs = vin.size(), outputs = vout.size(); | |||||
// 179 bytes is the minimum size it would take to spend any outputs which | |||||
// are created. We want to change in advance of spending them to | |||||
// incentivize keeping your UTXO set reasonbly sized. | |||||
int64_t modSize = | |||||
int64_t(nTxSize) + (int64_t(outputs) - int64_t(inputs)) * 179; | |||||
// Note: It is impossible to generate a negative number above in any real | |||||
// world situation. This is because the inputs have a least 179 byte | |||||
// each. However, it is possible to have shorter scriptSigs than 179 | |||||
// bytes. Therefore, we include a minimum of 10 bytes + 34 * vouts. | |||||
nTxSize = std::max(int64_t(outputs * 34 + 10), modSize); | |||||
return nTxSize; | |||||
} | |||||
unsigned int CTransaction::GetTotalSize() const { | unsigned int CTransaction::GetTotalSize() const { | ||||
return ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION); | return ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION); | ||||
} | } | ||||
std::string CTransaction::ToString() const { | std::string CTransaction::ToString() const { | ||||
std::string str; | std::string str; | ||||
str += strprintf("CTransaction(txid=%s, ver=%d, vin.size=%u, vout.size=%u, " | str += strprintf("CTransaction(txid=%s, ver=%d, vin.size=%u, vout.size=%u, " | ||||
"nLockTime=%u)\n", | "nLockTime=%u)\n", | ||||
GetId().ToString().substr(0, 10), nVersion, vin.size(), | GetId().ToString().substr(0, 10), nVersion, vin.size(), | ||||
vout.size(), nLockTime); | vout.size(), nLockTime); | ||||
for (unsigned int i = 0; i < vin.size(); i++) | for (unsigned int i = 0; i < vin.size(); i++) | ||||
str += " " + vin[i].ToString() + "\n"; | str += " " + vin[i].ToString() + "\n"; | ||||
for (unsigned int i = 0; i < vout.size(); i++) | for (unsigned int i = 0; i < vout.size(); i++) | ||||
str += " " + vout[i].ToString() + "\n"; | str += " " + vout[i].ToString() + "\n"; | ||||
return str; | return str; | ||||
} | } |