| 257 | } |
| 258 | |
| 259 | int ParseSighashString(const UniValue& sighash) |
| 260 | { |
| 261 | int hash_type = SIGHASH_DEFAULT; |
| 262 | if (!sighash.isNull()) { |
| 263 | static std::map<std::string, int> map_sighash_values = { |
| 264 | {std::string("DEFAULT"), int(SIGHASH_DEFAULT)}, |
| 265 | {std::string("ALL"), int(SIGHASH_ALL)}, |
| 266 | {std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)}, |
| 267 | {std::string("ALL|RANGEPROOF"), int(SIGHASH_ALL|SIGHASH_RANGEPROOF)}, |
| 268 | {std::string("ALL|ANYONECANPAY|RANGEPROOF"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY|SIGHASH_RANGEPROOF)}, |
| 269 | {std::string("NONE"), int(SIGHASH_NONE)}, |
| 270 | {std::string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY)}, |
| 271 | {std::string("NONE|RANGEPROOF"), int(SIGHASH_NONE|SIGHASH_RANGEPROOF)}, |
| 272 | {std::string("NONE|ANYONECANPAY|RANGEPROOF"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY|SIGHASH_RANGEPROOF)}, |
| 273 | {std::string("SINGLE"), int(SIGHASH_SINGLE)}, |
| 274 | {std::string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)}, |
| 275 | {std::string("SINGLE|RANGEPROOF"), int(SIGHASH_SINGLE|SIGHASH_RANGEPROOF)}, |
| 276 | {std::string("SINGLE|ANYONECANPAY|RANGEPROOF"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY|SIGHASH_RANGEPROOF)}, |
| 277 | }; |
| 278 | std::string strHashType = sighash.get_str(); |
| 279 | const auto& it = map_sighash_values.find(strHashType); |
| 280 | if (it != map_sighash_values.end()) { |
| 281 | hash_type = it->second; |
| 282 | } else { |
| 283 | throw std::runtime_error(strHashType + " is not a valid sighash parameter."); |
| 284 | } |
| 285 | } |
| 286 | return hash_type; |
| 287 | } |