simplified claim stripping, removed TX_CLAIM

This commit is contained in:
Brannon King 2019-08-29 11:11:45 -06:00 committed by Anthony Fieroni
parent 2aa33f2a36
commit 197f8427c4
6 changed files with 16 additions and 26 deletions

View file

@ -156,7 +156,7 @@ bool CBloomFilter::IsRelevantAndUpdate(const CTransaction& tx)
else if ((nFlags & BLOOM_UPDATE_MASK) == BLOOM_UPDATE_P2PUBKEY_ONLY) else if ((nFlags & BLOOM_UPDATE_MASK) == BLOOM_UPDATE_P2PUBKEY_ONLY)
{ {
std::vector<std::vector<unsigned char> > vSolutions; std::vector<std::vector<unsigned char> > vSolutions;
const CScript& scriptPubKey = StripClaimScriptPrefix(txout.scriptPubKey); const CScript& scriptPubKey = txout.scriptPubKey;
txnouttype type = Solver(scriptPubKey, vSolutions); txnouttype type = Solver(scriptPubKey, vSolutions);
if (type == TX_PUBKEY || type == TX_MULTISIG) { if (type == TX_PUBKEY || type == TX_MULTISIG) {
insert(COutPoint(hash, i)); insert(COutPoint(hash, i));

View file

@ -10,7 +10,7 @@
#include <consensus/validation.h> #include <consensus/validation.h>
#include <coins.h> #include <coins.h>
#include "nameclaim.h" #include <nameclaim.h>
CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn) CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
@ -114,8 +114,7 @@ bool IsStandardTx(const CTransaction& tx, bool permit_bare_multisig, const CFeeR
unsigned int nDataOut = 0; unsigned int nDataOut = 0;
txnouttype whichType; txnouttype whichType;
for (const CTxOut& txout : tx.vout) { for (const CTxOut& txout : tx.vout) {
const CScript& scriptPubKey = StripClaimScriptPrefix(txout.scriptPubKey); if (!::IsStandard(txout.scriptPubKey, whichType)) {
if (!::IsStandard(scriptPubKey, whichType)) {
reason = "scriptpubkey"; reason = "scriptpubkey";
return false; return false;
} }
@ -166,7 +165,7 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
const CTxOut& prev = mapInputs.AccessCoin(tx.vin[i].prevout).out; const CTxOut& prev = mapInputs.AccessCoin(tx.vin[i].prevout).out;
std::vector<std::vector<unsigned char> > vSolutions; std::vector<std::vector<unsigned char> > vSolutions;
const CScript& prevScript = StripClaimScriptPrefix(prev.scriptPubKey); const CScript& prevScript = prev.scriptPubKey;
txnouttype whichType = Solver(prevScript, vSolutions); txnouttype whichType = Solver(prevScript, vSolutions);
if (whichType == TX_NONSTANDARD) { if (whichType == TX_NONSTANDARD) {
return false; return false;

View file

@ -12,8 +12,6 @@
#include <script/standard.h> #include <script/standard.h>
#include <uint256.h> #include <uint256.h>
#include "nameclaim.h"
typedef std::vector<unsigned char> valtype; typedef std::vector<unsigned char> valtype;
MutableTransactionSignatureCreator::MutableTransactionSignatureCreator(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {} MutableTransactionSignatureCreator::MutableTransactionSignatureCreator(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {}
@ -105,10 +103,8 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator
ret.clear(); ret.clear();
std::vector<unsigned char> sig; std::vector<unsigned char> sig;
const CScript& strippedScriptPubKey = StripClaimScriptPrefix(scriptPubKey);
std::vector<valtype> vSolutions; std::vector<valtype> vSolutions;
whichTypeRet = Solver(strippedScriptPubKey, vSolutions); whichTypeRet = Solver(scriptPubKey, vSolutions);
switch (whichTypeRet) switch (whichTypeRet)
{ {

View file

@ -31,7 +31,6 @@ const char* GetTxnOutputType(txnouttype t)
switch (t) switch (t)
{ {
case TX_NONSTANDARD: return "nonstandard"; case TX_NONSTANDARD: return "nonstandard";
case TX_CLAIM: return "claim";
case TX_PUBKEY: return "pubkey"; case TX_PUBKEY: return "pubkey";
case TX_PUBKEYHASH: return "pubkeyhash"; case TX_PUBKEYHASH: return "pubkeyhash";
case TX_SCRIPTHASH: return "scripthash"; case TX_SCRIPTHASH: return "scripthash";
@ -94,18 +93,20 @@ txnouttype Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned
{ {
vSolutionsRet.clear(); vSolutionsRet.clear();
auto strippedPubKey = StripClaimScriptPrefix(scriptPubKey);
// Shortcut for pay-to-script-hash, which are more constrained than the other types: // Shortcut for pay-to-script-hash, which are more constrained than the other types:
// it is always OP_HASH160 20 [20 byte hash] OP_EQUAL // it is always OP_HASH160 20 [20 byte hash] OP_EQUAL
if (scriptPubKey.IsPayToScriptHash()) if (strippedPubKey.IsPayToScriptHash())
{ {
std::vector<unsigned char> hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22); std::vector<unsigned char> hashBytes(strippedPubKey.begin()+2, strippedPubKey.begin()+22);
vSolutionsRet.push_back(hashBytes); vSolutionsRet.push_back(hashBytes);
return TX_SCRIPTHASH; return TX_SCRIPTHASH;
} }
int witnessversion; int witnessversion;
std::vector<unsigned char> witnessprogram; std::vector<unsigned char> witnessprogram;
if (scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram)) { if (strippedPubKey.IsWitnessProgram(witnessversion, witnessprogram)) {
if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_KEYHASH_SIZE) { if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_KEYHASH_SIZE) {
vSolutionsRet.push_back(witnessprogram); vSolutionsRet.push_back(witnessprogram);
return TX_WITNESS_V0_KEYHASH; return TX_WITNESS_V0_KEYHASH;
@ -127,24 +128,24 @@ txnouttype Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned
// So long as script passes the IsUnspendable() test and all but the first // So long as script passes the IsUnspendable() test and all but the first
// byte passes the IsPushOnly() test we don't care what exactly is in the // byte passes the IsPushOnly() test we don't care what exactly is in the
// script. // script.
if (scriptPubKey.size() >= 1 && scriptPubKey[0] == OP_RETURN && scriptPubKey.IsPushOnly(scriptPubKey.begin()+1)) { if (strippedPubKey.size() >= 1 && strippedPubKey[0] == OP_RETURN && strippedPubKey.IsPushOnly(strippedPubKey.begin()+1)) {
return TX_NULL_DATA; return TX_NULL_DATA;
} }
std::vector<unsigned char> data; std::vector<unsigned char> data;
if (MatchPayToPubkey(scriptPubKey, data)) { if (MatchPayToPubkey(strippedPubKey, data)) {
vSolutionsRet.push_back(std::move(data)); vSolutionsRet.push_back(std::move(data));
return TX_PUBKEY; return TX_PUBKEY;
} }
if (MatchPayToPubkeyHash(scriptPubKey, data)) { if (MatchPayToPubkeyHash(strippedPubKey, data)) {
vSolutionsRet.push_back(std::move(data)); vSolutionsRet.push_back(std::move(data));
return TX_PUBKEYHASH; return TX_PUBKEYHASH;
} }
unsigned int required; unsigned int required;
std::vector<std::vector<unsigned char>> keys; std::vector<std::vector<unsigned char>> keys;
if (MatchMultisig(scriptPubKey, required, keys)) { if (MatchMultisig(strippedPubKey, required, keys)) {
vSolutionsRet.push_back({static_cast<unsigned char>(required)}); // safe as required is in range 1..16 vSolutionsRet.push_back({static_cast<unsigned char>(required)}); // safe as required is in range 1..16
vSolutionsRet.insert(vSolutionsRet.end(), keys.begin(), keys.end()); vSolutionsRet.insert(vSolutionsRet.end(), keys.begin(), keys.end());
vSolutionsRet.push_back({static_cast<unsigned char>(keys.size())}); // safe as size is in range 1..16 vSolutionsRet.push_back({static_cast<unsigned char>(keys.size())}); // safe as size is in range 1..16
@ -152,10 +153,7 @@ txnouttype Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned
} }
vSolutionsRet.clear(); vSolutionsRet.clear();
return TX_NONSTANDARD;
int op;
std::vector<std::vector<unsigned char> > vvchParams;
return (DecodeClaimScript(scriptPubKey, op, vvchParams)) ? TX_CLAIM : TX_NONSTANDARD;
} }
bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet) bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)

View file

@ -56,7 +56,6 @@ static const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS = SCRIPT_VERIFY_P2SH;
enum txnouttype enum txnouttype
{ {
TX_NONSTANDARD, TX_NONSTANDARD,
TX_CLAIM,
// 'standard' transaction types: // 'standard' transaction types:
TX_PUBKEY, TX_PUBKEY,
TX_PUBKEYHASH, TX_PUBKEYHASH,

View file

@ -1994,9 +1994,7 @@ void CWalletTx::GetAmounts(std::list<COutputEntry>& listReceived,
// In either case, we need to get the destination address // In either case, we need to get the destination address
CTxDestination address; CTxDestination address;
const CScript& scriptPubKey = StripClaimScriptPrefix(txout.scriptPubKey); if (!ExtractDestination(txout.scriptPubKey, address) && !txout.scriptPubKey.IsUnspendable())
if (!ExtractDestination(scriptPubKey, address) && !scriptPubKey.IsUnspendable())
{ {
pwallet->WalletLogPrintf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n", pwallet->WalletLogPrintf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
this->GetHash().ToString()); this->GetHash().ToString());