Skip to content

Commit

Permalink
Add mininput to deal with dust spam.
Browse files Browse the repository at this point in the history
By default, mininput is set to 0.0001. This means that create transaction will
ignore any transactions with an output value less than 0.0001. You can override
the default by passing in -mininput on startup or by calling setmininput.
  • Loading branch information
coblee authored and khalahan committed Jan 25, 2012
1 parent 1d8bff7 commit fe85d48
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/db.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ bool CWalletDB::LoadWallet(CWallet* pwallet)
if (strKey == "fGenerateBitcoins") ssValue >> fGenerateBitcoins; if (strKey == "fGenerateBitcoins") ssValue >> fGenerateBitcoins;
#endif #endif
if (strKey == "nTransactionFee") ssValue >> nTransactionFee; if (strKey == "nTransactionFee") ssValue >> nTransactionFee;
if (strKey == "nMinimumInputValue") ssValue >> nMinimumInputValue;
if (strKey == "fLimitProcessors") ssValue >> fLimitProcessors; if (strKey == "fLimitProcessors") ssValue >> fLimitProcessors;
if (strKey == "nLimitProcessors") ssValue >> nLimitProcessors; if (strKey == "nLimitProcessors") ssValue >> nLimitProcessors;
if (strKey == "fMinimizeToTray") ssValue >> fMinimizeToTray; if (strKey == "fMinimizeToTray") ssValue >> fMinimizeToTray;
Expand All @@ -821,6 +822,7 @@ bool CWalletDB::LoadWallet(CWallet* pwallet)
printf("nFileVersion = %d\n", nFileVersion); printf("nFileVersion = %d\n", nFileVersion);
printf("fGenerateBitcoins = %d\n", fGenerateBitcoins); printf("fGenerateBitcoins = %d\n", fGenerateBitcoins);
printf("nTransactionFee = %"PRI64d"\n", nTransactionFee); printf("nTransactionFee = %"PRI64d"\n", nTransactionFee);
printf("nMinimumInputValue = %"PRI64d"\n", nMinimumInputValue);
printf("fMinimizeToTray = %d\n", fMinimizeToTray); printf("fMinimizeToTray = %d\n", fMinimizeToTray);
printf("fMinimizeOnClose = %d\n", fMinimizeOnClose); printf("fMinimizeOnClose = %d\n", fMinimizeOnClose);
printf("fUseProxy = %d\n", fUseProxy); printf("fUseProxy = %d\n", fUseProxy);
Expand Down
10 changes: 10 additions & 0 deletions src/init.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ bool AppInit2(int argc, char* argv[])
#endif #endif
#endif #endif
" -paytxfee=<amt> \t " + _("Fee per KB to add to transactions you send\n") + " -paytxfee=<amt> \t " + _("Fee per KB to add to transactions you send\n") +
" -mininput=<amt> \t " + _("When creating transactions, ignore inputs with value less than this (default: 0.0001)\n") +
#ifdef GUI #ifdef GUI
" -server \t\t " + _("Accept command line and JSON-RPC commands\n") + " -server \t\t " + _("Accept command line and JSON-RPC commands\n") +
#endif #endif
Expand Down Expand Up @@ -512,6 +513,15 @@ bool AppInit2(int argc, char* argv[])
wxMessageBox(_("Warning: -paytxfee is set very high. This is the transaction fee you will pay if you send a transaction."), "Bitcoin", wxOK | wxICON_EXCLAMATION); wxMessageBox(_("Warning: -paytxfee is set very high. This is the transaction fee you will pay if you send a transaction."), "Bitcoin", wxOK | wxICON_EXCLAMATION);
} }


if (mapArgs.count("-mininput"))
{
if (!ParseMoney(mapArgs["-mininput"], nMinimumInputValue))
{
wxMessageBox(_("Invalid amount for -mininput=<amount>"), "Litecoin");
return false;
}
}

