Merge branch 'prices-rpc' of https://github.com/dimxy/komodo into dimxy-prices-rpc
This commit is contained in:
@@ -524,6 +524,11 @@ if GLIBC_BACK_COMPAT
|
||||
libbitcoin_util_a_SOURCES += compat/glibc_compat.cpp
|
||||
endif
|
||||
|
||||
if ENABLE_TESTS
|
||||
libbitcoin_server_a_SOURCES += rpc/testtransactions.cpp
|
||||
endif
|
||||
|
||||
|
||||
# cli: zcash-cli
|
||||
libbitcoin_cli_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
libbitcoin_cli_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
|
||||
@@ -17,34 +17,39 @@
|
||||
#ifndef CC_PRICES_H
|
||||
#define CC_PRICES_H
|
||||
|
||||
#include "komodo_defs.h"
|
||||
#include "CCinclude.h"
|
||||
int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblocks);
|
||||
|
||||
#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1)
|
||||
// #define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) // defined in komodo_defs.h
|
||||
#define PRICES_TXFEE 10000
|
||||
#define PRICES_MAXLEVERAGE 777
|
||||
#define PRICES_SMOOTHWIDTH 1
|
||||
#define KOMODO_MAXPRICES 2048 // must be power of 2 and less than 8192
|
||||
#define KOMODO_PRICEMASK (~(KOMODO_MAXPRICES - 1))
|
||||
#define PRICES_WEIGHT (KOMODO_MAXPRICES * 1)
|
||||
#define PRICES_MULT (KOMODO_MAXPRICES * 2)
|
||||
#define PRICES_DIV (KOMODO_MAXPRICES * 3)
|
||||
#define PRICES_INV (KOMODO_MAXPRICES * 4)
|
||||
#define PRICES_MDD (KOMODO_MAXPRICES * 5)
|
||||
#define PRICES_MMD (KOMODO_MAXPRICES * 6)
|
||||
#define PRICES_MMM (KOMODO_MAXPRICES * 7)
|
||||
#define PRICES_DDD (KOMODO_MAXPRICES * 8)
|
||||
#define KOMODO_PRICEMASK (~(KOMODO_MAXPRICES - 1)) // actually 1111 1000 0000 0000
|
||||
#define PRICES_WEIGHT (KOMODO_MAXPRICES * 1) // 0000 1000 0000 0000
|
||||
#define PRICES_MULT (KOMODO_MAXPRICES * 2) // 0001 0000 0000 0000
|
||||
#define PRICES_DIV (KOMODO_MAXPRICES * 3) // 0001 1000 0000 0000
|
||||
#define PRICES_INV (KOMODO_MAXPRICES * 4) // 0010 0000 0000 0000
|
||||
#define PRICES_MDD (KOMODO_MAXPRICES * 5) // 0010 1000 0000 0000
|
||||
#define PRICES_MMD (KOMODO_MAXPRICES * 6) // 0011 0000 0000 0000
|
||||
#define PRICES_MMM (KOMODO_MAXPRICES * 7) // 0011 1000 0000 0000
|
||||
#define PRICES_DDD (KOMODO_MAXPRICES * 8) // 0100 0000 0000 0000
|
||||
|
||||
#define PRICES_NORMFACTOR (int64_t)(SATOSHIDEN)
|
||||
#define PRICES_POINTFACTOR (int64_t)10000
|
||||
|
||||
bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn);
|
||||
|
||||
// CCcustom
|
||||
UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector<std::string> synthetic);
|
||||
UniValue PricesAddFunding(uint64_t txfee,uint256 bettxid,int64_t amount);
|
||||
UniValue PricesSetcostbasis(uint64_t txfee,uint256 bettxid);
|
||||
UniValue PricesRekt(uint64_t txfee,uint256 bettxid,int32_t rektheight);
|
||||
UniValue PricesCashout(uint64_t txfee,uint256 bettxid);
|
||||
UniValue PricesBet(int64_t txfee,int64_t amount,int16_t leverage,std::vector<std::string> synthetic);
|
||||
UniValue PricesAddFunding(int64_t txfee,uint256 bettxid,int64_t amount);
|
||||
UniValue PricesSetcostbasis(int64_t txfee,uint256 bettxid);
|
||||
UniValue PricesRekt(int64_t txfee,uint256 bettxid,int32_t rektheight);
|
||||
UniValue PricesCashout(int64_t txfee,uint256 bettxid);
|
||||
UniValue PricesInfo(uint256 bettxid,int32_t refheight);
|
||||
UniValue PricesList();
|
||||
UniValue PricesList(uint32_t filter, CPubKey mypk);
|
||||
UniValue PricesGetOrderbook();
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -298,6 +298,7 @@ UniValue ValueFromAmount(const CAmount& amount);
|
||||
|
||||
int64_t TotalPubkeyNormalInputs(const CTransaction &tx, const CPubKey &pubkey);
|
||||
int64_t TotalPubkeyCCInputs(const CTransaction &tx, const CPubKey &pubkey);
|
||||
inline std::string STR_TOLOWER(const std::string &str) { std::string out; for (std::string::const_iterator i = str.begin(); i != str.end(); i++) out += std::tolower(*i); return out; }
|
||||
|
||||
// bitcoin LogPrintStr with category "-debug" cmdarg support for C++ ostringstream:
|
||||
#define CCLOG_INFO 0
|
||||
|
||||
2192
src/cc/prices.cpp
2192
src/cc/prices.cpp
File diff suppressed because it is too large
Load Diff
@@ -38,7 +38,12 @@
|
||||
#define KOMODO_MAXNVALUE (((uint64_t)1 << 63) - 1)
|
||||
#define KOMODO_BIT63SET(x) ((x) & ((uint64_t)1 << 63))
|
||||
#define KOMODO_VALUETOOBIG(x) ((x) > (uint64_t)10000000001*COIN)
|
||||
|
||||
//#ifndef TESTMODE
|
||||
#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1)
|
||||
//#else
|
||||
//#define PRICES_DAYWINDOW (7)
|
||||
//#endif
|
||||
|
||||
extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC;
|
||||
int32_t MAX_BLOCK_SIZE(int32_t height);
|
||||
@@ -101,7 +106,7 @@ int32_t komodo_dpowconfs(int32_t height,int32_t numconfs);
|
||||
int8_t komodo_segid(int32_t nocache,int32_t height);
|
||||
int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight);
|
||||
char *komodo_pricename(char *name,int32_t ind);
|
||||
int32_t komodo_priceind(char *symbol);
|
||||
int32_t komodo_priceind(const char *symbol);
|
||||
int32_t komodo_pricesinit();
|
||||
int64_t komodo_priceave(int64_t *tmpbuf,int64_t *correlated,int32_t cskip);
|
||||
int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t rawskip,uint32_t *nonzprices,int32_t smoothwidth);
|
||||
@@ -112,4 +117,4 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo
|
||||
uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight);
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -2400,8 +2400,8 @@ char *komodo_pricename(char *name,int32_t ind)
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
int32_t komodo_priceind(char *symbol)
|
||||
// finds index for its symbol name
|
||||
int32_t komodo_priceind(const char *symbol)
|
||||
{
|
||||
char name[65]; int32_t i,n = (int32_t)(komodo_cbopretsize(ASSETCHAINS_CBOPRET) / sizeof(uint32_t));
|
||||
for (i=1; i<n; i++)
|
||||
@@ -2412,7 +2412,7 @@ int32_t komodo_priceind(char *symbol)
|
||||
}
|
||||
return(-1);
|
||||
}
|
||||
|
||||
// returns price value which is in a 10% interval for more than 50% points for the preceding 24 hours
|
||||
int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t rawskip,uint32_t *nonzprices,int32_t smoothwidth)
|
||||
{
|
||||
int32_t i,j,k,n,iter,correlation,maxcorrelation=0; int64_t firstprice,price,sum,den,mult,refprice,lowprice,highprice;
|
||||
@@ -2801,4 +2801,3 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo
|
||||
pthread_mutex_unlock(&pricemutex);
|
||||
return(retval);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,9 @@
|
||||
|
||||
#include <regex>
|
||||
|
||||
#include "cc/CCinclude.h"
|
||||
#include "cc/CCPrices.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
|
||||
@@ -1155,17 +1158,17 @@ UniValue paxprice(const UniValue& params, bool fHelp)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// fills pricedata with raw price, correlated and smoothed values for numblock
|
||||
/*int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks,int32_t ind)
|
||||
{
|
||||
int32_t height,i,n,width,numpricefeeds = -1; uint64_t seed,ignore,rngval; uint32_t rawprices[1440*6],*ptr; int64_t *tmpbuf;
|
||||
width = numblocks+PRICES_DAYWINDOW*2+PRICES_SMOOTHWIDTH;
|
||||
width = numblocks+PRICES_DAYWINDOW*2+PRICES_SMOOTHWIDTH; // need 2*PRICES_DAYWINDOW previous raw price points to calc PRICES_DAYWINDOW correlated points to calc, in turn, smoothed point
|
||||
komodo_heightpricebits(&seed,rawprices,firstheight + numblocks - 1);
|
||||
if ( firstheight < width )
|
||||
return(-1);
|
||||
for (i=0; i<width; i++)
|
||||
{
|
||||
if ( (n= komodo_heightpricebits(&ignore,rawprices,firstheight + numblocks - 1 - i)) < 0 )
|
||||
if ( (n= komodo_heightpricebits(&ignore,rawprices,firstheight + numblocks - 1 - i)) < 0 ) // stores raw prices in backward order
|
||||
return(-1);
|
||||
if ( numpricefeeds < 0 )
|
||||
numpricefeeds = n;
|
||||
@@ -1176,16 +1179,18 @@ UniValue paxprice(const UniValue& params, bool fHelp)
|
||||
ptr[1] = rawprices[0]; // timestamp
|
||||
}
|
||||
rngval = seed;
|
||||
for (i=0; i<numblocks+PRICES_DAYWINDOW+PRICES_SMOOTHWIDTH; i++)
|
||||
for (i=0; i<numblocks+PRICES_DAYWINDOW+PRICES_SMOOTHWIDTH; i++) // calculates +PRICES_DAYWINDOW more correlated values
|
||||
{
|
||||
rngval = (rngval*11109 + 13849);
|
||||
ptr = (uint32_t *)&pricedata[i*3];
|
||||
if ( (pricedata[i*3+1]= komodo_pricecorrelated(rngval,ind,(uint32_t *)&pricedata[i*3],6,0,PRICES_SMOOTHWIDTH)) < 0 )
|
||||
// takes previous PRICES_DAYWINDOW raw prices and calculates correlated price value
|
||||
if ( (pricedata[i*3+1]= komodo_pricecorrelated(rngval,ind,(uint32_t *)&pricedata[i*3],6,0,PRICES_SMOOTHWIDTH)) < 0 ) // skip is 6 == sizeof(int64_t)/sizeof(int32_t)*3
|
||||
return(-3);
|
||||
}
|
||||
tmpbuf = (int64_t *)calloc(sizeof(int64_t),2*PRICES_DAYWINDOW);
|
||||
for (i=0; i<numblocks; i++)
|
||||
pricedata[i*3+2] = komodo_priceave(tmpbuf,&pricedata[i*3+1],3);
|
||||
// takes previous PRICES_DAYWINDOW correlated price values and calculates smoothed value
|
||||
pricedata[i*3+2] = komodo_priceave(tmpbuf,&pricedata[i*3+1],3);
|
||||
free(tmpbuf);
|
||||
return(0);
|
||||
}*/
|
||||
@@ -1315,6 +1320,139 @@ UniValue prices(const UniValue& params, bool fHelp)
|
||||
return ret;
|
||||
}
|
||||
|
||||
// pricesbet rpc implementation
|
||||
UniValue pricesbet(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 3)
|
||||
throw runtime_error("pricesbet amount leverage \"synthetic-expression\"\n"
|
||||
"amount is in coins\n"
|
||||
"leverage is integer non-zero value, positive for long, negative for short position\n"
|
||||
"synthetic-expression example \"BTC_USD, 1\"\n");
|
||||
LOCK(cs_main);
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
|
||||
if (ASSETCHAINS_CBOPRET == 0)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices");
|
||||
|
||||
CAmount txfee = 10000;
|
||||
CAmount amount = atof(params[0].get_str().c_str()) * COIN;
|
||||
int16_t leverage = (int16_t)atoi(params[1].get_str().c_str());
|
||||
if (leverage == 0)
|
||||
throw runtime_error("invalid leverage\n");
|
||||
|
||||
std::string sexpr = params[2].get_str();
|
||||
std::vector<std::string> vexpr;
|
||||
SplitStr(sexpr, vexpr);
|
||||
|
||||
// debug print parsed strings:
|
||||
std::cerr << "parsed synthetic: ";
|
||||
for (auto s : vexpr)
|
||||
std::cerr << s << " ";
|
||||
std::cerr << std::endl;
|
||||
|
||||
return PricesBet(txfee, amount, leverage, vexpr);
|
||||
}
|
||||
|
||||
// pricesaddfunding rpc implementation
|
||||
UniValue pricesaddfunding(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 2)
|
||||
throw runtime_error("pricesaddfunding bettxid amount\n"
|
||||
"where amount is in coins\n");
|
||||
LOCK(cs_main);
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
|
||||
if (ASSETCHAINS_CBOPRET == 0)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices");
|
||||
|
||||
CAmount txfee = 10000;
|
||||
uint256 bettxid = Parseuint256(params[0].get_str().c_str());
|
||||
if (bettxid.IsNull())
|
||||
throw runtime_error("invalid bettxid\n");
|
||||
|
||||
CAmount amount = atof(params[1].get_str().c_str()) * COIN;
|
||||
if (amount <= 0)
|
||||
throw runtime_error("invalid amount\n");
|
||||
|
||||
return PricesAddFunding(txfee, bettxid, amount);
|
||||
}
|
||||
|
||||
// rpc pricessetcostbasis implementation
|
||||
UniValue pricessetcostbasis(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error("pricessetcostbasis bettxid\n");
|
||||
LOCK(cs_main);
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
|
||||
if (ASSETCHAINS_CBOPRET == 0)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices");
|
||||
|
||||
uint256 bettxid = Parseuint256(params[0].get_str().c_str());
|
||||
if (bettxid.IsNull())
|
||||
throw runtime_error("invalid bettxid\n");
|
||||
|
||||
int64_t txfee = 10000;
|
||||
|
||||
return PricesSetcostbasis(txfee, bettxid);
|
||||
}
|
||||
|
||||
// pricescashout rpc implementation
|
||||
UniValue pricescashout(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error("pricescashout bettxid\n");
|
||||
LOCK(cs_main);
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
|
||||
if (ASSETCHAINS_CBOPRET == 0)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices");
|
||||
|
||||
uint256 bettxid = Parseuint256(params[0].get_str().c_str());
|
||||
if (bettxid.IsNull())
|
||||
throw runtime_error("invalid bettxid\n");
|
||||
|
||||
int64_t txfee = 10000;
|
||||
|
||||
return PricesCashout(txfee, bettxid);
|
||||
}
|
||||
|
||||
// pricesrekt rpc implementation
|
||||
UniValue pricesrekt(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 2)
|
||||
throw runtime_error("pricesrekt bettxid height\n");
|
||||
LOCK(cs_main);
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
|
||||
if (ASSETCHAINS_CBOPRET == 0)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices");
|
||||
|
||||
uint256 bettxid = Parseuint256(params[0].get_str().c_str());
|
||||
if (bettxid.IsNull())
|
||||
throw runtime_error("invalid bettxid\n");
|
||||
|
||||
int32_t height = atoi(params[0].get_str().c_str());
|
||||
|
||||
int64_t txfee = 10000;
|
||||
|
||||
return PricesRekt(txfee, bettxid, height);
|
||||
}
|
||||
|
||||
// pricesrekt rpc implementation
|
||||
UniValue pricesgetorderbook(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error("pricesgetorderbook\n");
|
||||
LOCK(cs_main);
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
|
||||
if (ASSETCHAINS_CBOPRET == 0)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices");
|
||||
|
||||
return PricesGetOrderbook();
|
||||
}
|
||||
|
||||
UniValue gettxout(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() < 2 || params.size() > 3)
|
||||
@@ -1944,4 +2082,4 @@ void RegisterBlockchainRPCCommands(CRPCTable &tableRPC)
|
||||
{
|
||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
|
||||
tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]);
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,10 @@ void RegisterMiningRPCCommands(CRPCTable &tableRPC);
|
||||
/** Register raw transaction RPC commands */
|
||||
void RegisterRawTransactionRPCCommands(CRPCTable &tableRPC);
|
||||
|
||||
/** Register test transaction RPC commands */
|
||||
void RegisterTesttransactionsRPCCommands(CRPCTable &tableRPC);
|
||||
|
||||
|
||||
static inline void RegisterAllCoreRPCCommands(CRPCTable &tableRPC)
|
||||
{
|
||||
RegisterBlockchainRPCCommands(tableRPC);
|
||||
@@ -42,6 +46,9 @@ static inline void RegisterAllCoreRPCCommands(CRPCTable &tableRPC)
|
||||
RegisterMiscRPCCommands(tableRPC);
|
||||
RegisterMiningRPCCommands(tableRPC);
|
||||
RegisterRawTransactionRPCCommands(tableRPC);
|
||||
#ifdef TESTMODE
|
||||
RegisterTesttransactionsRPCCommands(tableRPC);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -463,7 +463,15 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "prices", "prices", &prices, true },
|
||||
{ "prices", "pricesaddress", &pricesaddress, true },
|
||||
{ "prices", "priceslist", &priceslist, true },
|
||||
{ "prices", "mypriceslist", &mypriceslist, true },
|
||||
{ "prices", "pricesinfo", &pricesinfo, true },
|
||||
{ "prices", "pricesbet", &pricesbet, true },
|
||||
{ "prices", "pricessetcostbasis", &pricessetcostbasis, true },
|
||||
{ "prices", "pricescashout", &pricescashout, true },
|
||||
{ "prices", "pricesrekt", &pricesrekt, true },
|
||||
{ "prices", "pricesaddfunding", &pricesaddfunding, true },
|
||||
{ "prices", "pricesgetorderbook", &pricesgetorderbook, true },
|
||||
|
||||
|
||||
// Pegs
|
||||
{ "pegs", "pegsaddress", &pegsaddress, true },
|
||||
@@ -569,10 +577,6 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "util", "reconsiderblock", &reconsiderblock, true },
|
||||
/* Not shown in help */
|
||||
{ "hidden", "setmocktime", &setmocktime, true },
|
||||
{ "hidden", "test_ac", &test_ac, true },
|
||||
{ "hidden", "test_heirmarker", &test_heirmarker, true },
|
||||
{ "hidden", "test_proof", &test_proof, true },
|
||||
{ "hidden", "test_burntx", &test_burntx, true },
|
||||
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
|
||||
@@ -273,6 +273,7 @@ extern UniValue oraclesdata(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclessamples(const UniValue& params, bool fHelp);
|
||||
extern UniValue pricesaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue priceslist(const UniValue& params, bool fHelp);
|
||||
extern UniValue mypriceslist(const UniValue& params, bool fHelp);
|
||||
extern UniValue pricesinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue pegsaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue marmaraaddress(const UniValue& params, bool fHelp);
|
||||
@@ -502,11 +503,13 @@ extern UniValue paxdeposit(const UniValue& params, bool fHelp);
|
||||
extern UniValue paxwithdraw(const UniValue& params, bool fHelp);
|
||||
|
||||
extern UniValue prices(const UniValue& params, bool fHelp);
|
||||
extern UniValue pricesbet(const UniValue& params, bool fHelp);
|
||||
extern UniValue pricessetcostbasis(const UniValue& params, bool fHelp);
|
||||
extern UniValue pricescashout(const UniValue& params, bool fHelp);
|
||||
extern UniValue pricesrekt(const UniValue& params, bool fHelp);
|
||||
extern UniValue pricesaddfunding(const UniValue& params, bool fHelp);
|
||||
extern UniValue pricesgetorderbook(const UniValue& params, bool fHelp);
|
||||
|
||||
|
||||
// test rpc:
|
||||
extern UniValue test_ac(const UniValue& params, bool fHelp);
|
||||
extern UniValue test_heirmarker(const UniValue& params, bool fHelp);
|
||||
extern UniValue test_burntx(const UniValue& params, bool fHelp);
|
||||
extern UniValue test_proof(const UniValue& params, bool fHelp);
|
||||
|
||||
#endif // BITCOIN_RPCSERVER_H
|
||||
|
||||
268
src/rpc/testtransactions.cpp
Normal file
268
src/rpc/testtransactions.cpp
Normal file
@@ -0,0 +1,268 @@
|
||||
// Copyright (c) 2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
/******************************************************************************
|
||||
* Copyright © 2014-2019 The SuperNET Developers. *
|
||||
* *
|
||||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
|
||||
* the top-level directory of this distribution for the individual copyright *
|
||||
* holder information and the developer policies on copyright and licensing. *
|
||||
* *
|
||||
* Unless otherwise agreed in a custom licensing agreement, no part of the *
|
||||
* SuperNET software, including this file may be copied, modified, propagated *
|
||||
* or distributed except according to the terms contained in the LICENSE file *
|
||||
* *
|
||||
* Removal or modification of this copyright notice is prohibited. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "amount.h"
|
||||
#include "chain.h"
|
||||
#include "chainparams.h"
|
||||
#include "checkpoints.h"
|
||||
#include "crosschain.h"
|
||||
#include "base58.h"
|
||||
#include "consensus/validation.h"
|
||||
#include "cc/eval.h"
|
||||
#include "main.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "rpc/server.h"
|
||||
#include "streams.h"
|
||||
#include "sync.h"
|
||||
#include "util.h"
|
||||
#include "script/script.h"
|
||||
#include "script/script_error.h"
|
||||
#include "script/sign.h"
|
||||
#include "script/standard.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <univalue.h>
|
||||
|
||||
#include <regex>
|
||||
|
||||
|
||||
#include "cc/CCinclude.h"
|
||||
#include "cc/CCPrices.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int32_t ensure_CCrequirements(uint8_t evalcode);
|
||||
|
||||
UniValue test_ac(const UniValue& params, bool fHelp)
|
||||
{
|
||||
// make fake token tx:
|
||||
struct CCcontract_info *cp, C;
|
||||
|
||||
if (fHelp || (params.size() != 4))
|
||||
throw runtime_error("incorrect params\n");
|
||||
if (ensure_CCrequirements(EVAL_HEIR) < 0)
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
|
||||
std::vector<unsigned char> pubkey1;
|
||||
std::vector<unsigned char> pubkey2;
|
||||
|
||||
pubkey1 = ParseHex(params[0].get_str().c_str());
|
||||
pubkey2 = ParseHex(params[1].get_str().c_str());
|
||||
|
||||
CPubKey pk1 = pubkey2pk(pubkey1);
|
||||
CPubKey pk2 = pubkey2pk(pubkey2);
|
||||
|
||||
if (!pk1.IsValid() || !pk2.IsValid())
|
||||
throw runtime_error("invalid pubkey\n");
|
||||
|
||||
int64_t txfee = 10000;
|
||||
int64_t amount = atoll(params[2].get_str().c_str()) * COIN;
|
||||
uint256 fundingtxid = Parseuint256((char *)params[3].get_str().c_str());
|
||||
|
||||
CPubKey myPubkey = pubkey2pk(Mypubkey());
|
||||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
|
||||
|
||||
int64_t normalInputs = AddNormalinputs(mtx, myPubkey, txfee + amount, 60);
|
||||
|
||||
if (normalInputs < txfee + amount)
|
||||
throw runtime_error("not enough normals\n");
|
||||
|
||||
mtx.vout.push_back(MakeCC1of2vout(EVAL_HEIR, amount, pk1, pk2));
|
||||
|
||||
CScript opret;
|
||||
fundingtxid = revuint256(fundingtxid);
|
||||
|
||||
opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'A' << fundingtxid << (uint8_t)0);
|
||||
|
||||
cp = CCinit(&C, EVAL_HEIR);
|
||||
return(FinalizeCCTx(0, cp, mtx, myPubkey, txfee, opret));
|
||||
}
|
||||
|
||||
UniValue test_heirmarker(const UniValue& params, bool fHelp)
|
||||
{
|
||||
// make fake token tx:
|
||||
struct CCcontract_info *cp, C;
|
||||
|
||||
if (fHelp || (params.size() != 1))
|
||||
throw runtime_error("incorrect params\n");
|
||||
if (ensure_CCrequirements(EVAL_HEIR) < 0)
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
|
||||
uint256 fundingtxid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
|
||||
CPubKey myPubkey = pubkey2pk(Mypubkey());
|
||||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
|
||||
|
||||
int64_t normalInputs = AddNormalinputs(mtx, myPubkey, 10000, 60);
|
||||
if (normalInputs < 10000)
|
||||
throw runtime_error("not enough normals\n");
|
||||
|
||||
mtx.vin.push_back(CTxIn(fundingtxid, 1));
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_HEIR, 10000, myPubkey));
|
||||
|
||||
CScript opret;
|
||||
fundingtxid = revuint256(fundingtxid);
|
||||
|
||||
opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'C' << fundingtxid << (uint8_t)0);
|
||||
|
||||
cp = CCinit(&C, EVAL_HEIR);
|
||||
return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, opret));
|
||||
}
|
||||
|
||||
UniValue test_burntx(const UniValue& params, bool fHelp)
|
||||
{
|
||||
// make fake token tx:
|
||||
struct CCcontract_info *cp, C;
|
||||
|
||||
if (fHelp || (params.size() != 1))
|
||||
throw runtime_error("incorrect params\n");
|
||||
if (ensure_CCrequirements(EVAL_TOKENS) < 0)
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
|
||||
uint256 tokenid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
|
||||
CPubKey myPubkey = pubkey2pk(Mypubkey());
|
||||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
|
||||
|
||||
int64_t normalInputs = AddNormalinputs(mtx, myPubkey, 10000, 60);
|
||||
if (normalInputs < 10000)
|
||||
throw runtime_error("not enough normals\n");
|
||||
|
||||
CPubKey burnpk = pubkey2pk(ParseHex(CC_BURNPUBKEY));
|
||||
|
||||
mtx.vin.push_back(CTxIn(tokenid, 0));
|
||||
mtx.vin.push_back(CTxIn(tokenid, 1));
|
||||
mtx.vout.push_back(MakeTokensCC1vout(EVAL_TOKENS, 1, burnpk));
|
||||
|
||||
std::vector<CPubKey> voutPubkeys;
|
||||
voutPubkeys.push_back(burnpk);
|
||||
|
||||
cp = CCinit(&C, EVAL_TOKENS);
|
||||
|
||||
std::vector<uint8_t> vopret;
|
||||
GetNonfungibleData(tokenid, vopret);
|
||||
if (vopret.size() > 0)
|
||||
cp->additionalTokensEvalcode2 = vopret.begin()[0];
|
||||
|
||||
uint8_t tokenpriv[33];
|
||||
char unspendableTokenAddr[64];
|
||||
CPubKey unspPk = GetUnspendable(cp, tokenpriv);
|
||||
GetCCaddress(cp, unspendableTokenAddr, unspPk);
|
||||
CCaddr2set(cp, EVAL_TOKENS, unspPk, tokenpriv, unspendableTokenAddr);
|
||||
return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, EncodeTokenOpRet(tokenid, voutPubkeys, std::make_pair(0, vscript_t()))));
|
||||
}
|
||||
|
||||
UniValue test_proof(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ);
|
||||
std::vector<uint8_t>proof;
|
||||
|
||||
if (fHelp || (params.size() != 2))
|
||||
throw runtime_error("incorrect params\n");
|
||||
|
||||
|
||||
proof = ParseHex(params[0].get_str());
|
||||
uint256 cointxid = Parseuint256((char *)params[1].get_str().c_str());
|
||||
|
||||
std::vector<uint256> txids;
|
||||
|
||||
CMerkleBlock merkleBlock;
|
||||
if (!E_UNMARSHAL(proof, ss >> merkleBlock)) {
|
||||
result.push_back(Pair("error", "could not unmarshal proof"));
|
||||
return result;
|
||||
}
|
||||
uint256 merkleRoot = merkleBlock.txn.ExtractMatches(txids);
|
||||
|
||||
result.push_back(Pair("source_root", merkleRoot.GetHex()));
|
||||
|
||||
for (int i = 0; i < txids.size(); i++)
|
||||
std::cerr << "merkle block txid=" << txids[0].GetHex() << std::endl;
|
||||
|
||||
|
||||
std::vector<bool> vMatches(txids.size());
|
||||
for (auto v : vMatches) v = true;
|
||||
CPartialMerkleTree verifTree(txids, vMatches);
|
||||
|
||||
result.push_back(Pair("verif_root", verifTree.ExtractMatches(txids).GetHex()));
|
||||
|
||||
if (std::find(txids.begin(), txids.end(), cointxid) == txids.end()) {
|
||||
fprintf(stderr, "invalid proof for this cointxid\n");
|
||||
}
|
||||
|
||||
std::vector<uint256> vMerkleTree;
|
||||
bool f;
|
||||
::BuildMerkleTree(&f, txids, vMerkleTree);
|
||||
|
||||
std::vector<uint256> vMerkleBranch = ::GetMerkleBranch(0, txids.size(), vMerkleTree);
|
||||
|
||||
uint256 ourResult = SafeCheckMerkleBranch(zeroid, vMerkleBranch, 0);
|
||||
result.push_back(Pair("SafeCheckMerkleBranch", ourResult.GetHex()));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
extern CScript prices_costbasisopret(uint256 bettxid, CPubKey mypk, int32_t height, int64_t costbasis);
|
||||
UniValue test_pricesmarker(const UniValue& params, bool fHelp)
|
||||
{
|
||||
// make fake token tx:
|
||||
struct CCcontract_info *cp, C;
|
||||
|
||||
if (fHelp || (params.size() != 1))
|
||||
throw runtime_error("incorrect params\n");
|
||||
if (ensure_CCrequirements(EVAL_PRICES) < 0)
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
|
||||
uint256 bettxid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
|
||||
cp = CCinit(&C, EVAL_PRICES);
|
||||
CPubKey myPubkey = pubkey2pk(Mypubkey());
|
||||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
|
||||
|
||||
int64_t normalInputs = AddNormalinputs(mtx, myPubkey, 10000, 60);
|
||||
if (normalInputs < 10000)
|
||||
throw runtime_error("not enough normals\n");
|
||||
|
||||
mtx.vin.push_back(CTxIn(bettxid, 1));
|
||||
mtx.vout.push_back(CTxOut(1000, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG));
|
||||
|
||||
return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, prices_costbasisopret(bettxid, myPubkey, 100, 100)));
|
||||
}
|
||||
|
||||
|
||||
static const CRPCCommand commands[] =
|
||||
{ // category name actor (function) okSafeMode
|
||||
// --------------------- ------------------------ ----------------------- ----------
|
||||
|
||||
/* Not shown in help */
|
||||
{ "hidden", "test_ac", &test_ac, true },
|
||||
{ "hidden", "test_heirmarker", &test_heirmarker, true },
|
||||
{ "hidden", "test_proof", &test_proof, true },
|
||||
{ "hidden", "test_burntx", &test_burntx, true },
|
||||
{ "hidden", "test_pricesmarker", &test_pricesmarker, true }
|
||||
};
|
||||
|
||||
void RegisterTesttransactionsRPCCommands(CRPCTable &tableRPC)
|
||||
{
|
||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
|
||||
tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]);
|
||||
}
|
||||
28
src/util.cpp
28
src/util.cpp
@@ -394,27 +394,23 @@ void ParseParameters(int argc, const char* const argv[])
|
||||
}
|
||||
}
|
||||
|
||||
// split string using by space or comma as a delimiter char
|
||||
void SplitStr(const std::string& strVal, std::vector<std::string> &outVals)
|
||||
{
|
||||
stringstream ss(strVal);
|
||||
std::string str;
|
||||
|
||||
while ( ss.peek() == ' ' )
|
||||
ss.ignore();
|
||||
|
||||
while ( ss >> str )
|
||||
{
|
||||
if ( str.size() == 0 )
|
||||
continue;
|
||||
if ( str[str.size()-1] == ',' )
|
||||
str.resize(str.size()-1);
|
||||
outVals.push_back(str);
|
||||
while ( ss.peek() == ' ' )
|
||||
ss.ignore();
|
||||
if ( ss.peek() == ',' )
|
||||
ss.ignore();
|
||||
while ( ss.peek() == ' ' )
|
||||
while (!ss.eof()) {
|
||||
int c;
|
||||
std::string str;
|
||||
|
||||
while (std::isspace(ss.peek()))
|
||||
ss.ignore();
|
||||
|
||||
while ((c = ss.get()) != EOF && !std::isspace(c) && c != ',')
|
||||
str += c;
|
||||
|
||||
if (!str.empty())
|
||||
outVals.push_back(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -287,6 +287,9 @@ template <typename Callable> void TraceThread(const char* name, Callable func)
|
||||
}
|
||||
}
|
||||
|
||||
// split string using by space or comma as a delimiter char
|
||||
void SplitStr(const std::string& strVal, std::vector<std::string> &outVals);
|
||||
|
||||
#define KOMODO_ASSETCHAIN_MAXLEN 65
|
||||
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
#include <numeric>
|
||||
|
||||
#include "komodo_defs.h"
|
||||
#include <string.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -6945,25 +6946,61 @@ UniValue faucetget(const UniValue& params, bool fHelp)
|
||||
return(result);
|
||||
}
|
||||
|
||||
uint32_t pricesGetParam(UniValue param) {
|
||||
uint32_t filter = 0;
|
||||
if (STR_TOLOWER(param.get_str()) == "all")
|
||||
filter = 0;
|
||||
else if (STR_TOLOWER(param.get_str()) == "open")
|
||||
filter = 1;
|
||||
else if (STR_TOLOWER(param.get_str()) == "closed")
|
||||
filter = 2;
|
||||
else
|
||||
throw runtime_error("incorrect parameter\n");
|
||||
return filter;
|
||||
}
|
||||
|
||||
UniValue priceslist(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if ( fHelp || params.size() > 0 )
|
||||
throw runtime_error("priceslist\n");
|
||||
if ( fHelp || params.size() != 0 && params.size() != 1)
|
||||
throw runtime_error("priceslist [all|open|closed]\n");
|
||||
if ( ensure_CCrequirements(EVAL_PRICES) < 0 )
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
return(PricesList());
|
||||
uint32_t filter = 0;
|
||||
if (params.size() == 1)
|
||||
filter = pricesGetParam(params[0]);
|
||||
|
||||
CPubKey emptypk;
|
||||
|
||||
return(PricesList(filter, emptypk));
|
||||
}
|
||||
|
||||
UniValue mypriceslist(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0 && params.size() != 1)
|
||||
throw runtime_error("mypriceslist [all|open|closed]\n");
|
||||
if (ensure_CCrequirements(EVAL_PRICES) < 0)
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
|
||||
uint32_t filter = 0;
|
||||
if (params.size() == 1)
|
||||
filter = pricesGetParam(params[0]);
|
||||
CPubKey mypk = pubkey2pk(Mypubkey());
|
||||
|
||||
return(PricesList(filter, mypk));
|
||||
}
|
||||
|
||||
UniValue pricesinfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
uint256 bettxid; int32_t height;
|
||||
if ( fHelp || params.size() != 2 )
|
||||
throw runtime_error("pricesinfo fundingtxid\n");
|
||||
if ( fHelp || params.size() != 1 && params.size() != 2)
|
||||
throw runtime_error("pricesinfo bettxid [height]\n");
|
||||
if ( ensure_CCrequirements(EVAL_PRICES) < 0 )
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
bettxid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
height = atoi(params[1].get_str().c_str());
|
||||
return(PricesInfo(bettxid,height));
|
||||
height = 0;
|
||||
if (params.size() == 2)
|
||||
height = atoi(params[1].get_str().c_str());
|
||||
return(PricesInfo(bettxid, height));
|
||||
}
|
||||
|
||||
UniValue dicefund(const UniValue& params, bool fHelp)
|
||||
@@ -7961,84 +7998,6 @@ void RegisterWalletRPCCommands(CRPCTable &tableRPC)
|
||||
tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]);
|
||||
}
|
||||
|
||||
UniValue test_ac(const UniValue& params, bool fHelp)
|
||||
{
|
||||
// make fake token tx:
|
||||
struct CCcontract_info *cp, C;
|
||||
|
||||
if (fHelp || (params.size() != 4))
|
||||
throw runtime_error("incorrect params\n");
|
||||
if (ensure_CCrequirements(EVAL_HEIR) < 0)
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
|
||||
std::vector<unsigned char> pubkey1;
|
||||
std::vector<unsigned char> pubkey2;
|
||||
|
||||
pubkey1 = ParseHex(params[0].get_str().c_str());
|
||||
pubkey2 = ParseHex(params[1].get_str().c_str());
|
||||
|
||||
CPubKey pk1 = pubkey2pk(pubkey1);
|
||||
CPubKey pk2 = pubkey2pk(pubkey2);
|
||||
|
||||
if(!pk1.IsValid() || !pk2.IsValid())
|
||||
throw runtime_error("invalid pubkey\n");
|
||||
|
||||
int64_t txfee = 10000;
|
||||
int64_t amount = atoll(params[2].get_str().c_str()) * COIN;
|
||||
uint256 fundingtxid = Parseuint256((char *)params[3].get_str().c_str());
|
||||
|
||||
CPubKey myPubkey = pubkey2pk(Mypubkey());
|
||||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
|
||||
|
||||
int64_t normalInputs = AddNormalinputs(mtx, myPubkey, txfee + amount, 60);
|
||||
|
||||
if( normalInputs < txfee + amount)
|
||||
throw runtime_error("not enough normals\n");
|
||||
|
||||
mtx.vout.push_back(MakeCC1of2vout(EVAL_HEIR, amount, pk1, pk2));
|
||||
|
||||
CScript opret;
|
||||
fundingtxid = revuint256(fundingtxid);
|
||||
|
||||
opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'A' << fundingtxid << (uint8_t)0);
|
||||
|
||||
cp = CCinit(&C, EVAL_HEIR);
|
||||
return(FinalizeCCTx(0, cp, mtx, myPubkey, txfee, opret));
|
||||
}
|
||||
|
||||
extern bool komodo_appendACscriptpub();
|
||||
|
||||
UniValue test_heirmarker(const UniValue& params, bool fHelp)
|
||||
{
|
||||
//make fake token tx:
|
||||
struct CCcontract_info *cp, C;
|
||||
|
||||
if (fHelp || (params.size() != 1))
|
||||
throw runtime_error("incorrect params\n");
|
||||
if (ensure_CCrequirements(EVAL_HEIR) < 0)
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
|
||||
uint256 fundingtxid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
|
||||
CPubKey myPubkey = pubkey2pk(Mypubkey());
|
||||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
|
||||
|
||||
int64_t normalInputs = AddNormalinputs(mtx, myPubkey, 10000, 60);
|
||||
if (normalInputs < 10000)
|
||||
throw runtime_error("not enough normals\n");
|
||||
|
||||
mtx.vin.push_back(CTxIn(fundingtxid, 1));
|
||||
mtx.vout.push_back(MakeCC1vout(EVAL_HEIR, 10000, myPubkey));
|
||||
|
||||
CScript opret;
|
||||
fundingtxid = revuint256(fundingtxid);
|
||||
|
||||
opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'C' << fundingtxid << (uint8_t)0);
|
||||
|
||||
cp = CCinit(&C, EVAL_HEIR);
|
||||
return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, opret));
|
||||
}
|
||||
|
||||
UniValue opreturn_burn(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || (params.size() != 2))
|
||||
@@ -8077,95 +8036,3 @@ UniValue opreturn_burn(const UniValue& params, bool fHelp)
|
||||
ret.push_back(Pair("hex",FinalizeCCTx(0, cp, mtx, myPubkey, 10000, CScript())));
|
||||
return(ret);
|
||||
}
|
||||
|
||||
UniValue test_burntx(const UniValue& params, bool fHelp)
|
||||
{
|
||||
// make fake token tx:
|
||||
struct CCcontract_info *cp, C;
|
||||
|
||||
if (fHelp || (params.size() != 1))
|
||||
throw runtime_error("incorrect params\n");
|
||||
if (ensure_CCrequirements(EVAL_TOKENS) < 0)
|
||||
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
|
||||
|
||||
uint256 tokenid = Parseuint256((char *)params[0].get_str().c_str());
|
||||
|
||||
CPubKey myPubkey = pubkey2pk(Mypubkey());
|
||||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
|
||||
|
||||
int64_t normalInputs = AddNormalinputs(mtx, myPubkey, 10000, 60);
|
||||
if (normalInputs < 10000)
|
||||
throw runtime_error("not enough normals\n");
|
||||
|
||||
CPubKey burnpk = pubkey2pk(ParseHex(CC_BURNPUBKEY));
|
||||
|
||||
mtx.vin.push_back(CTxIn(tokenid, 0));
|
||||
mtx.vin.push_back(CTxIn(tokenid, 1));
|
||||
mtx.vout.push_back(MakeTokensCC1vout(EVAL_TOKENS, 1, burnpk));
|
||||
|
||||
std::vector<CPubKey> voutPubkeys;
|
||||
voutPubkeys.push_back(burnpk);
|
||||
|
||||
cp = CCinit(&C, EVAL_TOKENS);
|
||||
|
||||
std::vector<uint8_t> vopret;
|
||||
GetNonfungibleData(tokenid, vopret);
|
||||
if (vopret.size() > 0)
|
||||
cp->additionalTokensEvalcode2 = vopret.begin()[0];
|
||||
|
||||
uint8_t tokenpriv[33];
|
||||
char unspendableTokenAddr[64];
|
||||
CPubKey unspPk = GetUnspendable(cp, tokenpriv);
|
||||
GetCCaddress(cp, unspendableTokenAddr, unspPk);
|
||||
CCaddr2set(cp, EVAL_TOKENS, unspPk, tokenpriv, unspendableTokenAddr);
|
||||
return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, EncodeTokenOpRet(tokenid, voutPubkeys, std::make_pair(0, vscript_t()))));
|
||||
}
|
||||
|
||||
UniValue test_proof(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ);
|
||||
std::vector<uint8_t>proof;
|
||||
|
||||
if (fHelp || (params.size() != 2))
|
||||
throw runtime_error("incorrect params\n");
|
||||
|
||||
|
||||
proof = ParseHex(params[0].get_str());
|
||||
uint256 cointxid = Parseuint256((char *)params[1].get_str().c_str());
|
||||
|
||||
std::vector<uint256> txids;
|
||||
|
||||
CMerkleBlock merkleBlock;
|
||||
if (!E_UNMARSHAL(proof, ss >> merkleBlock)) {
|
||||
result.push_back(Pair("error", "could not unmarshal proof"));
|
||||
return result;
|
||||
}
|
||||
uint256 merkleRoot = merkleBlock.txn.ExtractMatches(txids);
|
||||
|
||||
result.push_back(Pair("source_root", merkleRoot.GetHex()));
|
||||
|
||||
for (int i = 0; i < txids.size(); i++)
|
||||
std::cerr << "merkle block txid=" << txids[0].GetHex() << std::endl;
|
||||
|
||||
|
||||
std::vector<bool> vMatches(txids.size());
|
||||
for (auto v : vMatches) v = true;
|
||||
CPartialMerkleTree verifTree(txids, vMatches);
|
||||
|
||||
result.push_back(Pair("verif_root", verifTree.ExtractMatches(txids).GetHex()));
|
||||
|
||||
if (std::find(txids.begin(), txids.end(), cointxid) == txids.end()) {
|
||||
fprintf(stderr, "invalid proof for this cointxid\n");
|
||||
}
|
||||
|
||||
std::vector<uint256> vMerkleTree;
|
||||
bool f;
|
||||
::BuildMerkleTree(&f, txids, vMerkleTree);
|
||||
|
||||
std::vector<uint256> vMerkleBranch = ::GetMerkleBranch(0, txids.size(), vMerkleTree);
|
||||
|
||||
uint256 ourResult = SafeCheckMerkleBranch(zeroid, vMerkleBranch, 0);
|
||||
result.push_back(Pair("SafeCheckMerkleBranch", ourResult.GetHex()));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user