Rename zcashconsensus_* -> zcash_script_* in APIs

This commit is contained in:
Jack Grigg 2020-08-11 21:49:46 +01:00
parent 0368fb5d98
commit 128ba4b7bf
3 changed files with 26 additions and 26 deletions

View File

@ -56,7 +56,7 @@ private:
size_t m_remaining; size_t m_remaining;
}; };
inline int set_error(zcashconsensus_error* ret, zcashconsensus_error serror) inline int set_error(zcash_script_error* ret, zcash_script_error serror)
{ {
if (ret) if (ret)
*ret = serror; *ret = serror;
@ -71,25 +71,25 @@ struct ECCryptoClosure
ECCryptoClosure instance_of_eccryptoclosure; ECCryptoClosure instance_of_eccryptoclosure;
} }
int zcashconsensus_verify_script( int zcash_script_verify(
const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen,
int64_t amount, int64_t amount,
const unsigned char *txTo, unsigned int txToLen, const unsigned char *txTo, unsigned int txToLen,
unsigned int nIn, unsigned int flags, unsigned int nIn, unsigned int flags,
uint32_t consensusBranchId, uint32_t consensusBranchId,
zcashconsensus_error* err) zcash_script_error* err)
{ {
try { try {
TxInputStream stream(SER_NETWORK, PROTOCOL_VERSION, txTo, txToLen); TxInputStream stream(SER_NETWORK, PROTOCOL_VERSION, txTo, txToLen);
CTransaction tx; CTransaction tx;
stream >> tx; stream >> tx;
if (nIn >= tx.vin.size()) if (nIn >= tx.vin.size())
return set_error(err, zcashconsensus_ERR_TX_INDEX); return set_error(err, zcash_script_ERR_TX_INDEX);
if (GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION) != txToLen) if (GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION) != txToLen)
return set_error(err, zcashconsensus_ERR_TX_SIZE_MISMATCH); return set_error(err, zcash_script_ERR_TX_SIZE_MISMATCH);
// Regardless of the verification result, the tx did not error. // Regardless of the verification result, the tx did not error.
set_error(err, zcashconsensus_ERR_OK); set_error(err, zcash_script_ERR_OK);
PrecomputedTransactionData txdata(tx); PrecomputedTransactionData txdata(tx);
return VerifyScript( return VerifyScript(
tx.vin[nIn].scriptSig, tx.vin[nIn].scriptSig,
@ -99,12 +99,12 @@ int zcashconsensus_verify_script(
consensusBranchId, consensusBranchId,
NULL); NULL);
} catch (const std::exception&) { } catch (const std::exception&) {
return set_error(err, zcashconsensus_ERR_TX_DESERIALIZE); // Error deserializing return set_error(err, zcash_script_ERR_TX_DESERIALIZE); // Error deserializing
} }
} }
unsigned int zcashconsensus_version() unsigned int zcash_script_version()
{ {
// Just use the API version for now // Just use the API version for now
return ZCASHCONSENSUS_API_VER; return ZCASH_SCRIPT_API_VER;
} }

View File

@ -3,8 +3,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or https://www.opensource.org/licenses/mit-license.php . // file COPYING or https://www.opensource.org/licenses/mit-license.php .
#ifndef BITCOIN_ZCASHCONSENSUS_H #ifndef ZCASH_SCRIPT_H
#define BITCOIN_ZCASHCONSENSUS_H #define ZCASH_SCRIPT_H
#include <stdint.h> #include <stdint.h>
@ -33,37 +33,37 @@
extern "C" { extern "C" {
#endif #endif
#define ZCASHCONSENSUS_API_VER 0 #define ZCASH_SCRIPT_API_VER 0
typedef enum zcashconsensus_error_t typedef enum zcash_script_error_t
{ {
zcashconsensus_ERR_OK = 0, zcash_script_ERR_OK = 0,
zcashconsensus_ERR_TX_INDEX, zcash_script_ERR_TX_INDEX,
zcashconsensus_ERR_TX_SIZE_MISMATCH, zcash_script_ERR_TX_SIZE_MISMATCH,
zcashconsensus_ERR_TX_DESERIALIZE, zcash_script_ERR_TX_DESERIALIZE,
} zcashconsensus_error; } zcash_script_error;
/** Script verification flags */ /** Script verification flags */
enum enum
{ {
zcashconsensus_SCRIPT_FLAGS_VERIFY_NONE = 0, zcash_script_SCRIPT_FLAGS_VERIFY_NONE = 0,
zcashconsensus_SCRIPT_FLAGS_VERIFY_P2SH = (1U << 0), // evaluate P2SH (BIP16) subscripts zcash_script_SCRIPT_FLAGS_VERIFY_P2SH = (1U << 0), // evaluate P2SH (BIP16) subscripts
zcashconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY = (1U << 9), // enable CHECKLOCKTIMEVERIFY (BIP65) zcash_script_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY = (1U << 9), // enable CHECKLOCKTIMEVERIFY (BIP65)
}; };
/// Returns 1 if the input nIn of the serialized transaction pointed to by /// Returns 1 if the input nIn of the serialized transaction pointed to by
/// txTo correctly spends the scriptPubKey pointed to by scriptPubKey under /// txTo correctly spends the scriptPubKey pointed to by scriptPubKey under
/// the additional constraints specified by flags. /// the additional constraints specified by flags.
/// If not NULL, err will contain an error/success code for the operation /// If not NULL, err will contain an error/success code for the operation
EXPORT_SYMBOL int zcashconsensus_verify_script( EXPORT_SYMBOL int zcash_script_verify(
const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen,
int64_t amount, int64_t amount,
const unsigned char *txTo, unsigned int txToLen, const unsigned char *txTo, unsigned int txToLen,
unsigned int nIn, unsigned int flags, unsigned int nIn, unsigned int flags,
uint32_t consensusBranchId, uint32_t consensusBranchId,
zcashconsensus_error* err); zcash_script_error* err);
EXPORT_SYMBOL unsigned int zcashconsensus_version(); EXPORT_SYMBOL unsigned int zcash_script_version();
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
@ -71,4 +71,4 @@ EXPORT_SYMBOL unsigned int zcashconsensus_version();
#undef EXPORT_SYMBOL #undef EXPORT_SYMBOL
#endif // BITCOIN_ZCASHCONSENSUS_H #endif // ZCASH_SCRIPT_H

View File

@ -100,7 +100,7 @@ void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, int flags, ui
#if defined(HAVE_CONSENSUS_LIB) #if defined(HAVE_CONSENSUS_LIB)
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
stream << tx2; stream << tx2;
BOOST_CHECK_MESSAGE(zcashconsensus_verify_script( BOOST_CHECK_MESSAGE(zcash_script_verify(
begin_ptr(scriptPubKey), scriptPubKey.size(), begin_ptr(scriptPubKey), scriptPubKey.size(),
txCredit.vout[0].nValue, txCredit.vout[0].nValue,
(const unsigned char*)&stream[0], stream.size(), (const unsigned char*)&stream[0], stream.size(),