PIVX Core  5.6.99
P2P Digital Currency
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
ScriptPubKeyMan Class Reference

#include <scriptpubkeyman.h>

Collaboration diagram for ScriptPubKeyMan:
[legend]

Public Member Functions

 ScriptPubKeyMan (CWallet *parent)
 
 ~ScriptPubKeyMan ()
 
void SetHDChain (CHDChain &chain, bool memonly)
 
const CHDChainGetHDChain () const
 
bool SetupGeneration (bool newKeypool=true, bool force=false, bool memOnly=false)
 Sets up the key generation stuff, i.e. More...
 
bool Upgrade (const int prev_version, std::string &error)
 Upgrades the wallet to the specified version. More...
 
bool CanGenerateKeys ()
 
bool IsHDEnabled () const
 
int64_t GetOldestKeyPoolTime ()
 
size_t KeypoolCountExternalKeys ()
 
unsigned int GetKeyPoolSize () const
 
unsigned int GetStakingKeyPoolSize () const
 
bool CanGetAddresses (const uint8_t &type=HDChain::ChangeType::EXTERNAL)
 
CPubKey GenerateNewSeed ()
 
CPubKey DeriveNewSeed (const CKey &key)
 
void SetHDSeed (const CPubKey &key, bool force=false, bool memOnly=false)
 
void LoadKeyPool (int64_t nIndex, const CKeyPool &keypool)
 Load a keypool entry. More...
 
bool NewKeyPool ()
 Key pool. More...
 
void MarkPreSplitKeys ()
 Update pre HD keys in db with the pre-split flag enabled. More...
 
bool TopUp (unsigned int size=0)
 Fills internal address pool. More...
 
void MarkUnusedAddresses (const CScript &script)
 Mark unused addresses as being used. More...
 
void UpdateTimeFirstKey (int64_t nCreateTime)
 First wallet key time. More...
 
CPubKey GenerateNewKey (WalletBatch &batch, const uint8_t &type=HDChain::ChangeType::EXTERNAL)
 Generate a new key. More...
 
bool GetKeyFromPool (CPubKey &key, const uint8_t &changeType=HDChain::ChangeType::EXTERNAL)
 Fetches a key from the keypool. More...
 
bool GetReservedKey (const uint8_t &changeType, int64_t &index, CKeyPool &keypool)
 Reserve + fetch a key from the keypool. More...
 
const std::map< CKeyID, int64_t > & GetAllReserveKeys () const
 
bool ReserveKeyFromKeyPool (int64_t &nIndex, CKeyPool &keypool, const uint8_t &type=HDChain::ChangeType::EXTERNAL)
 Reserves a key from the keypool and sets nIndex to its index. More...
 
void KeepDestination (int64_t index)
 
void ReturnDestination (int64_t index, const uint8_t &type, const CTxDestination &)
 

Public Attributes

std::set< int64_t > set_pre_split_keypool
 

Private Member Functions

bool AddKeyPubKeyInner (const CKey &key, const CPubKey &pubkey)
 
bool AddKeyPubKeyWithDB (WalletBatch &batch, const CKey &key, const CPubKey &pubkey)
 Adds a key to the store, and saves it to disk. More...
 
void AddKeypoolPubkeyWithDB (const CPubKey &pubkey, const uint8_t &type, WalletBatch &batch)
 
void GeneratePool (WalletBatch &batch, int64_t targetSize, const uint8_t &type)
 
void DeriveNewChildKey (WalletBatch &batch, CKeyMetadata &metadata, CKey &secret, const uint8_t &type=HDChain::ChangeType::EXTERNAL)
 
void MarkReserveKeysAsUsed (int64_t keypool_id)
 Marks all keys in the keypool up to and including reserve_key as used. More...
 

Private Attributes

CWalletwallet {nullptr}
 
CHDChain hdChain
 
WalletBatchencrypted_batch = nullptr
 
std::set< int64_t > setInternalKeyPool
 
std::set< int64_t > setExternalKeyPool
 
std::set< int64_t > setStakingKeyPool
 
int64_t m_max_keypool_index = 0
 
std::map< CKeyID, int64_t > m_pool_key_to_index
 
std::map< int64_t, CKeyIDm_index_to_reserved_key
 

Detailed Description

Definition at line 24 of file scriptpubkeyman.h.

Constructor & Destructor Documentation

◆ ScriptPubKeyMan()

ScriptPubKeyMan::ScriptPubKeyMan ( CWallet parent)
inlineexplicit

Definition at line 27 of file scriptpubkeyman.h.

◆ ~ScriptPubKeyMan()

ScriptPubKeyMan::~ScriptPubKeyMan ( )
inline

Definition at line 28 of file scriptpubkeyman.h.

Member Function Documentation

◆ AddKeypoolPubkeyWithDB()

void ScriptPubKeyMan::AddKeypoolPubkeyWithDB ( const CPubKey pubkey,
const uint8_t &  type,
WalletBatch batch 
)
private

Definition at line 421 of file scriptpubkeyman.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddKeyPubKeyInner()

bool ScriptPubKeyMan::AddKeyPubKeyInner ( const CKey key,
const CPubKey pubkey 
)
private

