Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

dashconsensus.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 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 #include <script/dashconsensus.h>
7 
9 #include <pubkey.h>
10 #include <script/interpreter.h>
11 #include <version.h>
12 
13 namespace {
14 
16 class TxInputStream
17 {
18 public:
19  TxInputStream(int nTypeIn, int nVersionIn, const unsigned char *txTo, size_t txToLen) :
20  m_type(nTypeIn),
21  m_version(nVersionIn),
22  m_data(txTo),
23  m_remaining(txToLen)
24  {}
25 
26  void read(char* pch, size_t nSize)
27  {
28  if (nSize > m_remaining)
29  throw std::ios_base::failure(std::string(__func__) + ": end of data");
30 
31  if (pch == nullptr)
32  throw std::ios_base::failure(std::string(__func__) + ": bad destination buffer");
33 
34  if (m_data == nullptr)
35  throw std::ios_base::failure(std::string(__func__) + ": bad source buffer");
36 
37  memcpy(pch, m_data, nSize);
38  m_remaining -= nSize;
39  m_data += nSize;
40  }
41 
42  template<typename T>
43  TxInputStream& operator>>(T& obj)
44  {
45  ::Unserialize(*this, obj);
46  return *this;
47  }
48 
49  int GetVersion() const { return m_version; }
50  int GetType() const { return m_type; }
51 private:
52  const int m_type;
53  const int m_version;
54  const unsigned char* m_data;
55  size_t m_remaining;
56 };
57 
58 inline int set_error(dashconsensus_error* ret, dashconsensus_error serror)
59 {
60  if (ret)
61  *ret = serror;
62  return 0;
63 }
64 
65 struct ECCryptoClosure
66 {
67  ECCVerifyHandle handle;
68 };
69 
70 ECCryptoClosure instance_of_eccryptoclosure;
71 } // namespace
72 
74 static bool verify_flags(unsigned int flags)
75 {
77 }
78 
79 int dashconsensus_verify_script(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen,
80  const unsigned char *txTo , unsigned int txToLen,
81  unsigned int nIn, unsigned int flags, dashconsensus_error* err)
82 {
83  if (!verify_flags(flags)) {
85  }
86  try {
87  TxInputStream stream(SER_NETWORK, PROTOCOL_VERSION, txTo, txToLen);
88  CTransaction tx(deserialize, stream);
89  if (nIn >= tx.vin.size())
90  return set_error(err, dashconsensus_ERR_TX_INDEX);
91  if (GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION) != txToLen)
92  return set_error(err, dashconsensus_ERR_TX_SIZE_MISMATCH);
93 
94  // Regardless of the verification result, the tx did not error.
95  set_error(err, dashconsensus_ERR_OK);
96 
97  PrecomputedTransactionData txdata(tx);
98  CAmount am(0);
99  return VerifyScript(tx.vin[nIn].scriptSig, CScript(scriptPubKey, scriptPubKey + scriptPubKeyLen), flags, TransactionSignatureChecker(&tx, nIn, am, txdata), nullptr);
100  } catch (const std::exception&) {
101  return set_error(err, dashconsensus_ERR_TX_DESERIALIZE); // Error deserializing
102  }
103 }
104 
105 unsigned int dashconsensus_version()
106 {
107  // Just use the API version for now
109 }
int dashconsensus_verify_script(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, const unsigned char *txTo, unsigned int txToLen, unsigned int nIn, unsigned int flags, dashconsensus_error *err)
Returns 1 if the input nIn of the serialized transaction pointed to by txTo correctly spends the scri...
size_t GetSerializeSize(const T &t, int nType, int nVersion=0)
Definition: serialize.h:1295
static bool verify_flags(unsigned int flags)
Check that all specified flags are part of the libconsensus interface.
constexpr deserialize_type deserialize
Definition: serialize.h:43
int flags
Definition: dash-tx.cpp:462
const std::vector< CTxIn > vin
Definition: transaction.h:215
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
Users of this module must hold an ECCVerifyHandle.
Definition: pubkey.h:248
#define BITCOINCONSENSUS_API_VER
Definition: dashconsensus.h:36
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror)
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:389
void * memcpy(void *a, const void *b, size_t c)
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:14
unsigned int dashconsensus_version()
void Unserialize(Stream &s, char &a)
Definition: serialize.h:196
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:198
enum dashconsensus_error_t dashconsensus_error
Released under the MIT license