From c0fefe5571478f66f90381cbccb6ad12680f97b1 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 12 Jan 2020 22:58:45 +0100 Subject: [PATCH 1/6] Update komodo_defs.h https://github.com/KMDLabs/komodo/compare/403214b49b23...77a14e746593 --- src/komodo_defs.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 32977fe60ef..8c0ce748d62 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -384,6 +384,7 @@ extern int32_t ASSETCHAINS_EARLYTXIDCONTRACT; extern int32_t ASSETCHAINS_STAKED_SPLIT_PERCENTAGE; int tx_height( const uint256 &hash ); extern std::vector vWhiteListAddress; +extern bool fWalletFilter; extern std::map mapHeightEvalActivate; void komodo_netevent(std::vector payload); int32_t getacseason(uint32_t timestamp); From 41bff9b3bcb642258b43c16f4fd44bc27818e438 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 12 Jan 2020 23:00:29 +0100 Subject: [PATCH 2/6] Update komodo_globals.h https://github.com/KMDLabs/komodo/compare/403214b49b23...77a14e746593 --- src/komodo_globals.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 22975417d90..7ae1096fb55 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -57,6 +57,7 @@ int8_t ASSETCHAINS_ADAPTIVEPOW; bool VERUS_MINTBLOCKS; std::vector Mineropret; std::vector vWhiteListAddress; +bool fWalletFilter = false; char NOTARYADDRS[64][64]; char NOTARY_ADDRESSES[NUM_KMD_SEASONS][64][64]; From 008dcfe6e0e300f4807c213821c43233ed93569d Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 12 Jan 2020 23:05:06 +0100 Subject: [PATCH 3/6] Update rpcwallet.cpp https://github.com/KMDLabs/komodo/compare/403214b49b23...77a14e746593 --- src/wallet/rpcwallet.cpp | 184 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index cf60b8b5271..5debb50292b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -420,6 +420,186 @@ UniValue getaccount(const UniValue& params, bool fHelp, const CPubKey& mypk) } +void komodo_dumpwalletfilter() +{ + // save the wallet filter vector to a file for loading on restart of daemon. + char fname[512]; + komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"walletfilterlist"); + remove(fname); + std::ofstream out(fname); + if ( fWalletFilter ) + out << "1" << endl; + else + out << "0" << endl; + for ( auto address : vWhiteListAddress ) + out << address << endl; + out.close(); +} + +UniValue addwhitelistaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) +{ + if (!EnsureWalletIsAvailable(fHelp)) + return NullUniValue; + + if (fHelp || params.size() == 0) + throw runtime_error( + "addwhitelistaddress \"address1\" \"address2\" \"addressn\"\n" + "\nAdds a new " + strprintf("%s",komodo_chainname()) + " address to the whitelist walletfilter.\n" + "\nArguments:\n" + "1. \"address1\" (string) A valid komodo R address.\n" + "\nResult:\n" + "\"number of valid addresses added\n" + "\nExamples:\n" + + HelpExampleCli("addwhitelistaddress", "RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV") + + HelpExampleRpc("addwhitelistaddress", "RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV") + ); + + LOCK2(cs_main, pwalletMain->cs_wallet); + int n = 0; std::string NotaryAddress; + if ( NOTARY_PUBKEY33[0] != 0 ) + { + char Raddress[64]; + pubkey2addr((char *)Raddress,(uint8_t *)NOTARY_PUBKEY33); + NotaryAddress.assign(Raddress); + } + for ( int i = 0; i < params.size(); i++) + { + // check address is a valid address + CTxDestination dest = DecodeDestination(params[i].get_str()); + if ( IsValidDestination(dest) && params[i].get_str() != NotaryAddress ) + { + bool dupe = false; + // then add it to the vector. + for ( auto address : vWhiteListAddress ) + if ( params[i].get_str() == address ) + dupe = true; + if ( !dupe ) + { + vWhiteListAddress.push_back(params[i].get_str()); + n++; + } + } + } + komodo_dumpwalletfilter(); + return n; +} + +UniValue removewhitelistaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) +{ + if (!EnsureWalletIsAvailable(fHelp)) + return NullUniValue; + + if (fHelp || params.size() == 0) + throw runtime_error( + "removewhitelistaddress \"address1\" \"address2\" \"addressn\"\n" + "\nRemoves an " + strprintf("%s",komodo_chainname()) + " address from the whitelist walletfilter.\n" + "\nArguments:\n" + "1. \"address1\" (string) A valid komodo R address.\n" + "\nResult:\n" + "\"number of valid addresses removed\n" + "\nExamples:\n" + + HelpExampleCli("removewhitelistaddress", "RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV") + + HelpExampleRpc("removewhitelistaddress", "RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV") + ); + + LOCK2(cs_main, pwalletMain->cs_wallet); + int n = 0, total = 0; + for ( int i = 0; i < params.size(); i++) + { + // check address is a valid address + CTxDestination dest = DecodeDestination(params[i].get_str()); + if (IsValidDestination(dest)) + { + int j; + for ( j = 0; j < vWhiteListAddress.size(); j++ ) + { + if ( vWhiteListAddress[j] == params[i].get_str() ) + { + // then remove it from vector + n++; total++; + break; + } + } + if ( n > 0 ) + { + vWhiteListAddress.erase(vWhiteListAddress.begin()+j); + n = 0; + } + } + } + komodo_dumpwalletfilter(); + return total; +} + +UniValue setwalletfilter(const UniValue& params, bool fHelp, const CPubKey& mypk) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "setwalletfilter \"true/false\"\n" + "\nTurns the walletfilter on or off.\n" + "\nArguments:\n" + "1. \"true/false\" (string) True for on, False for off.\n" + "\nResult:\n" + "\"current status\n" + "\nExamples:\n" + + HelpExampleCli("setwalletfilter", "true") + + HelpExampleRpc("setwalletfilter", "false") + ); + + LOCK2(cs_main, pwalletMain->cs_wallet); + std::string ret; + if ( (ret= params[0].get_str()) == "true" ) + fWalletFilter = true; + else if ( ret == "false" ) + fWalletFilter = false; + + komodo_dumpwalletfilter(); + if ( fWalletFilter ) + return "true"; + else + return "false"; + return 0; +} + +UniValue getwalletfilterstatus(const UniValue& params, bool fHelp, const CPubKey& mypk) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "getwalletfilterstatus \n" + "\nReturns a list of address and walletfilter enabled/disabled.\n" + "\nResult:\n" + "\nenabled (string) true/false\n" + "[ (json array of string)\n" + " \"" + strprintf("%s",komodo_chainname()) + "_address\" (string) a " + strprintf("%s",komodo_chainname()) + " address in walletfilter\n" + " ,...\n" + "]\n" + "\nExamples:\n" + + HelpExampleCli("getwalletfilterstatus","") + + HelpExampleRpc("getwalletfilterstatus","") + ); + LOCK2(cs_main, pwalletMain->cs_wallet); + UniValue ret(UniValue::VOBJ); UniValue addresses(UniValue::VARR); + // get status + if ( fWalletFilter ) + ret.push_back(make_pair("enabled", "true")); + else + ret.push_back(make_pair("enabled", "false")); + // get address list + for ( auto address : vWhiteListAddress ) + addresses.push_back(address); + + if ( NOTARY_PUBKEY33[0] != 0 ) + { + char Raddress[64]; + pubkey2addr((char *)Raddress,(uint8_t *)NOTARY_PUBKEY33); + addresses.push_back(Raddress); + } + ret.push_back(make_pair("addresses", addresses)); + + return ret; +} + + UniValue getaddressesbyaccount(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) @@ -8439,6 +8619,10 @@ static const CRPCCommand commands[] = { "wallet", "getaddressesbyaccount", &getaddressesbyaccount, true }, { "wallet", "getbalance", &getbalance, false }, { "wallet", "getnewaddress", &getnewaddress, true }, + { "wallet", "addwhitelistaddress", &addwhitelistaddress, true }, + { "wallet", "removewhitelistaddress", &removewhitelistaddress, true }, + { "wallet", "setwalletfilter", &setwalletfilter, true }, + { "wallet", "getwalletfilterstatus", &getwalletfilterstatus, true }, { "wallet", "getrawchangeaddress", &getrawchangeaddress, true }, { "wallet", "getreceivedbyaccount", &getreceivedbyaccount, false }, { "wallet", "getreceivedbyaddress", &getreceivedbyaddress, false }, From 6dbf8987522734cd557bf56ee379812c7aee87f0 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 12 Jan 2020 23:12:04 +0100 Subject: [PATCH 4/6] Update wallet.cpp https://github.com/KMDLabs/komodo/compare/403214b49b23...77a14e746593 thank you blackjok3r --- src/wallet/wallet.cpp | 61 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 789dce356f9..5c359419392 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1753,6 +1753,48 @@ bool CWallet::UpdatedNoteData(const CWalletTx& wtxIn, CWalletTx& wtx) * If fUpdate is true, existing transactions will be updated. */ + void komodo_loadwalletfilter() + { + // Read any entries in the conf file first. + std::vector vTempAddr; + vTempAddr = mapMultiArgs["-whitelistaddress"]; + + // Load address's from text file. + char fname[512]; + komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"walletfilterlist"); + std::string test; + std::ifstream in(fname); + int i = 0; + while ( std::getline(in, test) ) + { + if ( i == 0 ) + test == "1" ? fWalletFilter = true : fWalletFilter = false; + else + vTempAddr.push_back(test); + i++; + } + std::set sTempAddr ( vTempAddr.begin(), vTempAddr.end()); + + if ( !sTempAddr.empty() ) + { + vWhiteListAddress.clear(); // just in case. + fprintf(stderr, "Wallet Filter is adding saved whitelist address's:\n"); + for ( auto wladdr : sTempAddr ) + { + // check address is valid + if ( IsValidDestination(DecodeDestination(wladdr)) ) + { + fprintf(stderr, " %s\n", wladdr.c_str()); + vWhiteListAddress.push_back(wladdr); + } + } + } + if ( fWalletFilter ) + fprintf(stderr, "Wallet Filter is Enabled.\n"); + else + fprintf(stderr, "Wallet Filter is Disabled.\n"); + } + bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate) { { @@ -1770,25 +1812,22 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl return false; } } - static std::string NotaryAddress; static bool didinit; + static std::string NotaryAddress = ""; static bool didinit = false; if ( !didinit && NotaryAddress.empty() && NOTARY_PUBKEY33[0] != 0 ) { - didinit = true; - char Raddress[64]; - pubkey2addr((char *)Raddress,(uint8_t *)NOTARY_PUBKEY33); - NotaryAddress.assign(Raddress); - vWhiteListAddress = mapMultiArgs["-whitelistaddress"]; - if ( !vWhiteListAddress.empty() ) + if ( NotaryAddress.empty() && NOTARY_PUBKEY33[0] != 0 ) { - fprintf(stderr, "Activated Wallet Filter \n Notary Address: %s \n Adding whitelist address's:\n", NotaryAddress.c_str()); - for ( auto wladdr : vWhiteListAddress ) - fprintf(stderr, " %s\n", wladdr.c_str()); + char Raddress[64]; + pubkey2addr((char *)Raddress,(uint8_t *)NOTARY_PUBKEY33); + NotaryAddress.assign(Raddress); } + komodo_loadwalletfilter(); + didinit = true; } if (fExisted || IsMine(tx) || IsFromMe(tx) || sproutNoteData.size() > 0 || saplingNoteData.size() > 0) { // wallet filter for notary nodes. Enables by setting -whitelistaddress= as startup param or in conf file (works same as -addnode byut with R-address's) - if ( !tx.IsCoinBase() && !vWhiteListAddress.empty() && !NotaryAddress.empty() ) + if ( fWalletFilter && !tx.IsCoinBase() && (!vWhiteListAddress.empty() || !NotaryAddress.empty()) ) { int numvinIsOurs = 0, numvinIsWhiteList = 0; for (size_t i = 0; i < tx.vin.size(); i++) From 18c9f54ddb7dd581dd162e490cfd08805b205943 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 12 Jan 2020 23:43:13 +0100 Subject: [PATCH 5/6] Update rpcwallet.cpp --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5debb50292b..801305c6e8a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -76,7 +76,7 @@ uint32_t komodo_segid32(char *coinaddr); int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); int32_t komodo_isnotaryvout(char *coinaddr,uint32_t tiptime); // from ac_private chains only CBlockIndex *komodo_getblockindex(uint256 hash); - +void komodo_statefname(char *fname,char *symbol,char *str); int64_t nWalletUnlockTime; static CCriticalSection cs_nWalletUnlockTime; std::string CCerror; From 389f7763d9f397c9930a16baaa9796e7b0f0b5bf Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 12 Jan 2020 23:44:13 +0100 Subject: [PATCH 6/6] Update wallet.cpp https://github.com/KMDLabs/komodo/compare/403214b49b23...77a14e746593 --- src/wallet/wallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5c359419392..a7168fbfa56 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -64,6 +64,7 @@ CBlockIndex *komodo_chainactive(int32_t height); extern std::string DONATION_PUBKEY; int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); int tx_height( const uint256 &hash ); +void komodo_statefname(char *fname,char *symbol,char *str); /** * Fees smaller than this (in satoshi) are considered zero fee (for transaction creation)