aboutsummaryrefslogtreecommitdiff
path: root/src/primitives/transaction.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2016-01-03 18:54:50 +0100
committerPieter Wuille <pieter.wuille@gmail.com>2016-06-22 15:43:00 +0200
commit2b1f6f9ccf36f1e0a2c9d99154e1642f796d7c2b (patch)
tree30b17fa55ea6c9ae0055c0c16d2e271a0c799d16 /src/primitives/transaction.h
parent7c4bf779e8b74e474551982a24f5acc265293abd (diff)
downloadbitcoin-2b1f6f9ccf36f1e0a2c9d99154e1642f796d7c2b.tar.xz
BIP141: Other consensus critical limits, and BIP145
Includes changes by Suhas Daftuar, Luke-jr, and mruddy.
Diffstat (limited to 'src/primitives/transaction.h')
-rw-r--r--src/primitives/transaction.h28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h
index 5a58241347..e87ad90f0d 100644
--- a/src/primitives/transaction.h
+++ b/src/primitives/transaction.h
@@ -13,6 +13,8 @@
static const int SERIALIZE_TRANSACTION_NO_WITNESS = 0x40000000;
+static const int WITNESS_SCALE_FACTOR = 4;
+
/** An outpoint - a combination of a transaction hash and an index n into its vout */
class COutPoint
{
@@ -166,15 +168,30 @@ public:
// which has units satoshis-per-kilobyte.
// If you'd pay more than 1/3 in fees
// to spend something, then we consider it dust.
- // A typical spendable txout is 34 bytes big, and will
+ // A typical spendable non-segwit txout is 34 bytes big, and will
// need a CTxIn of at least 148 bytes to spend:
// so dust is a spendable txout less than
- // 546*minRelayTxFee/1000 (in satoshis)
+ // 546*minRelayTxFee/1000 (in satoshis).
+ // A typical spendable segwit txout is 31 bytes big, and will
+ // need a CTxIn of at least 67 bytes to spend:
+ // so dust is a spendable txout less than
+ // 294*minRelayTxFee/1000 (in satoshis).
if (scriptPubKey.IsUnspendable())
return 0;
- size_t nSize = GetSerializeSize(SER_DISK,0)+148u;
- return 3*minRelayTxFee.GetFee(nSize);
+ size_t nSize = GetSerializeSize(SER_DISK, 0);
+ int witnessversion = 0;
+ std::vector<unsigned char> witnessprogram;
+
+ if (scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram)) {
+ // sum the sizes of the parts of a transaction input
+ // with 75% segwit discount applied to the script size.
+ nSize += (32 + 4 + 1 + (107 / WITNESS_SCALE_FACTOR) + 4);
+ } else {
+ nSize += (32 + 4 + 1 + 107 + 4); // the 148 mentioned above
+ }
+
+ return 3 * minRelayTxFee.GetFee(nSize);
}
bool IsDust(const CFeeRate &minRelayTxFee) const
@@ -442,4 +459,7 @@ struct CMutableTransaction
uint256 GetHash() const;
};
+/** Compute the cost of a transaction, as defined by BIP 141 */
+int64_t GetTransactionCost(const CTransaction &tx);
+
#endif // BITCOIN_PRIMITIVES_TRANSACTION_H