Browse Source

Decode CC opret RPC

metaverse
Mihailo Milenkovic 6 years ago
parent
commit
8089c2a86f
  1. 49
      src/rpc/misc.cpp
  2. 1
      src/rpc/server.cpp
  3. 1
      src/rpc/server.h

49
src/rpc/misc.cpp

@ -28,6 +28,7 @@
#include "timedata.h"
#include "txmempool.h"
#include "util.h"
#include "cc/eval.h"
#ifdef ENABLE_WALLET
#include "wallet/wallet.h"
#include "wallet/walletdb.h"
@ -1335,7 +1336,53 @@ UniValue txnotarizedconfirmed(const UniValue& params, bool fHelp)
txid = uint256S((char *)params[0].get_str().c_str());
notarizedconfirmed=komodo_txnotarizedconfirmed(txid);
UniValue result(UniValue::VOBJ);
result.push_back(Pair("result", notarizedconfirmed));
result.push_back(Pair("result", notarizedconfirmed));
return result;
}
UniValue decodeccopret(const UniValue& params, bool fHelp)
{
CTransaction tx; uint256 txid,hashBlock;
std::vector<uint8_t> vopret; uint8_t *script;
UniValue result(UniValue::VOBJ);
if (fHelp || params.size() < 1 || params.size() > 1)
{
string msg = "decodeccopret hex\n"
"\nReturns eval code and function id for CC OP RETURN data.\n"
"\nArguments:\n"
"1. txid (string, required) Transaction id.\n"
"\nResult:\n"
"{\n"
" eval_code, (string) Eval code name.\n"
" function, (char) Function id char.\n"
"}\n"
;
throw runtime_error(msg);
}
txid = uint256S((char *)params[0].get_str().c_str());
{
LOCK(cs_main);
if (!GetTransaction(txid, tx, hashBlock, true))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction");
}
GetOpReturnData(tx.vout[tx.vout.size()-1].scriptPubKey,vopret);
script = (uint8_t *)vopret.data();
if ( vopret.size() > 1)
{
char func[5];
sprintf(func,"%c",script[1]);
result.push_back(Pair("result", "success"));
result.push_back(Pair("eval_code", EvalToStr(script[0])));
result.push_back(Pair("function", func));
}
else
{
result.push_back(Pair("result", "error"));
result.push_back(Pair("error", "invalid or no CC opret data"));
}
return result;
}

1
src/rpc/server.cpp

@ -503,6 +503,7 @@ static const CRPCCommand vRPCCommands[] =
{ "util", "validateaddress", &validateaddress, true }, /* uses wallet if enabled */
{ "util", "verifymessage", &verifymessage, true },
{ "util", "txnotarizedconfirmed", &txnotarizedconfirmed, true },
{ "util", "decodeccopret", &decodeccopret, true },
{ "util", "estimatefee", &estimatefee, true },
{ "util", "estimatepriority", &estimatepriority, true },
{ "util", "z_validateaddress", &z_validateaddress, true }, /* uses wallet if enabled */

1
src/rpc/server.h

@ -356,6 +356,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 txnotarizedconfirmed(const UniValue& params, bool fHelp);
extern UniValue decodeccopret(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);

Loading…
Cancel
Save