test adding pubkey to getinfo and setpubkey RPC

This commit is contained in:
blackjok3r
2018-10-24 15:48:19 +08:00
parent b9b7f12d84
commit e3237f4a0b
4 changed files with 79 additions and 12 deletions

View File

@@ -64,6 +64,7 @@ extern uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,AS
UniValue getinfo(const UniValue& params, bool fHelp) UniValue getinfo(const UniValue& params, bool fHelp)
{ {
uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,longestchain,kmdnotarized_height,txid_height; uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,longestchain,kmdnotarized_height,txid_height;
extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[];
if (fHelp || params.size() != 0) if (fHelp || params.size() != 0)
throw runtime_error( throw runtime_error(
"getinfo\n" "getinfo\n"
@@ -158,6 +159,8 @@ UniValue getinfo(const UniValue& params, bool fHelp)
obj.push_back(Pair("pubkey", pubkeystr)); obj.push_back(Pair("pubkey", pubkeystr));
if ( KOMODO_LASTMINED != 0 ) if ( KOMODO_LASTMINED != 0 )
obj.push_back(Pair("lastmined", KOMODO_LASTMINED)); obj.push_back(Pair("lastmined", KOMODO_LASTMINED));
} else if ( NOTARY_PUBKEY33[0] != 0 ) {
obj.push_back(Pair("pubkey", NOTARY_PUBKEY));
} }
} }
if ( ASSETCHAINS_CC != 0 ) if ( ASSETCHAINS_CC != 0 )

View File

@@ -521,6 +521,7 @@ static const CRPCCommand vRPCCommands[] =
{ "wallet", "sendmany", &sendmany, false }, { "wallet", "sendmany", &sendmany, false },
{ "wallet", "sendtoaddress", &sendtoaddress, false }, { "wallet", "sendtoaddress", &sendtoaddress, false },
{ "wallet", "setaccount", &setaccount, true }, { "wallet", "setaccount", &setaccount, true },
{ "wallet", "setpubkey", &setpubkey, true },
{ "wallet", "settxfee", &settxfee, true }, { "wallet", "settxfee", &settxfee, true },
{ "wallet", "signmessage", &signmessage, true }, { "wallet", "signmessage", &signmessage, true },
{ "wallet", "walletlock", &walletlock, true }, { "wallet", "walletlock", &walletlock, true },

View File

@@ -322,6 +322,7 @@ extern UniValue walletlock(const UniValue& params, bool fHelp);
extern UniValue encryptwallet(const UniValue& params, bool fHelp); extern UniValue encryptwallet(const UniValue& params, bool fHelp);
extern UniValue validateaddress(const UniValue& params, bool fHelp); extern UniValue validateaddress(const UniValue& params, bool fHelp);
extern UniValue getinfo(const UniValue& params, bool fHelp); extern UniValue getinfo(const UniValue& params, bool fHelp);
extern UniValue setpubkey(const UniValue& params, bool fHelp);
extern UniValue getwalletinfo(const UniValue& params, bool fHelp); extern UniValue getwalletinfo(const UniValue& params, bool fHelp);
extern UniValue getblockchaininfo(const UniValue& params, bool fHelp); extern UniValue getblockchaininfo(const UniValue& params, bool fHelp);
extern UniValue getnetworkinfo(const UniValue& params, bool fHelp); extern UniValue getnetworkinfo(const UniValue& params, bool fHelp);

View File

@@ -4951,6 +4951,68 @@ UniValue channelsaddress(const UniValue& params, bool fHelp)
return(result); return(result);
} }
UniValue setpubkey(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ);
if ( fHelp || params.size() != 1 )
throw runtime_error(
"setpubkey\n"
"\nSets the -pubkey if the daemon was not started with it, if it was already set, it returns the pubkey.\n"
"\nArguments:\n"
"1. \"pubkey\" (string) pubkey to set.\n"
"\nResult:\n"
" {\n"
" \"pubkey\" : \"pubkey\", (string) The pubkey\n"
" \"ismine\" : \"true/false\", (bool)\n"
" \"R-address\" : \"R address\", (string) The pubkey\n"
" }\n"
"\nExamples:\n"
+ HelpExampleCli("setpubkey", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e")
+ HelpExampleRpc("setpubkey", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e")
);
#ifdef ENABLE_WALLET
LOCK2(cs_main, pwalletMain ? &pwalletMain->cs_wallet : NULL);
#else
LOCK(cs_main);
#endif
char Raddress[18];
uint8_t pubkey33[33];
extern uint8_t NOTARY_PUBKEY33[];
extern std::string NOTARY_PUBKEY;
if ( NOTARY_PUBKEY33[0] == 0 ) {
if (strlen(params[0].get_str().c_str()) == 66) {
decode_hex(pubkey33,33,(char *)params[0].get_str().c_str());
pubkey2addr((char *)Raddress,(uint8_t *)pubkey33);
if (strcmp("RRmWExvapDM9YbLT9X9xAyzDgxomYf63ng",Raddress) == 0) {
result.push_back(Pair("error", "pubkey entered is invalid."));
} else {
CBitcoinAddress address(Raddress);
bool isValid = address.IsValid();
if (isValid)
{
CTxDestination dest = address.Get();
string currentAddress = address.ToString();
result.push_back(Pair("address", currentAddress));
#ifdef ENABLE_WALLET
isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO;
result.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false));
#endif
}
NOTARY_PUBKEY = params[0].get_str();
decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str());
}
} else {
result.push_back(Pair("error", "pubkey is wrong length, must be 66 char hex string."));
}
} else {
result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon."));
}
result.push_back(Pair("pubkey", NOTARY_PUBKEY));
return result;
}
UniValue oraclesaddress(const UniValue& params, bool fHelp) UniValue oraclesaddress(const UniValue& params, bool fHelp)
{ {
struct CCcontract_info *cp,C; std::vector<unsigned char> pubkey; struct CCcontract_info *cp,C; std::vector<unsigned char> pubkey;