|
|
@ -29,13 +29,25 @@ unsigned int HaveKeys(const vector<valtype>& pubkeys, const CKeyStore& keystore) |
|
|
|
return nResult; |
|
|
|
return nResult; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
isminetype IsMine(const CKeyStore &keystore, const CTxDestination& dest) |
|
|
|
isminetype IsMine(const CKeyStore& keystore, const CScript& scriptPubKey, SigVersion sigversion) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
bool isInvalid = false; |
|
|
|
|
|
|
|
return IsMine(keystore, scriptPubKey, isInvalid, sigversion); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isminetype IsMine(const CKeyStore& keystore, const CTxDestination& dest, SigVersion sigversion) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
bool isInvalid = false; |
|
|
|
|
|
|
|
return IsMine(keystore, dest, isInvalid, sigversion); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isminetype IsMine(const CKeyStore &keystore, const CTxDestination& dest, bool& isInvalid, SigVersion sigversion) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CScript script = GetScriptForDestination(dest); |
|
|
|
CScript script = GetScriptForDestination(dest); |
|
|
|
return IsMine(keystore, script); |
|
|
|
return IsMine(keystore, script, isInvalid, sigversion); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey) |
|
|
|
isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey, bool& isInvalid, SigVersion sigversion) |
|
|
|
{ |
|
|
|
{ |
|
|
|
vector<valtype> vSolutions; |
|
|
|
vector<valtype> vSolutions; |
|
|
|
txnouttype whichType; |
|
|
|
txnouttype whichType; |
|
|
@ -53,12 +65,35 @@ isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey) |
|
|
|
break; |
|
|
|
break; |
|
|
|
case TX_PUBKEY: |
|
|
|
case TX_PUBKEY: |
|
|
|
keyID = CPubKey(vSolutions[0]).GetID(); |
|
|
|
keyID = CPubKey(vSolutions[0]).GetID(); |
|
|
|
|
|
|
|
if (sigversion != SIGVERSION_BASE && vSolutions[0].size() != 33) { |
|
|
|
|
|
|
|
isInvalid = true; |
|
|
|
|
|
|
|
return ISMINE_NO; |
|
|
|
|
|
|
|
} |
|
|
|
if (keystore.HaveKey(keyID)) |
|
|
|
if (keystore.HaveKey(keyID)) |
|
|
|
return ISMINE_SPENDABLE; |
|
|
|
return ISMINE_SPENDABLE; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case TX_PUBKEYHASH: |
|
|
|
|
|
|
|
case TX_WITNESS_V0_KEYHASH: |
|
|
|
case TX_WITNESS_V0_KEYHASH: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!keystore.HaveCScript(CScriptID(CScript() << OP_0 << vSolutions[0]))) { |
|
|
|
|
|
|
|
// We do not support bare witness outputs unless the P2SH version of it would be
|
|
|
|
|
|
|
|
// acceptable as well. This protects against matching before segwit activates.
|
|
|
|
|
|
|
|
// This also applies to the P2WSH case.
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
isminetype ret = ::IsMine(keystore, GetScriptForDestination(CKeyID(uint160(vSolutions[0]))), isInvalid, SIGVERSION_WITNESS_V0); |
|
|
|
|
|
|
|
if (ret == ISMINE_SPENDABLE || ret == ISMINE_WATCH_SOLVABLE || (ret == ISMINE_NO && isInvalid)) |
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case TX_PUBKEYHASH: |
|
|
|
keyID = CKeyID(uint160(vSolutions[0])); |
|
|
|
keyID = CKeyID(uint160(vSolutions[0])); |
|
|
|
|
|
|
|
if (sigversion != SIGVERSION_BASE) { |
|
|
|
|
|
|
|
CPubKey pubkey; |
|
|
|
|
|
|
|
if (keystore.GetPubKey(keyID, pubkey) && !pubkey.IsCompressed()) { |
|
|
|
|
|
|
|
isInvalid = true; |
|
|
|
|
|
|
|
return ISMINE_NO; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if (keystore.HaveKey(keyID)) |
|
|
|
if (keystore.HaveKey(keyID)) |
|
|
|
return ISMINE_SPENDABLE; |
|
|
|
return ISMINE_SPENDABLE; |
|
|
|
break; |
|
|
|
break; |
|
|
@ -67,21 +102,24 @@ isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey) |
|
|
|
CScriptID scriptID = CScriptID(uint160(vSolutions[0])); |
|
|
|
CScriptID scriptID = CScriptID(uint160(vSolutions[0])); |
|
|
|
CScript subscript; |
|
|
|
CScript subscript; |
|
|
|
if (keystore.GetCScript(scriptID, subscript)) { |
|
|
|
if (keystore.GetCScript(scriptID, subscript)) { |
|
|
|
isminetype ret = IsMine(keystore, subscript); |
|
|
|
isminetype ret = IsMine(keystore, subscript, isInvalid); |
|
|
|
if (ret == ISMINE_SPENDABLE) |
|
|
|
if (ret == ISMINE_SPENDABLE || ret == ISMINE_WATCH_SOLVABLE || (ret == ISMINE_NO && isInvalid)) |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
case TX_WITNESS_V0_SCRIPTHASH: |
|
|
|
case TX_WITNESS_V0_SCRIPTHASH: |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (!keystore.HaveCScript(CScriptID(CScript() << OP_0 << vSolutions[0]))) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
uint160 hash; |
|
|
|
uint160 hash; |
|
|
|
CRIPEMD160().Write(&vSolutions[0][0], vSolutions[0].size()).Finalize(hash.begin()); |
|
|
|
CRIPEMD160().Write(&vSolutions[0][0], vSolutions[0].size()).Finalize(hash.begin()); |
|
|
|
CScriptID scriptID = CScriptID(hash); |
|
|
|
CScriptID scriptID = CScriptID(hash); |
|
|
|
CScript subscript; |
|
|
|
CScript subscript; |
|
|
|
if (keystore.GetCScript(scriptID, subscript)) { |
|
|
|
if (keystore.GetCScript(scriptID, subscript)) { |
|
|
|
isminetype ret = IsMine(keystore, subscript); |
|
|
|
isminetype ret = IsMine(keystore, subscript, isInvalid, SIGVERSION_WITNESS_V0); |
|
|
|
if (ret == ISMINE_SPENDABLE) |
|
|
|
if (ret == ISMINE_SPENDABLE || ret == ISMINE_WATCH_SOLVABLE || (ret == ISMINE_NO && isInvalid)) |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -95,6 +133,14 @@ isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey) |
|
|
|
// them) enable spend-out-from-under-you attacks, especially
|
|
|
|
// them) enable spend-out-from-under-you attacks, especially
|
|
|
|
// in shared-wallet situations.
|
|
|
|
// in shared-wallet situations.
|
|
|
|
vector<valtype> keys(vSolutions.begin()+1, vSolutions.begin()+vSolutions.size()-1); |
|
|
|
vector<valtype> keys(vSolutions.begin()+1, vSolutions.begin()+vSolutions.size()-1); |
|
|
|
|
|
|
|
if (sigversion != SIGVERSION_BASE) { |
|
|
|
|
|
|
|
for (size_t i = 0; i < keys.size(); i++) { |
|
|
|
|
|
|
|
if (keys[i].size() != 33) { |
|
|
|
|
|
|
|
isInvalid = true; |
|
|
|
|
|
|
|
return ISMINE_NO; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if (HaveKeys(keys, keystore) == keys.size()) |
|
|
|
if (HaveKeys(keys, keystore) == keys.size()) |
|
|
|
return ISMINE_SPENDABLE; |
|
|
|
return ISMINE_SPENDABLE; |
|
|
|
break; |
|
|
|
break; |
|
|
|