X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Frpccrypt.cpp;h=91f03026b296d532296ea8c524e6f5f1a5eda1e9;hp=aaccb701ffa82a127a57369e6f28911f54780958;hb=05df71c9c292877e7469884227fd3ba84d02908b;hpb=ac7598160fb4a54fcc2c759e3f6c8a461b331381 diff --git a/src/rpccrypt.cpp b/src/rpccrypt.cpp index aaccb70..91f0302 100644 --- a/src/rpccrypt.cpp +++ b/src/rpccrypt.cpp @@ -4,11 +4,8 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "wallet.h" -#include "walletdb.h" #include "bitcoinrpc.h" #include "init.h" -#include "util.h" -#include "ntp.h" #include "base58.h" using namespace json_spirit; @@ -33,17 +30,26 @@ Value decryptdata(const Array& params, bool fHelp) { if (fHelp || params.size() != 2) throw runtime_error( - "decryptdata \n" + "decryptdata \n" "Decrypt octet stream.\n"); EnsureWalletIsUnlocked(); - CBitcoinAddress addr(params[0].get_str()); - - CKeyID keyID; - addr.GetKeyID(keyID); - CKey key; - pwalletMain->GetKey(keyID, key); + CBitcoinAddress addr(params[0].get_str()); + if (addr.IsValid()) { + CKeyID keyID; + addr.GetKeyID(keyID); + if (!pwalletMain->GetKey(keyID, key)) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "We have no private key for this address"); + } + else { + CBitcoinSecret vchSecret; + if (!vchSecret.SetString(params[0].get_str())) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Provided private key is inconsistent."); + bool fCompressed; + CSecret secret = vchSecret.GetSecret(fCompressed); + key.SetSecret(secret, fCompressed); + } vector vchDecrypted; key.DecryptData(ParseHex(params[1].get_str()), vchDecrypted); @@ -71,17 +77,27 @@ Value decryptmessage(const Array& params, bool fHelp) { if (fHelp || params.size() != 2) throw runtime_error( - "decryptdata \n" + "decryptmessage \n" "Decrypt message string.\n"); EnsureWalletIsUnlocked(); - CBitcoinAddress addr(params[0].get_str()); - - CKeyID keyID; - addr.GetKeyID(keyID); CKey key; - pwalletMain->GetKey(keyID, key); + CBitcoinAddress addr(params[0].get_str()); + if (addr.IsValid()) { + CKeyID keyID; + addr.GetKeyID(keyID); + if (!pwalletMain->GetKey(keyID, key)) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "We have no private key for this address"); + } + else { + CBitcoinSecret vchSecret; + if (!vchSecret.SetString(params[0].get_str())) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Provided private key is inconsistent."); + bool fCompressed; + CSecret secret = vchSecret.GetSecret(fCompressed); + key.SetSecret(secret, fCompressed); + } vector vchEncrypted; if (!DecodeBase58Check(params[1].get_str(), vchEncrypted))