MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / IsMineInner

Function IsMineInner

src/script/ismine.cpp:58–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58IsMineResult IsMineInner(const CKeyStore& keystore, const CScript& scriptPubKey, IsMineSigVersion sigversion)
59{
60 IsMineResult ret = IsMineResult::NO;
61
62 std::vector<valtype> vSolutions;
63 txnouttype whichType;
64 Solver(scriptPubKey, whichType, vSolutions);
65
66 CKeyID keyID;
67 switch (whichType)
68 {
69 case TX_NONSTANDARD:
70 case TX_NULL_DATA:
71 case TX_WITNESS_UNKNOWN:
72 break;
73 case TX_PUBKEY:
74 keyID = CPubKey(vSolutions[0]).GetID();
75 if (!PermitsUncompressed(sigversion) && vSolutions[0].size() != 33) {
76 return IsMineResult::INVALID;
77 }
78 if (keystore.HaveKey(keyID)) {
79 ret = std::max(ret, IsMineResult::SPENDABLE);
80 }
81 break;
82 case TX_WITNESS_V0_KEYHASH:
83 {
84 if (sigversion == IsMineSigVersion::WITNESS_V0) {
85 // P2WPKH inside P2WSH is invalid.
86 return IsMineResult::INVALID;
87 }
88 if (sigversion == IsMineSigVersion::TOP && !keystore.HaveCScript(CScriptID(CScript() << OP_0 << vSolutions[0]))) {
89 // We do not support bare witness outputs unless the P2SH version of it would be
90 // acceptable as well. This protects against matching before segwit activates.
91 // This also applies to the P2WSH case.
92 break;
93 }
94 ret = std::max(ret, IsMineInner(keystore, GetScriptForDestination(CKeyID(uint160(vSolutions[0]))), IsMineSigVersion::WITNESS_V0));
95 break;
96 }
97 case TX_PUBKEYHASH:
98 keyID = CKeyID(uint160(vSolutions[0]));
99 if (!PermitsUncompressed(sigversion)) {
100 CPubKey pubkey;
101 if (keystore.GetPubKey(keyID, pubkey) && !pubkey.IsCompressed()) {
102 return IsMineResult::INVALID;
103 }
104 }
105 if (keystore.HaveKey(keyID)) {
106 ret = std::max(ret, IsMineResult::SPENDABLE);
107 }
108 break;
109 case TX_SCRIPTHASH:
110 {
111 if (sigversion != IsMineSigVersion::TOP) {
112 // P2SH inside P2WSH or P2SH is invalid.
113 return IsMineResult::INVALID;
114 }
115 CScriptID scriptID = CScriptID(uint160(vSolutions[0]));

Callers 1

IsMineFunction · 0.85

Calls 15

SolverFunction · 0.85
PermitsUncompressedFunction · 0.85
maxFunction · 0.85
GetScriptForDestinationFunction · 0.85
CRIPEMD160Class · 0.85
HaveKeysFunction · 0.85
GetIDMethod · 0.80
HaveCScriptMethod · 0.80
HaveWatchOnlyMethod · 0.80
CPubKeyClass · 0.70
CScriptIDClass · 0.70
CScriptClass · 0.70

Tested by

no test coverage detected