|
| 1 | +// Copyright (c) 2023 The Bitcoin Core developers |
| 2 | +// Distributed under the MIT software license, see the accompanying |
| 3 | +// file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 4 | + |
| 5 | +#include <script/interpreter.h> |
| 6 | +#include <univalue.h> |
| 7 | +#include <util/strencodings.h> |
| 8 | + |
| 9 | +#include <map> |
| 10 | +#include <stdexcept> |
| 11 | +#include <string> |
| 12 | +#include <utility> |
| 13 | +#include <vector> |
| 14 | + |
| 15 | +std::vector<unsigned char> ParseHexUV(const UniValue& v, const std::string& strName) |
| 16 | +{ |
| 17 | + std::string strHex; |
| 18 | + if (v.isStr()) |
| 19 | + strHex = v.getValStr(); |
| 20 | + if (!IsHex(strHex)) |
| 21 | + throw std::runtime_error(strName + " must be hexadecimal string (not '" + strHex + "')"); |
| 22 | + return ParseHex(strHex); |
| 23 | +} |
| 24 | + |
| 25 | +int ParseSighashString(const UniValue& sighash) |
| 26 | +{ |
| 27 | + int hash_type = SIGHASH_DEFAULT; |
| 28 | + if (!sighash.isNull()) { |
| 29 | + static std::map<std::string, int> map_sighash_values = { |
| 30 | + {std::string("DEFAULT"), int(SIGHASH_DEFAULT)}, |
| 31 | + {std::string("ALL"), int(SIGHASH_ALL)}, |
| 32 | + {std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)}, |
| 33 | + {std::string("NONE"), int(SIGHASH_NONE)}, |
| 34 | + {std::string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY)}, |
| 35 | + {std::string("SINGLE"), int(SIGHASH_SINGLE)}, |
| 36 | + {std::string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)}, |
| 37 | + }; |
| 38 | + const std::string& strHashType = sighash.get_str(); |
| 39 | + const auto& it = map_sighash_values.find(strHashType); |
| 40 | + if (it != map_sighash_values.end()) { |
| 41 | + hash_type = it->second; |
| 42 | + } else { |
| 43 | + throw std::runtime_error(strHashType + " is not a valid sighash parameter."); |
| 44 | + } |
| 45 | + } |
| 46 | + return hash_type; |
| 47 | +} |
0 commit comments