You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.6 KiB
92 lines
2.6 KiB
15 years ago
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||
10 years ago
|
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
||
10 years ago
|
// Distributed under the MIT software license, see the accompanying
|
||
13 years ago
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||
12 years ago
|
|
||
10 years ago
|
#include "wallet_ismine.h"
|
||
12 years ago
|
|
||
13 years ago
|
#include "key.h"
|
||
12 years ago
|
#include "keystore.h"
|
||
10 years ago
|
#include "script/script.h"
|
||
10 years ago
|
#include "script/standard.h"
|
||
13 years ago
|
|
||
12 years ago
|
#include <boost/foreach.hpp>
|
||
10 years ago
|
|
||
12 years ago
|
using namespace std;
|
||
|
|
||
15 years ago
|
typedef vector<unsigned char> valtype;
|
||
|
|
||
13 years ago
|
unsigned int HaveKeys(const vector<valtype>& pubkeys, const CKeyStore& keystore)
|
||
13 years ago
|
{
|
||
13 years ago
|
unsigned int nResult = 0;
|
||
13 years ago
|
BOOST_FOREACH(const valtype& pubkey, pubkeys)
|
||
|
{
|
||
13 years ago
|
CKeyID keyID = CPubKey(pubkey).GetID();
|
||
|
if (keystore.HaveKey(keyID))
|
||
13 years ago
|
++nResult;
|
||
|
}
|
||
|
return nResult;
|
||
|
}
|
||
|
|
||
11 years ago
|
isminetype IsMine(const CKeyStore &keystore, const CTxDestination& dest)
|
||
13 years ago
|
{
|
||
10 years ago
|
CScript script = GetScriptForDestination(dest);
|
||
11 years ago
|
return IsMine(keystore, script);
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey)
|
||
15 years ago
|
{
|
||
13 years ago
|
vector<valtype> vSolutions;
|
||
13 years ago
|
txnouttype whichType;
|
||
12 years ago
|
if (!Solver(scriptPubKey, whichType, vSolutions)) {
|
||
11 years ago
|
if (keystore.HaveWatchOnly(scriptPubKey))
|
||
11 years ago
|
return ISMINE_WATCH_ONLY;
|
||
|
return ISMINE_NO;
|
||
12 years ago
|
}
|
||
14 years ago
|
|
||
13 years ago
|
CKeyID keyID;
|
||
13 years ago
|
switch (whichType)
|
||
14 years ago
|
{
|
||
13 years ago
|
case TX_NONSTANDARD:
|
||
12 years ago
|
case TX_NULL_DATA:
|
||
12 years ago
|
break;
|
||
13 years ago
|
case TX_PUBKEY:
|
||
13 years ago
|
keyID = CPubKey(vSolutions[0]).GetID();
|
||
12 years ago
|
if (keystore.HaveKey(keyID))
|
||
11 years ago
|
return ISMINE_SPENDABLE;
|
||
12 years ago
|
break;
|
||
13 years ago
|
case TX_PUBKEYHASH:
|
||
13 years ago
|
keyID = CKeyID(uint160(vSolutions[0]));
|
||
12 years ago
|
if (keystore.HaveKey(keyID))
|
||
11 years ago
|
return ISMINE_SPENDABLE;
|
||
12 years ago
|
break;
|
||
13 years ago
|
case TX_SCRIPTHASH:
|
||
|
{
|
||
12 years ago
|
CScriptID scriptID = CScriptID(uint160(vSolutions[0]));
|
||
13 years ago
|
CScript subscript;
|
||
12 years ago
|
if (keystore.GetCScript(scriptID, subscript)) {
|
||
|
isminetype ret = IsMine(keystore, subscript);
|
||
11 years ago
|
if (ret == ISMINE_SPENDABLE)
|
||
12 years ago
|
return ret;
|
||
|
}
|
||
|
break;
|
||
14 years ago
|
}
|
||
13 years ago
|
case TX_MULTISIG:
|
||
|
{
|
||
|
// Only consider transactions "mine" if we own ALL the
|
||
10 years ago
|
// keys involved. Multi-signature transactions that are
|
||
13 years ago
|
// partially owned (somebody else has a key that can spend
|
||
|
// them) enable spend-out-from-under-you attacks, especially
|
||
|
// in shared-wallet situations.
|
||
|
vector<valtype> keys(vSolutions.begin()+1, vSolutions.begin()+vSolutions.size()-1);
|
||
12 years ago
|
if (HaveKeys(keys, keystore) == keys.size())
|
||
11 years ago
|
return ISMINE_SPENDABLE;
|
||
12 years ago
|
break;
|
||
13 years ago
|
}
|
||
|
}
|
||
12 years ago
|
|
||
11 years ago
|
if (keystore.HaveWatchOnly(scriptPubKey))
|
||
11 years ago
|
return ISMINE_WATCH_ONLY;
|
||
|
return ISMINE_NO;
|
||
15 years ago
|
}
|