Browse Source

Merge pull request #199 from jl777/dev

Dev
win-cross
jl777 8 years ago
committed by GitHub
parent
commit
3cb3e312a3
  1. 18
      basilisk/basilisk.c
  2. 9
      basilisk/basilisk.h
  3. 103
      basilisk/basilisk_DEX.c
  4. 4
      basilisk/basilisk_MSG.c
  5. 112
      basilisk/basilisk_swap.c
  6. 36
      basilisk/basilisk_tradebot.c
  7. 10
      basilisk/tradebots_liquidity.c
  8. 7
      iguana/dPoW.h
  9. 222
      iguana/dpow/dpow_network.c
  10. 27
      iguana/dpow/dpow_rpc.c
  11. 5
      iguana/iguana777.c
  12. 4
      iguana/iguana777.h
  13. 4
      iguana/iguana_chains.c
  14. 5
      iguana/iguana_notary.c
  15. 52
      iguana/iguana_payments.c
  16. 2
      iguana/iguana_rpc.c
  17. 22
      iguana/iguana_unspents.c
  18. 15
      iguana/main.c
  19. 5
      iguana/tests/dexcheckaddress
  20. 2
      iguana/tests/dexlistunspent
  21. 2
      iguana/tests/paxfiats
  22. 2
      iguana/tests/snapshot
  23. 7
      includes/iguana_apideclares.h

18
basilisk/basilisk.c

@ -1044,21 +1044,27 @@ HASH_ARRAY_STRING(basilisk,history,hash,vals,hexstr)
return(jprint(retjson,1)); return(jprint(retjson,1));
} }
ZERO_ARGS(passthru,paxfiats) INT_ARG(passthru,paxfiats,mask)
{ {
komodo_assetcoins(-1); if ( mask == 0 )
mask = -1;
komodo_assetcoins(-1,mask);
return(clonestr("{\"result\":\"success\"}")); return(clonestr("{\"result\":\"success\"}"));
} }
ZERO_ARGS(basilisk,paxfiats) INT_ARG(basilisk,paxfiats,mask)
{ {
komodo_assetcoins(0); if ( mask == 0 )
mask = -1;
komodo_assetcoins(0,mask);
return(clonestr("{\"result\":\"success\"}")); return(clonestr("{\"result\":\"success\"}"));
} }
ZERO_ARGS(iguana,paxfiats) INT_ARG(iguana,paxfiats,mask)
{ {
komodo_assetcoins(1); if ( mask == 0 )
mask = -1;
komodo_assetcoins(1,mask);
return(clonestr("{\"result\":\"success\"}")); return(clonestr("{\"result\":\"success\"}"));
} }
#include "../includes/iguana_apiundefs.h" #include "../includes/iguana_apiundefs.h"

9
basilisk/basilisk.h

@ -16,7 +16,7 @@
#ifndef H_BASILISK_H #ifndef H_BASILISK_H
#define H_BASILISK_H #define H_BASILISK_H
//#define BASILISK_DISABLESENDTX #define BASILISK_DISABLESENDTX
#define BASILISK_DISABLEWAITTX #define BASILISK_DISABLEWAITTX
#include "../iguana/iguana777.h" #include "../iguana/iguana777.h"
@ -25,8 +25,9 @@
#define BASILISK_MINFANOUT 8 #define BASILISK_MINFANOUT 8
#define BASILISK_MAXFANOUT 64 #define BASILISK_MAXFANOUT 64
#define BASILISK_DEFAULTDIFF 0x1effffff #define BASILISK_DEFAULTDIFF 0x1effffff
#define BASILISK_DEXDURATION 180 #define BASILISK_DEXDURATION 300
#define BASILISK_MSGDURATION 60 #define BASILISK_MSGDURATION 30
#define BASILISK_AUCTION_DURATION 5
#define BASILISK_MAXFUTUREBLOCK 60 #define BASILISK_MAXFUTUREBLOCK 60
#define BASILISK_HDROFFSET ((int32_t)(sizeof(bits256)+sizeof(struct iguana_msghdr)+sizeof(uint32_t))) #define BASILISK_HDROFFSET ((int32_t)(sizeof(bits256)+sizeof(struct iguana_msghdr)+sizeof(uint32_t)))
@ -140,5 +141,7 @@ int32_t basilisk_rwDEXquote(int32_t rwflag,uint8_t *serialized,struct basilisk_r
cJSON *basilisk_requestjson(struct basilisk_request *rp); cJSON *basilisk_requestjson(struct basilisk_request *rp);
int32_t basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t depositflag,int32_t genflag); int32_t basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t depositflag,int32_t genflag);
void basilisk_txlog(struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *rawtx,int32_t delay); void basilisk_txlog(struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *rawtx,int32_t delay);
int32_t basilisk_messagekey(uint8_t *key,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash);
cJSON *basilisk_unspents(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr);
#endif #endif

103
basilisk/basilisk_DEX.c

