small refactor
This commit is contained in:
@@ -2,26 +2,15 @@
|
||||
#include "replacementpool.h"
|
||||
#include "komodo_cryptoconditions.h"
|
||||
#include "cryptoconditions/include/cryptoconditions.h"
|
||||
#include "script/interpreter.h"
|
||||
#include "coins.h"
|
||||
|
||||
|
||||
#define REPLACEMENT_WINDOW_BLOCKS 2
|
||||
|
||||
|
||||
bool GetOpReturnData(const CScript &sig, std::vector<unsigned char> &data)
|
||||
{
|
||||
auto pc = sig.begin();
|
||||
opcodetype opcode;
|
||||
if (sig.GetOp(pc, opcode))
|
||||
if (opcode == OP_RETURN)
|
||||
if (sig.GetOp(pc, opcode, data))
|
||||
return opcode > OP_0 && opcode <= OP_PUSHDATA4;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool EvalConditionBool(const CC *cond, const CTransaction *txTo)
|
||||
/*
|
||||
* Evaluate the validity of an Eval node
|
||||
*/
|
||||
bool EvalConditionValidity(const CC *cond, const CTransaction *txTo)
|
||||
{
|
||||
if (strcmp(cond->method, "testEval") == 0) {
|
||||
return cond->paramsBinLength == 8 &&
|
||||
@@ -35,7 +24,16 @@ bool EvalConditionBool(const CC *cond, const CTransaction *txTo)
|
||||
}
|
||||
|
||||
|
||||
bool GetConditionPriority(const CC *cond, CTxReplacementPoolItem *rep)
|
||||
/*
|
||||
* Evaluate the priority of an eval node.
|
||||
*
|
||||
* This method should set the ->priority and ->replacementWindow (in blocks)
|
||||
* of the provided replacement pool item. Priority is a 64 bit unsigned int and
|
||||
* 0 is invalid.
|
||||
*
|
||||
* This method does not need to validate, that is done separately.
|
||||
*/
|
||||
bool EvalConditionPriority(const CC *cond, CTxReplacementPoolItem *rep)
|
||||
{
|
||||
if (strcmp((const char*)cond->method, "testReplace") == 0) {
|
||||
std::vector<unsigned char> data;
|
||||
@@ -49,30 +47,18 @@ bool GetConditionPriority(const CC *cond, CTxReplacementPoolItem *rep)
|
||||
}
|
||||
|
||||
|
||||
bool TransactionSignatureChecker::CheckEvalCondition(const CC *cond) const
|
||||
{
|
||||
return EvalConditionBool(cond, txTo);
|
||||
}
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
int visitConditionPriority(CC *cond, struct CCVisitor visitor);
|
||||
}
|
||||
|
||||
|
||||
int visitConditionPriority(CC *cond, struct CCVisitor visitor)
|
||||
{
|
||||
if (cc_typeId(cond) == CC_Eval) {
|
||||
if (GetConditionPriority(cond, (CTxReplacementPoolItem*)visitor.context)) {
|
||||
return 0; // stop
|
||||
}
|
||||
}
|
||||
return 1; // continue
|
||||
auto rep = (CTxReplacementPoolItem*)visitor.context;
|
||||
// visitor protocol is 1 for continue, 0 for stop
|
||||
return !(cc_typeId(cond) == CC_Eval && EvalConditionPriority(cond, rep));
|
||||
}
|
||||
|
||||
|
||||
bool SetReplacementParams(CTxReplacementPoolItem &rep)
|
||||
/*
|
||||
* Try to get replacement parameters from a transaction in &rep.
|
||||
*/
|
||||
bool PutReplacementParams(CTxReplacementPoolItem &rep)
|
||||
{
|
||||
// first, see if we have a cryptocondition
|
||||
const CScript &sig = rep.tx.vin[0].scriptSig;
|
||||
@@ -82,6 +68,7 @@ bool SetReplacementParams(CTxReplacementPoolItem &rep)
|
||||
opcodetype opcode;
|
||||
if (!sig.GetOp(pc, opcode, data)) return false;
|
||||
CC *cond = cc_readFulfillmentBinary((unsigned char*)data.data(), data.size());
|
||||
auto wat = {1, ""};
|
||||
if (!cond) return false;
|
||||
|
||||
// now, see if it has a replacement node
|
||||
@@ -91,3 +78,15 @@ bool SetReplacementParams(CTxReplacementPoolItem &rep)
|
||||
cc_free(cond);
|
||||
return !out;
|
||||
}
|
||||
|
||||
|
||||
bool GetOpReturnData(const CScript &sig, std::vector<unsigned char> &data)
|
||||
{
|
||||
auto pc = sig.begin();
|
||||
opcodetype opcode;
|
||||
if (sig.GetOp(pc, opcode))
|
||||
if (opcode == OP_RETURN)
|
||||
if (sig.GetOp(pc, opcode, data))
|
||||
return opcode > OP_0 && opcode <= OP_PUSHDATA4;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include "replacementpool.h"
|
||||
#include "cryptoconditions/include/cryptoconditions.h"
|
||||
#include "script/script.h"
|
||||
|
||||
|
||||
extern int32_t ASSETCHAINS_CC;
|
||||
|
||||
@@ -12,8 +14,10 @@ static bool IsCryptoConditionsEnabled() {
|
||||
|
||||
extern CTxReplacementPool replacementPool;
|
||||
|
||||
bool EvalConditionBool(const CC *cond, const CTransaction *tx);
|
||||
bool EvalConditionValidity(const CC *cond, const CTransaction *tx);
|
||||
|
||||
bool SetReplacementParams(CTxReplacementPoolItem &rep);
|
||||
|
||||
bool GetOpReturnData(const CScript &sig, std::vector<unsigned char> &data);
|
||||
|
||||
#endif /* KOMODO_CRYPTOCONDITIONS_H */
|
||||
|
||||
@@ -1152,15 +1152,19 @@ bool TransactionSignatureChecker::CheckSig(const vector<unsigned char>& vchSigIn
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
|
||||
bool TransactionSignatureChecker::CheckEvalCondition(const CC *cond) const
|
||||
{
|
||||
static int komodoCCEval(CC *cond, void *transactionSignatureChecker);
|
||||
return EvalConditionValidity(cond, txTo);
|
||||
}
|
||||
|
||||
static int komodoCCEval(CC *cond, void *checker) {
|
||||
|
||||
static int komodoCCEval(CC *cond, void *checker)
|
||||
{
|
||||
return ((TransactionSignatureChecker*)checker)->CheckEvalCondition(cond);
|
||||
}
|
||||
|
||||
|
||||
bool TransactionSignatureChecker::CheckCryptoCondition(const CC *cond, const std::vector<unsigned char>& condBin, const CScript& scriptCode) const
|
||||
{
|
||||
uint256 message = SignatureHash(scriptCode, *txTo, nIn, SIGHASH_ALL);
|
||||
@@ -1168,6 +1172,7 @@ bool TransactionSignatureChecker::CheckCryptoCondition(const CC *cond, const std
|
||||
condBin.data(), condBin.size(), komodoCCEval, (void*)this);
|
||||
}
|
||||
|
||||
|
||||
bool TransactionSignatureChecker::CheckLockTime(const CScriptNum& nLockTime) const
|
||||
{
|
||||
// There are two times of nLockTime: lock-by-blockheight
|
||||
|
||||
Reference in New Issue
Block a user