mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-11 23:58:18 +00:00
Preparations for key import/export
This commit is contained in:
parent
15a8590ecf
commit
30ab2c9c46
@ -12,6 +12,7 @@
|
|||||||
#include <boost/iostreams/concepts.hpp>
|
#include <boost/iostreams/concepts.hpp>
|
||||||
#include <boost/iostreams/stream.hpp>
|
#include <boost/iostreams/stream.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
#ifdef USE_SSL
|
#ifdef USE_SSL
|
||||||
#include <boost/asio/ssl.hpp>
|
#include <boost/asio/ssl.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
@ -516,7 +516,7 @@ bool CTransaction::RemoveFromMemoryPool()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
int CMerkleTx::GetDepthInMainChain(int& nHeightRet) const
|
int CMerkleTx::GetDepthInMainChain(CBlockIndex* &pindexRet) const
|
||||||
{
|
{
|
||||||
if (hashBlock == 0 || nIndex == -1)
|
if (hashBlock == 0 || nIndex == -1)
|
||||||
return 0;
|
return 0;
|
||||||
@ -537,7 +537,7 @@ int CMerkleTx::GetDepthInMainChain(int& nHeightRet) const
|
|||||||
fMerkleVerified = true;
|
fMerkleVerified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
nHeightRet = pindex->nHeight;
|
pindexRet = pindex;
|
||||||
return pindexBest->nHeight - pindex->nHeight + 1;
|
return pindexBest->nHeight - pindex->nHeight + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
src/main.h
10
src/main.h
@ -695,8 +695,8 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
int SetMerkleBranch(const CBlock* pblock=NULL);
|
int SetMerkleBranch(const CBlock* pblock=NULL);
|
||||||
int GetDepthInMainChain(int& nHeightRet) const;
|
int GetDepthInMainChain(CBlockIndex* &pindexRet) const;
|
||||||
int GetDepthInMainChain() const { int nHeight; return GetDepthInMainChain(nHeight); }
|
int GetDepthInMainChain() const { CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet); }
|
||||||
bool IsInMainChain() const { return GetDepthInMainChain() > 0; }
|
bool IsInMainChain() const { return GetDepthInMainChain() > 0; }
|
||||||
int GetBlocksToMaturity() const;
|
int GetBlocksToMaturity() const;
|
||||||
bool AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs=true);
|
bool AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs=true);
|
||||||
@ -758,6 +758,7 @@ public:
|
|||||||
return !(a == b);
|
return !(a == b);
|
||||||
}
|
}
|
||||||
int GetDepthInMainChain() const;
|
int GetDepthInMainChain() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -1263,6 +1264,11 @@ public:
|
|||||||
Set((*mi).second);
|
Set((*mi).second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CBlockLocator(const std::vector<uint256>& vHaveIn)
|
||||||
|
{
|
||||||
|
vHave = vHaveIn;
|
||||||
|
}
|
||||||
|
|
||||||
IMPLEMENT_SERIALIZE
|
IMPLEMENT_SERIALIZE
|
||||||
(
|
(
|
||||||
if (!(nType & SER_GETHASH))
|
if (!(nType & SER_GETHASH))
|
||||||
|
@ -299,7 +299,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
|
|||||||
// Add a transaction to the wallet, or update it.
|
// Add a transaction to the wallet, or update it.
|
||||||
// pblock is optional, but should be provided if the transaction is known to be in a block.
|
// pblock is optional, but should be provided if the transaction is known to be in a block.
|
||||||
// If fUpdate is true, existing transactions will be updated.
|
// If fUpdate is true, existing transactions will be updated.
|
||||||
bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate)
|
bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate, bool fFindBlock)
|
||||||
{
|
{
|
||||||
uint256 hash = tx.GetHash();
|
uint256 hash = tx.GetHash();
|
||||||
CRITICAL_BLOCK(cs_wallet)
|
CRITICAL_BLOCK(cs_wallet)
|
||||||
@ -586,6 +586,15 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CWallet::ScanForWalletTransaction(const uint256& hashTx)
|
||||||
|
{
|
||||||
|
CTransaction tx;
|
||||||
|
tx.ReadFromDisk(COutPoint(hashTx, 0));
|
||||||
|
if (AddToWalletIfInvolvingMe(tx, NULL, true, true))
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void CWallet::ReacceptWalletTransactions()
|
void CWallet::ReacceptWalletTransactions()
|
||||||
{
|
{
|
||||||
CTxDB txdb("r");
|
CTxDB txdb("r");
|
||||||
@ -1325,6 +1334,22 @@ void CWallet::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64 CWallet::AddReserveKey(const CKeyPool& keypool)
|
||||||
|
{
|
||||||
|
CRITICAL_BLOCK(cs_main)
|
||||||
|
CRITICAL_BLOCK(cs_wallet)
|
||||||
|
{
|
||||||
|
CWalletDB walletdb(strWalletFile);
|
||||||
|
|
||||||
|
int64 nIndex = 1 + *(--setKeyPool.end());
|
||||||
|
if (!walletdb.WritePool(nIndex, keypool))
|
||||||
|
throw runtime_error("AddReserveKey() : writing added key failed");
|
||||||
|
setKeyPool.insert(nIndex);
|
||||||
|
return nIndex;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void CWallet::KeepKey(int64 nIndex)
|
void CWallet::KeepKey(int64 nIndex)
|
||||||
{
|
{
|
||||||
// Remove from key pool
|
// Remove from key pool
|
||||||
@ -1413,3 +1438,22 @@ void CReserveKey::ReturnKey()
|
|||||||
vchPubKey.clear();
|
vchPubKey.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CWallet::GetAllReserveAddresses(set<CBitcoinAddress>& setAddress)
|
||||||
|
{
|
||||||
|
setAddress.clear();
|
||||||
|
|
||||||
|
CWalletDB walletdb(strWalletFile);
|
||||||
|
|
||||||
|
CRITICAL_BLOCK(cs_main)
|
||||||
|
BOOST_FOREACH(const int64& id, setKeyPool)
|
||||||
|
{
|
||||||
|
CKeyPool keypool;
|
||||||
|
if (!walletdb.ReadPool(id, keypool))
|
||||||
|
throw runtime_error("GetAllReserveKeyHashes() : read failed");
|
||||||
|
CBitcoinAddress address(keypool.vchPubKey);
|
||||||
|
assert(!keypool.vchPubKey.empty());
|
||||||
|
if (!HaveKey(address))
|
||||||
|
throw runtime_error("GetAllReserveKeyHashes() : unknown key in key pool");
|
||||||
|
setAddress.insert(address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -75,10 +75,11 @@ public:
|
|||||||
bool EncryptWallet(const SecureString& strWalletPassphrase);
|
bool EncryptWallet(const SecureString& strWalletPassphrase);
|
||||||
|
|
||||||
bool AddToWallet(const CWalletTx& wtxIn);
|
bool AddToWallet(const CWalletTx& wtxIn);
|
||||||
bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate = false);
|
bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate = false, bool fFindBlock = false);
|
||||||
bool EraseFromWallet(uint256 hash);
|
bool EraseFromWallet(uint256 hash);
|
||||||
void WalletUpdateSpent(const CTransaction& prevout);
|
void WalletUpdateSpent(const CTransaction& prevout);
|
||||||
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
|
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
|
||||||
|
int ScanForWalletTransaction(const uint256& hashTx);
|
||||||
void ReacceptWalletTransactions();
|
void ReacceptWalletTransactions();
|
||||||
void ResendWalletTransactions();
|
void ResendWalletTransactions();
|
||||||
int64 GetBalance() const;
|
int64 GetBalance() const;
|
||||||
@ -92,11 +93,13 @@ public:
|
|||||||
|
|
||||||
bool NewKeyPool();
|
bool NewKeyPool();
|
||||||
bool TopUpKeyPool();
|
bool TopUpKeyPool();
|
||||||
|
int64 AddReserveKey(const CKeyPool& keypool);
|
||||||
void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool);
|
void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool);
|
||||||
void KeepKey(int64 nIndex);
|
void KeepKey(int64 nIndex);
|
||||||
void ReturnKey(int64 nIndex);
|
void ReturnKey(int64 nIndex);
|
||||||
bool GetKeyFromPool(std::vector<unsigned char> &key, bool fAllowReuse=true);
|
bool GetKeyFromPool(std::vector<unsigned char> &key, bool fAllowReuse=true);
|
||||||
int64 GetOldestKeyPoolTime();
|
int64 GetOldestKeyPoolTime();
|
||||||
|
void GetAllReserveAddresses(std::set<CBitcoinAddress>& setAddress);
|
||||||
|
|
||||||
bool IsMine(const CTxIn& txin) const;
|
bool IsMine(const CTxIn& txin) const;
|
||||||
int64 GetDebit(const CTxIn& txin) const;
|
int64 GetDebit(const CTxIn& txin) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user