Skip to content

Commit e17853f

Browse files
committed
[bitcoin-tx] add rbfoptin command
1 parent cbf2d56 commit e17853f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/bitcoin-tx.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static bool AppInitRawTx(int argc, char* argv[])
7070
strUsage += HelpMessageOpt("in=TXID:VOUT(:SEQUENCE_NUMBER)", _("Add input to TX"));
7171
strUsage += HelpMessageOpt("locktime=N", _("Set TX lock time to N"));
7272
strUsage += HelpMessageOpt("nversion=N", _("Set TX version to N"));
73+
strUsage += HelpMessageOpt("rbfoptin(=N)", _("Set RBF opt-in sequence number for input N (if not provided, opt-in all available inputs)"));
7374
strUsage += HelpMessageOpt("outaddr=VALUE:ADDRESS", _("Add address-based output to TX"));
7475
strUsage += HelpMessageOpt("outdata=[VALUE:]DATA", _("Add data-based output to TX"));
7576
strUsage += HelpMessageOpt("outscript=VALUE:SCRIPT", _("Add raw script output to TX"));
@@ -175,6 +176,24 @@ static void MutateTxLocktime(CMutableTransaction& tx, const string& cmdVal)
175176
tx.nLockTime = (unsigned int) newLocktime;
176177
}
177178

179+
static void MutateTxRBFOptIn(CMutableTransaction& tx, const string& strInIdx)
180+
{
181+
// parse requested index
182+
int inIdx = atoi(strInIdx);
183+
if (inIdx < 0 || inIdx >= (int)tx.vin.size()) {
184+
string strErr = "Invalid TX input index '" + strInIdx + "'";
185+
throw runtime_error(strErr.c_str());
186+
}
187+
188+
// set the nSequence to MAX_INT - 2 (= RBF opt in flag)
189+
int cnt = 0;
190+
BOOST_FOREACH(CTxIn& txin, tx.vin) {
191+
if (strInIdx == "" || cnt == inIdx)
192+
txin.nSequence = std::numeric_limits<unsigned int>::max() - 2;
193+
cnt++;
194+
}
195+
}
196+
178197
static void MutateTxAddInput(CMutableTransaction& tx, const string& strInput)
179198
{
180199
std::vector<std::string> vStrInputParts;
@@ -502,6 +521,8 @@ static void MutateTx(CMutableTransaction& tx, const string& command,
502521
MutateTxVersion(tx, commandVal);
503522
else if (command == "locktime")
504523
MutateTxLocktime(tx, commandVal);
524+
else if (command == "rbfoptin")
525+
MutateTxRBFOptIn(tx, commandVal);
505526

506527
else if (command == "delin")
507528
MutateTxDelInput(tx, commandVal);

0 commit comments

Comments
 (0)