Merge pull request #116 from fsb4000/Warn
author0xDEADFACE <masmfan@gmail.com>
Wed, 14 Jan 2015 18:09:08 +0000 (21:09 +0300)
committer0xDEADFACE <masmfan@gmail.com>
Wed, 14 Jan 2015 18:09:08 +0000 (21:09 +0300)
предупреждения при создании адреса с мультиподписью

src/bitcoinrpc.cpp
src/bitcoinrpc.h
src/kernel.cpp
src/kernel.h
src/main.cpp
src/main.h
src/miner.cpp
src/rpcnet.cpp
src/wallet.cpp
src/wallet.h

index 86c062d..bd711d1 100644 (file)
@@ -242,6 +242,7 @@ static const CRPCCommand vRPCCommands[] =
     { "getbestblockhash",       &getbestblockhash,       true,   false },
     { "getblockcount",          &getblockcount,          true,   false },
     { "getconnectioncount",     &getconnectioncount,     true,   false },
+    { "getaddrmaninfo",         &getaddrmaninfo,         true,   false },
     { "getpeerinfo",            &getpeerinfo,            true,   false },
     { "addnode",                &addnode,                true,   true  },
     { "getaddednodeinfo",       &getaddednodeinfo,       true,   true  },
index 72f7128..ecb14f8 100644 (file)
@@ -146,6 +146,7 @@ extern std::vector<unsigned char> ParseHexO(const json_spirit::Object& o, std::s
 
 extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp
 extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp);
+extern json_spirit::Value getaddrmaninfo(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp);
 extern json_spirit::Value dumpwallet(const json_spirit::Array& params, bool fHelp);
index a2cc24f..b1064fe 100644 (file)
@@ -434,7 +434,7 @@ bool CheckStakeKernelHash(uint32_t nBits, const CBlock& blockFrom, uint32_t nTxP
 }
 
 // Scan given coins set for kernel solution
