Refactors in anticipation of blinded values

This commit is contained in:
Luke Dashjr 2016-02-15 15:19:28 -08:00 committed by Gregory Sanders
parent 743081a205
commit b5f1b6dd38
34 changed files with 262 additions and 133 deletions

View file

@ -76,8 +76,8 @@ static bool verify_flags(unsigned int flags)
return (flags & ~(bitcoinconsensus_SCRIPT_FLAGS_VERIFY_ALL)) == 0;
}
static int verify_script(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, CAmount amount,
CAmount amountPreviousInput,
static int verify_script(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, CTxOutValue amount,
CTxOutValue amountPreviousInput,
const unsigned char *txTo , unsigned int txToLen,
unsigned int nIn, unsigned int flags, bitcoinconsensus_error* err)
{
@ -96,7 +96,7 @@ static int verify_script(const unsigned char *scriptPubKey, unsigned int scriptP
set_error(err, bitcoinconsensus_ERR_OK);
PrecomputedTransactionData txdata(tx);
if (amountPreviousInput < -1 || (nIn != 0 && !MoneyRange(amountPreviousInput)))
if (amountPreviousInput.IsAmount() && (amountPreviousInput.GetAmount() < -1 || (nIn != 0 && !MoneyRange(amountPreviousInput.GetAmount()))))
return VerifyScript(tx.vin[nIn].scriptSig, CScript(scriptPubKey, scriptPubKey + scriptPubKeyLen), &tx.vin[nIn].scriptWitness, flags, TransactionNoWithdrawsSignatureChecker(&tx, nIn, amount, txdata), NULL);
else
return VerifyScript(tx.vin[nIn].scriptSig, CScript(scriptPubKey, scriptPubKey + scriptPubKeyLen), &tx.vin[nIn].scriptWitness, flags, TransactionSignatureChecker(&tx, nIn, amount, amountPreviousInput, txdata), NULL);
@ -105,14 +105,25 @@ static int verify_script(const unsigned char *scriptPubKey, unsigned int scriptP
}
}
int bitcoinconsensus_verify_script_with_amount(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen, int64_t amount,
int64_t amountPreviousInput,
int bitcoinconsensus_verify_script_with_amount(const unsigned char *scriptPubKey, unsigned int scriptPubKeyLen,
const unsigned char* amount, unsigned int amountLen,
const unsigned char* amountPreviousInput, unsigned int amountPreviousInputLen,
const unsigned char *txTo , unsigned int txToLen,
unsigned int nIn, unsigned int flags, bitcoinconsensus_error* err)
{
CAmount am(amount);
CAmount prevInAm(amountPreviousInput);
return ::verify_script(scriptPubKey, scriptPubKeyLen, am, prevInAm, txTo, txToLen, nIn, flags, err);
try {
TxInputStream stream(SER_NETWORK, PROTOCOL_VERSION, amount, amountLen);
CTxOutValue am;
stream >> am;
TxInputStream stream2(SER_NETWORK, PROTOCOL_VERSION, amountPreviousInput, amountPreviousInputLen);
CTxOutValue prevInAm;
stream >> prevInAm;
return ::verify_script(scriptPubKey, scriptPubKeyLen, am, prevInAm, txTo, txToLen, nIn, flags, err);
} catch (const std::exception&) {
return set_error(err, bitcoinconsensus_ERR_TX_DESERIALIZE); // Error deserializing
}
}
@ -124,8 +135,8 @@ int bitcoinconsensus_verify_script(const unsigned char *scriptPubKey, unsigned i
return set_error(err, bitcoinconsensus_ERR_AMOUNT_REQUIRED);
}
CAmount am(0);
CAmount prevInAm(-2);
CTxOutValue am(0);
CTxOutValue prevInAm(-2);
return ::verify_script(scriptPubKey, scriptPubKeyLen, am, prevInAm, txTo, txToLen, nIn, flags, err);
}