return key.GetPubKey();
}
+CMalleableKeyView CWallet::GenerateNewMalleableKey()
+{
+ RandAddSeedPerfmon();
+
+ // Compressed public keys were introduced in version 0.6.0
+ SetMinVersion(FEATURE_MALLKEY);
+
+ CMalleableKey mKey;
+ mKey.MakeNewKeys();
+ const CMalleableKeyView &keyView(mKey);
+
+ // Create new metadata
+ int64_t nCreationTime = GetTime();
+ mapMalleableKeyMetadata[keyView] = CKeyMetadata(nCreationTime);
+ if (!nTimeFirstKey || nCreationTime < nTimeFirstKey)
+ nTimeFirstKey = nCreationTime;
+
+ if (!AddMalleableKey(mKey))
+ throw std::runtime_error("CWallet::GenerateNewMalleableKey() : AddMalleableKey failed");
+ return CMalleableKeyView(mKey);
+}
+
bool CWallet::AddKey(const CKey& key)
{
CPubKey pubkey = key.GetPubKey();
return true;
}
+bool CWallet::AddMalleableKey(const CMalleableKey& mKey)
+{
+ CMalleableKeyView keyView = CMalleableKeyView(mKey);
+ if (!CCryptoKeyStore::AddMalleableKey(mKey))
+ return false;
+ if (!fFileBacked)
+ return true;
+ if (!IsCrypted())
+ return CWalletDB(strWalletFile).WriteMalleableKey(keyView, mKey, mapMalleableKeyMetadata[keyView]);
+ return true;
+}
+
bool CWallet::AddCryptedKey(const CPubKey &vchPubKey, const vector<unsigned char> &vchCryptedSecret)
{
if (!CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret))
return true;
}
+bool CWallet::LoadMalleableKeyMetadata(const CMalleableKeyView &keyView, const CKeyMetadata &metadata)
+{
+ if (metadata.nCreateTime && (!nTimeFirstKey || metadata.nCreateTime < nTimeFirstKey))
+ nTimeFirstKey = metadata.nCreateTime;
+
+ mapMalleableKeyMetadata[keyView] = metadata;
+ return true;
+}
+
bool CWallet::AddCScript(const CScript& redeemScript)
{
if (!CCryptoKeyStore::AddCScript(redeemScript))
if (setCoins.empty())
return false;
- bool fMaxTimeWeight = false;
+ bool fDontSplitCoins = false;
if (GetWeight((int64_t)wtx.nTime, (int64_t)nGenerationTime) == nStakeMaxAge)
{
// Only one output for old kernel inputs
vwtxPrev.push_back(pcoin->first);
}
- fMaxTimeWeight = true;
+ fDontSplitCoins = true;
}
else
{
- // Split stake input if maximum weight isn't reached yet
- txNew.vout.push_back(CTxOut(0, scriptPubKeyOut));
- txNew.vout.push_back(CTxOut(0, scriptPubKeyOut));
+ int64_t nSplitThreshold = GetArg("-splitthreshold", nCombineThreshold);
if (fDebug && GetBoolArg("-printcoinstake"))
- printf("CreateCoinStake : maximum time weight isn't reached, splitting coinstake\n");
+ printf("CreateCoinStake : nSplitThreshold=%" PRId64 "\n", nSplitThreshold);
+
+ if (nCredit > nSplitThreshold)
+ {
+ // Split stake input if credit is lower than combine threshold and maximum weight isn't reached yet
+ txNew.vout.push_back(CTxOut(0, scriptPubKeyOut));
+ txNew.vout.push_back(CTxOut(0, scriptPubKeyOut));
+
+ if (fDebug && GetBoolArg("-printcoinstake"))
+ printf("CreateCoinStake : splitting coinstake\n");
+ }
+ else
+ {
+ txNew.vout.push_back(CTxOut(0, scriptPubKeyOut));
+ fDontSplitCoins = true;
+ }
}
// Calculate coin age reward
while (true)
{
// Set output amount
- if (fMaxTimeWeight)
+ if (fDontSplitCoins)
txNew.vout[1].nValue = nCredit - nMinFee;
else
{
AddToWallet(wtxNew);
// Mark old coins as spent
- set<CWalletTx*> setCoins;
BOOST_FOREACH(const CTxIn& txin, wtxNew.vin)
{
CWalletTx &coin = mapWallet[txin.prevout.hash];
string CWallet::SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, bool fAskFee)
{
+ // Check amount
+ if (nValue <= 0)
+ return _("Invalid amount");
+ if (nValue + nTransactionFee > GetBalance())
+ return _("Insufficient funds");
+
CReserveKey reservekey(this);
int64_t nFeeRequired;
return "";
}
-
-
-string CWallet::SendMoneyToDestination(const CTxDestination& address, int64_t nValue, CWalletTx& wtxNew, bool fAskFee)
-{
- // Check amount
- if (nValue <= 0)
- return _("Invalid amount");
- if (nValue + nTransactionFee > GetBalance())
- return _("Insufficient funds");
-
- // Parse Bitcoin address
- CScript scriptPubKey;
- scriptPubKey.SetDestination(address);
-
- return SendMoney(scriptPubKey, nValue, wtxNew, fAskFee);
-}
-
-
-
-
DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
{
if (!fFileBacked)