-bool ScanForStakeKernelHash(MetaMap &mapMeta, KernelSearchSettings &settings, CoinsSet::value_type &kernelcoin, uint32_t &nTimeTx, uint32_t &nBlockTime, uint64_t &nKernelsTried, uint64_t &nCoinDaysTried)
+bool ScanForStakeKernelHash(MetaMap &mapMeta, uint32_t nBits, uint32_t nTime, uint32_t nSearchInterval, CoinsSet::value_type &kernelcoin, uint32_t &nTimeTx, uint32_t &nBlockTime, uint64_t &nKernelsTried, uint64_t &nCoinDaysTried)
 {
     uint256 hashProofOfStake = 0;
 
@@ -451,21 +451,21 @@ bool ScanForStakeKernelHash(MetaMap &mapMeta, KernelSearchSettings &settings, Co
         // Get coin
         CoinsSet::value_type pcoin = meta_item->second.first.second;
 
-        static int nMaxStakeSearchInterval = 60;
+        static unsigned int nMaxStakeSearchInterval = 60;
 
         // only count coins meeting min age requirement
-        if (nStakeMinAge + block.nTime > settings.nTime - nMaxStakeSearchInterval)
+        if (nStakeMinAge + block.nTime > nTime - nMaxStakeSearchInterval)
             continue;
 
         // Transaction offset inside block
         uint32_t nTxOffset = txindex.pos.nTxPos - txindex.pos.nBlockPos;
 
         // Current timestamp scanning interval
-        unsigned int nCurrentSearchInterval = min((int64_t)settings.nSearchInterval, (int64_t)nMaxStakeSearchInterval);
+        unsigned int nCurrentSearchInterval = min(nSearchInterval, nMaxStakeSearchInterval);
 
         nBlockTime = block.nTime;
         CBigNum bnTargetPerCoinDay;
-        bnTargetPerCoinDay.SetCompact(settings.nBits);
+        bnTargetPerCoinDay.SetCompact(nBits);
         int64_t nValueIn = pcoin.first->vout[pcoin.second].nValue;
 
         // Search backward in time from the given timestamp 
@@ -473,7 +473,7 @@ bool ScanForStakeKernelHash(MetaMap &mapMeta, KernelSearchSettings &settings, Co
         // Stopping search in case of shutting down or cache invalidation
         for (unsigned int n=0; n<nCurrentSearchInterval && fCoinsDataActual && !fShutdown; n++)
         {
-            nTimeTx = settings.nTime - n;
+            nTimeTx = nTime - n;
             CBigNum bnCoinDayWeight = CBigNum(nValueIn) * GetWeight((int64_t)pcoin.first->nTime, (int64_t)nTimeTx) / COIN / (24 * 60 * 60);
             CBigNum bnTargetProofOfStake = bnCoinDayWeight * bnTargetPerCoinDay;
 
index e784f2a..1b639a6 100644 (file)
@@ -33,23 +33,8 @@ bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64_t& nStakeModifier);
 // Sets hashProofOfStake on success return
 bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, uint32_t nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, uint32_t nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake=false);
 
-// Coins scanning options
-typedef struct KernelSearchSettings {
-    uint32_t nBits;           // Packed difficulty
-    uint32_t nTime;           // Basic time
-    uint32_t nOffset;         // Offset inside CoinsSet (isn't used yet)
-    uint32_t nLimit;          // Coins to scan (isn't used yet)
-    uint32_t nSearchInterval; // Number of seconds allowed to go into the past
-} KernelSearchSettings;
-
-typedef std::set<std::pair<const CWalletTx*,unsigned int> > CoinsSet;
-
-// Preloaded coins metadata
-// txid => ((txindex, (tx, vout.n)), (block, modifier))
-typedef std::map<std::pair<uint256, unsigned int>, std::pair<std::pair<CTxIndex, std::pair<const CWalletTx*,unsigned int> >, std::pair<CBlock, uint64_t> > > MetaMap;
-
 // Scan given coins set for kernel solution
-bool ScanForStakeKernelHash(MetaMap &mapMeta, KernelSearchSettings &settings, CoinsSet::value_type &kernelcoin, uint32_t &nTimeTx, uint32_t &nBlockTime, uint64_t &nKernelsTried, uint64_t &nCoinDaysTried);
+bool ScanForStakeKernelHash(MetaMap &mapMeta, uint32_t nBits, uint32_t nTime, uint32_t nSearchInterval, CoinsSet::value_type &kernelcoin, uint32_t &nTimeTx, uint32_t &nBlockTime, uint64_t &nKernelsTried, uint64_t &nCoinDaysTried);
 
 // Check kernel hash target and coinstake signature
 // Sets hashProofOfStake on success return
index 6390366..a091f6d 100644 (file)
@@ -2636,11 +2636,11 @@ bool CBlock::SignBlock(CWallet& wallet)
     if (IsProofOfStake())
         return true;
 
-    static int64_t nLastCoinStakeSearchTime = GetAdjustedTime(); // startup timestamp
+    static uint32_t nLastCoinStakeSearchTime = GetAdjustedTime(); // startup timestamp
 
     CKey key;
     CTransaction txCoinStake;
-    int64_t nSearchTime = txCoinStake.nTime; // search to current time
+    uint32_t nSearchTime = txCoinStake.nTime; // search to current time
 
     if (nSearchTime > nLastCoinStakeSearchTime)
     {
index b75a679..692c6b0 100644 (file)
@@ -81,7 +81,7 @@ extern CBlockIndex* pindexBest;
 extern unsigned int nTransactionsUpdated;
 extern uint64_t nLastBlockTx;
 extern uint64_t nLastBlockSize;
-extern int64_t nLastCoinStakeSearchInterval;
+extern uint32_t nLastCoinStakeSearchInterval;
 extern const std::string strMessageMagic;
 extern int64_t nTimeBestReceived;
 extern CCriticalSection cs_setpwalletRegistered;
index 8430f54..0f04521 100644 (file)
@@ -80,7 +80,7 @@ public:
 
 uint64_t nLastBlockTx = 0;
 uint64_t nLastBlockSize = 0;
-int64_t nLastCoinStakeSearchInterval = 0;
+uint32_t nLastCoinStakeSearchInterval = 0;
  
 // We want to sort transactions by priority and fee, so:
 typedef boost::tuple<double, double, CTransaction*> TxPriority;
index 604db0f..5404c01 100644 (file)
@@ -36,6 +36,52 @@ static void CopyNodeStats(std::vector<CNodeStats>& vstats)
     }
 }
 
+Value getaddrmaninfo(const Array& params, bool fHelp)
+{
+    if (fHelp || params.size() != 0)
+        throw runtime_error(
+            "getaddrmaninfo\n"
+            "Returns a dump of addrman data.");
+
+    vector<CAddress> vAddr = addrman.GetAddr();
+
+    Array ret;
+
+    BOOST_FOREACH(const CAddress &addr, vAddr) {
+        // Don't return addresses older than nCutOff timestamp
+        int64_t nCutOff = GetTime() - (nNodeLifespan * 24 * 60 * 60);
+
+        if (!addr.IsRoutable() || addr.IsLocal() || addr.nTime > nCutOff)
+            continue;
+
+        Object addrManItem;
+        addrManItem.push_back(Pair("address", addr.ToString()));
+
+        string strNetType;
+        switch(addr.GetNetwork())
+        {
+            case NET_TOR:
+                strNetType = "tor";
+            break;
+            case NET_I2P:
+                strNetType = "i2p";
+            case NET_IPV4:
+                strNetType = "ipv4";
+            break;
+            default:
+            case NET_IPV6:
+                strNetType = "ipv6";
+
+        }
+        addrManItem.push_back(Pair("type", strNetType));
+        addrManItem.push_back(Pair("time", (int64_t)addr.nTime));
+
+        ret.push_back(addrManItem);
+    }
+
+    return ret;
+}
+
 Value getpeerinfo(const Array& params, bool fHelp)
 {
     if (fHelp || params.size() != 0)
index 9972627..f62bb18 100644 (file)
@@ -1794,7 +1794,7 @@ bool CWallet::MergeCoins(const int64_t& nAmount, const int64_t& nMinValue, const
 }
 
 
-bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64_t nSearchInterval, CTransaction& txNew, CKey& key)
+bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, uint32_t nSearchInterval, CTransaction& txNew, CKey& key)
 {
     // The following combine threshold is important to security
     // Should not be adjusted if you don't understand the consequences
@@ -1876,18 +1876,11 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int
     int64_t nCredit = 0;
     CScript scriptPubKeyKernel;
 
-    KernelSearchSettings settings;
-    settings.nBits = nBits;
-    settings.nTime = txNew.nTime;
-    settings.nOffset = 0;
-    settings.nLimit = mapMeta.size();
-    settings.nSearchInterval = nSearchInterval;
-
     unsigned int nTimeTx, nBlockTime;
     COutPoint prevoutStake;
     CoinsSet::value_type kernelcoin;
 
-    if (ScanForStakeKernelHash(mapMeta, settings, kernelcoin, nTimeTx, nBlockTime, nKernelsTried, nCoinDaysTried))
+    if (ScanForStakeKernelHash(mapMeta, nBits, txNew.nTime, nSearchInterval, kernelcoin, nTimeTx, nBlockTime, nKernelsTried, nCoinDaysTried))
     {
         // Found a kernel
         if (fDebug && GetBoolArg("-printcoinstake"))
@@ -2209,17 +2202,16 @@ void CWallet::PrintWallet(const CBlock& block)
 {
     {
         LOCK(cs_wallet);
-        if (block.IsProofOfWork() && mapWallet.count(block.vtx[0].GetHash()))
-        {
-            CWalletTx& wtx = mapWallet[block.vtx[0].GetHash()];
-            printf("    mine:  %d  %d  %" PRId64 "", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit(MINE_ALL));
-        }
         if (block.IsProofOfStake() && mapWallet.count(block.vtx[1].GetHash()))
         {
             CWalletTx& wtx = mapWallet[block.vtx[1].GetHash()];
-            printf("    stake: %d  %d  %" PRId64 "", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit(MINE_ALL));
-         }
-
+            printf("    PoS: %d  %d  %" PRId64 "", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit(MINE_ALL));
+        }
+        else if (mapWallet.count(block.vtx[0].GetHash()))
+        {
+            CWalletTx& wtx = mapWallet[block.vtx[0].GetHash()];
+            printf("    PoW:  %d  %d  %" PRId64 "", wtx.GetDepthInMainChain(), wtx.GetBlocksToMaturity(), wtx.GetCredit(MINE_ALL));
+        }
     }
     printf("\n");
 }
index ce5f205..c1a987e 100644 (file)
@@ -27,6 +27,14 @@ class CReserveKey;
 class COutput;
 class CCoinControl;
 
+// Set of selected transactions
+typedef std::set<std::pair<const CWalletTx*,unsigned int> > CoinsSet;
+
+// Preloaded coins metadata
+// (txid, vout.n) => ((txindex, (tx, vout.n)), (block, modifier))
+typedef std::map<std::pair<uint256, unsigned int>, std::pair<std::pair<CTxIndex, std::pair<const CWalletTx*,unsigned int> >, std::pair<CBlock, uint64_t> > > MetaMap;
+
+
 /** (client) version numbers for particular wallet features */
 enum WalletFeature
 {
@@ -214,7 +222,7 @@ public:
 
     void GetStakeStats(float &nKernelsRate, float &nCoinDaysRate);
     void GetStakeWeightFromValue(const int64_t& nTime, const int64_t& nValue, uint64_t& nWeight);
-    bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64_t nSearchInterval, CTransaction& txNew, CKey& key);
+    bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, uint32_t nSearchInterval, CTransaction& txNew, CKey& key);
     bool MergeCoins(const int64_t& nAmount, const int64_t& nMinValue, const int64_t& nMaxValue, std::list<uint256>& listMerged);
 
     std::string SendMoney(CScript scriptPubKey, int64_t nValue, CWalletTx& wtxNew, bool fAskFee=false);