Browse Source

Test

etomic
jl777 8 years ago
parent
commit
30929bbee1
  1. 14
      basilisk/basilisk.c
  2. 6
      basilisk/basilisk_DEX.c
  3. 19
      basilisk/basilisk_swap.c
  4. 4
      basilisk/basilisk_tradebot.c
  5. 40
      basilisk/jumblr.c
  6. 188
      basilisk/smartaddress.c
  7. 21
      basilisk/tradebots_liquidity.c
  8. 3
      iguana/iguana777.h
  9. 13
      iguana/iguana_wallet.c
  10. 2
      iguana/main.c
  11. 2
      includes/iguana_apideclares.h
  12. 8
      includes/iguana_funcs.h

14
basilisk/basilisk.c

@ -1354,7 +1354,7 @@ HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr)
STRING_ARG(jumblr,setpassphrase,passphrase)
{
cJSON *retjson; char KMDaddr[64],BTCaddr[64],wifstr[64]; bits256 privkey; struct iguana_info *coinbtc;
cJSON *retjson,*tmp; char KMDaddr[64],BTCaddr[64],wifstr[64],*smartaddrs; bits256 privkey; struct iguana_info *coinbtc;
if ( passphrase == 0 || passphrase[0] == 0 || (coin= iguana_coinfind("KMD")) == 0 )//|| coin->FULLNODE >= 0 )
return(clonestr("{\"error\":\"no passphrase or no native komodod\"}"));
else
@ -1363,7 +1363,7 @@ STRING_ARG(jumblr,setpassphrase,passphrase)
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
privkey = jumblr_privkey(myinfo,BTCaddr,0,KMDaddr,JUMBLR_DEPOSITPREFIX);
smartaddress_add(myinfo,privkey,BTCaddr,KMDaddr);
smartaddress_add(myinfo,privkey,"deposit");
myinfo->jumblr_depositkey = curve25519(privkey,curve25519_basepoint9());
bitcoin_priv2wif(wifstr,privkey,coin->chain->wiftype);
if ( coin->FULLNODE < 0 )
@ -1378,12 +1378,18 @@ STRING_ARG(jumblr,setpassphrase,passphrase)
jaddnum(retjson,"BTCdeposits",dstr(jumblr_balance(myinfo,coinbtc,BTCaddr)));
}
privkey = jumblr_privkey(myinfo,BTCaddr,0,KMDaddr,"");
smartaddress_add(myinfo,privkey,BTCaddr,KMDaddr);
smartaddress_add(myinfo,privkey,"jumblr");
myinfo->jumblr_pubkey = curve25519(privkey,curve25519_basepoint9());
jaddstr(retjson,"KMDjumblr",KMDaddr);
jaddstr(retjson,"BTCjumblr",BTCaddr);
if ( coinbtc != 0 )
jaddnum(retjson,"BTCjumbled",dstr(jumblr_balance(myinfo,coinbtc,BTCaddr)));
if ( (smartaddrs= InstantDEX_smartaddresses(myinfo,0,0,0)) != 0 )
{
if ( (tmp= cJSON_Parse(smartaddrs)) != 0 )
jadd(retjson,"smartaddresses",tmp);
free(smartaddrs);
}
return(jprint(retjson,1));
}
}
@ -1945,6 +1951,4 @@ ZERO_ARGS(InstantDEX,getswaplist)
return(basilisk_swaplist(myinfo));
}
#include "../includes/iguana_apiundefs.h"

6
basilisk/basilisk_DEX.c

