Changeset View
Changeset View
Standalone View
Standalone View
src/script/ismine.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <script/ismine.h> | #include <script/ismine.h> | ||||
#include <key.h> | #include <key.h> | ||||
#include <keystore.h> | #include <keystore.h> | ||||
#include <script/script.h> | #include <script/script.h> | ||||
#include <script/sign.h> | #include <script/sign.h> | ||||
#include <script/standard.h> | #include <script/standard.h> | ||||
typedef std::vector<uint8_t> valtype; | typedef std::vector<uint8_t> valtype; | ||||
unsigned int HaveKeys(const std::vector<valtype> &pubkeys, | static bool HaveKeys(const std::vector<valtype> &pubkeys, | ||||
const CKeyStore &keystore) { | const CKeyStore &keystore) { | ||||
unsigned int nResult = 0; | |||||
for (const valtype &pubkey : pubkeys) { | for (const valtype &pubkey : pubkeys) { | ||||
CKeyID keyID = CPubKey(pubkey).GetID(); | CKeyID keyID = CPubKey(pubkey).GetID(); | ||||
if (keystore.HaveKey(keyID)) ++nResult; | if (!keystore.HaveKey(keyID)) { | ||||
return false; | |||||
} | } | ||||
return nResult; | } | ||||
return true; | |||||
} | } | ||||
isminetype IsMine(const CKeyStore &keystore, const CScript &scriptPubKey) { | isminetype IsMine(const CKeyStore &keystore, const CScript &scriptPubKey) { | ||||
bool isInvalid = false; | bool isInvalid = false; | ||||
return IsMine(keystore, scriptPubKey, isInvalid); | return IsMine(keystore, scriptPubKey, isInvalid); | ||||
} | } | ||||
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest) { | isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest) { | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | switch (whichType) { | ||||
// Only consider transactions "mine" if we own ALL the keys | // Only consider transactions "mine" if we own ALL the keys | ||||
// involved. Multi-signature transactions that are partially owned | // involved. Multi-signature transactions that are partially owned | ||||
// (somebody else has a key that can spend them) enable | // (somebody else has a key that can spend them) enable | ||||
// spend-out-from-under-you attacks, especially in shared-wallet | // spend-out-from-under-you attacks, especially in shared-wallet | ||||
// situations. | // situations. | ||||
std::vector<valtype> keys(vSolutions.begin() + 1, | std::vector<valtype> keys(vSolutions.begin() + 1, | ||||
vSolutions.begin() + vSolutions.size() - | vSolutions.begin() + vSolutions.size() - | ||||
1); | 1); | ||||
if (HaveKeys(keys, keystore) == keys.size()) | if (HaveKeys(keys, keystore)) { | ||||
return ISMINE_SPENDABLE; | return ISMINE_SPENDABLE; | ||||
} | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (keystore.HaveWatchOnly(scriptPubKey)) { | if (keystore.HaveWatchOnly(scriptPubKey)) { | ||||
// TODO: This could be optimized some by doing some work after the above | // TODO: This could be optimized some by doing some work after the above | ||||
// solver | // solver | ||||
SignatureData sigs; | SignatureData sigs; | ||||
return ProduceSignature(DummySignatureCreator(&keystore), scriptPubKey, | return ProduceSignature(DummySignatureCreator(&keystore), scriptPubKey, | ||||
sigs) | sigs) | ||||
? ISMINE_WATCH_SOLVABLE | ? ISMINE_WATCH_SOLVABLE | ||||
: ISMINE_WATCH_UNSOLVABLE; | : ISMINE_WATCH_UNSOLVABLE; | ||||
} | } | ||||
return ISMINE_NO; | return ISMINE_NO; | ||||
} | } |