PPCoin: Change date display format and clean up a merge issue
[novacoin.git] / src / bitcoinrpc.cpp
index 08a1dac..04faea9 100644 (file)
@@ -2023,7 +2023,7 @@ Value getcheckpoint(const Array& params, bool fHelp)
     result.push_back(Pair("synccheckpoint", Checkpoints::hashSyncCheckpoint.ToString().c_str()));
     pindexCheckpoint = mapBlockIndex[Checkpoints::hashSyncCheckpoint];        
     result.push_back(Pair("height", pindexCheckpoint->nHeight));
-    result.push_back(Pair("timestamp", DateTimeStrFormat("%x %H:%M:%S", pindexCheckpoint->GetBlockTime()).c_str()));
+    result.push_back(Pair("timestamp", DateTimeStrFormat(pindexCheckpoint->GetBlockTime()).c_str()));
     
     return result;
 }
@@ -2051,25 +2051,22 @@ Value reservebalance(const Array& params, bool fHelp)
             nAmount = (nAmount / CENT) * CENT;  // round to cent
             if (nAmount < 0)
                 throw runtime_error("amount cannot be negative.\n");
-            // TODO: handle persistence of nBalanceReserve
-            // settings removed since bitcoin 0.6
-            // WriteSetting("nBalanceReserve", nBalanceReserve = nAmount);
-            nBalanceReserve = nAmount;
+            mapArgs["-reservebalance"] = FormatMoney(nAmount).c_str();
         }
         else
         {
             if (params.size() > 1)
                 throw runtime_error("cannot specify amount to turn off reserve.\n");
-            // TODO: handle persistence of nBalanceReserve
-            // settings removed since bitcoin 0.6
-            // WriteSetting("nBalanceReserve", nBalanceReserve = 0);
-            nBalanceReserve = 0;
+            mapArgs["-reservebalance"] = "0";
         }
     }
 
     Object result;
-    result.push_back(Pair("reserve", (nBalanceReserve > 0)));
-    result.push_back(Pair("amount", ValueFromAmount(nBalanceReserve)));
+    int64 nReserveBalance = 0;
+    if (mapArgs.count("-reservebalance") && !ParseMoney(mapArgs["-reservebalance"], nReserveBalance))
+        throw runtime_error("invalid reserve balance amount\n");
+    result.push_back(Pair("reserve", (nReserveBalance > 0)));
+    result.push_back(Pair("amount", ValueFromAmount(nReserveBalance)));
     return result;
 }
 
@@ -2214,59 +2211,30 @@ Value sendalert(const Array& params, bool fHelp)
     return result;
 }
 
-// ppcoin: send checkpoint
-Value sendcheckpoint(const Array& params, bool fHelp)
+// ppcoin: set checkpoint key
+Value setcheckpointkey(const Array& params, bool fHelp)
 {
-    if (fHelp || params.size() > 2 || params.size() < 1 )
+    if (fHelp || params.size() != 1)
         throw runtime_error(
-            "sendcheckpoint <privatekey> [checkpointhash]\n"
-            "<privatekey> is hex string of checkpoint master private key\n"
-            "<checkpointhash> is the hash of checkpoint block\n");
+            "setcheckpointkey <privatekey>\n"
+            "<privatekey> is hex string of checkpoint master private key\n");
 
     CSyncCheckpoint checkpoint;
-    CKey key;
-
-    // TODO: omit checkpointhash parameter
-    if (params.size() > 1)
-    {
-        checkpoint.hashCheckpoint = uint256(params[1].get_str());
-        if (!mapBlockIndex.count(checkpoint.hashCheckpoint))
-            throw runtime_error(
-                "Provided checkpoint block is not on main chain\n");
-    }
-    else
-    {
-        checkpoint.hashCheckpoint = Checkpoints::AutoSelectSyncCheckpoint();
-        if (checkpoint.hashCheckpoint == Checkpoints::hashSyncCheckpoint)
-            throw runtime_error(
-                "Unable to select a more recent sync-checkpoint");
-    }
-
+    checkpoint.hashCheckpoint = hashGenesisBlock;
     CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION);
     sMsg << (CUnsignedSyncCheckpoint)checkpoint;
     checkpoint.vchMsg = vector<unsigned char>(sMsg.begin(), sMsg.end());
 
     vector<unsigned char> vchPrivKey = ParseHex(params[0].get_str());
+    CKey key;
     key.SetPrivKey(CPrivKey(vchPrivKey.begin(), vchPrivKey.end())); // if key is not correct openssl may crash
     if (!key.Sign(Hash(checkpoint.vchMsg.begin(), checkpoint.vchMsg.end()), checkpoint.vchSig))
         throw runtime_error(
             "Unable to sign checkpoint, check private key?\n");
 
-    if(!checkpoint.ProcessSyncCheckpoint(NULL))
-        throw runtime_error(
-            "Failed to process checkpoint.\n");
-    // Relay checkpoint
-    {
-        LOCK(cs_vNodes);
-        BOOST_FOREACH(CNode* pnode, vNodes)
-            checkpoint.RelayTo(pnode);
-    }
+    CSyncCheckpoint::strMasterPrivKey = params[0].get_str();
 
-    Object result;
-    result.push_back(Pair("checkpoint", Checkpoints::hashSyncCheckpoint.ToString().c_str()));
-    result.push_back(Pair("height", mapBlockIndex[Checkpoints::hashSyncCheckpoint]->nHeight));
-    result.push_back(Pair("timestamp", DateTimeStrFormat("%x %H:%M:%S", mapBlockIndex[Checkpoints::hashSyncCheckpoint]->GetBlockTime()).c_str()));
-    return result;
+    return "checkpoint master key has been set.";
 }
 
 
@@ -2330,7 +2298,7 @@ static const CRPCCommand vRPCCommands[] =
     { "repairwallet",           &repairwallet,           false},
     { "makekeypair",            &makekeypair,            false},
     { "sendalert",              &sendalert,              false},
-    { "sendcheckpoint",         &sendcheckpoint,         false},
+    { "setcheckpointkey",       &setcheckpointkey,       false},
 };
 
 CRPCTable::CRPCTable()