Link in sudoku
This commit is contained in:
@@ -13,7 +13,7 @@ $(info $(OS))
|
|||||||
TARGET = ../libcc.so
|
TARGET = ../libcc.so
|
||||||
TARGET_DARWIN = ../libcc.dylib
|
TARGET_DARWIN = ../libcc.dylib
|
||||||
TARGET_WIN = ../libcc.dll
|
TARGET_WIN = ../libcc.dll
|
||||||
SOURCES = cclib.cpp
|
SOURCES = cclib.cpp sudoku.cpp
|
||||||
#HEADERS = $(shell echo ../cryptoconditions/include/*.h)
|
#HEADERS = $(shell echo ../cryptoconditions/include/*.h)
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|||||||
@@ -28,24 +28,63 @@
|
|||||||
#include "crosschain.h"
|
#include "crosschain.h"
|
||||||
|
|
||||||
#define FAUCET2SIZE COIN
|
#define FAUCET2SIZE COIN
|
||||||
|
#defein EVAL_FAUCET2 EVAL_FIRSTUSER
|
||||||
|
#define EVAL_SUDOKU 17
|
||||||
|
|
||||||
|
std::string MYCCLIBNAME = (char *)"sudoku";
|
||||||
|
char *CClib_name() { return((char *)MYCCLIBNAME.c_str()); }
|
||||||
|
|
||||||
struct CClib_rpcinfo
|
struct CClib_rpcinfo
|
||||||
{
|
{
|
||||||
char *method,*help;
|
char *CCname,*method,*help;
|
||||||
int32_t numrequiredargs,maxargs; // frontloaded with required
|
int32_t numrequiredargs,maxargs; // frontloaded with required
|
||||||
uint8_t funcid;
|
uint8_t funcid,evalcode;
|
||||||
}
|
}
|
||||||
CClib_methods[] =
|
CClib_methods[] =
|
||||||
{
|
{
|
||||||
{ (char *)"faucet2_fund", (char *)"amount", 1, 1, 'F' },
|
{ (char *)"faucet2", (char *)"fund", (char *)"amount", 1, 1, 'F', EVAL_FAUCET2 },
|
||||||
{ (char *)"faucet2_get", (char *)"<no args>", 0, 0, 'G' },
|
{ (char *)"faucet2", (char *)"get", (char *)"<no args>", 0, 0, 'G', EVAL_FAUCET2 },
|
||||||
|
{ (char *)"sudoku", (char *)"gen", (char *)"amount", 1, 1, 'G', EVAL_SUDOKU },
|
||||||
|
{ (char *)"sudoku", (char *)"txidinfo", (char *)"txid", 1, 1, 'T', EVAL_SUDOKU },
|
||||||
|
{ (char *)"sudoku", (char *)"pending", (char *)"<no args>", 0, 0, 'U', EVAL_SUDOKU },
|
||||||
|
{ (char *)"sudoku", (char *)"solution", (char *)"solution timestamps[]", 2, 2, 'S', EVAL_SUDOKU },
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string MYCCLIBNAME = (char *)"faucet2";
|
|
||||||
|
|
||||||
char *CClib_name() { return((char *)MYCCLIBNAME.c_str()); }
|
|
||||||
|
|
||||||
std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *params);
|
std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *params);
|
||||||
|
UniValue sudoku_txidinfo(struct CCcontract_info *cp,cJSON *params);
|
||||||
|
UniValue sudoku_generate(struct CCcontract_info *cp,cJSON *params);
|
||||||
|
UniValue sudoku_solution(struct CCcontract_info *cp,cJSON *params);
|
||||||
|
UniValue sudoku_pending(struct CCcontract_info *cp,cJSON *params);
|
||||||
|
|
||||||
|
UniValue CClib_method(struct CCcontract_info *cp,char *method,cJSON *params)
|
||||||
|
{
|
||||||
|
UniValue result(UniValue::VOBJ);
|
||||||
|
if ( cp->evalcode == EVAL_SUDOKU )
|
||||||
|
{
|
||||||
|
if ( strcmp(method,"txidinfo") == 0 )
|
||||||
|
return(sudoku_txidinfo(cp,params));
|
||||||
|
else if ( strcmp(method,"gen") == 0 )
|
||||||
|
return(sudoku_generate(cp,params));
|
||||||
|
else if ( strcmp(method,"solution") == 0 )
|
||||||
|
return(sudoku_solution(cp,params));
|
||||||
|
else if ( strcmp(method,"pending") == 0 )
|
||||||
|
return(sudoku_pending(cp,params));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.push_back(Pair("result","error"));
|
||||||
|
result.push_back(Pair("error","invalid sudoku method"));
|
||||||
|
result.push_back(Pair("method",method));
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.push_back(Pair("result","error"));
|
||||||
|
result.push_back(Pair("error","only sudoku supported for now"));
|
||||||
|
result.push_back(Pair("evalcode",(int)cp->evalcode));
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UniValue CClib_info(struct CCcontract_info *cp)
|
UniValue CClib_info(struct CCcontract_info *cp)
|
||||||
{
|
{
|
||||||
@@ -55,6 +94,7 @@ UniValue CClib_info(struct CCcontract_info *cp)
|
|||||||
for (i=0; i<sizeof(CClib_methods)/sizeof(*CClib_methods); i++)
|
for (i=0; i<sizeof(CClib_methods)/sizeof(*CClib_methods); i++)
|
||||||
{
|
{
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
|
obj.push_back(Pair("evalcode",CClib_methods[i].evalcode));
|
||||||
if ( CClib_methods[i].funcid < ' ' || CClib_methods[i].funcid >= 128 )
|
if ( CClib_methods[i].funcid < ' ' || CClib_methods[i].funcid >= 128 )
|
||||||
obj.push_back(Pair("funcid",CClib_methods[i].funcid));
|
obj.push_back(Pair("funcid",CClib_methods[i].funcid));
|
||||||
else
|
else
|
||||||
@@ -63,7 +103,8 @@ UniValue CClib_info(struct CCcontract_info *cp)
|
|||||||
str[1] = 0;
|
str[1] = 0;
|
||||||
obj.push_back(Pair("funcid",str));
|
obj.push_back(Pair("funcid",str));
|
||||||
}
|
}
|
||||||
obj.push_back(Pair("name",CClib_methods[i].method));
|
obj.push_back(Pair("name",CClib_methods[i].CCname));
|
||||||
|
obj.push_back(Pair("method",CClib_methods[i].method));
|
||||||
obj.push_back(Pair("help",CClib_methods[i].help));
|
obj.push_back(Pair("help",CClib_methods[i].help));
|
||||||
obj.push_back(Pair("params_required",CClib_methods[i].numrequiredargs));
|
obj.push_back(Pair("params_required",CClib_methods[i].numrequiredargs));
|
||||||
obj.push_back(Pair("params_max",CClib_methods[i].maxargs));
|
obj.push_back(Pair("params_max",CClib_methods[i].maxargs));
|
||||||
@@ -78,13 +119,16 @@ UniValue CClib(struct CCcontract_info *cp,char *method,cJSON *params)
|
|||||||
UniValue result(UniValue::VOBJ); int32_t i; std::string rawtx;
|
UniValue result(UniValue::VOBJ); int32_t i; std::string rawtx;
|
||||||
for (i=0; i<sizeof(CClib_methods)/sizeof(*CClib_methods); i++)
|
for (i=0; i<sizeof(CClib_methods)/sizeof(*CClib_methods); i++)
|
||||||
{
|
{
|
||||||
if ( strcmp(method,CClib_methods[i].method) == 0 )
|
if ( cp->evalcode == CClib_methods[i].evalcode && strcmp(method,CClib_methods[i].method) == 0 )
|
||||||
{
|
{
|
||||||
result.push_back(Pair("result","success"));
|
if ( cp->evalcode == EVAL_FAUCET2 )
|
||||||
result.push_back(Pair("method",CClib_methods[i].method));
|
{
|
||||||
rawtx = CClib_rawtxgen(cp,CClib_methods[i].funcid,params);
|
result.push_back(Pair("result","success"));
|
||||||
result.push_back(Pair("rawtx",rawtx));
|
result.push_back(Pair("method",CClib_methods[i].method));
|
||||||
return(result);
|
rawtx = CClib_rawtxgen(cp,CClib_methods[i].funcid,params);
|
||||||
|
result.push_back(Pair("rawtx",rawtx));
|
||||||
|
return(result);
|
||||||
|
} else return(CClib_method(cp,method,params));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.push_back(Pair("result","error"));
|
result.push_back(Pair("result","error"));
|
||||||
@@ -234,7 +278,6 @@ int64_t AddCClibInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK
|
|||||||
return(totalinputs);
|
return(totalinputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string Faucet2Fund(struct CCcontract_info *cp,uint64_t txfee,int64_t funds)
|
std::string Faucet2Fund(struct CCcontract_info *cp,uint64_t txfee,int64_t funds)
|
||||||
{
|
{
|
||||||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
|
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight());
|
||||||
@@ -289,14 +332,14 @@ std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *para
|
|||||||
if ( inputs > nValue )
|
if ( inputs > nValue )
|
||||||
CCchange = (inputs - nValue - txfee);
|
CCchange = (inputs - nValue - txfee);
|
||||||
if ( CCchange != 0 )
|
if ( CCchange != 0 )
|
||||||
mtx.vout.push_back(MakeCC1vout(EVAL_FIRSTUSER,CCchange,cclibpk));
|
mtx.vout.push_back(MakeCC1vout(EVAL_FAUCET2,CCchange,cclibpk));
|
||||||
mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
|
mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG));
|
||||||
fprintf(stderr,"start at %u\n",(uint32_t)time(NULL));
|
fprintf(stderr,"start at %u\n",(uint32_t)time(NULL));
|
||||||
j = rand() & 0xfffffff;
|
j = rand() & 0xfffffff;
|
||||||
for (i=0; i<1000000; i++,j++)
|
for (i=0; i<1000000; i++,j++)
|
||||||
{
|
{
|
||||||
tmpmtx = mtx;
|
tmpmtx = mtx;
|
||||||
rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_FIRSTUSER << (uint8_t)'G' << j));
|
rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_FAUCET2 << (uint8_t)'G' << j));
|
||||||
if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 )
|
if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 )
|
||||||
{
|
{
|
||||||
len >>= 1;
|
len >>= 1;
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
gcc -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o ../cclib.so cclib.cpp
|
gcc -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o ../cclib.so cclib.cpp sudoku.cpp
|
||||||
|
|||||||
@@ -474,3 +474,55 @@ void sudoku_gen(uint8_t key32[32],uint8_t unsolved[9][9],uint32_t srandi)
|
|||||||
sudoku_privkey(key32,vals9);
|
sudoku_privkey(key32,vals9);
|
||||||
sudoku_privkeydisp(key32);
|
sudoku_privkeydisp(key32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////// start of CClib interface
|
||||||
|
#include <assert.h>
|
||||||
|
#include <cryptoconditions.h>
|
||||||
|
|
||||||
|
#include "primitives/block.h"
|
||||||
|
#include "primitives/transaction.h"
|
||||||
|
#include "script/cc.h"
|
||||||
|
#include "cc/eval.h"
|
||||||
|
#include "cc/utils.h"
|
||||||
|
#include "cc/CCinclude.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include "chain.h"
|
||||||
|
#include "core_io.h"
|
||||||
|
#include "crosschain.h"
|
||||||
|
|
||||||
|
UniValue sudoku_txidinfo(struct CCcontract_info *cp,cJSON *params)
|
||||||
|
{
|
||||||
|
UniValue result(UniValue::VOBJ);
|
||||||
|
if ( params != 0 )
|
||||||
|
printf("params.(%s)\n",jprint(params,0));
|
||||||
|
result.push_back(Pair("result","success"));
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
UniValue sudoku_generate(struct CCcontract_info *cp,cJSON *params)
|
||||||
|
{
|
||||||
|
UniValue result(UniValue::VOBJ);
|
||||||
|
if ( params != 0 )
|
||||||
|
printf("params.(%s)\n",jprint(params,0));
|
||||||
|
result.push_back(Pair("result","success"));
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
UniValue sudoku_solution(struct CCcontract_info *cp,cJSON *params)
|
||||||
|
{
|
||||||
|
UniValue result(UniValue::VOBJ);
|
||||||
|
if ( params != 0 )
|
||||||
|
printf("params.(%s)\n",jprint(params,0));
|
||||||
|
result.push_back(Pair("result","success"));
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
UniValue sudoku_pending(struct CCcontract_info *cp,cJSON *params)
|
||||||
|
{
|
||||||
|
UniValue result(UniValue::VOBJ);
|
||||||
|
if ( params != 0 )
|
||||||
|
printf("params.(%s)\n",jprint(params,0));
|
||||||
|
result.push_back(Pair("result","success"));
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user