Bitcoin Core  27.99.0
P2P Digital Currency
bitcoinconsensus.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2021 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.
5 
6 #ifndef BITCOIN_SCRIPT_BITCOINCONSENSUS_H
7 #define BITCOIN_SCRIPT_BITCOINCONSENSUS_H
8 
9 #include <stdint.h>
10 
11 #if defined(BUILD_BITCOIN_INTERNAL) && defined(HAVE_CONFIG_H)
12 #include <config/bitcoin-config.h>
13  #if defined(_WIN32)
14  #if defined(HAVE_DLLEXPORT_ATTRIBUTE)
15  #define EXPORT_SYMBOL __declspec(dllexport)
16  #else
17  #define EXPORT_SYMBOL
18  #endif
19  #elif defined(HAVE_DEFAULT_VISIBILITY_ATTRIBUTE)
20  #define EXPORT_SYMBOL __attribute__ ((visibility ("default")))
21  #endif
22 #elif defined(MSC_VER) && !defined(STATIC_LIBBITCOINCONSENSUS)
23  #define EXPORT_SYMBOL __declspec(dllimport)
24 #endif
25 
26 #ifndef EXPORT_SYMBOL
27  #define EXPORT_SYMBOL
28 #endif
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #define BITCOINCONSENSUS_API_VER 2
35 
37 {
47 
49 enum
50 {
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_TAPROOT = (1U << 17), // enable TAPROOT (BIPs 341 & 342)
63 };
64 
65 typedef struct {
66  const unsigned char *scriptPubKey;
67  unsigned int scriptPubKeySize;
68  int64_t value;
69 } UTXO;
70 
75 EXPORT_SYMBOL int bitcoinconsensus_verify_script(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen,
76  const unsigned char *txTo , unsigned int txToLen,
77  unsigned int nIn, unsigned int flags, bitcoinconsensus_error* err);
78 
79 EXPORT_SYMBOL int bitcoinconsensus_verify_script_with_amount(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, int64_t amount,
80  const unsigned char *txTo , unsigned int txToLen,
81  unsigned int nIn, unsigned int flags, bitcoinconsensus_error* err);
82 
83 EXPORT_SYMBOL int bitcoinconsensus_verify_script_with_spent_outputs(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, int64_t amount,
84  const unsigned char *txTo , unsigned int txToLen,
85  const UTXO *spentOutputs, unsigned int spentOutputsLen,
86  unsigned int nIn, unsigned int flags, bitcoinconsensus_error* err);
87 
89 
90 #ifdef __cplusplus
91 } // extern "C"
92 #endif
93 
94 #undef EXPORT_SYMBOL
95 
96 #endif // BITCOIN_SCRIPT_BITCOINCONSENSUS_H
int flags
Definition: bitcoin-tx.cpp:530
enum bitcoinconsensus_error_t bitcoinconsensus_error
EXPORT_SYMBOL unsigned int bitcoinconsensus_version()
bitcoinconsensus_error_t
@ bitcoinconsensus_ERR_OK
@ bitcoinconsensus_ERR_SPENT_OUTPUTS_MISMATCH
@ bitcoinconsensus_ERR_TX_DESERIALIZE
@ bitcoinconsensus_ERR_AMOUNT_REQUIRED
@ bitcoinconsensus_ERR_TX_INDEX
@ bitcoinconsensus_ERR_INVALID_FLAGS
@ bitcoinconsensus_ERR_TX_SIZE_MISMATCH
@ bitcoinconsensus_ERR_SPENT_OUTPUTS_REQUIRED
EXPORT_SYMBOL int bitcoinconsensus_verify_script_with_spent_outputs(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, int64_t amount, const unsigned char *txTo, unsigned int txToLen, const UTXO *spentOutputs, unsigned int spentOutputsLen, unsigned int nIn, unsigned int flags, bitcoinconsensus_error *err)
EXPORT_SYMBOL int bitcoinconsensus_verify_script(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, const unsigned char *txTo, unsigned int txToLen, unsigned int nIn, unsigned int flags, bitcoinconsensus_error *err)
Returns 1 if the input nIn of the serialized transaction pointed to by txTo correctly spends the scri...
#define EXPORT_SYMBOL
@ bitcoinconsensus_SCRIPT_FLAGS_VERIFY_ALL
@ bitcoinconsensus_SCRIPT_FLAGS_VERIFY_TAPROOT
@ bitcoinconsensus_SCRIPT_FLAGS_VERIFY_WITNESS
@ bitcoinconsensus_SCRIPT_FLAGS_VERIFY_NONE
@ bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY
@ bitcoinconsensus_SCRIPT_FLAGS_VERIFY_NULLDUMMY
@ bitcoinconsensus_SCRIPT_FLAGS_VERIFY_P2SH
@ bitcoinconsensus_SCRIPT_FLAGS_VERIFY_DERSIG
@ bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY
EXPORT_SYMBOL int bitcoinconsensus_verify_script_with_amount(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, int64_t amount, const unsigned char *txTo, unsigned int txToLen, unsigned int nIn, unsigned int flags, bitcoinconsensus_error *err)
unsigned int scriptPubKeySize
const unsigned char * scriptPubKey
int64_t value