Object obj;
obj.push_back(Pair("version", (int)VERSION));
obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
+ obj.push_back(Pair("newmint", ValueFromAmount(pwalletMain->GetNewMint())));
obj.push_back(Pair("stake", ValueFromAmount(pwalletMain->GetStake())));
obj.push_back(Pair("blocks", (int)nBestHeight));
obj.push_back(Pair("connections", (int)vNodes.size()));
return result;
}
+// ppcoin: make a public-private key pair
+Value makekeypair(const Array& params, bool fHelp)
+{
+ CKey key;
+ key.MakeNewKey();
+ CPrivKey vchPrivKey = key.GetPrivKey();
+
+ Object result;
+ result.push_back(Pair("PrivateKey", HexStr<CPrivKey::iterator>(vchPrivKey.begin(), vchPrivKey.end())));
+ result.push_back(Pair("PublicKey", HexStr(key.GetPubKey())));
+ return result;
+}
+
extern CCriticalSection cs_mapAlerts;
extern map<uint256, CAlert> mapAlerts;
-// ppcoin: send alert
+// ppcoin: send alert.
+// There is a known deadlock situation with ThreadMessageHandler
+// ThreadMessageHandler: holds cs_vSend and acquiring cs_main in SendMessages()
+// ThreadRPCServer: holds cs_main and acquiring cs_vSend in alert.RelayTo()/PushMessage()/BeginMessage()
Value sendalert(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 5)
if (!key.Sign(Hash(alert.vchMsg.begin(), alert.vchMsg.end()), alert.vchSig))
throw runtime_error(
"Unable to sign alert, check private key?\n");
- alert.ProcessAlert();
+ if(!alert.ProcessAlert())
+ throw runtime_error(
+ "Failed to process alert.\n");
// Relay alert
CRITICAL_BLOCK(cs_vNodes)
BOOST_FOREACH(CNode* pnode, vNodes)
return result;
}
-Value makekeypair(const Array& params, bool fHelp)
+// ppcoin: send checkpoint
+Value sendcheckpoint(const Array& params, bool fHelp)
{
+ if (fHelp || params.size() > 2 || 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");
+
+ CSyncCheckpoint checkpoint;
CKey key;
- key.MakeNewKey();
- CPrivKey vchPrivKey = key.GetPrivKey();
- Object result;
- result.push_back(Pair("PrivateKey", HexStr<CPrivKey::iterator>(vchPrivKey.begin(), vchPrivKey.end())));
- result.push_back(Pair("PublicKey", HexStr(key.GetPubKey())));
- return result;
+ // 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");
+ }
+
+ CDataStream sMsg;
+ sMsg << (CUnsignedSyncCheckpoint)checkpoint;
+ checkpoint.vchMsg = vector<unsigned char>(sMsg.begin(), sMsg.end());
+
+ vector<unsigned char> vchPrivKey = ParseHex(params[0].get_str());
+ 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
+ CRITICAL_BLOCK(cs_vNodes)
+ BOOST_FOREACH(CNode* pnode, vNodes)
+ checkpoint.RelayTo(pnode);
+
+ return Value::null;
}
+
//
// Call Table
//
make_pair("reservebalance", &reservebalance),
make_pair("checkwallet", &checkwallet),
make_pair("repairwallet", &repairwallet),
- make_pair("sendalert", &sendalert),
make_pair("makekeypair", &makekeypair),
+ make_pair("sendalert", &sendalert),
+ make_pair("sendcheckpoint", &sendcheckpoint),
};
map<string, rpcfn_type> mapCallTable(pCallTable, pCallTable + sizeof(pCallTable)/sizeof(pCallTable[0]));