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
  1. meshcollider commented at 11:00 AM on August 28, 2017: contributor

    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.

  2. fanquake added the label RPC/REST/ZMQ on Aug 28, 2017
  3. meshcollider renamed this:
    Add iswitness parameter to decode- and fundrawtransaction RPCs
    [WIP] Add iswitness parameter to decode- and fundrawtransaction RPCs
    on Aug 28, 2017
  4. meshcollider renamed this:
    [WIP] Add iswitness parameter to decode- and fundrawtransaction RPCs
    Add iswitness parameter to decode- and fundrawtransaction RPCs
    on Aug 28, 2017
  5. meshcollider commented at 12:21 PM on August 28, 2017: contributor

    @achow101 @roconnor-blockstream you might want to take a look at this :)

  6. 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_case

  7. achow101 commented at 3:41 PM on August 30, 2017: member

    utACK 55e2b9c8a13b5f80d03936f4275cd9e3828e4b3f

  8. meshcollider commented at 9:47 PM on August 31, 2017: contributor

    Changed style as requested, thanks @achow101

  9. luke-jr commented at 7:10 AM on September 2, 2017: member

    Please don't change the style of existing code, only the new code... :/

  10. 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

  11. promag commented at 1:57 PM on September 2, 2017: member

    Missing tests.

  12. 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 the if (try_witness) block, the if(!try_witness) inside the catch above becomes unnecessary. I think that'd be a cleaner flow.


    meshcollider commented at 10:33 PM on September 3, 2017:

    Good idea yep, done

  13. 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

  14. 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: catch on the same line as }.

  15. 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:

  16. 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.

  17. 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.

  18. sipa commented at 7:16 PM on September 4, 2017: member

    utACK 3d16658226cd08911200dbd90db762dc3409e443

  19. Add iswitness parameter to decode- and fundrawtransaction RPCs bbdbe805a2
  20. Add test for decoderawtransaction bool 6f39ac0437
  21. meshcollider commented at 11:25 PM on September 5, 2017: contributor

    Rebased

  22. ryanofsky commented at 3:33 PM on December 18, 2017: member

    utACK 6f39ac04375a5f6ef803da59ba0b606123d63142

    Probably could merge given 3 acks.

  23. laanwj commented at 8:54 AM on December 19, 2017: member

    utACK 6f39ac04375a5f6ef803da59ba0b606123d63142

  24. laanwj merged this on Dec 19, 2017
  25. laanwj closed this on Dec 19, 2017

  26. laanwj referenced this in commit fee0370fd6 on Dec 19, 2017
  27. laanwj referenced this in commit 4508519250 on Dec 19, 2017
  28. MarcoFalke referenced this in commit 797441ee99 on Dec 19, 2017
  29. hkjn referenced this in commit aa6b20f8e3 on Jan 13, 2018
  30. HashUnlimited referenced this in commit 7d3ad221e2 on Mar 15, 2018
  31. meshcollider deleted the branch on Oct 15, 2018
  32. DrahtBot 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