|
13 | 13 |
|
14 | 14 | #include <vector>
|
15 | 15 |
|
| 16 | +using ExtPubKeyMap = std::unordered_map<uint32_t, CExtPubKey>; |
| 17 | + |
| 18 | +/** Cache for single descriptor's derived extended pubkeys */ |
| 19 | +class DescriptorCache { |
| 20 | +private: |
| 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 | + |
| 26 | +public: |
| 27 | + /** Cache a parent xpub |
| 28 | + * |
| 29 | + * @param[in] key_exp_pos Position of the key expression within the descriptor |
| 30 | + * @param[in] xpub The CExtPubKey to cache |
| 31 | + */ |
| 32 | + void CacheParentExtPubKey(uint32_t key_exp_pos, const CExtPubKey& xpub); |
| 33 | + /** Retrieve a cached parent xpub |
| 34 | + * |
| 35 | + * @param[in] key_exp_pos Position of the key expression within the descriptor |
| 36 | + * @param[in] xpub The CExtPubKey to get from cache |
| 37 | + */ |
| 38 | + bool GetCachedParentExtPubKey(uint32_t key_exp_pos, CExtPubKey& xpub) const; |
| 39 | + /** Cache an xpub derived at an index |
| 40 | + * |
| 41 | + * @param[in] key_exp_pos Position of the key expression within the descriptor |
| 42 | + * @param[in] der_index Derivation index of the xpub |
| 43 | + * @param[in] xpub The CExtPubKey to cache |
| 44 | + */ |
| 45 | + void CacheDerivedExtPubKey(uint32_t key_exp_pos, uint32_t der_index, const CExtPubKey& xpub); |
| 46 | + /** Retrieve a cached xpub derived at an index |
| 47 | + * |
| 48 | + * @param[in] key_exp_pos Position of the key expression within the descriptor |
| 49 | + * @param[in] der_index Derivation index of the xpub |
| 50 | + * @param[in] xpub The CExtPubKey to get from cache |
| 51 | + */ |
| 52 | + bool GetCachedDerivedExtPubKey(uint32_t key_exp_pos, uint32_t der_index, CExtPubKey& xpub) const; |
| 53 | + |
| 54 | + /** Retrieve all cached parent xpubs */ |
| 55 | + const ExtPubKeyMap GetCachedParentExtPubKeys() const; |
| 56 | + /** Retrieve all cached derived xpubs */ |
| 57 | + const std::unordered_map<uint32_t, ExtPubKeyMap> GetCachedDerivedExtPubKeys() const; |
| 58 | +}; |
16 | 59 |
|
17 | 60 | /** \brief Interface for parsed descriptor objects.
|
18 | 61 | *
|
|
0 commit comments