Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

ismine.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <script/ismine.h>
7 
8 #include <key.h>
9 #include <keystore.h>
10 #include <script/script.h>
11 #include <script/sign.h>
12 
13 
14 typedef std::vector<unsigned char> valtype;
15 
16 unsigned int HaveKeys(const std::vector<valtype>& pubkeys, const CKeyStore& keystore)
17 {
18  unsigned int nResult = 0;
19  for (const valtype& pubkey : pubkeys)
20  {
21  CKeyID keyID = CPubKey(pubkey).GetID();
22  if (keystore.HaveKey(keyID))
23  ++nResult;
24  }
25  return nResult;
26 }
27 
28 isminetype IsMine(const CKeyStore &keystore, const CTxDestination& dest)
29 {
30  CScript script = GetScriptForDestination(dest);
31  return IsMine(keystore, script);
32 }
33 
34 isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey)
35 {
36  std::vector<valtype> vSolutions;
37  txnouttype whichType;
38  if (!Solver(scriptPubKey, whichType, vSolutions)) {
39  if (keystore.HaveWatchOnly(scriptPubKey))
41  return ISMINE_NO;
42  }
43 
44  CKeyID keyID;
45  switch (whichType)
46  {
47  case TX_NONSTANDARD:
48  case TX_NULL_DATA:
49  break;
50  case TX_PUBKEY:
51  keyID = CPubKey(vSolutions[0]).GetID();
52  if (keystore.HaveKey(keyID))
53  return ISMINE_SPENDABLE;
54  break;
55  case TX_PUBKEYHASH:
56  keyID = CKeyID(uint160(vSolutions[0]));
57  if (keystore.HaveKey(keyID))
58  return ISMINE_SPENDABLE;
59  break;
60  case TX_SCRIPTHASH:
61  {
62  CScriptID scriptID = CScriptID(uint160(vSolutions[0]));
63  CScript subscript;
64  if (keystore.GetCScript(scriptID, subscript)) {
65  isminetype ret = IsMine(keystore, subscript);
66  if (ret == ISMINE_SPENDABLE)
67  return ret;
68  }
69  break;
70  }
71  case TX_MULTISIG:
72  {
73  // Only consider transactions "mine" if we own ALL the
74  // keys involved. Multi-signature transactions that are
75  // partially owned (somebody else has a key that can spend
76  // them) enable spend-out-from-under-you attacks, especially
77  // in shared-wallet situations.
78  std::vector<valtype> keys(vSolutions.begin()+1, vSolutions.begin()+vSolutions.size()-1);
79  if (HaveKeys(keys, keystore) == keys.size())
80  return ISMINE_SPENDABLE;
81  break;
82  }
83  }
84 
85  if (keystore.HaveWatchOnly(scriptPubKey)) {
86  // TODO: This could be optimized some by doing some work after the above solver
87  SignatureData sigs;
89  }
90  return ISMINE_NO;
91 }
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:80
unspendable OP_RETURN script that carries data
Definition: standard.h:64
std::vector< unsigned char > valtype
Definition: ismine.cpp:14
bool ProduceSignature(const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
Definition: sign.cpp:124
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:149
Indicates that we don&#39;t know how to create a scriptSig that would solve this if we were given the app...
Definition: ismine.h:21
unsigned int HaveKeys(const std::vector< valtype > &pubkeys, const CKeyStore &keystore)
Definition: ismine.cpp:16
isminetype
IsMine() return codes.
Definition: ismine.h:17
virtual bool HaveKey(const CKeyID &address) const =0
Check whether a key corresponding to a given address is present in the store.
An encapsulated public key.
Definition: pubkey.h:30
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:256
bool Solver(const CScript &scriptPubKey, txnouttype &typeRet, std::vector< std::vector< unsigned char > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
Definition: standard.cpp:35
virtual bool HaveWatchOnly(const CScript &dest) const =0
txnouttype
Definition: standard.h:56
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:389
A virtual base class for key stores.
Definition: keystore.h:19
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:20
160-bit opaque blob.
Definition: uint256.h:112
std::vector< unsigned char > valtype
Definition: interpreter.cpp:15
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:22
Indicates that we know how to create a scriptSig that would solve this if we were given the appropria...
Definition: ismine.h:23
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest)
Definition: ismine.cpp:28
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const =0
A signature creator that just produces 72-byte empty signatures.
Definition: sign.h:55
Released under the MIT license