@ -245,8 +245,8 @@ char *basilisk_start(struct supernet_info *myinfo,bits256 privkey,struct basilis
//printf("filter duplicate r%u\n",_rp->requestid);
return(clonestr("{\"error\":\"filter duplicate requestid\"}"));
}
srcmatch = smartaddress_pubkey(myinfo,&tmpprivkey,_rp->srchash) >= 0;
destmatch = smartaddress_pubkey(myinfo,&tmpprivkey,_rp->desthash) >= 0;
srcmatch = smartaddress_pubkey(myinfo,&tmpprivkey,_rp->src,_rp->srchash) >= 0;
destmatch = smartaddress_pubkey(myinfo,&tmpprivkey,_rp->dest,_rp->desthash) >= 0;
if ( srcmatch != 0 || destmatch != 0 )
{
for (i=0; i<myinfo->numswaps; i++)
@ -310,7 +310,7 @@ int32_t basilisk_requests_poll(struct supernet_info *myinfo)
if ( hwm > 0. )
{
myinfo->DEXaccept = issueR;
if ( smartaddress_pubkey(myinfo,&privkey,issueR.srchash) >= 0 )
if ( smartaddress_pubkey(myinfo,&privkey,issueR.src,issueR.srchash) >= 0 )
{
printf("matched dex_smartpubkey\n");
dex_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid)); // 60

19
basilisk/basilisk_swap.c

@ -500,7 +500,7 @@ cJSON *basilisk_privkeyarray(struct supernet_info *myinfo,struct iguana_info *co
bitcoin_priv2wif(wifstr,waddr->privkey,coin->chain->wiftype);
jaddistr(privkeyarray,waddr->wifstr);
}
else if ( smartaddress(myinfo,&privkey,coinaddr) >= 0 )
else if ( smartaddress(myinfo,&privkey,coin->symbol,coinaddr) >= 0 )
{
bitcoin_priv2wif(wifstr,privkey,coin->chain->wiftype);
jaddistr(privkeyarray,wifstr);
@ -2711,9 +2711,9 @@ cJSON *basilisk_swapjson(struct supernet_info *myinfo,struct basilisk_swap *swap
struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,bits256 privkey,struct basilisk_request *rp,uint32_t statebits,int32_t optionduration,int32_t reinit)
{
int32_t i,m,n; uint8_t pubkey33[33]; bits256 pubkey25519; uint32_t channel,starttime; cJSON *retarray,*item,*msgobj; struct iguana_info *coin; struct basilisk_swap *swap = 0;
int32_t i,m,n; uint8_t pubkey33[33]; bits256 pubkey25519; uint32_t channel,starttime; cJSON *retarray,*item,*msgobj; struct iguana_info *coin; double pending=0.; struct basilisk_swap *swap = 0;
// statebits 1 -> client, 0 -> LP
if ( statebits == 0 && myinfo->numswaps > 0 )
if ( myinfo->numswaps > 0 )
{
if ( (coin= iguana_coinfind(rp->src)) == 0 || coin->FULLNODE >= 0 )
{
@ -2818,7 +2818,18 @@ struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,bits256
}
myinfo->swaps[myinfo->numswaps++] = swap;
} else printf("%u/%u offer wasnt accepted statebits.%d m.%d n.%d\n",rp->requestid,rp->quoteid,statebits,m,n);
}
else
{
if ( statebits != 0 )
{
if ( (coin= iguana_coinfind(rp->src)) != 0 )
{
}
}
printf("%u/%u offer wasnt accepted statebits.%d m.%d n.%d pending %.8f\n",rp->requestid,rp->quoteid,statebits,m,n,pending);
}
}
}
}

4
basilisk/basilisk_tradebot.c

