| 201 | } |
| 202 | |
| 203 | int ParseSighashString(const UniValue& sighash, bool enforce_forkid) |
| 204 | { |
| 205 | int hash_type = SIGHASH_ALL | SIGHASH_FORKID; |
| 206 | if (!sighash.isNull()) { |
| 207 | static std::map<std::string, int> map_sighash_values = { |
| 208 | {std::string("ALL"), int(SIGHASH_ALL)}, |
| 209 | {std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)}, |
| 210 | {std::string("ALL|FORKID"), int(SIGHASH_ALL|SIGHASH_FORKID)}, |
| 211 | {std::string("ALL|FORKID|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_FORKID|SIGHASH_ANYONECANPAY)}, |
| 212 | {std::string("NONE"), int(SIGHASH_NONE)}, |
| 213 | {std::string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY)}, |
| 214 | {std::string("NONE|FORKID"), int(SIGHASH_NONE|SIGHASH_FORKID)}, |
| 215 | {std::string("NONE|FORKID|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_FORKID|SIGHASH_ANYONECANPAY)}, |
| 216 | {std::string("SINGLE"), int(SIGHASH_SINGLE)}, |
| 217 | {std::string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)}, |
| 218 | {std::string("SINGLE|FORKID"), int(SIGHASH_SINGLE|SIGHASH_FORKID)}, |
| 219 | {std::string("SINGLE|FORKID|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_FORKID|SIGHASH_ANYONECANPAY)}, |
| 220 | }; |
| 221 | std::string strHashType = sighash.get_str(); |
| 222 | const auto& it = map_sighash_values.find(strHashType); |
| 223 | if (it != map_sighash_values.end()) { |
| 224 | hash_type = it->second; |
| 225 | } else { |
| 226 | throw std::runtime_error(strHashType + " is not a valid sighash parameter."); |
| 227 | } |
| 228 | if (enforce_forkid && !(hash_type & SIGHASH_FORKID)) { |
| 229 | throw std::runtime_error("Signature must use SIGHASH_FORKID"); |
| 230 | } |
| 231 | } |
| 232 | return hash_type; |
| 233 | } |
no test coverage detected