[Dev] Documenting Feathercoin Specific Software settings - Part 6
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Add stealth address : - commit
https://github.com/FeatherCoin/Feathercoin/commit/e993143a1688a6aa57c03da6f181f8bf2f375bf6
src/ui_interface.h
+ /** Ask the user whether they want to pay a fee or not. */ + boost::signals2::signal<bool (int64_t nFeeRequired, const std::string& strCaption), boost::signals2::last_value<bool> > ThreadSafeAskFee; +
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Add stealth address : - commit
https://github.com/FeatherCoin/Feathercoin/commit/e993143a1688a6aa57c03da6f181f8bf2f375bf6
src/ui_interface.h
+ /** Ask the user whether they want to pay a fee or not. */ + boost::signals2::signal<bool (int64_t nFeeRequired, const std::string& strCaption), boost::signals2::last_value<bool> > ThreadSafeAskFee; +
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Add stealth address : - commit
https://github.com/FeatherCoin/Feathercoin/commit/e993143a1688a6aa57c03da6f181f8bf2f375bf6
src/wallet.cpp
Large number of changes
+ #if defined(_MSC_VER) || defined(__MSVCRT__) + /* (s)size_t and ptrdiff_t have the same size specifier in MSVC: + http://msdn.microsoft.com/en-us/library/tcxf1dw6%28v=vs.100%29.aspx + */ + #define PRIszx "Ix" + #define PRIszu "Iu" + #define PRIszd "Id" + #define PRIpdx "Ix" + #define PRIpdu "Iu" + #define PRIpdd "Id" + #else /* C99 standard */ + #define PRIszx "zx" + #define PRIszu "zu" + #define PRIszd "zd" + #define PRIpdx "tx" + #define PRIpdu "tu" + #define PRIpdd "td" + #endif +
Code added
+ bool CWallet::Lock() + { + if (IsLocked()) + return true; + + if (fDebug) + printf("Locking wallet.\n"); + + { + LOCK(cs_wallet); + CWalletDB wdb(strWalletFile); + + // -- load encrypted spend_secret of stealth addresses + CStealthAddress sxAddrTemp; + std::set<CStealthAddress>::iterator it; + for (it = stealthAddresses.begin(); it != stealthAddresses.end(); + + it) + { + if (it->scan_secret.size() < 32) + continue; // stealth address is not owned + // -- CStealthAddress are only sorted on spend_pubkey + CStealthAddress &sxAddr = const_cast<CStealthAddress&>(*it); + if (fDebug) + printf("Recrypting stealth key %s\n", sxAddr.Encoded().c_str()); + + sxAddrTemp.scan_pubkey = sxAddr.scan_pubkey; + if (!wdb.ReadStealthAddress(sxAddrTemp)) + { + printf("Error: Failed to read stealth key from db %s\n", sxAddr.Encoded().c_str()); + continue; + } + sxAddr.spend_secret = sxAddrTemp.spend_secret; + }; + } + return LockKeyStore(); + };
Code added
+ UnlockStealthAddresses(vMasterKey);
Code added
- if (CCryptoKeyStore::Unlock(vMasterKey)) + if (CCryptoKeyStore::Unlock(vMasterKey)&& UnlockStealthAddresses(vMasterKey))
Code replaced
+ std::set<CStealthAddress>::iterator it; + for (it = stealthAddresses.begin(); it != stealthAddresses.end(); + + it) + { + if (it->scan_secret.size() < 32) + continue; // stealth address is not owned + // -- CStealthAddress is only sorted on spend_pubkey + CStealthAddress &sxAddr = const_cast<CStealthAddress&>(*it); + + if (fDebug) + printf("Encrypting stealth key %s\n", sxAddr.Encoded().c_str()); + + std::vector<unsigned char> vchCryptedSecret; + + CSecret vchSecret; + vchSecret.resize(32); + memcpy(&vchSecret[0], &sxAddr.spend_secret[0], 32); + + uint256 iv = Hash(sxAddr.spend_pubkey.begin(), sxAddr.spend_pubkey.end()); + if (!EncryptSecret(vMasterKey, vchSecret, iv, vchCryptedSecret)) + { + printf("Error: Failed encrypting stealth key %s\n", sxAddr.Encoded().c_str()); + continue; + }; + + sxAddr.spend_secret = vchCryptedSecret; + pwalletdbEncryption->WriteStealthAddress(sxAddr); + }; + +
Code added
+ + FindStealthTransactions(tx); +
Code added
-bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend, + bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend, - CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl) + CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, int32_t& nChangePos, std::string& strFailReason, const CCoinControl* coinControl)
Code replaced
- vector<CTxOut>::iterator position = wtxNew.vout.begin()+GetRandInt(wtxNew.vout.size()+1);
Code removed
+ vector<CTxOut>::iterator position = wtxNew.vout.begin() + GetRandInt(wtxNew.vout.size() + 1); + + if (position > wtxNew.vout.begin() && position < wtxNew.vout.end()) + { + while (position > wtxNew.vout.begin()) + { + if (position->nValue != 0) + break; + position--; + }; + }; wtxNew.vout.insert(position, newTxOut); + nChangePos = std::distance(wtxNew.vout.begin(), position);
Code added
- bool CWallet::CreateTransaction(CScript scriptPubKey, int64_t nValue, - CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl) + bool CWallet::CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl)
Code replaced
- return CreateTransaction(vecSend, wtxNew, reservekey, nFeeRet, strFailReason, coinControl);
Code removed
+ int nChangePos; + string strError; + bool rv = CreateTransaction(vecSend, wtxNew, reservekey, nFeeRet, nChangePos, strError, coinControl); + return rv; + } + + bool CWallet::NewStealthAddress(std::string& sError, std::string& sLabel, CStealthAddress& sxAddr) + { + ec_secret scan_secret; + ec_secret spend_secret; + + if (GenerateRandomSecret(scan_secret) != 0 + || GenerateRandomSecret(spend_secret) != 0) + { + sError = "GenerateRandomSecret failed."; + printf("Error CWallet::NewStealthAddress - %s\n", sError.c_str()); + return false; + }; + + ec_point scan_pubkey, spend_pubkey; + if (SecretToPublicKey(scan_secret, scan_pubkey) != 0) + { + sError = "Could not get scan public key."; + printf("Error CWallet::NewStealthAddress - %s\n", sError.c_str()); + return false; + }; + + if (SecretToPublicKey(spend_secret, spend_pubkey) != 0) + { + sError = "Could not get spend public key."; + printf("Error CWallet::NewStealthAddress - %s\n", sError.c_str()); + return false; + }; + + if (fDebug)
Start of large section of code added from lines 1500 to 2128
+ FindStealthTransactions(wtxNew); +
Code added
+ LogPrintf("CommitTransaction start................\n"); + LogPrintf("CommitTransaction Broadcast start.............\n"); + LogPrintf("CommitTransaction RelayWalletTransaction............\n");
Code added for LofPrintf
- string CWallet::SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew)
Code replaced
+ //string CWallet::SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew) + string CWallet::SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, bool fAskFee)
Code replaced
+ //if (fAskFee && !uiInterface.ThreadSafeAskFee(nFeeRequired)) + if (fAskFee && !uiInterface.ThreadSafeAskFee(nFeeRequired, _("Sending..."))) + return "ABORTED"; + + LogPrintf("SendMoney, scriptPubKey=%s \n",scriptPubKey.ToString()); +
Code added
-string CWallet::SendMoneyToDestination(const CTxDestination& address, int64_t nValue, CWalletTx& wtxNew) + //string CWallet::SendMoneyToDestination(const CTxDestination& address, int64_t nValue, CWalletTx& wtxNew) + string CWallet::SendMoneyToDestination(const CTxDestination& address, int64 nValue, CWalletTx& wtxNew, bool fAskFee)
Code replaced
- return SendMoney(scriptPubKey, nValue, wtxNew); + LogPrintf("SendMoneyToDestination.....................\n"); + + return SendMoney(scriptPubKey, nValue, wtxNew, fAskFee);
Code replaced
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Add stealth address : - commit
https://github.com/FeatherCoin/Feathercoin/commit/e993143a1688a6aa57c03da6f181f8bf2f375bf6
src/wallet.h
Large number of updates
+ #include "stealth.h" + typedef std::map<CKeyID, CStealthKeyMetadata> StealthKeyMetaMap; + typedef std::map<std::string, std::string> mapValue_t; + std::set<CStealthAddress> stealthAddresses; + StealthKeyMetaMap mapStealthKeyMeta; + uint32_t nStealth, nFoundStealth; // for reporting, zero before use + + bool Lock();
Code added
- bool CreateTransaction(const std::vector<std::pair<CScript, int64_t> >& vecSend, - CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL); - bool CreateTransaction(CScript scriptPubKey, int64_t nValue, - CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL); - std::string SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew); - std::string SendMoneyToDestination(const CTxDestination &address, int64_t nValue, CWalletTx& wtxNew);
Code replaced
+ /*bool CreateTransaction(const std::vector<std::pair<CScript, int64_t> >& vecSend, + CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL);*/ + bool CreateTransaction(const std::vector<std::pair<CScript, int64> >& vecSend, + CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, int32_t& nChangePos, std::string& strFailReason, const CCoinControl *coinControl=NULL); + /*bool CreateTransaction(CScript scriptPubKey, int64_t nValue, + CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL);*/ + bool CreateTransaction(CScript scriptPubKey, int64 nValue, + CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL); + bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey); + //std::string SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew); + std::string SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, bool fAskFee=false); + //std::string SendMoneyToDestination(const CTxDestination &address, int64_t nValue, CWalletTx& wtxNew); + std::string SendMoneyToDestination(const CTxDestination& address, int64_t nValue, CWalletTx& wtxNew, bool fAskFee=false); + + bool NewStealthAddress(std::string& sError, std::string& sLabel, CStealthAddress& sxAddr); + bool AddStealthAddress(CStealthAddress& sxAddr); + bool UnlockStealthAddresses(const CKeyingMaterial& vMasterKeyIn); + bool UpdateStealthAddress(std::string &addr, std::string &label, bool addIfNotExist); + + bool CreateStealthTransaction(CScript scriptPubKey, int64_t nValue, std::vector<uint8_t>& P, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, const CCoinControl* coinControl=NULL); + std::string SendStealthMoney(CScript scriptPubKey, int64_t nValue, std::vector<uint8_t>& P, CWalletTx& wtxNew, bool fAskFee=false); + bool SendStealthMoneyToDestination(CStealthAddress& sxAddress, int64_t nValue, CWalletTx& wtxNew, std::string& sError, bool fAskFee=false); + bool FindStealthTransactions(const CTransaction& tx); +
Replace code added
- typedef std::map<std::string, std::string> mapValue_t; + //typedef std::map<std::string, std::string> mapValue_t;
Code commented out?
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Add stealth address : - commit
https://github.com/FeatherCoin/Feathercoin/commit/e993143a1688a6aa57c03da6f181f8bf2f375bf6
src/walletdb.cpp
- else if (strType == "acentry") + { + if (fDebug) + printf("WalletDB ReadKeyValue sxAddr\n"); + + CStealthAddress sxAddr; + ssValue >> sxAddr; + + pwallet->stealthAddresses.insert(sxAddr); + } else if (strType == "acentry")
Code replaced
+ } else if (strType == "sxKeyMeta") + { + if (fDebug) + printf("WalletDB ReadKeyValue sxKeyMeta\n"); + + CKeyID keyId; + ssKey >> keyId; + CStealthKeyMetadata sxKeyMeta; + ssValue >> sxKeyMeta; + + pwallet->mapStealthKeyMeta[keyId] = sxKeyMeta;
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Add stealth address : - commit
https://github.com/FeatherCoin/Feathercoin/commit/e993143a1688a6aa57c03da6f181f8bf2f375bf6
src/walletdb.h
+#include "stealth.h"
Code added
+ class CStealthKeyMetadata + { + // -- used to get secret for keys created by stealth transaction with wallet locked + public: + CStealthKeyMetadata() {}; + + CStealthKeyMetadata(CPubKey pkEphem_, CPubKey pkScan_) + { + pkEphem = pkEphem_; + pkScan = pkScan_; + }; + + CPubKey pkEphem; + CPubKey pkScan; + + IMPLEMENT_SERIALIZE + ( + READWRITE(pkEphem); + READWRITE(pkScan); + ) + + }; +
Stealth class added
+ Dbc* GetAtCursor() + { + return GetCursor(); + } + + Dbc* GetTxnCursor() + { + if (!pdb) + return NULL; + + DbTxn* ptxnid = activeTxn; // call TxnBegin first + + Dbc* pcursor = NULL; + int ret = pdb->cursor(ptxnid, &pcursor, 0); + if (ret != 0) + return NULL; + return pcursor; + } + + DbTxn* GetAtActiveTxn() + { + return activeTxn; + } +
Code added
+ bool WriteStealthKeyMeta(const CKeyID& keyId, const CStealthKeyMetadata& sxKeyMeta) + { + nWalletDBUpdated + + ; + return Write(std::make_pair(std::string("sxKeyMeta"), keyId), sxKeyMeta, true); + } + + bool EraseStealthKeyMeta(const CKeyID& keyId) + { + nWalletDBUpdated + + ; + return Erase(std::make_pair(std::string("sxKeyMeta"), keyId)); + } + + bool WriteStealthAddress(const CStealthAddress& sxAddr) + { + nWalletDBUpdated + + ; + + return Write(std::make_pair(std::string("sxAddr"), sxAddr.scan_pubkey), sxAddr, true); + } + + bool ReadStealthAddress(CStealthAddress& sxAddr) + { + // -- set scan_pubkey before reading + return Read(std::make_pair(std::string("sxAddr"), sxAddr.scan_pubkey), sxAddr); + } +
Code added
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix int_t64 : - commit
src/walletdb.cpp
-bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend, + bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend, - CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, int32_t& nChangePos, std::string& strFailReason, const CCoinControl* coinControl) + CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, int32_t& nChangePos, std::string& strFailReason, const CCoinControl* coinControl)
Code replaced
-bool CWallet::CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl) + bool CWallet::CreateTransaction(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl)
Code replaced
- int nChangePos; + int32_t nChangePos;
Code replaced
- vector< pair<CScript, int64> > vecSend; + vector< pair<CScript, int64_t> > vecSend;
Code replaced
- int nChangePos; + int32_t nChangePos;
Code replaced
-string CWallet::SendMoneyToDestination(const CTxDestination& address, int64 nValue, CWalletTx& wtxNew, bool fAskFee) + string CWallet::SendMoneyToDestination(const CTxDestination& address, int64_t nValue, CWalletTx& wtxNew, bool fAskFee)
Code replaced
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Fix int_t64 : - commit
src/walletdb.h
- bool CreateTransaction(const std::vector<std::pair<CScript, int64> >& vecSend, - CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, int32_t& nChangePos, std::string& strFailReason, const CCoinControl *coinControl=NULL);
Code replaced
+ bool CreateTransaction(const std::vector<std::pair<CScript, int64_t> >& vecSend, + CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, int32_t& nChangePos, std::string& strFailReason, const CCoinControl *coinControl=NULL); +
Code replaced
- bool CreateTransaction(CScript scriptPubKey, int64 nValue, - CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL);
Code replaced
+ bool CreateTransaction(CScript scriptPubKey, int64_t nValue, + CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL);
Code replaced
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
fix horizontalHeader : - commit
https://github.com/FeatherCoin/Feathercoin/commit/5abd3183c550fb9de271c10072f7e2db3cb25f47
src/qt/addressbookpage.cpp
- ui ->tableView ->horizontalHeader() ->resizeSection(0, 140); - ui ->tableView ->horizontalHeader() ->resizeSection(1, 600);
Code replaced
+ ui ->tableView ->horizontalHeader() ->resizeSection(0, 150); + ui ->tableView ->horizontalHeader() ->resizeSection(1, 900);
Code replaced, minor positional fix
-
Feathercoin specific changes made to convert Bitcoin to FTC 0.9.6.*
Define to 0 libzxing : - commit
https://github.com/FeatherCoin/Feathercoin/commit/b9528bb6426bf759d2ca241c0b49f50e8cea9cca
- define(_USE_ZXING,1) + define(_USE_ZXING,0)
Code replaced
- AC_DEFINE(USE_ZXING, _USE_ZXING,[Define to 1 libzxing must be available for support]) + AC_DEFINE(USE_ZXING, _USE_ZXING,[Define to 0 libzxing must be available for support])
Code replaced