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

Class CAffectedKeysVisitor

src/wallet/wallet.cpp:108–167  ·  view source on GitHub ↗

A class to identify which pubkeys a script and a keystore have in common. */

Source from the content-addressed store, hash-verified

106
107/** A class to identify which pubkeys a script and a keystore have in common. */
108class CAffectedKeysVisitor : public boost::static_visitor<void> {
109private:
110 const CKeyStore &keystore;
111 std::vector<CKeyID> &vKeys;
112
113public:
114 /**
115 * @param[in] keystoreIn The CKeyStore that is queried for the presence of a pubkey.
116 * @param[out] vKeysIn A vector to which a script's pubkey identifiers are appended if they are in the keystore.
117 */
118 CAffectedKeysVisitor(const CKeyStore &keystoreIn, std::vector<CKeyID> &vKeysIn) : keystore(keystoreIn), vKeys(vKeysIn) {}
119
120 /**
121 * Apply the visitor to each destination in a script, recursively to the redeemscript
122 * in the case of p2sh destinations.
123 * @param[in] script The CScript from which destinations are extracted.
124 * @post Any CKeyIDs that script and keystore have in common are appended to the visitor's vKeys.
125 */
126 void Process(const CScript &script) {
127 txnouttype type;
128 std::vector<CTxDestination> vDest;
129 int nRequired;
130 if (ExtractDestinations(script, type, vDest, nRequired)) {
131 for (const CTxDestination &dest : vDest)
132 boost::apply_visitor(*this, dest);
133 }
134 }
135
136 void operator()(const CKeyID &keyId) {
137 if (keystore.HaveKey(keyId))
138 vKeys.push_back(keyId);
139 }
140
141 void operator()(const CScriptID &scriptId) {
142 CScript script;
143 if (keystore.GetCScript(scriptId, script))
144 Process(script);
145 }
146
147 void operator()(const WitnessV0ScriptHash& scriptID)
148 {
149 CScriptID id;
150 CRIPEMD160().Write(scriptID.begin(), 32).Finalize(id.begin());
151 CScript script;
152 if (keystore.GetCScript(id, script)) {
153 Process(script);
154 }
155 }
156
157 void operator()(const WitnessV0KeyHash& keyid)
158 {
159 CKeyID id(keyid);
160 if (keystore.HaveKey(id)) {
161 vKeys.push_back(id);
162 }
163 }
164
165 template<typename X>

Callers 2

GetKeyBirthTimesMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected