Skip to content

Commit 575cde4

Browse files
jonasschnelliluke-jr
authored andcommitted
[bitcoin-tx] add rbfoptin command
1 parent 5d26244 commit 575cde4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/bitcoin-tx.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static int AppInitRawTx(int argc, char* argv[])
7777
strUsage += HelpMessageOpt("in=TXID:VOUT(:SEQUENCE_NUMBER)", _("Add input to TX"));
7878
strUsage += HelpMessageOpt("locktime=N", _("Set TX lock time to N"));
7979
strUsage += HelpMessageOpt("nversion=N", _("Set TX version to N"));
80+
strUsage += HelpMessageOpt("rbfoptin(=N)", _("Set RBF opt-in sequence number for input N (if not provided, opt-in all available inputs)"));
8081
strUsage += HelpMessageOpt("outaddr=VALUE:ADDRESS", _("Add address-based output to TX"));
8182
strUsage += HelpMessageOpt("outpubkey=VALUE:PUBKEY[:FLAGS]", _("Add pay-to-pubkey output to TX") + ". " +
8283
_("Optionally add the \"W\" flag to produce a pay-to-witness-pubkey-hash output") + ". " +
@@ -202,6 +203,24 @@ static void MutateTxLocktime(CMutableTransaction& tx, const std::string& cmdVal)
202203
tx.nLockTime = (unsigned int) newLocktime;
203204
}
204205

206+
static void MutateTxRBFOptIn(CMutableTransaction& tx, const std::string& strInIdx)
207+
{
208+
// parse requested index
209+
int inIdx = atoi(strInIdx);
210+
if (inIdx < 0 || inIdx >= (int)tx.vin.size()) {
211+
throw std::runtime_error("Invalid TX input index '" + strInIdx + "'");
212+
}
213+
214+
// set the nSequence to MAX_INT - 2 (= RBF opt in flag)
215+
int cnt = 0;
216+
for (CTxIn& txin : tx.vin) {
217+
if (strInIdx == "" || cnt == inIdx) {
218+
txin.nSequence = std::numeric_limits<unsigned int>::max() - 2;
219+
}
220+
++cnt;
221+
}
222+
}
223+
205224
static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInput)
206225
{
207226
std::vector<std::string> vStrInputParts;
@@ -649,6 +668,9 @@ static void MutateTx(CMutableTransaction& tx, const std::string& command,
649668
MutateTxVersion(tx, commandVal);
650669
else if (command == "locktime")
651670
MutateTxLocktime(tx, commandVal);
671+
else if (command == "rbfoptin") {
672+
MutateTxRBFOptIn(tx, commandVal);
673+
}
652674

653675
else if (command == "delin")
654676
MutateTxDelInput(tx, commandVal);

0 commit comments

Comments
 (0)