simplified claim stripping, removed TX_CLAIM

This commit is contained in:
Brannon King 2019-08-29 11:11:45 -06:00
parent a84c196916
commit b3c5b1e88d
6 changed files with 16 additions and 31 deletions

View file

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

View file

@ -10,11 +10,9 @@
#include <consensus/validation.h> #include <consensus/validation.h>
#include <validation.h> #include <validation.h>
#include <coins.h> #include <coins.h>
#include <tinyformat.h>
#include <util.h>
#include <utilstrencodings.h> #include <utilstrencodings.h>
#include "nameclaim.h" #include <nameclaim.h>
CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn) CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
@ -117,8 +115,7 @@ bool IsStandardTx(const CTransaction& tx, std::string& reason)
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;
} }
@ -171,8 +168,7 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
std::vector<std::vector<unsigned char> > vSolutions; std::vector<std::vector<unsigned char> > vSolutions;
txnouttype whichType; txnouttype whichType;
// get the scriptPubKey corresponding to this input: // get the scriptPubKey corresponding to this input:
const CScript& prevScript = StripClaimScriptPrefix(prev.scriptPubKey); if (!Solver(prev.scriptPubKey, whichType, vSolutions))
if (!Solver(prevScript, whichType, vSolutions))
return false; return false;
if (whichType == TX_SCRIPTHASH) if (whichType == TX_SCRIPTHASH)

View file

@ -11,8 +11,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) {}
@ -102,10 +100,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;
if (!Solver(strippedScriptPubKey, whichTypeRet, vSolutions)) if (!Solver(scriptPubKey, whichTypeRet, vSolutions))
return false; return false;
switch (whichTypeRet) switch (whichTypeRet)

View file

@ -9,7 +9,6 @@
#include <nameclaim.h> #include <nameclaim.h>
#include <pubkey.h> #include <pubkey.h>
#include <script/script.h> #include <script/script.h>
#include <util.h>
#include <utilstrencodings.h> #include <utilstrencodings.h>
@ -30,7 +29,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";
@ -93,19 +91,21 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::v
{ {
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())
{ {
typeRet = TX_SCRIPTHASH; typeRet = TX_SCRIPTHASH;
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 true; return true;
} }
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) {
typeRet = TX_WITNESS_V0_KEYHASH; typeRet = TX_WITNESS_V0_KEYHASH;
vSolutionsRet.push_back(witnessprogram); vSolutionsRet.push_back(witnessprogram);
@ -131,19 +131,19 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::v
// 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)) {
typeRet = TX_NULL_DATA; typeRet = TX_NULL_DATA;
return true; return true;
} }
std::vector<unsigned char> data; std::vector<unsigned char> data;
if (MatchPayToPubkey(scriptPubKey, data)) { if (MatchPayToPubkey(strippedPubKey, data)) {
typeRet = TX_PUBKEY; typeRet = TX_PUBKEY;
vSolutionsRet.push_back(std::move(data)); vSolutionsRet.push_back(std::move(data));
return true; return true;
} }
if (MatchPayToPubkeyHash(scriptPubKey, data)) { if (MatchPayToPubkeyHash(strippedPubKey, data)) {
typeRet = TX_PUBKEYHASH; typeRet = TX_PUBKEYHASH;
vSolutionsRet.push_back(std::move(data)); vSolutionsRet.push_back(std::move(data));
return true; return true;
@ -151,7 +151,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::v
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)) {
typeRet = TX_MULTISIG; typeRet = TX_MULTISIG;
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());
@ -160,10 +160,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::v
} }
vSolutionsRet.clear(); vSolutionsRet.clear();
typeRet = TX_NONSTANDARD;
int op;
std::vector<std::vector<unsigned char> > vvchParams;
typeRet = (DecodeClaimScript(scriptPubKey, op, vvchParams)) ? TX_CLAIM : TX_NONSTANDARD;
return false; return false;
} }

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

@ -1692,9 +1692,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());