@ -136,11 +136,7 @@ bool AddToWallet(const CWalletTx& wtxIn)
wtx . fFromMe = wtxIn . fFromMe ;
wtx . fFromMe = wtxIn . fFromMe ;
fUpdated = true ;
fUpdated = true ;
}
}
if ( wtxIn . fSpent & & wtxIn . fSpent ! = wtx . fSpent )
fUpdated | = wtx . UpdateSpent ( wtxIn . vfSpent ) ;
{
wtx . fSpent = wtxIn . fSpent ;
fUpdated = true ;
}
}
}
//// debug print
//// debug print
@ -221,10 +217,10 @@ void WalletUpdateSpent(const COutPoint& prevout)
if ( mi ! = mapWallet . end ( ) )
if ( mi ! = mapWallet . end ( ) )
{
{
CWalletTx & wtx = ( * mi ) . second ;
CWalletTx & wtx = ( * mi ) . second ;
if ( ! wtx . fSpent & & wtx . vout [ prevout . n ] . IsMine ( ) )
if ( ! wtx . IsSpent ( prevout . n ) & & wtx . vout [ prevout . n ] . IsMine ( ) )
{
{
printf ( " WalletUpdateSpent found spent coin %sbc %s \n " , FormatMoney ( wtx . GetCredit ( ) ) . c_str ( ) , wtx . GetHash ( ) . ToString ( ) . c_str ( ) ) ;
printf ( " WalletUpdateSpent found spent coin %sbc %s \n " , FormatMoney ( wtx . GetCredit ( ) ) . c_str ( ) , wtx . GetHash ( ) . ToString ( ) . c_str ( ) ) ;
wtx . fSpent = true ;
wtx . MarkSpent ( prevout . n ) ;
wtx . WriteToDisk ( ) ;
wtx . WriteToDisk ( ) ;
vWalletUpdated . push_back ( prevout . hash ) ;
vWalletUpdated . push_back ( prevout . hash ) ;
}
}
@ -939,34 +935,34 @@ void ReacceptWalletTransactions()
foreach ( PAIRTYPE ( const uint256 , CWalletTx ) & item , mapWallet )
foreach ( PAIRTYPE ( const uint256 , CWalletTx ) & item , mapWallet )
{
{
CWalletTx & wtx = item . second ;
CWalletTx & wtx = item . second ;
if ( wtx . fSpent & & wtx . IsCoinBase ( ) )
if ( wtx . IsCoinBase ( ) & & wtx . IsSpent ( 0 ) )
continue ;
continue ;
CTxIndex txindex ;
CTxIndex txindex ;
bool fUpdated = false ;
if ( txdb . ReadTxIndex ( wtx . GetHash ( ) , txindex ) )
if ( txdb . ReadTxIndex ( wtx . GetHash ( ) , txindex ) )
{
{
// Update fSpent if a tx got spent somewhere else by a copy of wallet.dat
// Update fSpent if a tx got spent somewhere else by a copy of wallet.dat
if ( ! wtx . fSpent )
if ( txindex . vSpent . size ( ) ! = wtx . vout . size ( ) )
{
{
if ( txindex . vSpent . size ( ) ! = wtx . vout . size ( ) )
printf ( " ERROR: ReacceptWalletTransactions() : txindex.vSpent.size() %d != wtx.vout.size() %d \n " , txindex . vSpent . size ( ) , wtx . vout . size ( ) ) ;
{
continue ;
printf ( " ERROR: ReacceptWalletTransactions() : txindex.vSpent.size() %d != wtx.vout.size() %d \n " , txindex . vSpent . size ( ) , wtx . vout . size ( ) ) ;
}
continue ;
for ( int i = 0 ; i < txindex . vSpent . size ( ) ; i + + )
}
{
for ( int i = 0 ; i < txindex . vSpent . size ( ) ; i + + )
if ( ! txindex . vSpent [ i ] . IsNull ( ) & & wtx . vout [ i ] . IsMine ( ) )
{
if ( ! txindex . vSpent [ i ] . IsNull ( ) & & wtx . vout [ i ] . IsMine ( ) )
{
wtx . fSpent = true ;
vMissingTx . push_back ( txindex . vSpent [ i ] ) ;
}
}
if ( wtx . fSpent )
{
{
printf ( " ReacceptWalletTransactions found spent coin %sbc %s \n " , FormatMoney ( wtx . GetCredit ( ) ) . c_str ( ) , wtx . GetHash ( ) . ToString ( ) . c_str ( ) ) ;
wtx . MarkSpent ( i ) ;
wtx . WriteToDisk ( ) ;
fUpdated = true ;
vMissingTx . push_back ( txindex . vSpent [ i ] ) ;
}
}
}
}
if ( fUpdated )
{
printf ( " ReacceptWalletTransactions found spent coin %sbc %s \n " , FormatMoney ( wtx . GetCredit ( ) ) . c_str ( ) , wtx . GetHash ( ) . ToString ( ) . c_str ( ) ) ;
wtx . MarkDirty ( ) ;
wtx . WriteToDisk ( ) ;
}
}
}
else
else
{
{
@ -3732,9 +3728,9 @@ int64 GetBalance()
for ( map < uint256 , CWalletTx > : : iterator it = mapWallet . begin ( ) ; it ! = mapWallet . end ( ) ; + + it )
for ( map < uint256 , CWalletTx > : : iterator it = mapWallet . begin ( ) ; it ! = mapWallet . end ( ) ; + + it )
{
{
CWalletTx * pcoin = & ( * it ) . second ;
CWalletTx * pcoin = & ( * it ) . second ;
if ( ! pcoin - > IsFinal ( ) | | pcoin - > fSpent | | ! pcoin - > IsConfirmed ( ) )
if ( ! pcoin - > IsFinal ( ) | | ! pcoin - > IsConfirmed ( ) )
continue ;
continue ;
nTotal + = pcoin - > GetCredit ( ) ;
nTotal + = pcoin - > GetAvailable Credit ( ) ;
}
}
}
}
@ -3763,14 +3759,17 @@ bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, set<
foreach ( CWalletTx * pcoin , vCoins )
foreach ( CWalletTx * pcoin , vCoins )
{
{
if ( ! pcoin - > IsFinal ( ) | | pcoin - > fSpent | | ! pcoin - > IsConfirmed ( ) )
if ( ! pcoin - > IsFinal ( ) | | ! pcoin - > IsConfirmed ( ) )
continue ;
if ( pcoin - > IsCoinBase ( ) & & pcoin - > GetBlocksToMaturity ( ) > 0 )
continue ;
continue ;
int nDepth = pcoin - > GetDepthInMainChain ( ) ;
int nDepth = pcoin - > GetDepthInMainChain ( ) ;
if ( nDepth < ( pcoin - > IsFromMe ( ) ? nConfMine : nConfTheirs ) )
if ( nDepth < ( pcoin - > IsFromMe ( ) ? nConfMine : nConfTheirs ) )
continue ;
continue ;
int64 n = pcoin - > GetCredit ( ) ;
int64 n = pcoin - > GetAvailable Credit ( ) ;
if ( n < = 0 )
if ( n < = 0 )
continue ;
continue ;
if ( n = = nTargetValue )
if ( n = = nTargetValue )
@ -4017,12 +4016,11 @@ bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
// Mark old coins as spent
// Mark old coins as spent
set < CWalletTx * > setCoins ;
set < CWalletTx * > setCoins ;
foreach ( const CTxIn & txin , wtxNew . vin )
foreach ( const CTxIn & txin , wtxNew . vin )
setCoins . insert ( & mapWallet [ txin . prevout . hash ] ) ;
foreach ( CWalletTx * pcoin , setCoins )
{
{
pcoin - > fSpent = true ;
CWalletTx & pcoin = mapWallet [ txin . prevout . hash ] ;
pcoin - > WriteToDisk ( ) ;
pcoin . MarkSpent ( txin . prevout . n ) ;
vWalletUpdated . push_back ( pcoin - > GetHash ( ) ) ;
pcoin . WriteToDisk ( ) ;
vWalletUpdated . push_back ( pcoin . GetHash ( ) ) ;
}
}
}
}