Suggested in #10481 (comment), this adds the option to explicitly choose whether a serialized transaction should be decoded as a witness or non-witness transaction rather than relying on the heuristic checks in #10481. The parameter defaults to relying on #10481 if not included, but it overrides that if included.
Add iswitness parameter to decode- and fundrawtransaction RPCs #11178
pull meshcollider wants to merge 2 commits into bitcoin:master from meshcollider:201708_rawtx_bool changing 7 files +56 −29-
meshcollider commented at 11:00 AM on August 28, 2017: contributor
- fanquake added the label RPC/REST/ZMQ on Aug 28, 2017
- meshcollider renamed this:
Add iswitness parameter to decode- and fundrawtransaction RPCs
[WIP] Add iswitness parameter to decode- and fundrawtransaction RPCs
on Aug 28, 2017 - meshcollider renamed this:
[WIP] Add iswitness parameter to decode- and fundrawtransaction RPCs
Add iswitness parameter to decode- and fundrawtransaction RPCs
on Aug 28, 2017 -
meshcollider commented at 12:21 PM on August 28, 2017: contributor
@achow101 @roconnor-blockstream you might want to take a look at this :)
-
in src/core_read.cpp:111 in 55e2b9c8a1 outdated
107 | @@ -108,7 +108,7 @@ bool CheckTxScriptsSanity(const CMutableTransaction& tx) 108 | return true; 109 | } 110 | 111 | -bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx, bool fTryNoWitness) 112 | +bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx, bool fTryNoWitness, bool fTryWitness)
achow101 commented at 3:35 PM on August 30, 2017:snake_caseachow101 commented at 3:41 PM on August 30, 2017: memberutACK 55e2b9c8a13b5f80d03936f4275cd9e3828e4b3f
meshcollider commented at 9:47 PM on August 31, 2017: contributorChanged style as requested, thanks @achow101
luke-jr commented at 7:10 AM on September 2, 2017: memberPlease don't change the style of existing code, only the new code... :/
meshcollider commented at 12:19 PM on September 2, 2017: contributor@luke-jr the style refactor only touches a tiny amount of code inside that single function, in a similar way to adding braces to existing if-statements when modifying nearby code. I'd argue that this small change to existing code style is worth it for the consistency, especially between try_witness and try_no_witness
promag commented at 1:57 PM on September 2, 2017: memberMissing tests.
in src/core_read.cpp:149 in 162763903d outdated
157 | - catch (const std::exception&) { 158 | - return false; 159 | - } 160 | - 161 | + 162 | return true;
sipa commented at 8:37 PM on September 3, 2017:If you move this
return true;inside theif (try_witness)block, theif(!try_witness)inside thecatchabove becomes unnecessary. I think that'd be a cleaner flow.
meshcollider commented at 10:33 PM on September 3, 2017:Good idea yep, done
in src/rpc/rawtransaction.cpp:428 in 162763903d outdated
425 | + "decoderawtransaction \"hexstring\" ( iswitness )\n" 426 | "\nReturn a JSON object representing the serialized, hex-encoded transaction.\n" 427 | 428 | "\nArguments:\n" 429 | "1. \"hexstring\" (string, required) The transaction hex string\n" 430 | + "2. iswitness (boolean, optional) Whether the transaction hex is a serialized witness transaction \n"
sipa commented at 8:39 PM on September 3, 2017:Nit: trailing space
meshcollider commented at 10:33 PM on September 3, 2017:Fixed
in src/core_read.cpp:140 in b0bd002c21 outdated
139 | + ssData >> tx; 140 | + if (!ssData.empty()) { 141 | + return false; 142 | + } 143 | + } 144 | + catch (const std::exception&) {
sipa commented at 10:35 PM on September 3, 2017:Nit:
catchon the same line as}.in src/core_read.cpp:137 in b0bd002c21 outdated
136 | + if (try_witness) { 137 | + CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION); 138 | + try { 139 | + ssData >> tx; 140 | + if (!ssData.empty()) { 141 | + return false;
sipa commented at 10:35 PM on September 3, 2017:Even shorter: invert this test and make it return true.
meshcollider commented at 10:45 PM on September 3, 2017:Nice :+1:
in src/core_read.cpp:139 in 946ba02507 outdated
145 | + ssData >> tx; 146 | + if (ssData.empty()) { 147 | + return true; 148 | + } 149 | + } catch (const std::exception&) { 150 | return false;
sipa commented at 10:50 PM on September 3, 2017:And now this line is unnecessary as well :)
meshcollider commented at 10:54 PM on September 3, 2017:Heh, changed. Next you'll want me to move the try-catch outside the if statements so there only needs to be one of them ;) Thanks for reviewing!
sipa commented at 11:06 PM on September 3, 2017:Nope, that wouldn't actually work. If both flags were true, and the first attempt to deserialize throws, you still want to try the second.
in src/core_read.cpp:123 in ffa5949533 outdated
123 | + if (try_no_witness) { 124 | CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS); 125 | try { 126 | ssData >> tx; 127 | - if (ssData.eof() && CheckTxScriptsSanity(tx)) { 128 | + if (ssData.eof() && (CheckTxScriptsSanity(tx) || !try_witness)) {
sipa commented at 11:58 PM on September 3, 2017:One final tiny nit: swap the arguments, as checking a boolean is much faster than CheckTxScriptsSanity.
sipa commented at 7:16 PM on September 4, 2017: memberutACK 3d16658226cd08911200dbd90db762dc3409e443
Add iswitness parameter to decode- and fundrawtransaction RPCs bbdbe805a2Add test for decoderawtransaction bool 6f39ac0437meshcollider commented at 11:25 PM on September 5, 2017: contributorRebased
ryanofsky commented at 3:33 PM on December 18, 2017: memberutACK 6f39ac04375a5f6ef803da59ba0b606123d63142
Probably could merge given 3 acks.
laanwj commented at 8:54 AM on December 19, 2017: memberutACK 6f39ac04375a5f6ef803da59ba0b606123d63142
laanwj merged this on Dec 19, 2017laanwj closed this on Dec 19, 2017laanwj referenced this in commit fee0370fd6 on Dec 19, 2017laanwj referenced this in commit 4508519250 on Dec 19, 2017MarcoFalke referenced this in commit 797441ee99 on Dec 19, 2017hkjn referenced this in commit aa6b20f8e3 on Jan 13, 2018HashUnlimited referenced this in commit 7d3ad221e2 on Mar 15, 2018meshcollider deleted the branch on Oct 15, 2018DrahtBot locked this on Sep 8, 2021
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:15 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me