Browse Source

Merge pull request #323 from jl777/dev

Dev
beta
jl777 8 years ago
committed by GitHub
parent
commit
c8d62aa4ea
  1. 72
      basilisk/basilisk.c
  2. 31
      basilisk/jumblr.c
  3. 2
      iguana/iguana_notary.c
  4. 7
      iguana/iguana_payments.c
  5. 11
      iguana/iguana_sign.c
  6. 2
      iguana/tests/utxocombine
  7. 3
      iguana/tests/utxorawtx
  8. 1
      includes/iguana_apideclares.h

72
basilisk/basilisk.c

@ -33,6 +33,55 @@ int32_t basilisk_notarycmd(char *cmd)
else return(0);
}*/
cJSON *basilisk_utxosweep(struct supernet_info *myinfo,char *symbol,int64_t *satoshis,uint64_t limit,int32_t maxvins,char *coinaddr)
{
int32_t i,n,numvins = 0; char *retstr; uint64_t value,biggest = 0; struct iguana_info *coin=0; cJSON *item,*biggestitem=0,*array,*utxos = 0;
coin = iguana_coinfind(symbol);
if ( (retstr= dex_listunspent(myinfo,coin,0,0,symbol,coinaddr)) != 0 )
{
//printf("(%s)\n",retstr);
if ( (array= cJSON_Parse(retstr)) != 0 )
{
n = cJSON_GetArraySize(array);
for (i=0; i<n; i++)
{
item = jitem(array,i);
if ( (value= SATOSHIDEN*jdouble(item,"amount")) != 0 || (value= SATOSHIDEN*jdouble(item,"value")) != 0 )
{
//fprintf(stderr,"%.8f ",dstr(value));
if ( value <= limit )
{
//fprintf(stderr,"< ");
if ( utxos == 0 )
utxos = cJSON_CreateArray();
if ( numvins < maxvins )
{
jaddi(utxos,jduplicate(item));
numvins++;
}
}
else if ( value > biggest )
{
//fprintf(stderr,"biggest! ");
if ( biggestitem != 0 )
free_json(biggestitem);
biggestitem = jduplicate(item);
*satoshis = biggest = value;
} //else fprintf(stderr,"> ");
}
}
free_json(array);
if ( utxos == 0 && biggestitem != 0 )
{
fprintf(stderr,"add biggest.(%s)\n",jprint(biggestitem,0));
jaddi(utxos,biggestitem);
}
}
free(retstr);
}
return(utxos);
}
uint32_t basilisk_calcnonce(struct supernet_info *myinfo,uint8_t *data,int32_t datalen,uint32_t nBits)
{
int32_t i,numiters = 0; bits256 hash,hash2,threshold; uint32_t basilisktag;
@ -1071,6 +1120,7 @@ ARRAY_OBJ_INT(tradebot,goals,currencies,vals,targettime)
return(clonestr("{\"result\":\"success\"}"));
} else return(clonestr("{\"error\":\"no currencies or vals\"}"));
}
HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr)
{
uint32_t msgid,width,channel; char *retstr;
@ -1617,6 +1667,28 @@ STRING_ARRAY_OBJ_STRING(basilisk,utxorawtx,symbol,utxos,vals,ignore)
return(clonestr("{\"error\":\"invalid coin or address specified\"}"));
}
HASH_ARRAY_STRING(basilisk,utxocombine,ignore,vals,symbol)
{
char *coinaddr,*retstr=0; cJSON *utxos; int64_t satoshis,limit,txfee; int32_t maxvins,completed,sendflag,timelock;
timelock = 0;
if ( (maxvins= jint(vals,"maxvins")) == 0 )
maxvins = 20;
sendflag = jint(vals,"sendflag");
coinaddr = jstr(vals,"coinaddr");
limit = jdouble(vals,"maxamount") * SATOSHIDEN;
if ( limit > 0 && symbol != 0 && symbol[0] != 0 && (utxos= basilisk_utxosweep(myinfo,symbol,&satoshis,limit,maxvins,coinaddr)) != 0 && cJSON_GetArraySize(utxos) > 0 )
{
if ( coinaddr != 0 && symbol != 0 && (coin= iguana_coinfind(symbol)) != 0 )
{
txfee = jdouble(vals,"txfee") * SATOSHIDEN;
retstr = iguana_utxorawtx(myinfo,coin,timelock,coinaddr,coinaddr,&satoshis,1,txfee,&completed,sendflag,utxos,0);
}
free_json(utxos);
}
if ( retstr == 0 )
return(clonestr("{\"error\":\"invalid coin or address specified or no available utxos\"}"));
return(retstr);
}
//int64_t iguana_verifytimelock(struct supernet_info *myinfo,struct iguana_info *coin,uint32_t timelocked,char *destaddr,bits256 txid,int32_t vout)
THREE_STRINGS_AND_DOUBLE(tradebot,aveprice,comment,base,rel,basevolume)

