1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #ifndef BITCOIN_BITCOINCONSENSUS_H
7 #define BITCOIN_BITCOINCONSENSUS_H
11 #if defined(BUILD_BITCOIN_INTERNAL) && defined(HAVE_CONFIG_H)
12 #include <config/bitcoin-config.h>
14 #if defined(DLL_EXPORT)
15 #if defined(HAVE_FUNC_ATTRIBUTE_DLLEXPORT)
16 #define EXPORT_SYMBOL __declspec(dllexport)
21 #elif defined(HAVE_FUNC_ATTRIBUTE_VISIBILITY)
22 #define EXPORT_SYMBOL __attribute__ ((visibility ("default")))
24 #elif defined(MSC_VER) && !defined(STATIC_LIBBITCOINCONSENSUS)
25 #define EXPORT_SYMBOL __declspec(dllimport)
36 #define BITCOINCONSENSUS_API_VER 1
38 typedef enum bitcoinconsensus_error_t
40 bitcoinconsensus_ERR_OK
= 0,
41 bitcoinconsensus_ERR_TX_INDEX
,
42 bitcoinconsensus_ERR_TX_SIZE_MISMATCH
,
43 bitcoinconsensus_ERR_TX_DESERIALIZE
,
44 bitcoinconsensus_ERR_AMOUNT_REQUIRED
,
45 bitcoinconsensus_ERR_INVALID_FLAGS
,
46 } bitcoinconsensus_error
;
48 /** Script verification flags */
51 bitcoinconsensus_SCRIPT_FLAGS_VERIFY_NONE
= 0,
52 bitcoinconsensus_SCRIPT_FLAGS_VERIFY_P2SH
= (1U << 0), // evaluate P2SH (BIP16) subscripts
53 bitcoinconsensus_SCRIPT_FLAGS_VERIFY_DERSIG
= (1U << 2), // enforce strict DER (BIP66) compliance
54 bitcoinconsensus_SCRIPT_FLAGS_VERIFY_NULLDUMMY
= (1U << 4), // enforce NULLDUMMY (BIP147)
55 bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY
= (1U << 9), // enable CHECKLOCKTIMEVERIFY (BIP65)
56 bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY
= (1U << 10), // enable CHECKSEQUENCEVERIFY (BIP112)
57 bitcoinconsensus_SCRIPT_FLAGS_VERIFY_WITNESS
= (1U << 11), // enable WITNESS (BIP141)
58 bitcoinconsensus_SCRIPT_FLAGS_VERIFY_ALL
= bitcoinconsensus_SCRIPT_FLAGS_VERIFY_P2SH
| bitcoinconsensus_SCRIPT_FLAGS_VERIFY_DERSIG
|
59 bitcoinconsensus_SCRIPT_FLAGS_VERIFY_NULLDUMMY
| bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY
|
60 bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY
| bitcoinconsensus_SCRIPT_FLAGS_VERIFY_WITNESS
63 /// Returns 1 if the input nIn of the serialized transaction pointed to by
64 /// txTo correctly spends the scriptPubKey pointed to by scriptPubKey under
65 /// the additional constraints specified by flags.
66 /// If not nullptr, err will contain an error/success code for the operation
67 EXPORT_SYMBOL
int bitcoinconsensus_verify_script(const unsigned char *scriptPubKey
, unsigned int scriptPubKeyLen
,
68 const unsigned char *txTo
, unsigned int txToLen
,
69 unsigned int nIn
, unsigned int flags
, bitcoinconsensus_error
* err
);
71 EXPORT_SYMBOL
int bitcoinconsensus_verify_script_with_amount(const unsigned char *scriptPubKey
, unsigned int scriptPubKeyLen
, int64_t amount
,
72 const unsigned char *txTo
, unsigned int txToLen
,
73 unsigned int nIn
, unsigned int flags
, bitcoinconsensus_error
* err
);
75 EXPORT_SYMBOL
unsigned int bitcoinconsensus_version();
83 #endif // BITCOIN_BITCOINCONSENSUS_H