@@ -69,29 +69,49 @@ struct ECCryptoClosure
69
69
ECCryptoClosure instance_of_eccryptoclosure;
70
70
}
71
71
72
- int bitcoinconsensus_verify_script (const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, uint64_t amount,
72
+ static int verify_script (const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, CAmount amount,
73
73
const unsigned char *txTo , unsigned int txToLen,
74
74
unsigned int nIn, unsigned int flags, bitcoinconsensus_error* err)
75
75
{
76
76
try {
77
- TxInputStream stream (SER_NETWORK, PROTOCOL_VERSION, txTo, txToLen);
77
+ TxInputStream stream (SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_WITNESS , txTo, txToLen);
78
78
CTransaction tx;
79
79
stream >> tx;
80
80
if (nIn >= tx.vin .size ())
81
81
return set_error (err, bitcoinconsensus_ERR_TX_INDEX);
82
- if (tx.GetSerializeSize (SER_NETWORK, PROTOCOL_VERSION) != txToLen)
82
+ if (tx.GetSerializeSize (SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_WITNESS ) != txToLen)
83
83
return set_error (err, bitcoinconsensus_ERR_TX_SIZE_MISMATCH);
84
84
85
- // Regardless of the verification result, the tx did not error.
86
- set_error (err, bitcoinconsensus_ERR_OK);
85
+ // Regardless of the verification result, the tx did not error.
86
+ set_error (err, bitcoinconsensus_ERR_OK);
87
87
88
- CAmount am (amount);
89
- return VerifyScript (tx.vin [nIn].scriptSig , CScript (scriptPubKey, scriptPubKey + scriptPubKeyLen), nIn < tx.wit .vtxinwit .size () ? &tx.wit .vtxinwit [nIn].scriptWitness : NULL , flags, TransactionSignatureChecker (&tx, nIn, am), NULL );
88
+ return VerifyScript (tx.vin [nIn].scriptSig , CScript (scriptPubKey, scriptPubKey + scriptPubKeyLen), nIn < tx.wit .vtxinwit .size () ? &tx.wit .vtxinwit [nIn].scriptWitness : NULL , flags, TransactionSignatureChecker (&tx, nIn, amount), NULL );
90
89
} catch (const std::exception&) {
91
90
return set_error (err, bitcoinconsensus_ERR_TX_DESERIALIZE); // Error deserializing
92
91
}
93
92
}
94
93
94
+ int bitcoinconsensus_verify_script_with_amount (const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, uint64_t amount,
95
+ const unsigned char *txTo , unsigned int txToLen,
96
+ unsigned int nIn, unsigned int flags, bitcoinconsensus_error* err)
97
+ {
98
+ CAmount am (amount);
99
+ return ::verify_script (scriptPubKey, scriptPubKeyLen, am, txTo, txToLen, nIn, flags, err);
100
+ }
101
+
102
+
103
+ int bitcoinconsensus_verify_script (const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen,
104
+ const unsigned char *txTo , unsigned int txToLen,
105
+ unsigned int nIn, unsigned int flags, bitcoinconsensus_error* err)
106
+ {
107
+ if (flags & bitcoinconsensus_SCRIPT_FLAGS_VERIFY_WITNESS) {
108
+ return set_error (err, bitcoinconsensus_ERR_AMOUNT_REQUIRED);
109
+ }
110
+
111
+ CAmount am (0 );
112
+ return ::verify_script (scriptPubKey, scriptPubKeyLen, am, txTo, txToLen, nIn, flags, err);
113
+ }
114
+
95
115
unsigned int bitcoinconsensus_version ()
96
116
{
97
117
// Just use the API version for now
0 commit comments