Browse Source

Test

etomic
jl777 8 years ago
parent
commit
2989789576
  1. 6
      basilisk/basilisk_DEX.c
  2. 4
      basilisk/basilisk_MSG.c
  3. 14
      basilisk/basilisk_bitcoin.c
  4. 25
      basilisk/jumblr.c
  5. 1
      includes/iguana_funcs.h

6
basilisk/basilisk_DEX.c

@ -681,19 +681,19 @@ HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr)
} else printf("error creating request\n");
if ( datalen > 0 )
{
uint32_t msgid,crc=0,crcs[2],numiters = 0; uint8_t buf[4096];
uint32_t msgid,crc=0;//,crcs[2],numiters = 0; uint8_t buf[4096];
memset(hash.bytes,0,sizeof(hash));
msgid = (uint32_t)time(NULL);
DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
basilisk_channelsend(myinfo,myinfo->myaddr.persistent,hash,DEX_channel,msgid,serialized,datalen,60);
sleep(3);
while ( numiters < 10 && (crc= basilisk_crcsend(myinfo,0,buf,sizeof(buf),hash,myinfo->myaddr.persistent,DEX_channel,msgid,serialized,datalen,crcs)) == 0 )
/*while ( numiters < 10 && (crc= basilisk_crcsend(myinfo,0,buf,sizeof(buf),hash,myinfo->myaddr.persistent,DEX_channel,msgid,serialized,datalen,crcs)) == 0 )
{
//printf("didnt get back what was sent\n");
sleep(3);
basilisk_channelsend(myinfo,myinfo->myaddr.persistent,hash,DEX_channel,msgid,serialized,datalen,60);
numiters++;
}
}*/
if ( crc != 0 )//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\"}"));

4
basilisk/basilisk_MSG.c

@ -335,7 +335,7 @@ int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 srchash,bits25
jaddnum(valsobj,"timeout",1000);
jaddbits256(valsobj,"srchash",srchash);
jaddbits256(valsobj,"desthash",desthash);
//char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s numrelays.%d\n",datalen,channel,msgid,bits256_str(str,desthash),myinfo->NOTARY.NUMRELAYS);
char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s numrelays.%d\n",datalen,channel,msgid,bits256_str(str,desthash),myinfo->NOTARY.NUMRELAYS);
if ( (retstr= basilisk_sendmessage(myinfo,0,0,0,desthash,valsobj,hexstr)) != 0 )
free(retstr);
free_json(valsobj);
@ -386,7 +386,7 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 srchash,bits256
jaddbits256(valsobj,"desthash",desthash);
if ( (retstr= basilisk_getmessage(myinfo,0,0,0,desthash,valsobj,0)) != 0 )
{
//printf("channel.%u msgid.%u gotmessage.(%d)\n",channel,msgid,(int32_t)strlen(retstr));
printf("channel.%u msgid.%u gotmessage.(%d)\n",channel,msgid,(int32_t)strlen(retstr));
if ( (retarray= cJSON_Parse(retstr)) != 0 )
{
if ( is_cJSON_Array(retarray) == 0 )

14
basilisk/basilisk_bitcoin.c

@ -567,12 +567,12 @@ int64_t iguana_esttxfee(struct supernet_info *myinfo,struct iguana_info *coin,ch
coin->estimatedfee = iguana_getestimatedfee(myinfo,coin);
if ( signedtx != 0 )
{
txfee = coin->estimatedfee * (strlen(signedtx) + numvins);
txfee = coin->estimatedfee * (strlen(signedtx)/2 + numvins);
free(signedtx);
}
else if ( rawtx != 0 )
{
txfee = coin->estimatedfee * (strlen(rawtx) + numvins * 110);
txfee = coin->estimatedfee * (strlen(rawtx)/2 + numvins * 110);
free(rawtx);
}
return(txfee);
@ -748,7 +748,7 @@ char *iguana_utxorawtx(struct supernet_info *myinfo,struct iguana_info *coin,int
char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj,struct vin_info *V)
{
uint8_t buf[4096]; int32_t oplen,offset,minconf,spendlen; cJSON *vins,*addresses,*txobj = 0; uint32_t locktime; char *opreturn,*spendscriptstr,*changeaddr,*rawtx = 0; int64_t amount,txfee,burnamount;
uint8_t buf[4096]; int32_t oplen,len,offset,minconf,spendlen; cJSON *vins,*addresses,*txobj = 0; uint32_t locktime; char *opreturn,*spendscriptstr,*changeaddr,*rawtx = 0; int64_t amount,txfee,burnamount;
if ( valsobj == 0 )
return(clonestr("{\"error\":\"null valsobj\"}"));
//if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 )
@ -798,7 +798,13 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
} else oplen = datachain_opreturnscript(coin,buf,opreturn,oplen);
}
rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,amount,changeaddr,txfee,addresses,minconf,oplen!=0?buf:0,oplen+offset,burnamount,remoteaddr,V,0);
//printf("generated.(%s) vins.(%s)\n",rawtx!=0?rawtx:"",vins!=0?jprint(vins,0):"");
if ( txfee == 0 )
{
txfee = iguana_esttxfee(myinfo,coin,rawtx,0,vins != 0 ? cJSON_GetArraySize(vins): 0);
rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,amount,changeaddr,txfee,addresses,minconf,oplen!=0?buf:0,oplen+offset,burnamount,remoteaddr,V,0);
printf("new txfee %.8f\n",dstr(txfee));
}
printf("generated.(%s) vins.(%s)\n",rawtx!=0?rawtx:"",vins!=0?jprint(vins,0):"");
}
if ( rawtx != 0 )
{

25
basilisk/jumblr.c

@ -366,9 +366,9 @@ bits256 jumblr_privkey(struct supernet_info *myinfo,char *BTCaddr,char *KMDaddr,
void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coinkmd,char *BTCaddr,char *KMDaddr,bits256 privkey)
{
static double kmdprice; static uint32_t lasttime;
double btcavail=0,minbtc,avebid,aveask,highbid,lowask,CMC_average,USD_average,changes[3]; struct iguana_info *coinbtc = iguana_coinfind("BTC");
printf("DEXcheck %p\n",coinbtc);
static double kmdprice,pending; static uint32_t lasttime;
double btcavail=0,minbtc,avebid,aveask,highbid,lowask,CMC_average,USD_average,changes[3]; struct iguana_info *coinbtc; cJSON *vals; bits256 hash; char *retstr;
coinbtc = iguana_coinfind("BTC");
if ( kmdprice == 0. || time(NULL) > lasttime+600 )
{
kmdprice = get_theoretical(&avebid,&aveask,&highbid,&lowask,&CMC_average,changes,"komodo","KMD","BTC",&USD_average);
@ -378,9 +378,22 @@ void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coinkmd,ch
if ( kmdprice > SMALLVAL )
{
minbtc = (kmdprice * 1.1) * (JUMBLR_INCR + 3*(JUMBLR_INCR * JUMBLR_FEE + JUMBLR_TXFEE));
if ( coinbtc != 0 && (btcavail= dstr(jumblr_balance(myinfo,coinbtc,BTCaddr))) > minbtc )
if ( coinbtc != 0 && (btcavail= dstr(jumblr_balance(myinfo,coinbtc,BTCaddr))) > minbtc+pending )
{
printf("BTC deposits %.8f, min %.8f\n",btcavail,minbtc);
vals = cJSON_CreateObject();
jaddstr(vals,"source","BTC");
jaddstr(vals,"dest","KMD");
jaddnum(vals,"amount",btcavail*.95);
jaddnum(vals,"minprice",kmdprice*.95);
memset(hash.bytes,0,sizeof(hash));
pending = btcavail;
if ( (retstr= InstantDEX_request(myinfo,coinbtc,0,0,hash,vals,"")) != 0 )
{
printf("request.(%s) -> (%s)\n",jprint(vals,0),retstr);
free(retstr);
}
// curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"request\",\"vals\":{\"source\":\"KMD\",\"amount\":20,\"dest\":\"USD\",\"minprice\":0.08}}"
} else printf("btcavail %.8f\n",btcavail);
}
}
@ -389,11 +402,11 @@ void jumblr_iteration(struct supernet_info *myinfo,struct iguana_info *coin,int3
{
static uint32_t lasttime;
char BTCaddr[64],KMDaddr[64],*zaddr,*retstr; bits256 privkey; uint64_t amount=0,total=0; double fee; struct jumblr_item *ptr,*tmp; uint8_t r;
// if BTC has arrived in deposit address, invoke DEX -> KMD
// if BTC has arrived in destination address, invoke DEX -> BTC
privkey = jumblr_privkey(myinfo,BTCaddr,KMDaddr,JUMBLR_DEPOSITPREFIX);
if ( time(NULL) > lasttime+60 )
{
// if BTC has arrived in deposit address, invoke DEX -> KMD
// if BTC has arrived in destination address, invoke DEX -> BTC
jumblr_DEXcheck(myinfo,coin,BTCaddr,KMDaddr,privkey);
lasttime = (uint32_t)time(NULL);
}

1
includes/iguana_funcs.h

@ -617,6 +617,7 @@ void iguana_walletinitcheck(struct supernet_info *myinfo,struct iguana_info *coi
void jumblr_iteration(struct supernet_info *myinfo,struct iguana_info *coin,int32_t selector,int32_t modval);
bits256 jumblr_privkey(struct supernet_info *myinfo,char *BTCaddr,char *KMDaddr,char *prefix);
char *jumblr_importprivkey(struct supernet_info *myinfo,struct iguana_info *coin,char *wifstr);
int64_t iguana_esttxfee(struct supernet_info *myinfo,struct iguana_info *coin,char *rawtx,char *signedtx,int32_t numvins);
// ------------------------------------------------------[ Preparation ]----
// Initialise a gfshare context for producing shares

Loading…
Cancel
Save