|
|
@ -74,75 +74,52 @@ int64 nTransactionFee = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// These functions dispatch to one or all registered wallets
|
|
|
|
// These functions dispatch to one or all registered wallets
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
void RegisterWallet(CWallet* pwalletIn)
|
|
|
|
struct CMainSignals {
|
|
|
|
{
|
|
|
|
// Notifies listeners of updated transaction data (passing hash, transaction, and optionally the block it is found in.
|
|
|
|
{
|
|
|
|
boost::signals2::signal<void (const uint256 &, const CTransaction &, const CBlock *)> SyncTransaction;
|
|
|
|
LOCK(cs_setpwalletRegistered);
|
|
|
|
// Notifies listeners of an erased transaction (currently disabled, requires transaction replacement).
|
|
|
|
setpwalletRegistered.insert(pwalletIn);
|
|
|
|
boost::signals2::signal<void (const uint256 &)> EraseTransaction;
|
|
|
|
}
|
|
|
|
// Notifies listeners of an updated transaction without new data (for now: a coinbase potentially becoming visible).
|
|
|
|
}
|
|
|
|
boost::signals2::signal<void (const uint256 &)> UpdatedTransaction;
|
|
|
|
|
|
|
|
// Notifies listeners of a new active block chain.
|
|
|
|
void UnregisterWallet(CWallet* pwalletIn)
|
|
|
|
boost::signals2::signal<void (const CBlockLocator &)> SetBestChain;
|
|
|
|
{
|
|
|
|
// Notifies listeners about an inventory item being seen on the network.
|
|
|
|
{
|
|
|
|
boost::signals2::signal<void (const uint256 &)> Inventory;
|
|
|
|
LOCK(cs_setpwalletRegistered);
|
|
|
|
// Tells listeners to broadcast their data.
|
|
|
|
setpwalletRegistered.erase(pwalletIn);
|
|
|
|
boost::signals2::signal<void ()> Broadcast;
|
|
|
|
}
|
|
|
|
} g_signals;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UnregisterAllWallets()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
LOCK(cs_setpwalletRegistered);
|
|
|
|
|
|
|
|
setpwalletRegistered.clear();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// erases transaction with the given hash from all wallets
|
|
|
|
void RegisterWallet(CWalletInterface* pwalletIn) {
|
|
|
|
void static EraseFromWallets(uint256 hash)
|
|
|
|
g_signals.SyncTransaction.connect(boost::bind(&CWalletInterface::SyncTransaction, pwalletIn, _1, _2, _3));
|
|
|
|
{
|
|
|
|
g_signals.EraseTransaction.connect(boost::bind(&CWalletInterface::EraseFromWallet, pwalletIn, _1));
|
|
|
|
LOCK(cs_setpwalletRegistered);
|
|
|
|
g_signals.UpdatedTransaction.connect(boost::bind(&CWalletInterface::UpdatedTransaction, pwalletIn, _1));
|
|
|
|
BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered)
|
|
|
|
g_signals.SetBestChain.connect(boost::bind(&CWalletInterface::SetBestChain, pwalletIn, _1));
|
|
|
|
pwallet->EraseFromWallet(hash);
|
|
|
|
g_signals.Inventory.connect(boost::bind(&CWalletInterface::Inventory, pwalletIn, _1));
|
|
|
|
|
|
|
|
g_signals.Broadcast.connect(boost::bind(&CWalletInterface::ResendWalletTransactions, pwalletIn));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// make sure all wallets know about the given transaction, in the given block
|
|
|
|
void UnregisterWallet(CWalletInterface* pwalletIn) {
|
|
|
|
void SyncWithWallets(const uint256 &hash, const CTransaction& tx, const CBlock* pblock, bool fUpdate)
|
|
|
|
g_signals.Broadcast.disconnect(boost::bind(&CWalletInterface::ResendWalletTransactions, pwalletIn));
|
|
|
|
{
|
|
|
|
g_signals.Inventory.disconnect(boost::bind(&CWalletInterface::Inventory, pwalletIn, _1));
|
|
|
|
LOCK(cs_setpwalletRegistered);
|
|
|
|
g_signals.SetBestChain.disconnect(boost::bind(&CWalletInterface::SetBestChain, pwalletIn, _1));
|
|
|
|
BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered)
|
|
|
|
g_signals.UpdatedTransaction.disconnect(boost::bind(&CWalletInterface::UpdatedTransaction, pwalletIn, _1));
|
|
|
|
pwallet->AddToWalletIfInvolvingMe(hash, tx, pblock, fUpdate);
|
|
|
|
g_signals.EraseTransaction.disconnect(boost::bind(&CWalletInterface::EraseFromWallet, pwalletIn, _1));
|
|
|
|
|
|
|
|
g_signals.SyncTransaction.disconnect(boost::bind(&CWalletInterface::SyncTransaction, pwalletIn, _1, _2, _3));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// notify wallets about a new best chain
|
|
|
|
void UnregisterAllWallets() {
|
|
|
|
void static SetBestChain(const CBlockLocator& loc)
|
|
|
|
g_signals.Broadcast.disconnect_all_slots();
|
|
|
|
{
|
|
|
|
g_signals.Inventory.disconnect_all_slots();
|
|
|
|
LOCK(cs_setpwalletRegistered);
|
|
|
|
g_signals.SetBestChain.disconnect_all_slots();
|
|
|
|
BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered)
|
|
|
|
g_signals.UpdatedTransaction.disconnect_all_slots();
|
|
|
|
pwallet->SetBestChain(loc);
|
|
|
|
g_signals.EraseTransaction.disconnect_all_slots();
|
|
|
|
|
|
|
|
g_signals.SyncTransaction.disconnect_all_slots();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// notify wallets about an updated transaction
|
|
|
|
void SyncWithWallets(const uint256 &hash, const CTransaction &tx, const CBlock *pblock) {
|
|
|
|
void static UpdatedTransaction(const uint256& hashTx)
|
|
|
|
g_signals.SyncTransaction(hash, tx, pblock);
|
|
|
|
{
|
|
|
|
|
|
|
|
LOCK(cs_setpwalletRegistered);
|
|
|
|
|
|
|
|
BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered)
|
|
|
|
|
|
|
|
pwallet->UpdatedTransaction(hashTx);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// notify wallets about an incoming inventory (for request counts)
|
|
|
|
|
|
|
|
void static Inventory(const uint256& hash)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
LOCK(cs_setpwalletRegistered);
|
|
|
|
|
|
|
|
BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered)
|
|
|
|
|
|
|
|
pwallet->Inventory(hash);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ask wallets to resend their transactions
|
|
|
|
|
|
|
|
void static ResendWalletTransactions()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
LOCK(cs_setpwalletRegistered);
|
|
|
|
|
|
|
|
BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered)
|
|
|
|
|
|
|
|
pwallet->ResendWalletTransactions();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
@ -913,8 +890,8 @@ bool CTxMemPool::accept(CValidationState &state, const CTransaction &tx, bool fL
|
|
|
|
///// are we sure this is ok when loading transactions or restoring block txes
|
|
|
|
///// are we sure this is ok when loading transactions or restoring block txes
|
|
|
|
// If updated, erase old tx from wallet
|
|
|
|
// If updated, erase old tx from wallet
|
|
|
|
if (ptxOld)
|
|
|
|
if (ptxOld)
|
|
|
|
EraseFromWallets(ptxOld->GetHash());
|
|
|
|
g_signals.EraseTransaction(ptxOld->GetHash());
|
|
|
|
SyncWithWallets(hash, tx, NULL, true);
|
|
|
|
g_signals.SyncTransaction(hash, tx, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
LogPrint("mempool", "CTxMemPool::accept() : accepted %s (poolsz %"PRIszu")\n",
|
|
|
|
LogPrint("mempool", "CTxMemPool::accept() : accepted %s (poolsz %"PRIszu")\n",
|
|
|
|
hash.ToString().c_str(),
|
|
|
|
hash.ToString().c_str(),
|
|
|
@ -1974,7 +1951,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
|
|
|
|
|
|
|
|
|
|
|
|
// Watch for transactions paying to me
|
|
|
|
// Watch for transactions paying to me
|
|
|
|
for (unsigned int i = 0; i < block.vtx.size(); i++)
|
|
|
|
for (unsigned int i = 0; i < block.vtx.size(); i++)
|
|
|
|
SyncWithWallets(block.GetTxHash(i), block.vtx[i], &block, true);
|
|
|
|
g_signals.SyncTransaction(block.GetTxHash(i), block.vtx[i], &block);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -2108,7 +2085,7 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
|
|
|
|
|
|
|
|
|
|
|
|
// Update best block in wallet (so we can detect restored wallets)
|
|
|
|
// Update best block in wallet (so we can detect restored wallets)
|
|
|
|
if ((pindexNew->nHeight % 20160) == 0 || (!fIsInitialDownload && (pindexNew->nHeight % 144) == 0))
|
|
|
|
if ((pindexNew->nHeight % 20160) == 0 || (!fIsInitialDownload && (pindexNew->nHeight % 144) == 0))
|
|
|
|
::SetBestChain(chainActive.GetLocator(pindexNew));
|
|
|
|
g_signals.SetBestChain(chainActive.GetLocator(pindexNew));
|
|
|
|
|
|
|
|
|
|
|
|
// New best block
|
|
|
|
// New best block
|
|
|
|
nTimeBestReceived = GetTime();
|
|
|
|
nTimeBestReceived = GetTime();
|
|
|
@ -2188,7 +2165,7 @@ bool AddToBlockIndex(CBlock& block, CValidationState& state, const CDiskBlockPos
|
|
|
|
CheckForkWarningConditions();
|
|
|
|
CheckForkWarningConditions();
|
|
|
|
// Notify UI to display prev block's coinbase if it was ours
|
|
|
|
// Notify UI to display prev block's coinbase if it was ours
|
|
|
|
static uint256 hashPrevBestCoinBase;
|
|
|
|
static uint256 hashPrevBestCoinBase;
|
|
|
|
UpdatedTransaction(hashPrevBestCoinBase);
|
|
|
|
g_signals.UpdatedTransaction(hashPrevBestCoinBase);
|
|
|
|
hashPrevBestCoinBase = block.GetTxHash(0);
|
|
|
|
hashPrevBestCoinBase = block.GetTxHash(0);
|
|
|
|
} else
|
|
|
|
} else
|
|
|
|
CheckForkWarningConditionsOnNewFork(pindexNew);
|
|
|
|
CheckForkWarningConditionsOnNewFork(pindexNew);
|
|
|
@ -3311,7 +3288,7 @@ void static ProcessGetData(CNode* pfrom)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Track requests for our stuff.
|
|
|
|
// Track requests for our stuff.
|
|
|
|
Inventory(inv.hash);
|
|
|
|
g_signals.Inventory(inv.hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -3573,7 +3550,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Track requests for our stuff
|
|
|
|
// Track requests for our stuff
|
|
|
|
Inventory(inv.hash);
|
|
|
|
g_signals.Inventory(inv.hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -4193,7 +4170,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
|
|
|
// transactions become unconfirmed and spams other nodes.
|
|
|
|
// transactions become unconfirmed and spams other nodes.
|
|
|
|
if (!fReindex && !fImporting && !IsInitialBlockDownload())
|
|
|
|
if (!fReindex && !fImporting && !IsInitialBlockDownload())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ResendWalletTransactions();
|
|
|
|
g_signals.Broadcast();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|