limenkaconsensus.h raw

   1  // Copyright (c) 2009-2010 Satoshi Nakamoto
   2  // Copyright (c) 2009-2021 The Limenka 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 LIMENKA_SCRIPT_LIMENKACONSENSUS_H
   7  #define LIMENKA_SCRIPT_LIMENKACONSENSUS_H
   8  
   9  #include <stdint.h>
  10  
  11  #if defined(STATIC_LIBLIMENKACONSENSUS)
  12    // No export/import for static libraries
  13  #elif defined(_WIN32)
  14    #if defined(BUILD_LIMENKA_INTERNAL)
  15      #define EXPORT_SYMBOL __declspec (dllexport)
  16    #else
  17      #define EXPORT_SYMBOL __declspec (dllimport)
  18    #endif
  19  #elif defined(BUILD_LIMENKA_INTERNAL)
  20    #if defined(__GNUC__) && (__GNUC__ >= 4)
  21      #define EXPORT_SYMBOL __attribute__ ((visibility ("default")))
  22    #endif
  23  #endif
  24  
  25  #ifndef EXPORT_SYMBOL
  26    #define EXPORT_SYMBOL
  27  #endif
  28  
  29  #ifdef __cplusplus
  30  extern "C" {
  31  #endif
  32  
  33  #define LIMENKACONSENSUS_API_VER 2
  34  
  35  typedef enum limenkaconsensus_error_t
  36  {
  37      limenkaconsensus_ERR_OK = 0,
  38      limenkaconsensus_ERR_TX_INDEX,
  39      limenkaconsensus_ERR_TX_SIZE_MISMATCH,
  40      limenkaconsensus_ERR_TX_DESERIALIZE,
  41      limenkaconsensus_ERR_AMOUNT_REQUIRED,
  42      limenkaconsensus_ERR_INVALID_FLAGS,
  43      limenkaconsensus_ERR_SPENT_OUTPUTS_REQUIRED,
  44      limenkaconsensus_ERR_SPENT_OUTPUTS_MISMATCH
  45  } limenkaconsensus_error;
  46  
  47  /** Script verification flags */
  48  enum
  49  {
  50      limenkaconsensus_SCRIPT_FLAGS_VERIFY_NONE                = 0,
  51      limenkaconsensus_SCRIPT_FLAGS_VERIFY_P2SH                = (1U << 0), // evaluate P2SH (BIP16) subscripts
  52      limenkaconsensus_SCRIPT_FLAGS_VERIFY_DERSIG              = (1U << 2), // enforce strict DER (BIP66) compliance
  53      limenkaconsensus_SCRIPT_FLAGS_VERIFY_NULLDUMMY           = (1U << 4), // enforce NULLDUMMY (BIP147)
  54      limenkaconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY = (1U << 9), // enable CHECKLOCKTIMEVERIFY (BIP65)
  55      limenkaconsensus_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY = (1U << 10), // enable CHECKSEQUENCEVERIFY (BIP112)
  56      limenkaconsensus_SCRIPT_FLAGS_VERIFY_WITNESS             = (1U << 11), // enable WITNESS (BIP141)
  57      limenkaconsensus_SCRIPT_FLAGS_VERIFY_TAPROOT             = (1U << 17), // enable TAPROOT (BIPs 341 & 342)
  58      limenkaconsensus_SCRIPT_FLAGS_VERIFY_ALL                 = limenkaconsensus_SCRIPT_FLAGS_VERIFY_P2SH | limenkaconsensus_SCRIPT_FLAGS_VERIFY_DERSIG |
  59                                                                 limenkaconsensus_SCRIPT_FLAGS_VERIFY_NULLDUMMY | limenkaconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY |
  60                                                                 limenkaconsensus_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY | limenkaconsensus_SCRIPT_FLAGS_VERIFY_WITNESS |
  61                                                                 limenkaconsensus_SCRIPT_FLAGS_VERIFY_TAPROOT
  62  };
  63  
  64  typedef struct {
  65      const unsigned char *scriptPubKey;
  66      unsigned int scriptPubKeySize;
  67      int64_t value;
  68  } UTXO;
  69  
  70  /// Returns 1 if the input nIn of the serialized transaction pointed to by
  71  /// txTo correctly spends the scriptPubKey pointed to by scriptPubKey under
  72  /// the additional constraints specified by flags.
  73  /// If not nullptr, err will contain an error/success code for the operation
  74  EXPORT_SYMBOL int limenkaconsensus_verify_script(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen,
  75                                                   const unsigned char *txTo        , unsigned int txToLen,
  76                                                   unsigned int nIn, unsigned int flags, limenkaconsensus_error* err);
  77  
  78  EXPORT_SYMBOL int limenkaconsensus_verify_script_with_amount(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, int64_t amount,
  79                                      const unsigned char *txTo        , unsigned int txToLen,
  80                                      unsigned int nIn, unsigned int flags, limenkaconsensus_error* err);
  81  
  82  EXPORT_SYMBOL int limenkaconsensus_verify_script_with_spent_outputs(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, int64_t amount,
  83                                      const unsigned char *txTo        , unsigned int txToLen,
  84                                      const UTXO *spentOutputs, unsigned int spentOutputsLen,
  85                                      unsigned int nIn, unsigned int flags, limenkaconsensus_error* err);
  86  
  87  EXPORT_SYMBOL unsigned int limenkaconsensus_version();
  88  
  89  #ifdef __cplusplus
  90  } // extern "C"
  91  #endif
  92  
  93  #undef EXPORT_SYMBOL
  94  
  95  #endif // LIMENKA_SCRIPT_LIMENKACONSENSUS_H
  96