31
basilisk/jumblr.c

@ -376,14 +376,15 @@ bits256 jumblr_privkey(struct supernet_info *myinfo,char *coinaddr,uint8_t pubty
bitcoin_pubkey33(myinfo->ctx,pubkey33,privkey);
bitcoin_address(coinaddr,pubtype,pubkey33,33);
bitcoin_address(KMDaddr,60,pubkey33,33);
printf("(%s) -> (%s %s)\n",passphrase,coinaddr,KMDaddr);
//printf("(%s) -> (%s %s)\n",passphrase,coinaddr,KMDaddr);
return(privkey);
}
int64_t jumblr_DEXsplit(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *splittxidp,char *coinaddr,bits256 txid,int32_t vout,int64_t remaining,double bigprice,double middleprice,double smallprice,double fees[4],cJSON *privkeys)
int64_t jumblr_DEXsplit(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *splittxidp,char *coinaddr,bits256 txid,int32_t vout,int64_t remaining,double bigprice,double middleprice,double smallprice,double fees[4],cJSON *privkeys,double esttxfee)
{
int64_t values[4],outputs[64],value,total,estfee = 150000; int32_t i,n,success=0,completed,sendflag,numoutputs = 0; char *retstr; cJSON *retjson,*utxo,*item;
int64_t values[4],outputs[64],value,total,estfee; int32_t i,n,success=0,completed,sendflag,numoutputs = 0; char *retstr; cJSON *retjson,*utxo,*item;
total = 0;
estfee = SATOSHIDEN * esttxfee;
memset(values,0,sizeof(values));
memset(outputs,0,sizeof(outputs));
if ( bigprice > SMALLVAL )
@ -515,7 +516,7 @@ int32_t jumblr_DEXutxoind(int32_t *shouldsplitp,double targetvolB,double targetv
}
}
int32_t jumblr_DEXutxoupdate(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *splittxidp,char *coinaddr,bits256 privkey,bits256 txid,int32_t vout,uint64_t value,int32_t isbob,double kmdprice)
int32_t jumblr_DEXutxoupdate(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *splittxidp,char *coinaddr,bits256 privkey,bits256 txid,int32_t vout,uint64_t value,int32_t isbob,double kmdprice,double estfee)
{
double fees[4],targetvolB,amount,targetvolM,targetvolS,depositfactor,dexfeeratio,margin; int32_t ind,i,shouldsplit; cJSON *privkeys; char wifstr[128];
margin = 1.1;
@ -525,9 +526,9 @@ int32_t jumblr_DEXutxoupdate(struct supernet_info *myinfo,struct iguana_info *co
memset(splittxidp,0,sizeof(*splittxidp));
depositfactor = jumblr_DEXutxosize(&targetvolB,&targetvolM,&targetvolS,isbob,kmdprice);
printf("depositfactor %.8f targetvols %.8f %.8f %.8f\n",depositfactor,targetvolB,targetvolM,targetvolS);
fees[0] = (margin * targetvolB) / dexfeeratio;
fees[1] = (margin * targetvolM) / dexfeeratio;
fees[2] = (margin * targetvolS) / dexfeeratio;
fees[0] = estfee + (margin * targetvolB) / dexfeeratio;
fees[1] = estfee + (margin * targetvolM) / dexfeeratio;
fees[2] = estfee + (margin * targetvolS) / dexfeeratio;
fees[3] = (strcmp("BTC",coin->symbol) == 0) ? 50000 : 10000;
for (i=0; i<4; i++)
if ( fees[i] < 10000 )
@ -540,7 +541,7 @@ int32_t jumblr_DEXutxoupdate(struct supernet_info *myinfo,struct iguana_info *co
privkeys = cJSON_CreateArray();
bitcoin_priv2wif(wifstr,privkey,coin->chain->wiftype);
jaddistr(privkeys,wifstr);
jumblr_DEXsplit(myinfo,coin,splittxidp,coinaddr,txid,vout,value,margin * targetvolB,margin * targetvolM,margin * targetvolS,fees,privkeys);
jumblr_DEXsplit(myinfo,coin,splittxidp,coinaddr,txid,vout,value,margin * targetvolB,margin * targetvolM,margin * targetvolS,fees,privkeys,estfee);
free_json(privkeys);
ind = -1;
}
@ -588,7 +589,7 @@ void jumblr_utxotxidpendingadd(struct supernet_info *myinfo,struct iguana_info *
coin->DEXinfo.pending[coin->DEXinfo.numpending++] = pend;
}
void jumblr_utxoupdate(struct supernet_info *myinfo,struct iguana_info *coin,double price,char *coinaddr,bits256 privkey)
void jumblr_utxoupdate(struct supernet_info *myinfo,struct iguana_info *coin,double price,char *coinaddr,bits256 privkey,double estfee)
{
char *retstr; cJSON *array,*item; int32_t i,n,vout,ind; bits256 txid,splittxid; uint64_t value;
if ( (retstr= jumblr_listunspent(myinfo,coin,coinaddr)) != 0 )
@ -607,7 +608,7 @@ void jumblr_utxoupdate(struct supernet_info *myinfo,struct iguana_info *coin,dou
printf("price %.8f %llx/v%d %.8f %d of %d\n",price,(long long)txid.txid,vout,dstr(value),i,n);
if ( jumblr_utxotxidpending(myinfo,&splittxid,&ind,coin,txid,vout) < 0 )
{
ind = jumblr_DEXutxoupdate(myinfo,coin,&splittxid,coinaddr,privkey,txid,vout,value,myinfo->IAMLP,price);
ind = jumblr_DEXutxoupdate(myinfo,coin,&splittxid,coinaddr,privkey,txid,vout,value,myinfo->IAMLP,price,estfee);
jumblr_utxotxidpendingadd(myinfo,coin,txid,vout,splittxid,ind);
} //else printf("already have txid\n");
}
@ -620,9 +621,11 @@ void jumblr_utxoupdate(struct supernet_info *myinfo,struct iguana_info *coin,dou
void jumblr_DEXupdate(struct supernet_info *myinfo,struct iguana_info *coin,char *symbol,char *CMCname,double BTC2KMD,double KMDavail)
{
double avebid,aveask,highbid,lowask,CMC_average,changes[3]; struct iguana_info *btccoin,*kmdcoin; struct DEXcoin_info *ptr = &coin->DEXinfo;
double avebid,aveask,highbid,lowask,CMC_average,changes[3],estfee,estbtcfee; struct iguana_info *btccoin,*kmdcoin; struct DEXcoin_info *ptr = &coin->DEXinfo;
// wait for one confirmation to clear most in mempool (ha, ha)
// deal with changing addresses, ie all pendings?
estfee = 0.0001;
estbtcfee = 0.0015;
if ( coin != 0 && (kmdcoin= iguana_coinfind("KMD")) != 0 && time(NULL) > ptr->lasttime+60 )
{
ptr->coin = coin;
@ -652,14 +655,14 @@ void jumblr_DEXupdate(struct supernet_info *myinfo,struct iguana_info *coin,char
ptr->kmdprice = 1.;
ptr->KMDavail = ptr->avail;
if ( (btccoin= iguana_coinfind("BTC")) != 0 )
jumblr_utxoupdate(myinfo,btccoin,ptr->btcprice,ptr->depositaddr,ptr->deposit_privkey);
jumblr_utxoupdate(myinfo,kmdcoin,1.,ptr->KMDdepositaddr,ptr->deposit_privkey);
jumblr_utxoupdate(myinfo,btccoin,ptr->btcprice,ptr->depositaddr,ptr->deposit_privkey,estbtcfee);
jumblr_utxoupdate(myinfo,kmdcoin,1.,ptr->KMDdepositaddr,ptr->deposit_privkey,estfee);
}
else if ( (ptr->BTC2KMD= BTC2KMD) > SMALLVAL )
{
ptr->kmdprice = ptr->btcprice / BTC2KMD;
ptr->KMDavail = KMDavail;
jumblr_utxoupdate(myinfo,ptr->coin,ptr->kmdprice,ptr->depositaddr,ptr->deposit_privkey);
jumblr_utxoupdate(myinfo,ptr->coin,ptr->kmdprice,ptr->depositaddr,ptr->deposit_privkey,estfee);
}
ptr->lasttime = (uint32_t)time(NULL);
} // else printf("skip\n");

2
iguana/iguana_notary.c

@ -665,6 +665,8 @@ TWO_STRINGS(dex,listunspent,symbol,address)
return(retstr);
}
}
else if ( coin != 0 && coin->FULLNODE < 0 )
return(jprint(dpow_listunspent(myinfo,coin,address),1));
return(_dex_listunspent(myinfo,symbol,address));
}

7
iguana/iguana_payments.c

@ -554,7 +554,10 @@ char *iguana_calcutxorawtx(struct supernet_info *myinfo,struct iguana_info *coin
for (i=0; i<numoutputs; i++)
satoshis += outputs[i];
if ( (n= cJSON_GetArraySize(utxos)) == 0 )
{
fprintf(stderr,"iguana_calcutxorawtx: no utxos provided?\n");
return(0);
}
for (i=0; i<n; i++)
{
item = jitem(utxos,i);
@ -568,8 +571,10 @@ char *iguana_calcutxorawtx(struct supernet_info *myinfo,struct iguana_info *coin
continue;
}
unspents = realloc(unspents,(1 + max) * sizeof(*unspents));
value = jdouble(item,"value") * SATOSHIDEN;
if ( (value= jdouble(item,"value") * SATOSHIDEN) == 0 )
value = jdouble(item,"amount") * SATOSHIDEN;
interests += SATOSHIDEN * jdouble(item,"interest");
//printf("(%s) ",jprint(item,0));
iguana_outptset(myinfo,coin,&unspents[max++],jbits256(item,"txid"),jint(item,"vout"),value,spendscriptstr);
avail += value;
}

11
iguana/iguana_sign.c

@ -568,14 +568,15 @@ void iguana_vinobjset(struct iguana_msgvin *vin,cJSON *item,uint8_t *spendscript
}
}
int32_t iguana_vinarray_check(cJSON *vinarray,bits256 txid)
int32_t iguana_vinarray_check(cJSON *vinarray,bits256 txid,int32_t vout)
{
bits256 array_txid; cJSON *item; int32_t i,n = cJSON_GetArraySize(vinarray);
bits256 array_txid; cJSON *item; int32_t array_vout,i,n = cJSON_GetArraySize(vinarray);
for (i=0; i<n; i++)
{
item = jitem(vinarray,i);
array_txid = jbits256(item,"txid");
if ( bits256_cmp(array_txid,txid) == 0 )
array_vout = jint(item,"vout");
if ( bits256_cmp(array_txid,txid) == 0 && array_vout == vout )
{
printf("vinarray.[%d] duplicate\n",i);
return(i);
@ -704,11 +705,11 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
iguana_vinobjset(&msg->vins[i],jitem(vins,i),spendscript,sizeof(spendscript));
sigtxid = bitcoin_sigtxid(coin,height,sigser,maxsize*2,msg,i,msg->vins[i].spendscript,msg->vins[i].spendlen,SIGHASH_ALL,vpnstr,suppress_pubkeys);
//printf("after vini.%d vinscript.%p spendscript.%p spendlen.%d (%s)\n",i,msg->vins[i].vinscript,msg->vins[i].spendscript,msg->vins[i].spendlen,jprint(jitem(vins,i),0));
if ( iguana_vinarray_check(vinarray,msg->vins[i].prev_hash) < 0 )
if ( iguana_vinarray_check(vinarray,msg->vins[i].prev_hash,msg->vins[i].prev_vout) < 0 )
jaddi(vinarray,iguana_vinjson(coin,&msg->vins[i],sigtxid));
if ( msg->vins[i].spendscript == spendscript )
msg->vins[i].spendscript = 0;
} else if ( iguana_vinarray_check(vinarray,msg->vins[i].prev_hash) < 0 )
} else if ( iguana_vinarray_check(vinarray,msg->vins[i].prev_hash,msg->vins[i].prev_vout) < 0 )
jaddi(vinarray,iguana_vinjson(coin,&msg->vins[i],sigtxid));
}
free(sigser);

2
iguana/tests/utxocombine

@ -0,0 +1,2 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"symbol\":\"BTC\",\"agent\":\"basilisk\",\"method\":\"utxocombine\",\"vals\":{\"coinaddr\":\"1E2ac2gxeFR2ir1H3vqETTperWkiXkwy99\",\"maxamount\":0.0001,\"sendflag\":0}}"

3
iguana/tests/utxorawtx

@ -1,2 +1 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"symbol\":\"BTC\",\"agent\":\"basilisk\",\"method\":\"utxorawtx\",\"vals\":{\"timelock\":0,\"changeaddr\":\"1P3rU1Nk1pmc2BiWC8dEy9bZa1ZbMp5jfg\",\"destaddr\":\"1P3rU1Nk1pmc2BiWC8dEy9bZa1ZbMp5jfg\",\"txfee\":0,\"amount\":0.0001,\"sendflag\":0},\"utxos\":[{\"value\":0.00100000,\"address\":\"1Hgzt5xsnbfc8UTWqWKSTLRm5bEYHYBoCE\",\"scriptPubKey\":\"76a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac\",\"confirmations\":23351,\"spendable\":true}]}"
#!/bin/bashcurl --url "http://127.0.0.1:7778" --data "{\"symbol\":\"BTC\",\"agent\":\"basilisk\",\"method\":\"utxorawtx\",\"vals\":{\"timelock\":0,\"changeaddr\":\"1P3rU1Nk1pmc2BiWC8dEy9bZa1ZbMp5jfg\",\"destaddr\":\"1P3rU1Nk1pmc2BiWC8dEy9bZa1ZbMp5jfg\",\"txfee\":0,\"amount\":0.0001,\"sendflag\":0},\"utxos\":[{\"value\":0.00100000,\"address\":\"1Hgzt5xsnbfc8UTWqWKSTLRm5bEYHYBoCE\",\"scriptPubKey\":\"76a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac\",\"confirmations\":23351,\"spendable\":true}]}"

1
includes/iguana_apideclares.h

@ -67,6 +67,7 @@ HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr);
TWO_STRINGS(basilisk,refresh,symbol,address);
ZERO_ARGS(basilisk,cancelrefresh);
STRING_ARRAY_OBJ_STRING(basilisk,utxorawtx,symbol,utxos,vals,ignore);
HASH_ARRAY_STRING(basilisk,utxocombine,ignore,vals,symbol);
HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr);
HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr);

Loading…
Cancel
Save