Definition at line 602 of file scriptpubkeyman.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddKeyPubKeyWithDB()

bool ScriptPubKeyMan::AddKeyPubKeyWithDB ( WalletBatch batch,
const CKey key,
const CPubKey pubkey 
)
private

Adds a key to the store, and saves it to disk.

Definition at line 580 of file scriptpubkeyman.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CanGenerateKeys()

bool ScriptPubKeyMan::CanGenerateKeys ( )

Definition at line 52 of file scriptpubkeyman.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CanGetAddresses()

bool ScriptPubKeyMan::CanGetAddresses ( const uint8_t &  type = HDChain::ChangeType::EXTERNAL)

Definition at line 64 of file scriptpubkeyman.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeriveNewChildKey()

void ScriptPubKeyMan::DeriveNewChildKey ( WalletBatch batch,
CKeyMetadata metadata,
CKey secret,
const uint8_t &  type = HDChain::ChangeType::EXTERNAL 
)
private

Definition at line 480 of file scriptpubkeyman.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeriveNewSeed()

CPubKey ScriptPubKeyMan::DeriveNewSeed ( const CKey key)

Definition at line 634 of file scriptpubkeyman.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GenerateNewKey()

CPubKey ScriptPubKeyMan::GenerateNewKey ( WalletBatch batch,
const uint8_t &  type = HDChain::ChangeType::EXTERNAL 
)

Generate a new key.

Generate a new key and stores it in db.

Definition at line 445 of file scriptpubkeyman.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GenerateNewSeed()

CPubKey ScriptPubKeyMan::GenerateNewSeed ( )

Definition at line 627 of file scriptpubkeyman.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GeneratePool()

void ScriptPubKeyMan::GeneratePool ( WalletBatch batch,
int64_t  targetSize,
const uint8_t &  type 
)
private

Definition at line 413 of file scriptpubkeyman.cpp.

Here is the call graph for this function:

◆ GetAllReserveKeys()

const std::map<CKeyID, int64_t>& ScriptPubKeyMan::GetAllReserveKeys ( ) const
inline

Definition at line 103 of file scriptpubkeyman.h.

Here is the caller graph for this function:

◆ GetHDChain()

const CHDChain& ScriptPubKeyMan::GetHDChain ( ) const
inline

Definition at line 32 of file scriptpubkeyman.h.

Here is the caller graph for this function:

◆ GetKeyFromPool()

bool ScriptPubKeyMan::GetKeyFromPool ( CPubKey key,
const uint8_t &  changeType = HDChain::ChangeType::EXTERNAL 
)

Fetches a key from the keypool.

Definition at line 135 of file scriptpubkeyman.cpp.

Here is the call graph for this function:

◆ GetKeyPoolSize()

unsigned int ScriptPubKeyMan::GetKeyPoolSize ( ) const

Definition at line 123 of file scriptpubkeyman.cpp.

◆ GetOldestKeyPoolTime()

int64_t ScriptPubKeyMan::GetOldestKeyPoolTime ( )

Definition at line 99 of file scriptpubkeyman.cpp.

Here is the call graph for this function:

◆ GetReservedKey()

bool ScriptPubKeyMan::GetReservedKey ( const uint8_t &  changeType,
int64_t &  index,
CKeyPool keypool 
)

Reserve + fetch a key from the keypool.

Definition at line 161 of file scriptpubkeyman.cpp.

Here is the call graph for this function:

◆ GetStakingKeyPoolSize()

unsigned int ScriptPubKeyMan::GetStakingKeyPoolSize ( ) const

Definition at line 129 of file scriptpubkeyman.cpp.

◆ IsHDEnabled()

bool ScriptPubKeyMan::IsHDEnabled ( ) const

Definition at line 59 of file scriptpubkeyman.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ KeepDestination()

void ScriptPubKeyMan::KeepDestination ( int64_t  index)

Definition at line 225 of file scriptpubkeyman.cpp.

Here is the call graph for this function:

◆ KeypoolCountExternalKeys()

size_t ScriptPubKeyMan::KeypoolCountExternalKeys ( )

Definition at line 117 of file scriptpubkeyman.cpp.

Here is the caller graph for this function:

◆ LoadKeyPool()

void ScriptPubKeyMan::LoadKeyPool ( int64_t  nIndex,
const CKeyPool keypool 
)

Load a keypool entry.

Definition at line 539 of file scriptpubkeyman.cpp.

Here is the call graph for this function:

◆ MarkPreSplitKeys()

void ScriptPubKeyMan::MarkPreSplitKeys ( )

Update pre HD keys in db with the pre-split flag enabled.

Definition at line 308 of file scriptpubkeyman.cpp.

Here is the call graph for this function:

◆ MarkReserveKeysAsUsed()

void ScriptPubKeyMan::MarkReserveKeysAsUsed ( int64_t  keypool_id)
private

Marks all keys in the keypool up to and including reserve_key as used.

Definition at line 260 of file scriptpubkeyman.cpp.

Here is the call graph for this function:

◆ MarkUnusedAddresses()

