MCPcopy Create free account
hub / github.com/ElementsProject/elements / DescriptorCache

Class DescriptorCache

src/script/descriptor.h:19–79  ·  view source on GitHub ↗

Cache for single descriptor's derived extended pubkeys */

Source from the content-addressed store, hash-verified

17
18/** Cache for single descriptor's derived extended pubkeys */
19class DescriptorCache {
20private:
21 /** Map key expression index -> map of (key derivation index -> xpub) */
22 std::unordered_map<uint32_t, ExtPubKeyMap> m_derived_xpubs;
23 /** Map key expression index -> parent xpub */
24 ExtPubKeyMap m_parent_xpubs;
25 /** Map key expression index -> last hardened xpub */
26 ExtPubKeyMap m_last_hardened_xpubs;
27
28public:
29 /** Cache a parent xpub
30 *
31 * @param[in] key_exp_pos Position of the key expression within the descriptor
32 * @param[in] xpub The CExtPubKey to cache
33 */
34 void CacheParentExtPubKey(uint32_t key_exp_pos, const CExtPubKey& xpub);
35 /** Retrieve a cached parent xpub
36 *
37 * @param[in] key_exp_pos Position of the key expression within the descriptor
38 * @param[in] xpub The CExtPubKey to get from cache
39 */
40 bool GetCachedParentExtPubKey(uint32_t key_exp_pos, CExtPubKey& xpub) const;
41 /** Cache an xpub derived at an index
42 *
43 * @param[in] key_exp_pos Position of the key expression within the descriptor
44 * @param[in] der_index Derivation index of the xpub
45 * @param[in] xpub The CExtPubKey to cache
46 */
47 void CacheDerivedExtPubKey(uint32_t key_exp_pos, uint32_t der_index, const CExtPubKey& xpub);
48 /** Retrieve a cached xpub derived at an index
49 *
50 * @param[in] key_exp_pos Position of the key expression within the descriptor
51 * @param[in] der_index Derivation index of the xpub
52 * @param[in] xpub The CExtPubKey to get from cache
53 */
54 bool GetCachedDerivedExtPubKey(uint32_t key_exp_pos, uint32_t der_index, CExtPubKey& xpub) const;
55 /** Cache a last hardened xpub
56 *
57 * @param[in] key_exp_pos Position of the key expression within the descriptor
58 * @param[in] xpub The CExtPubKey to cache
59 */
60 void CacheLastHardenedExtPubKey(uint32_t key_exp_pos, const CExtPubKey& xpub);
61 /** Retrieve a cached last hardened xpub
62 *
63 * @param[in] key_exp_pos Position of the key expression within the descriptor
64 * @param[in] xpub The CExtPubKey to get from cache
65 */
66 bool GetCachedLastHardenedExtPubKey(uint32_t key_exp_pos, CExtPubKey& xpub) const;
67
68 /** Retrieve all cached parent xpubs */
69 const ExtPubKeyMap GetCachedParentExtPubKeys() const;
70 /** Retrieve all cached derived xpubs */
71 const std::unordered_map<uint32_t, ExtPubKeyMap> GetCachedDerivedExtPubKeys() const;
72 /** Retrieve all cached last hardened xpubs */
73 const ExtPubKeyMap GetCachedLastHardenedExtPubKeys() const;
74
75 /** Combine another DescriptorCache into this one.
76 * Returns a cache containing the items from the other cache unknown to current cache

Callers 1

walletdb.cppFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected