Skip to content

Commit 4d7b787

Browse files
committed
Merge bitcoin#29022: Make bitcoin-tx replaceable value optional
98afe78 doc: Update bitcoin-tx replaceable documentation (Kashif Smith) 94feaf2 tests: Add unit tests for bitcoin-tx replaceable command (Kashif Smith) c2b836b bitcoin-tx: Make replaceable value optional (Kashif Smith) Pull request description: This fixes bitcoin#28638. The issue was originally raised by dooglus, who also suggested the patch found in this code. Additionally, test coverage has been added and documentation has been updated. ACKs for top commit: achow101: ACK 98afe78 pinheadmz: ACK 98afe78 hernanmarino: Tested ACK 98afe78 instagibbs: untested ACK bitcoin@98afe78 Tree-SHA512: ea1384aba7b0014c8cbeb7280d66b1e617d406fb02471dff33873057132b80518c94c7caa4b0426c26d17ce8aa393107de319dde781ace8df72f0314c8c75159
2 parents e6dbf48 + 98afe78 commit 4d7b787

File tree

7 files changed

+92
-4
lines changed

7 files changed

+92
-4
lines changed

Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ EXTRA_DIST += \
310310
test/util/data/txcreatesignv1.hex \
311311
test/util/data/txcreatesignv1.json \
312312
test/util/data/txcreatesignv2.hex \
313+
test/util/data/txreplace1.hex \
314+
test/util/data/txreplacenoinputs.hex \
315+
test/util/data/txreplaceomittedn.hex \
316+
test/util/data/txreplacesingleinput.hex \
313317
test/util/rpcauth-test.py
314318

315319
CLEANFILES = $(OSX_ZIP) $(BITCOIN_WIN_INSTALLER)

