Fulcrum/bitcoin/script_standard.h
Calin Culianu bd8bb06203 Added Cash Address support!
Note internally the BTC::Address class just stores hash160.

Its ToString() is always legacy (for now), but the server can now accept
both legacy or cash address from clients.  Class c'tor for
BTC::Address() auto-detects address type and decodes it appropriately.
2019-05-07 12:15:53 +03:00

114 lines
3.7 KiB
C++

// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2016 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_SCRIPT_STANDARD_H
#define BITCOIN_SCRIPT_STANDARD_H
#include "amount.h"
#include "pubkey.h"
#include "script_flags.h"
#include "uint256.h"
//#include <boost/variant.hpp>
#include <variant> // C++17, added by Calin as boost::variant work-alike
#include <cstdint>
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wold-style-cast"
#pragma clang diagnostic ignored "-Wsign-conversion"
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wunused-template"
#pragma clang diagnostic ignored "-Wtautological-unsigned-enum-zero-compare"
#pragma clang diagnostic ignored "-Wstring-conversion"
#pragma clang diagnostic ignored "-Wunreachable-code-break"
#pragma clang diagnostic ignored "-Wcast-qual"
#endif
namespace bitcoin {
static const bool DEFAULT_ACCEPT_DATACARRIER = true;
class CKeyID;
class CScript;
/** A reference to a CScript: the Hash160 of its serialization (see script.h) */
class CScriptID : public uint160 {
public:
CScriptID() : uint160() {}
CScriptID(const CScript &in);
CScriptID(const uint160 &in) : uint160(in) {}
};
//!< bytes (+1 for OP_RETURN, +2 for the pushdata opcodes)
static const unsigned int MAX_OP_RETURN_RELAY = 223;
extern bool fAcceptDatacarrier;
/**
* Mandatory script verification flags that all new blocks must comply with for
* them to be valid. (but old blocks may not comply with) Currently just P2SH,
* but in the future other flags may be added, such as a soft-fork to enforce
* strict DER encoding.
*
* Failing one of these tests may trigger a DoS ban - see CheckInputs() for
* details.
*/
static const uint32_t MANDATORY_SCRIPT_VERIFY_FLAGS =
SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC |
SCRIPT_ENABLE_SIGHASH_FORKID | SCRIPT_VERIFY_LOW_S | SCRIPT_VERIFY_NULLFAIL;
enum txnouttype {
TX_NONSTANDARD,
// 'standard' transaction types:
TX_PUBKEY,
TX_PUBKEYHASH,
TX_SCRIPTHASH,
TX_MULTISIG,
TX_NULL_DATA,
};
class CNoDestination {
public:
friend bool operator==(const CNoDestination &a, const CNoDestination &b) {
return true;
}
friend bool operator<(const CNoDestination &a, const CNoDestination &b) {
return true;
}
};
/**
* A txout script template with a specific destination. It is either:
* * CNoDestination: no destination set
* * CKeyID: TX_PUBKEYHASH destination
* * CScriptID: TX_SCRIPTHASH destination
* A CTxDestination is the internal data type encoded in a bitcoin address
*/
//typedef boost::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
typedef std::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
const char *GetTxnOutputType(txnouttype t);
bool IsValidDestination(const CTxDestination &dest);
bool Solver(const CScript &scriptPubKey, txnouttype &typeRet,
std::vector<std::vector<uint8_t>> &vSolutionsRet);
bool ExtractDestination(const CScript &scriptPubKey,
CTxDestination &addressRet);
bool ExtractDestinations(const CScript &scriptPubKey, txnouttype &typeRet,
std::vector<CTxDestination> &addressRet,
int &nRequiredRet);
CScript GetScriptForDestination(const CTxDestination &dest);
CScript GetScriptForRawPubKey(const CPubKey &pubkey);
CScript GetScriptForMultisig(int nRequired, const std::vector<CPubKey> &keys);
} // end namespace bitcoin
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif // BITCOIN_SCRIPT_STANDARD_H