add rpc to return pubkey

This commit is contained in:
blackjok3r
2018-10-24 12:12:18 +08:00
parent 5a363fdffc
commit c4ee47ec36
4 changed files with 36 additions and 15 deletions

View File

@@ -257,18 +257,6 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex)
return result;
}
void voutToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
{
UniValue vout(UniValue::VARR);
for (unsigned int i = 0; i < tx.vout.size(); i++) {
const CTxOut& txout = tx.vout[i];
UniValue out(UniValue::VOBJ);
out.push_back(Pair("hex", HexStr(txout.scriptPubKey.begin(), txout.scriptPubKey.end())));
vout.push_back(out);
}
entry.push_back(Pair("vout", vout));
}
UniValue getdatafromblock(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
@@ -335,18 +323,20 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp)
UniValue result(UniValue::VARR);
unsigned int i = 0;
fprintf(stderr, "number of tx in block: %ld\n", block.vtx.size());
// Iif block tx size is > 2 then we can do this
BOOST_FOREACH(const CTransaction&tx, block.vtx)
{
//if the vout size = 3 then its a valid TX get the data. dont use the test here! it wont work with notarisations!
if ( (i == 0) || (i == (block.vtx.size() -1)) )
{
fprintf(stderr, "skipped tx number: %d \n",i);
} else {
fprintf(stderr, "added tx number: %d \n",i);
UniValue objTx(UniValue::VOBJ);
//voutToJSON(tx, uint256(), objTx);
//const CTxOut& txout = tx.vout[i];
//UniValue out(UniValue::VOBJ);
objTx.push_back(Pair("hex", HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end())));
// function here to extract seqid from first and last TX
// we an push the data or not depending on input from RPC.
result.push_back(objTx);
}
i = i + 1;

View File

@@ -264,6 +264,7 @@ static const CRPCCommand vRPCCommands[] =
{ "control", "getinfo", &getinfo, true }, /* uses wallet if enabled */
{ "control", "help", &help, true },
{ "control", "stop", &stop, true },
{ "control", "getpubkey", &getpubkey, true },
/* P2P networking */
{ "network", "getnetworkinfo", &getnetworkinfo, 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 validateaddress(const UniValue& params, bool fHelp);
extern UniValue getinfo(const UniValue& params, bool fHelp);
extern UniValue getpubkey(const UniValue& params, bool fHelp);
extern UniValue getwalletinfo(const UniValue& params, bool fHelp);
extern UniValue getblockchaininfo(const UniValue& params, bool fHelp);
extern UniValue getnetworkinfo(const UniValue& params, bool fHelp);

View File

@@ -4953,6 +4953,35 @@ UniValue channelsaddress(const UniValue& params, bool fHelp)
return(result);
}
UniValue getpubkey(const UniValue& params, bool fHelp)
{
UniValue result(UniValue::VOBJ);
if (fHelp || params.size() > 0)
throw runtime_error(
"getpubkey\n"
"\nReturns the -pubkey the daemon was started with.\n"
"\nResult:\n"
"[\n"
" {\n"
" \"pubkey\" : \"pubkey\", (string) The pubkey\n"
" }\n"
"]\n"
"\nExamples:\n"
"\nList pubkey.\n"
+ HelpExampleCli("getpubkey", "")
+ HelpExampleRpc("getpubkey", "")
);
extern uint8_t NOTARY_PUBKEY33[];
extern std::string NOTARY_PUBKEY;
if ( NOTARY_PUBKEY33[0] == 0 ) {
result.push_back(Pair("error","pubkey was not set!";
} else {
result.push_back(Pair("pubkey", NOTARY_PUBKEY);
}
return result;
}
UniValue oraclesaddress(const UniValue& params, bool fHelp)
{
struct CCcontract_info *cp,C; std::vector<unsigned char> pubkey;