Merge branch 'FSM' of https://github.com/jl777/komodo
This commit is contained in:
34
src/cc/Makefile
Normal file
34
src/cc/Makefile
Normal file
@@ -0,0 +1,34 @@
|
||||
SHELL = /bin/sh
|
||||
CC = gcc
|
||||
CC_DARWIN = g++-6
|
||||
CC_WIN = x86_64-w64-mingw32-gcc-posix
|
||||
CFLAGS_DARWIN = -std=c++11 -arch x86_64 -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -c -Wl,-undefined -Wl,dynamic_lookup -dynamiclib
|
||||
CFLAGS = -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c
|
||||
CFLAGS_WIN = -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c
|
||||
DEBUGFLAGS = -O0 -D _DEBUG
|
||||
RELEASEFLAGS = -O2 -D NDEBUG -combine -fwhole-program
|
||||
$(info $(OS))
|
||||
OS := $(shell uname -s)
|
||||
$(info $(OS))
|
||||
TARGET = ../libcc.so
|
||||
TARGET_DARWIN = ../libcc.dylib
|
||||
TARGET_WIN = ../libcc.dll
|
||||
SOURCES = cclib.cpp
|
||||
#HEADERS = $(shell echo ../cryptoconditions/include/*.h)
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(SOURCES)
|
||||
$(info Building cclib to src/)
|
||||
ifeq ($(OS),Darwin)
|
||||
$(CC_DARWIN) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET_DARWIN) $(SOURCES)
|
||||
else ifeq ($(OS),Linux)
|
||||
$(CC) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES)
|
||||
#else ifeq ($(WIN_HOST),True) - todo: pass ENV var from build.sh if WIN host
|
||||
else
|
||||
$(info WINDOWS)
|
||||
$(CC_WIN) $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) $(SOURCES)
|
||||
endif
|
||||
|
||||
clean:
|
||||
rm -rf $(TARGET)
|
||||
7
src/cc/README.md
Normal file
7
src/cc/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
## CCLIB
|
||||
Please follow the below instructions to build the cryptoconditions library into the Komodo source directory `komodo/src` - supported operating systems are Linux, OSX and Windows (mingw crossbuild):
|
||||
|
||||
```
|
||||
make clean
|
||||
make
|
||||
```
|
||||
@@ -20,18 +20,18 @@
|
||||
#include "cJSON.c"
|
||||
|
||||
/*
|
||||
z_migrate: the purpose of z_migrate is to make converting of all sprout outputs into sapling. the usage would be for the user to specify a sapling address and call z_migrate zsaddr, until it returns that there is nothing left to be done.
|
||||
|
||||
its main functionality is quite similar to a z_mergetoaddress ANY_ZADDR -> onetime_taddr followed by a z_sendmany onetime_taddr -> zsaddr
|
||||
|
||||
since the z_mergetoaddress will take time, it would just queue up an async operation. When it starts, it should see if there are any onetime_taddr with 10000.0001 funds in it, that is a signal for it to do the sapling tx and it can just do that without async as it is fast enough, especially with a taddr input. Maybe it limits itself to one, or it does all possible taddr -> sapling as fast as it can. either is fine as it will be called over and over anyway.
|
||||
|
||||
It might be that there is nothing to do, but some operations are pending. in that case it would return such a status. as soon as the operation finishes, there would be more work to do.
|
||||
|
||||
the amount sent to the taddr, should be 10000.0001
|
||||
|
||||
The GUI or user would be expected to generate a sapling address and then call z_migrate saplingaddr in a loop, until it returns that it is all done. this loop should pause for 10 seconds or so, if z_migrate is just waiting for opid to complete.
|
||||
*/
|
||||
z_migrate: the purpose of z_migrate is to make converting of all sprout outputs into sapling. the usage would be for the user to specify a sapling address and call z_migrate zsaddr, until it returns that there is nothing left to be done.
|
||||
|
||||
its main functionality is quite similar to a z_mergetoaddress ANY_ZADDR -> onetime_taddr followed by a z_sendmany onetime_taddr -> zsaddr
|
||||
|
||||
since the z_mergetoaddress will take time, it would just queue up an async operation. When it starts, it should see if there are any onetime_taddr with 10000.0001 funds in it, that is a signal for it to do the sapling tx and it can just do that without async as it is fast enough, especially with a taddr input. Maybe it limits itself to one, or it does all possible taddr -> sapling as fast as it can. either is fine as it will be called over and over anyway.
|
||||
|
||||
It might be that there is nothing to do, but some operations are pending. in that case it would return such a status. as soon as the operation finishes, there would be more work to do.
|
||||
|
||||
the amount sent to the taddr, should be 10000.0001
|
||||
|
||||
The GUI or user would be expected to generate a sapling address and then call z_migrate saplingaddr in a loop, until it returns that it is all done. this loop should pause for 10 seconds or so, if z_migrate is just waiting for opid to complete.
|
||||
*/
|
||||
|
||||
bits256 zeroid;
|
||||
|
||||
@@ -331,7 +331,7 @@ cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char
|
||||
system(cmdstr);
|
||||
*retstrp = 0;
|
||||
if ( (jsonstr= filestr(&fsize,fname)) != 0 )
|
||||
{
|
||||
{
|
||||
jsonstr[strlen(jsonstr)-1]='\0';
|
||||
//fprintf(stderr,"%s -> jsonstr.(%s)\n",cmdstr,jsonstr);
|
||||
if ( (jsonstr[0] != '{' && jsonstr[0] != '[') || (retjson= cJSON_Parse(jsonstr)) == 0 )
|
||||
@@ -599,13 +599,13 @@ int32_t validateaddress(char *refcoin,char *acname,char *depositaddr, char* comp
|
||||
cJSON *retjson; char *retstr; int32_t res=0;
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"validateaddress",depositaddr,"","","")) != 0 )
|
||||
{
|
||||
if (is_cJSON_True(jobj(retjson,compare)) != 0 ) res=1;
|
||||
if (is_cJSON_True(jobj(retjson,compare)) != 0 ) res=1;
|
||||
free_json(retjson);
|
||||
}
|
||||
else if ( retstr != 0 )
|
||||
{
|
||||
fprintf(stderr,"validateaddress.(%s) %s error.(%s)\n",refcoin,acname,retstr);
|
||||
free(retstr);
|
||||
free(retstr);
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
@@ -649,21 +649,21 @@ int64_t z_getbalance(char *refcoin,char *acname,char *coinaddr)
|
||||
|
||||
int32_t z_exportkey(char *privkey,char *refcoin,char *acname,char *zaddr)
|
||||
{
|
||||
cJSON *retjson; char *retstr,cmpstr[64]; int64_t amount=0; int32_t retval = -1;
|
||||
cJSON *retjson; char *retstr,cmpstr[64]; int64_t amount=0;
|
||||
privkey[0] = 0;
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_exportkey",zaddr,"","","")) != 0 )
|
||||
{
|
||||
fprintf(stderr,"z_exportkey.(%s) %s returned json!\n",refcoin,acname);
|
||||
free_json(retjson);
|
||||
return(-1);
|
||||
}
|
||||
else if ( retstr != 0 )
|
||||
{
|
||||
//printf("retstr %s -> %.8f\n",retstr,dstr(amount));
|
||||
strcpy(privkey,retstr);
|
||||
free(retstr);
|
||||
retval = 0;
|
||||
return(0);
|
||||
}
|
||||
return(retval);
|
||||
}
|
||||
|
||||
int32_t getnewaddress(char *coinaddr,char *refcoin,char *acname)
|
||||
@@ -700,6 +700,23 @@ int32_t z_getnewaddress(char *coinaddr,char *refcoin,char *acname,char *typestr)
|
||||
return(retval);
|
||||
}
|
||||
|
||||
int32_t z_getnewaddress(char *coinaddr,char *refcoin,char *acname,char *typestr)
|
||||
{
|
||||
cJSON *retjson; char *retstr; int64_t amount=0;
|
||||
if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_getnewaddress",typestr,"","","")) != 0 )
|
||||
{
|
||||
fprintf(stderr,"z_getnewaddress.(%s) %s returned json!\n",refcoin,acname);
|
||||
free_json(retjson);
|
||||
return(-1);
|
||||
}
|
||||
else if ( retstr != 0 )
|
||||
{
|
||||
strcpy(coinaddr,retstr);
|
||||
free(retstr);
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
int64_t find_onetime_amount(char *coinstr,char *coinaddr)
|
||||
{
|
||||
cJSON *array,*item; int32_t i,n; char *addr; int64_t amount = 0;
|
||||
@@ -824,6 +841,39 @@ int32_t z_mergetoaddress(char *opidstr,char *coinstr,char *acname,char *destaddr
|
||||
return(retval);
|
||||
}
|
||||
|
||||
int32_t z_mergetoaddress(char *opidstr,char *coinstr,char *acname,char *destaddr)
|
||||
{
|
||||
cJSON *retjson; char *retstr,addr[128],*opstr; int32_t retval = -1;
|
||||
sprintf(addr,"[\\\"ANY_SPROUT\\\"]");
|
||||
//printf("z_sendmany from.(%s) -> %s\n",addr,destaddr);
|
||||
if ( (retjson= get_komodocli(coinstr,&retstr,acname,"z_mergetoaddress",addr,destaddr,"","")) != 0 )
|
||||
{
|
||||
/*{
|
||||
"remainingUTXOs": 0,
|
||||
"remainingTransparentValue": 0.00000000,
|
||||
"remainingNotes": 222,
|
||||
"remainingShieldedValue": 5413.39093055,
|
||||
"mergingUTXOs": 0,
|
||||
"mergingTransparentValue": 0.00000000,
|
||||
"mergingNotes": 10,
|
||||
"mergingShieldedValue": 822.47447172,
|
||||
"opid": "opid-f28f6261-4120-436c-aca5-859870a40a70"
|
||||
}*/
|
||||
if ( (opstr= jstr(retjson,"opid")) != 0 )
|
||||
strcpy(opidstr,opstr);
|
||||
retval = jint(retjson,"remainingNotes");
|
||||
fprintf(stderr,"%s\n",jprint(retjson,0));
|
||||
free_json(retjson);
|
||||
}
|
||||
else if ( retstr != 0 )
|
||||
{
|
||||
fprintf(stderr,"z_mergetoaddress.(%s) -> opid.(%s)\n",coinstr,retstr);
|
||||
strcpy(opidstr,retstr);
|
||||
free(retstr);
|
||||
}
|
||||
return(retval);
|
||||
}
|
||||
|
||||
int32_t empty_mempool(char *coinstr,char *acname)
|
||||
{
|
||||
cJSON *array; int32_t n;
|
||||
@@ -872,7 +922,7 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd
|
||||
if ( (vouts= jarray(&numarray,txobj,"vout")) != 0 )
|
||||
{
|
||||
for (i=0; i<numarray; i++)
|
||||
{
|
||||
{
|
||||
if ((vout = jitem(vouts,i)) !=0 && (sobj= jobj(vout,"scriptPubKey")) != 0 )
|
||||
{
|
||||
if ( (addresses= jarray(&n,sobj,"addresses")) != 0 )
|
||||
@@ -893,7 +943,7 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd
|
||||
}
|
||||
}
|
||||
// if (hasvout==1 && (vins=jarray(&numarray,txobj,"vin"))!=0)
|
||||
// {
|
||||
// {
|
||||
// for (int i=0;i<numarray;i++)
|
||||
// {
|
||||
// if ((vin=jitem(vins,i))!=0 && validateaddress(refcoin,acname,jstr(vin,"address"),"ismine")!=0)
|
||||
@@ -901,7 +951,7 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd
|
||||
// retval=1;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
free_json(txobj);
|
||||
}
|
||||
|
||||
@@ -496,7 +496,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height)
|
||||
else
|
||||
{
|
||||
result.push_back(Pair("result",(char *)"success"));
|
||||
result.push_back(Pair("rawtx",rawtx));
|
||||
result.push_back(Pair("hex",rawtx));
|
||||
return(result);
|
||||
}
|
||||
} else errorstr = (char *)"insufficient funds";
|
||||
@@ -600,7 +600,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid)
|
||||
mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk));
|
||||
rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,refmatures,currency),pubkeys);
|
||||
result.push_back(Pair("result",(char *)"success"));
|
||||
result.push_back(Pair("rawtx",rawtx));
|
||||
result.push_back(Pair("hex",rawtx));
|
||||
return(result);
|
||||
} else remaining -= inputsum;
|
||||
if ( mtx.vin.size() >= CC_MAXVINS - MARMARA_VINS )
|
||||
@@ -616,7 +616,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid)
|
||||
rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,refmatures,currency),pubkeys);
|
||||
result.push_back(Pair("result",(char *)"error"));
|
||||
result.push_back(Pair("error",(char *)"insufficient funds"));
|
||||
result.push_back(Pair("rawtx",rawtx));
|
||||
result.push_back(Pair("hex",rawtx));
|
||||
result.push_back(Pair("remaining",ValueFromAmount(remaining)));
|
||||
}
|
||||
else
|
||||
@@ -731,7 +731,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri
|
||||
else
|
||||
{
|
||||
result.push_back(Pair("result",(char *)"success"));
|
||||
result.push_back(Pair("rawtx",rawtx));
|
||||
result.push_back(Pair("hex",rawtx));
|
||||
result.push_back(Pair("funcid","R"));
|
||||
result.push_back(Pair("createtxid",createtxid.GetHex()));
|
||||
if ( batontxid != zeroid )
|
||||
@@ -787,7 +787,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a
|
||||
else
|
||||
{
|
||||
result.push_back(Pair("result",(char *)"success"));
|
||||
result.push_back(Pair("rawtx",rawtx));
|
||||
result.push_back(Pair("hex",rawtx));
|
||||
char str[2]; str[0] = funcid, str[1] = 0;
|
||||
result.push_back(Pair("funcid",str));
|
||||
result.push_back(Pair("createtxid",createtxid.GetHex()));
|
||||
@@ -1025,7 +1025,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *
|
||||
else
|
||||
{
|
||||
result.push_back(Pair("result",(char *)"success"));
|
||||
result.push_back(Pair("rawtx",rawtx));
|
||||
result.push_back(Pair("hex",rawtx));
|
||||
if ( totalpayout > 0 && total > totalpayout-txfee )
|
||||
{
|
||||
result.push_back(Pair("firstheight",firstheight));
|
||||
|
||||
Reference in New Issue
Block a user