src/bitcoin-tx.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ static void SetupBitcoinTxArgs(ArgsManager &argsman)
6666
argsman.AddArg("outscript=VALUE:SCRIPT[:FLAGS]", "Add raw script output to TX. "
6767
"Optionally add the \"W\" flag to produce a pay-to-witness-script-hash output. "
6868
"Optionally add the \"S\" flag to wrap the output in a pay-to-script-hash.", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
69-
argsman.AddArg("replaceable(=N)", "Set RBF opt-in sequence number for input N (if not provided, opt-in all available inputs)", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
69+
argsman.AddArg("replaceable(=N)", "Sets Replace-By-Fee (RBF) opt-in sequence number for input N. "
70+
"If N is not provided, the command attempts to opt-in all available inputs for RBF. "
71+
"If the transaction has no inputs, this option is ignored.", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
7072
argsman.AddArg("sign=SIGHASH-FLAGS", "Add zero or more signatures to transaction. "
7173
"This command requires JSON registers:"
7274
"prevtxs=JSON object, "
@@ -223,8 +225,8 @@ static void MutateTxLocktime(CMutableTransaction& tx, const std::string& cmdVal)
223225
static void MutateTxRBFOptIn(CMutableTransaction& tx, const std::string& strInIdx)
224226
{
225227
// parse requested index
226-
int64_t inIdx;
227-
if (!ParseInt64(strInIdx, &inIdx) || inIdx < 0 || inIdx >= static_cast<int64_t>(tx.vin.size())) {
228+
int64_t inIdx = -1;
229+
if (strInIdx != "" && (!ParseInt64(strInIdx, &inIdx) || inIdx < 0 || inIdx >= static_cast<int64_t>(tx.vin.size()))) {
228230
throw std::runtime_error("Invalid TX input index '" + strInIdx + "'");
229231
}
230232

test/util/data/bitcoin-util-test.json

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,85 @@
163163
"replaceable=0foo"],
164164
"return_code": 1,
165165
"error_txt": "error: Invalid TX input index",
166-
"description": "Tests the check for an invalid input index with replaceable"
166+
"description": "Tests the check for an invalid string input index with replaceable"
167+
},
168+
{
169+
"exec": "./bitcoin-tx",
170+
"args":
171+
["-create",
172+
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
173+
"replaceable=-1"],
174+
"return_code": 1,
175+
"error_txt": "error: Invalid TX input index",
176+
"description": "Tests the check for an invalid negative input index with replaceable"
177+
},
178+
{
179+
"exec": "./bitcoin-tx",
180+
"args":
181+
["-create",
182+
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
183+
"replaceable=1"],
184+
"return_code": 1,
185+
"error_txt": "error: Invalid TX input index",
186+
"description": "Tests the check for an invalid positive out-of-bounds input index with replaceable"
187+
},
188+
{
189+
"exec": "./bitcoin-tx",
190+
"args":
191+
["-create",
192+
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
193+
"replaceable=0"],
194+
"output_cmp": "txreplacesingleinput.hex",
195+
"description": "Tests that the 'SEQUENCE' value for a single input is set to fdffffff for single input"
196+
},
197+
{
198+
"exec": "./bitcoin-tx",
199+
"args":
200+
["-create",
201+
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
202+
"replaceable="],
203+
"output_cmp": "txreplacesingleinput.hex",
204+
"description": "Tests that the 'SEQUENCE' value for a single input is set to fdffffff when N omitted"
205+
},
206+
{
207+
"exec": "./bitcoin-tx",
208+
"args":
209+
["-create",
210+
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
211+
"in=bf829c6bcf84579331337659d31f89dfd138f7f7785802d5501c92333145ca7c:18",
212+
"in=22a6f904655d53ae2ff70e701a0bbd90aa3975c0f40bfc6cc996a9049e31cdfc:1",
213+
"replaceable=1"],
214+
"output_cmp": "txreplace1.hex",
215+
"description": "Tests that only the 'SEQUENCE' value of input[1] is set to fdffffff"
216+
},
217+
{
218+
"exec": "./bitcoin-tx",
219+
"args":
220+
["-create",
221+
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
222+
"in=bf829c6bcf84579331337659d31f89dfd138f7f7785802d5501c92333145ca7c:18",
223+
"in=22a6f904655d53ae2ff70e701a0bbd90aa3975c0f40bfc6cc996a9049e31cdfc:1",
224+
"replaceable="],
225+
"output_cmp": "txreplaceomittedn.hex",
226+
"description": "Tests that the 'SEQUENCE' value for each input is set to fdffffff when N omitted"
227+
},
228+
{
229+
"exec": "./bitcoin-tx",
230+
"args":
231+
["-create",
232+
"replaceable="],
233+
"output_cmp": "txreplacenoinputs.hex",
234+
"description": "Tests behavior when no inputs are provided in the transaction"
235+
},
236+
{
237+
"exec": "./bitcoin-tx",
238+
"args":
239+
["-create",
240+
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0:abcdef00",
241+
"replaceable="],
242+
"return_code": 1,
243+
"error_txt": "error: invalid TX sequence id 'abcdef00'",
244+
"description": "Try to make invalid input replaceable"
167245
},
168246
{ "exec": "./bitcoin-tx",
169247
"args":

test/util/data/txreplace1.hex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
02000000031f5c38dfcf6f1a5f5a87c416076d392c87e6d41970d5ad5e477a02d66bde97580000000000ffffffff7cca453133921c50d5025878f7f738d1df891fd359763331935784cf6b9c82bf1200000000fdfffffffccd319e04a996c96cfc0bf4c07539aa90bd0b1a700ef72fae535d6504f9a6220100000000ffffffff0000000000

test/util/data/txreplacenoinputs.hex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
02000000000000000000

test/util/data/txreplaceomittedn.hex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
02000000031f5c38dfcf6f1a5f5a87c416076d392c87e6d41970d5ad5e477a02d66bde97580000000000fdffffff7cca453133921c50d5025878f7f738d1df891fd359763331935784cf6b9c82bf1200000000fdfffffffccd319e04a996c96cfc0bf4c07539aa90bd0b1a700ef72fae535d6504f9a6220100000000fdffffff0000000000
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
02000000011f5c38dfcf6f1a5f5a87c416076d392c87e6d41970d5ad5e477a02d66bde97580000000000fdffffff0000000000

0 commit comments

Comments
 (0)