#include "crypter.h"
#include "ui_interface.h"
#include "base58.h"
+#include <boost/algorithm/string/replace.hpp>
using namespace std;
}
else
printf("AddToWallet() : found %s in block %s not in index\n",
- wtxIn.GetHash().ToString().substr(0,10).c_str(),
+ wtxIn.GetHash().ToString().c_str(),
wtxIn.hashBlock.ToString().c_str());
}
}
}
//// debug print
- printf("AddToWallet %s %s%s\n", wtxIn.GetHash().ToString().substr(0,10).c_str(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : ""));
+ printf("AddToWallet %s %s%s\n", wtxIn.GetHash().ToString().c_str(), (fInsertedNew ? "new" : ""), (fUpdated ? "update" : ""));
// Write to disk
if (fInsertedNew || fUpdated)
// Notify UI of new or updated transaction
NotifyTransactionChanged(this, hash, fInsertedNew ? CT_NEW : CT_UPDATED);
+
+ // notify an external script when a wallet transaction comes in or is updated
+ std::string strCmd = GetArg("-walletnotify", "");
+
+ if ( !strCmd.empty())
+ {
+ boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex());
+ boost::thread t(runCommand, strCmd); // thread runs free
+ }
+
}
return true;
}
{
if (GetDepthInMainChain() == 0) {
uint256 hash = GetHash();
- printf("Relaying wtx %s\n", hash.ToString().substr(0,10).c_str());
+ printf("Relaying wtx %s\n", hash.ToString().c_str());
RelayTransaction((CTransaction)*this, hash);
}
}
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
const CWalletTx* pcoin = &(*it).second;
- if (pcoin->IsFinal() && pcoin->IsConfirmed())
+ if (pcoin->IsConfirmed())
nTotal += pcoin->GetAvailableCredit();
}
}
vfBest.assign(vValue.size(), true);
nBest = nTotalLower;
+ seed_insecure_rand();
+
for (int nRep = 0; nRep < iterations && nBest != nTargetValue; nRep++)
{
vfIncluded.assign(vValue.size(), false);
{
for (unsigned int i = 0; i < vValue.size(); i++)
{
- if (nPass == 0 ? rand() % 2 : !vfIncluded[i])
+ //The solver here uses a randomized algorithm,
+ //the randomness serves no real security purpose but is just
+ //needed to prevent degenerate behavior and it is important
+ //that the rng fast. We do not use a constant random sequence,
+ //because there may be some privacy improvement by making
+ //the selection random.
+ if (nPass == 0 ? insecure_rand()&1 : !vfIncluded[i])
{
nTotal += vValue[i].first;
vfIncluded[i] = true;
double dPriority = 0;
// vouts to the payees
BOOST_FOREACH (const PAIRTYPE(CScript, int64)& s, vecSend)
- wtxNew.vout.push_back(CTxOut(s.second, s.first));
+ {
+ CTxOut txout(s.second, s.first);
+ if (txout.IsDust())
+ return false;
+ wtxNew.vout.push_back(txout);
+ }
// Choose coins to use
set<pair<const CWalletTx*,unsigned int> > setCoins;
CScript scriptChange;
scriptChange.SetDestination(vchPubKey.GetID());
- // Insert change txn at random position:
- vector<CTxOut>::iterator position = wtxNew.vout.begin()+GetRandInt(wtxNew.vout.size());
- wtxNew.vout.insert(position, CTxOut(nChange, scriptChange));
+ CTxOut newTxOut(nChange, scriptChange);
+
+ // Never create dust outputs; if we would, just
+ // add the dust to the fee.
+ if (newTxOut.IsDust())
+ {
+ nFeeRet += nChange;
+ reservekey.ReturnKey();
+ }
+ else
+ {
+ // Insert change txn at random position:
+ vector<CTxOut>::iterator position = wtxNew.vout.begin()+GetRandInt(wtxNew.vout.size()+1);
+ wtxNew.vout.insert(position, newTxOut);
+ }
}
else
reservekey.ReturnKey();
// Limit size
unsigned int nBytes = ::GetSerializeSize(*(CTransaction*)&wtxNew, SER_NETWORK, PROTOCOL_VERSION);
- if (nBytes >= MAX_BLOCK_SIZE_GEN/5)
+ if (nBytes >= MAX_STANDARD_TX_SIZE)
return false;
dPriority /= nBytes;
mapRequestCount[wtxNew.GetHash()] = 0;
// Broadcast
- if (!wtxNew.AcceptToMemoryPool())
+ if (!wtxNew.AcceptToMemoryPool(true, false))
{
// This must not fail. The transaction has already been signed and recorded.
printf("CommitTransaction() : Error: Transaction not valid");
return nLoadWalletRet;
fFirstRunRet = !vchDefaultKey.IsValid();
- NewThread(ThreadFlushWalletDB, &strWalletFile);
return DB_LOAD_OK;
}