Add support for dual opret with Token opret.
This commit is contained in:
@@ -29,6 +29,7 @@
|
|||||||
#include "txmempool.h"
|
#include "txmempool.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "cc/eval.h"
|
#include "cc/eval.h"
|
||||||
|
#include "cc/CCinclude.h"
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
#include "wallet/wallet.h"
|
#include "wallet/wallet.h"
|
||||||
#include "wallet/walletdb.h"
|
#include "wallet/walletdb.h"
|
||||||
@@ -1343,17 +1344,17 @@ UniValue txnotarizedconfirmed(const UniValue& params, bool fHelp)
|
|||||||
|
|
||||||
UniValue decodeccopret(const UniValue& params, bool fHelp)
|
UniValue decodeccopret(const UniValue& params, bool fHelp)
|
||||||
{
|
{
|
||||||
CTransaction tx; uint256 txid,hashBlock;
|
CTransaction tx; uint256 tokenid,txid,hashblock;
|
||||||
std::vector<uint8_t> vopret; uint8_t *script;
|
std::vector<uint8_t> vopret,vOpretExtra; uint8_t *script,tokenevalcode;
|
||||||
UniValue result(UniValue::VOBJ);
|
UniValue result(UniValue::VOBJ),array(UniValue::VARR); std::vector<CPubKey> pubkeys;
|
||||||
|
|
||||||
if (fHelp || params.size() < 1 || params.size() > 1)
|
if (fHelp || params.size() < 1 || params.size() > 1)
|
||||||
{
|
{
|
||||||
string msg = "decodeccopret hex\n"
|
string msg = "decodeccopret scriptPubKey\n"
|
||||||
"\nReturns eval code and function id for CC OP RETURN data.\n"
|
"\nReturns eval code and function id for CC OP RETURN data.\n"
|
||||||
|
|
||||||
"\nArguments:\n"
|
"\nArguments:\n"
|
||||||
"1. txid (string, required) Transaction id.\n"
|
"1. scriptPubKey (string, required) Hex of scriptPubKey with OP_RETURN data.\n"
|
||||||
|
|
||||||
"\nResult:\n"
|
"\nResult:\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
@@ -1363,21 +1364,38 @@ UniValue decodeccopret(const UniValue& params, bool fHelp)
|
|||||||
;
|
;
|
||||||
throw runtime_error(msg);
|
throw runtime_error(msg);
|
||||||
}
|
}
|
||||||
txid = uint256S((char *)params[0].get_str().c_str());
|
std::vector<unsigned char> hex(ParseHex(params[0].get_str()));
|
||||||
|
CScript scripthex(hex.begin(),hex.end());
|
||||||
|
if (DecodeTokenOpRet(scripthex,tokenevalcode,tokenid,pubkeys,vOpretExtra)!=0 && tokenevalcode==EVAL_TOKENS && vOpretExtra.size()>0)
|
||||||
{
|
{
|
||||||
LOCK(cs_main);
|
UniValue obj(UniValue::VOBJ);
|
||||||
if (!GetTransaction(txid, tx, hashBlock, true))
|
GetOpReturnData(scripthex,vopret);
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction");
|
script = (uint8_t *)vopret.data();
|
||||||
|
if ( vopret.size() > 1)
|
||||||
|
{
|
||||||
|
char func[5];
|
||||||
|
sprintf(func,"%c",script[1]);
|
||||||
|
obj.push_back(Pair("eval_code", EvalToStr(script[0])));
|
||||||
|
obj.push_back(Pair("function", func));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
obj.push_back(Pair("error", "invalid or no CC opret data for Token OP_RETURN"));
|
||||||
|
}
|
||||||
|
array.push_back(obj);
|
||||||
|
if (!E_UNMARSHAL(vOpretExtra, { ss >> vopret; })) return (0);
|
||||||
}
|
}
|
||||||
GetOpReturnData(tx.vout[tx.vout.size()-1].scriptPubKey,vopret);
|
else GetOpReturnData(scripthex,vopret);
|
||||||
script = (uint8_t *)vopret.data();
|
script = (uint8_t *)vopret.data();
|
||||||
if ( vopret.size() > 1)
|
if ( vopret.size() > 1)
|
||||||
{
|
{
|
||||||
char func[5];
|
char func[5]; UniValue obj(UniValue::VOBJ);
|
||||||
sprintf(func,"%c",script[1]);
|
|
||||||
result.push_back(Pair("result", "success"));
|
result.push_back(Pair("result", "success"));
|
||||||
result.push_back(Pair("eval_code", EvalToStr(script[0])));
|
sprintf(func,"%c",script[1]);
|
||||||
result.push_back(Pair("function", func));
|
obj.push_back(Pair("eval_code", EvalToStr(script[0])));
|
||||||
|
obj.push_back(Pair("function", func));
|
||||||
|
array.push_back(obj);
|
||||||
|
result.push_back(Pair("OpRets",array));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user