@ -291,7 +291,7 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk
return(0.);
pendingid = active->I.req.quoteid;
}
if ( smartaddress_pubkey(myinfo,&privkey,list[0].srchash) >= 0 )
if ( smartaddress_pubkey(myinfo,&privkey,list[0].src,list[0].srchash) >= 0 )
myrequest = 1;
for (i=0; i<n; i++)
{
@ -299,7 +299,7 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk
return(-1);
if ( list[i].quoteid != 0 )
{
if ( smartaddress_pubkey(myinfo,&privkey,list[i].desthash) >= 0 )
if ( smartaddress_pubkey(myinfo,&privkey,list[i].dest,list[i].desthash) >= 0 )
myrequest |= 2;
havequoteflag++;
if ( pendingid == 0 )

40
basilisk/jumblr.c

@ -371,20 +371,6 @@ void jumblr_opidsupdate(struct supernet_info *myinfo,struct iguana_info *coin)
}
}
bits256 jumblr_privkey(struct supernet_info *myinfo,char *coinaddr,uint8_t pubtype,char *KMDaddr,char *prefix)
{
bits256 privkey,pubkey; uint8_t pubkey33[33]; char passphrase[sizeof(myinfo->jumblr_passphrase) + 64];
sprintf(passphrase,"%s%s",prefix,myinfo->jumblr_passphrase);
if ( myinfo->jumblr_passphrase[0] == 0 )
strcpy(myinfo->jumblr_passphrase,"password");
conv_NXTpassword(privkey.bytes,pubkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
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);
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,double esttxfee)
{
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;
@ -691,15 +677,11 @@ void jumblr_DEXupdate(struct supernet_info *myinfo,struct iguana_info *coin,char
ptr->BTC2KMD = ptr->btcprice;
ptr->kmdprice = 1.;
ptr->KMDavail = KMDavail;
/*if ( (btccoin= iguana_coinfind("BTC")) != 0 )
jumblr_utxoupdate(myinfo,"KMD",btccoin,ptr->btcprice,ptr->depositaddr,ptr->deposit_privkey,estbtcfee);
jumblr_utxoupdate(myinfo,"BTC",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,"KMD",ptr->coin,ptr->kmdprice,ptr->depositaddr,ptr->deposit_privkey,estfee);
}
ptr->lasttime = (uint32_t)time(NULL);
printf("%s avail %.8f KMDavail %.8f btcprice %.8f deposit.(%s %s) -> jumblr.(%s %s)\n",symbol,ptr->avail,KMDavail,ptr->btcprice,ptr->depositaddr,ptr->KMDdepositaddr,ptr->jumblraddr,ptr->KMDjumblraddr);
@ -718,12 +700,12 @@ void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coin,int32
kmdcoin = iguana_coinfind("KMD");
coinbtc = iguana_coinfind("BTC");
//printf("jumblr_DEXcheck numswaps.%d notary.%d IAMLP.%d %p %p %f\n",myinfo->numswaps,myinfo->IAMNOTARY,myinfo->IAMLP,kmdcoin,coinbtc,kmdcoin->DEXinfo.btcprice);
if ( myinfo->IAMNOTARY != 0 || myinfo->IAMLP != 0 )
if ( myinfo->IAMNOTARY != 0 || myinfo->IAMLP != 0 || myinfo->secret[0] == 0 )
return;
if ( kmdcoin == 0 || coinbtc == 0 )
return;
jumblr_DEXupdate(myinfo,kmdcoin,"KMD","komodo",0.,0.);
if ( strcmp(coin->symbol,"KMD") != 0 && kmdcoin->DEXinfo.btcprice > 0. )
if ( strcmp(coin->symbol,"KMD") != 0 && strcmp(coin->symbol,"BTC") != 0 && kmdcoin->DEXinfo.btcprice > 0. )
{
if ( coin->CMCname[0] == 0 )
jumblr_CMCname(coin->CMCname,coin->symbol);
@ -737,9 +719,9 @@ void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coin,int32
double minbtc,minkmd,btcavail; char *retstr; cJSON *vals; bits256 hash;
minbtc = (kmdcoin->DEXinfo.btcprice * 1.2) * (JUMBLR_INCR + 3*(JUMBLR_INCR * JUMBLR_FEE + JUMBLR_TXFEE));
btcavail = dstr(jumblr_balance(myinfo,coinbtc,kmdcoin->DEXinfo.depositaddr));
avail = (btcavail - kmdcoin->DEXinfo.DEXpending);
printf("BTC.%d deposits %.8f, min %.8f avail %.8f pending %.8f\n",toKMD,btcavail,minbtc,avail,kmdcoin->DEXinfo.DEXpending);
if ( toKMD == 0 && coinbtc != 0 && btcavail > (minbtc + kmdcoin->DEXinfo.DEXpending) )
avail = (btcavail - coinbtc->DEXinfo.DEXpending);
printf("BTC.%d deposits %.8f, min %.8f avail %.8f pending %.8f\n",toKMD,btcavail,minbtc,avail,coinbtc->DEXinfo.DEXpending);
if ( toKMD == 0 && coinbtc != 0 && btcavail > (minbtc + coinbtc->DEXinfo.DEXpending) )
{
/*if ( avail >= (100. * minbtc) )
vol = (100. * minbtc);
@ -759,7 +741,7 @@ void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coin,int32
jaddnum(vals,"usejumblr",1);
jaddnum(vals,"DEXselector",1);
memset(hash.bytes,0,sizeof(hash));
kmdcoin->DEXinfo.DEXpending += vol;
coinbtc->DEXinfo.DEXpending += vol;
if ( (retstr= InstantDEX_request(myinfo,coinbtc,0,0,hash,vals,"")) != 0 )
{
printf("request.(%s) -> (%s)\n",jprint(vals,0),retstr);
@ -770,9 +752,9 @@ void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coin,int32
}
} //else printf("btcavail %.8f pending %.8f\n",btcavail,pending);
minkmd = 100.;
avail = (kmdcoin->DEXinfo.KMDavail - kmdcoin->DEXinfo.KMDpending);
printf("KMD.%d deposits %.8f, min %.8f, avail %.8f pending %.8f\n",toKMD,kmdcoin->DEXinfo.KMDavail,minkmd,avail,kmdcoin->DEXinfo.KMDpending);
if ( toKMD != 0 && coinbtc != 0 && kmdcoin->DEXinfo.KMDavail > (minkmd + kmdcoin->DEXinfo.KMDpending) )
avail = (kmdcoin->DEXinfo.KMDavail - kmdcoin->DEXinfo.DEXpending);
printf("KMD.%d deposits %.8f, min %.8f, avail %.8f pending %.8f\n",toKMD,kmdcoin->DEXinfo.KMDavail,minkmd,avail,kmdcoin->DEXinfo.DEXpending);
if ( toKMD != 0 && coinbtc != 0 && kmdcoin->DEXinfo.KMDavail > (minkmd + kmdcoin->DEXinfo.DEXpending) )
{
/*if ( avail > 100.*JUMBLR_INCR )
vol = 100.*JUMBLR_INCR;
@ -791,7 +773,7 @@ void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coin,int32
jaddnum(vals,"minprice",0.985 * kmdcoin->DEXinfo.btcprice);
jaddnum(vals,"usejumblr",2);
memset(hash.bytes,0,sizeof(hash));
kmdcoin->DEXinfo.KMDpending += vol;
kmdcoin->DEXinfo.DEXpending += vol;
jaddnum(vals,"DEXselector",2);
if ( (retstr= InstantDEX_request(myinfo,coinbtc,0,0,hash,vals,"")) != 0 )
{
@ -800,7 +782,7 @@ void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coin,int32
}
free_json(vals);
}
} else printf("kmdavail %.8f pending %.8f\n",kmdcoin->DEXinfo.KMDavail,kmdcoin->DEXinfo.KMDpending);
} else printf("kmdavail %.8f pending %.8f\n",kmdcoin->DEXinfo.KMDavail,kmdcoin->DEXinfo.DEXpending);
} else printf("notlp.%d kmdprice %.8f\n",myinfo->IAMLP,kmdcoin->DEXinfo.btcprice);
}

188
basilisk/smartaddress.c

@ -15,15 +15,101 @@
// included from basilisk.c
int32_t smartaddress_add(struct supernet_info *myinfo,bits256 privkey,char *BTCaddr,char *KMDaddr)
// deposit address <coin> -> corresponding KMD address, if KMD deposit starts JUMBLR
// jumblr address <coin> is the destination of JUMBLR and JUMBLR BTC (would need tracking to map back to non-BTC)
// <symbol> address <coin> is DEX'ed for <SYMBOL>
// return value convention: -1 error, 0 partial match, >= 1 exact match
int32_t smartaddress_type(char *typestr)
{
char upper[64];
if ( strcmp(typestr,"deposit") != 0 && strcmp(typestr,"jumblr") != 0 )
{
upper[sizeof(upper)-1] = 0;
strncpy(upper,typestr,sizeof(upper)-1);
touppercase(upper);
if ( iguana_coinfind(upper) != 0 )
return(0);
}
return(-1);
}
bits256 jumblr_privkey(struct supernet_info *myinfo,char *coinaddr,uint8_t pubtype,char *KMDaddr,char *prefix)
{
bits256 privkey,pubkey; uint8_t pubkey33[33]; char passphrase[sizeof(myinfo->jumblr_passphrase) + 64];
sprintf(passphrase,"%s%s",prefix,myinfo->jumblr_passphrase);
if ( myinfo->jumblr_passphrase[0] == 0 )
strcpy(myinfo->jumblr_passphrase,"password");
conv_NXTpassword(privkey.bytes,pubkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
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);
return(privkey);
}
cJSON *smartaddress_json(struct smartaddress *ap)
{
char coinaddr[64]; uint8_t addrtype,rmd160[20]; struct smartaddress *ap; int32_t i;
char coinaddr[64],*symbol; int32_t j,n; struct iguana_info *coin; cJSON *item = cJSON_CreateObject();
bitcoin_address(coinaddr,60,ap->pubkey33,33);
jaddstr(item,"KMD",coinaddr);
bitcoin_address(coinaddr,0,ap->pubkey33,33);
jaddstr(item,"BTC",coinaddr);
if ( ap->typejson != 0 )
{
jadd(item,"type",ap->typejson);
if ( (n= cJSON_GetArraySize(ap->typejson)) > 1 )
{
for (j=1; j<n; j++)
{
if ( (symbol= jstri(ap->typejson,j)) != 0 )
{
if ( strcmp(symbol,"KMD") != 0 && strcmp(symbol,"BTC") != 0 )
{
if ( (coin= iguana_coinfind(symbol)) != 0 )
{
bitcoin_address(coinaddr,coin->chain->pubtype,ap->pubkey33,33);
jaddstr(item,symbol,coinaddr);
}
}
}
}
}
}
return(item);
}
int32_t smartaddress_add(struct supernet_info *myinfo,bits256 privkey,char *symbol)
{
char coinaddr[64]; uint8_t addrtype,rmd160[20]; struct smartaddress *ap; int32_t i,j,n;
if ( myinfo->numsmartaddrs < sizeof(myinfo->smartaddrs)/sizeof(*myinfo->smartaddrs) )
{
for (i=0; i<myinfo->numsmartaddrs; i++)
if ( bits256_cmp(myinfo->smartaddrs[i].privkey,privkey) == 0 )
{
ap = &myinfo->smartaddrs[i];
if ( ap->typejson == 0 )
return(-1);
ap = &myinfo->smartaddrs[myinfo->numsmartaddrs++];
else
{
n = cJSON_GetArraySize(ap->typejson);
for (j=0; j<n; j++)
{
if ( strcmp(jstri(ap->typejson,j),symbol) == 0 )
return(0);
}
}
jaddistr(ap->typejson,symbol);
return(i+1);
}
ap = &myinfo->smartaddrs[myinfo->numsmartaddrs];
ap->typejson = cJSON_CreateArray();
if ( smartaddress_type(symbol) < 0 )
return(-1);
jaddistr(ap->typejson,symbol);
jaddistr(ap->typejson,"KMD");
jaddistr(ap->typejson,"BTC");
ap->privkey = privkey;
bitcoin_pubkey33(myinfo->ctx,ap->pubkey33,privkey);
calc_rmd160_sha256(ap->rmd160,ap->pubkey33,33);
@ -35,24 +121,40 @@ int32_t smartaddress_add(struct supernet_info *myinfo,bits256 privkey,char *BTCa
printf(", ");
for (i=0; i<20; i++)
printf("%02x",rmd160[i]);
printf (" <- rmd160 for %d %s vs %s\n",myinfo->numsmartaddrs,coinaddr,BTCaddr);
return(myinfo->numsmartaddrs);
printf (" <- rmd160 for %d %s\n",myinfo->numsmartaddrs,coinaddr);
return(++myinfo->numsmartaddrs + 1);
}
printf("too many smartaddresses %d vs %d\n",myinfo->numsmartaddrs,(int32_t)(sizeof(myinfo->smartaddrs)/sizeof(*myinfo->smartaddrs)));
return(-1);
}
int32_t smartaddress(struct supernet_info *myinfo,bits256 *privkeyp,char *coinaddr)
int32_t smartaddress_symbolmatch(struct smartaddress *ap,char *symbol)
{
int32_t i; uint8_t addrtype,rmd160[20];
int32_t j,n;
if ( ap->typejson != 0 && (n= cJSON_GetArraySize(ap->typejson)) > 0 )
{
for (j=0; j<n; j++)
{
if ( strcmp(jstri(ap->typejson,j),symbol) == 0 )
return(j);
}
}
return(-1);
}
int32_t smartaddress(struct supernet_info *myinfo,bits256 *privkeyp,char *symbol,char *coinaddr)
{
int32_t i,j; uint8_t addrtype,rmd160[20]; struct smartaddress *ap;
memset(privkeyp,0,sizeof(*privkeyp));
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
for (i=0; i<myinfo->numsmartaddrs; i++)
if ( memcmp(myinfo->smartaddrs[i].rmd160,rmd160,20) == 0 )
{
*privkeyp = myinfo->smartaddrs[i].privkey;
printf("MATCHED %s\n",coinaddr);
return(i);
ap = &myinfo->smartaddrs[i];
*privkeyp = ap->privkey;
if ( (j= smartaddress_symbolmatch(ap,symbol)) >= 0 )
return(0);
return(i+1);
}
for (i=0; i<20; i++)
printf("%02x",rmd160[i]);
@ -60,29 +162,77 @@ int32_t smartaddress(struct supernet_info *myinfo,bits256 *privkeyp,char *coinad
return(-1);
}
int32_t smartaddress_pubkey(struct supernet_info *myinfo,bits256 *privkeyp,bits256 pubkey)
int32_t smartaddress_pubkey(struct supernet_info *myinfo,bits256 *privkeyp,char *symbol,bits256 pubkey)
{
int32_t i;
int32_t i,j; struct smartaddress *ap;
memset(privkeyp,0,sizeof(*privkeyp));
for (i=0; i<myinfo->numsmartaddrs; i++)
if ( bits256_cmp(myinfo->smartaddrs[i].pubkey,pubkey) == 0 )
{
*privkeyp = myinfo->smartaddrs[i].privkey;
return(i);
ap = &myinfo->smartaddrs[i];
*privkeyp = ap->privkey;
if ( (j= smartaddress_symbolmatch(ap,symbol)) >= 0 )
return(0);
return(i+1);
}
return(-1);
}
int32_t smartaddress_pubkey33(struct supernet_info *myinfo,bits256 *privkeyp,uint8_t *pubkey33)
int32_t smartaddress_pubkey33(struct supernet_info *myinfo,bits256 *privkeyp,char *symbol,uint8_t *pubkey33)
{
int32_t i;
int32_t i,j; struct smartaddress *ap;
memset(privkeyp,0,sizeof(*privkeyp));
for (i=0; i<myinfo->numsmartaddrs; i++)
if ( memcmp(myinfo->smartaddrs[i].pubkey33,pubkey33,33) == 0 )
{
*privkeyp = myinfo->smartaddrs[i].privkey;
return(i);
}
ap = &myinfo->smartaddrs[i];
*privkeyp = ap->privkey;
if ( (j= smartaddress_symbolmatch(ap,symbol)) >= 0 )
return(0);
return(i+1);
}
return(-1);
}
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
ZERO_ARGS(InstantDEX,smartaddresses)
{
int32_t i; cJSON *retjson = cJSON_CreateArray();
for (i=0; i<myinfo->numsmartaddrs; i++)
jaddi(retjson,smartaddress_json(&myinfo->smartaddrs[i]));
return(jprint(retjson,1));
}
TWO_STRINGS(InstantDEX,smartaddress,type,symbol)
{
char prefix[64],coinaddr[64],KMDaddr[64]; uint8_t pubkey33[33]; bits256 privkey;
if ( smartaddress_type(type) < 0 )
return(clonestr("{\"error\":\"non-supported smartaddress type\"}"));
if ( iguana_coinfind(symbol) == 0 )
return(clonestr("{\"error\":\"non-supported smartaddress symbol\"}"));
if ( strcmp(type,"deposit") == 0 || strcmp(type,"jumblr") == 0 )
{
if ( smartaddress_pubkey(myinfo,&privkey,symbol,strcmp(type,"deposit") == 0 ? myinfo->jumblr_depositkey : myinfo->jumblr_pubkey) < 0 )
return(clonestr("{\"error\":\"unexpected missing smartaddress deposit/jumblr\"}"));
}
else
{
strcpy(prefix,type);
tolowercase(prefix);
if ( strcmp(prefix,"btc") == 0 || strcmp(prefix,"kmd") == 0 )
return(clonestr("{\"success\":\"no need add BTC or KMD to smartaddress\"}"));
strcat(prefix," ");
privkey = jumblr_privkey(myinfo,coinaddr,0,KMDaddr,prefix);
}
if ( (coin= iguana_coinfind(symbol)) == 0 )
return(clonestr("{\"error\":\"non-supported smartaddress symbol\"}"));
bitcoin_pubkey33(myinfo->ctx,pubkey33,privkey);
bitcoin_address(coinaddr,coin->chain->pubtype,pubkey33,33);
smartaddress_add(myinfo,privkey,symbol);
return(InstantDEX_smartaddresses(myinfo,0,0,0));
}
#include "../includes/iguana_apiundefs.h"

21
basilisk/tradebots_liquidity.c

@ -1142,13 +1142,22 @@ void _default_swap_balancingtrade(struct supernet_info *myinfo,struct basilisk_s
void tradebot_swap_balancingtrade(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t iambob)
{
struct iguana_info *kmdcoin = iguana_coinfind("KMD");
if ( kmdcoin != 0 )
if ( swap->bobcoin != 0 && swap->alicecoin != 0 )
{
if ( swap->DEXselector == 1 )
kmdcoin->DEXinfo.DEXpending -= swap->I.req.srcamount;
else if ( swap->DEXselector == 2 )
kmdcoin->DEXinfo.KMDpending -= swap->I.req.srcamount;
if ( iambob != 0 )
{
if ( strcmp(swap->I.req.src,swap->bobcoin->symbol) == 0 )
swap->bobcoin->DEXinfo.DEXpending -= swap->I.req.srcamount;
else if ( strcmp(swap->I.req.dest,swap->bobcoin->symbol) == 0 )
swap->bobcoin->DEXinfo.DEXpending -= swap->I.req.destamount;
}
else
{
if ( strcmp(swap->I.req.src,swap->alicecoin->symbol) == 0 )
swap->alicecoin->DEXinfo.DEXpending -= swap->I.req.srcamount;
else if ( strcmp(swap->I.req.dest,swap->alicecoin->symbol) == 0 )
swap->alicecoin->DEXinfo.DEXpending -= swap->I.req.destamount;
}
}
printf(">>>>>>>>>>>>>>>>>> balancing trade done by marketmaker\n");
return;

3
iguana/iguana777.h

@ -98,6 +98,7 @@ struct supernet_address
struct smartaddress
{
bits256 privkey,pubkey;
cJSON *typejson;
uint8_t pubkey33[33],rmd160[20];
};
@ -182,7 +183,7 @@ struct basilisk_swap
{
struct supernet_info *myinfoptr; struct iguana_info *bobcoin,*alicecoin;
void (*balancingtrade)(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t iambob);
int32_t subsock,pushsock,connected,DEXselector,aliceunconf,depositunconf,paymentunconf; uint32_t lasttime,aborted;
int32_t subsock,pushsock,connected,aliceunconf,depositunconf,paymentunconf; uint32_t lasttime,aborted;
FILE *fp;
bits256 persistent_privkey,persistent_pubkey;
struct basilisk_swapinfo I;

13
iguana/iguana_wallet.c

@ -910,6 +910,9 @@ void iguana_walletlock(struct supernet_info *myinfo,struct iguana_info *coin)
memset(&myinfo->persistent_priv,0,sizeof(myinfo->persistent_priv));
memset(&myinfo->persistent_pubkey33,0,sizeof(myinfo->persistent_pubkey33));
memset(myinfo->secret,0,sizeof(myinfo->secret));
memset(myinfo->jumblr_passphrase,0,sizeof(myinfo->jumblr_passphrase));
memset(&myinfo->jumblr_depositkey,0,sizeof(myinfo->jumblr_depositkey));
memset(&myinfo->jumblr_pubkey,0,sizeof(myinfo->jumblr_pubkey));
memset(myinfo->permanentfile,0,sizeof(myinfo->permanentfile));
if ( myinfo->decryptstr != 0 )
scrubfree(myinfo->decryptstr), myinfo->decryptstr = 0;
@ -1369,8 +1372,14 @@ TWOSTRINGS_AND_INT(bitcoinrpc,walletpassphrase,password,permanentfile,timeout)
}
}
if ( bits256_nonz(myinfo->persistent_priv) != 0 )
smartaddress_add(myinfo,myinfo->persistent_priv,"","");
{
char *jumblrstr,jumblr_passphrase[1024];
sprintf(jumblr_passphrase,"jumblr %s",password);
if ( (jumblrstr= jumblr_setpassphrase(myinfo,0,0,0,jumblr_passphrase)) != 0 )
free(jumblrstr);
smartaddress_add(myinfo,myinfo->persistent_priv,"kmd");
smartaddress_add(myinfo,myinfo->persistent_priv,"btc");
}
//basilisk_unspents_update(myinfo,coin);
return(retstr);
}

2
iguana/main.c

@ -753,7 +753,7 @@ void jumblr_loop(void *ptr)
printf("JUMBLR loop\n");
while ( myinfo->IAMNOTARY == 0 )
{
if ( (coin= iguana_coinfind("KMD")) != 0 )
if ( (coin= iguana_coinfind("KMD")) != 0 && iguana_coinfind("BTC") != 0 )
{
//#ifdef __APPLE__
//if ( (n++ % 10) == 0 )

2
includes/iguana_apideclares.h

@ -226,6 +226,8 @@ STRING_ARG(InstantDEX,allpairs,exchange);
THREE_STRINGS(InstantDEX,supports,exchange,base,rel);
ZERO_ARGS(InstantDEX,init);
ZERO_ARGS(InstantDEX,getswaplist);
ZERO_ARGS(InstantDEX,smartaddresses);
TWO_STRINGS(InstantDEX,smartaddress,type,symbol);
//THREE_STRINGS(atomic,approve,myorderid,otherid,txname);
//THREE_STRINGS(atomic,claim,myorderid,otherid,txname);

8
includes/iguana_funcs.h

@ -606,10 +606,10 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr);
int32_t iguana_datachain_scan(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t rmd160[20]);
int32_t basilisk_requests_poll(struct supernet_info *myinfo);
void dpow_psockloop(void *_ptr);
int32_t smartaddress_add(struct supernet_info *myinfo,bits256 privkey,char *BTCaddr,char *KMDaddr);
int32_t smartaddress(struct supernet_info *myinfo,bits256 *privkeyp,char *coinaddr);
int32_t smartaddress_pubkey(struct supernet_info *myinfo,bits256 *privkeyp,bits256 pubkey);
int32_t smartaddress_pubkey33(struct supernet_info *myinfo,bits256 *privkeyp,uint8_t *pubkey33);
int32_t smartaddress_add(struct supernet_info *myinfo,bits256 privkey,char *typestr);
int32_t smartaddress(struct supernet_info *myinfo,bits256 *privkeyp,char *symbol,char *coinaddr);
int32_t smartaddress_pubkey(struct supernet_info *myinfo,bits256 *privkeyp,char *symbol,bits256 pubkey);
int32_t smartaddress_pubkey33(struct supernet_info *myinfo,bits256 *privkeyp,char *symbol,uint8_t *pubkey33);
void iguana_RTreset(struct iguana_info *coin);
void iguana_RTpurge(struct iguana_info *coin,int32_t lastheight);

Loading…
Cancel
Save