if (fHaveUPnP) if (fHaveUPnP)
{ {
#if USE_UPNP #if USE_UPNP
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ int64 nHPSTimerStart;
// Settings // Settings
int fGenerateBitcoins = false; int fGenerateBitcoins = false;
int64 nTransactionFee = 0; int64 nTransactionFee = 0;
int64 nMinimumInputValue = CENT / 100;
int fLimitProcessors = false; int fLimitProcessors = false;
int nLimitProcessors = 1; int nLimitProcessors = 1;
int fMinimizeToTray = true; int fMinimizeToTray = true;
Expand Down
1 change: 1 addition & 0 deletions src/main.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ extern std::set<CWallet*> setpwalletRegistered;
// Settings // Settings
extern int fGenerateBitcoins; extern int fGenerateBitcoins;
extern int64 nTransactionFee; extern int64 nTransactionFee;
extern int64 nMinimumInputValue;
extern int fLimitProcessors; extern int fLimitProcessors;
extern int nLimitProcessors; extern int nLimitProcessors;
extern int fMinimizeToTray; extern int fMinimizeToTray;
Expand Down
19 changes: 19 additions & 0 deletions src/rpc.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("testnet", fTestNet)); obj.push_back(Pair("testnet", fTestNet));
obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime())); obj.push_back(Pair("keypoololdest", (boost::int64_t)pwalletMain->GetOldestKeyPoolTime()));
obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee))); obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
obj.push_back(Pair("mininput", ValueFromAmount(nMinimumInputValue)));
obj.push_back(Pair("errors", GetWarnings("statusbar"))); obj.push_back(Pair("errors", GetWarnings("statusbar")));
return obj; return obj;
} }
Expand Down Expand Up @@ -651,6 +652,22 @@ Value settxfee(const Array& params, bool fHelp)
return true; return true;
} }


Value setmininput(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 1)
throw runtime_error(
"setmininput <amount>\n"
"<amount> is a real and is rounded to the nearest 0.00000001");

// Amount
int64 nAmount = 0;
if (params[0].get_real() != 0.0)
nAmount = AmountFromValue(params[0]); // rejects 0.0 amounts

nMinimumInputValue = nAmount;
return true;
}

Value sendtoaddress(const Array& params, bool fHelp) Value sendtoaddress(const Array& params, bool fHelp)
{ {
if (fHelp || params.size() < 2 || params.size() > 4) if (fHelp || params.size() < 2 || params.size() > 4)
Expand Down Expand Up @@ -2012,6 +2029,7 @@ pair<string, rpcfn_type> pCallTable[] =
make_pair("listaccounts", &listaccounts), make_pair("listaccounts", &listaccounts),
make_pair("settxfee", &settxfee), make_pair("settxfee", &settxfee),
make_pair("getmemorypool", &getmemorypool), make_pair("getmemorypool", &getmemorypool),
make_pair("setmininput", &setmininput),
}; };
map<string, rpcfn_type> mapCallTable(pCallTable, pCallTable + sizeof(pCallTable)/sizeof(pCallTable[0])); map<string, rpcfn_type> mapCallTable(pCallTable, pCallTable + sizeof(pCallTable)/sizeof(pCallTable[0]));


Expand Down Expand Up @@ -2656,6 +2674,7 @@ int CommandLineRPC(int argc, char *argv[])
if (strMethod == "sendtoaddress" && n > 1) ConvertTo<double>(params[1]); if (strMethod == "sendtoaddress" && n > 1) ConvertTo<double>(params[1]);
if (strMethod == "settxfee" && n > 0) ConvertTo<double>(params[0]); if (strMethod == "settxfee" && n > 0) ConvertTo<double>(params[0]);
if (strMethod == "getamountreceived" && n > 1) ConvertTo<boost::int64_t>(params[1]); // deprecated if (strMethod == "getamountreceived" && n > 1) ConvertTo<boost::int64_t>(params[1]); // deprecated
if (strMethod == "setmininput" && n > 0) ConvertTo<double>(params[0]);
if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "getreceivedbylabel" && n > 1) ConvertTo<boost::int64_t>(params[1]); // deprecated if (strMethod == "getreceivedbylabel" && n > 1) ConvertTo<boost::int64_t>(params[1]); // deprecated
Expand Down
4 changes: 3 additions & 1 deletion src/wallet.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -621,7 +621,9 @@ bool CWallet::SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfThe


int64 n = pcoin->vout[i].nValue; int64 n = pcoin->vout[i].nValue;


if (n <= 0) // If output is less than minimum value, then don't include transaction.
// This is to help deal with dust spam clogging up create transactions.
if (n <= 0 || n < nMinimumInputValue)
continue; continue;


pair<int64,pair<const CWalletTx*,unsigned int> > coin = make_pair(n,make_pair(pcoin,i)); pair<int64,pair<const CWalletTx*,unsigned int> > coin = make_pair(n,make_pair(pcoin,i));
Expand Down

0 comments on commit fe85d48

Please sign in to comment.