@ -126,7 +126,7 @@ int32_t basilisk_rwDEXquote(int32_t rwflag,uint8_t *serialized,struct basilisk_r
uint32_t basilisk_request_enqueue(struct supernet_info *myinfo,struct basilisk_request *rp) uint32_t basilisk_request_enqueue(struct supernet_info *myinfo,struct basilisk_request *rp)
{ {
uint8_t serialized[256]; int32_t len; struct queueitem *item; uint8_t serialized[256]; int32_t len; struct queueitem *item;
printf(" basilisk_request_enqueue\n"); //printf(" basilisk_request_enqueue\n");
len = basilisk_rwDEXquote(1,serialized+1,rp); len = basilisk_rwDEXquote(1,serialized+1,rp);
if ( (item= calloc(1,sizeof(*item) + len + 1)) != 0 ) if ( (item= calloc(1,sizeof(*item) + len + 1)) != 0 )
{ {
@ -135,7 +135,7 @@ uint32_t basilisk_request_enqueue(struct supernet_info *myinfo,struct basilisk_r
portable_mutex_lock(&myinfo->DEX_mutex); portable_mutex_lock(&myinfo->DEX_mutex);
DL_APPEND(myinfo->DEX_quotes,item); DL_APPEND(myinfo->DEX_quotes,item);
portable_mutex_unlock(&myinfo->DEX_mutex); portable_mutex_unlock(&myinfo->DEX_mutex);
printf("ENQUEUE.%u calc.%u\n",rp->requestid,basilisk_requestid(rp)); //printf("ENQUEUE.%u calc.%u\n",rp->requestid,basilisk_requestid(rp));
return(rp->requestid); return(rp->requestid);
} }
return(0); return(0);
@ -231,12 +231,26 @@ int32_t basilisk_request_create(struct basilisk_request *rp,cJSON *valsobj,bits2
char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *_rp,uint32_t statebits,int32_t optionduration) char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *_rp,uint32_t statebits,int32_t optionduration)
{ {
cJSON *retjson; struct basilisk_request *rp; cJSON *retjson; struct basilisk_request *rp=0; int32_t i;
if ( _rp->requestid == myinfo->lastdexrequestid )
{
//printf("filter duplicate r%u\n",_rp->requestid);
return(clonestr("{\"error\":\"filter duplicate requestid\"}"));
}
if ( (bits256_cmp(_rp->srchash,myinfo->myaddr.persistent) == 0 || bits256_cmp(_rp->desthash,myinfo->myaddr.persistent) == 0) ) if ( (bits256_cmp(_rp->srchash,myinfo->myaddr.persistent) == 0 || bits256_cmp(_rp->desthash,myinfo->myaddr.persistent) == 0) )
{
for (i=0; i<myinfo->numswaps; i++)
if ( myinfo->swaps[i]->I.req.requestid == _rp->requestid )
{
printf("basilisk_thread_start error trying to start requestid.%u which is already started\n",rp->requestid);
break;
}
if ( i == myinfo->numswaps )
{ {
rp = calloc(1,sizeof(*rp)); rp = calloc(1,sizeof(*rp));
*rp = *_rp; *rp = *_rp;
printf("START thread to complete %u/%u for (%s %.8f) <-> (%s %.8f) q.%u\n",rp->requestid,rp->quoteid,rp->src,dstr(rp->srcamount),rp->dest,dstr(rp->destamount),rp->quoteid); printf("START thread to complete %u/%u for (%s %.8f) <-> (%s %.8f) q.%u\n",rp->requestid,rp->quoteid,rp->src,dstr(rp->srcamount),rp->dest,dstr(rp->destamount),rp->quoteid);
myinfo->lastdexrequestid = rp->requestid;
if ( basilisk_thread_start(myinfo,rp,statebits,optionduration) != 0 ) if ( basilisk_thread_start(myinfo,rp,statebits,optionduration) != 0 )
{ {
basilisk_request_enqueue(myinfo,rp); basilisk_request_enqueue(myinfo,rp);
@ -244,6 +258,12 @@ char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *_rp,u
} }
else return(clonestr("{\"error\":\"couldnt atomic swap thread\"}")); else return(clonestr("{\"error\":\"couldnt atomic swap thread\"}"));
} }
else
{
printf("trying to start already pending swap.r%u\n",rp->requestid);
return(clonestr("{\"error\":\"cant start pending swap\"}"));
}
}
else if ( myinfo->IAMLP != 0 ) else if ( myinfo->IAMLP != 0 )
{ {
retjson = cJSON_CreateObject(); retjson = cJSON_CreateObject();
@ -255,7 +275,7 @@ char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *_rp,u
void basilisk_requests_poll(struct supernet_info *myinfo) void basilisk_requests_poll(struct supernet_info *myinfo)
{ {
static uint32_t lastpoll; static uint32_t lastpoll;
char *retstr; uint8_t data[32768],buf[4096]; cJSON *outerarray,*retjson; uint32_t msgid,crcs[2],crc,channel; int32_t datalen,i,n,numiters; struct basilisk_request issueR; double hwm = 0.; char *retstr; uint8_t data[32768]; cJSON *outerarray,*retjson; uint32_t msgid,channel; int32_t datalen,i,n; struct basilisk_request issueR; double hwm = 0.;
if ( time(NULL) < lastpoll+3 ) if ( time(NULL) < lastpoll+3 )
return; return;
lastpoll = (uint32_t)time(NULL); lastpoll = (uint32_t)time(NULL);
@ -292,11 +312,16 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
free(retstr);*/ free(retstr);*/
if ( bits256_cmp(myinfo->myaddr.persistent,issueR.srchash) == 0 ) // my request if ( bits256_cmp(myinfo->myaddr.persistent,issueR.srchash) == 0 ) // my request
{ {
if ( (retstr= InstantDEX_accept(myinfo,0,0,0,issueR.requestid,issueR.quoteid)) != 0 ) dex_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid)); // 60
dpow_nanomsg_update(myinfo);
dex_updateclient(myinfo);
if ( (retstr= basilisk_start(myinfo,&issueR,1,issueR.optionhours * 3600)) != 0 )
free(retstr);
/*if ( (retstr= InstantDEX_accept(myinfo,0,0,0,issueR.requestid,issueR.quoteid)) != 0 )
free(retstr); free(retstr);
printf("my req hwm %f -> %u\n",hwm,issueR.requestid); printf("my req hwm %f -> %u\n",hwm,issueR.requestid);
basilisk_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),60); basilisk_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),60);
numiters = 0; numiters = crc = 0;
while ( numiters < 10 && (crc= basilisk_crcsend(myinfo,0,buf,sizeof(buf),issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),crcs)) == 0 ) while ( numiters < 10 && (crc= basilisk_crcsend(myinfo,0,buf,sizeof(buf),issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),crcs)) == 0 )
{ {
printf("didnt get back what was sent\n"); printf("didnt get back what was sent\n");
@ -309,16 +334,21 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
printf("crc.%08x -> basilisk_starta\n",crc); printf("crc.%08x -> basilisk_starta\n",crc);
if ( (retstr= basilisk_start(myinfo,&issueR,1,issueR.optionhours * 3600)) != 0 ) if ( (retstr= basilisk_start(myinfo,&issueR,1,issueR.optionhours * 3600)) != 0 )
free(retstr); free(retstr);
} else printf("couldnt accept offer\n"); } // else printf("couldnt accept offer\n");*/
} }
else //if ( issueR.quoteid == 0 ) else if ( issueR.requestid != myinfo->lastdexrequestid )//if ( issueR.quoteid == 0 )
{ {
printf("other req hwm %f >>>>>>>>>>> send response (%llx -> %llx)\n",hwm,(long long)issueR.desthash.txid,(long long)issueR.srchash.txid);
issueR.quoteid = basilisk_quoteid(&issueR); issueR.quoteid = basilisk_quoteid(&issueR);
issueR.desthash = myinfo->myaddr.persistent; issueR.desthash = myinfo->myaddr.persistent;
datalen = basilisk_rwDEXquote(1,data,&issueR); datalen = basilisk_rwDEXquote(1,data,&issueR);
msgid = (uint32_t)time(NULL); msgid = (uint32_t)time(NULL);
crcs[0] = crcs[1] = 0; printf("other req hwm %f >>>>>>>>>>> send response (%llx -> %llx) last.%u r.%u quoteid.%u\n",hwm,(long long)issueR.desthash.txid,(long long)issueR.srchash.txid,myinfo->lastdexrequestid,issueR.requestid,issueR.quoteid);
dex_channelsend(myinfo,issueR.desthash,issueR.srchash,channel,msgid,data,datalen); //INSTANTDEX_LOCKTIME*2
dpow_nanomsg_update(myinfo);
dex_updateclient(myinfo);
if ( (retstr= basilisk_start(myinfo,&issueR,0,issueR.optionhours * 3600)) != 0 )
free(retstr);
/*crcs[0] = crcs[1] = 0;
numiters = 0; numiters = 0;
basilisk_channelsend(myinfo,issueR.desthash,issueR.srchash,channel,msgid,data,datalen,INSTANTDEX_LOCKTIME*2); basilisk_channelsend(myinfo,issueR.desthash,issueR.srchash,channel,msgid,data,datalen,INSTANTDEX_LOCKTIME*2);
while ( numiters < 10 && (crc= basilisk_crcsend(myinfo,0,buf,sizeof(buf),issueR.desthash,issueR.srchash,channel,msgid,data,datalen,crcs)) == 0 ) while ( numiters < 10 && (crc= basilisk_crcsend(myinfo,0,buf,sizeof(buf),issueR.desthash,issueR.srchash,channel,msgid,data,datalen,crcs)) == 0 )
@ -333,7 +363,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
printf("crc.%08x -> basilisk_start\n",crc); printf("crc.%08x -> basilisk_start\n",crc);
if ( (retstr= basilisk_start(myinfo,&issueR,0,issueR.optionhours * 3600)) != 0 ) if ( (retstr= basilisk_start(myinfo,&issueR,0,issueR.optionhours * 3600)) != 0 )
free(retstr); free(retstr);
} }*/
} //else printf("basilisk_requests_poll unexpected hwm issueR\n"); } //else printf("basilisk_requests_poll unexpected hwm issueR\n");
} }
} }
@ -502,36 +532,63 @@ THREE_STRINGS_AND_DOUBLE(tradebot,aveprice,comment,base,rel,basevolume)
ZERO_ARGS(InstantDEX,allcoins) ZERO_ARGS(InstantDEX,allcoins)
{ {
struct iguana_info *tmp; cJSON *notarychains,*basilisk,*virtual,*full,*retjson = cJSON_CreateObject(); struct iguana_info *tmp; cJSON *native,*notarychains,*basilisk,*virtual,*full,*retjson = cJSON_CreateObject();
full = cJSON_CreateArray(); full = cJSON_CreateArray();
native = cJSON_CreateArray();
basilisk = cJSON_CreateArray(); basilisk = cJSON_CreateArray();
virtual = cJSON_CreateArray(); virtual = cJSON_CreateArray();
notarychains = cJSON_CreateArray(); notarychains = cJSON_CreateArray();
HASH_ITER(hh,myinfo->allcoins,coin,tmp) HASH_ITER(hh,myinfo->allcoins,coin,tmp)
{ {
if ( coin->virtualchain != 0 ) if ( coin->FULLNODE < 0 )
jaddistr(virtual,coin->symbol); jaddistr(native,coin->symbol);
if ( coin->FULLNODE > 0 || coin->VALIDATENODE > 0 ) //else if ( coin->virtualchain != 0 )
// jaddistr(virtual,coin->symbol);
else if ( coin->FULLNODE > 0 )//|| coin->VALIDATENODE > 0 )
jaddistr(full,coin->symbol); jaddistr(full,coin->symbol);
else if ( coin->notarychain >= 0 ) //else if ( coin->notarychain >= 0 )
jaddistr(notarychains,coin->symbol); // jaddistr(notarychains,coin->symbol);
else jaddistr(basilisk,coin->symbol); else jaddistr(basilisk,coin->symbol);
} }
jadd(retjson,"native",native);
jadd(retjson,"basilisk",basilisk); jadd(retjson,"basilisk",basilisk);
jadd(retjson,"full",full); jadd(retjson,"full",full);
jadd(retjson,"virtual",virtual); //jadd(retjson,"virtual",virtual);
jadd(retjson,"notarychains",notarychains); //jadd(retjson,"notarychains",notarychains);
return(jprint(retjson,1)); return(jprint(retjson,1));
} }
cJSON *basilisk_unspents(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr)
{
cJSON *unspents=0,*array=0; char *retstr;
if ( coin->FULLNODE > 0 )
{
array = cJSON_CreateArray();
jaddistr(array,coinaddr);
unspents = iguana_listunspents(myinfo,coin,array,0,0,"");
free_json(array);
}
else if ( coin->FULLNODE == 0 )
{
if ( (retstr= _dex_listunspent(myinfo,coin->symbol,coinaddr)) != 0 )
{
unspents = cJSON_Parse(retstr);
free(retstr);
}
}
else unspents = dpow_listunspent(myinfo,coin,coinaddr);
return(unspents);
}
STRING_ARG(InstantDEX,available,source) STRING_ARG(InstantDEX,available,source)
{ {
uint64_t total = 0; int32_t i,n=0; cJSON *item,*unspents,*retjson = 0; uint64_t total = 0; int32_t i,n=0; char coinaddr[64]; cJSON *item,*unspents,*retjson = 0;
if ( source != 0 && source[0] != 0 && (coin= iguana_coinfind(source)) != 0 ) if ( source != 0 && source[0] != 0 && (coin= iguana_coinfind(source)) != 0 )
{ {
if ( myinfo->expiration != 0 ) if ( myinfo->expiration != 0 )
{ {
if ( (unspents= iguana_listunspents(myinfo,coin,0,0,0,remoteaddr)) != 0 ) bitcoin_address(coinaddr,coin->chain->pubtype,myinfo->persistent_pubkey33,33);
if ( (unspents= basilisk_unspents(myinfo,coin,coinaddr)) != 0 )
{ {
//printf("available.(%s)\n",jprint(unspents,0)); //printf("available.(%s)\n",jprint(unspents,0));
if ( (n= cJSON_GetArraySize(unspents)) > 0 ) if ( (n= cJSON_GetArraySize(unspents)) > 0 )
@ -539,10 +596,8 @@ STRING_ARG(InstantDEX,available,source)
for (i=0; i<n; i++) for (i=0; i<n; i++)
{ {
item = jitem(unspents,i); item = jitem(unspents,i);
//if ( jobj(item,"unspent") != 0 ) //if ( is_cJSON_True(jobj(item,"spendable")) != 0 )
{
total += jdouble(item,"amount") * SATOSHIDEN; total += jdouble(item,"amount") * SATOSHIDEN;
}
//printf("(%s) -> %.8f\n",jprint(item,0),dstr(total)); //printf("(%s) -> %.8f\n",jprint(item,0),dstr(total));
} }
} }

4
basilisk/basilisk_MSG.c

@ -329,7 +329,7 @@ int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 srchash,bits25
jaddnum(valsobj,"channel",channel); jaddnum(valsobj,"channel",channel);
if ( msgid == 0 ) if ( msgid == 0 )
msgid = (uint32_t)time(NULL); msgid = (uint32_t)time(NULL);
jaddnum(valsobj,"fanout",MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2)); jaddnum(valsobj,"fanout",1);//MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2));
jaddnum(valsobj,"msgid",msgid); jaddnum(valsobj,"msgid",msgid);
jaddnum(valsobj,"duration",duration); jaddnum(valsobj,"duration",duration);
jaddnum(valsobj,"timeout",1000); jaddnum(valsobj,"timeout",1000);
@ -380,7 +380,7 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 srchash,bits256
jaddnum(valsobj,"msgid",msgid); jaddnum(valsobj,"msgid",msgid);
jaddnum(valsobj,"width",width); jaddnum(valsobj,"width",width);
jaddnum(valsobj,"timeout",BASILISK_TIMEOUT); jaddnum(valsobj,"timeout",BASILISK_TIMEOUT);
jaddnum(valsobj,"fanout",MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); jaddnum(valsobj,"fanout",1);//MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1));
jaddnum(valsobj,"numrequired",1); jaddnum(valsobj,"numrequired",1);
jaddbits256(valsobj,"srchash",srchash); jaddbits256(valsobj,"srchash",srchash);
jaddbits256(valsobj,"desthash",desthash); jaddbits256(valsobj,"desthash",desthash);

112
basilisk/basilisk_swap.c

@ -658,6 +658,7 @@ int32_t basilisk_rawtx_return(struct supernet_info *myinfo,int32_t height,struct
{ {
if ( lockinputs != 0 ) if ( lockinputs != 0 )
{ {
//printf("lockinputs\n");
iguana_RTunspentslock(myinfo,rawtx->coin,vins); iguana_RTunspentslock(myinfo,rawtx->coin,vins);
if ( (n= cJSON_GetArraySize(vins)) != 0 ) if ( (n= cJSON_GetArraySize(vins)) != 0 )
{ {
@ -684,7 +685,7 @@ int32_t basilisk_rawtx_return(struct supernet_info *myinfo,int32_t height,struct
int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t iambob,int32_t lockinputs,struct basilisk_rawtx *rawtx,uint32_t locktime,uint8_t *script,int32_t scriptlen,int64_t txfee,int32_t minconf,int32_t delay) int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t iambob,int32_t lockinputs,struct basilisk_rawtx *rawtx,uint32_t locktime,uint8_t *script,int32_t scriptlen,int64_t txfee,int32_t minconf,int32_t delay)
{ {
char *retstr,scriptstr[1024]; uint32_t basilisktag; int32_t flag,i,n,retval = -1; cJSON *valsobj,*retarray=0; struct vin_info *V; char *retstr,scriptstr[1024],coinaddr[64]; uint32_t basilisktag; int32_t flag,i,n,retval = -1; cJSON *addresses,*valsobj,*retarray=0; struct vin_info *V;
//bitcoin_address(coinaddr,rawtx->coin->chain->pubtype,myinfo->persistent_pubkey33,33); //bitcoin_address(coinaddr,rawtx->coin->chain->pubtype,myinfo->persistent_pubkey33,33);
if ( rawtx->coin->changeaddr[0] == 0 ) if ( rawtx->coin->changeaddr[0] == 0 )
{ {
@ -703,6 +704,10 @@ int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,struct basilis
jaddnum(valsobj,"locktime",locktime); jaddnum(valsobj,"locktime",locktime);
jaddnum(valsobj,"timeout",30000); jaddnum(valsobj,"timeout",30000);
jaddnum(valsobj,"timestamp",swap->I.started+delay); jaddnum(valsobj,"timestamp",swap->I.started+delay);
addresses = cJSON_CreateArray();
bitcoin_address(coinaddr,rawtx->coin->chain->pubtype,myinfo->persistent_pubkey33,33);
jaddistr(addresses,coinaddr);
jadd(valsobj,"addresses",addresses);
rawtx->I.locktime = locktime; rawtx->I.locktime = locktime;
//printf("%s locktime.%u\n",rawtx->name,locktime); //printf("%s locktime.%u\n",rawtx->name,locktime);
V = calloc(256,sizeof(*V)); V = calloc(256,sizeof(*V));
@ -753,6 +758,8 @@ int32_t basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swa
{ {
for (i=0; i<3; i++) for (i=0; i<3; i++)
{ {
//if ( swap->bobpayment.txbytes != 0 && swap->bobpayment.I.spendlen != 0 )
// break;
basilisk_rawtx_gen("payment",myinfo,swap,1,1,&swap->bobpayment,swap->bobpayment.I.locktime,swap->bobpayment.spendscript,swap->bobpayment.I.spendlen,swap->bobpayment.coin->chain->txfee,1,0); basilisk_rawtx_gen("payment",myinfo,swap,1,1,&swap->bobpayment,swap->bobpayment.I.locktime,swap->bobpayment.spendscript,swap->bobpayment.I.spendlen,swap->bobpayment.coin->chain->txfee,1,0);
if ( swap->bobpayment.txbytes == 0 || swap->bobpayment.I.spendlen == 0 ) if ( swap->bobpayment.txbytes == 0 || swap->bobpayment.I.spendlen == 0 )
{ {
@ -770,18 +777,22 @@ int32_t basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swa
printf(" <- GENERATED BOB PAYMENT.%d\n",swap->bobpayment.I.datalen); printf(" <- GENERATED BOB PAYMENT.%d\n",swap->bobpayment.I.datalen);
iguana_unspents_mark(myinfo,swap->bobcoin,swap->bobpayment.vins); iguana_unspents_mark(myinfo,swap->bobcoin,swap->bobpayment.vins);
basilisk_bobpayment_reclaim(myinfo,swap,swap->I.callduration); basilisk_bobpayment_reclaim(myinfo,swap,swap->I.callduration);
printf("bobscripts set completed\n");
return(0); return(0);
} }
} }
} }
return(0);
} }
else else
{ {
swap->bobdeposit.I.spendlen = basilisk_bobscript(swap->bobdeposit.I.rmd160,swap->bobdeposit.redeemscript,&swap->bobdeposit.I.redeemlen,swap->bobdeposit.spendscript,0,&swap->bobdeposit.I.locktime,&swap->bobdeposit.I.secretstart,&swap->I,1); swap->bobdeposit.I.spendlen = basilisk_bobscript(swap->bobdeposit.I.rmd160,swap->bobdeposit.redeemscript,&swap->bobdeposit.I.redeemlen,swap->bobdeposit.spendscript,0,&swap->bobdeposit.I.locktime,&swap->bobdeposit.I.secretstart,&swap->I,1);
if ( genflag != 0 ) if ( genflag != 0 && (swap->bobdeposit.txbytes == 0 || swap->bobrefund.txbytes == 0) )
{ {
for (i=0; i<3; i++) for (i=0; i<3; i++)
{ {
//if ( swap->bobdeposit.txbytes != 0 && swap->bobdeposit.I.spendlen != 0 )
// break;
basilisk_rawtx_gen("deposit",myinfo,swap,1,1,&swap->bobdeposit,swap->bobdeposit.I.locktime,swap->bobdeposit.spendscript,swap->bobdeposit.I.spendlen,swap->bobdeposit.coin->chain->txfee,1,0); basilisk_rawtx_gen("deposit",myinfo,swap,1,1,&swap->bobdeposit,swap->bobdeposit.I.locktime,swap->bobdeposit.spendscript,swap->bobdeposit.I.spendlen,swap->bobdeposit.coin->chain->txfee,1,0);
if ( swap->bobdeposit.txbytes == 0 || swap->bobdeposit.I.spendlen == 0 ) if ( swap->bobdeposit.txbytes == 0 || swap->bobdeposit.I.spendlen == 0 )
{ {
@ -799,10 +810,12 @@ int32_t basilisk_bobscripts_set(struct supernet_info *myinfo,struct basilisk_swa
//printf("GENERATED BOB DEPOSIT\n"); //printf("GENERATED BOB DEPOSIT\n");
iguana_unspents_mark(myinfo,swap->bobcoin,swap->bobdeposit.vins); iguana_unspents_mark(myinfo,swap->bobcoin,swap->bobdeposit.vins);
basilisk_bobdeposit_refund(myinfo,swap,swap->I.putduration); basilisk_bobdeposit_refund(myinfo,swap,swap->I.putduration);
printf("bobscripts set completed\n");
return(0); return(0);
} }
} }
} }
return(0);
//for (i=0; i<swap->bobdeposit.redeemlen; i++) //for (i=0; i<swap->bobdeposit.redeemlen; i++)
// printf("%02x",swap->bobdeposit.redeemscript[i]); // printf("%02x",swap->bobdeposit.redeemscript[i]);
//printf(" <- bobdeposit.%d\n",i); //printf(" <- bobdeposit.%d\n",i);
@ -867,10 +880,10 @@ int32_t basilisk_swapget(struct supernet_info *myinfo,struct basilisk_swap *swap
uint32_t basilisk_swapsend(struct supernet_info *myinfo,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t datalen,uint32_t nextbits,uint32_t crcs[2]) uint32_t basilisk_swapsend(struct supernet_info *myinfo,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t datalen,uint32_t nextbits,uint32_t crcs[2])
{ {
//if ( (rand() % 10) == 0 ) //if ( (rand() % 10) == 0 )
basilisk_channelsend(myinfo,swap->I.myhash,swap->I.otherhash,swap->I.req.quoteid,msgbits,data,datalen,INSTANTDEX_LOCKTIME*2); // basilisk_channelsend(myinfo,swap->I.myhash,swap->I.otherhash,swap->I.req.quoteid,msgbits,data,datalen,INSTANTDEX_LOCKTIME*2);
if ( basilisk_crcsend(myinfo,0,swap->verifybuf,sizeof(swap->verifybuf),swap->I.myhash,swap->I.otherhash,swap->I.req.quoteid,msgbits,data,datalen,crcs) != 0 ) //if ( basilisk_crcsend(myinfo,0,swap->verifybuf,sizeof(swap->verifybuf),swap->I.myhash,swap->I.otherhash,swap->I.req.quoteid,msgbits,data,datalen,crcs) != 0 )
return(nextbits); //return(nextbits);
basilisk_channelsend(myinfo,swap->I.myhash,swap->I.otherhash,swap->I.req.quoteid,msgbits,data,datalen,INSTANTDEX_LOCKTIME*2); dex_channelsend(myinfo,swap->I.myhash,swap->I.otherhash,swap->I.req.quoteid,msgbits,data,datalen); //INSTANTDEX_LOCKTIME*2
return(0); return(0);
} }
@ -1016,8 +1029,8 @@ void basilisk_rawtx_setparms(char *name,struct supernet_info *myinfo,struct basi
if ( rawtx->I.vouttype <= 1 && rawtx->I.destaddr[0] != 0 ) if ( rawtx->I.vouttype <= 1 && rawtx->I.destaddr[0] != 0 )
{ {
rawtx->I.spendlen = bitcoin_standardspend(rawtx->spendscript,0,rawtx->I.rmd160); rawtx->I.spendlen = bitcoin_standardspend(rawtx->spendscript,0,rawtx->I.rmd160);
//printf("%s spendlen.%d %s <- %.8f\n",name,rawtx->spendlen,rawtx->destaddr,dstr(rawtx->amount)); printf("%s spendlen.%d %s <- %.8f\n",name,rawtx->I.spendlen,rawtx->I.destaddr,dstr(rawtx->I.amount));
} //else printf("%s vouttype.%d destaddr.(%s)\n",name,rawtx->vouttype,rawtx->destaddr); } else printf("%s vouttype.%d destaddr.(%s)\n",name,rawtx->I.vouttype,rawtx->I.destaddr);
} }
int32_t bitcoin_coinptrs(struct supernet_info *myinfo,struct iguana_info **bobcoinp,struct iguana_info **alicecoinp,char *src,char *dest,bits256 srchash,bits256 desthash) int32_t bitcoin_coinptrs(struct supernet_info *myinfo,struct iguana_info **bobcoinp,struct iguana_info **alicecoinp,char *src,char *dest,bits256 srchash,bits256 desthash)
@ -1026,16 +1039,27 @@ int32_t bitcoin_coinptrs(struct supernet_info *myinfo,struct iguana_info **bobco
if ( coin == 0 || iguana_coinfind(dest) == 0 ) if ( coin == 0 || iguana_coinfind(dest) == 0 )
return(0); return(0);
*bobcoinp = *alicecoinp = 0; *bobcoinp = *alicecoinp = 0;
if ( strcmp("BTC",src) == 0 || coin->notarychain >= 0 ) if ( strcmp("BTC",src) == 0 )
{
*bobcoinp = iguana_coinfind(src);
*alicecoinp = iguana_coinfind(dest);
}
else if ( strcmp("BTC",dest) == 0 )
{
*bobcoinp = iguana_coinfind(dest);
*alicecoinp = iguana_coinfind(src);
}
else if ( (coin= iguana_coinfind(src)) != 0 && coin->chain->havecltv != 0 )
{ {
*bobcoinp = iguana_coinfind(src); *bobcoinp = iguana_coinfind(src);
*alicecoinp = iguana_coinfind(dest); *alicecoinp = iguana_coinfind(dest);
} }
else //if ( strcmp("BTC",dest) == 0 ) else if ( (coin= iguana_coinfind(dest)) != 0 && coin->chain->havecltv != 0 )
{ {
*bobcoinp = iguana_coinfind(dest); *bobcoinp = iguana_coinfind(dest);
*alicecoinp = iguana_coinfind(src); *alicecoinp = iguana_coinfind(src);
} }
else return(0);
if ( bits256_cmp(myinfo->myaddr.persistent,srchash) == 0 ) if ( bits256_cmp(myinfo->myaddr.persistent,srchash) == 0 )
{ {
if ( strcmp(src,(*bobcoinp)->symbol) == 0 ) if ( strcmp(src,(*bobcoinp)->symbol) == 0 )
@ -1047,12 +1071,12 @@ int32_t bitcoin_coinptrs(struct supernet_info *myinfo,struct iguana_info **bobco
else if ( bits256_cmp(myinfo->myaddr.persistent,desthash) == 0 ) else if ( bits256_cmp(myinfo->myaddr.persistent,desthash) == 0 )
{ {
if ( strcmp(src,(*bobcoinp)->symbol) == 0 ) if ( strcmp(src,(*bobcoinp)->symbol) == 0 )
return(0);
else if ( strcmp(dest,(*alicecoinp)->symbol) == 0 )
return(-1); return(-1);
else return(1); else if ( strcmp(dest,(*alicecoinp)->symbol) == 0 )
return(1);
else return(0);
} }
return(-1); return(0);
} }
struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t optionduration) struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t optionduration)
@ -1100,13 +1124,13 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,struct basil
swap->I.bobsatoshis = swap->I.req.destamount; swap->I.bobsatoshis = swap->I.req.destamount;
swap->alicecoin = iguana_coinfind(swap->I.req.src); swap->alicecoin = iguana_coinfind(swap->I.req.src);
swap->I.alicesatoshis = swap->I.req.srcamount; swap->I.alicesatoshis = swap->I.req.srcamount;
} } else printf("neither coin handles ctlv %s %s\n",swap->I.req.src,swap->I.req.dest);
} } else printf("cant find src or dest coin.(%s %s)\n",swap->I.req.src,swap->I.req.dest);
} } else printf("cant find src coin.(%s)\n",swap->I.req.src);
} }
if ( swap->bobcoin == 0 || swap->alicecoin == 0 ) if ( swap->bobcoin == 0 || swap->alicecoin == 0 )
{ {
printf("missing BTC.%p or missing alicecoin.%p\n",swap->bobcoin,swap->alicecoin); printf("missing bobcoin.%p or missing alicecoin.%p src.%p dest.%p\n",swap->bobcoin,swap->alicecoin,iguana_coinfind(swap->I.req.src),iguana_coinfind(swap->I.req.dest));
free(swap); free(swap);
return(0); return(0);
} }
@ -1145,9 +1169,9 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,struct basil
printf("neither src nor dest error\n"); printf("neither src nor dest error\n");
return(0); return(0);
} }
if ( bitcoin_coinptrs(myinfo,&bobcoin,&alicecoin,swap->I.req.src,swap->I.req.dest,swap->I.req.srchash,swap->I.req.desthash) != swap->I.iambob ) if ( (bitcoin_coinptrs(myinfo,&bobcoin,&alicecoin,swap->I.req.src,swap->I.req.dest,swap->I.req.srchash,swap->I.req.desthash)+1)/2 != swap->I.iambob )
{ {
printf("iambob.%d != %d\n",swap->I.iambob,bitcoin_coinptrs(myinfo,&bobcoin,&alicecoin,swap->I.req.src,swap->I.req.dest,swap->I.req.srchash,swap->I.req.desthash)); printf("error iambob.%d != %d\n",swap->I.iambob,bitcoin_coinptrs(myinfo,&bobcoin,&alicecoin,swap->I.req.src,swap->I.req.dest,swap->I.req.srchash,swap->I.req.desthash));
return(0); return(0);
} }
if ( bits256_nonz(myinfo->persistent_priv) == 0 || (x= instantdex_pubkeyargs(myinfo,swap,2 + INSTANTDEX_DECKSIZE,myinfo->persistent_priv,swap->I.orderhash,0x02+swap->I.iambob)) != 2 + INSTANTDEX_DECKSIZE ) if ( bits256_nonz(myinfo->persistent_priv) == 0 || (x= instantdex_pubkeyargs(myinfo,swap,2 + INSTANTDEX_DECKSIZE,myinfo->persistent_priv,swap->I.orderhash,0x02+swap->I.iambob)) != 2 + INSTANTDEX_DECKSIZE )
@ -1339,7 +1363,7 @@ uint32_t basilisk_swapdata_rawtxsend(struct supernet_info *myinfo,struct basilis
uint8_t sendbuf[32768]; int32_t sendlen; uint8_t sendbuf[32768]; int32_t sendlen;
if ( basilisk_swapdata_rawtx(myinfo,swap,data,maxlen,rawtx) != 0 ) if ( basilisk_swapdata_rawtx(myinfo,swap,data,maxlen,rawtx) != 0 )
{ {
if ( bits256_nonz(rawtx->I.signedtxid) != 0 )//&& bits256_nonz(rawtx->actualtxid) == 0 ) if ( bits256_nonz(rawtx->I.signedtxid) != 0 && bits256_nonz(rawtx->I.actualtxid) == 0 )
{ {
char str[65],str2[65]; char str[65],str2[65];
rawtx->I.actualtxid = basilisk_swap_broadcast(rawtx->name,myinfo,swap,rawtx->coin,rawtx->txbytes,rawtx->I.datalen); rawtx->I.actualtxid = basilisk_swap_broadcast(rawtx->name,myinfo,swap,rawtx->coin,rawtx->txbytes,rawtx->I.datalen);
@ -1516,7 +1540,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap
} }
while ( retval == 0 && time(NULL) < swap->I.expiration ) // both sides have setup required data and paid txfee while ( retval == 0 && time(NULL) < swap->I.expiration ) // both sides have setup required data and paid txfee
{ {
if ( (rand() % 30) == 0 ) //if ( (rand() % 30) == 0 )
printf("E r%u/q%u swapstate.%x otherstate.%x\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits,swap->I.otherstatebits); printf("E r%u/q%u swapstate.%x otherstate.%x\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits,swap->I.otherstatebits);
if ( swap->I.iambob != 0 ) if ( swap->I.iambob != 0 )
{ {
@ -1711,7 +1735,8 @@ void basilisk_swaploop(void *_swap)
while ( (swap->I.statebits & (0x08|0x02)) != (0x08|0x02) && time(NULL) < expiration ) while ( (swap->I.statebits & (0x08|0x02)) != (0x08|0x02) && time(NULL) < expiration )
{ {
printf("A r%u/q%u swapstate.%x\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits); printf("A r%u/q%u swapstate.%x\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits);
basilisk_channelsend(myinfo,swap->I.req.srchash,swap->I.req.desthash,channel,0x4000000,(void *)&swap->I.req.requestid,sizeof(swap->I.req.requestid),60); //basilisk_channelsend(myinfo,swap->I.req.srchash,swap->I.req.desthash,channel,0x4000000,(void *)&swap->I.req.requestid,sizeof(swap->I.req.requestid),60);
dex_channelsend(myinfo,swap->I.req.srchash,swap->I.req.desthash,channel,0x4000000,(void *)&swap->I.req.requestid,sizeof(swap->I.req.requestid)); //,60);
basilisk_sendstate(myinfo,swap,data,maxlen); basilisk_sendstate(myinfo,swap,data,maxlen);
basilisk_sendpubkeys(myinfo,swap,data,maxlen); // send pubkeys basilisk_sendpubkeys(myinfo,swap,data,maxlen); // send pubkeys
if ( basilisk_checkdeck(myinfo,swap,data,maxlen) == 0) // check for other deck 0x02 if ( basilisk_checkdeck(myinfo,swap,data,maxlen) == 0) // check for other deck 0x02
@ -1720,8 +1745,8 @@ void basilisk_swaploop(void *_swap)
if ( (swap->I.statebits & (0x08|0x02)) == (0x08|0x02) ) if ( (swap->I.statebits & (0x08|0x02)) == (0x08|0x02) )
break; break;
sleep(1); sleep(1);
//dpow_nanomsg_update(myinfo); dpow_nanomsg_update(myinfo);
//dex_updateclient(myinfo); dex_updateclient(myinfo);
} }
while ( (swap->I.statebits & 0x20) == 0 && time(NULL) < expiration ) while ( (swap->I.statebits & 0x20) == 0 && time(NULL) < expiration )
{ {
@ -1735,19 +1760,22 @@ void basilisk_swaploop(void *_swap)
break; break;
} }
sleep(3 + (swap->I.iambob == 0)*1); sleep(3 + (swap->I.iambob == 0)*1);
//dpow_nanomsg_update(myinfo); dpow_nanomsg_update(myinfo);
//dex_updateclient(myinfo); dex_updateclient(myinfo);
} }
if ( time(NULL) >= expiration ) if ( time(NULL) >= expiration )
retval = -1; retval = -1;
myinfo->DEXactive = swap->I.expiration; myinfo->DEXactive = swap->I.expiration;
printf("C r%u/q%u swapstate.%x\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits); printf("C r%u/q%u swapstate.%x retval.%d\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits,retval);
while ( retval == 0 && (swap->I.statebits & 0x40) == 0 ) // send fee while ( retval == 0 && (swap->I.statebits & 0x40) == 0 ) // send fee
{ {
//dpow_nanomsg_update(myinfo); dpow_nanomsg_update(myinfo);
//dex_updateclient(myinfo); dex_updateclient(myinfo);
printf("sendstate.%x\n",swap->I.statebits);
basilisk_sendstate(myinfo,swap,data,maxlen); basilisk_sendstate(myinfo,swap,data,maxlen);
printf("swapget\n");
basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits); basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits);
printf("after swapget\n");
if ( swap->myfee.txbytes == 0 ) if ( swap->myfee.txbytes == 0 )
{ {
/*for (i=0; i<20; i++) /*for (i=0; i<20; i++)
@ -1783,9 +1811,11 @@ void basilisk_swaploop(void *_swap)
basilisk_txlog(myinfo,swap,0,-1); basilisk_txlog(myinfo,swap,0,-1);
if ( swap->I.iambob != 0 ) if ( swap->I.iambob != 0 )
{ {
printf("bobscripts set\n");
if ( basilisk_bobscripts_set(myinfo,swap,1,1) < 0 ) if ( basilisk_bobscripts_set(myinfo,swap,1,1) < 0 )
{ {
sleep(3); sleep(3);
printf("bobscripts set error\n");
continue; continue;
} }
} }
@ -1793,6 +1823,8 @@ void basilisk_swaploop(void *_swap)
{ {
for (i=0; i<3; i++) for (i=0; i<3; i++)
{ {
//if ( swap->alicepayment.txbytes != 0 && swap->alicepayment.I.spendlen != 0 )
// break;
basilisk_alicepayment(myinfo,swap,swap->alicepayment.coin,&swap->alicepayment,swap->I.pubAm,swap->I.pubBn); basilisk_alicepayment(myinfo,swap,swap->alicepayment.coin,&swap->alicepayment,swap->I.pubAm,swap->I.pubBn);
if ( swap->alicepayment.txbytes == 0 || swap->alicepayment.I.spendlen == 0 ) if ( swap->alicepayment.txbytes == 0 || swap->alicepayment.I.spendlen == 0 )
{ {
@ -1811,14 +1843,16 @@ void basilisk_swaploop(void *_swap)
} }
} }
} }
printf("generate fee\n");
if ( basilisk_rawtx_gen("myfee",myinfo,swap,swap->I.iambob,1,&swap->myfee,0,swap->myfee.spendscript,swap->myfee.I.spendlen,swap->myfee.coin->chain->txfee,1,0) == 0 ) if ( basilisk_rawtx_gen("myfee",myinfo,swap,swap->I.iambob,1,&swap->myfee,0,swap->myfee.spendscript,swap->myfee.I.spendlen,swap->myfee.coin->chain->txfee,1,0) == 0 )
{ {
printf("done generate fee\n");
swap->I.statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x80,data,maxlen,&swap->myfee,0x40); swap->I.statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x80,data,maxlen,&swap->myfee,0x40);
iguana_unspents_mark(myinfo,swap->I.iambob!=0?swap->bobcoin:swap->alicecoin,swap->myfee.vins); iguana_unspents_mark(myinfo,swap->I.iambob!=0?swap->bobcoin:swap->alicecoin,swap->myfee.vins);
basilisk_txlog(myinfo,swap,&swap->myfee,-1); basilisk_txlog(myinfo,swap,&swap->myfee,-1);
for (i=0; i<swap->myfee.I.spendlen; i++) for (i=0; i<swap->myfee.I.spendlen; i++)
printf("%02x",swap->myfee.txbytes[i]); printf("%02x",swap->myfee.txbytes[i]);
printf(" alice fee %p %x\n",swap->myfee.txbytes,swap->I.statebits); printf(" fee %p %x\n",swap->myfee.txbytes,swap->I.statebits);
swap->I.statebits |= 0x40; swap->I.statebits |= 0x40;
if ( swap->alicepayment.txbytes != 0 && swap->alicepayment.I.spendlen > 0 ) if ( swap->alicepayment.txbytes != 0 && swap->alicepayment.I.spendlen > 0 )
break; break;
@ -1837,8 +1871,8 @@ void basilisk_swaploop(void *_swap)
basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits); basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits);
if ( time(NULL) > swap->I.expiration ) if ( time(NULL) > swap->I.expiration )
break; break;
//dpow_nanomsg_update(myinfo); dpow_nanomsg_update(myinfo);
//dex_updateclient(myinfo); dex_updateclient(myinfo);
} }
printf("end of atomic swap\n"); printf("end of atomic swap\n");
if ( swap->I.iambob != 0 && swap->bobdeposit.txbytes != 0 ) if ( swap->I.iambob != 0 && swap->bobdeposit.txbytes != 0 )
@ -1865,7 +1899,6 @@ void basilisk_swaploop(void *_swap)
struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct basilisk_request *rp,uint32_t statebits,int32_t optionduration) struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct basilisk_request *rp,uint32_t statebits,int32_t optionduration)
{ {
int32_t i,m,n; uint32_t channel,starttime; cJSON *retarray,*item,*msgobj; struct basilisk_swap *swap = 0; int32_t i,m,n; uint32_t channel,starttime; cJSON *retarray,*item,*msgobj; struct basilisk_swap *swap = 0;
printf("basilisk_thread_start\n");
portable_mutex_lock(&myinfo->DEX_swapmutex); portable_mutex_lock(&myinfo->DEX_swapmutex);
for (i=0; i<myinfo->numswaps; i++) for (i=0; i<myinfo->numswaps; i++)
if ( myinfo->swaps[i]->I.req.requestid == rp->requestid ) if ( myinfo->swaps[i]->I.req.requestid == rp->requestid )
@ -1875,6 +1908,7 @@ struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct
} }
if ( i == myinfo->numswaps && i < sizeof(myinfo->swaps)/sizeof(*myinfo->swaps) ) if ( i == myinfo->numswaps && i < sizeof(myinfo->swaps)/sizeof(*myinfo->swaps) )
{ {
printf("basilisk_thread_start request.%u statebits.%d\n",rp->requestid,statebits);
swap = calloc(1,sizeof(*swap)); swap = calloc(1,sizeof(*swap));
vcalc_sha256(0,swap->I.orderhash.bytes,(uint8_t *)rp,sizeof(*rp)); vcalc_sha256(0,swap->I.orderhash.bytes,(uint8_t *)rp,sizeof(*rp));
swap->I.req = *rp; swap->I.req = *rp;
@ -1883,7 +1917,8 @@ struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct
if ( bitcoin_swapinit(myinfo,swap,optionduration) != 0 ) if ( bitcoin_swapinit(myinfo,swap,optionduration) != 0 )
{ {
starttime = (uint32_t)time(NULL); starttime = (uint32_t)time(NULL);
while ( statebits == 0 && m <= n/2 && time(NULL) < starttime+30 ) printf("statebits.%x m.%d n.%d\n",statebits,m,n);
while ( statebits == 0 && m <= n/2 && time(NULL) < starttime+BASILISK_MSGDURATION )
{ {
m = n = 0; m = n = 0;
dpow_nanomsg_update(myinfo); dpow_nanomsg_update(myinfo);
@ -1909,17 +1944,18 @@ struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct
} }
} else printf("no retarray\n"); } else printf("no retarray\n");
} }
if ( statebits != 0 || m > n/2 ) printf("LAUNCH check.%d m.%d\n",statebits,m);
if ( statebits != 0 || m > 0 )//n/2 )
{ {
//for (i=0; i<sizeof(swap->I.req); i++) //for (i=0; i<sizeof(swap->I.req); i++)
// fprintf(stderr,"%02x",((uint8_t *)&swap->I.req)[i]); // fprintf(stderr,"%02x",((uint8_t *)&swap->I.req)[i]);
//fprintf(stderr," M.%d N.%d launch.%d %d %p\n",m,n,myinfo->numswaps,(int32_t)(sizeof(myinfo->swaps)/sizeof(*myinfo->swaps)),&swap->I.req); fprintf(stderr," M.%d N.%d launch.%d %d %p\n",m,n,myinfo->numswaps,(int32_t)(sizeof(myinfo->swaps)/sizeof(*myinfo->swaps)),&swap->I.req);
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)basilisk_swaploop,(void *)swap) != 0 ) if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)basilisk_swaploop,(void *)swap) != 0 )
{ {
} }
myinfo->swaps[myinfo->numswaps++] = swap; myinfo->swaps[myinfo->numswaps++] = swap;
} else printf("%u/%u offer wasnt accepted\n",rp->requestid,rp->quoteid); } else printf("%u/%u offer wasnt accepted statebits.%d m.%d n.%d\n",rp->requestid,rp->quoteid,statebits,m,n);
} }
} }
portable_mutex_unlock(&myinfo->DEX_swapmutex); portable_mutex_unlock(&myinfo->DEX_swapmutex);

36
basilisk/basilisk_tradebot.c

@ -281,7 +281,6 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk
int32_t i,noquoteflag=0,havequoteflag=0,myrequest=0,maxi=-1; int64_t balance=0,destamount,minamount = 0,maxamount = 0; uint32_t pendingid=0; struct basilisk_swap *active; double metric = 0.; int32_t i,noquoteflag=0,havequoteflag=0,myrequest=0,maxi=-1; int64_t balance=0,destamount,minamount = 0,maxamount = 0; uint32_t pendingid=0; struct basilisk_swap *active; double metric = 0.;
memset(issueR,0,sizeof(*issueR)); memset(issueR,0,sizeof(*issueR));
minamount = list[0].minamount; minamount = list[0].minamount;
//bids and asks??
//printf("need to verify null quoteid is list[0] requestid.%u quoteid.%u\n",list[0].requestid,list[0].quoteid); //printf("need to verify null quoteid is list[0] requestid.%u quoteid.%u\n",list[0].requestid,list[0].quoteid);
if ( (active= basilisk_request_started(myinfo,list[0].requestid)) != 0 ) if ( (active= basilisk_request_started(myinfo,list[0].requestid)) != 0 )
{ {
@ -314,18 +313,26 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk
} else noquoteflag++; } else noquoteflag++;
} }
// MVP -> USD myrequest.0 pendingid.0 noquoteflag.1 havequoteflag.0 maxi.-1 0.00000000 // MVP -> USD myrequest.0 pendingid.0 noquoteflag.1 havequoteflag.0 maxi.-1 0.00000000
printf("%s -> %s myrequest.%d pendingid.%u noquoteflag.%d havequoteflag.%d maxi.%d %.8f\n",list[0].src,list[0].dest,myrequest,pendingid,noquoteflag,havequoteflag,maxi,dstr(maxamount)); double retvals[4],refprice=0.,profitmargin,aveprice,destvolume; cJSON *retjson; char *retstr;
double retvals[4],refprice,profitmargin,aveprice; cJSON *retjson; char *retstr; destvolume = dstr(maxamount);
if ( maxi >= 0 && myinfo->IAMLP != 0 && myrequest == 0 && pendingid == 0 && noquoteflag != 0 && (profitmargin= tradebot_liquidity_active(myinfo,&refprice,"DEX",list[maxi].src,list[maxi].dest,(double)maxamount/SATOSHIDEN)) > 0. ) if ( fabs(destvolume) < SMALLVAL )
{ {
printf("maxi.%d profitmargin %f\n",maxi,profitmargin); if ( (destvolume= dstr(minamount)) == 0 )
if ( (aveprice= instantdex_avehbla(myinfo,retvals,list[0].src,list[0].dest,1.3 * dstr(list[0].srcamount))) == 0. || refprice > aveprice ) {
aveprice = instantdex_avehbla(myinfo,retvals,list[0].src,list[0].dest,1.3 * dstr(list[0].srcamount));
destvolume = aveprice * dstr(list[0].srcamount);
}
}
printf("%s -> %s myrequest.%d pendingid.%u noquoteflag.%d havequoteflag.%d maxi.%d %.8f destvol %f\n",list[0].src,list[0].dest,myrequest,pendingid,noquoteflag,havequoteflag,maxi,dstr(maxamount),destvolume);
if ( myinfo->IAMLP != 0 && myrequest == 0 && pendingid == 0 && noquoteflag != 0 && ((profitmargin= tradebot_liquidity_active(myinfo,&refprice,"DEX",list[0].src,list[0].dest,destvolume)) > 0. || refprice != 0.) )
{
if ( profitmargin == 0 || (aveprice= instantdex_avehbla(myinfo,retvals,list[0].src,list[0].dest,1.3 * dstr(list[0].srcamount))) == 0. || refprice > aveprice )
aveprice = refprice; aveprice = refprice;
if ( fabs(aveprice) < SMALLVAL ) if ( fabs(aveprice) < SMALLVAL )
return(0); return(0);
printf("avebid %f bidvol %f, aveask %f askvol %f\n",retvals[0],retvals[1],retvals[2],retvals[3]); printf("avebid %f bidvol %f, aveask %f askvol %f\n",retvals[0],retvals[1],retvals[2],retvals[3]);
//retvals[0] = avebid, retvals[1] = bidvol, retvals[2] = aveask, retvals[3] = askvol; //retvals[0] = avebid, retvals[1] = bidvol, retvals[2] = aveask, retvals[3] = askvol;
destamount = (1.0 - profitmargin) * retvals[0] * list[0].srcamount; destamount = (1.0 - profitmargin) * aveprice * list[0].srcamount;
if ( (retstr= InstantDEX_available(myinfo,iguana_coinfind(list[0].dest),0,0,list[0].dest)) != 0 ) if ( (retstr= InstantDEX_available(myinfo,iguana_coinfind(list[0].dest),0,0,list[0].dest)) != 0 )
{ {
if ( (retjson= cJSON_Parse(retstr)) != 0 ) if ( (retjson= cJSON_Parse(retstr)) != 0 )
@ -345,17 +352,16 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk
issueR->destamount = destamount; issueR->destamount = destamount;
issueR->quotetime = (uint32_t)time(NULL); issueR->quotetime = (uint32_t)time(NULL);
issueR->profitmargin = (uint32_t)(profitmargin * 1000000); issueR->profitmargin = (uint32_t)(profitmargin * 1000000);
printf("issueR set!\n");
} }
} }
else if ( myrequest != 0 && pendingid == 0 && maxi >= 0 ) // automatch best quote else if ( myrequest != 0 && pendingid == 0 && maxi >= 0 ) // automatch best quote
{ {
if ( minamount != 0 && maxamount > minamount && time(NULL) > BASILISK_DEXDURATION/2 ) if ( minamount != 0 && maxamount >= minamount && time(NULL) > list[0].timestamp+BASILISK_AUCTION_DURATION )
{ {
*issueR = list[maxi]; *issueR = list[maxi];
for (i=0; i<sizeof(*issueR); i++) for (i=0; i<sizeof(*issueR); i++)
printf("%02x",((uint8_t *)issueR)[i]); printf("%02x",((uint8_t *)issueR)[i]);
printf(" automatch[%d] quoteid.%u triggered %.8f > %.8f\n",maxi,list[maxi].quoteid,dstr(maxamount),dstr(minamount)); printf(" automatch[%d] r.%u quoteid.%u triggered %.8f > %.8f\n",maxi,list[maxi].requestid,list[maxi].quoteid,dstr(maxamount),dstr(minamount));
if ( minamount > 0 ) if ( minamount > 0 )
metric = (dstr(maxamount) / dstr(minamount)) - 1.; metric = (dstr(maxamount) / dstr(minamount)) - 1.;
else metric = 1.; else metric = 1.;
@ -382,7 +388,7 @@ double basilisk_process_results(struct supernet_info *myinfo,struct basilisk_req
{ {
memset(&R,0,sizeof(R)); memset(&R,0,sizeof(R));
basilisk_rwDEXquote(0,hexdata,&R); basilisk_rwDEXquote(0,hexdata,&R);
printf("[%d].(%s)\n",i,jprint(basilisk_requestjson(&R),1)); //printf("[%d].(%s)\n",i,jprint(basilisk_requestjson(&R),1));
} }
} else basilisk_parsejson(&R,item); } else basilisk_parsejson(&R,item);
if ( nonz != 0 ) if ( nonz != 0 )
@ -414,10 +420,10 @@ double basilisk_process_results(struct supernet_info *myinfo,struct basilisk_req
if ( (metric= basilisk_request_listprocess(myinfo,&tmpR,list,m)) > hwm ) if ( (metric= basilisk_request_listprocess(myinfo,&tmpR,list,m)) > hwm )
{ {
*issueR = tmpR, hwm = metric; *issueR = tmpR, hwm = metric;
printf("set hwm\n"); //printf("set hwm\n");
for (i=0; i<sizeof(*issueR); i++) //for (i=0; i<sizeof(*issueR); i++)
printf("%02x",((uint8_t *)issueR)[i]); // printf("%02x",((uint8_t *)issueR)[i]);
printf("\n"); //printf("\n");
} }
} }
return(hwm); return(hwm);

10
basilisk/tradebots_liquidity.c

@ -931,7 +931,7 @@ void _default_liquidity_command(struct supernet_info *myinfo,char *base,bits256
li.bid = jdouble(vals,"bid"); li.bid = jdouble(vals,"bid");
li.ask = jdouble(vals,"ask"); li.ask = jdouble(vals,"ask");
if ( (li.minvol= jdouble(vals,"minvol")) <= 0. ) if ( (li.minvol= jdouble(vals,"minvol")) <= 0. )
li.minvol = (strcmp("BTC",base) == 0) ? 0.0001 : 0.01; li.minvol = (strcmp("BTC",base) == 0) ? 0.0001 : 0.001;
if ( (li.maxvol= jdouble(vals,"maxvol")) < li.minvol ) if ( (li.maxvol= jdouble(vals,"maxvol")) < li.minvol )
li.maxvol = li.minvol; li.maxvol = li.minvol;
if ( (li.totalvol= jdouble(vals,"total")) < li.maxvol ) if ( (li.totalvol= jdouble(vals,"total")) < li.maxvol )
@ -991,16 +991,16 @@ void _default_liquidity_command(struct supernet_info *myinfo,char *base,bits256
int32_t _default_volume_ok(struct supernet_info *myinfo,struct liquidity_info *li,int32_t dir,double volume) int32_t _default_volume_ok(struct supernet_info *myinfo,struct liquidity_info *li,int32_t dir,double volume)
{ {
printf("minvol %f maxvol %f vs volume %f\n",li->minvol,li->maxvol,volume);
if ( (li->minvol == 0 || volume >= li->minvol) && (li->maxvol == 0 || volume <= li->maxvol) ) if ( (li->minvol == 0 || volume >= li->minvol) && (li->maxvol == 0 || volume <= li->maxvol) )
return(0); return(0);
else return(-1); else return(-1);
} }
double _default_liquidity_active(struct supernet_info *myinfo,double *refpricep,char *exchange,char *base,char *rel,double volume) double _default_liquidity_active(struct supernet_info *myinfo,double *refpricep,char *exchange,char *base,char *rel,double destvolume)
{ {
int32_t i,dir; struct liquidity_info refli; int32_t i,dir; struct liquidity_info refli;
*refpricep = 0.; *refpricep = 0.;
printf("_default_liquidity_active %s %s/%s\n",exchange,base,rel);
for (i=0; i<sizeof(myinfo->linfos)/sizeof(*myinfo->linfos); i++) for (i=0; i<sizeof(myinfo->linfos)/sizeof(*myinfo->linfos); i++)
{ {
refli = myinfo->linfos[i]; refli = myinfo->linfos[i];
@ -1016,8 +1016,7 @@ double _default_liquidity_active(struct supernet_info *myinfo,double *refpricep,
printf("continue %s %s/%s [%d] dir.%d vs %s %s/%s\n",exchange,base,rel,i,dir,refli.exchange,refli.base,refli.rel); printf("continue %s %s/%s [%d] dir.%d vs %s %s/%s\n",exchange,base,rel,i,dir,refli.exchange,refli.base,refli.rel);
continue; continue;
} }
printf(">>>>>>>> %s %s/%s [%d] dir.%d vs %s/%s\n",exchange,base,rel,i,dir,refli.base,refli.rel); if ( _default_volume_ok(myinfo,&refli,dir,destvolume) == 0 )
if ( _default_volume_ok(myinfo,&refli,dir,volume) == 0 )
{ {
if ( refli.profit != 0. ) if ( refli.profit != 0. )
*refpricep = refli.refprice; *refpricep = refli.refprice;
@ -1025,6 +1024,7 @@ double _default_liquidity_active(struct supernet_info *myinfo,double *refpricep,
*refpricep = refli.bid; *refpricep = refli.bid;
else if ( dir < 0 ) else if ( dir < 0 )
*refpricep = refli.ask; *refpricep = refli.ask;
printf(">>>>>>>> %s %s/%s [%d] dir.%d vs %s/%s -> %.8f margin %f\n",exchange,base,rel,i,dir,refli.base,refli.rel,*refpricep,refli.profit);
return(refli.profit); return(refli.profit);
} }
break; break;

7
iguana/dPoW.h

@ -45,7 +45,7 @@
#define DPOW_MAXRELAYS 64 #define DPOW_MAXRELAYS 64
#define DPOW_MAXSIGLEN 128 #define DPOW_MAXSIGLEN 128
#define DEX_VERSION 0x0103 #define DEX_VERSION 0x0104
#define DPOW_SOCK 7775 #define DPOW_SOCK 7775
#define DEX_SOCK 7774 #define DEX_SOCK 7774
#define PUB_SOCK 7773 #define PUB_SOCK 7773
@ -149,7 +149,7 @@ int32_t dpow_getchaintip(struct supernet_info *myinfo,bits256 *blockhashp,uint32
void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgbits,uint8_t *data,int32_t datalen); void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgbits,uint8_t *data,int32_t datalen);
int32_t dpow_nanomsg_update(struct supernet_info *myinfo); int32_t dpow_nanomsg_update(struct supernet_info *myinfo);
int32_t dpow_haveutxo(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,int32_t *voutp,char *coinaddr); int32_t dpow_haveutxo(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,int32_t *voutp,char *coinaddr);
void komodo_assetcoins(int32_t fullnode); void komodo_assetcoins(int32_t fullnode,uint64_t mask);
int32_t iguana_isnotarychain(char *symbol); int32_t iguana_isnotarychain(char *symbol);
cJSON *dpow_getinfo(struct supernet_info *myinfo,struct iguana_info *coin); cJSON *dpow_getinfo(struct supernet_info *myinfo,struct iguana_info *coin);
@ -181,5 +181,8 @@ char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol);
int32_t _dex_getheight(struct supernet_info *myinfo,char *symbol); int32_t _dex_getheight(struct supernet_info *myinfo,char *symbol);
char *_dex_getnotaries(struct supernet_info *myinfo,char *symbol); char *_dex_getnotaries(struct supernet_info *myinfo,char *symbol);
int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height); int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height);
cJSON *dpow_checkaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *address);
void dex_channelsend(struct supernet_info *myinfo,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen);
#endif #endif

222
iguana/dpow/dpow_network.c

@ -21,6 +21,86 @@ struct signed_nnpacket
uint8_t packet[]; uint8_t packet[];
} PACKED; } PACKED;
/*
NN_CONNECT to (tcp://167.114.118.5:7775)
NN_CONNECT to (tcp://10.0.0.4:7775)
NN_CONNECT to (tcp://85.143.211.6:7775)
NN_CONNECT to (tcp://158.69.25.7:7775)
NN_CONNECT to (tcp://123.249.79.12:7775)
NN_CONNECT to (tcp://141.105.66.18:7775)
NN_CONNECT to (tcp://198.27.75.27:7775)
NN_CONNECT to (tcp://198.204.226.34:7775)
NN_CONNECT to (tcp://144.76.94.38:7775)
NN_CONNECT to (tcp://142.54.174.42:7775)
NN_CONNECT to (tcp://88.198.70.43:7775)
NN_CONNECT to (tcp://182.162.169.44:7775)
NN_CONNECT to (tcp://104.168.128.50:7775)
NN_CONNECT to (tcp://167.114.64.64:7775)
NN_CONNECT to (tcp://185.169.229.64:7775)
NN_CONNECT to (tcp://46.4.68.72:7775)
NN_CONNECT to (tcp://173.208.203.74:7775)
NN_CONNECT to (tcp://192.99.232.81:7775)
NN_CONNECT to (tcp://149.56.28.84:7775)
NN_CONNECT to (tcp://148.251.190.89:7775)
NN_CONNECT to (tcp://149.56.240.91:7775)
NN_CONNECT to (tcp://88.99.56.99:7775)
NN_CONNECT to (tcp://217.106.238.109:7775)
NN_CONNECT to (tcp://142.54.164.114:7775)
NN_CONNECT to (tcp://163.172.101.118:7775)
NN_CONNECT to (tcp://189.1.174.119:7775)
NN_CONNECT to (tcp://1.234.19.123:7775)
NN_CONNECT to (tcp://221.121.144.138:7775)
NN_CONNECT to (tcp://46.166.168.138:7775)
NN_CONNECT to (tcp://221.121.144.140:7775)
NN_CONNECT to (tcp://163.172.100.144:7775)
NN_CONNECT to (tcp://185.106.122.147:7775)
NN_CONNECT to (tcp://103.18.58.150:7775)
NN_CONNECT to (tcp://23.88.234.153:7775)
NN_CONNECT to (tcp://164.132.202.176:7775)
NN_CONNECT to (tcp://178.63.85.196:7775)
NN_CONNECT to (tcp://69.12.77.197:7775)
NN_CONNECT to (tcp://192.157.238.198:7775)
NN_CONNECT to (tcp://209.58.183.199:7775)
NN_CONNECT to (tcp://149.202.65.200:7775)
NN_CONNECT to (tcp://27.100.36.201:7775)
NN_CONNECT to (tcp://173.208.184.202:7775)
NN_CONNECT to (tcp://94.102.63.208:7775)
NN_CONNECT to (tcp://5.9.109.208:7775)
NN_CONNECT to (tcp://94.102.63.209:7775)
NN_CONNECT to (tcp://197.189.248.210:7775)
NN_CONNECT to (tcp://149.56.19.212:7775)
NN_CONNECT to (tcp://46.165.243.214:7775)
NN_CONNECT to (tcp://45.64.168.216:7775)
NN_CONNECT to (tcp://94.102.63.217:7775)
NN_CONNECT to (tcp://192.99.233.217:7775)
NN_CONNECT to (tcp://27.50.68.219:7775)
NN_CONNECT to (tcp://167.114.227.223:7775)
NN_CONNECT to (tcp://94.102.63.227:7775)
NN_CONNECT to (tcp://176.9.0.233:7775)
NN_CONNECT to (tcp://27.50.93.252:7775)*/
void dex_init(struct supernet_info *myinfo)
{
int32_t i,j,mask = 0; char *seeds[] = { "78.47.196.146", "149.56.29.163", "191.235.80.138", "94.102.63.226", "129.232.225.202", "104.255.64.3", "52.72.135.200" };
OS_randombytes((void *)&i,sizeof(i));
srand(i);
for (i=0; i<sizeof(myinfo->dexseed_ipaddrs)/sizeof(*myinfo->dexseed_ipaddrs); i++)
{
while ( 1 )
{
j = i == 0 ? i : (rand() % (sizeof(seeds)/sizeof(*seeds)));
if ( ((1 << j) & mask) == 0 )
break;
}
mask |= (1 << j);
printf("seed.[%d] <- %s\n",i,seeds[j]);
strcpy(myinfo->dexseed_ipaddrs[i],seeds[j]);
myinfo->dexipbits[i] = (uint32_t)calc_ipbits(myinfo->dexseed_ipaddrs[i]);
}
myinfo->numdexipbits = i;
portable_mutex_init(&myinfo->dexmutex);
}
int32_t signed_nn_send(void *ctx,bits256 privkey,int32_t sock,void *packet,int32_t size) int32_t signed_nn_send(void *ctx,bits256 privkey,int32_t sock,void *packet,int32_t size)
{ {
int32_t i,j,sentbytes,siglen = 0; uint8_t sig[65],pubkey33[33],signpubkey33[33]; struct signed_nnpacket *sigpacket; int32_t i,j,sentbytes,siglen = 0; uint8_t sig[65],pubkey33[33],signpubkey33[33]; struct signed_nnpacket *sigpacket;
@ -73,7 +153,7 @@ int32_t signed_nn_recv(void **freeptrp,void *ctx,uint8_t notaries[64][33],int32_
{ {
//for (i=0; i<recvbytes; i++) //for (i=0; i<recvbytes; i++)
// printf("%02x",((uint8_t *)sigpacket)[i]); // printf("%02x",((uint8_t *)sigpacket)[i]);
//printf(" <- RECV.%d\n",recvbytes); //printf(" <- RECV.%d crc.%08x\n",recvbytes,calc_crc32(0,(void *)sigpacket,recvbytes));
} }
if ( sigpacket != 0 && recvbytes > sizeof(*sigpacket) && sigpacket->packetlen == recvbytes-sizeof(*sigpacket) ) if ( sigpacket != 0 && recvbytes > sizeof(*sigpacket) && sigpacket->packetlen == recvbytes-sizeof(*sigpacket) )
{ {
@ -151,14 +231,6 @@ int32_t dex_rwrequest(int32_t rwflag,uint8_t *serialized,struct dex_request *dex
return(len); return(len);
} }
void dex_init(struct supernet_info *myinfo)
{
strcpy(myinfo->dexseed_ipaddr,"78.47.196.146");
myinfo->dexipbits[0] = (uint32_t)calc_ipbits(myinfo->dexseed_ipaddr);
myinfo->numdexipbits = 1;
portable_mutex_init(&myinfo->dexmutex);
}
char *nanomsg_tcpname(struct supernet_info *myinfo,char *str,char *ipaddr,uint16_t port) char *nanomsg_tcpname(struct supernet_info *myinfo,char *str,char *ipaddr,uint16_t port)
{ {
if ( myinfo != 0 ) // bind path) if ( myinfo != 0 ) // bind path)
@ -188,7 +260,7 @@ void dex_packet(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp,int32_t
char *retstr; int32_t datalen; struct iguana_info *coin; struct dex_request dexreq; char *retstr; int32_t datalen; struct iguana_info *coin; struct dex_request dexreq;
//for (i=0; i<size; i++) //for (i=0; i<size; i++)
// printf("%02x",((uint8_t *)dexp)[i]); // printf("%02x",((uint8_t *)dexp)[i]);
printf(" uniq.%s DEX_PACKET.[%d] crc.%x lag.%d (%d %d)\n",dexp->handler,size,calc_crc32(0,dexp->packet,dexp->datalen),(int32_t)(time(NULL)-dexp->timestamp),dexp->size,dexp->datalen); //printf(" uniq.%s DEX_PACKET.[%d] crc.%x lag.%d (%d %d)\n",dexp->handler,size,calc_crc32(0,dexp->packet,dexp->datalen),(int32_t)(time(NULL)-dexp->timestamp),dexp->size,dexp->datalen);
if ( strcmp(dexp->handler,"DEX") == 0 && dexp->datalen > BASILISK_KEYSIZE ) if ( strcmp(dexp->handler,"DEX") == 0 && dexp->datalen > BASILISK_KEYSIZE )
{ {
if ( (retstr= basilisk_respond_addmessage(myinfo,dexp->packet,BASILISK_KEYSIZE,&dexp->packet[BASILISK_KEYSIZE],dexp->datalen-BASILISK_KEYSIZE,0,BASILISK_DEXDURATION)) != 0 ) if ( (retstr= basilisk_respond_addmessage(myinfo,dexp->packet,BASILISK_KEYSIZE,&dexp->packet[BASILISK_KEYSIZE],dexp->datalen-BASILISK_KEYSIZE,0,BASILISK_DEXDURATION)) != 0 )
@ -206,7 +278,7 @@ void dex_packet(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp,int32_t
} }
} }
char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32_t datalen) char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen)
{ {
struct dex_nanomsghdr *dexp; cJSON *retjson; char ipaddr[64],str[128]; int32_t timeout,i,n,size,recvbytes,sentbytes = 0,reqsock,subsock; uint32_t *retptr,ipbits; void *freeptr; char *retstr = 0; struct dex_nanomsghdr *dexp; cJSON *retjson; char ipaddr[64],str[128]; int32_t timeout,i,n,size,recvbytes,sentbytes = 0,reqsock,subsock; uint32_t *retptr,ipbits; void *freeptr; char *retstr = 0;
portable_mutex_lock(&myinfo->dexmutex); portable_mutex_lock(&myinfo->dexmutex);
@ -214,12 +286,14 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3
reqsock = myinfo->reqsock; reqsock = myinfo->reqsock;
if ( reqsock < 0 && (reqsock= nn_socket(AF_SP,NN_REQ)) >= 0 ) if ( reqsock < 0 && (reqsock= nn_socket(AF_SP,NN_REQ)) >= 0 )
{ {
if ( nn_connect(reqsock,nanomsg_tcpname(0,str,myinfo->dexseed_ipaddr,REP_SOCK)) < 0 ) for (i=0; i<sizeof(myinfo->dexseed_ipaddrs)/sizeof(*myinfo->dexseed_ipaddrs); i++)
if ( nn_connect(reqsock,nanomsg_tcpname(0,str,myinfo->dexseed_ipaddrs[i],REP_SOCK)) < 0 )
{ {
nn_close(reqsock); nn_close(reqsock);
reqsock = -1; reqsock = -1;
break;
} }
else if ( reqsock >= 0 )
{ {
timeout = 100; timeout = 100;
nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
@ -228,14 +302,16 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3
//nn_setsockopt(reqsock,NN_TCP,NN_RECONNECT_IVL,&timeout,sizeof(timeout)); //nn_setsockopt(reqsock,NN_TCP,NN_RECONNECT_IVL,&timeout,sizeof(timeout));
if ( myinfo->IAMNOTARY == 0 && subsock < 0 && (subsock= nn_socket(AF_SP,NN_SUB)) >= 0 ) if ( myinfo->IAMNOTARY == 0 && subsock < 0 && (subsock= nn_socket(AF_SP,NN_SUB)) >= 0 )
{ {
if ( nn_connect(subsock,nanomsg_tcpname(0,str,myinfo->dexseed_ipaddr,PUB_SOCK)) < 0 ) for (i=0; i<sizeof(myinfo->dexseed_ipaddrs)/sizeof(*myinfo->dexseed_ipaddrs); i++)
if ( nn_connect(subsock,nanomsg_tcpname(0,str,myinfo->dexseed_ipaddrs[i],PUB_SOCK)) < 0 )
{ {
nn_close(reqsock); nn_close(reqsock);
reqsock = -1; reqsock = -1;
nn_close(subsock); nn_close(subsock);
subsock = -1; subsock = -1;
break;
} }
else if ( reqsock >= 0 && subsock >= 0 )
{ {
timeout = 100; timeout = 100;
nn_setsockopt(subsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); nn_setsockopt(subsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
@ -252,16 +328,25 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3
portable_mutex_unlock(&myinfo->dexmutex); portable_mutex_unlock(&myinfo->dexmutex);
if ( myinfo->reqsock >= 0 ) if ( myinfo->reqsock >= 0 )
{ {
size = (int32_t)(sizeof(*dexp) + datalen); size = (int32_t)(sizeof(*dexp) + keylen + datalen);
dexp = calloc(1,size); // endian dependent! dexp = calloc(1,size); // endian dependent!
safecopy(dexp->handler,handler,sizeof(dexp->handler)); safecopy(dexp->handler,handler,sizeof(dexp->handler));
dexp->size = size; dexp->size = size;
dexp->datalen = datalen; dexp->datalen = datalen + keylen;
dexp->timestamp = (uint32_t)time(NULL); dexp->timestamp = (uint32_t)time(NULL);
dexp->version0 = DEX_VERSION & 0xff; dexp->version0 = DEX_VERSION & 0xff;
dexp->version1 = (DEX_VERSION >> 8) & 0xff; dexp->version1 = (DEX_VERSION >> 8) & 0xff;
if ( key != 0 && keylen != 0 )
{
memcpy(dexp->packet,key,keylen);
memcpy(&dexp->packet[keylen],data,datalen);
dexp->crc32 = calc_crc32(calc_crc32(0,key,keylen),data,datalen);
}
else
{
memcpy(dexp->packet,data,datalen); memcpy(dexp->packet,data,datalen);
dexp->crc32 = calc_crc32(0,data,datalen); dexp->crc32 = calc_crc32(0,data,datalen);
}
for (i=0; i<100; i++) for (i=0; i<100; i++)
{ {
struct nn_pollfd pfd; struct nn_pollfd pfd;
@ -270,7 +355,7 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3
if ( nn_poll(&pfd,1,100) > 0 ) if ( nn_poll(&pfd,1,100) > 0 )
{ {
sentbytes = nn_send(myinfo->reqsock,dexp,size,0); sentbytes = nn_send(myinfo->reqsock,dexp,size,0);
//printf(" sent.%d:%d datalen.%d\n",sentbytes,size,datalen); //printf(" sent.%d:%d datalen.%d crc.%08x\n",sentbytes,size,datalen,calc_crc32(0,(void *)dexp,size));
break; break;
} }
usleep(1000); usleep(1000);
@ -318,11 +403,14 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3
printf("%d: subscribe connect (%s)\n",myinfo->numdexipbits,str); printf("%d: subscribe connect (%s)\n",myinfo->numdexipbits,str);
} }
} }
if ( (rand() % 100) < 0 )
{
nanomsg_tcpname(0,str,ipaddr,REP_SOCK); nanomsg_tcpname(0,str,ipaddr,REP_SOCK);
//nn_connect(myinfo->reqsock,str); nn_connect(myinfo->reqsock,str);
printf("%d: req connect (%s)\n",myinfo->numdexipbits,str); printf("%d: req connect (%s)\n",myinfo->numdexipbits,str);
} }
} }
}
if ( freeptr != 0 ) if ( freeptr != 0 )
nn_freemsg(freeptr), freeptr = 0, retptr = 0; nn_freemsg(freeptr), freeptr = 0, retptr = 0;
portable_mutex_unlock(&myinfo->dexmutex); portable_mutex_unlock(&myinfo->dexmutex);
@ -330,7 +418,7 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3
else else
{ {
//retval = -2; //retval = -2;
//printf("no rep return? recvbytes.%d\n",recvbytes); printf("no rep return? recvbytes.%d\n",recvbytes);
} }
//printf("DEXREQ.[%d] crc32.%08x datalen.%d sent.%d recv.%d timestamp.%u\n",size,dexp->crc32,datalen,sentbytes,recvbytes,dexp->timestamp); //printf("DEXREQ.[%d] crc32.%08x datalen.%d sent.%d recv.%d timestamp.%u\n",size,dexp->crc32,datalen,sentbytes,recvbytes,dexp->timestamp);
free(dexp); free(dexp);
@ -338,6 +426,14 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3
return(retstr); return(retstr);
} }
void dex_channelsend(struct supernet_info *myinfo,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen)
{
int32_t keylen; uint8_t key[BASILISK_KEYSIZE]; char *retstr;
keylen = basilisk_messagekey(key,channel,msgid,srchash,desthash);
if ( (retstr= _dex_reqsend(myinfo,"DEX",key,keylen,data,datalen)) != 0 )
free(retstr);
}
void dpow_randipbits(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *retjson) void dpow_randipbits(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *retjson)
{ {
int32_t m; uint32_t ipbits; char *coinstr; int32_t m; uint32_t ipbits; char *coinstr;
@ -434,6 +530,14 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d
retstr = jprint(retjson,1); retstr = jprint(retjson,1);
} }
} }
else if ( dexreq.func == 'C' )
{
if ( (retjson= dpow_checkaddress(myinfo,coin,(char *)&dexp->packet[datalen])) != 0 )
{
dpow_randipbits(myinfo,coin,retjson);
retstr = jprint(retjson,1);
}
}
else if ( dexreq.func == 'A' ) else if ( dexreq.func == 'A' )
{ {
retstr = dpow_importaddress(myinfo,coin,(char *)&dexp->packet[datalen]); retstr = dpow_importaddress(myinfo,coin,(char *)&dexp->packet[datalen]);
@ -503,10 +607,11 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d
char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32_t datalen,int32_t M,char *field) char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32_t datalen,int32_t M,char *field)
{ {
char *retstrs[64],*origretstr0 = 0; cJSON *retjson; int32_t err,i,j,max = myinfo->numdexipbits; char *retstrs[64],*origretstr0 = 0; cJSON *retjson; int32_t err,i,j,max = myinfo->numdexipbits;
M = 1;
memset(retstrs,0,sizeof(retstrs)); memset(retstrs,0,sizeof(retstrs));
for (i=j=0; i<=max; i++) for (i=j=0; i<=max; i++)
{ {
if ( (retstrs[j]= _dex_reqsend(myinfo,handler,data,datalen)) != 0 ) if ( (retstrs[j]= _dex_reqsend(myinfo,handler,0,0,data,datalen)) != 0 )
{ {
//printf("j.%d of max.%d M.%d (%s)\n",j,max,M,retstrs[j]); //printf("j.%d of max.%d M.%d (%s)\n",j,max,M,retstrs[j]);
if ( strncmp(retstrs[j],"{\"error\":\"null return\"}",strlen("{\"error\":\"null return\"}")) != 0 && strncmp(retstrs[j],"[]",strlen("[]")) != 0 && strcmp("0",retstrs[j]) != 0 ) if ( strncmp(retstrs[j],"{\"error\":\"null return\"}",strlen("{\"error\":\"null return\"}")) != 0 && strncmp(retstrs[j],"[]",strlen("[]")) != 0 && strcmp("0",retstrs[j]) != 0 )
@ -568,13 +673,27 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32
} }
else else
{ {
#define DEX_LESSTHAN_RETSTR "{\"error\":\"less than required responses\"}"
for (i=0; i<j; i++) for (i=0; i<j; i++)
free(retstrs[i]); free(retstrs[i]);
retstrs[0] = clonestr("{\"error\":\"less than required responses\"}"); retstrs[0] = clonestr(DEX_LESSTHAN_RETSTR);
} }
return(retstrs[0]); return(retstrs[0]);
} }
char *_dex_arrayreturn(char *retstr)
{
if ( retstr != 0 )
{
if ( strcmp(retstr,DEX_LESSTHAN_RETSTR) == 0 )
{
free(retstr);
retstr = clonestr("[]");
}
}
return(retstr);
}
char *_dex_sendrequest(struct supernet_info *myinfo,struct dex_request *dexreq,int32_t M,char *field) char *_dex_sendrequest(struct supernet_info *myinfo,struct dex_request *dexreq,int32_t M,char *field)
{ {
uint8_t packet[sizeof(*dexreq)]; int32_t datalen; uint8_t packet[sizeof(*dexreq)]; int32_t datalen;
@ -649,12 +768,28 @@ int32_t _dex_getheight(struct supernet_info *myinfo,char *symbol)
char *_dex_getnotaries(struct supernet_info *myinfo,char *symbol) char *_dex_getnotaries(struct supernet_info *myinfo,char *symbol)
{ {
struct dex_request dexreq; struct dex_request dexreq; char *retstr,*pubkeystr; cJSON *retjson,*array,*item; int32_t i,n;
memset(&dexreq,0,sizeof(dexreq)); memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.func = 'N'; dexreq.func = 'N';
dexreq.intarg = -1; dexreq.intarg = -1;
return(_dex_sendrequest(myinfo,&dexreq,1,"")); if ( (retstr= _dex_sendrequest(myinfo,&dexreq,1,"")) != 0 )
{
if ( myinfo->numnotaries <= 0 && (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (myinfo->numnotaries= jint(retjson,"numnotaries")) != 0 && (array= jarray(&n,retjson,"notaries")) != 0 && n == myinfo->numnotaries )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
if ( (pubkeystr= jstr(item,"pubkey")) != 0 && strlen(pubkeystr) == 33*2 )
decode_hex(myinfo->notaries[i],33,pubkeystr);
}
}
free_json(retjson);
}
}
return(retstr);
} }
char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol) char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol)
@ -663,7 +798,7 @@ char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol)
memset(&dexreq,0,sizeof(dexreq)); memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.func = '*'; dexreq.func = '*';
return(_dex_sendrequest(myinfo,&dexreq,1,"")); return(_dex_arrayreturn(_dex_sendrequest(myinfo,&dexreq,1,"")));
} }
char *_dex_getblock(struct supernet_info *myinfo,char *symbol,bits256 hash2) char *_dex_getblock(struct supernet_info *myinfo,char *symbol,bits256 hash2)
@ -713,6 +848,15 @@ char *_dex_importaddress(struct supernet_info *myinfo,char *symbol,char *address
return(_dex_sendrequeststr(myinfo,&dexreq,address,1,"")); return(_dex_sendrequeststr(myinfo,&dexreq,address,1,""));
} }
char *_dex_checkaddress(struct supernet_info *myinfo,char *symbol,char *address)
{
struct dex_request dexreq;
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.func = 'C';
return(_dex_sendrequeststr(myinfo,&dexreq,address,3,"address"));
}
char *_dex_validateaddress(struct supernet_info *myinfo,char *symbol,char *address) char *_dex_validateaddress(struct supernet_info *myinfo,char *symbol,char *address)
{ {
struct dex_request dexreq; struct dex_request dexreq;
@ -728,7 +872,7 @@ char *_dex_listunspent(struct supernet_info *myinfo,char *symbol,char *address)
memset(&dexreq,0,sizeof(dexreq)); memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.func = 'U'; dexreq.func = 'U';
return(_dex_sendrequeststr(myinfo,&dexreq,address,1,"")); return(_dex_arrayreturn(_dex_sendrequeststr(myinfo,&dexreq,address,1,"")));
} }
char *_dex_listtransactions(struct supernet_info *myinfo,char *symbol,char *address,int32_t count,int32_t skip) char *_dex_listtransactions(struct supernet_info *myinfo,char *symbol,char *address,int32_t count,int32_t skip)
@ -739,7 +883,7 @@ char *_dex_listtransactions(struct supernet_info *myinfo,char *symbol,char *addr
dexreq.intarg = skip; dexreq.intarg = skip;
dexreq.shortarg = count; dexreq.shortarg = count;
dexreq.func = 'L'; dexreq.func = 'L';
return(_dex_sendrequeststr(myinfo,&dexreq,address,1,"")); return(_dex_arrayreturn(_dex_sendrequeststr(myinfo,&dexreq,address,1,"")));
} }
int32_t dex_crc32find(struct supernet_info *myinfo,uint32_t crc32) int32_t dex_crc32find(struct supernet_info *myinfo,uint32_t crc32)
@ -763,15 +907,16 @@ int32_t dex_crc32find(struct supernet_info *myinfo,uint32_t crc32)
int32_t dex_packetcheck(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp,int32_t size) int32_t dex_packetcheck(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp,int32_t size)
{ {
int32_t firstz; uint32_t crc32; int32_t firstz=-1; uint32_t crc32;
if ( dexp->version0 == (DEX_VERSION & 0xff) && dexp->version1 == ((DEX_VERSION >> 8) & 0xff) ) if ( dexp->version0 == (DEX_VERSION & 0xff) && dexp->version1 == ((DEX_VERSION >> 8) & 0xff) )
{ {
if ( dexp->datalen == (size - sizeof(*dexp)) ) if ( dexp->datalen == (size - sizeof(*dexp)) )
{ {
crc32 = calc_crc32(0,dexp->packet,dexp->datalen);//(void *)((long)dexp + sizeof(dexp->crc32)),(int32_t)(size - sizeof(dexp->crc32))); crc32 = calc_crc32(0,dexp->packet,dexp->datalen);//(void *)((long)dexp + sizeof(dexp->crc32)),(int32_t)(size - sizeof(dexp->crc32)));
if ( dexp->crc32 == crc32 && (firstz= dex_crc32find(myinfo,crc32)) >= 0 ) if ( dexp->crc32 == crc32 )//&& (firstz= dex_crc32find(myinfo,crc32)) >= 0 )
return(0); return(0);
} else printf("dexp %08x != %08x || firstz.%d < 0\n",dexp->crc32,crc32,firstz);
} else printf("datalen.%d != (%d - %ld)\n",dexp->datalen,size,sizeof(*dexp));
} }
return(-1); return(-1);
} }
@ -779,14 +924,15 @@ int32_t dex_packetcheck(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp
int32_t dex_subsock_poll(struct supernet_info *myinfo) int32_t dex_subsock_poll(struct supernet_info *myinfo)
{ {
int32_t size= -1; struct dex_nanomsghdr *dexp; void *freeptr; int32_t size= -1; struct dex_nanomsghdr *dexp; void *freeptr;
//fprintf(stderr,"subsock.%d\n",myinfo->subsock);
if ( myinfo->subsock >= 0 && (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->subsock,&dexp)) >= 0 ) if ( myinfo->subsock >= 0 && (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->subsock,&dexp)) >= 0 )
{ {
//printf("SUBSOCK.%08x recv.%d datalen.%d\n",dexp->crc32,size,dexp->datalen); if ( dexp != 0 )
if ( dexp != 0 && dex_packetcheck(myinfo,dexp,size) == 0 )
{ {
//printf("SUBSOCK.%08x ",dexp->crc32); //printf("SUBSOCK.%08x recv.%d datalen.%d\n",dexp->crc32,size,dexp->datalen);
if ( dex_packetcheck(myinfo,dexp,size) == 0 )
dex_packet(myinfo,dexp,size); dex_packet(myinfo,dexp,size);
} } //else printf("size.%d\n",size);
if ( freeptr != 0 ) if ( freeptr != 0 )
nn_freemsg(freeptr), dexp = 0, freeptr = 0; nn_freemsg(freeptr), dexp = 0, freeptr = 0;
} }
@ -1661,7 +1807,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo)
if ( (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) > 0 ) if ( (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) > 0 )
{ {
num++; num++;
//printf("REP got %d\n",size); //printf("REP got %d crc.%08x\n",size,calc_crc32(0,(void *)dexp,size));
if ( (retstr= dex_response(&broadcastflag,myinfo,dexp)) != 0 ) if ( (retstr= dex_response(&broadcastflag,myinfo,dexp)) != 0 )
{ {
signed_nn_send(myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,retstr,(int32_t)strlen(retstr)+1); signed_nn_send(myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,retstr,(int32_t)strlen(retstr)+1);
@ -1687,7 +1833,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo)
signed_nn_send(myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size); signed_nn_send(myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size);
//printf("REP.%08x -> dexbus and pub, t.%d lag.%d\n",dexp->crc32,dexp->timestamp,(int32_t)(time(NULL)-dexp->timestamp)); //printf("REP.%08x -> dexbus and pub, t.%d lag.%d\n",dexp->crc32,dexp->timestamp,(int32_t)(time(NULL)-dexp->timestamp));
dex_packet(myinfo,dexp,size); dex_packet(myinfo,dexp,size);
} } else printf("failed dexpacketcheck\n");
} }
//printf("GOT DEX rep PACKET.%d\n",size); //printf("GOT DEX rep PACKET.%d\n",size);
//if ( freeptr != 0 ) //if ( freeptr != 0 )
@ -1894,7 +2040,7 @@ uint16_t komodo_port(char *symbol,uint64_t supply,uint32_t *magicp)
#define MAX_CURRENCIES 32 #define MAX_CURRENCIES 32
extern char CURRENCIES[][8]; extern char CURRENCIES[][8];
void komodo_assetcoins(int32_t fullnode) void komodo_assetcoins(int32_t fullnode,uint64_t mask)
{ {
uint16_t extract_userpass(char *serverport,char *userpass,char *coinstr,char *userhome,char *coindir,char *confname); uint16_t extract_userpass(char *serverport,char *userpass,char *coinstr,char *userhome,char *coindir,char *confname);
int32_t i,j; uint32_t magic; cJSON *json; uint16_t port; long filesize; char *userhome,confstr[16],jsonstr[512],magicstr[9],path[512]; struct iguana_info *coin; int32_t i,j; uint32_t magic; cJSON *json; uint16_t port; long filesize; char *userhome,confstr[16],jsonstr[512],magicstr[9],path[512]; struct iguana_info *coin;
@ -1907,6 +2053,8 @@ void komodo_assetcoins(int32_t fullnode)
} }
for (i=0; i<MAX_CURRENCIES; i++) for (i=0; i<MAX_CURRENCIES; i++)
{ {
if ( ((1LL << i) & mask) == 0 )
continue;
port = komodo_port(CURRENCIES[i],10,&magic); port = komodo_port(CURRENCIES[i],10,&magic);
for (j=0; j<4; j++) for (j=0; j<4; j++)
sprintf(&magicstr[j*2],"%02x",((uint8_t *)&magic)[j]); sprintf(&magicstr[j*2],"%02x",((uint8_t *)&magic)[j]);

27
iguana/dpow/dpow_rpc.c

@ -475,6 +475,33 @@ void update_alladdresses(struct supernet_info *myinfo,struct iguana_info *coin,c
} }
} }
cJSON *dpow_checkaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *address)
{
int32_t isvalid=0,doneflag=0; char *retstr; cJSON *validatejson,*retjson = cJSON_CreateObject();
if ( (retstr= dpow_validateaddress(myinfo,coin,address)) != 0 )
{
if ( (validatejson= cJSON_Parse(retstr)) != 0 )
{
if ( (isvalid= is_cJSON_True(jobj(validatejson,"isvalid")) != 0) != 0 )
{
if ( is_cJSON_True(jobj(validatejson,"iswatchonly")) != 0 || is_cJSON_True(jobj(validatejson,"ismine")) != 0 )
doneflag = 1;
}
free_json(validatejson);
}
free(retstr);
retstr = 0;
}
if ( isvalid == 0 )
jaddstr(retjson,"error","invalid address");
else if ( doneflag != 0 )
{
jaddstr(retjson,"coin",coin->symbol);
jaddstr(retjson,"address",address);
}
return(retjson);
}
char *dpow_importaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *address) char *dpow_importaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *address)
{ {
char buf[1024],*retstr; cJSON *validatejson; int32_t isvalid=0,doneflag = 0; char buf[1024],*retstr; cJSON *validatejson; int32_t isvalid=0,doneflag = 0;

5
iguana/iguana777.c

@ -884,7 +884,9 @@ void iguana_coinloop(void *arg)
n = (int32_t)(long)coins[0]; n = (int32_t)(long)coins[0];
coins++; coins++;
coin = coins[0]; coin = coins[0];
printf("begin coinloop[%d] %s\n",n,coin->symbol); if ( (coin->notarychain= iguana_isnotarychain(coin->symbol)) >= 0 )
coin->VALIDATENODE = 0;
printf("begin coinloop[%d] %s notarychain.%d\n",n,coin->symbol,coin->notarychain);
memset(zero.bytes,0,sizeof(zero)); memset(zero.bytes,0,sizeof(zero));
while ( 1 ) while ( 1 )
{ {
@ -1126,6 +1128,7 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers,
coin->startPEND = coin->endPEND = 1; coin->startPEND = coin->endPEND = 1;
#endif #endif
} else coin->MAXPEERS = 0; } else coin->MAXPEERS = 0;
coin->notarychain = iguana_isnotarychain(coin->symbol);
coin->myservices = services; coin->myservices = services;
coin->initialheight = initialheight; coin->initialheight = initialheight;
coin->mapflags = mapflags; coin->mapflags = mapflags;

4
iguana/iguana777.h

@ -107,7 +107,7 @@ struct supernet_info
void (*liquidity_command)(struct supernet_info *myinfo,char *base,bits256 hash,cJSON *vals); void (*liquidity_command)(struct supernet_info *myinfo,char *base,bits256 hash,cJSON *vals);
double (*liquidity_active)(struct supernet_info *myinfo,double *refpricep,char *exchange,char *base,char *rel,double volume); double (*liquidity_active)(struct supernet_info *myinfo,double *refpricep,char *exchange,char *base,char *rel,double volume);
int32_t maxdelay,IAMRELAY,IAMNOTARY,IAMLP,publicRPC,basilisk_busy,genesisresults,remoteorigin; int32_t maxdelay,IAMRELAY,IAMNOTARY,IAMLP,publicRPC,basilisk_busy,genesisresults,remoteorigin;
uint32_t expiration,dirty,DEXactive,DEXpoll,totalcoins,nanoinit,dexcrcs[1024]; uint32_t expiration,dirty,DEXactive,DEXpoll,totalcoins,nanoinit,lastdexrequestid,dexcrcs[1024];
uint16_t argport,rpcport; uint16_t argport,rpcport;
struct basilisk_info basilisks; struct basilisk_info basilisks;
struct exchange_info *tradingexchanges[SUPERNET_MAXEXCHANGES]; int32_t numexchanges; struct exchange_info *tradingexchanges[SUPERNET_MAXEXCHANGES]; int32_t numexchanges;
@ -131,7 +131,7 @@ struct supernet_info
struct liquidity_info linfos[512]; struct liquidity_info linfos[512];
struct komodo_notaries NOTARY; struct komodo_notaries NOTARY;
char seedipaddr[64]; uint32_t dpowipbits[128]; int32_t numdpowipbits; portable_mutex_t notarymutex,dpowmutex; char seedipaddr[64]; uint32_t dpowipbits[128]; int32_t numdpowipbits; portable_mutex_t notarymutex,dpowmutex;
char dexseed_ipaddr[64]; uint32_t dexipbits[128]; int32_t numdexipbits; portable_mutex_t dexmutex; char dexseed_ipaddrs[1][64]; uint32_t dexipbits[128]; int32_t numdexipbits; portable_mutex_t dexmutex;
// compatibility // compatibility
bits256 pangea_category,instantdex_category; bits256 pangea_category,instantdex_category;
uint8_t logs[256],exps[510]; uint8_t logs[256],exps[510];

4
iguana/iguana_chains.c

@ -303,8 +303,6 @@ void iguana_chainparms(struct supernet_info *myinfo,struct iguana_chain *chain,c
chain->estblocktime = juint(argjson,"blocktime"); chain->estblocktime = juint(argjson,"blocktime");
if ( chain->estblocktime == 0 ) if ( chain->estblocktime == 0 )
chain->estblocktime = 60; chain->estblocktime = 60;
if ( chain->havecltv == 0 )
chain->havecltv = juint(argjson,"havecltv");
path = jstr(argjson,"path"); path = jstr(argjson,"path");
if ( jobj(argjson,"conf") == 0 ) if ( jobj(argjson,"conf") == 0 )
conf[0] = 0; conf[0] = 0;
@ -348,6 +346,8 @@ void iguana_chainparms(struct supernet_info *myinfo,struct iguana_chain *chain,c
chain->rpcport = 14632; chain->rpcport = 14632;
} }
chain->zcash = juint(argjson,"zcash"); chain->zcash = juint(argjson,"zcash");
if ( chain->havecltv == 0 )
chain->havecltv = juint(argjson,"havecltv") || chain->zcash;
chain->debug = juint(argjson,"debug"); chain->debug = juint(argjson,"debug");
chain->fixit = juint(argjson,"fixit"); chain->fixit = juint(argjson,"fixit");
if ( (chain->normal_txversion= juint(argjson,"normal_txversion")) == 0 ) if ( (chain->normal_txversion= juint(argjson,"normal_txversion")) == 0 )

5
iguana/iguana_notary.c

@ -643,6 +643,11 @@ TWO_STRINGS(dex,importaddress,symbol,address)
return(_dex_importaddress(myinfo,symbol,address)); return(_dex_importaddress(myinfo,symbol,address));
} }
TWO_STRINGS(dex,checkaddress,symbol,address)
{
return(_dex_checkaddress(myinfo,symbol,address));
}
TWO_STRINGS(dex,validateaddress,symbol,address) TWO_STRINGS(dex,validateaddress,symbol,address)
{ {
return(_dex_validateaddress(myinfo,symbol,address)); return(_dex_validateaddress(myinfo,symbol,address));

52
iguana/iguana_payments.c

@ -169,10 +169,13 @@ int32_t iguana_RTbestunspent(struct supernet_info *myinfo,struct iguana_info *co
for (above=below=i=0; i<numunspents; i++) for (above=below=i=0; i<numunspents; i++)
{ {
if ( (atx_value= unspents[i].value) <= 0 ) if ( (atx_value= unspents[i].value) <= 0 )
{
//printf("illegal value.%d\n",i);
continue; continue;
}
if ( iguana_RTunspent_check(myinfo,coin,unspents[i]) != 0 ) if ( iguana_RTunspent_check(myinfo,coin,unspents[i]) != 0 )
{ {
//printf("(%d u%d) %.8f already used\n",unspents[i].hdrsi,unspents[i].unspentind,dstr(atx_value)); printf("(%d u%d) %.8f already used\n",unspents[i].hdrsi,unspents[i].unspentind,dstr(atx_value));
continue; continue;
} }
if ( maxmode == 0 ) if ( maxmode == 0 )
@ -214,6 +217,7 @@ int32_t iguana_RTbestunspent(struct supernet_info *myinfo,struct iguana_info *co
*abovep = above; *abovep = above;
*belowip = belowi; *belowip = belowi;
*belowp = below; *belowp = below;
//printf("above.%d below.%d\n",abovei,belowi);
return(abovei >= 0 ? abovei : belowi); return(abovei >= 0 ? abovei : belowi);
} }
@ -295,7 +299,7 @@ bits256 iguana_sendrawtransaction(struct supernet_info *myinfo,struct iguana_inf
txid = bits256_doublesha256(0,&serialized[sizeof(struct iguana_msghdr)],len); txid = bits256_doublesha256(0,&serialized[sizeof(struct iguana_msghdr)],len);
if ( coin->FULLNODE < 0 || coin->notarychain >= 0 ) if ( coin->FULLNODE < 0 || coin->notarychain >= 0 )
{ {
if ( coin->FULLNODE < 0 || coin->notarychain >= 0 ) if ( coin->FULLNODE < 0 )
str = dpow_sendrawtransaction(myinfo,coin,signedtx); str = dpow_sendrawtransaction(myinfo,coin,signedtx);
else str = _dex_sendrawtransaction(myinfo,coin->symbol,signedtx); else str = _dex_sendrawtransaction(myinfo,coin->symbol,signedtx);
if ( str != 0 ) if ( str != 0 )
@ -337,7 +341,7 @@ bits256 iguana_sendrawtransaction(struct supernet_info *myinfo,struct iguana_inf
uint64_t iguana_interest(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t vout,uint64_t value) uint64_t iguana_interest(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t vout,uint64_t value)
{ {
char *retstr; int32_t height; cJSON *retjson; struct iguana_txid T,*tx; char *retstr; int32_t height; cJSON *retjson; struct iguana_txid T,*tx;
int32_t minutes; uint64_t numerator,denominator,interest = 0; int32_t minutes; uint64_t numerator=0,denominator=0,interest = 0;
if ( coin->FULLNODE < 0 ) // komodod is running if ( coin->FULLNODE < 0 ) // komodod is running
{ {
if ( (retjson= dpow_gettxout(myinfo,coin,txid,vout)) != 0 ) if ( (retjson= dpow_gettxout(myinfo,coin,txid,vout)) != 0 )
@ -372,7 +376,7 @@ uint64_t iguana_interest(struct supernet_info *myinfo,struct iguana_info *coin,b
numerator = (value / 20); // assumes 5%! numerator = (value / 20); // assumes 5%!
interest = (numerator / denominator); interest = (numerator / denominator);
} }
else else if ( value >= 10*SATOSHIDEN )
{ {
numerator = (value * KOMODO_INTEREST); numerator = (value * KOMODO_INTEREST);
interest = (numerator / denominator) / SATOSHIDEN; interest = (numerator / denominator) / SATOSHIDEN;
@ -403,16 +407,48 @@ uint64_t iguana_interests(struct supernet_info *myinfo,struct iguana_info *coin,
char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,cJSON *txobj,int64_t satoshis,char *changeaddr,int64_t txfee,cJSON *addresses,int32_t minconf,uint8_t *opreturn,int32_t oplen,int64_t burnamount,char *remoteaddr,struct vin_info *V,int32_t maxmode) char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,cJSON *txobj,int64_t satoshis,char *changeaddr,int64_t txfee,cJSON *addresses,int32_t minconf,uint8_t *opreturn,int32_t oplen,int64_t burnamount,char *remoteaddr,struct vin_info *V,int32_t maxmode)
{ {
uint8_t addrtype,rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE]; int32_t allocflag=0,max,num,spendlen; char *rawtx=0; bits256 txid; cJSON *vins=0; uint64_t avail,total,change; struct iguana_outpoint *unspents = 0; uint8_t addrtype,rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE]; char *coinaddr; int32_t allocflag=0,max,i,j,m,n,num,spendlen; char *spendscriptstr,*rawtx=0; bits256 txid; cJSON *vins=0,*array,*item; uint64_t value,avail=0,total,change; struct iguana_outpoint *unspents = 0;
*vinsp = 0; *vinsp = 0;
max = 10000; max = 0;//10000;
satoshis += burnamount; satoshis += burnamount;
unspents = calloc(max,sizeof(*unspents)); if ( (n= cJSON_GetArraySize(addresses)) == 0 )
return(0);
for (i=0; i<n; i++)
{
coinaddr = jstri(addresses,i);
if ( (array= basilisk_unspents(myinfo,coin,coinaddr)) != 0 )
{
//printf("unspents.(%s) %s\n",coinaddr,jprint(array,0));
if ( (m= cJSON_GetArraySize(array)) > 0 )
{
for (j=0; j<m; j++)
{
item = jitem(array,j);
if ( coin->FULLNODE != 0 && is_cJSON_False(jobj(item,"spendable")) != 0 )
continue;
if ( (spendscriptstr= jstr(item,"scriptPubKey")) == 0 )
{
printf("no spendscriptstr.(%s)\n",jprint(item,0));
continue;
}
unspents = realloc(unspents,(1 + max) * sizeof(*unspents));
value = jdouble(item,"amount") * SATOSHIDEN;
iguana_outptset(myinfo,coin,&unspents[max++],jbits256(item,"txid"),jint(item,"vout"),value,spendscriptstr);
avail += value;
}
}
free_json(array);
}
}
if ( unspents == 0 )
return(0);
num = max;
/*unspents = calloc(max,sizeof(*unspents));
if ( (num= iguana_RTunspentslists(myinfo,coin,&avail,unspents,max,satoshis+txfee,minconf,addresses,remoteaddr)) <= 0 ) if ( (num= iguana_RTunspentslists(myinfo,coin,&avail,unspents,max,satoshis+txfee,minconf,addresses,remoteaddr)) <= 0 )
{ {
free(unspents); free(unspents);
return(0); return(0);
} }*/
printf("avail %.8f satoshis %.8f, txfee %.8f burnamount %.8f vin0.scriptlen %d\n",dstr(avail),dstr(satoshis),dstr(txfee),dstr(burnamount),unspents[0].spendlen); printf("avail %.8f satoshis %.8f, txfee %.8f burnamount %.8f vin0.scriptlen %d\n",dstr(avail),dstr(satoshis),dstr(txfee),dstr(burnamount),unspents[0].spendlen);
if ( txobj != 0 && avail >= satoshis+txfee ) if ( txobj != 0 && avail >= satoshis+txfee )
{ {

2
iguana/iguana_rpc.c

@ -984,7 +984,7 @@ char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsiz
if ( (data= jstr(json,"POST")) == 0 || (argjson= cJSON_Parse(data)) == 0 ) if ( (data= jstr(json,"POST")) == 0 || (argjson= cJSON_Parse(data)) == 0 )
{ {
userpass = jstr(argjson,"userpass"); userpass = jstr(argjson,"userpass");
printf("userpass.(%s)\n",userpass); //printf("userpass.(%s)\n",userpass);
if ( (n= cJSON_GetArraySize(tokens)) > 0 ) if ( (n= cJSON_GetArraySize(tokens)) > 0 )
{ {
if ( n > 1 ) if ( n > 1 )

22
iguana/iguana_unspents.c

@ -128,13 +128,33 @@ int32_t iguana_unspentindfind(struct supernet_info *myinfo,struct iguana_info *c
char *iguana_RTinputaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,struct iguana_outpoint *spentp,cJSON *vinobj) char *iguana_RTinputaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,struct iguana_outpoint *spentp,cJSON *vinobj)
{ {
bits256 txid; int32_t vout,checkind,height; bits256 txid; int32_t vout,checkind,height,n; cJSON *txoutjson,*array; char *retstr,_coinaddr[64];
memset(spentp,0,sizeof(*spentp)); memset(spentp,0,sizeof(*spentp));
if ( coinaddr == 0 )
coinaddr = _coinaddr;
spentp->hdrsi = -1; spentp->hdrsi = -1;
//printf("%s RTinputaddress.(%s).%d %d\n",coin->symbol,jprint(vinobj,0),coin->FULLNODE,coin->notarychain);
if ( jobj(vinobj,"txid") != 0 && jobj(vinobj,"vout") != 0 ) if ( jobj(vinobj,"txid") != 0 && jobj(vinobj,"vout") != 0 )
{ {
txid = jbits256(vinobj,"txid"); txid = jbits256(vinobj,"txid");
vout = jint(vinobj,"vout"); vout = jint(vinobj,"vout");
if ( coin->FULLNODE == 0 && coin->notarychain >= 0 )
{
if ( (retstr= _dex_gettxout(myinfo,coin->symbol,txid,vout)) != 0 )
{
//printf("dexgetO.(%s)\n",retstr);
if ( (txoutjson= cJSON_Parse(retstr)) != 0 )
{
if ( (array= jarray(&n,txoutjson,"addresses")) != 0 )
safecopy(coinaddr,jstri(array,0),64);
spentp->value = jdouble(txoutjson,"value") * SATOSHIDEN;
free_json(txoutjson);
}
free(retstr);
return(coinaddr);
} else printf("dexgettxout null retstr\n");
return(0);
}
height = jint(vinobj,"height"); height = jint(vinobj,"height");
checkind = jint(vinobj,"checkind"); checkind = jint(vinobj,"checkind");
if ( (height != 0 && checkind != 0) || iguana_RTunspentindfind(myinfo,coin,spentp,coinaddr,0,0,0,&height,txid,vout,coin->bundlescount-1,0) == 0 ) if ( (height != 0 && checkind != 0) || iguana_RTunspentindfind(myinfo,coin,spentp,coinaddr,0,0,0,&height,txid,vout,coin->bundlescount-1,0) == 0 )

15
iguana/main.c

@ -1644,23 +1644,10 @@ void iguana_main(void *arg)
#ifdef __APPLE__ #ifdef __APPLE__
iguana_appletests(myinfo); iguana_appletests(myinfo);
#endif #endif
char *retstr,*pubkeystr; cJSON *retjson,*array,*item; int32_t i,n; char *retstr;
if ( (retstr= _dex_getnotaries(myinfo,"KMD")) != 0 ) if ( (retstr= _dex_getnotaries(myinfo,"KMD")) != 0 )
{ {
printf("INITIAL NOTARIES.(%s)\n",retstr); printf("INITIAL NOTARIES.(%s)\n",retstr);
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (myinfo->numnotaries= jint(retjson,"numnotaries")) != 0 && (array= jarray(&n,retjson,"notaries")) != 0 && n == myinfo->numnotaries )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
if ( (pubkeystr= jstr(item,"pubkey")) != 0 && strlen(pubkeystr) == 33*2 )
decode_hex(myinfo->notaries[i],33,pubkeystr);
}
}
free_json(retjson);
}
free(retstr); free(retstr);
} }
} }

5
iguana/tests/dexcheckaddress

@ -0,0 +1,5 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"checkaddress\",\"address\":\"RYHpUJFaB4QHUW8jCJCCNL2kzWq3D3QoyG\",\"symbol\":\"KMD\"}"
#curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"checkaddress\",\"address\":\"1Hgzt5xsnbfc8UTWqWKSTLRm5bEYHYBoCE\",\"symbol\":\"BTC\"}"
#curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"checkaddress\",\"address\":\"RRyBxbrAPRUBCUpiJgJZYrkxqrh8x5ta9Z\",\"symbol\":\"USD\"}"
#curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"checkaddress\",\"address\":\"RRyBxbrAPRUBCUpiJgJZYrkxqrh8x5ta9Z\",\"symbol\":\"MVP\"}"

2
iguana/tests/dexlistunspent

@ -1,2 +1,2 @@
#!/bin/bash #!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RRyBxbrAPRUBCUpiJgJZYrkxqrh8x5ta9Z\",\"symbol\":\"KMD\"}" curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RYHpUJFaB4QHUW8jCJCCNL2kzWq3D3QoyG\",\"symbol\":\"KMD\"}"

2
iguana/tests/paxfiats

@ -0,0 +1,2 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"basilisk\",\"method\":\"paxfiats\",\"mask\":$1}"

2
iguana/tests/snapshot

@ -1,3 +1,3 @@
#!/bin/bash #!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"snapshot\",\"height\":1486500,\"symbol\":\"BTCD\"}" curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"snapshot\",\"height\":1486000,\"symbol\":\"BTCD\"}"

7
includes/iguana_apideclares.h

@ -22,9 +22,9 @@ THREE_STRINGS(iguana,passthru,asset,function,hex);
STRING_ARG(dpow,bindaddr,ipaddr); STRING_ARG(dpow,bindaddr,ipaddr);
STRING_AND_INT(dpow,fundnotaries,symbol,numblocks); STRING_AND_INT(dpow,fundnotaries,symbol,numblocks);
ZERO_ARGS(dpow,notarychains); ZERO_ARGS(dpow,notarychains);
ZERO_ARGS(passthru,paxfiats); INT_ARG(passthru,paxfiats,mask);
ZERO_ARGS(basilisk,paxfiats); INT_ARG(basilisk,paxfiats,mask);
ZERO_ARGS(iguana,paxfiats); INT_ARG(iguana,paxfiats,mask);
STRING_AND_INT(iguana,snapshot,symbol,height); STRING_AND_INT(iguana,snapshot,symbol,height);
INT_ARRAY_STRING(iguana,dividends,height,vals,symbol); INT_ARRAY_STRING(iguana,dividends,height,vals,symbol);
@ -39,6 +39,7 @@ HASH_AND_STRING(dex,getblock,hash,symbol);
TWO_STRINGS(dex,sendrawtransaction,symbol,signedtx); TWO_STRINGS(dex,sendrawtransaction,symbol,signedtx);
HASH_AND_STRING_AND_INT(dex,gettxout,txid,symbol,vout); HASH_AND_STRING_AND_INT(dex,gettxout,txid,symbol,vout);
TWO_STRINGS(dex,importaddress,symbol,address); TWO_STRINGS(dex,importaddress,symbol,address);
TWO_STRINGS(dex,checkaddress,symbol,address);
TWO_STRINGS(dex,validateaddress,symbol,address); TWO_STRINGS(dex,validateaddress,symbol,address);
TWO_STRINGS(dex,listunspent,symbol,address); TWO_STRINGS(dex,listunspent,symbol,address);
TWO_STRINGS_AND_TWO_DOUBLES(dex,listtransactions,symbol,address,count,skip); TWO_STRINGS_AND_TWO_DOUBLES(dex,listtransactions,symbol,address,count,skip);

Loading…
Cancel
Save