jl777 8 years ago
parent
commit
68080c63f6
  1. 2
      basilisk/basilisk.c
  2. 76
      basilisk/basilisk_DEX.c
  3. 28
      basilisk/basilisk_MSG.c
  4. 5
      basilisk/basilisk_swap.c
  5. 15
      iguana/iguana_payments.c
  6. 1
      includes/iguana_funcs.h

2
basilisk/basilisk.c

@ -837,7 +837,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
issueR.quoteid = basilisk_quoteid(&issueR);
issueR.desthash = myinfo->myaddr.persistent;
datalen = basilisk_rwDEXquote(1,data,&issueR);
basilisk_channelsend(myinfo,issueR.desthash,'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16),(uint32_t)time(NULL),data,datalen,0);
basilisk_channelsend(myinfo,issueR.srchash,issueR.desthash,'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16),(uint32_t)time(NULL),data,datalen,0);
if ( (retstr= basilisk_start(myinfo,&issueR,0)) != 0 )
free(retstr);
} //else printf("basilisk_requests_poll unexpected hwm issueR\n");

76
basilisk/basilisk_DEX.c

@ -413,42 +413,31 @@ ZERO_ARGS(InstantDEX,allcoins)
STRING_ARG(InstantDEX,available,source)
{
char *retstr; uint64_t total = 0; int32_t i,n; cJSON *item,*vals,*unspents,*balancejson,*retjson = 0;
uint64_t total = 0; int32_t i,n=0; cJSON *item,*unspents,*retjson = 0;
if ( source != 0 && source[0] != 0 && (coin= iguana_coinfind(source)) != 0 )
{
if ( myinfo->expiration != 0 )
{
//return(bitcoinrpc_getbalance(myinfo,coin,json,remoteaddr,"*",coin->chain->minconfirms,1,1<<30));
if ( (vals= basilisk_balance_valsobj(myinfo,coin)) != 0 )
if ( (unspents= iguana_listunspents(myinfo,coin,0,0,0,remoteaddr)) != 0 )
{
if ( (retstr= basilisk_balances(myinfo,coin,0,0,GENESIS_PUBKEY,vals,"")) != 0 )
if ( (n= cJSON_GetArraySize(unspents)) > 0 )
{
//printf("available.(%s)\n",retstr);
if ( (balancejson= cJSON_Parse(retstr)) != 0 )
for (i=0; i<n; i++)
{
if ( (unspents= jarray(&n,balancejson,"unspents")) != 0 )
item = jitem(unspents,i);
if ( jobj(item,"unspent") != 0 )
{
for (i=0; i<n; i++)
{
item = jitem(unspents,i);
if ( jobj(item,"unspent") != 0 )
{
total += jdouble(item,"amount") * SATOSHIDEN;
}
//printf("(%s) -> %.8f\n",jprint(item,0),dstr(total));
}
} else printf("no unspents in available\n");
retjson = cJSON_CreateObject();
jaddnum(retjson,"result",dstr(total));
free_json(balancejson);
printf("n.%d total %.8f (%s)\n",n,dstr(total),jprint(retjson,0));
} else printf("parse error.(%s)\n",retstr);
free(retstr);
total += jdouble(item,"amount") * SATOSHIDEN;
}
//printf("(%s) -> %.8f\n",jprint(item,0),dstr(total));
}
}
free_json(vals);
if ( retjson != 0 )
return(jprint(retjson,1));
free_json(unspents);
}
retjson = cJSON_CreateObject();
jaddnum(retjson,"result",dstr(total));
printf("(%s) n.%d total %.8f (%s)\n",jprint(unspents,0),n,dstr(total),jprint(retjson,0));
return(jprint(retjson,1));
}
printf("InstantDEX_available: need to unlock wallet\n");
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
@ -471,27 +460,25 @@ HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr)
jaddnum(vals,"timestamp",time(NULL));
hash = myinfo->myaddr.persistent;
printf("service.(%s)\n",jprint(vals,0));
memset(&R,0,sizeof(R));
if ( basilisk_request_create(&R,vals,hash,juint(vals,"timestamp")) == 0 )
{
memset(&R,0,sizeof(R));
if ( basilisk_request_create(&R,vals,hash,juint(vals,"timestamp")) == 0 )
{
printf("R.requestid.%u vs calc %u, q.%u\n",R.requestid,basilisk_requestid(&R),R.quoteid);
//if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 )
// R.relaybits = myinfo->myaddr.myipbits;
if ( (reqjson= basilisk_requestjson(&R)) != 0 )
free_json(reqjson);
datalen = basilisk_rwDEXquote(1,serialized,&R);
int32_t i; for (i=0; i<sizeof(R); i++)
printf("%02x",((uint8_t *)&R)[i]);
printf(" R.requestid.%u vs calc %u, q.%u datalen.%d\n",R.requestid,basilisk_requestid(&R),R.quoteid,datalen);
basilisk_rwDEXquote(0,serialized,&R);
} else printf("error creating request\n");
}
printf("R.requestid.%u vs calc %u, q.%u\n",R.requestid,basilisk_requestid(&R),R.quoteid);
//if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 )
// R.relaybits = myinfo->myaddr.myipbits;
if ( (reqjson= basilisk_requestjson(&R)) != 0 )
free_json(reqjson);
datalen = basilisk_rwDEXquote(1,serialized,&R);
int32_t i; for (i=0; i<sizeof(R); i++)
printf("%02x",((uint8_t *)&R)[i]);
printf(" R.requestid.%u vs calc %u, q.%u datalen.%d\n",R.requestid,basilisk_requestid(&R),R.quoteid,datalen);
basilisk_rwDEXquote(0,serialized,&R);
} else printf("error creating request\n");
if ( datalen > 0 )
{
memset(hash.bytes,0,sizeof(hash));
DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
if ( basilisk_channelsend(myinfo,hash,DEX_channel,(uint32_t)time(NULL),serialized,datalen,30) == 0 )
if ( basilisk_channelsend(myinfo,R.srchash,R.desthash,DEX_channel,(uint32_t)time(NULL),serialized,datalen,30) == 0 )
return(clonestr("{\"result\":\"DEX message sent\"}"));
else return(clonestr("{\"error\":\"DEX message couldnt be sent\"}"));
}
@ -521,8 +508,9 @@ int32_t InstantDEX_process_channelget(struct supernet_info *myinfo,void *ptr,int
INT_ARG(InstantDEX,incoming,requestid)
{
cJSON *retjson,*retarray; uint32_t DEX_channel,msgid,now; int32_t retval,width,drift=3; uint8_t data[8192];
cJSON *retjson,*retarray; bits256 zero; uint32_t DEX_channel,msgid,now; int32_t retval,width,drift=3; uint8_t data[8192];
now = (uint32_t)time(NULL);
memset(&zero,0,sizeof(zero));
width = (now - myinfo->DEXpoll) + 2*drift;
if ( width < (drift+1) )
width = 2*drift+1;
@ -532,7 +520,7 @@ INT_ARG(InstantDEX,incoming,requestid)
retjson = cJSON_CreateObject();
DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
msgid = (uint32_t)time(NULL) + drift;
if ( (retarray= basilisk_channelget(myinfo,myinfo->myaddr.persistent,DEX_channel,msgid,width)) != 0 )
if ( (retarray= basilisk_channelget(myinfo,zero,myinfo->myaddr.persistent,DEX_channel,msgid,width)) != 0 )
{
//printf("GOT.(%s)\n",jprint(retarray,0));
if ( (retval= basilisk_process_retarray(myinfo,0,InstantDEX_process_channelget,data,sizeof(data),DEX_channel,msgid,retarray,InstantDEX_incoming_func)) > 0 )

28
basilisk/basilisk_MSG.c

@ -108,7 +108,7 @@ int32_t basilisk_messagekey(uint8_t *key,uint32_t channel,uint32_t msgid,bits256
char *basilisk_respond_OUT(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk)
{
int32_t keylen,duration; uint8_t key[BASILISK_KEYSIZE]; bits256 senderhash; char *retstr;
senderhash = jbits256(valsobj,"sender");
senderhash = jbits256(valsobj,"srchash");
duration = juint(valsobj,"duration");
keylen = basilisk_messagekey(key,juint(valsobj,"channel"),juint(valsobj,"msgid"),senderhash,hash);
retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration);
@ -203,7 +203,7 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha
msgid = juint(valsobj,"msgid");
channel = juint(valsobj,"channel");
//char str[65],str2[65]; printf("%s -> %s channel.%u msgid.%x width.%d\n",bits256_str(str,jbits256(valsobj,"sender")),bits256_str(str2,hash),juint(valsobj,"channel"),msgid,width);
return(basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(valsobj,"sender"),hash,width));
return(basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(valsobj,"srchash"),hash,width));
}
#include "../includes/iguana_apidefs.h"
@ -212,7 +212,8 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha
HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr)
{
uint32_t msgid,width,channel;
jaddbits256(vals,"sender",myinfo->myaddr.persistent);
jaddbits256(vals,"srchash",hash);
jaddbits256(vals,"desthash",myinfo->myaddr.persistent);
if ( (msgid= juint(vals,"msgid")) == 0 )
{
msgid = (uint32_t)time(NULL);
@ -223,8 +224,8 @@ HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr)
{
channel = juint(vals,"channel");
width = juint(vals,"width");
return(basilisk_iterate_MSG(myinfo,channel,msgid,hash,myinfo->myaddr.persistent,width));
} else return(basilisk_standardservice("MSG",myinfo,0,hash,vals,hexstr,1));
return(basilisk_iterate_MSG(myinfo,channel,msgid,myinfo->myaddr.persistent,myinfo->myaddr.persistent,width));
} else return(basilisk_standardservice("MSG",myinfo,0,myinfo->myaddr.persistent,vals,hexstr,1));
}
HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr)
@ -232,7 +233,7 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr)
int32_t keylen,datalen; uint8_t key[BASILISK_KEYSIZE],space[16384],*data,*ptr = 0; char *retstr=0;
if ( myinfo->IAMNOTARY != 0 && myinfo->NOTARY.RELAYID >= 0 )
{
keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"sender"),hash);
keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"srchash"),hash);
if ( (data= get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,space,sizeof(space),hexstr)) != 0 )
{
retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,juint(vals,"duration"));
@ -248,7 +249,7 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr)
}
#include "../includes/iguana_apiundefs.h"
int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 hash,uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen,uint32_t duration)
int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen,uint32_t duration)
{
char *retstr,*hexstr,strbuf[4096],*ptr = 0; int32_t retval = -1; cJSON *valsobj;
if ( (hexstr= basilisk_addhexstr(&ptr,0,strbuf,sizeof(strbuf),data,datalen)) != 0 )
@ -260,9 +261,10 @@ int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 hash,uint32_t
jaddnum(valsobj,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2));
jaddnum(valsobj,"msgid",msgid);
jaddnum(valsobj,"duration",duration);
jaddbits256(valsobj,"sender",myinfo->myaddr.persistent);
char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s numrelays.%d:%d\n",datalen,channel,msgid,bits256_str(str,hash),myinfo->NOTARY.NUMRELAYS,juint(valsobj,"fanout"));
if ( (retstr= basilisk_sendmessage(myinfo,0,0,0,hash,valsobj,hexstr)) != 0 )
jaddbits256(valsobj,"srchash",srchash);
jaddbits256(valsobj,"desthash",desthash);
char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s numrelays.%d:%d\n",datalen,channel,msgid,bits256_str(str,desthash),myinfo->NOTARY.NUMRELAYS,juint(valsobj,"fanout"));
if ( (retstr= basilisk_sendmessage(myinfo,0,0,0,desthash,valsobj,hexstr)) != 0 )
free(retstr);
free_json(valsobj);
if ( ptr != 0 )
@ -296,7 +298,7 @@ int32_t basilisk_message_returned(uint8_t *key,uint8_t *data,int32_t maxlen,cJSO
return(retval);
}
cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 hash,uint32_t channel,uint32_t msgid,int32_t width)
cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgid,int32_t width)
{
char *retstr; cJSON *valsobj,*retarray=0,*item;
valsobj = cJSON_CreateObject();
@ -308,7 +310,9 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 hash,uint32_t ch
jaddnum(valsobj,"timeout",2500);
jaddnum(valsobj,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1));
jaddnum(valsobj,"numrequired",1);
if ( (retstr= basilisk_getmessage(myinfo,0,0,0,hash,valsobj,0)) != 0 )
jaddbits256(valsobj,"srchash",srchash);
jaddbits256(valsobj,"desthash",desthash);
if ( (retstr= basilisk_getmessage(myinfo,0,0,0,srchash,valsobj,0)) != 0 )
{
//printf("channel.%u msgid.%u gotmessage.(%s)\n",channel,msgid,retstr);
if ( (retarray= cJSON_Parse(retstr)) != 0 )

5
basilisk/basilisk_swap.c

@ -468,8 +468,9 @@ int32_t basilisk_process_swapget(struct supernet_info *myinfo,void *ptr,int32_t
int32_t basilisk_swapget(struct supernet_info *myinfo,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t maxlen,int32_t (*basilisk_verify_func)(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen))
{
int32_t retval; cJSON *retarray;
if ( (retarray= basilisk_channelget(myinfo,myinfo->myaddr.persistent,swap->req.quoteid,msgbits,0)) != 0 )
if ( (retarray= basilisk_channelget(myinfo,swap->otherhash,swap->myhash,swap->req.quoteid,msgbits,0)) != 0 )
{
printf("got.(%s) msgbits.%08x\n",jprint(retarray,0),msgbits);
retval = basilisk_process_retarray(myinfo,swap,basilisk_process_swapget,data,maxlen,swap->req.quoteid,msgbits,retarray,basilisk_verify_func);
if ( retval > 0 )
return(0);
@ -955,7 +956,7 @@ int32_t basilisk_verify_privkeys(struct supernet_info *myinfo,void *ptr,uint8_t
uint32_t basilisk_swapsend(struct supernet_info *myinfo,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t datalen,uint32_t nextbits)
{
if ( basilisk_channelsend(myinfo,swap->otherhash,swap->req.quoteid,msgbits,data,datalen,INSTANTDEX_LOCKTIME*2) == 0 )
if ( basilisk_channelsend(myinfo,swap->myhash,swap->otherhash,swap->req.quoteid,msgbits,data,datalen,INSTANTDEX_LOCKTIME*2) == 0 )
return(nextbits);
printf("ERROR basilisk_channelsend\n");
return(0);

15
iguana/iguana_payments.c

@ -1286,19 +1286,24 @@ ARRAY_OBJ_INT(bitcoinrpc,createrawtransaction,vins,vouts,locktime)
return(jprint(retjson,1));
}
cJSON *iguana_listunspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,char *remoteaddr)
{
if ( minconf == 0 )
minconf = 1;
if ( maxconf == 0 )
maxconf = (1 << 30);
return(iguana_RTlistunspent(myinfo,coin,array,minconf,maxconf,remoteaddr,0));
}
TWOINTS_AND_ARRAY(bitcoinrpc,listunspent,minconf,maxconf,array)
{
//int32_t numrmds,numunspents=0; uint8_t *rmdarray; cJSON *retjson = cJSON_CreateArray();
cJSON *argarray,*retjson;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( minconf == 0 )
minconf = 1;
if ( maxconf == 0 )
maxconf = (1 << 30);
if ( (argarray= array) == 0 || cJSON_GetArraySize(array) == 0 )
argarray = iguana_getaddressesbyaccount(myinfo,coin,"*");
retjson = iguana_RTlistunspent(myinfo,coin,argarray,minconf,maxconf,remoteaddr,0);
retjson = iguana_listunspents(myinfo,coin,argarray,minconf,maxconf,remoteaddr);
if ( argarray != array )
free_json(argarray);
return(jprint(retjson,1));

1
includes/iguana_funcs.h

@ -569,6 +569,7 @@ int32_t iguana_datachain_scan(struct supernet_info *myinfo,struct iguana_info *c
void iguana_RTreset(struct iguana_info *coin);
void iguana_RTpurge(struct iguana_info *coin,int32_t lastheight);
void iguana_RTnewblock(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block *block);
cJSON *iguana_listunspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,char *remoteaddr);
void *iguana_RTrawdata(struct iguana_info *coin,bits256 hash2,uint8_t *data,int32_t *recvlenp,int32_t *numtxp,int32_t checkonly);
int32_t iguana_bundlehash2_check(struct iguana_info *coin,bits256 hash2);
void iguana_RTramchainalloc(char *fname,struct iguana_info *coin,struct iguana_bundle *bp);

Loading…
Cancel
Save