Skip to content

Commit ad44c79

Browse files
committed
RBF is not disabled by default anymore
But it's not enabled by default either: the developer is forced to make a decision if he wants to avoid the compile-time warnings. This way we avoid the potential problems that could have been caused by simply switching the default to be RFB-enabled, as discussed originally here: #355
1 parent e5628f2 commit ad44c79

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

NBitcoin.Tests/transaction_tests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public void CanOptInRBF()
335335
builder.Send(new Key().ScriptPubKey, Money.Coins(1));
336336
builder.SendFees(Money.Coins(0.001m));
337337
builder.SetChange(address);
338-
builder.OptInRBF = true;
338+
builder.RBF = true;
339339
var tx = builder.BuildTransaction(false);
340340
Assert.True(tx.RBF);
341341
foreach(var inp in tx.Inputs)
@@ -349,7 +349,7 @@ public void CanOptInRBF()
349349
builder.Send(new Key().ScriptPubKey, Money.Coins(1));
350350
builder.SendFees(Money.Coins(0.001m));
351351
builder.SetChange(address);
352-
builder.OptInRBF = true;
352+
builder.RBF = true;
353353
builder.SetLockTime(1230944461);
354354
tx = builder.BuildTransaction(false);
355355
Assert.True(tx.RBF);

NBitcoin/ConsensusFactory.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,32 @@ public virtual TxOut CreateTxOut()
120120
#pragma warning restore CS0618 // Type or member is obsolete
121121
}
122122

123+
protected virtual TransactionBuilder CreateTransactionBuilderCore(bool RBF)
124+
{
125+
return new TransactionBuilder(RBF);
126+
}
127+
128+
[Obsolete("Use CreateTransactionBuilder(bool RBF)")]
123129
protected virtual TransactionBuilder CreateTransactionBuilderCore()
124130
{
125131
#pragma warning disable CS0618 // Type or member is obsolete
126132
return new TransactionBuilder();
127133
#pragma warning restore CS0618 // Type or member is obsolete
128134
}
129135

136+
/// <summary>
137+
/// Creates the transaction builder.
138+
/// </summary>
139+
/// <returns>The transaction builder.</returns>
140+
/// <param name="RBF">If set to <c>true</c>, replace-by-fee will be enabled (recommended, unless you need to keep backwards compatibility with previous transactions built with previous NBitcoin versions, i.e. older than 4.1.2.8).</param>
141+
public TransactionBuilder CreateTransactionBuilder(bool RBF)
142+
{
143+
var builder = CreateTransactionBuilderCore(RBF);
144+
builder.SetConsensusFactory(this);
145+
return builder;
146+
}
147+
148+
[Obsolete("Use CreateTransactionBuilder(bool RBF)")]
130149
public TransactionBuilder CreateTransactionBuilder()
131150
{
132151
#pragma warning disable CS0618 // Type or member is obsolete

NBitcoin/Network.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,7 +2513,18 @@ internal NetworkStringParser NetworkStringParser
25132513
get;
25142514
set;
25152515
} = new NetworkStringParser();
2516+
2517+
/// <summary>
2518+
/// Creates the transaction builder for this network.
2519+
/// </summary>
2520+
/// <returns>The transaction builder.</returns>
2521+
/// <param name="RBF">If set to <c>true</c>, replace-by-fee will be enabled (recommended, unless you need to keep backwards compatibility with previous transactions built with previous NBitcoin versions, i.e. older than 4.1.2.8).</param>
2522+
public TransactionBuilder CreateTransactionBuilder(bool RBF)
2523+
{
2524+
return consensus.ConsensusFactory.CreateTransactionBuilder(RBF);
2525+
}
25162526

2527+
[Obsolete("Use CreateTransactionBuilder(bool RBF)")]
25172528
public TransactionBuilder CreateTransactionBuilder()
25182529
{
25192530
return consensus.ConsensusFactory.CreateTransactionBuilder();

NBitcoin/TransactionBuilder.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -555,17 +555,22 @@ internal BuilderGroup CurrentGroup
555555
return _CurrentGroup;
556556
}
557557
}
558-
[Obsolete("Use Network.CreateTransactionBuilder() or ConsensusFactory.CreateTransactionBuilder() instead")]
559-
public TransactionBuilder()
558+
559+
internal TransactionBuilder(bool RBF)
560560
{
561561
ShuffleRandom = new Random();
562562
CoinSelector = new DefaultCoinSelector(ShuffleRandom);
563563
StandardTransactionPolicy = new StandardTransactionPolicy();
564564
DustPrevention = true;
565-
OptInRBF = false;
565+
this.RBF = RBF;
566566
InitExtensions();
567567
}
568568

569+
[Obsolete("Use Network.CreateTransactionBuilder() or ConsensusFactory.CreateTransactionBuilder() instead")]
570+
public TransactionBuilder() : this(false)
571+
{
572+
}
573+
569574
private void InitExtensions()
570575
{
571576
Extensions.Add(new P2PKHBuilderExtension());
@@ -602,17 +607,17 @@ public bool DustPrevention
602607
{
603608
get;
604609
set;
605-
}
606-
610+
}
611+
607612
/// <summary>
608-
/// If true, it will signal the transaction replaceability in every input. (Default: false)
613+
/// If true, it will signal the transaction replaceability in every input.
609614
/// </summary>
610-
public bool OptInRBF
615+
public bool RBF
611616
{
612617
get;
613618
set;
614-
}
615-
619+
}
620+
616621
/// <summary>
617622
/// If true and the transaction has two outputs sending to the same scriptPubKey, those will be merged into a single output. (Default: true)
618623
/// </summary>
@@ -1424,7 +1429,7 @@ private IEnumerable<ICoin> BuildTransaction(
14241429
if(input == null)
14251430
input = ctx.Transaction.Inputs.Add(coin.Outpoint);
14261431

1427-
if(OptInRBF)
1432+
if(RBF)
14281433
{
14291434
input.Sequence = Sequence.OptInRBF;
14301435
ctx.NonFinalSequenceSet = true;

0 commit comments

Comments
 (0)