mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-11 07:17:53 +00:00
implement new rpc dumppubkey.
importprivkey now verifies if username exists in txdb
This commit is contained in:
parent
549ba353dd
commit
6ade53ce53
@ -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<std::stri
|
||||
if (strMethod == "lockunspent" && n > 0) ConvertTo<bool>(params[0]);
|
||||
if (strMethod == "lockunspent" && n > 1) ConvertTo<Array>(params[1]);
|
||||
if (strMethod == "importprivkey" && n > 2) ConvertTo<bool>(params[2]);
|
||||
if (strMethod == "importprivkey" && n > 3) ConvertTo<bool>(params[3]);
|
||||
if (strMethod == "verifychain" && n > 0) ConvertTo<boost::int64_t>(params[0]);
|
||||
if (strMethod == "verifychain" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
||||
if (strMethod == "dhtput" && n > 3) ConvertToValue(params[3]);
|
||||
|
@ -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);
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "bitcoinrpc.h"
|
||||
#include "ui_interface.h"
|
||||
#include "base58.h"
|
||||
#include "twister.h"
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
@ -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 <bitcoinprivkey> <username> [rescan=true]\n"
|
||||
"importprivkey <bitcoinprivkey> <username> [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 <username>\n"
|
||||
"Returns the public key corresponding to <username>.");
|
||||
|
||||
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<const char *>(pubkey.begin()), pubkey.size());
|
||||
return strPubkey;
|
||||
}
|
||||
|
||||
|
||||
Value dumpwallet(const Array& params, bool fHelp)
|
||||
{
|
||||
|
@ -1552,7 +1552,7 @@ Value listusernamespartial(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || (params.size() < 2 || params.size() > 3))
|
||||
throw runtime_error(
|
||||
"listusernamespartial <username_starts_with> <count> [exact_match]\n"
|
||||
"listusernamespartial <username_starts_with> <count> [exact_match=false]\n"
|
||||
"get list of usernames starting with");
|
||||
|
||||
string userStartsWith = params[0].get_str();
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user