diff options
author | Jonas Schnelli <dev@jonasschnelli.ch> | 2015-12-03 16:42:01 +0100 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2017-06-05 23:13:24 +0000 |
commit | 575cde4605c9a321ad591dbb7d632dd0ef946d40 (patch) | |
tree | 6bdbdc65495ddceed61621fccfa2dbb0f7b93a71 /src | |
parent | 5d26244148b636c1b81b9eb5ab6a45f33766bd08 (diff) |
[bitcoin-tx] add rbfoptin command
Diffstat (limited to 'src')
-rw-r--r-- | src/bitcoin-tx.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index cf280f485c..87d8475942 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -77,6 +77,7 @@ static int AppInitRawTx(int argc, char* argv[]) strUsage += HelpMessageOpt("in=TXID:VOUT(:SEQUENCE_NUMBER)", _("Add input to TX")); strUsage += HelpMessageOpt("locktime=N", _("Set TX lock time to N")); strUsage += HelpMessageOpt("nversion=N", _("Set TX version to N")); + strUsage += HelpMessageOpt("rbfoptin(=N)", _("Set RBF opt-in sequence number for input N (if not provided, opt-in all available inputs)")); strUsage += HelpMessageOpt("outaddr=VALUE:ADDRESS", _("Add address-based output to TX")); strUsage += HelpMessageOpt("outpubkey=VALUE:PUBKEY[:FLAGS]", _("Add pay-to-pubkey output to TX") + ". " + _("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) tx.nLockTime = (unsigned int) newLocktime; } +static void MutateTxRBFOptIn(CMutableTransaction& tx, const std::string& strInIdx) +{ + // parse requested index + int inIdx = atoi(strInIdx); + if (inIdx < 0 || inIdx >= (int)tx.vin.size()) { + throw std::runtime_error("Invalid TX input index '" + strInIdx + "'"); + } + + // set the nSequence to MAX_INT - 2 (= RBF opt in flag) + int cnt = 0; + for (CTxIn& txin : tx.vin) { + if (strInIdx == "" || cnt == inIdx) { + txin.nSequence = std::numeric_limits<unsigned int>::max() - 2; + } + ++cnt; + } +} + static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInput) { std::vector<std::string> vStrInputParts; @@ -649,6 +668,9 @@ static void MutateTx(CMutableTransaction& tx, const std::string& command, MutateTxVersion(tx, commandVal); else if (command == "locktime") MutateTxLocktime(tx, commandVal); + else if (command == "rbfoptin") { + MutateTxRBFOptIn(tx, commandVal); + } else if (command == "delin") MutateTxDelInput(tx, commandVal); |