void ScriptPubKeyMan::MarkUnusedAddresses ( const CScript script)

Mark unused addresses as being used.

Definition at line 291 of file scriptpubkeyman.cpp.

Here is the call graph for this function:

◆ NewKeyPool()

bool ScriptPubKeyMan::NewKeyPool ( )

Key pool.

Mark old keypool keys as used, and generate all new keys.

Definition at line 330 of file scriptpubkeyman.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReserveKeyFromKeyPool()

bool ScriptPubKeyMan::ReserveKeyFromKeyPool ( int64_t &  nIndex,
CKeyPool keypool,
const uint8_t &  type = HDChain::ChangeType::EXTERNAL 
)

Reserves a key from the keypool and sets nIndex to its index.

Parameters
[out]nIndexthe index of the key in keypool
[out]keypoolthe keypool the key was drawn from, which could be the the pre-split pool if present, or the internal or external pool
fRequestedInternaltrue if the caller would like the key drawn from the internal keypool, false if external is preferred
Returns
true if succeeded, false if failed due to empty keypool
Exceptions
std::runtime_errorif keypool read failed, key was invalid, was not found in the wallet, or was misclassified in the internal or external keypool

Definition at line 172 of file scriptpubkeyman.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReturnDestination()

void ScriptPubKeyMan::ReturnDestination ( int64_t  index,
const uint8_t &  type,
const CTxDestination  
)

Definition at line 237 of file scriptpubkeyman.cpp.

Here is the call graph for this function:

◆ SetHDChain()

void ScriptPubKeyMan::SetHDChain ( CHDChain chain,
bool  memonly 
)

Definition at line 682 of file scriptpubkeyman.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetHDSeed()

void ScriptPubKeyMan::SetHDSeed ( const CPubKey key,
bool  force = false,
bool  memOnly = false 
)
Todo:
: Connect this if is needed.

Definition at line 663 of file scriptpubkeyman.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetupGeneration()

bool ScriptPubKeyMan::SetupGeneration ( bool  newKeypool = true,
bool  force = false,
bool  memOnly = false 
)

Sets up the key generation stuff, i.e.

generates new HD seeds and sets them as active. Returns false if already setup or setup fails, true if setup is successful Set force=true to make it re-setup if already setup, used for upgrades

Definition at line 10 of file scriptpubkeyman.cpp.

Here is the call graph for this function:

◆ TopUp()

bool ScriptPubKeyMan::TopUp ( unsigned int  size = 0)

Fills internal address pool.

Fill the key pool.

Use within ScriptPubKeyMan implementations should be used sparingly and only when something from the address pool is removed, excluding GetNewDestination and GetReservedDestination. External wallet code is primarily responsible for topping up prior to fetching new addresses

Todo:
: Implement this.

Definition at line 368 of file scriptpubkeyman.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateTimeFirstKey()

void ScriptPubKeyMan::UpdateTimeFirstKey ( int64_t  nCreateTime)

First wallet key time.

Update wallet first key creation time.

This should be called whenever keys are added to the wallet, with the oldest key creation time.

Definition at line 568 of file scriptpubkeyman.cpp.

Here is the caller graph for this function:

◆ Upgrade()

bool ScriptPubKeyMan::Upgrade ( const int  prev_version,
std::string &  error 
)

Upgrades the wallet to the specified version.

Definition at line 23 of file scriptpubkeyman.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ encrypted_batch

WalletBatch* ScriptPubKeyMan::encrypted_batch = nullptr
private

Definition at line 133 of file scriptpubkeyman.h.

◆ hdChain

CHDChain ScriptPubKeyMan::hdChain
private

Definition at line 130 of file scriptpubkeyman.h.

◆ m_index_to_reserved_key

std::map<int64_t, CKeyID> ScriptPubKeyMan::m_index_to_reserved_key
private

Definition at line 142 of file scriptpubkeyman.h.

◆ m_max_keypool_index

int64_t ScriptPubKeyMan::m_max_keypool_index = 0
private

Definition at line 139 of file scriptpubkeyman.h.

◆ m_pool_key_to_index

std::map<CKeyID, int64_t> ScriptPubKeyMan::m_pool_key_to_index
private

Definition at line 140 of file scriptpubkeyman.h.

◆ set_pre_split_keypool

std::set<int64_t> ScriptPubKeyMan::set_pre_split_keypool
Todo:
: This is public for now but shouldn't be here.

Definition at line 124 of file scriptpubkeyman.h.

◆ setExternalKeyPool

std::set<int64_t> ScriptPubKeyMan::setExternalKeyPool
private

Definition at line 137 of file scriptpubkeyman.h.

◆ setInternalKeyPool

std::set<int64_t> ScriptPubKeyMan::setInternalKeyPool
private

Definition at line 136 of file scriptpubkeyman.h.

◆ setStakingKeyPool

std::set<int64_t> ScriptPubKeyMan::setStakingKeyPool
private

Definition at line 138 of file scriptpubkeyman.h.

◆ wallet

CWallet* ScriptPubKeyMan::wallet {nullptr}
private

Definition at line 128 of file scriptpubkeyman.h.


The documentation for this class was generated from the following files: