// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include <regex>
+
#include "txdb.h"
#include "wallet.h"
#include "walletdb.h"
#include "base58.h"
#include "kernel.h"
#include "coincontrol.h"
-#include <boost/algorithm/string/replace.hpp>
+#include "timedata.h"
+
#include <openssl/bio.h>
#include "main.h"
using namespace std;
+
+//Settings
+
extern int64_t nReserveBalance;
+int64_t nTransactionFee = MIN_TX_FEE;
//////////////////////////////////////////////////////////////////////////////
//
return true;
}
+bool CWallet::LoadMinVersion(int nVersion)
+{
+ nWalletVersion = nVersion;
+ nWalletMaxVersion = max(nWalletMaxVersion, nVersion);
+ return true;
+}
+
bool CWallet::AddCScript(const CScript& redeemScript)
{
if (!CCryptoKeyStore::AddCScript(redeemScript))
* these. Do not add them to the wallet and warn. */
if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE)
{
- auto strAddr = CBitcoinAddress(redeemScript.GetID()).ToString();
+ auto strAddr = CBitcoinAddress(CScriptID(redeemScript)).ToString();
printf("LoadCScript() : Warning: This wallet contains a redeemScript of size %" PRIszu " which exceeds maximum size %i thus can never be redeemed. Do not use address %s.\n",
redeemScript.size(), MAX_SCRIPT_ELEMENT_SIZE, strAddr.c_str());
return true;
// notify an external script when a wallet transaction comes in or is updated
auto strCmd = GetArg("-walletnotify", "");
- if ( !strCmd.empty())
- {
- boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex());
- boost::thread t(runCommand, strCmd); // thread runs free
- }
+ if (!strCmd.empty())
+ // thread runs free
+ boost::thread t(runCommand, regex_replace(strCmd, static_cast<regex>("%s"), wtxIn.GetHash().GetHex()));
}
return true;
return MINE_NO;
}
+
CWalletTx::CWalletTx()
{
Init(NULL);
{
// Check amount
if (nValue <= 0)
- return _("Invalid amount");
+ return "Invalid amount";
if (nValue + nTransactionFee > GetBalance())
- return _("Insufficient funds");
+ return "Insufficient funds";
CReserveKey reservekey(this);
int64_t nFeeRequired;
if (IsLocked())
{
- string strError = _("Error: Wallet locked, unable to create transaction ");
+ string strError("Error: Wallet locked, unable to create transaction ");
printf("SendMoney() : %s", strError.c_str());
return strError;
}
if (fWalletUnlockMintOnly)
{
- string strError = _("Error: Wallet unlocked for block minting only, unable to create transaction.");
+ string strError("Error: Wallet unlocked for block minting only, unable to create transaction.");
printf("SendMoney() : %s", strError.c_str());
return strError;
}
return "ABORTED";
if (!CommitTransaction(wtxNew, reservekey))
- return _("Error: The transaction was rejected. This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here.");
+ return "Error: The transaction was rejected. This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here.";
return "";
}
printf("\n");
}
+void CWallet::Inventory(const uint256 &hash)
+{
+ {
+ LOCK(cs_wallet);
+ auto mi = mapRequestCount.find(hash);
+ if (mi != mapRequestCount.end())
+ (*mi).second++;
+ }
+}
+
bool CWallet::GetTransaction(const uint256 &hashTx, CWalletTx& wtx)
{
{
}
}
-int64_t CWallet::AddReserveKey(const CKeyPool& keypool)
-{
- {
- LOCK2(cs_main, cs_wallet);
- CWalletDB walletdb(strWalletFile);
-
- int64_t 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_t nIndex)
{
// Remove from key pool
{
CWalletTx *pcoin = &walletEntry.second;
- if (pcoin->vin.size() > 0 && IsMine(pcoin->vin[0]))
+ if (pcoin->vin.size() > 0)
{
+ bool any_mine = false;
// group all input addresses with each other
for(CTxIn txin : pcoin->vin)
{
CBitcoinAddress address;
+ if(!IsMine(txin)) // If this input isn't mine, ignore it
+ continue;
if(!ExtractAddress(*this, mapWallet[txin.prevout.hash].vout[txin.prevout.n].scriptPubKey, address))
continue;
grouping.insert(address);
+ any_mine = true;
}
// group change with input addresses
+ if (any_mine)
+ {
for(CTxOut txout : pcoin->vout)
if (IsChange(txout))
{
- auto tx = mapWallet[pcoin->vin[0].prevout.hash];
CBitcoinAddress txoutAddr;
if(!ExtractAddress(*this, txout.scriptPubKey, txoutAddr))
continue;
grouping.insert(txoutAddr);
}
- groupings.insert(grouping);
- grouping.clear();
+ }
+ if (!grouping.empty())
+ {
+ groupings.insert(grouping);
+ grouping.clear();
+ }
}
// group lone addrs by themselves