scripted-diff: TxoutType C++11 scoped enum class #19114

pull MarcoFalke wants to merge 4 commits into bitcoin:master from MarcoFalke:2005-enumClassTxoutType changing 18 files +211 −212
  1. MarcoFalke commented at 2:36 pm on May 30, 2020: member

    Non-scoped enums can accidentally and silently decay into an integral type. Also, the symbol names of the keys are exported to the surrounding (usually global) namespace.

    Fix both issues by switching to an enum class TxoutType in a (mostly) scripted-diff.

  2. practicalswift commented at 2:48 pm on May 30, 2020: contributor

    Concept ACK: Prefer class enums over “plain” enums (C++ Core Guidelines)

    These are the remaining non-class enums that might be worth investigating too:

    0$ git grep '^enum [^c][^l][^(]*$' -- "*.h" "*.cpp" ":(exclude)src/univalue/" 
    1      ":(exclude)src/leveldb/" | cut -f2 -d' ' | cut -f1 -d: | sort -u | tr "\n" " "
    2BindFlags ChangeType DeploymentPos DisconnectResult GetDataMsg HTTPStatusCode
    3isminetype NetPermissionFlags Network NumConnections opcodetype RPCErrorCode SafeChars
    4ServiceFlags SOCKS5Atyp SOCKS5Command SOCKS5Method SOCKS5Reply SOCKSVersion txnouttype
    5WalletFeature WalletFlags
    
  3. DrahtBot added the label Refactoring on May 30, 2020
  4. DrahtBot added the label RPC/REST/ZMQ on May 30, 2020
  5. DrahtBot added the label Tests on May 30, 2020
  6. DrahtBot added the label TX fees and policy on May 30, 2020
  7. DrahtBot added the label Wallet on May 30, 2020
  8. hebasto commented at 3:09 pm on May 30, 2020: member
    Concept ACK. Also: #17877
  9. in src/script/standard.h:39 in fa38a7472a outdated
    35@@ -36,11 +36,11 @@ static const unsigned int MAX_OP_RETURN_RELAY = 83;
    36 
    37 /**
    38  * A data carrying output is an unspendable output containing data. The script
    39- * type is designated as TX_NULL_DATA.
    40+ * type is designated as NULL_DATA.
    


    hebasto commented at 3:27 pm on May 30, 2020:

    nit:

    0 * type is designated as TxoutType::NULL_DATA.
    

    MarcoFalke commented at 3:54 pm on May 30, 2020:
    I think in comments we don’t need to be overly verbose. Especially not in the file that defines these values. I think the comment is clearer as is.
  10. in src/script/standard.h:43 in fa38a7472a outdated
    40+ * type is designated as NULL_DATA.
    41  */
    42 extern bool fAcceptDatacarrier;
    43 
    44-/** Maximum size of TX_NULL_DATA scripts that this node considers standard. */
    45+/** Maximum size of NULL_DATA scripts that this node considers standard. */
    


    hebasto commented at 3:27 pm on May 30, 2020:

    nit:

    0/** Maximum size of TxoutType::NULL_DATA scripts that this node considers standard. */
    

    MarcoFalke commented at 3:55 pm on May 30, 2020:
    I think in comments we don’t need to be overly verbose. Especially not in the file that defines these values. I think the comment is clearer as is.
  11. MarcoFalke removed the label RPC/REST/ZMQ on May 30, 2020
  12. MarcoFalke removed the label TX fees and policy on May 30, 2020
  13. MarcoFalke removed the label Tests on May 30, 2020
  14. MarcoFalke removed the label Wallet on May 30, 2020
  15. in src/script/standard.h:159 in fa38a7472a outdated
    155@@ -157,9 +156,9 @@ std::string GetTxnOutputType(txnouttype t);
    156  *
    157  * @param[in]   scriptPubKey   Script to parse
    158  * @param[out]  vSolutionsRet  Vector of parsed pubkeys and hashes
    159- * @return                     The script type. TX_NONSTANDARD represents a failed solve.
    160+ * @return                     The script type. NONSTANDARD represents a failed solve.
    


    hebasto commented at 3:32 pm on May 30, 2020:

    nit:

    0 * [@return](/bitcoin-bitcoin/contributor/return/)                     The script type. TxoutType::NONSTANDARD represents a failed solve.
    

    MarcoFalke commented at 3:55 pm on May 30, 2020:
    I think in comments we don’t need to be overly verbose. Especially not in the file that defines these values and where the return type is mentioned one line below the comment. I think the comment is clearer as is.
  16. MarcoFalke commented at 3:34 pm on May 30, 2020: member
    @practicalswift It might be best to open a new brainstorming issue for discussion about those. I think enum flags can not (or should not?) be switched to enum class.
  17. in src/script/standard.cpp:44 in fa38a7472a outdated
    49+    case TxoutType::NULL_DATA: return "nulldata";
    50+    case TxoutType::WITNESS_V0_KEYHASH: return "witness_v0_keyhash";
    51+    case TxoutType::WITNESS_V0_SCRIPTHASH: return "witness_v0_scripthash";
    52+    case TxoutType::WITNESS_UNKNOWN: return "witness_unknown";
    53+        // no default case, so the compiler can warn about missing cases
    54     }
    


    hebasto commented at 3:34 pm on May 30, 2020:

    nit:

    0    } // no default case, so the compiler can warn about missing cases
    

    as described in Developer Notes


    MarcoFalke commented at 4:02 pm on May 30, 2020:
    Thanks. Done
  18. hebasto commented at 3:39 pm on May 30, 2020: member

    ACK fa38a7472ab475806cf50f302db9c69dfb8ac0f5, tested on Linux Mint 19.3 (x86_64).

    fa868d3a8de56582538a3e4ef8de6082f2b8c747: maybe make a separate utility function to derive an underlying type of an enumerator?

  19. MarcoFalke force-pushed on May 30, 2020
  20. MarcoFalke force-pushed on May 30, 2020
  21. hebasto approved
  22. hebasto commented at 4:16 pm on May 30, 2020: member
    ACK fa5997bd6fc82e16b597ea96e3c5c665f1f174ab, since fa38a7472ab475806cf50f302db9c69dfb8ac0f5 suggested changes applied.
  23. DrahtBot commented at 9:38 pm on May 30, 2020: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #19326 (Simplify hash.h interface using Spans by sipa)
    • #15294 ([moveonly] wallet: Extract RipeMd160 by Empact)
    • #13525 (policy: Report reason inputs are nonstandard from AreInputsStandard by Empact)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  24. DrahtBot added the label Needs rebase on Jun 21, 2020
  25. rpc: Simplify GetAllOutputTypes with the Join helper
    This commit does not change behavior
    fa41c65702
  26. rpc: Properly use underlying type in GetAllOutputTypes
    Don't blindly assume it is int.
    
    In practice this is usually `unsigned` or `int`, so this commit should
    not change behavior.
    fa58469c77
  27. doc: Update outdated txnouttype documentation
    Also, remove scope of txnouttype in fuzz tests temporarily. The next
    commit will add scopes to all txnouttype.
    fa95a694c4
  28. scripted-diff: TxoutType C++11 scoped enum class
    -BEGIN VERIFY SCRIPT-
     # General rename helper: $1 -> $2
     rename_global() { sed -i "s/\<$1\>/$2/g" $(git grep -l "$1"); }
    
     # Helper to rename TxoutType $1
     rename_value() {
       sed -i "s/    TX_$1,/    $1,/g" src/script/standard.h;  # First strip the prefix in the definition (header)
       rename_global TX_$1 "TxoutType::$1";                    # Then replace globally
     }
    
     # Change the type globally to bring it in line with the style-guide
     # (clsses are UpperCamelCase)
     rename_global 'enum txnouttype' 'enum class TxoutType'
     rename_global      'txnouttype'            'TxoutType'
    
     # Now rename each enum value
     rename_value 'NONSTANDARD'
     rename_value 'PUBKEY'
     rename_value 'PUBKEYHASH'
     rename_value 'SCRIPTHASH'
     rename_value 'MULTISIG'
     rename_value 'NULL_DATA'
     rename_value 'WITNESS_V0_KEYHASH'
     rename_value 'WITNESS_V0_SCRIPTHASH'
     rename_value 'WITNESS_UNKNOWN'
    
    -END VERIFY SCRIPT-
    fa32adf9dc
  29. MarcoFalke force-pushed on Jun 21, 2020
  30. MarcoFalke commented at 10:45 am on June 21, 2020: member

    Rebased due to merge conflict in adjacent line. Can be trivially re-ACKed with git range-diff

  31. DrahtBot removed the label Needs rebase on Jun 21, 2020
  32. practicalswift commented at 9:18 pm on June 21, 2020: contributor
    ACK fa32adf9dc25540ad27f5b82654c7057d7738627 – patch looks correct
  33. hebasto approved
  34. hebasto commented at 8:54 am on June 22, 2020: member
    re-ACK fa32adf9dc25540ad27f5b82654c7057d7738627, since fa5997bd6fc82e16b597ea96e3c5c665f1f174ab (https://github.com/bitcoin/bitcoin/pull/19114#pullrequestreview-421425198) rebased only (verified with git range-diff).
  35. hebasto commented at 8:59 am on June 22, 2020: member
    @MarcoFalke from which key-server I could receive your non-expired key to verify commit signatures?
  36. MarcoFalke commented at 12:24 pm on June 28, 2020: member
  37. hebasto commented at 12:59 pm on June 28, 2020: member

    @MarcoFalke

    @hebasto See #18385

    Thanks. It was helpful!

  38. MarcoFalke merged this on Jun 28, 2020
  39. MarcoFalke closed this on Jun 28, 2020

  40. MarcoFalke deleted the branch on Jun 28, 2020
  41. Fabcien referenced this in commit 97c446e3bf on Feb 2, 2021
  42. DrahtBot locked this on Feb 15, 2022

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: 2024-12-18 21:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me