X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Frpcwallet.cpp;h=8b3780ecbc29f79ece87bb1b2d1657a65d9c7e34;hb=7f70ddc68f4afa4a87a15e620ba519afbc5c8b15;hp=67c24e349b7f681486efb8f6f1af00752e035a11;hpb=0c15e9be384df1db22a714c3ec77e9902df0492f;p=novacoin.git diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 67c24e3..8b3780e 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -18,7 +18,7 @@ int64_t nWalletUnlockTime; static CCriticalSection cs_nWalletUnlockTime; extern int64_t nReserveBalance; -extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, json_spirit::Object& entry); +extern void TxToJSON(const CTransaction& tx, const uint256& hashBlock, json_spirit::Object& entry); std::string HelpRequiringPassphrase() { @@ -467,7 +467,7 @@ Value getreceivedbyaddress(const Array& params, bool fHelp) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid NovaCoin address"); scriptPubKey.SetDestination(address.Get()); if (!IsMine(*pwalletMain,scriptPubKey)) - return (double)0.0; + return 0.0; // Minimum confirmations int nMinDepth = 1; @@ -734,7 +734,7 @@ Value sendmany(const Array& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 4) throw runtime_error( - "sendmany {address:amount,...} [minconf=1] [comment]\n" + "sendmany '{address:amount,...}' [minconf=1] [comment]\n" "amounts are double-precision floating point numbers" + HelpRequiringPassphrase()); @@ -1429,7 +1429,7 @@ Value keypoolrefill(const Array& params, bool fHelp) "should be replaced with the newly generated one." + HelpRequiringPassphrase()); - unsigned int nSize = max(GetArg("-keypool", 100), 0); + unsigned int nSize = max(GetArgUInt("-keypool", 100), 0); if (params.size() > 0) { if (params[0].get_int() < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size"); @@ -1456,7 +1456,7 @@ Value keypoolreset(const Array& params, bool fHelp) "should be replaced with the newly generated one." + HelpRequiringPassphrase()); - unsigned int nSize = max(GetArg("-keypool", 100), 0); + unsigned int nSize = max(GetArgUInt("-keypool", 100), 0); if (params.size() > 0) { if (params[0].get_int() < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size"); @@ -1833,25 +1833,147 @@ Value resendtx(const Array& params, bool fHelp) return Value::null; } -// ppcoin: make a public-private key pair +// Make a public-private key pair Value makekeypair(const Array& params, bool fHelp) { - if (fHelp || params.size() > 1) + if (fHelp || params.size() > 0) throw runtime_error( - "makekeypair [prefix]\n" - "Make a public/private key pair.\n" - "[prefix] is optional preferred prefix for the public key.\n"); + "makekeypair\n" + "Make a public/private key pair.\n"); string strPrefix = ""; if (params.size() > 0) strPrefix = params[0].get_str(); - + CKey key; - key.MakeNewKey(false); + key.MakeNewKey(true); CPrivKey vchPrivKey = key.GetPrivKey(); Object result; result.push_back(Pair("PrivateKey", HexStr(vchPrivKey.begin(), vchPrivKey.end()))); + + bool fCompressed; + CSecret vchSecret = key.GetSecret(fCompressed); + result.push_back(Pair("Secret", HexStr(vchSecret.begin(), vchSecret.end()))); result.push_back(Pair("PublicKey", HexStr(key.GetPubKey().Raw()))); return result; } + +Value newmalleablekey(const Array& params, bool fHelp) +{ + if (fHelp || params.size() > 0) + throw runtime_error( + "newmalleablekey\n" + "Make a malleable public/private key pair.\n"); + + if (!fTestNet) + throw runtime_error("This feature has been disabled for mainNet clients"); + + CMalleableKeyView keyView = pwalletMain->GenerateNewMalleableKey(); + + CMalleableKey mKey; + if (!pwalletMain->GetMalleableKey(keyView, mKey)) + throw runtime_error("Unable to generate new malleable key"); + + Object result; + result.push_back(Pair("PublicPair", mKey.GetMalleablePubKey().ToString())); + result.push_back(Pair("KeyView", keyView.ToString())); + + return result; +} + +Value dumpmalleablekey(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error ( + "dumpmalleablekey \n" + "Dump the private and public key pairs, which correspond to provided key view.\n"); + + CMalleableKey mKey; + CMalleableKeyView keyView; + keyView.SetString(params[0].get_str()); + + if (!pwalletMain->GetMalleableKey(keyView, mKey)) + throw runtime_error("There is no such item in the wallet"); + + Object result; + result.push_back(Pair("PrivatePair", mKey.ToString())); + result.push_back(Pair("PublicPair", mKey.GetMalleablePubKey().ToString())); + + return result; +} + +Value adjustmalleablekey(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 3) + throw runtime_error( + "adjustmalleablekey \n" + "Calculate new private key using provided malleable key, public key and R data.\n"); + + CMalleableKey malleableKey; + malleableKey.SetString(params[0].get_str()); + + CKey privKeyVariant; + CPubKey vchPubKeyVariant = CPubKey(ParseHex(params[1].get_str())); + + CPubKey R(ParseHex(params[2].get_str())); + + if (!malleableKey.CheckKeyVariant(R,vchPubKeyVariant, privKeyVariant)) { + throw runtime_error("Unable to calculate the private key"); + } + + Object result; + bool fCompressed; + CSecret vchPrivKeyVariant = privKeyVariant.GetSecret(fCompressed); + + result.push_back(Pair("PrivateKey", CBitcoinSecret(vchPrivKeyVariant, fCompressed).ToString())); + + return result; +} + +Value adjustmalleablepubkey(const Array& params, bool fHelp) +{ + if (fHelp || params.size() > 2 || params.size() == 0) + throw runtime_error( + "adjustmalleablepubkey \n" + "Calculate new public key using provided malleable public key data.\n"); + + string pubKeyPair = params[0].get_str(); + CMalleablePubKey malleablePubKey; + + if (pubKeyPair.size() == 138) { + CDataStream ssPublicBytes(ParseHex(pubKeyPair), SER_NETWORK, PROTOCOL_VERSION); + ssPublicBytes >> malleablePubKey; + } else + malleablePubKey.SetString(pubKeyPair); + + CPubKey R, vchPubKeyVariant; + malleablePubKey.GetVariant(R, vchPubKeyVariant); + + Object result; + result.push_back(Pair("R", HexStr(R.Raw()))); + result.push_back(Pair("PubkeyVariant", HexStr(vchPubKeyVariant.Raw()))); + result.push_back(Pair("KeyVariantID", CBitcoinAddress(vchPubKeyVariant.GetID()).ToString())); + + return result; +} + +Value listmalleableviews(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "listmalleableviews\n" + "Get list of views for generated malleable keys.\n"); + + std::list keyViewList; + pwalletMain->ListMalleableViews(keyViewList); + + Array result; + BOOST_FOREACH(const CMalleableKeyView &keyView, keyViewList) + { + result.push_back(keyView.ToString()); + } + + return result; +} +