Changeset View
Changeset View
Standalone View
Standalone View
src/script/descriptor.h
// Copyright (c) 2018 The Bitcoin Core developers | // Copyright (c) 2018 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_SCRIPT_DESCRIPTOR_H | #ifndef BITCOIN_SCRIPT_DESCRIPTOR_H | ||||
#define BITCOIN_SCRIPT_DESCRIPTOR_H | #define BITCOIN_SCRIPT_DESCRIPTOR_H | ||||
#include <script/script.h> | #include <script/script.h> | ||||
#include <script/sign.h> | #include <script/sign.h> | ||||
#include <script/signingprovider.h> | #include <script/signingprovider.h> | ||||
#include <vector> | #include <vector> | ||||
using ExtPubKeyMap = std::unordered_map<uint32_t, CExtPubKey>; | |||||
/** Cache for single descriptor's derived extended pubkeys */ | |||||
class DescriptorCache { | |||||
private: | |||||
/** Map key expression index -> map of (key derivation index -> xpub) */ | |||||
std::unordered_map<uint32_t, ExtPubKeyMap> m_derived_xpubs; | |||||
/** Map key expression index -> parent xpub */ | |||||
ExtPubKeyMap m_parent_xpubs; | |||||
public: | |||||
/** | |||||
* Cache a parent xpub | |||||
* | |||||
* @param[in] key_exp_pos Position of the key expression within the | |||||
* descriptor | |||||
* @param[in] xpub The CExtPubKey to cache | |||||
*/ | |||||
void CacheParentExtPubKey(uint32_t key_exp_pos, const CExtPubKey &xpub); | |||||
/** | |||||
* Retrieve a cached parent xpub | |||||
* | |||||
* @param[in] key_exp_pos Position of the key expression within the | |||||
* descriptor | |||||
* @param[in] xpub The CExtPubKey to get from cache | |||||
*/ | |||||
bool GetCachedParentExtPubKey(uint32_t key_exp_pos, CExtPubKey &xpub) const; | |||||
/** | |||||
* Cache an xpub derived at an index | |||||
* | |||||
* @param[in] key_exp_pos Position of the key expression within the | |||||
* descriptor | |||||
* @param[in] der_index Derivation index of the xpub | |||||
* @param[in] xpub The CExtPubKey to cache | |||||
*/ | |||||
void CacheDerivedExtPubKey(uint32_t key_exp_pos, uint32_t der_index, | |||||
const CExtPubKey &xpub); | |||||
/** | |||||
* Retrieve a cached xpub derived at an index | |||||
* | |||||
* @param[in] key_exp_pos Position of the key expression within the | |||||
* descriptor | |||||
* @param[in] der_index Derivation index of the xpub | |||||
* @param[in] xpub The CExtPubKey to get from cache | |||||
*/ | |||||
bool GetCachedDerivedExtPubKey(uint32_t key_exp_pos, uint32_t der_index, | |||||
CExtPubKey &xpub) const; | |||||
/** Retrieve all cached parent xpubs */ | |||||
const ExtPubKeyMap GetCachedParentExtPubKeys() const; | |||||
/** Retrieve all cached derived xpubs */ | |||||
const std::unordered_map<uint32_t, ExtPubKeyMap> | |||||
GetCachedDerivedExtPubKeys() const; | |||||
}; | |||||
/** | /** | ||||
* \brief Interface for parsed descriptor objects. | * \brief Interface for parsed descriptor objects. | ||||
* | * | ||||
* Descriptors are strings that describe a set of scriptPubKeys, together with | * Descriptors are strings that describe a set of scriptPubKeys, together with | ||||
* all information necessary to solve them. By combining all information into | * all information necessary to solve them. By combining all information into | ||||
* one, they avoid the need to separately import keys and scripts. | * one, they avoid the need to separately import keys and scripts. | ||||
* | * | ||||
* Descriptors may be ranged, which occurs when the public keys inside are | * Descriptors may be ranged, which occurs when the public keys inside are | ||||
▲ Show 20 Lines • Show All 122 Lines • Show Last 20 Lines |