diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index a93ff3ca..b3c79f67 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -230,6 +230,7 @@ static const CRPCCommand vRPCCommands[] = { "submitblock", &submitblock, false, false }, { "listsinceblock", &listsinceblock, false, false }, { "dumpprivkey", &dumpprivkey, true, false }, + { "dumppubkey", &dumppubkey, false, false }, { "dumpwallet", &dumpwallet, true, false }, { "importprivkey", &importprivkey, false, false }, { "importwallet", &importwallet, false, false }, @@ -1241,6 +1242,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 0) ConvertTo(params[0]); if (strMethod == "lockunspent" && n > 1) ConvertTo(params[1]); if (strMethod == "importprivkey" && n > 2) ConvertTo(params[2]); + if (strMethod == "importprivkey" && n > 3) ConvertTo(params[3]); if (strMethod == "verifychain" && n > 0) ConvertTo(params[0]); if (strMethod == "verifychain" && n > 1) ConvertTo(params[1]); if (strMethod == "dhtput" && n > 3) ConvertToValue(params[3]); diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 5dc0d06e..071c6a72 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -146,6 +146,7 @@ extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp +extern json_spirit::Value dumppubkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value dumpwallet(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fHelp); diff --git a/src/rpcdump.cpp b/src/rpcdump.cpp index 6c139d6d..f76d5591 100644 --- a/src/rpcdump.cpp +++ b/src/rpcdump.cpp @@ -9,6 +9,7 @@ #include "bitcoinrpc.h" #include "ui_interface.h" #include "base58.h" +#include "twister.h" #include #include @@ -67,9 +68,9 @@ std::string DecodeDumpString(const std::string &str) { Value importprivkey(const Array& params, bool fHelp) { - if (fHelp || params.size() < 2 || params.size() > 3) + if (fHelp || params.size() < 2 || params.size() > 4) throw runtime_error( - "importprivkey [rescan=true]\n" + "importprivkey [rescan=true] [allow_new_user=false]\n" "Adds a private key (as returned by dumpprivkey) to your wallet."); string strSecret = params[0].get_str(); @@ -80,11 +81,24 @@ Value importprivkey(const Array& params, bool fHelp) if (params.size() > 2) fRescan = params[2].get_bool(); + bool fAllowNewUser = false; + if (params.size() > 3) + fAllowNewUser = params[3].get_bool(); + CBitcoinSecret vchSecret; bool fGood = vchSecret.SetString(strSecret); if (!fGood) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key"); + if( !fAllowNewUser ) { + CTransaction txOut; + uint256 hashBlock; + uint256 userhash = SerializeHash(strUsername); + if( !GetTransaction(userhash, txOut, hashBlock) ) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "User must exist (or allow_new_user flag must be set)"); + } + } + CKey key = vchSecret.GetKey(); CPubKey pubkey = key.GetPubKey(); CKeyID vchAddress = pubkey.GetID(); @@ -211,6 +225,25 @@ Value dumpprivkey(const Array& params, bool fHelp) return CBitcoinSecret(vchSecret).ToString(); } +Value dumppubkey(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "dumppubkey \n" + "Returns the public key corresponding to ."); + + string strUsername = params[0].get_str(); + + CPubKey pubkey; + bool gotKey = getUserPubKey(strUsername, pubkey); + + if( !gotKey ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Username not found"); + + string strPubkey = string( reinterpret_cast(pubkey.begin()), pubkey.size()); + return strPubkey; +} + Value dumpwallet(const Array& params, bool fHelp) { diff --git a/src/twister.cpp b/src/twister.cpp index 57c21521..428d204c 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -1552,7 +1552,7 @@ Value listusernamespartial(const Array& params, bool fHelp) { if (fHelp || (params.size() < 2 || params.size() > 3)) throw runtime_error( - "listusernamespartial [exact_match]\n" + "listusernamespartial [exact_match=false]\n" "get list of usernames starting with"); string userStartsWith = params[0].get_str(); diff --git a/src/twister.h b/src/twister.h index ef3daaba..913b985d 100644 --- a/src/twister.h +++ b/src/twister.h @@ -23,6 +23,7 @@ public: void startSessionTorrent(boost::thread_group& threadGroup); void stopSessionTorrent(); +bool getUserPubKey(std::string const &strUsername, CPubKey &pubkey); std::string createSignature(std::string const &strMessage, CKeyID &keyID); std::string createSignature(std::string const &strMessage, std::string const &strUsername); bool verifySignature(std::string const &strMessage, std::string const &strUsername, std::string const &strSign);