Fix a bug that treats all claims as our own wallet txs.
This commit is contained in:
parent
0c130f40c7
commit
3340fcb85a
2 changed files with 29 additions and 12 deletions
|
@ -6,6 +6,7 @@
|
|||
#include <wallet/ismine.h>
|
||||
|
||||
#include <key.h>
|
||||
#include <nameclaim.h>
|
||||
#include <script/script.h>
|
||||
#include <script/sign.h>
|
||||
#include <script/signingprovider.h>
|
||||
|
@ -39,6 +40,8 @@ enum class IsMineResult
|
|||
WATCH_ONLY = 1, //!< Included in watch-only balance
|
||||
SPENDABLE = 2, //!< Included in all balances
|
||||
INVALID = 3, //!< Not spendable by anyone (uncompressed pubkey in segwit, P2SH inside P2SH or witness, witness inside witness)
|
||||
CLAIM = 4,
|
||||
SUPPORT = 5,
|
||||
};
|
||||
|
||||
bool PermitsUncompressed(IsMineSigVersion sigversion)
|
||||
|
@ -57,7 +60,15 @@ bool HaveKeys(const std::vector<valtype>& pubkeys, const CWallet& keystore)
|
|||
|
||||
IsMineResult IsMineInner(const CWallet& keystore, const CScript& scriptPubKey, IsMineSigVersion sigversion)
|
||||
{
|
||||
int op = 0;
|
||||
IsMineResult ret = IsMineResult::NO;
|
||||
IsMineResult claim_ret = IsMineResult::NO;
|
||||
|
||||
CScript strippedScriptPubKey = StripClaimScriptPrefix(scriptPubKey, op);
|
||||
if (strippedScriptPubKey != scriptPubKey)
|
||||
claim_ret = ((op == OP_CLAIM_NAME || op == OP_UPDATE_CLAIM) ? IsMineResult::CLAIM :
|
||||
((op == OP_SUPPORT_CLAIM) ? IsMineResult::SUPPORT :
|
||||
IsMineResult::NO));
|
||||
|
||||
std::vector<valtype> vSolutions;
|
||||
txnouttype whichType = Solver(scriptPubKey, vSolutions);
|
||||
|
@ -75,7 +86,7 @@ IsMineResult IsMineInner(const CWallet& keystore, const CScript& scriptPubKey, I
|
|||
return IsMineResult::INVALID;
|
||||
}
|
||||
if (keystore.HaveKey(keyID)) {
|
||||
ret = std::max(ret, IsMineResult::SPENDABLE);
|
||||
ret = std::max(claim_ret, IsMineResult::SPENDABLE);
|
||||
}
|
||||
break;
|
||||
case TX_WITNESS_V0_KEYHASH:
|
||||
|
@ -90,6 +101,10 @@ IsMineResult IsMineInner(const CWallet& keystore, const CScript& scriptPubKey, I
|
|||
// This also applies to the P2WSH case.
|
||||
break;
|
||||
}
|
||||
// Claims are not explicitly supported on Witness v0
|
||||
// Transactions, and instead of supporting the wrapped inner
|
||||
// tx, we are ignoring this type at this time (consistent with
|
||||
// previous releases).
|
||||
ret = std::max(ret, IsMineInner(keystore, GetScriptForDestination(PKHash(uint160(vSolutions[0]))), IsMineSigVersion::WITNESS_V0));
|
||||
break;
|
||||
}
|
||||
|
@ -102,7 +117,7 @@ IsMineResult IsMineInner(const CWallet& keystore, const CScript& scriptPubKey, I
|
|||
}
|
||||
}
|
||||
if (keystore.HaveKey(keyID)) {
|
||||
ret = std::max(ret, IsMineResult::SPENDABLE);
|
||||
ret = std::max(claim_ret, IsMineResult::SPENDABLE);
|
||||
}
|
||||
break;
|
||||
case TX_SCRIPTHASH:
|
||||
|
@ -114,7 +129,7 @@ IsMineResult IsMineInner(const CWallet& keystore, const CScript& scriptPubKey, I
|
|||
CScriptID scriptID = CScriptID(uint160(vSolutions[0]));
|
||||
CScript subscript;
|
||||
if (keystore.GetCScript(scriptID, subscript)) {
|
||||
ret = std::max(ret, IsMineInner(keystore, subscript, IsMineSigVersion::P2SH));
|
||||
ret = std::max(claim_ret, IsMineInner(keystore, subscript, IsMineSigVersion::P2SH));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -132,6 +147,10 @@ IsMineResult IsMineInner(const CWallet& keystore, const CScript& scriptPubKey, I
|
|||
CScriptID scriptID = CScriptID(hash);
|
||||
CScript subscript;
|
||||
if (keystore.GetCScript(scriptID, subscript)) {
|
||||
// Claims are not explicitly supported on Witness v0
|
||||
// Transactions, and instead of supporting the wrapped inner
|
||||
// tx, we are ignoring this type at this time (consistent with
|
||||
// previous releases).
|
||||
ret = std::max(ret, IsMineInner(keystore, subscript, IsMineSigVersion::WITNESS_V0));
|
||||
}
|
||||
break;
|
||||
|
@ -158,14 +177,14 @@ IsMineResult IsMineInner(const CWallet& keystore, const CScript& scriptPubKey, I
|
|||
}
|
||||
}
|
||||
if (HaveKeys(keys, keystore)) {
|
||||
ret = std::max(ret, IsMineResult::SPENDABLE);
|
||||
ret = std::max(claim_ret, IsMineResult::SPENDABLE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == IsMineResult::NO && keystore.HaveWatchOnly(scriptPubKey)) {
|
||||
ret = std::max(ret, IsMineResult::WATCH_ONLY);
|
||||
ret = std::max(claim_ret, IsMineResult::WATCH_ONLY);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -182,6 +201,10 @@ isminetype IsMine(const CWallet& keystore, const CScript& scriptPubKey)
|
|||
return ISMINE_WATCH_ONLY;
|
||||
case IsMineResult::SPENDABLE:
|
||||
return ISMINE_SPENDABLE;
|
||||
case IsMineResult::CLAIM:
|
||||
return ISMINE_CLAIM;
|
||||
case IsMineResult::SUPPORT:
|
||||
return ISMINE_SUPPORT;
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
|
|
|
@ -1542,13 +1542,7 @@ CAmount CWallet::GetDebit(const CTxIn &txin, const isminefilter& filter) const
|
|||
|
||||
isminetype CWallet::IsMine(const CTxOut& txout) const
|
||||
{
|
||||
int op = 0;
|
||||
auto script = StripClaimScriptPrefix(txout.scriptPubKey, op);
|
||||
if (op == OP_CLAIM_NAME)
|
||||
return isminetype::ISMINE_CLAIM;
|
||||
if (op == OP_SUPPORT_CLAIM)
|
||||
return isminetype::ISMINE_SUPPORT;
|
||||
return ::IsMine(*this, script);
|
||||
return ::IsMine(*this, txout.scriptPubKey);
|
||||
}
|
||||
|
||||
CAmount CWallet::GetCredit(const CTxOut& txout, const isminefilter& filter) const
|
||||
|
|
Loading…
Add table
Reference in a new issue