[#wallet-LegacyDataSPKM]
= xref:wallet.adoc[wallet]::LegacyDataSPKM
:relfileprefix: ../
:mrdocs:

Manages the minimum data needed to load and migrate a legacy wallet&period;

== Synopsis

Declared in `&lt;wallet&sol;scriptpubkeyman&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class LegacyDataSPKM
    : public xref:wallet/ScriptPubKeyMan.adoc[ScriptPubKeyMan]
    , public xref:FillableSigningProvider.adoc[FillableSigningProvider]
----

== Base Classes

[cols="1,4"]
|===
| Name| Description
| `xref:wallet/ScriptPubKeyMan.adoc[ScriptPubKeyMan]`
| A class implementing ScriptPubKeyMan manages some (or all) scriptPubKeys used in a wallet&period; It contains the scripts and keys related to the scriptPubKeys it manages&period; A ScriptPubKeyMan will be able to give out scriptPubKeys to be used, as well as marking when a scriptPubKey has been used&period; It also handles when and how to store a scriptPubKey and its related scripts and keys, including encryption&period;
| `xref:FillableSigningProvider.adoc[FillableSigningProvider]`
| Fillable signing provider that keeps keys in an address&hyphen;&gt;secret map
|===

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:FillableSigningProvider/AddCScript.adoc[`AddCScript`]  [.small]#[virtual]#
| Add a redeem or witness script&period;
| xref:wallet/LegacyDataSPKM/AddInactiveHDChain.adoc[`AddInactiveHDChain`] 
| Stores an inactive HD chain, keyed by its seed id&period;
| xref:FillableSigningProvider/AddKey.adoc[`AddKey`]  [.small]#[virtual]#
| Add a private key, deriving its public key&period;
| xref:FillableSigningProvider/AddKeyPubKey.adoc[`AddKeyPubKey`]  [.small]#[virtual]#
| Add a private key together with its public key&period;
| xref:wallet/ScriptPubKeyMan/CanGetAddresses.adoc[`CanGetAddresses`]  [.small]#[virtual]#
| Returns true if the wallet can give out new addresses&period; This means it has keys in the keypool or can generate new keys
| xref:wallet/ScriptPubKeyMan/CanProvide.adoc[`CanProvide`]  [.small]#[virtual]#
| Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSolvingProvider) that, combined with sigdata, can produce solving data&period;
| xref:wallet/LegacyDataSPKM/CheckDecryptionKey.adoc[`CheckDecryptionKey`]  [.small]#[virtual]#
| Checks whether the given master key decrypts all keys handled by this spkm&period;
| xref:SigningProvider/DeleteMuSig2Session.adoc[`DeleteMuSig2Session`]  [.small]#[virtual]#
| Delete the state stored for a MuSig2 signing session&period;
| xref:wallet/LegacyDataSPKM/DeleteRecordsWithDB.adoc[`DeleteRecordsWithDB`] 
| Delete the legacy wallet records from disk&period;
| xref:wallet/ScriptPubKeyMan/Encrypt.adoc[`Encrypt`]  [.small]#[virtual]#
| Encrypts this ScriptPubKeyMan&apos;s keys with the given master key, writing changes to the batch&period;
| xref:wallet/ScriptPubKeyMan/FillPSBT.adoc[`FillPSBT`]  [.small]#[virtual]#
| Adds script and derivation path information to a PSBT, and optionally signs it&period;
| xref:SigningProvider/GetAllMuSig2ParticipantPubkeys.adoc[`GetAllMuSig2ParticipantPubkeys`]  [.small]#[virtual]#
| Return all known MuSig2 aggregate pubkeys and their participants&period;
| xref:FillableSigningProvider/GetCScript-0d.adoc[`GetCScript`] 
| Look up a script by its script id&period;
| xref:FillableSigningProvider/GetCScripts.adoc[`GetCScripts`]  [.small]#[virtual]#
| Return the ids of all known scripts&period;
| xref:wallet/LegacyDataSPKM/GetHDChain.adoc[`GetHDChain`] 
| Returns the active HD chain model&period;
| xref:wallet/LegacyDataSPKM/GetID.adoc[`GetID`]  [.small]#[virtual]#
| Returns the fixed identifier for the legacy spkm&period;
| xref:wallet/LegacyDataSPKM/GetKey-0e.adoc[`GetKey`] 
| `GetKey` overloads
| xref:SigningProvider/GetKeyByXOnly.adoc[`GetKeyByXOnly`] 
| Look up a private key by any key id derived from an x&hyphen;only pubkey&period;
| xref:wallet/LegacyDataSPKM/GetKeyOrigin.adoc[`GetKeyOrigin`]  [.small]#[virtual]#
| Retrieves the key origin (derivation path and fingerprint) for the given key id&period;
| xref:SigningProvider/GetKeyOriginByXOnly.adoc[`GetKeyOriginByXOnly`] 
| Look up key origin info by any key id derived from an x&hyphen;only pubkey&period;
| xref:wallet/ScriptPubKeyMan/GetKeyPoolSize.adoc[`GetKeyPoolSize`]  [.small]#[virtual]#
| Returns the number of keys currently available in the keypool&period;
| xref:FillableSigningProvider/GetKeys.adoc[`GetKeys`]  [.small]#[virtual]#
| Return the ids of all known private keys&period;
| xref:wallet/ScriptPubKeyMan/GetMetadata.adoc[`GetMetadata`]  [.small]#[virtual]#
| Returns the key metadata for the given destination, or nullptr if none is known&period;
| xref:SigningProvider/GetMuSig2ParticipantPubkeys.adoc[`GetMuSig2ParticipantPubkeys`]  [.small]#[virtual]#
| Return the MuSig2 participant pubkeys for an aggregate pubkey&period;
| xref:SigningProvider/GetMuSig2SecNonce.adoc[`GetMuSig2SecNonce`]  [.small]#[virtual]#
| Retrieve the MuSig2 secret nonce for a signing session&period;
| xref:wallet/ScriptPubKeyMan/GetNewDestination.adoc[`GetNewDestination`]  [.small]#[virtual]#
| Returns a new destination of the given output type, or an error if unsupported&period;
| xref:wallet/LegacyDataSPKM/GetNotMineScriptPubKeys.adoc[`GetNotMineScriptPubKeys`] 
| Retrieves scripts that were imported by bugs into the legacy spkm and are simply invalid, such as a sh(sh(pkh())) script, or not watched&period;
| xref:wallet/LegacyDataSPKM/GetPubKey-0d.adoc[`GetPubKey`] 
| `GetPubKey` overloads
| xref:SigningProvider/GetPubKeyByXOnly.adoc[`GetPubKeyByXOnly`] 
| Look up a public key by any key id derived from an x&hyphen;only pubkey&period;
| xref:wallet/ScriptPubKeyMan/GetReservedDestination.adoc[`GetReservedDestination`]  [.small]#[virtual]#
| Reserves a destination from the keypool and returns it, keeping the reservation index&period;
| xref:wallet/LegacyDataSPKM/GetScriptPubKeys.adoc[`GetScriptPubKeys`]  [.small]#[virtual]#
| Returns the set of scriptPubKeys watched by this spkm&period;
| xref:wallet/LegacyDataSPKM/GetSolvingProvider.adoc[`GetSolvingProvider`]  [.small]#[virtual]#
| Returns a SigningProvider able to solve the given script&period;
| xref:SigningProvider/GetTaprootBuilder.adoc[`GetTaprootBuilder`]  [.small]#[virtual]#
| Look up the Taproot builder for an output key&period;
| xref:SigningProvider/GetTaprootSpendData.adoc[`GetTaprootSpendData`]  [.small]#[virtual]#
| Look up the Taproot spend data for an output key&period;
| xref:wallet/ScriptPubKeyMan/GetTimeFirstKey.adoc[`GetTimeFirstKey`]  [.small]#[virtual]#
| Returns the creation time of the earliest key, used as the wallet&apos;s birth time&period;
| xref:wallet/LegacyDataSPKM/GetWatchPubKey.adoc[`GetWatchPubKey`] 
| Fetches a pubkey from mapWatchKeys if it exists there
| xref:FillableSigningProvider/HaveCScript-09.adoc[`HaveCScript`] 
| Report whether a script with the given id is known&period;
| xref:wallet/ScriptPubKeyMan/HaveCryptedKeys.adoc[`HaveCryptedKeys`]  [.small]#[virtual]#
| Returns whether this ScriptPubKeyMan holds any encrypted private keys&period;
| xref:wallet/LegacyDataSPKM/HaveKey.adoc[`HaveKey`]  [.small]#[virtual]#
| Returns whether the private key for the given address is held&period;
| xref:wallet/ScriptPubKeyMan/HavePrivateKeys.adoc[`HavePrivateKeys`]  [.small]#[virtual]#
| Returns whether this ScriptPubKeyMan holds any unencrypted private keys&period;
| xref:wallet/LegacyDataSPKM/HaveWatchOnly.adoc[`HaveWatchOnly`] 
| Returns whether the watch&hyphen;only script is in the wallet
| xref:wallet/ScriptPubKeyMan/IsHDEnabled.adoc[`IsHDEnabled`]  [.small]#[virtual]#
| Returns true if HD is enabled
| xref:wallet/ScriptPubKeyMan/IsMine.adoc[`IsMine`]  [.small]#[virtual]#
| Returns whether the given script is owned by this ScriptPubKeyMan&period;
| xref:wallet/ScriptPubKeyMan/KeepDestination.adoc[`KeepDestination`]  [.small]#[virtual]#
| Marks a previously reserved destination as used so it is not handed out again&period;
| xref:wallet/LegacyDataSPKM/LoadCScript.adoc[`LoadCScript`] 
| Adds a CScript to the store
| xref:wallet/LegacyDataSPKM/LoadCryptedKey.adoc[`LoadCryptedKey`] 
| Adds an encrypted key to the store, without saving it to disk (used by LoadWallet)
| xref:wallet/LegacyDataSPKM/LoadHDChain.adoc[`LoadHDChain`] 
| Load a HD chain model (used by LoadWallet)
| xref:wallet/LegacyDataSPKM/LoadKey.adoc[`LoadKey`] 
| Adds a key to the store, without saving it to disk (used by LoadWallet)
| xref:wallet/LegacyDataSPKM/LoadKeyMetadata.adoc[`LoadKeyMetadata`]  [.small]#[virtual]#
| Load metadata (used by LoadWallet)
| xref:wallet/LegacyDataSPKM/LoadScriptMetadata.adoc[`LoadScriptMetadata`]  [.small]#[virtual]#
| Loads metadata for a watch&hyphen;only script (used by LoadWallet)&period;
| xref:wallet/LegacyDataSPKM/LoadWatchOnly.adoc[`LoadWatchOnly`] 
| Adds a watch&hyphen;only address to the store, without saving it to disk (used by LoadWallet)
| xref:wallet/ScriptPubKeyMan/MarkUnusedAddresses.adoc[`MarkUnusedAddresses`]  [.small]#[virtual]#
| Mark unused addresses as being used Affects all keys up to and including the one determined by provided script&period;
| xref:wallet/LegacyDataSPKM/MigrateToDescriptor.adoc[`MigrateToDescriptor`] 
| Get the DescriptorScriptPubKeyMans (with private keys) that have the same scriptPubKeys as this LegacyDataSPKM&period; Does not modify this LegacyDataSPKM&period;
| xref:wallet/ScriptPubKeyMan/ReturnDestination.adoc[`ReturnDestination`]  [.small]#[virtual]#
| Returns a previously reserved destination to the keypool for reuse&period;
| xref:SigningProvider/SetMuSig2SecNonce.adoc[`SetMuSig2SecNonce`]  [.small]#[virtual]#
| Store a MuSig2 secret nonce for a signing session&period;
| xref:wallet/ScriptPubKeyMan/SignMessage.adoc[`SignMessage`]  [.small]#[virtual]#
| Sign a message with the given script
| xref:wallet/ScriptPubKeyMan/SignTransaction.adoc[`SignTransaction`]  [.small]#[virtual]#
| Creates new signatures and adds them to the transaction&period; Returns whether all inputs were signed
| xref:wallet/ScriptPubKeyMan/TopUp.adoc[`TopUp`]  [.small]#[virtual]#
| Fills internal address pool&period; Use within ScriptPubKeyMan implementations should be used sparingly and only when something from the address pool is removed, excluding GetNewDestination and GetReservedDestination&period; External wallet code is primarily responsible for topping up prior to fetching new addresses
| xref:wallet/ScriptPubKeyMan/WalletLogPrintf.adoc[`WalletLogPrintf`] 
| Prepends the wallet name in logging output to ease debugging in multi&hyphen;wallet use cases
|===


== Data Members

[cols="1,4"]
|===
| Name| Description
| xref:wallet/ScriptPubKeyMan/NotifyCanGetAddressesChanged.adoc[`NotifyCanGetAddressesChanged`] 
| Keypool has new keys
| xref:wallet/ScriptPubKeyMan/NotifyFirstKeyTimeChanged.adoc[`NotifyFirstKeyTimeChanged`] 
| Birth time changed
| xref:FillableSigningProvider/cs_KeyStore.adoc[`cs&lowbar;KeyStore`] 
| Mutex guarding the key and script maps&period;
| xref:wallet/LegacyDataSPKM/m_script_metadata.adoc[`m&lowbar;script&lowbar;metadata`] 
| Map from Script ID to key metadata (for watch&hyphen;only keys)&period;
| xref:wallet/LegacyDataSPKM/mapKeyMetadata.adoc[`mapKeyMetadata`] 
| Map from Key ID to key metadata&period;
|===


== Using Declarations

[cols="1,4"]
|===
| Name| Description
| xref:wallet/LegacyDataSPKM/2constructor.adoc[`LegacyDataSPKM`] 
| Inherit the ScriptPubKeyMan constructors&period;
|===


== Protected Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:FillableSigningProvider/KeyMap.adoc[`KeyMap`] 
| Map of key id to private key&period;
| xref:FillableSigningProvider/ScriptMap.adoc[`ScriptMap`] 
| Map of script id to script&period;
|===


== Protected Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:FillableSigningProvider/ImplicitlyLearnRelatedKeyScripts.adoc[`ImplicitlyLearnRelatedKeyScripts`] 
| Record the scripts implied by a public key without persisting them&period;
|===


== Protected Data Members

[cols="1,4"]
|===
| Name| Description
| xref:wallet/ScriptPubKeyMan/m_storage.adoc[`m&lowbar;storage`] 
| The wallet storage this ScriptPubKeyMan uses to persist and query wallet&hyphen;wide state&period;
| xref:FillableSigningProvider/mapKeys.adoc[`mapKeys`] 
| Map of key id to unencrypted private keys known by the signing provider&period; Map may be empty if the provider has another source of keys, like an encrypted store&period;
| xref:FillableSigningProvider/mapScripts.adoc[`mapScripts`] 
| Map of script id to scripts known by the signing provider&period;
|===


== Non-Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:GetKeyForDestination.adoc[`&colon;&colon;GetKeyForDestination`]
| Return the CKeyID of the key involved in a script (if there is a unique one)&period;
| xref:IsSegWitOutput.adoc[`&colon;&colon;IsSegWitOutput`]
| Check whether a scriptPubKey is known to be segwit&period;
| xref:ProduceSignature.adoc[`&colon;&colon;ProduceSignature`]
| Produce a script signature using a generic signature creator&period;
| xref:SignPSBTInput.adoc[`&colon;&colon;SignPSBTInput`]
| Signs a PSBTInput, verifying that all provided data matches what is being signed&period;
| xref:UpdatePSBTOutput.adoc[`&colon;&colon;UpdatePSBTOutput`]
| Updates a PSBTOutput with information from provider&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
