X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fbitcoinrpc.cpp;h=dbbe67f1777d168c5cea2abdf9e52ba441b59819;hb=9c28b3c6a120e07c3a0caea8e17e02c072e686b2;hp=4836fe3a226a4d43ba62c5aafda7edffc82b4961;hpb=b92fd202e243bf3cbb6902833d991296213b8c2f;p=novacoin.git diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 4836fe3..dbbe67f 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1931,6 +1931,19 @@ Value repairwallet(const Array& params, bool fHelp) 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(vchPrivKey.begin(), vchPrivKey.end()))); + result.push_back(Pair("PublicKey", HexStr(key.GetPubKey()))); + return result; +} + extern CCriticalSection cs_mapAlerts; extern map mapAlerts; @@ -1993,18 +2006,60 @@ Value sendalert(const Array& params, bool fHelp) 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 [checkpointhash]\n" + " is hex string of checkpoint master private key\n" + " is the hash of checkpoint block\n"); + + CSyncCheckpoint checkpoint; CKey key; - key.MakeNewKey(); - CPrivKey vchPrivKey = key.GetPrivKey(); + + // 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"); + } + + CDataStream sMsg; + sMsg << (CUnsignedSyncCheckpoint)checkpoint; + checkpoint.vchMsg = vector(sMsg.begin(), sMsg.end()); + + vector 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); Object result; - result.push_back(Pair("PrivateKey", HexStr(vchPrivKey.begin(), vchPrivKey.end()))); - result.push_back(Pair("PublicKey", HexStr(key.GetPubKey()))); + 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; } + // // Call Table // @@ -2056,8 +2111,9 @@ pair pCallTable[] = 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 mapCallTable(pCallTable, pCallTable + sizeof(pCallTable)/sizeof(pCallTable[0]));